优化代码

This commit is contained in:
刘祥超
2024-01-13 19:31:52 +08:00
parent e1057fc76e
commit ca227a846a
5 changed files with 212 additions and 35 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -1,7 +1,12 @@
Vue.component("size-capacity-view", {
props:["v-default-text", "v-value"],
methods: {
composeCapacity: function (capacity) {
return teaweb.convertSizeCapacityToString(capacity)
}
},
template: `<div>
<span v-if="vValue != null && vValue.count > 0">{{vValue.count}}{{vValue.unit.toUpperCase().replace(/(.)B/, "$1iB")}}</span>
<span v-if="vValue != null && vValue.count > 0">{{composeCapacity(vValue)}}</span>
<span v-else>{{vDefaultText}}</span>
</div>`
})

View File

@@ -1097,10 +1097,13 @@ window.teaweb = {
return -1
},
convertSizeCapacityToString: function (c) {
if (c == null || c.count == null || c.unit == null) {
if (c == null || c.count == null || c.unit == null || c.unit.length == 0) {
return ""
}
return c.count + c.unit.toString().toUpperCase()
if (c.unit == "byte") {
return c.count + "B"
}
return c.count + c.unit[0].toUpperCase() + "i" + c.unit.substring(1).toUpperCase()
}
}

File diff suppressed because one or more lines are too long