// pages/index/index.js const app = getApp(); const util = require('../../utils/util.js'); Page({ /** * 页面的初始数据 */ data: { imgPath: app.globalData.imgPath, path: app.globalData.path, username: app.globalData.userInfo.usernameShow, role_name: app.globalData.roleInfo.name, app_bottom: '大城细管·大城众管·大城智管', nextMeeting: null }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { let that = this; if (!app.globalData.userInfo.usernameShow || !app.globalData.userInfo.nickName || !app.globalData.userInfo.headImgUrl) { wx.showModal({ title: '提示', content: '轻应用需要取您的用户信息', showCancel: false, confirmText: '确定', success: (res) => { if (res.confirm) { wx.getUserProfile({ desc: '提升用户体验感', success: (res) => { app.globalData.userInfo.usernameShow = res.userInfo.nickName; app.globalData.userInfo.nickName = res.userInfo.nickName; app.globalData.userInfo.headImgUrl = res.userInfo.avatarUrl; that.setData({ username: app.globalData.userInfo.usernameShow, role_name: app.globalData.roleInfo.name }); util.post({ url: '/sys/user/updateNoAuth', data: { id: app.globalData.userInfo.id, nickName: res.userInfo.nickName, usernameShow: res.userInfo.nickName, headImgUrl: res.userInfo.avatarUrl } }); }, fail: (res) => { util.toast('拒绝授权将影响您的体验感'); that.setData({ username: '未知用户', role_name: app.globalData.roleInfo.name }); } }); } }, }); } else { that.setData({ username: app.globalData.userInfo.usernameShow, role_name: app.globalData.roleInfo.name }); } // 下一场会议 util.get({ url: '/api/meeting/info/getNextMeeting', success: (res) => { wx.hideLoading(); console.info(res) if (res.data.code != 200) { util.toast(res.data.msg); } else { let datas = res.data.data; if (datas) { that.setData({ nextMeeting: datas, nextTitle: datas.title, nextTime: util.formatDate(datas.receptionTime), nextUnit: datas.receptionObject }); } else { util.toast('暂无下一场会议'); } } } }); }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { }, /** * 调试使用:切换角色菜单 */ changeRole: function () { wx.redirectTo({ url: '../index-admin/index-admin', }); }, /** * 点击查看下一场会议详情 */ meetingInfo: function () { let nextMeeting = this.data.nextMeeting; if (nextMeeting) { wx.navigateTo({ url: '../meeting-cover/meeting-cover?item=' + JSON.stringify(nextMeeting), }); } else { util.toast('暂无下一场会议'); } }, /** * 日常巡检 */ dailyInspection: function () { wx.navigateTo({ url: '../daily-inspection/daily-inspection', }); }, /** * 会议巡检 */ meetingInspection: function () { wx.navigateTo({ url: '../meeting-list/meeting-list?type=INSPECTION', }); }, /** * 点击参观议程跳转至会议列表 */ visitAgenda: function () { wx.navigateTo({ url: '../meeting-list/meeting-list', }); }, /** * 图片回传 */ uploadImage: function () { let that = this; wx.chooseImage({ count: 1, success: function (res) { console.info(res.tempFilePaths); wx.uploadFile({ filePath: res.tempFilePaths[0], name: 'file', url: that.data.path + '/api/upload/record/upload', header: { "Content-Type": "multipart/form-data", "Authorization": app.globalData.Authorization }, formData: { fileType: 10 }, success(res) { console.info(res) } }); } }); }, /** * 内容投屏 */ contentScreen: function () { let wifi, pass; // 打开微信扫一扫 wx.scanCode({ onlyFromCamera: true, scanType: 'qrCode', success: (res) => { console.info(res); if (res.result.indexOf('WIFI') < 0) { util.toast('请扫描WIFI二维码'); return; } wx.showLoading({ title: '加载中...', mask: true }); try { let a = res.result.split(','); wifi = a[0].split(':')[1]; pass = a[1].split(':')[1]; } catch (error) { util.toast('请扫描WIFI二维码'); return; } // 获取设备系统类型 wx.getSystemInfo({ success: (res) => { console.info(res); if (!res.wifiEnabled) { wx.hideLoading(); util.toast('请打开WIFI功能'); return; } // 1、初始化Wi-Fi模块 wx.startWifi({ success: (res) => { console.info(res) if (res.errMsg == 'startWifi:ok') { // 4、连接Wi-Fi wx.connectWifi({ SSID: wifi, password: pass, success: (res) => { wx.hideLoading(); console.info('connectWifi', res); if (res.errMsg == 'connectWifi:ok') { util.toast('WIFI连接成功', 'success'); } else { util.toast(res.errMsg); } }, fail: (e) => { console.info(e); util.toast('WIFI连接失败'); } }); } else { util.toast(res.errMsg); } }, fail: (e) => { console.info(e); util.toast('初始化WiFi模块失败'); } }); }, fail: (e) => { util.toast('获取设备系统类型失败'); return; } }); }, fail: (e) => { util.toast('扫码失败,请重试'); return; } }); }, /** * 聊天室 * @param {*} e */ chatRoom: function (e) { wx.navigateTo({ url: '../chat-room/chat-room', }); }, /** * 地图 */ lightMap: function () { wx.getSetting({ withSubscriptions: true, success: function (res) { console.info(res); if (!res.authSetting['scope.userLocation']) { wx.authorize({ scope: 'scope.userLocation', success: function (res) { console.info(res); wx.navigateTo({ url: '../light-map/light-map', }); }, fail: function (e) { console.info(e); wx.showToast({ title: '用户拒绝授权', icon: 'error' }); } }); } else { wx.navigateTo({ url: '../light-map/light-map', }); } } }); } })