// pages/privacy/index.js const api = require('../../api/index.js'); // const getCurrentTime = require("../../utils/util.js") const getCurrentTime = require('../../utils/util.js'); // import { getCurrentTime } from '../../utils/util.js'; Page({ /** * 页面的初始数据 */ data: { // 状态栏高度 statusBarHeight:'', // 导航栏高度 navBarHeight:'', // 导航栏和状态栏高度 navStatusBarHeight: '', // 胶囊 menu:'', index:0, objectArray: [], workorder:[], reviewdata:[], currentTime:'', intervalId:'' }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { console.log(getCurrentTime); // 启动定时器:每秒(1000ms)更新一次时间 this.intervalId = setInterval(() => { const time = getCurrentTime.getCurrentTime(); // 获取当前时间(补零后的时分秒) this.setData({ currentTime: time.ymdhms // 更新到页面数据,如 "15:08:03" }); }, 1000); // 必须指定时间间隔(毫秒),这里设为1秒 if (wx.getStorageSync('powerstationId')=='') { wx.setStorage({ key: 'powerstationId', // 存储的key值 data:'' }); } this.getShowScreenHeight() // this.getpowestation() this.setData({ statusBarHeight:wx.getStorageSync('statusBarHeight'), navBarHeight: wx.getStorageSync('navBarHeight'), navStatusBarHeight:wx.getStorageSync('navStatusBarHeight'), menu:wx.getStorageSync('menu') }) }, getShowScreenHeight(){ //系统信息 const systemInfo = wx.getWindowInfo() //胶囊位置 const capsuleInfo = wx.getMenuButtonBoundingClientRect() //计算导航栏高度 let navHeight = systemInfo.statusBarHeight + capsuleInfo.height + (capsuleInfo.top - systemInfo.statusBarHeight) * 2 //计算tabbar高度 let tabHeight = systemInfo.safeArea.bottom - systemInfo.safeArea.height //计算可现实内容高度(中间区域) // let screenHeight = systemInfo.screenHeight-navHeight-tabHeight-30 const menu = wx.getMenuButtonBoundingClientRect() wx.setStorageSync('menu', menu) // 手机系统状态栏高度 wx.setStorageSync('statusBarHeight', tabHeight) // 导航栏高度 wx.setStorageSync('navBarHeight', menu.height+(menu.top-systemInfo.statusBarHeight) *2 ) // 状态栏加导航栏 wx.setStorageSync('navStatusBarHeight',navHeight) }, // 查询电站 getpowestation(){ this.setData({ objectArray:[] }) api.request(`/syspowerstation/selectpowestation`, 'POST',{}) .then((res) => { if (res.code==200) { res.data.unshift({ powerstationAddress: "", powerstationId: "", powerstationImg: "", powerstationName: "全部电站" }) this.setData({ objectArray:res.data }) for (let index = 0; index < res.data.length; index++) { if (res.data[index].powerstationId==wx.getStorageSync('powerstationId')) { this.setData({ index:index }) return }else{ this.setData({ index:0 }) } } // this.getuser() } }) .catch((err) => { console.error('请求失败:', err); // 在这里处理请求失败的情况 }); }, getworkoder(){ let data = { workorderType:'' } api.request(`/workoder/statistics`, 'POST',data) .then((res) => { console.log(res); this.setData({ workorder:res.data }) }) .catch((err) => { console.error('请求失败:', err); // 在这里处理请求失败的情况 }); }, getreview(){ let data = { workorderName:'', workorderType:'', workorderAddress:'', starttime:'', type:'', examineType:5 } api.request(`/workoder/selectworkoder`, 'POST',data) .then((res) => { console.log(res); this.setData({ reviewdata:res.data }) }) .catch((err) => { console.error('请求失败:', err); // 在这里处理请求失败的情况 }); }, rolelocate(e){ console.log(e.currentTarget.dataset.index); if (e.currentTarget.dataset.index==1) { if (wx.getStorageSync('partnerPosition').partnerPosition==1||wx.getStorageSync('partnerPosition').partnerPosition==5) { wx.showToast({ title: '暂无权限', icon: 'none' }); return } wx.navigateTo({ url: '/pages/malfunction/index', }) }else if(e.currentTarget.dataset.index==2){ wx.navigateTo({ url: '/pages/statistics/index', }) }else if(e.currentTarget.dataset.index==3){ if (wx.getStorageSync('partnerPosition').partnerPosition==5) { wx.showToast({ title: '暂无权限', icon: 'none' }); return } wx.navigateTo({ url: '/pages/device/index', }) }else if(e.currentTarget.dataset.index==4){ if (wx.getStorageSync('partnerPosition').partnerPosition==5) { wx.showToast({ title: '暂无权限', icon: 'none' }); return } wx.navigateTo({ url: '/pages/scheduling/index', }) } }, ondetails(e){ console.log(e.currentTarget.dataset.id); wx.navigateTo({ url: `/pages/workorderdetails/index?id=${e.currentTarget.dataset.id}&workorderId=${e.currentTarget.dataset.workorderid}`, }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { }, /** * 生命周期函数--监听页面显示 */ onShow() { if (!this.intervalId) { // 避免重复创建定时器 this.intervalId = setInterval(() => { const time = getCurrentTime.getCurrentTime(); this.setData({ currentTime: time.ymdhms }); }, 1000); } let _this = this // _this.getpowestation() _this.authorizationbtn() _this.getworkoder() _this.getreview() // wx.getSetting({ // withSubscriptions: true, // success (res) { // console.log(res.authSetting) // if (res.authSetting['scope.subscribeMessage']) { // }else{ // wx.showModal({ // title: '', // content: '检测到您没有开启工单服务通知的权限,是否开启', // success (res) { // if (res.confirm) { // console.log('用户点击确定') // _this.authorizationbtn() // } else if (res.cancel) { // console.log('用户点击取消') // } // } // }) // } // } // }) // }, authorizationbtn(){ wx.requestSubscribeMessage({ tmplIds: ['G_37RkJ_mwZeTdPv5A0fjBlYW6_lRQIW9_SywmUAX7Q','AhToqLaCeOvSvSSQ7RvZYd2WgGA11Da13j1PMvqcGqQ'], success(res) { console.log(res); if(res['AhToqLaCeOvSvSSQ7RvZYd2WgGA11Da13j1PMvqcGqQ'] === 'accept' && res['G_37RkJ_mwZeTdPv5A0fjBlYW6_lRQIW9_SywmUAX7Q'] === 'accept') { // 用户同意订阅 } } }) }, bindPickerChange: function(e) { console.log('picker发送选择改变,携带值为', e.detail.value) this.setData({ index: e.detail.value }) wx.setStorage({ key: 'powerstationId', // 存储的key值 data:this.data.objectArray[e.detail.value].powerstationId}); let data = { powerstationId:this.data.objectArray[e.detail.value].powerstationId } api.request(`/syspowerstation/addredisredis`, 'POST',data) .then((res) => { console.log(res); this.getworkoder() this.getreview() }) .catch((err) => { console.error('请求失败:', err); // 在这里处理请求失败的情况 }); }, /** * 生命周期函数--监听页面隐藏 */ onHide() { if (this.intervalId) { clearInterval(this.intervalId); this.intervalId = null; } }, /** * 生命周期函数--监听页面卸载 */ onUnload() { if (this.intervalId) { clearInterval(this.intervalId); // 停止定时器 this.intervalId = null; // 释放引用 } }, /** * 页面相关事件处理函数--监听用户下拉动作 */ async onPullDownRefresh() { let _this = this // _this.authorizationbtn() await _this.getworkoder() await _this.getreview() wx.stopPullDownRefresh(); }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { console.log(11111111); }, /** * 用户点击右上角分享 */ onShareAppMessage() { } })