小程序开发记录贴(陕西挂测)五-执行流程记录js
- 内容
- 评论
- 相关
前面我们说到了小程序的登陆以及数据的获取,现在我们开始解说下程序的执行流程问题,重点js的循环取值与赋值,以及后台回执信息错误与正确的判断。前端重点主要判断显示效果,运用了wx:if以及取余数和取商的结果来判断,当返回结果正确则显示正常绿色不然直接显示红色异常。
具体js代码:
// pages/index/indexnew/start/start.js var app = getApp(), Util = require('../../../../utils/util.js') Page({ /** * 页面的初始数据 */ data: { isfald: "", sheet: "", woId: "", projectId: "", outInfo: [], intInfo: [] }, /** * 生命周期函数--监听页面加载 */ onLoad: function(options) { var that = this that.onHanging(options) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function() { wx.setNavigationBarTitle({ title: "挂侧结果详细信息" }) }, /** * 挂测开始启动 */ onHanging: function(data) { var that = this that.data.woId = data.woId that.data.projectId = data.projectId const url = '/diagnosis/diagnosis.do' //换成自己的后台地址 var data = { woId: that.data.woId, } Util.sendRequest(url, data, 'post', "正在载入..").then(data => { if (data.data.succFlag != 0) { that.setData({ heinfo: '系统正常,流程启动.', error: 'normal' }) that.data.sheet = data.data.sheetNo var sheet = that.data.sheet that.process(true, data, sheet); } else { that.setData({ heinfo: '系统异常,流程启动失败!', error: 'error', showProcess: true }) } }) }, /** * 判断错误抛出runFactor流程执行 */ process: function(isFirst, resdata, sheetNo) { var that = this if (resdata.data.detectType === 3) { var len = resdata.data.actFactors.length for (var i = 0; i < len; i++) { (function(resdata, i) { var factor = resdata.data.actFactors[i]; const url = '/diagnosis/runFactor.do' var data = { 'sheetNo': sheetNo, 'repoId': resdata.data.repoId, 'factorConfId': factor.factorConfId, 'refresh': false } Util.sendRequest(url, data, 'post', "").then(resultMap => { if (resultMap.data.succFlag == 0) { if (that.data.isfald == 1) { that.data.intInfo.push("分支判断因子出现异常!") that.setData({ intInfo: that.data.intInfo }) } else { that.data.outInfo.push("分支判断因子出现异常!") that.setData({ outInfo: that.data.outInfo }) } } len--; if (len == 0) { that.flownext(sheetNo) } }) })(resdata, i); } } else if (resdata.data.detectType === 1) { that.data.outInfo.push(resdata.data.actName) that.setData({ outInfo: that.data.outInfo, }) wx.hideLoading() } else { var len = resdata.data.actFactors.length; for (var i = 0; i < len; i++) { (function(resdata, i) { const url = '/diagnosis/runFactor.do' var factor = resdata.data.actFactors[i]; var data = { 'sheetNo': sheetNo, 'repoId': resdata.data.repoId, 'factorConfId': factor.factorConfId, 'refresh': false } Util.sendRequest(url, data, 'POST', "").then(resultMap => { if (resultMap.data.succFlag == 0) { statusdesc = "异常" if (that.data.isfald == 1) { that.data.intInfo.push(resultMap.data.diagResult) that.data.intInfo.push(statusdesc) that.setData({ intInfo: that.data.intInfo }) } else { that.data.outInfo.push(resultMap.data.diagResult) that.data.outInfo.push(statusdesc) that.setData({ outInfo: that.data.outInfo }) } } else { var statusdesc = '' if (resultMap.data.errFlag == '0') { statusdesc = '异常'; if (that.data.isfald == 1) { that.data.intInfo.push(resultMap.data.diagResult) that.data.intInfo.push(statusdesc) that.setData({ intInfo: that.data.intInfo }) } else { that.data.outInfo.push(resultMap.data.diagResult) that.data.outInfo.push(statusdesc) that.setData({ outInfo: that.data.outInfo }) } } else if (resultMap.data.errFlag == '1') { statusdesc = '正常'; if (that.data.isfald == 1) { that.data.intInfo.push(resultMap.data.diagResult) that.data.intInfo.push(statusdesc) that.setData({ intInfo: that.data.intInfo }) } else { that.data.outInfo.push(resultMap.data.diagResult) that.data.outInfo.push(statusdesc) that.setData({ outInfo: that.data.outInfo }) } } else if (resultMap.data.errFlag == '2') { statusdesc = '接口失败'; if (that.data.isfald == 1) { that.data.intInfo.push(resultMap.data.diagResult) that.data.intInfo.push(statusdesc) that.setData({ intInfo: that.data.intInfo }) } else { that.data.outInfo.push(resultMap.data.diagResult) that.data.outInfo.push(statusdesc) that.setData({ outInfo: that.data.outInfo }) } } } len--; if (len == 0) { that.flownext(sheetNo) } }) })(resdata, i); } } }, /** * 判断错误抛出runFactor流程执行 */ flownext: function(sheetNo) { var that = this let cookie = app.serData.cookie const url = '/diagnosis/flowNextDeal.do' //换成自己的后台地址 var data = { sheetNo: sheetNo, } Util.sendRequest(url, data, 'POST', "").then(res => { if (res.data.succFlag == 0) { return; } if (res.data.finishFlag == 'finish') { that.data.isfald = "" if (res.data.testResult == 0) { that.setData({ showProcess: true }) } else if (res.data.testResult == 1) { that.setData({ showFeedback: true }) } that.setData({ intInfo: that.data.intInfo, }) that.pageScrollToBottom() wx.hideLoading() } else { that.process(false, res, sheetNo); } }) }, /** * 继续挂测被点击 */ toastShow: function() { wx.showLoading({ title: "正在载入..", }) var that = this, sheet = that.data.sheet that.data.isfald = 1 setTimeout(function() { //自动延迟3秒 that.flownext(sheet) }, 3000); }, /** * 重新挂测 */ reprocess: function() { wx.navigateBack({ delta: 1 }) }, /** * 跳转到页面最底部 */ pageScrollToBottom: function() { wx.createSelectorQuery().select('.page__bd').boundingClientRect(function(rect) { // 使页面滚动到底部 wx.pageScrollTo({ scrollTop: rect.bottom }) }).exec() }, /** *更新首页数据 */ updateFpage: function() { var pages = getCurrentPages(); if (pages.length > 1) { var beforePage = pages[pages.length - 3]; //获取上一个页面实例对象 beforePage.changeData(); //触发父页面中的方法 } }, /** * 挂侧完成回单 */ feedback: function() { var that = this, woId = that.data.woId, projectId = that.data.projectId that.updateFpage() const url = '/diagnosis/feedback.do' var data = { 'woId': woId, 'projectIds': projectId } Util.sendRequest(url, data, 'POST', "").then(res => { if (res.data.succFlag == 0) { wx.showModal({ title: '系统提示', content: '系统异常,回单失败!', showCancel: false, confirmColor: "#FF0000", //确定文字的颜色 success: function(resmal) { if (resmal.confirm) { wx.navigateBack({ delta: 2 }) } } }) } else { that.qfeedback(woId) //确认审核 } }) }, /** * 确认审核 */ qfeedback: function(woid) { var that = this const url = '/gcgc/feedback.do' var data = { 'woId': woid, } Util.sendRequest(url, data, 'POST', "").then(res => { if (res.data == "success") { const url = '/gcgc/gcgcProjectPass.do' //换成自己的后台地址 var data = { 'woId': woid, } Util.sendRequest(url, data, 'POST', "").then(res => { wx.showModal({ title: '系统提示', content: '1、系统回单\r\n 2、确认审核成功!!', showCancel: false, confirmColor: "#FF0000", //确定文字的颜色 success: function(resmal) { wx.navigateBack({ delta: 2 }) } }) }) } }) }, })
前端wxml代码:
挂测信息 {{heinfo}} {{outInfo[idx]}} {{outInfo[idx]}} {{intInfo[id]}} {{intInfo[id]}}
- 标签:
- 小程序
正文到此结束
版权声明:本文中使用的部分内容来自于网络,如有侵权,请联系《博主》进行删除
LEAVE A REPLY