var app = getApp(); var util = require('../../utils/util.js'); var md5 = require('../../utils/md5.js'); var crc16 = require('../../utils/crc16.js') var datagram = require('../../utils/datagramHelp'); const datagramHelp = require('../../utils/datagramHelp'); Page({ /** * 页面的初始数据 */ data: { openid: null, wxCode: null, timeoutID: null, hiddenLogin: true, hiddenIndex: true, user: '', password: '', blockColors: ["#B0CC99", "#677E52", "#B7CA79", "#89725B", "#354242", "#ACEBAE", "#C9DE55", "#7D9100", "#10222B", "#95AB63", "#BDD684", "#36362C", "#5D917D", "#A8AD80", "#E6D4A7", "#825534", "#588C7E", "#F2AE72", "#D96459", "#8C4646", "#D6655A", "#DC9C76", "#D6CCAD", "#74A588", "#42282F", "#302B1D", "#3F522B", "#737D26", "#A99E46", "#D9CB84", "#AF7575", "#3D9CA8"], rtuBlockColor: "#4a4266", projectBlockColor: "#ffa400", blueboothBlockColor: "#75664d", projectImplementionBlockColor: "#75664d", checkBlockColor: "#AF7575", mapNavBlockColor: "#D96459", helpBlockColor: "#ae7000", rtuBlockTouchStyle: "1", projectBlockTouchStyle: "1", blueboothBlockTouchStyle: "1", projectImplementionBlockTouchStyle: "1", checkReportBlockTouchStyle: "1", mapNavBlockTouchStyle: "1", helpBlockTouchStyle: "1", hiddenFooter: false, rememberLoginInfoChecked: false }, onLoad: function (options) { // load var that = this; var tmpColors = [] var colorCount = 0; var s = 1; var e = this.data.blockColors.length; while (true) { if (colorCount >= 7) { break; } var num = Math.floor(Math.random() * (s - e) + e) - 1; if (colorCount == 0) { tmpColors[colorCount] = num; colorCount += 1; } else { if (num != tmpColors[colorCount - 1]) { tmpColors[colorCount] = num; colorCount += 1; } } } wx.setNavigationBarColor({ frontColor: '#000000', backgroundColor: '#ffffff', }) this.setData({ rtuBlockColor: this.data.blockColors[tmpColors[0]], projectBlockColor: this.data.blockColors[tmpColors[1]], blueboothBlockColor: this.data.blockColors[tmpColors[2]], projectImplementionBlockColor: this.data.blockColors[tmpColors[3]], checkBlockColor: this.data.blockColors[tmpColors[4]], mapNavBlockColor: this.data.blockColors[tmpColors[5]], helpBlockColor: this.data.blockColors[tmpColors[6]] }) //帐号密码 const loginId = wx.getStorageSync('user_login_id'); const pw = wx.getStorageSync('user_login_pw'); if (loginId != null && loginId.length > 0 && pw != null && pw.length > 0) { this.setData({ user: loginId, password: pw, rememberLoginInfoChecked: true }) } wx.checkSession({ success: function () { console.debug("already login"); try { var openid = wx.getStorageSync('openid'); if (openid == null || openid == undefined || openid == "") { that.setData({ hiddenLogin: false, hiddenIndex: true, hiddenFooter: true }) // wx.removeStorageSync("user_token"); wx.removeStorageSync("openid"); that.loginToWx(); } else { that.setData({ hiddenLogin: true, hiddenIndex: false, hiddenFooter: false }) } } catch (e) { console.log(e); wx.showToast({ title: '系统异常错误', icon: 'loading', duration: 2000 }) } }, fail: function () { console.log("go login"); that.setData({ hiddenLogin: false, hiddenIndex: true, hiddenFooter: true }) // wx.removeStorageSync("user_token"); wx.removeStorageSync("openid"); that.loginToWx(); } }) }, onUnload: function () { }, onReady: function () { }, onShow: function () { }, /** * 微信授权登录 */ loginToWx: function () { var that = this; wx.login({ success: function (res) { console.debug("wx.login success " + res.code); if (res.code) { console.log('wx.login get code ' + res.errMsg) that.setData({ wxCode: res.code }) } else { console.log('wx.login code is null ' + res.errMsg) } }, fail: function (res) { console.log('fail' + res.errMsg) } }) }, /** * 登录泰山系统 * @param {*} code */ loginToTaishan: function () { var that = this; if (this.data.wxCode == null) { wx.showToast({ title: '系统错误', icon: 'loading', duration: 2000 }) return; } if (this.data.user.length == 0 || this.data.password.length == 0) { wx.showToast({ title: '请检查帐号密码', icon: 'loading', duration: 2000 }) } else { // 这里修改成跳转的页面 // wx.showToast({ // title: '登录成功', // icon: 'success', // duration: 2000 // }) wx.request({ url: app.globalData.cloudBase + "/Wx/Login?code=" + this.data.wxCode + "&user=" + this.data.user + "&password=" + md5.hexMD5(this.data.password), method: 'GET', header: { "Content-Type": "json" }, success: function (res) { // console.debug("login " + res.data); if (res.data.code === "0") { try { if (that.data.rememberLoginInfoChecked) { wx.setStorageSync('user_login_id', that.data.user); wx.setStorageSync('user_login_pw', that.data.password); } else { wx.setStorageSync('user_login_id', ''); wx.setStorageSync('user_login_pw', ''); that.setData({ rememberLoginInfoChecked: false, user: '', password: '' }) } wx.setStorageSync('openid', res.data.openId); //wx.setStorageSync('user_token', res.data.sessionKey); that.setData({ hiddenLogin: true, hiddenIndex: false, hiddenFooter: false }) } catch (e) { console.log(e); } } else { wx.showToast({ title: res.data.msg, // icon: 'fail', duration: 2000 }) } }, fail: function (res) { console.log("login fail" + res); } }) } }, jump: function () { }, toMenu: function (e) { var menuId = e.currentTarget.dataset.menuid; if (menuId == '1') { wx.navigateTo({ url: '/pages/index/index', }) } else if (menuId == '2') { wx.navigateTo({ url: '/pages/project/project', }) } else if (menuId == '3') { wx.navigateTo({ url: '/pages/bluetooth/bluetooth', //url:'/pages/bluetooth/baseSetting/bluetoothBaseSetting', }) } else if (menuId == '4') { wx.navigateTo({ url: '/pages/report/report', }) } else if (menuId == '5') { // wx.navigateTo({ // url: '/pages/deviceCheck/deviceCheckList', // }) } else if (menuId == '6') { wx.navigateTo({ url: '/pages/rtu/projectSelectView?model=2' }); } else if (menuId == '7') { wx.navigateTo({ url: '/pages/help/help', }) } // else if (menuId == '7') { // wx.navigateTo({ // url: '/pages/sign/sign', // }) // } }, menuTouchDown: function (e) { var opacity = 0.6; var menuId = e.currentTarget.dataset.menuid; if (menuId == '1') { this.setData({ rtuBlockTouchStyle: opacity }) } else if (menuId == '2') { this.setData({ projectBlockTouchStyle: opacity }) } else if (menuId == '3') { this.setData({ bluebootBlockTouchStyle: opacity }) } else if (menuId == '4') { this.setData({ projectImplementionBlockTouchStyle: opacity }) } else if (menuId == '5') { this.setData({ checkReportBlockTouchStyle: opacity }) } else if (menuId == '6') { this.setData({ mapNavBlockTouchStyle: opacity }) } else if (menuId == '7') { this.setData({ helpBlockTouchStyle: opacity }) } }, menuTouchUp: function (e) { var menuId = e.currentTarget.dataset.menuid; if (menuId == '1') { this.setData({ rtuBlockTouchStyle: 1 }) } else if (menuId == '2') { this.setData({ projectBlockTouchStyle: 1 }) } else if (menuId == '3') { this.setData({ bluebootBlockTouchStyle: 1 }) } else if (menuId == '4') { this.setData({ projectImplementionBlockTouchStyle: 1 }) } else if (menuId == '5') { this.setData({ checkReportBlockTouchStyle: 1 }) } else if (menuId == '6') { this.setData({ mapNavBlockTouchStyle: 1 }) } else if (menuId == '7') { this.setData({ helpBlockTouchStyle: 1 }) } }, logout: function (e) { this.setData({ hiddenLogin: false, hiddenIndex: true, hiddenFooter: true }) //wx.removeStorageSync("user_token"); wx.removeStorageSync("openid"); this.loginToWx(); }, start: function () { var animation = wx.createAnimation({ duration: 3000, timingFunction: 'ease', delay: 500 }); animation.opacity(1).step() this.setData({ ani: animation.export() }) }, loginIdInput: function (e) { this.setData({ user: e.detail.value }) }, // 获取输入密码 passwordInput: function (e) { this.setData({ password: e.detail.value }) }, rememberLoginInfoCheckboxChange: function (e) { console.log('change事件,携带值为', e.detail.value) this.setData({ rememberLoginInfoChecked: e.detail.value }) } })