- TypeError: Function(...) is not a function官方指引没用?
前几年就有人fail怎么现在还fail. 看了官方指引 开了JS 转ES5 也更新了 没用 谢谢大神解答。 https://developers.weixin.qq.com/community/develop/doc/0002ce07a58000a57c5da5e6456c09 TypeError: Function(...) is not a function at runtime.js? [sm]:747 at WASubContext.js?t=wechat&s=1752280867204&v=3.8.3:1 at _.runWith (WASubContext.js?t=wechat&s=1752280867204&v=3.8.3:1) at q (WASubContext.js?t=wechat&s=1752280867204&v=3.8.3:1) at n (WASubContext.js?t=wechat&s=1752280867204&v=3.8.3:1) at index.js? [sm]:3 at WASubContext.js?t=wechat&s=1752280867204&v=3.8.3:1 at _.runWith (WASubContext.js?t=wechat&s=1752280867204&v=3.8.3:1) at q (WASubContext.js?t=wechat&s=1752280867204&v=3.8.3:1) at appservice.js:1403(env: Windows,mp,1.06.2405020; lib: 3.8.3) [图片] [图片][图片] // pages/cart/index.js import{getSetting,chooseAddress,openSetting,showModal,showToast } from "../../utils/asyncWx.js"; import regeneratorRuntime from '../../lib/runtime/runtime';//local path import {accAdd,accMul} from "../../utils/util.js"; Page({ data: { address:{}, cart:[], allChecked:false, totalPrice:0, totalNum:0, curSchoolName:'', }, onShow:function(){ //如果之前选择了地址 就载入 const address=wx.getStorageSync("curAddr")||[]; this.setData({address}); //获取缓存中数据 const cart=wx.getStorageSync("cart")||[]; //计算全选 //every()遍历 接受一个回调函数 确保每一个回调函数返回true then every方法返回true //空数组返回就是true //const allChecked=cart.length?cart.every(v=>v.checked):false; this.setCart(cart); //update cartreddot this.scanCart(this); }, async handleChooseAddress(){ wx.navigateTo({ url: '/pages/address/index' }) }, handleItemChange(e){ //1.被修改的商品id const cl_id=e.currentTarget.dataset.id; console.log(cl_id); //购物车数组 let {cart}=this.data; //被修改的商品对象 let index=cart.findIndex(v=>v.cloth_id===cl_id); //选中取反 cart[index].checked=!cart[index].checked; // 重新设置数据 //this.setData({ cart }); this.setCart(cart); //update cartDot this.scanCart(this) }, //设置购物车状态重新计算 底部工具栏 setCart(cart){ let allChecked=true; let totalPrice=0; let totalNum=0; cart.forEach(v=>{ if(v.checked){ totalPrice=accAdd(accMul(v.num,v.cloth_price),totalPrice); totalNum+=v.num; } else{ allChecked=false; } }) //判断数组为空 allChecked=cart.length!=0?allChecked:false; //重新设置data this.setData({ cart, allChecked, totalPrice, totalNum }); wx.setStorageSync('cart', cart); }, //全选 handleAlhandleItemAllChecklChange(){ let {cart,allChecked}=this.data; allChecked=!allChecked; cart.forEach(v=>v.checked=allChecked); this.setCart(cart); this.scanCart(this) }, async handleItemNumEdit(e){ //获取传递过来的参数 const {operation,id}=e.currentTarget.dataset; //获取购物车数组 let {cart}=this.data; //找到需要修改的商品索引 const index=cart.findIndex(v=>v.cloth_id===id); //判断是否删除 if(cart[index].num===1&&operation===-1){ const res=await showModal({content:"您确定要删除商品吗?"}) if (res.confirm) { cart.splice(index,1); this.setCart(cart); } } /* */ if(cart[index].num===2&&operation===+1&&( wx.getStorageSync("curschool")['_id']==101004 ||wx.getStorageSync("curschool")['_id']==101005 ||wx.getStorageSync("curschool")['_id']==101002) &&cart[index].cloth_class==2025 ) { await showToast({title:""}); return; } else { //进行数量修改 cart[index].num+=operation; //设置会缓存和data中 this.setCart(cart); } this.scanCart(this) }, async handleSubmit(){ const {address,totalNum}=this.data; if(!address.receiver){ await showToast({title:"您还没有选择收货地址"}); return; } if(totalNum===0){ await showToast({title:"您还没有选择商品"}); return; } if((totalNum!=4 ||wx.getStorageSync("cart")[0]['cloth_name']==wx.getStorageSync("cart")[1]['cloth_name'] ||wx.getStorageSync("cart")[0]['cloth_class']!=wx.getStorageSync("cart")[1]['cloth_class'] ||wx.getStorageSync("cart")[0]['cloth_grade']!=wx.getStorageSync("cart")[1]['cloth_grade'] ||wx.getStorageSync("cart")[0]['cloth_gender']!=wx.getStorageSync("cart")[1]['cloth_gender'] ) &&(wx.getStorageSync("curschool")['_id']==101004 ||wx.getStorageSync("curschool")['_id']==101005 ||wx.getStorageSync("curschool")['_id']==101002) && wx.getStorageSync("cart")[0]['cloth_class']==2025) { await showToast({title:""}); return; } wx.navigateTo({ url: '/pages/submit/index', }) }, scanCart: function (that) { //我把购物车里面的数据都塞到了缓存里,取名cart,任何一项修改购物车的行为,都会先取购物车的缓存,在重新更新缓存里的购物车参数 //购物车 var cart = wx.getStorageSync("cart"); //统计购物车商品的总数量 var cartnumber = 0; //购物车菜品的一共的数量 for (var index in cart) { cartnumber += cart[index].num } if (cart.length) { //判断购物车的数量个数,购物车如果为空就走else wx.setTabBarBadge({ //购物车不为空 ,给购物车的tabar右上角添加购物车数量标志 index: 1, //标志添加位置 text: "" + cartnumber + "" //通过编译,将购物车总数量放到这里 }) } else {//购物车为空 wx.removeTabBarBadge({ //移除指定位置的tabbar右上角的标志 index: 1, }) } } })
07-12 - 小程序支付成功 但是云数据库没有存入订单 这个如何debug?
9月的订单,交易单号4200002346202409147100666709 商户单号:2024091414211861 环境id: prod-dbtpz 云函数支付代码: // 云函数入口函数 //questionPay: exports.main = async (event, context) => { const res = await cloud.cloudPay.unifiedOrder({ body: event.body, // 商品描述,必填 details:event.details,//商品详情 outTradeNo: event.goodsnum, // 商户订单号,必填,不能重复 spbillCreateIp: '127.0.0.1', // 终端IP,必填 subMchId: event.subMchId, // 子商户号,微信支付商户号,必填 totalFee:parseInt(event.payVal), // 总金额,必填 envId: 'prod-dbtpz', // 结果通知回调云函数环境,你自己小程序的坏境id functionName: 'wechatpay', // 结果通知回调云函数名,非必填参数,即使为空,也不影响支付,但是官方文档里写的是必填参数,表示已醉 nonceStr:event.nonceStr,//第三个坑:官方文档中相关云函数代码没有nonceStr和tradeType,测试的时候会报nonceStr不存在的错,翻看文档才发现这个是必填项,直接粘过来以后还需要加上这两个参数 //tradeType:'JSAPI' }); return res; }; 支付函数代码: // 请求questionPay云函数,调用支付能力 _callQuestionPay(body, details,goodsnum, subMchId, payVal) { wx.cloud .callFunction({ name: 'questionPay', data: { // 需要将data里面的参数传给questionPay云函数 body, details, goodsnum, // 商品订单号不能重复 subMchId, // 子商户号,微信支付商户号,必填 payVal, // 这里必须整数,不能是小数,而且类型是number,否则就会报错 nonceStr:uuid(32, 32)//调用自己的uuid函数 不用也行 原来发现错在totalprice没值 }, }) .then((res) => { console.log(res);//商户支付受限 const payment = res.result.payment; console.log('payment:'+payment); // 里面包含appId,nonceStr,package,paySign,signType,timeStamp这些支付参数 wx.requestPayment({ // 根据获取到的参数调用支付 API 发起支付 ...payment, // 解构参数appId,nonceStr,package,paySign,signType,timeStamp success: (res) => { console.log('支付成功', res); wx.showToast({ title: '支付成功', success: () => console.log('success'), fail: () => console.log('failure'), }); this.creatOrder(goodsnum); }, fail: (err) => { console.error('支付失败', err); wx.showToast({ title: '支付失败', success: () => console.log('success'), fail: () => console.log('failure'), }); }, }); }) .catch((err) => { console.error(err); }); }, creatOrder(goodsnum){ //获取缓存中数据 let cart=wx.getStorageSync("cart")||[]; //过滤后购物车数组 cart=cart.filter(v=>v.checked); //把商品信息写进body var order_item=[]; for(let i=0;i<cart.length;i++){ order_item.push({ cloth_id:cart[i].cloth_id, cloth_price:cart[i].cloth_price, cloth_notes:cart[i].cloth_notes, num:cart[i].num }); } const address=wx.getStorageSync("curAddr"); const totalPrice=this.data.totalPrice; //获取当前时间戳 转换成北京时间 //console.log("after bejing: "+utc_beijing(app.globalData.serverDate)); let curBeijingTime = formatTime(new Date())//utc_beijing(app.globalData.serverDate); console.log("当前北京时间为:" + curBeijingTime); //写入数据库 const testDB = wx.cloud.database({ //env: 'test-3aahe' env: 'prod-dbtpz' }) testDB.collection('orders').add({ data: { _id:goodsnum, product:order_item, totalPrice:totalPrice, address:address, orderDate:curBeijingTime, status:'待发货', curName:this.data.curName, curId:this.data.curId }, success: function(res) { // res 是一个对象 console.log("订单添加成功") wx.showToast({ title: '订单提交成功,如有问题请联系客服', icon: 'none', duration: 3000, success: function () { setTimeout(function() { // wx.navigateTo({url: '../order/index?type=1',})//跳转到order页面要给个参数要不没order list wx.switchTab({url: '../user/index',}) }, 3000); } }); } }) wx.setStorageSync("cart",[]);//清空购物车 },
2024-11-22 - 云函数保存数据到excel报错?TypeError: Cannot read property '0
之前有另一个云函数整理数据库的文件,已打印验证之前那个云函数没问题,大概1300行10列左右的数据 现在这个excel云函数用来读然后存到excel里, 之后要上传到云存储 问题就是出现在excel云函数读完数据存不下来, 但不知道是数 报错: 11/08 23:00:07:821 [excel][1] ERROR RequestId: b5df872c-7e96-43f3-8b15-30a6078d380f Result: TypeError: Cannot read property '0' of undefined at exports.main (/var/user/index.js:39:49) at IncomingMessage.<anonymous> (/data/scf/frame/node12/runtime.js:246:26) at IncomingMessage.emit (events.js:323:22) at endReadableNT (_stream_readable.js:1204:12) at processTicksAndRejections (internal/process/task_queues.js:84:21) excel云函数代码: // 云函数入口文件 const cloud = require('wx-server-sdk') const moment = require("moment-timezone") cloud.init({ traceUser: true, env: cloud.DYNAMIC_CURRENT_ENV }) // 使用当前云环境 //操作excel用的类库 const xlsx = require('xlsx'); // 云函数入口函数 exports.main = async(event, context) => { let {userdata} = event // javascript date // console.log(new Date()); // 2021-03-16T08:04:07.441Z (UTC+0 // console.log(moment().tz("Asia/Shanghai").format()); // 2021-03-16T16:04:07+08:00 (UTC+8) let curDate = moment().tz("Asia/Shanghai").format('YYYYMMDDHHmmss'); //let curDate =new Date().toISOString() //1,定义excel表格名 let dataCVS = 'xiaofu101_order_list_'+curDate+'.xlsx' //2,定义存储数据的 let alldata = []; //let row = ['status','receiver']; //表属性 let row=['_id' , 'orderDate', 'region','address','receiver','phone' ,'SchoolName','cloth_id','cloth_notes','num','cloth_price','totalPrice','status'] alldata.push(row); console.log('excel before loop:'+alldata) let count = 0 for (let key in userdata) { for (let i in userdata[key]['product']){ let arr = []; arr.push(userdata[key]._id); arr.push(userdata[key].orderDate); arr.push(userdata[key]['address'].region[0]+'-' +userdata[key]['address'].region[1]+'-' +userdata[key]['address'].region[2]); arr.push(userdata[key]['address'].address); arr.push(userdata[key]['address'].receiver); arr.push(userdata[key]['address'].phone); arr.push(userdata[key].curSchoolName); arr.push(userdata[key]['product'][i].cloth_id); arr.push(userdata[key]['product'][i].cloth_notes); arr.push(userdata[key]['product'][i].cloth_price); arr.push(userdata[key]['product'][i].num); arr.push(userdata[key].totalPrice); arr.push(userdata[key].status); alldata.push(arr) } count += 1 console.log(count) } console.log('excel has data:'+alldata) //3,把数据保存到excel里 const buffer = xlsx.utils.book_new(); const worksheet = xlsx.utils.aoa_to_sheet(alldata); xlsx.utils.book_append_sheet(buffer, worksheet, 'mySheetName'); const excelBuffer = xlsx.write(buffer, { type: 'buffer' }); console.log('buffer has data : ', excelBuffer); //4,把excel文件保存到云存储里 console.log(dataCVS) return await cloud.uploadFile({ cloudPath: dataCVS, fileContent: excelBuffer, //excel二进制文件 }) } 这条语句没有执行打印出来, console.log('excel has data:'+alldata) console.log(count)打印出来了 说明错可能是在上面 alldata.push(arr) 但不知道是保存的数据类型造成的property '0' of undefined还是怎么回事, 请问怎么同时调式2个云函数,现在只能调式1个excel云函数,不能模拟传数据库数据的情况
2024-11-08 - 小程序 微信支付失败 查了下是订单详情长度越界 这个怎么办?
//把商品信息写进body var good_info=''; for(let i=0;i<cart.length;i++){ good_info+=cart[i].cloth_title+';'; } console.log(good_info) var good_details=''; for(let j=0;j<cart.length;j++){ good_details+=cart[j].cloth_id+' x '+cart[j].num+';'; } console.log(good_details); const body = good_info;//订单名称 const details = good_details;//订单详情 const inputSubmitVal = totalPrice * 100;//系统是用分开始计算 console.log(totalPrice); if (totalPrice>0) { const res=await showModal({content:"您确定要提交订单了吗?。"}); if (res.confirm) { //提交订单 this._callQuestionPay(body, details,goodsnum, subMchId, inputSubmitVal ); //if not wepay, use this.creatOrder(goodsnum); } } else { await showToast({title:"亲,没有商品,无法提交哦"}); } // 请求questionPay云函数,调用支付能力 _callQuestionPay(body, details,goodsnum, subMchId, payVal) { wx.cloud .callFunction({ name: 'questionPay', data: { // 需要将data里面的参数传给questionPay云函数 body, details, goodsnum, // 商品订单号不能重复 subMchId, // 子商户号,微信支付商户号,必填 payVal, // 这里必须整数,不能是小数,而且类型是number,否则就会报错 nonceStr:uuid(32, 32)//调用自己的uuid函数 不用也行 原来发现错在totalprice没值 }, }) .then((res) => { console.log(res);//商户支付受限 const payment = res.result.payment; console.log('payment:'+payment); // 里面包含appId,nonceStr,package,paySign,signType,timeStamp这些支付参数 wx.requestPayment({ // 根据获取到的参数调用支付 API 发起支付 ...payment, // 解构参数appId,nonceStr,package,paySign,signType,timeStamp success: (res) => { console.log('支付成功', res); wx.showToast({ title: '支付成功', success: () => console.log('success'), fail: () => console.log('failure'), }); this.creatOrder(goodsnum); }, fail: (err) => { console.error('支付失败', err); wx.showToast({ title: '支付失败', success: () => console.log('success'), fail: () => console.log('failure'), }); }, }); }) .catch((err) => { console.error(err); }); }, [图片] 貌似是这个details越界了 这个怎么能限制一下?
2023-10-19 - 请问云开发导出数据库失败 怎么办?
[图片] 这是什么原因 是因为是国外ip吗? 那人在国外维护国内小程序 那怎么才能导出?
2022-09-07 - 2年没用 push failed 远程推送github失败?同时开发工具更新出错无法更新
[图片] 2年没登了 远程push github 出问题,已经检查了 设置->网络和认证里的用户名密码是对的 [图片] 难道是版本问题?现在还有个问题开发工具下载的更新无法安装 [图片]
2022-09-06 - openSetting()的问题,我用了打不开设置?
关于为了避免用户取消“获取地址”之后无法再打开,我看教程说是用opensetting(). https://www.bilibili.com/video/BV1y7411z7hQ?p=85 但是代码一样还是没用。我用openSetting()怎么还打不开设置,不知道哪错了. 点取消授权,再点button, console确实输出我故意打印的“取消”了但并没有打开设置。 WXML: 获取收货地址 JS. handleChooseAddress(){ wx.getSetting({ success: (result) => { // console.log(result); const scopeAddress=result.authSetting["scope.address"]; if (scopeAddress===true||scopeAddress===undefined){ //console.log(result); wx.chooseAddress({ success: (result1) => { console.log(result1); } }); }else{ console.log("取消"); wx.openSetting({ success: (result2) => { wx.chooseAddress({ success: (result3) => { console.log(result3); } }); } }); } } }) } 另一种写法还是不对 : 报错:errMsg: "openSetting:fail errcode 1"} /* Promise形式 getSetting */ export const getSetting=()=>{ return new Promise((resolve,reject)=>{ wx.getSetting({ withSubscriptions: true, success: (result)=>{ resolve(result); }, fail:(err)=>{ reject(err); } }); }) } /* Promise形式 chooseAddress */ export const chooseAddress=()=>{ return new Promise((resolve,reject)=>{ wx.chooseAddress({ withSubscriptions: true, success: (result)=>{ resolve(result); }, fail:(err)=>{ reject(err); } }); }) } /* Promise形式 openSetting */ export const openSetting=()=>{ return new Promise((resolve,reject)=>{ wx.openSetting({ withSubscriptions: true, success: (result)=>{ resolve(result); }, fail:(err)=>{ reject(err); } }); }) } // pages/cart/index.js import{getSetting,chooseAddress,openSetting } from "../../utils/asyncWx.js"; import regeneratorRuntime from '../../lib/runtime/runtime'; Page({ /** * 页面的初始数据 */ data: { }, async handleChooseAddress(){ try { /* wx.getSetting({ success: (result) => { // console.log(result); const scopeAddress=result.authSetting["scope.address"]; if (scopeAddress===true||scopeAddress===undefined){ //console.log(result); wx.chooseAddress({ success: (result1) => { console.log(result1); } }); }else{ console.log("取消"); wx.openSetting({ success: (result2) => { wx.chooseAddress({ success: (result3) => { console.log(result3); } }); } }); } }, fail:()=>{}, complete:()=>{} }); */ const res1=await getSetting(); const scopeAddress=res1.authSetting["scope.address"]; if (scopeAddress===false){ await openSetting(); } const res2=await chooseAddress(); console.log(res2); } catch (error) { console.log(error); } } })
2020-07-27