个人案例
- 为什么wx:for-items列表渲染[object Object]?
为什么wx:for-items列表渲染[object Object]? [图片] addAttributeType: function (e) { let idx = e.currentTarget.dataset.index; let arr = (this.data.attribute[`${idx}`].type) ? this.data.attribute[`${idx}`].type : []; let obj = new Object; obj["name"] = this.data.attributeType; obj["checked"] = false; arr.push(obj); this.setData({ [`attribute[${idx}].type`]: arr, attributeType: '', }) console.log("属性列表:::", this.data.attribute) }, <block wx:for-items="{{item.type}}" wx:key="items"> <view class="tag_item" data-idx="{{idx}}" data-cur="{{index}}" catchtap="delAttributeType"> <text>{{items.name}}</text> </view> </block>
2021-07-05 - 云函数 Waiting TTFB时间过长?
云函数的执行时间很短,为什么Waiting TTFB时间过长? [图片] [图片] 是因为我使用了switch case的原因吗? [图片]
2021-06-13 - 选择图片报错:readFile:fail permission denied, open?
"readFile:fail permission denied, open http://tmp/Fe4kW9rQpRU99211d0b988f05102b249bb86fd9589fe.jpg" 选择图片成功后,再读取本地内容时报错 wx.getFileSystemManager().readFile()
2021-06-10 - 图片批量鉴黄,如何实现按图片上传顺序返回结果?
期望的结果 index = 0 按(图片压缩成功)=>(图片格式转换成功)=>(图片检测结果)的顺序执行完,再执行index = 1 [图片] onChangeFlockData: function (e) { wx.chooseImage({ count: 3, sizeType: ['original', 'compressed'], sourceType: ['album', 'camera'], success: async res => { const tempFilePaths = res.tempFilePaths; this.setData({ tempFile: [...this.data.tempFile, ...tempFilePaths] }); for (let i = 0; i < this.data.tempFile.length; i++) { await this.compressImg(this.data.tempFile[i], i) } } }) }, //图片压缩 async compressImg(imgUrl, index) { return new Promise((resolve, reject) => { wx.getImageInfo({ src: imgUrl, }).then(res => { const imgInfo = res.path; const imgWidth = res.width; const imgHeight = res.height; const query = wx.createSelectorQuery() query.select('#canvas') .fields({ node: true, size: true }) .exec(async res => { const canvas = res[0].node; const ctx = canvas.getContext('2d'); const dpr = wx.getSystemInfoSync().pixelRatio; const imgW = Math.trunc(imgWidth / dpr); const imgH = Math.trunc(imgW / imgWidth * imgHeight); canvas.width = imgW; canvas.height = imgH; ctx.clearRect(0, 0, imgW, imgH); this.setData({ canvasWidth: imgW, canvasHeight: imgH }); let imageObj = canvas.createImage(); imageObj.src = imgInfo; imageObj.onload = (res) => { ctx.drawImage(imageObj, 0, 0, imgW, imgH) }; const cfgSave = { fileType: "jpg", quality: 0.5, width: imgW, height: imgH, destWidth: imgW, destHeight: imgH, canvas: canvas, }; wx.canvasToTempFilePath({ ...cfgSave, }).then(async res => { console.log("图片压缩成功:::", res.tempFilePath + "index:::", index) resolve(res.tempFilePath) let tempUrl = res.tempFilePath; await this.imgSecCheck(tempUrl, index); }).catch(err => { reject(err) }) }) }) }) }, //图片送审 imgSecCheck: async function (tempUrl, index) { wx.showLoading({ mask: true }); wx.getFileSystemManager().readFile({ filePath: tempUrl, encoding: "base64", success: async (res) => { console.log("图片格式转换成功:::", res + "index:::", index); let imgBuffer = res.data await this.wait(imgBuffer, index) }, fail: err => { console.error(err); }, }) }, wait: async function (imgBuffer, index) { return new Promise((resolve, reject) => { wx.cloud.callFunction({ name: "msgSecCheck", data: { type: 'imgSecCheckBuffer', value: imgBuffer, } }).then(res => { console.log("图片检测结果:", res.result + "index:::", index) wx.hideLoading() if (res.result.errCode === 87014) { wx.hideLoading() wx.showToast({ title: '图片含有违法违规内容', icon: 'none' }) return } resolve(res.result) // this._uploadImg(tempUrl) }).catch(err => { console.log(err) reject(err) wx.hideLoading() wx.showModal({ title: '提示', content: '图片尺寸过大,请调整图片尺寸', success(res) { if (res.confirm) { console.log('用户点击确定') } else if (res.cancel) { console.log('用户点击取消') } } }) }) }) },
2021-05-19 - 群名称,已经获取到openGid但是前端页面,有部分群名称不显示?
组件名称:open-data(type="groupName"); 微信版本:8.0.6; 基础库:2.17.0; 手机型号:iOS14.5.1; 问题描述:群名称,已经获取到openGid但是前端页面,有部分群名称不显示? [图片]
2021-05-18 - for循环,图片批量鉴黄?
我理想中的结果是一张一张图片鉴黄,把鉴定违规的图片删除,但是现在的结果如图: [图片] //上传图片 onChangeFlockData: async function (e) { let imgUrls = e.detail.all; //上传的图片数组 for (let i = 0; i < imgUrls.length; i++) { await this.imgInfoCheck(imgUrls[i].url) } }, //获取图片信息 imgInfoCheck: async function (url) { wx.getImageInfo({ src: url, }).then(async (res) => { console.log("图片信息:", res) const imgInfo = res.path; const imgWidth = res.width; const imgHeight = res.height; await this._compressImage(imgInfo, imgWidth, imgHeight); }) }, //图片压缩 _compressImage: async function (imgInfo, imgWidth, imgHeight) { const query = wx.createSelectorQuery() query.select('#canvas') .fields({ node: true, size: true }) .exec(res => { const canvas = res[0].node; const ctx = canvas.getContext('2d'); const dpr = wx.getSystemInfoSync().pixelRatio; const imgW = Math.trunc(imgWidth / dpr); const imgH = Math.trunc(imgW / imgWidth * imgHeight); canvas.width = imgW; canvas.height = imgH; ctx.clearRect(0, 0, imgW, imgH); this.setData({ canvasWidth: imgW, canvasHeight: imgH }); let imageObj = canvas.createImage(); imageObj.src = imgInfo; imageObj.onload = (res) => { ctx.drawImage(imageObj, 0, 0, imgW, imgH) }; const cfgSave = { fileType: "jpg", quality: 0.5, width: imgW, height: imgH, destWidth: imgW, destHeight: imgH, canvas: canvas, }; wx.canvasToTempFilePath({ ...cfgSave, }).then(async res => { let tempUrl = res.tempFilePath console.log("压缩后图片:", res) await this.imgSecCheck(tempUrl) }) }) }, //图片送审 imgSecCheck: async function (tempUrl) { wx.showLoading({ mask: true }); wx.getFileSystemManager().readFile({ filePath: tempUrl, encoding: "base64", success: function (res) { let imgBuffer = res.data wx.cloud.callFunction({ name: "msgSecCheck", data: { type: 'imgSecCheckBuffer', //以buffer方式上传送审 value: imgBuffer, } }).then(res => { console.log("图片检测结果:", res.result.errCode) wx.hideLoading() if (res.result.errCode === 87014) { wx.hideLoading() wx.showToast({ title: '图片含有违法违规内容', icon: 'none' }) return } // this._uploadImg(tempUrl) }).catch(err => { console.log(err) wx.hideLoading() wx.showModal({ title: '提示', content: '图片尺寸过大,请调整图片尺寸', success(res) { if (res.confirm) { console.log('用户点击确定') } else if (res.cancel) { console.log('用户点击取消') } } }) }) }, fail: err => { console.error(err); } }) },
2021-05-16 - await 对此表达式类型没有影响?
await 对此表达式类型没有影响? onChangeFlockData: function (e) { let tempArr = []; let imgUrls = e.detail.all; imgUrls.forEach(async(item) => { tempArr.push(item.url) if (item.imageSize >= 1048576) { this.imgInfoCheck(item.url) } else { await this.imgSecCheck(item.url) } }); this.setData({ tempArr: tempArr }) console.log("tempArr:::", this.data.tempArr) }, imgSecCheck: function (tempUrl) { wx.showLoading({ mask: true }); wx.getFileSystemManager().readFile({ filePath: tempUrl, encoding: "base64", success: res => { console.log(res) let imgBuffer = res.data wx.cloud.callFunction({ name: "msgSecCheck", data: { type: 'imgSecCheckBuffer', //以buffer方式上传送审 value: imgBuffer, } }).then(res => { console.log("图片检测结果:", res) if (res.result.errCode === 87014) { wx.hideLoading() wx.showToast({ title: '图片含有违法违规内容', icon: 'none' }) } }).catch(err => { console.log(err) wx.hideLoading() wx.showModal({ title: '提示', content: '图片尺寸过大,请调整图片尺寸', success(res) { if (res.confirm) { console.log('用户点击确定') } else if (res.cancel) { console.log('用户点击取消') } } }) }) }, fail: err => { console.error(err); } }) },
2021-05-15 - 分包页面引用腾讯地图,开发工具正常,手机不显示?
分包页面引用腾讯地图,开发工具正常,手机不显示 import QQMapWX from '../../../utils/libs/qqmap-wx-jssdk.js'; var qqmapsdk = new QQMapWX({ key: 'XDZBZ-ZJUW4-I2AUQ-XTPDQ' //腾讯地图秘钥key }); _fetchLocation: function (e) { wx.getLocation({ type: 'gcj02', success: res => { qqmapsdk.reverseGeocoder({ success: res => { console.log(res) var address = res.result.address_component this.setData({ city: address.city, }) } }) } }) }, 开发工具可以正常获取到数据,手机预览获取不到数据,函数不执行。 [图片]
2021-05-09 - 请问Excel文件如何导出嵌套数组格式的json文件?
请问Excel文件如何导出嵌套数组格式的json文件 [图片] 导出如下格式: [图片]
2021-05-08 - 小程序客服消息“进入会话事件”为什么获取不到数据包?
云开发 如何接收session-from传的参数 <button class="btn_like btn_join" open-type="contact" show-message-card="true" send-message-title="加入粉丝群" session-from="{{mediaId}}" send-message-img="/images/default_img.png" send-message-path="/pages/lordHome/lordHome" bindcontact="handleContact"> <text>加入社群</text> </button> [图片]
2021-04-06