Skip to content

Commit 02883b8

Browse files
committed
update
1 parent baf1a84 commit 02883b8

File tree

1 file changed

+29
-3
lines changed

1 file changed

+29
-3
lines changed

Scripts/wsgw.js

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,42 @@ class Widget extends DmYY {
4747
desc: '左侧背景色',
4848
val: 'leftColor',
4949
});
50+
this.registerAction({
51+
icon: { name: 'arrow.clockwise', color: '#1890ff' },
52+
type: 'input',
53+
title: '缓存时间',
54+
desc: '默认3小时 (单位小时),填写方式数字',
55+
placeholder: '3',
56+
val: 'cacheTime',
57+
});
5058
this.registerAction('基础设置', this.setWidgetConfig);
5159
}
60+
this.cacheTime = (this.settings.cacheTime || 3) * 3600000;
5261
}
5362

5463
date = new Date();
64+
day = this.date.getTime();
5565

5666
dataSource = { ...defaultData };
5767

5868
init = async () => {
5969
console.log(`当前用户下标:${this.userNum}`);
60-
await this.cacheData();
70+
if (
71+
!this.settings.data ||
72+
this.settings.cacheDay + this.cacheTime < this.day
73+
) {
74+
console.log(`缓存失效,重新获取`);
75+
await this.cacheData();
76+
} else {
77+
console.log(
78+
`最后更新时间:${new Date(parseInt(this.settings.cacheDay)).toLocaleString()}`
79+
);
80+
console.log(
81+
`缓存失效时间:${new Date(parseInt(this.settings.cacheDay) + this.cacheTime).toLocaleString()}`
82+
);
83+
this.dataSource = { ...this.settings.data[this.userNum] };
84+
console.log(this.dataSource);
85+
}
6186
};
6287

6388
cacheData = async () => {
@@ -67,7 +92,7 @@ class Widget extends DmYY {
6792
{ timeoutInterval: 60 }
6893
);
6994
console.log(response);
70-
this.settings.data = [];
95+
this.settings.data = [];
7196
response.forEach((dataInfo) => {
7297
const dataSource = {
7398
user: '**',
@@ -84,7 +109,7 @@ class Widget extends DmYY {
84109
},
85110
update: '',
86111
};
87-
112+
88113
dataSource.user = dataInfo.userInfo.consName_dst.replaceAll('*', '');
89114
dataSource.left.balance = parseFloat(dataInfo.eleBill.sumMoney);
90115
dataSource.left.dayElePq = dataInfo.dayElecQuantity.sevenEleList
@@ -130,6 +155,7 @@ class Widget extends DmYY {
130155
});
131156
console.log(this.settings.data);
132157
this.dataSource = { ...this.settings.data[this.userNum] };
158+
this.settings.cacheDay = this.day;
133159
this.saveSettings(false);
134160
} catch (e) {
135161
console.log(`接口数据异常:请检查 BoxJS 重写`);

0 commit comments

Comments
 (0)