代码更新

This commit is contained in:
jia 2023-10-16 09:16:50 +08:00
parent 7c424824bc
commit bed4cd1a01
6 changed files with 2456 additions and 25 deletions

View File

@ -13,7 +13,7 @@
"type" : "uniCloud"
},
{
"playground" : "standard",
"playground" : "custom",
"type" : "uni-app:app-android"
},
{

View File

@ -18,6 +18,31 @@ export function ttWss(data) {
return requesta.post(`index/tts`, data);
}
// base64 转 二进制流(blob)
export function dataURLtoBlob(dataurl) {
// console.log(dataurl);
// let str = "data:audio/wav;base64," + dataurl.slice(2)
// console.log(str);
let mime = "audio/wav"
// var arr = str.split(","),
// mime = arr[0].match(/:(.*?);/),
// let bstr = atob(arr[1])
let bstr = atob(dataurl)
let n = bstr.length
let u8arr = new Uint8Array(n);
while (n--) {
u8arr[n] = bstr.charCodeAt(n);
}
console.log(u8arr)
// return new Blob([u8arr], {
// type: mime,
// });
}
// -防抖
export function debounce(fn, wait) {
let delay = wait || 500

View File

@ -366,7 +366,7 @@
success: (res) => {
uni.hideLoading()
console.log(res)
this.$emit('down', res)
this.show = false
//
uni.saveImageToPhotosAlbum({

View File

@ -0,0 +1,444 @@
<template>
<view class="qiqb-ctx" v-bind:class="{'on':show}">
<view class="qiqb-ctx-box">
<!-- <text @click="show=false"></text> -->
<canvas canvas-id="ctx" style="width:330px;height:300px" v-show="img_show"></canvas>
</view>
<view class="qiqb-ctx-btns u-border-bottom">
<view>分享至</view>
<view>长按海报可转发分享</view>
<view>
<!-- <text>微信好友</text><text>分享朋友圈</text> -->
<text @click="down">保存图片</text>
</view>
</view>
<view class="qiqb-ctx-close" @click="show=false">取消</view>
</view>
</template>
<!-- https://crmeb-test.shop.lihaink.cn/api/upload/image/field -->
<script>
export default {
name: "share",
data() {
return {
show: false,
img_show: true,
mode: 'img',
list: [],
pext1: '',
pext2: ''
}
},
onLoad() {
uni.$on('add', function(res) {
console.log(res.listData) // B
})
},
mounted() {
// console.log(this.list,'222222')
},
methods: {
//
refresh(index) {
this.list = index;
this.pext1 = index[index.length - 2].content
this.pext2 = index[index.length - 1].content
// console.log(this.list)
},
init() { // opt
uni.showLoading({
title: '生成中'
})
let self = this
let ctx = uni.createCanvasContext('ctx')
//
self.drawBg(ctx, 330, 300, 8, '#fff')
//
uni.downloadFile({
url: 'http://banbai.oss-cn-beijing.aliyuncs.com/20230524/96e80fb572e35d4acebdce67dbd41f30.jpg',
success: function(e) {
let img = e.tempFilePath //
uni.downloadFile({
url: 'http://banbai.oss-cn-beijing.aliyuncs.com/20230524/96e80fb572e35d4acebdce67dbd41f30.jpg',
success: function(e) {
let photo = e.tempFilePath //
uni.downloadFile({
url: 'http://banbai.oss-cn-beijing.aliyuncs.com/20230606/f0738e1ff432c08b369ca5e4b906a34a.png',
success: function(e) {
uni.hideLoading()
let qrcode = e.tempFilePath //
self.drawTxtOne(ctx, '农业咨询小程序', 220, 35, 100,
'#222', 12, false)
//
self.drawImg(ctx,
'https://lihai001.oss-cn-chengdu.aliyuncs.com/storage/202310/20231013091310.png',
170, 10, 40, 40, 20)
self.drawImg(ctx,
'https://lihai001.oss-cn-chengdu.aliyuncs.com/storage/202310/20231013091059.png',
10, 50, 40, 40, 20)
self.drawImg(ctx,
'https://lihai001.oss-cn-chengdu.aliyuncs.com/storage/202310/20231013091310.png',
10, 118, 40, 40, 20)
//
// self.drawImg(ctx, img, 10, 120, 210, 260, 8)
//
self.drawImg(ctx,
'https://lihai001.oss-cn-chengdu.aliyuncs.com/storage/202310/ai_qr_20231013091327.jpg',
174, 195, 100, 100, 0)
//
self.drawTxtOne(ctx, self.pext1, 60, 70, 100,
'#222', 12, false)
// self.drawTxtTwo(ctx, self.pext1, 60, 64, 80,
// '#222', 13)
// self.drawTxtTwo(ctx, self.pext1, 60,64,
// 190, 20, '#222', 12)
//
// self.drawTxtOne(ctx, '', 60, 80, 100,
// '#666', 9, false)
//
self.drawTxtFour(ctx,
self.pext2,
60, 120,
190, 20, '#222', 12)
//
self.drawTxtOne(ctx, '下载二维码', 15, 250, 100,
'#666', 11, false)
//
// self.drawTxtOne(ctx, '', 15, 350, 100,
// '#ED3327', 11, false)
//
// self.drawTxtOne(ctx, '86.00', 82, 350, 100,
// '#ED3327', 11, true)
//
// self.drawTxtDel(ctx, ':20', 15, 370, 4,
// '#818181', 10, false)
//
ctx.draw()
self.show = true
}
})
}
})
}
})
},
down() {
uni.showLoading({
title: '保存中'
})
uni.canvasToTempFilePath({
canvasId: 'ctx',
quality: 1,
success: (res) => {
uni.hideLoading()
console.log(res)
this.$emit('down', res)
this.show = false
//
uni.saveImageToPhotosAlbum({
filePath: res.tempFilePath,
success: (res) => {
console.log('保存')
uni.showModal({
title: '保存成功'
})
}
})
}
})
},
//
drawBg(ctx, w, h, r, color) {
let x = 0
let y = 0
ctx.setFillStyle(color)
ctx.save()
ctx.beginPath()
ctx.moveTo(x + r, y)
ctx.arcTo(x + w, y, x + w, y + h, r)
ctx.arcTo(x + w, y + h, x, y + h, r)
ctx.arcTo(x, y + h, x, y, r)
ctx.arcTo(x, y, x + w, y, r)
ctx.closePath()
ctx.fill()
},
//
drawImg(ctx, img, x, y, w, h, r) {
let self = this
ctx.save()
ctx.beginPath()
ctx.arc(x + r, y + r, r, Math.PI, Math.PI * 1.5)
ctx.arc(x + w - r, y + r, r, Math.PI * 1.5, Math.PI * 2)
ctx.arc(x + w - r, y + h - r, r, 0, Math.PI * 0.5)
ctx.arc(x + r, y + h - r, r, Math.PI * 0.5, Math.PI)
ctx.clip()
ctx.drawImage(img, x, y, w, h)
ctx.restore()
},
//
drawTxtOne(ctx, text, x, y, maxWidth, color, size, bold) {
ctx.save()
ctx.beginPath()
let chr = text.split("")
let temp = ""
let row = []
ctx.setFontSize(size)
ctx.setFillStyle(color)
for (let a = 0; a < chr.length; a++) {
if (ctx.measureText(temp).width < maxWidth) {
temp += chr[a]
}
}
row.push(temp)
if (ctx.measureText(temp).width > maxWidth) row[0] = row[0] + '...'
for (var b = 0; b < row.length; b++) {
ctx.fillStyle = color
if (bold) {
ctx.font = 'normal bold ' + size + 'px sans-serif'
} else {
ctx.font = 'normal ' + size + 'px sans-serif'
}
ctx.fillText(row[b], x, y)
}
},
//
drawTxtTwo(ctx, text, x, y, maxWidth, lineHeight, color, size) {
ctx.save()
ctx.beginPath()
let chr = text.split("")
let temp = ""
let row = []
ctx.setFontSize(size)
ctx.setFillStyle(color)
for (let a = 0; a < chr.length; a++) {
if (ctx.measureText(temp).width < maxWidth) {
temp += chr[a];
} else {
a--
row.push(temp)
temp = ""
}
}
row.push(temp)
if (row.length > 2) {
let rowCut = row.slice(0, 2)
let rowPart = rowCut[1]
let test = ""
let empty = []
for (var a = 0; a < rowPart.length; a++) {
if (ctx.measureText(test).width < maxWidth) {
test += rowPart[a]
} else {
break
}
}
empty.push(test)
var group = empty[0] + "..."
rowCut.splice(1, 1, group)
row = rowCut
}
for (var b = 0; b < row.length; b++) {
ctx.fillStyle = color
ctx.font = 'normal ' + size + 'px sans-serif'
ctx.fillText(row[b], x, y + b * lineHeight, 300)
}
},
drawTxtFour(ctx, text, x, y, maxWidth, lineHeight, color, size) {
ctx.save()
ctx.beginPath()
let chr = text.split("")
let temp = ""
let row = []
ctx.setFontSize(size)
ctx.setFillStyle(color)
for (let a = 0; a < chr.length; a++) {
if (ctx.measureText(temp).width < maxWidth) {
temp += chr[a];
} else {
a--
row.push(temp)
temp = ""
}
}
row.push(temp)
if (row.length > 4) {
let rowCut = row.slice(0, 4)
let rowPart = rowCut[1]
let test = ""
let empty = []
for (var a = 0; a < rowPart.length; a++) {
if (ctx.measureText(test).width < maxWidth) {
test += rowPart[a]
} else {
break
}
}
empty.push(test)
var group = empty[0] + "..."
rowCut.splice(1, 1, group)
row = rowCut
}
for (var b = 0; b < row.length; b++) {
ctx.fillStyle = color
ctx.font = 'normal ' + size + 'px sans-serif'
ctx.fillText(row[b], x, y + b * lineHeight, 300)
}
},
// 线
drawTxtDel(ctx, txt, x, y, h, color, size) {
ctx.fillStyle = color
ctx.font = 'normal ' + size + 'px sans-serif'
ctx.fillText(txt, x, y)
ctx.beginPath()
let width = ctx.measureText(txt).width;
ctx.rect(x, y - h, width, 1)
ctx.fillStyle = color
ctx.fill()
}
}
}
</script>
<style>
.qiqb-ctx {
position: fixed;
top: 0;
right: 0;
bottom: 0;
bottom: 0;
left: 0;
z-index: -1;
display: flex;
background: rgba(0, 0, 0, .6);
opacity: 0;
transition: all .3s;
flex-direction: column;
align-items: flex-end;
justify-content: flex-end
}
.qiqb-ctx.on {
z-index: 2000;
opacity: 1
}
.qiqb-ctx-box {
position: relative;
display: flex;
padding: 30upx 0 40upx;
width: 750upx;
justify-content: center
}
.qiqb-ctx-box text {
position: absolute;
top: -40upx;
right: 145upx;
display: inline-flex;
width: 47upx;
height: 47upx;
background: url('img/close.png');
background-size: 100% 100%
}
.qiqb-ctx-btns {
display: flex;
width: 750upx;
height: 330upx;
border-radius: 20upx 20upx 0 0;
background: #fff;
flex-direction: row;
flex-direction: column;
align-items: center
}
.qiqb-ctx-btns view:nth-child(1) {
display: flex;
padding-top: 10upx;
height: 80upx;
font-weight: 700;
font-size: 30upx;
align-items: center
}
.qiqb-ctx-btns view:nth-child(2) {
height: 80upx;
color: #666;
font-size: 24upx
}
.qiqb-ctx-btns view:nth-child(3) {
display: flex;
padding-bottom: 30upx;
font-size: 26upx;
flex-direction: row;
align-items: center
}
.qiqb-ctx-btns view:nth-child(3) text {
display: flex;
width: 250upx;
flex-direction: column;
align-items: center;
justify-content: center
}
.qiqb-ctx-btns view:nth-child(3) text:nth-child(1)::before {
display: inline-flex;
margin-bottom: 20upx;
width: 86upx;
height: 86upx;
background: url('img/3.png');
background-size: 100% 100%;
content: ''
}
.qiqb-ctx-btns view:nth-child(3) text:nth-child(2)::before {
display: inline-flex;
margin-bottom: 20upx;
width: 86upx;
height: 86upx;
background: url('img/1.png');
background-size: 100% 100%;
content: ''
}
.qiqb-ctx-btns view:nth-child(3) text:nth-child(3)::before {
display: inline-flex;
margin-bottom: 20upx;
width: 86upx;
height: 86upx;
background: url('img/2.png');
background-size: 100% 100%;
content: ''
}
.qiqb-ctx-close {
display: flex;
padding-bottom: 50upx;
width: 100%;
height: 150upx;
background: #fff;
font-size: 32upx;
align-items: center;
justify-content: center
}
</style>

View File

@ -182,7 +182,7 @@
</view>
</uni-popup>
<qiqbshare ref="child" ></qiqbshare>
<qiqbshare ref="child"></qiqbshare>
</view>
@ -194,7 +194,9 @@
iatWss,
debounce,
throttle,
ttWss
fileToBase64,
dataURLtoBlob,
ttWss,
} from "@/api/api.js"
import {
HTTP_REQUEST_URL
@ -379,14 +381,14 @@
let arry1 = []
let a;
let b;
if(data.length>2){
a=data.length-2
b=data.length-1
}else{
a=0
b=1
}
if (data.length > 2) {
a = data.length - 2
b = data.length - 1
} else {
a = 0
b = 1
}
for (let i in data[a].content) {
if (data[a].content.slice(i * 22, (i + 1) * 22)) {
arry.push(data[a].content.slice(i * 22, (i + 1) * 22))
@ -397,14 +399,14 @@
if (data[b].content.slice(i * 22, (i + 1) * 22)) {
arry1.push(data[b].content.slice(i * 22, (i + 1) * 22))
}
}
// console.log(arry1.length,arry.length)
this.imageSize.height=(arry1.length*20)+(arry.length*20)+100+150
this.$refs.child.refresh(this.talkList,this.imageSize.height,(arry.length*20)+100);
this.imageSize.height = (arry1.length * 20) + (arry.length * 20) + 100 + 150
this.$refs.child.refresh(this.talkList, this.imageSize.height, (arry.length * 20) + 100);
},
@ -418,7 +420,7 @@
},
//
Share() {
// this.isDraw = !this.isDraw;
this.cavshare(this.talkList)
this.$refs.child.init()
@ -628,6 +630,38 @@
}
// #endif
},
//
voiceBegain() {
let _this = this;
let options = {};
//#ifdef APP-PLUS || APP-PLUS-NVUE
options.engine = 'iFly';
options.punctuation = false; //
options.timeout = 10 * 6000; //
plus.speech.startRecognize(options, function(s) {
_this.searchText = _this.searchText + s;
console.log(_this.searchText) //
//
_this.searchValue = s;
_this.searchText = ""
//
_this.words1 = _this.searchValue
_this.words2 = _this.searchText
//
plus.speech.stopRecognize();
}, function(e){
console.log('语音识别失败:'+JSON.stringify(e));
});
//#endif
// #ifdef H5
alert("只有h5平台才有alert方法")
// #endif
},
//
txtspeech(val, i) {
@ -642,21 +676,21 @@
// }).catch((err) => {
// console.log(err)
// })
ttWss({
data: val
}).then(res => {
if (res.code == 0) {
this.talkList[i].audio_file = res.data.mp3
this.nums = this.talkList.length - 1
this.talkList[i].audio_file = res.data.mp3
this.nums = this.talkList.length - 1
this.nums = this.talkList.length - 1
}
}).catch((err) => {
console.log(err)
})
},
//
@ -668,6 +702,7 @@
},
longpress(e) {
// console.log(e.touches[0].pageX)
this.voiceBegain()
this.onFeedTap()
this.touchT = new Date().getTime();
this.islong = true
@ -829,7 +864,7 @@
console.error(error)
})
},
//
deletespeech() {
this.btnStatus = 0
@ -875,7 +910,7 @@
palyaudio(item) {
this.palystatus = !this.palystatus
if (!this.palystatus) {
innerAudioContext.src = item.audio_file;
innerAudioContext.play()

1927
pages/index/index2.vue Normal file

File diff suppressed because it is too large Load Diff