You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
87 lines
1.9 KiB
JavaScript
87 lines
1.9 KiB
JavaScript
function formatDateTime(time) {
|
|
if (typeof time === 'string') {
|
|
time = time.replace(/-/g, '/')
|
|
}
|
|
const date = new Date(time)
|
|
if (isNaN(date.getTime())) return ''
|
|
|
|
const y = date.getFullYear()
|
|
const m = String(date.getMonth() + 1).padStart(2, '0')
|
|
const d = String(date.getDate()).padStart(2, '0')
|
|
const weekMap = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六']
|
|
const week = weekMap[date.getDay()]
|
|
return `${y}年${m}月${d}日 ${week}`
|
|
}
|
|
|
|
Page({
|
|
data: {
|
|
date: formatDateTime(new Date()),
|
|
list: [],
|
|
num1: 0,
|
|
num2: 0
|
|
},
|
|
goDetail(e) {
|
|
const id = e.currentTarget.dataset.id
|
|
wx.setStorageSync('energyInfo', {
|
|
id
|
|
})
|
|
wx.switchTab({
|
|
url: `/pages/energyInfo/energyInfo`,
|
|
})
|
|
},
|
|
onReady() {
|
|
wx.request({
|
|
url: 'http://119.45.202.115:9005/miniProgramApi/collectDevice/list',
|
|
method: 'post',
|
|
header: {
|
|
'content-type': 'application/json'
|
|
},
|
|
success: (res) => {
|
|
this.setData({
|
|
list: res.data.data
|
|
})
|
|
},
|
|
fail(err) {
|
|
console.error(err)
|
|
}
|
|
})
|
|
wx.request({
|
|
url: 'http://119.45.202.115:9005/miniProgramApi/monitor/sum',
|
|
method: 'post',
|
|
header: {
|
|
'content-type': 'application/json'
|
|
},
|
|
success: (res) => {
|
|
this.setData({
|
|
num1: res.data.data
|
|
})
|
|
},
|
|
fail(err) {
|
|
console.error(err)
|
|
}
|
|
})
|
|
wx.request({
|
|
url: 'http://119.45.202.115:9005/miniProgramApi/collectDevice/sum',
|
|
method: 'post',
|
|
header: {
|
|
'content-type': 'application/json'
|
|
},
|
|
success: (res) => {
|
|
this.setData({
|
|
num2: res.data.data
|
|
})
|
|
},
|
|
fail(err) {
|
|
console.error(err)
|
|
}
|
|
})
|
|
},
|
|
onShow() {
|
|
const tabBar = this.getTabBar?.()
|
|
if (tabBar) {
|
|
tabBar.setData({
|
|
nowPage: getCurrentPages().at(-1)?.route
|
|
})
|
|
}
|
|
}
|
|
}); |