From d4a2cc2d8b6e5b0faa19b199b343f010c0a6c14a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E8=96=AA=E5=90=8D?= <942005050@qq.com> Date: Sat, 20 Jul 2024 17:59:28 +0800 Subject: [PATCH] =?UTF-8?q?=E7=9B=B4=E6=8E=A5=E7=BF=BB=E5=8C=85=E6=89=93?= =?UTF-8?q?=E5=8D=B0=20=E4=BC=98=E5=8C=96=20=E6=9C=AA=E5=AE=8C=E5=96=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/point/index.vue | 138 ++++++++++++++++++++++++++++++-------- 1 file changed, 110 insertions(+), 28 deletions(-) diff --git a/src/pages/point/index.vue b/src/pages/point/index.vue index d37f6815..8d9043b5 100644 --- a/src/pages/point/index.vue +++ b/src/pages/point/index.vue @@ -91,6 +91,76 @@ methods: { + // 递归循环 qrcodeRef 组件集合 + forEachQrcodeRef(el,index,elLength,wait) { + let _this = this + console.log('11111111111111'); + console.log(index); + if (index == elLength) { + console.log('99999999'); + return; + } + const item = el[index]; + setTimeout(() => { + console.log(el[index]); + console.log(item.canvasToTempFilePath); + // try{ + item.canvasToTempFilePath({ + success: (res) => { + console.log(res); + // 将临时路径转换成base64 + pathToBase64(res.tempFilePath).then(base64 => { + console.log(res.tempFilePath); + _this.data[index].barcodeBase64 = base64 + if (index == elLength - 1) { + _this.isLoadFinish = true + uni.hideLoading(); + }else { + console.log(index); + } + this.forEachQrcodeRef(el,index+1,el.length,100) + }).catch(err => { + console.log(err); + this.forEachQrcodeRef(el,index+1,el.length,100) + }) + }, + fail(err) { + console.log(err) + } + }) + // }catch(e){ + // console.log(e) + // //TODO handle the exception + // // this.forEachQrcodeRef(el,index,el.length) + // } + },wait); + }, + // stringToBase64(str) { + // console.log('999999999999999'); + // console.log(str); + // // 对中文字符进行编码 + // // var encodeUTF8 = uni.getSystemInfoSync().platform === 'android' ? 'utf-8' : 'utf8'; + // // console.log('8888888888888'); + // // var utf8Str = uni.encode(str, encodeUTF8); + // // console.log(utf8Str); data: + // // 将utf8字符串转为base64 + // var base64Str = btoa(str); + // console.log(base64Str); + // return base64Str; + // }, + // getQrCodeBase64(index) { + // let _this = this + // // 使用setTimeout确保DOM更新完成后再获取canvas + // setTimeout(() => { + // const qrcodeCanvas = this.$refs.qrcodeRef.$el.querySelector('canvas'); + // if (qrcodeCanvas) { + // // 将canvas转换为Base64编码的图片URL + // _this.data[index].barcodeBase64 = qrcodeCanvas.toDataURL('image/png'); + // } else { + // console.log('xxxxxxxxxxxxxxxxx') + // } + // }, 0); + // }, getListData(){ // 获取数据 // 大哥:后端添加了 制造标签 生产线 ,可根据 生产线是否有值 来判断打印的是制造标签 @@ -112,36 +182,45 @@ // }] let _this = this - this.$nextTick(async () => { + // this.$nextTick(async () => { // 获取二维码图片临时路径 const el = _this.$refs['qrcodeRef'] - let str = '' - el.forEach(async (item, index) => { - await item.canvasToTempFilePath({ - success: async (res) => { - // 将临时路径转换成base64 - await pathToBase64(res.tempFilePath).then(base64 => { - _this.data[index].barcodeBase64 = base64 - if (index == el.length - 1) { - _this.isLoadFinish = true - uni.hideLoading(); - - }else { - console.log(index); - } - }).catch(err => { - console.log(err); - }) - }, - fail(err) { - console.log('err:::', err) - } - }) + _this.forEachQrcodeRef(el,0,el.length,5000); + // // }) - }) - - }) + + // let _this = this + // this.$nextTick(async () => { + // // 获取二维码图片临时路径 + // const el = _this.$refs['qrcodeRef'] + // let str = '' + // el.forEach(async (item, index) => { + // await item.canvasToTempFilePath({ + // success: async (res) => { + // // 将临时路径转换成base64 + // await pathToBase64(res.tempFilePath).then(base64 => { + // _this.data[index].barcodeBase64 = base64 + // if (index == el.length - 1) { + // _this.isLoadFinish = true + // uni.hideLoading(); + + // }else { + // console.log(index); + // } + // }).catch(err => { + // console.log(err); + // }) + // }, + // fail(err) { + // console.log('err:::', err) + // } + // }) + + // }) + + // }) + // }) }, // #ifdef APP @@ -250,7 +329,7 @@ }) this.newHtmlContent = this.newHtmlContent.replace( "mainBody", str); //替换物品代码 - console.log(this.newHtmlContent) + // console.log(this.newHtmlContent) }); // #endif } @@ -278,7 +357,10 @@ this.timer = null } this.data = this.originData - this.getListData() + console.log(287,'11111111') + this.$nextTick(()=> { + this.getListData() + }) },1000) }, }