diff --git a/Scripts/wsgw.js b/Scripts/wsgw.js index 08ff1de..a8c1007 100644 --- a/Scripts/wsgw.js +++ b/Scripts/wsgw.js @@ -92,6 +92,7 @@ class Widget extends DmYY { `缓存失效时间:${new Date(parseInt(this.settings.cacheDay) + this.cacheTime).toLocaleString()}` ); this.dataSource = { ...this.settings.data[this.userNum] }; + if (!this.dataSource.user) await this.cacheData(); console.log(this.dataSource); } }; @@ -104,7 +105,7 @@ class Widget extends DmYY { ); console.log(response); this.settings.data = []; - response.forEach((dataInfo) => { + response?.forEach((dataInfo) => { const dataSource = { user: '**', left: { @@ -133,13 +134,13 @@ class Widget extends DmYY { dataSource.left.arrearsOfFees = dataInfo.arrearsOfFees; dataSource.right.previousBill = parseFloat( - this.last(dataInfo.monthElecQuantity.mothEleList).monthEleCost + this.last(dataInfo.monthElecQuantity?.mothEleList || []) + ?.monthEleCost || 0 ); - const oldVal = this.last( - dataInfo.monthElecQuantity.mothEleList, - 2 - ).monthEleCost; + const oldVal = + this.last(dataInfo.monthElecQuantity?.mothEleList || [], 2) + ?.monthEleCost || 1; dataSource.right.previousBillRate = ((dataSource.right.previousBill - oldVal) / oldVal) * 100; @@ -149,7 +150,7 @@ class Widget extends DmYY { ); dataSource.right.thisYear = parseFloat( - dataInfo.monthElecQuantity.dataInfo.totalEleCost + dataInfo.monthElecQuantity?.dataInfo?.totalEleCost || 0 ); const lastYearVal = dataInfo.lastYearElecQuantity.dataInfo.totalEleCost;