- 一个form表单突然不能点击提交了,但手机预览又可以?
一个页面的form表单,之前还好好的,填加了一些内容后,突然点击提交按钮不起作用了,也不报错,就是点击提交按钮没有任何反应,将整个formSumbit()注释点,从新写一个最简单formSumbit()就是console一下提交内容,依然没有反应。一开始我以为是页面哪里错了,反复了看了反复编译执行,系统也没有报错,也没有错,就是点击提交按钮,没有任何反应。 但是最奇怪的是,不管是手机预览,还是真机调试,在手机上点击提交按钮都能正常提交,这是为什么呢?如果开发真工具点击没有反应,为什么手机预览又可以正常运行,这样我在电脑上就没法调试了! 请各位老师指点!!谢谢! 不好意思,没有上代码,我把全部这个页面的代码上传如下,请老师指点: // pages/dangchu/dangchu.js import WxValidate from '../../utils/WxValidate.js'; const db = wx.cloud.database() Page({ /** * 页面的初始数据 */ data: { punishment_date: '2022-01-01', date: { year: '', month: '', day: '' }, certificateID1: '', certificateID2: '', // 模糊查询时长 timer: 0, // 点击结果项之后替换到文本框的值 inputValue: '', // 是否隐藏模糊查询的面板 hideScroll: true, // 模糊查询结果 searchTip: [] }, onInput(e) { const inputValue = e.detail.value clearTimeout(this.data.timer) let timer = setTimeout(() => { if (inputValue) { // 如果输入的关键字不为空,则发起请求获取联想值 var that = this; //这句不能少,在查询时 const legalTerms = db.collection('legalTerms').where({ behavior:{ $regex:'.*'+ inputValue, $options: 'i' } }).get({ success(res) { console.log('查询成功', res.data); //将查询返回的结果赋值给本地变量 that.setData({ searchTip: res.data, inputValue: inputValue, hideScroll: false }) console.log('查询成功', that.data.searchTip); }, fail: err => { console.log('失败') } }) } // 如果为空,则收起 this.setData({ searchTip: [], hideScroll: true, // inputValue: '' }) }, 600) this.data.timer = timer }, itemtap(e) { const { info } = e.currentTarget.dataset console.log('选择的ID是',info) this.setData({ // 将点击选择的值展示在input框中 inputValue: info.behavior, illegalLawName: info.illegalLawName, illegalTitle: info.illegalTitle, punishLawName: info.punishLawName, punishTitle: info.punishTitle, // 当用户选择某个联想词,隐藏下拉列表 hideScroll: true }) }, showToast(error) { wx.showToast({ title: error.msg, icon: 'none' }) }, initValidate() { const rules = { officers_name1: { required: true }, officers_name2: { required: true, }, document_number: { required: true, }, } const messages = { officers_name1: { required: '请输入执法人员姓名', }, officers_name2: { required: '请输入执法人员姓名', }, document_number: { required: '请输入文书编号', }, // boxType: { // required: '请选择箱型', // }, // boxCount: { // required: '请输入发单数量', // intType: '发单数量请输入10以内' // }, // weight: { // required: '请输入箱重', // weight: '箱重请填写100以内整数或两位小数' // }, // store: { // required: '请输入门点地址', // }, // harbour: { // required: '请输入港区', // }, // freight: { // required: '请输入运费金额', // money: '请输入正确的金额' // }, // freshInterval: { // required: '请选择重发间隔', // }, // linkman: { // required: '请选择联系人', } this.WxValidate = new WxValidate(rules, messages) }, bindDateChange: function (e) { console.log('picker发送选择改变,携带值为', e.detail) this.setData({ punishment_date: e.detail.value }) }, // formSubmit(e) { // console.log('form发生了submit事件,携带数据为:', e.detail.value) // }, formSubmit(e) { var that = this console.log('form发生了submit事件,携带数据为:', e.detail.value) const params = e.detail.value // 校验表单 if (!this.WxValidate.checkForm(params)) { console.log(this.WxValidate.errorList[0]) const error = this.WxValidate.errorList[0] this.showToast(error) return false } var date = new Date(e.detail.value.punishment_date) var year = date.getFullYear() var month = date.getMonth()+1 var day = date.getDate() this.setData({ date: { year: year, month: month, day: day } }) const certificate1 = db.collection('certificate').where({ name: e.detail.value.officers_name1 }) .get().then(res=>{ this.setData({ certificateID1: res.data[0].certificateID }) console.log('当前数据库返回的是:',res.data[0].certificateID) const certificate2 = db.collection('certificate').where({ name: e.detail.value.officers_name2 }) .get().then(res=>{ this.setData({ certificateID2: res.data[0].certificateID }) console.log('当前数据库返回的是:',res.data[0].certificateID) wx.setStorageSync('dangchu_result',{ business_address: e.detail.value.business_address, enterprise_name: e.detail.value.enterprise_name, idCardNO: e.detail.value.idCardNO, person_name: e.detail.value.person_name, punishment_address: e.detail.value.punishment_address, reg_num: e.detail.value.reg_num, telNO: e.detail.value.telNO, officers_name1: e.detail.value.officers_name1, officers_name2: e.detail.value.officers_name2, illegal_behavior: e.detail.value.illegal_behavior, document_number: e.detail.value.document_number, punishment_day: that.data.date.day, punishment_month: that.data.date.month, punishment_year: that.data.date.year, certificateID1: that.data.certificateID1, certificateID2: that.data.certificateID2, illegalLawName: that.data.illegalLawName, illegalTitle: that.data.illegalTitle, punishLawName: that.data.punishLawName, punishTitle: that.data.punishTitle, }) wx.navigateTo({ url: '../handWrite/handWrite', }) }) .catch(res=>{ // 处理执法人员2输入错误 console.log('发生错误!', res), wx.showToast({ title: '输入的执法人员2不存在', icon: 'none' }) }) }) .catch(res=>{ // 处理执法人员1输入错误 console.log('发生错误!', res), wx.showToast({ title: '输入的执法人员1不存在', icon: 'none' }) }) }, getStorage(){ // var that=this var business= wx.getStorageSync('business') var idCard= wx.getStorageSync('idCard') this.setData({ enterprise_name: business.enterprise_name, reg_num: business.reg_num, business_address: business.business_address, person_name: business.person_name, idCardNO: idCard.idCardNO, }) }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { this.initValidate() }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { this.getStorage() }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { } }) <!--pages/dangchu/dangchu.wxml--> <form bindsubmit="formSubmit" bindreset="formReset"> <view class="chapter"> <view class="chapter__title">当事人基本信息</view> <view class="section"> <view class="section__title">请输入当事人名称</view> <input class="ordinaryInput" name="enterprise_name" focus="true" value="{{enterprise_name}}"/> </view> <view class="section"> <view class="section__title">请输入统一社会信用代码</view> <input class="ordinaryInput" name="reg_num" value="{{reg_num}}"/> </view> <view class="section"> <view class="section__title">请输入住所地址</view> <input class="ordinaryInput" name="business_address" value="{{business_address}}"/> </view> <view class="section"> <view class="section__title">请输入法定代表人姓名</view> <input class="ordinaryInput" name="person_name" value="{{person_name}}"/> </view> <view class="section"> <view class="section__title">请输入法人身份证号</view> <input class="ordinaryInput" name="idCardNO" type="idcard" value="{{idCardNO}}"/> </view> <view class="section"> <view class="section__title">请输入法人联系电话</view> <input class="ordinaryInput" name="telNO" type="number"/> </view> </view> <view class="chapter"> <view class="chapter__title">处罚基本信息</view> <view class="section"> <view class="section__title">请输入文书编号</view> <input class="ordinaryInput" name="document_number" type="number"/> </view> <view class="section_two"> <view class="section__title">请输入执法人员姓名</view> <view class="twoInputBox"> <input class="twoInput" name="officers_name1" /> <input class="twoInput" name="officers_name2" /> </view> </view> <view class="section" style="clear: both;"> <view class="section__title">请输入处罚地点</view> <input class="ordinaryInput" name="punishment_address" value="{{business_address}}"/> </view> <view class="section"> <view class="section__title">请选择当前日期</view> <picker name="punishment_date" mode="date" start="2015-09-01" end="2025-12-01" bindchange="bindDateChange"> <view class="picker"> {{punishment_date}} <view class='arrow'></view> </view> </picker> </view> <view class="section"> <view class="section__title">请输入违法行为</view> <input class="ordinaryInput" name="illegal_behavior" value="{{inputValue}}" focus='true' confirm-type="search" placeholder="请输入违法行为的主要关键字" bindinput="onInput" /> <view class="line"></view> <scroll-view scroll-y="true" class="search-res" hidden="{{hideScroll}}"> <view class="sum">共找到和“{{inputValue}}”相关的结果{{searchTip.length}}个</view> <block wx:for="{{searchTip}}" wx:key="_id"> <view class="tip-item" bindtap="itemtap" data-info="{{item}}"> <view class="left"> <view class="tip"> <view>{{item.illegalLawName}}</view> <view>{{item.illegalTitle}}</view> </view> <view class="content"> {{item.illegalContent}} </view> </view> </view> </block> </scroll-view> </view> </view> <button formType="submit" class="End_button" type="primary">提交</button> </form> <view class="line"></view>
2022-01-16 - 云函数中调用fs.readFileSync的问题?
我在云函数中调用fs.readFileSync想读取一个在云存储中的文件,但是发现fs.readFileSync好像只能读取在云函数文件夹中的文件,不能读取在云存储中的文件,但是我查询了fs.readFileSync官方文档,里面说路径可以是URL,我尝试了各种方法传入URL,要么提示“TypeError [ERR_INVALID_URL_SCHEME]: The URL must be of scheme file”,或者“Error: ENOENT: no such file or directory, open 'https://7778-wxmltodocx-9gnoh53l4e4377ca-1309024106.tcb.qcloud.la/20220112/74gf2CAw6dBH8Kn4kSGswuQw1UPLYPCR.docx'”,代码如下,请各位高手老师指点!!!感谢!!!! const cloud = require('wx-server-sdk') const { createReport } = require('docx-templates') const fs = require('fs') const path = require('path') const dayjs = require('dayjs') const url = require('url') cloud.init({ env: 'wxmltodocx-9gnoh53l4e4377ca' }) // 云函数入口函数 exports.main = async (event, context) => { console.log(event) //读取本地传入的云函数ID,并将其转换成一个临时的URL const fileList = [event.downloadFileID] const result = await cloud.getTempFileURL({ fileList: fileList, }) console.log('换取临时文件网络地址是:',result.fileList[0].tempFileURL) const myURL = new URL(result.fileList[0].tempFileURL) console.log('转换后的文件网络地址是:',myURL) const myPath = myURL.toString() const template = fs.readFileSync(myPath)//读取文件 执行到这一步就反复出错了。 请各位老师指点。谢谢!
2022-01-12 - cloud.uploadFile()始终失败?
照搬照抄云开发文档里的示例,运行后始终失败,一直都是返回如下错误代码 [error] 函数执行失败(耗时 178ms) TypeErruploadFile:fail or: uploadFile:fail Cannot read property 'url' of undefined ??急人,请老师指点 // 云函数入口文件 const cloud = require('wx-server-sdk') const { createReport } = require('docx-templates') const fs = require('fs') const path = require('path') // const dayjs = require('dayjs') cloud.init({ env: 'cloud.DYNAMIC_CURRENT_ENV' }) // 云函数入口函数 exports.main = async (event, context) => { const fileStream = fs.createReadStream(path.join(__dirname, 'verify_company.docx')) return await cloud.uploadFile({ cloudPath: 'verify_company.docx', fileContent: fileStream, }) }
2022-01-07 - 云函数使用cloud.uploadFile时出错,怎么解决?
云函数在return使用cloud.uploadFile,准备把生成的文件上传到云存储,但是始终提示Error: errCode: -404011 cloud function execution error | errMsg: cloud.callFunction:fail requestID 195ed62a-6ec9-11ec-b78e-5254005a5a71, cloud function service error code -504002, error message TypeErruploadFile:fail or: uploadFile:fail Cannot read property 'url' of undefined。 源代码如下: 云函数index.js // 云函数入口文件 const cloud = require('wx-server-sdk') const { createReport } = require('docx-templates') const fs = require('fs'); const path = require('path') // const dayjs = require('dayjs') cloud.init({ env: 'cloud.DYNAMIC_CURRENT_ENV' }) // 云函数入口函数 exports.main = async (event, context) => { const template = fs.readFileSync(path.join(__dirname, 'verify_company.docx'))//读取文件 const buffer = await createReport({ template, data: { //变量 no: '123', creator: 'Appleseed', }, cmdDelimiter: ['{', '}']//以{}作为变量分隔符 }) const dayjs = require('dayjs'); const preDir = dayjs().format("YY/MM/DD");//日期 const stringRandom = require('string-random') const randfilename = stringRandom(32)//随机文件名 const cloudPath = `${preDir}${randfilename}.docx`//文件 return await cloud.uploadFile({ cloudPath, fileContent: Buffer.from(buffer, 'hex') }) } 考虑到可能是cloudPath的路径的问题,所以把上面cloudPath的修改成了如下: const cloudPath = `7778-wxmltodocx-9gnoh53l4e4377ca-1309024106/test/${preDir}${randfilename}.docx`//文件 上面的7778-wxmltodocx-9gnoh53l4e4377ca-1309024106/test/为我的云存储的路径。 [图片] 但是各种调试都不能解决,系统提示的问题依然一样,请各位老师指点,感谢! 1月7日经老师指点,将cloudPath修改为了固定值,代码如下: // const dayjs = require('dayjs'); // const preDir = dayjs().format("YY/MM/DD");//日期 // const stringRandom = require('string-random') // const randfilename = stringRandom(32)//随机文件名 // // const cloudPath = `7778-wxmltodocx-9gnoh53l4e4377ca-1309024106/test/${preDir}${randfilename}.docx`//文件 // const cloudPath = preDir+randfilename+'.docx'//文件 //上面这一段代码都注释了不用,直接指定一个导出的文件名。 return await cloud.uploadFile({ cloudPath: 'test1.docx', fileContent: Buffer.from(buffer, 'hex') }) 但是依然报的是同样的错误问题,还请各位老师指点!感谢!!!!
2022-01-06 - 调用云函数显示-404011 cloud function execution error?
在调用云函数时显示Error: errCode: -404011 cloud function execution error | errMsg: cloud.callFunction:fail requestID 5269cea3-6ea2-11ec-922d-525400868f7d, cloud function service error code -504002, error message Runtime.ImportModuleError: Error: Cannot find module 'docxtemplates' Require stack: - /var/user/index.js - /var/runtime/node12/UserFunction.js - /var/runtime/node12/Runtime.engine.js - /var/runtime/node12/bootstrap.js at Object.module.exports.load (:39520/var/runtime/node12/UserFunction.js:34) at Runtime.handleOnce (:39520/var/runtime/node12/Runtime.engine.js:99) at Timeout._onTimeout (:39520/var/runtime/node12/Runtime.engine.js:56) at listOnTimeout (:39520/appservice/internal/timers.js:549) at processTimers (:39520/appservice/internal/timers.js:492); at cloud.callFunction api; at new t (WASubContext.js?t=wechat&s=1641432266952&v=2.14.1:17) at u (WASubContext.js?t=wechat&s=1641432266952&v=2.14.1:17) at l (WASubContext.js?t=wechat&s=1641432266952&v=2.14.1:17) at Function.success (WASubContext.js?t=wechat&s=1641432266952&v=2.14.1:17) at d (WASubContext.js?t=wechat&s=1641432266952&v=2.14.1:2) at WASubContext.js?t=wechat&s=1641432266952&v=2.14.1:2 at f (WASubContext.js?t=wechat&s=1641432266952&v=2.14.1:26) at Function.<anonymous> (WASubContext.js?t=wechat&s=1641432266952&v=2.14.1:26) at d (WASubContext.js?t=wechat&s=1641432266952&v=2.14.1:2) at WASubContext.js?t=wechat&s=1641432266952&v=2.14.1:2(env: Windows,mp,1.05.2111300; lib: 2.14.1) 云函数的入口文件和本地的JS应该都没有问题,云函数环境也输入了的,就是解决不了?请各位指点哈,感谢! 附代码如下: 云函数: / 云函数入口文件 const cloud = require('wx-server-sdk') const { createReport } = require('docxtemplates') const fs = require('fs'); const path = require('path') cloud.init({ env: 'cloud.DYNAMIC_CURRENT_ENV' }) // 云函数入口函数 exports.main = async (event, context) => { const template = fs.readFileSync(path.join(__dirname, 'verify_company.docx'))//读取文件 const buffer = await createReport({ template, data: { //变量 no: '123', creator: 'Appleseed', }, cmdDelimiter: ['{', '}']//以{}作为变量分隔符 }) const dayjs = require('../../extend/dayjs'); const preDir = dayjs().format("YY/MM/DD");//日期 const stringRandom = require('string-random') const randfilename = stringRandom(32)//随机文件名 const cloudPath = `verify/docx/${preDir}/${randfilename}.docx`//文件 return await cloud.uploadFile({ cloudPath, fileContent: Buffer.from(buffer, 'hex') }) } 本地的调用页面js文件: testdocx(){ wx.cloud.callFunction({ // 云函数名称 name: 'testdocx', // 传给云函数的参数 data: { }, }) .then(res => { console.log(res.result) }) .catch(console.error) }, 本地的app.js文件 App({ onLaunch: function () { if (!wx.cloud) { console.error('请使用 2.2.3 或以上的基础库以使用云能力'); } else { wx.cloud.init({ // env 参数说明: // env 参数决定接下来小程序发起的云开发调用(wx.cloud.xxx)会默认请求到哪个云环境的资源 // 此处请填入环境 ID, 环境 ID 可打开云控制台查看 // 如不填则使用默认环境(第一个创建的环境) env: 'wxmltodocx-9gnoh53l4e4377ca', traceUser: true, }); } this.globalData = {}; } });
2022-01-06