js 享元模式
//js 享元模式
//将你所需要更改的数据名称先放入数组
//以下示例由于数据是从两个不同的数组中取出,所以会有if和else的区分
let attrAry = ['sdOccupy', 'sdGross', 'diskGross', 'diskOccupy', 'memoryOccupancy.occupyMemory', 'memoryOccupancy.totalMemory']
attrAry.forEach(attr => {
if (this.keySelfInfo.diskSpace.sdOccupy >= 1024 || this.keySelfInfo.diskSpace.sdGross >= 1024 || this.keySelfInfo.diskSpace.diskGross >= 1024 || this.keySelfInfo.diskSpace.diskOccupy >= 1024 || this.keySelfInfo.memoryOccupancy.occupyMemory >= 1024 || this.keySelfInfo.memoryOccupancy.totalMemory >= 1024) {
if (attr.indexOf('.') === -1) {//判断为哪一个数组里的数据
this.keySelfInfo.diskSpace[attr] = (this.keySelfInfo.diskSpace[attr] / 1024).toFixed(1) + 'GB'
} else {
this.keySelfInfo.memoryOccupancy[attr.split('.')[1]] = (this.keySelfInfo.memoryOccupancy[attr.split('.')[1]] / 1024).toFixed(1) + 'GB'
}
} else {
if (attr.indexOf('.') === -1) {//
this.keySelfInfo.diskSpace[attr] = this.keySelfInfo.diskSpace[attr] + 'MB'
} else {
this.keySelfInfo.memoryOccupancy[attr.split('.')[1]] = this.keySelfInfo.memoryOccupancy[attr.split('.')[1]] + 'MB'
}
}
})