const app = require('../../utils/util.js'); Page({ data: { texts: "至少需要2个字", min: 2, //最少字数 max: 200, //最多字数 (根据自己需求改变) currentWordNumber: 0, value: '' }, //字数限制 inputs: function (e) { // 获取输入框的内容 var value = e.detail.value; this.setData({ value: e.detail.value }) // 获取输入框内容的长度 var len = parseInt(value.length); console.log(len) //最少字数限制 if (len <= this.data.min) this.setData({ texts: "至少还需要", textss: "字", num: this.data.min - len }) else if (len > this.data.min) this.setData({ texts: " ", textss: " ", num: '' }) this.setData({ currentWordNumber: len //当前字数 }); //最多字数限制 if (len > this.data.max) return; // 当输入框内容的长度大于最大长度限制(max)时,终止setData()的执行 console.log(this.data) }, submit() { var test = this.data.value; if (test.match(/^\s+$/) || test.match(/^[ ]+$/) || test.match(/^[ ]*$/) || test.match(/^\s*$/)) { console.log("反馈为空") wx.showToast({ title: '反馈不能为空哦', icon: 'none', duration: 3000, }); return; } // if (test.match(/^[ ]+$/)) { // console.log("all space") // return; // } // if (test.match(/^[ ]*$/)) { // console.log("all space or empty") // return; // } // if (test.match(/^\s*$/)) { // console.log("all space or \\n or empty") // return; // } // if (this.data.value) { wx.request({ url: app.globalData.publicUrl + '/feedback/add', method: "POST", data: { appletsId: wx.getStorageSync('openId'), content: this.data.value }, success: res => { console.log(res, '我提交成功了') this.setData({ value: '' }) wx.showToast({ title: '感谢您的反馈,我们会认真处理问题并尽快完善相关功能!', icon: 'none', duration: 3000, }); setTimeout(function () { wx.switchTab({ url: '../../pages/personInfo/personInfo' }); }, 3000) } }); // } else { // wx.showToast({ // title: '反馈不能为空哦', // icon: 'none', // duration: 3000, // }); // } }, })