From 10d606a101a3e2cc520231ac572d5bb4b2eca5c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E7=A5=A5=E8=B6=85?= Date: Thu, 11 Jan 2024 15:17:52 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=B8=A6=E5=AE=BD=E7=9B=B8?= =?UTF-8?q?=E5=85=B3=E7=BB=84=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/bandwidth-size-capacity-box.js | 79 +++++++++++++++++++ .../common/bandwidth-size-capacity-view.js | 15 ++++ 2 files changed, 94 insertions(+) create mode 100644 web/public/js/components/common/bandwidth-size-capacity-box.js create mode 100644 web/public/js/components/common/bandwidth-size-capacity-view.js diff --git a/web/public/js/components/common/bandwidth-size-capacity-box.js b/web/public/js/components/common/bandwidth-size-capacity-box.js new file mode 100644 index 00000000..fd3a6789 --- /dev/null +++ b/web/public/js/components/common/bandwidth-size-capacity-box.js @@ -0,0 +1,79 @@ +Vue.component("bandwidth-size-capacity-box", { + props: ["v-name", "v-value", "v-count", "v-unit", "size", "maxlength", "v-supported-units"], + data: function () { + let v = this.vValue + if (v == null) { + v = { + count: this.vCount, + unit: this.vUnit + } + } + if (v.unit == null || v.unit.length == 0) { + v.unit = "mb" + } + + if (typeof (v["count"]) != "number") { + v["count"] = -1 + } + + let vSize = this.size + if (vSize == null) { + vSize = 6 + } + + let vMaxlength = this.maxlength + if (vMaxlength == null) { + vMaxlength = 10 + } + + let supportedUnits = this.vSupportedUnits + if (supportedUnits == null) { + supportedUnits = [] + } + + return { + capacity: v, + countString: (v.count >= 0) ? v.count.toString() : "", + vSize: vSize, + vMaxlength: vMaxlength, + supportedUnits: supportedUnits + } + }, + watch: { + "countString": function (newValue) { + let value = newValue.trim() + if (value.length == 0) { + this.capacity.count = -1 + this.change() + return + } + let count = parseInt(value) + if (!isNaN(count)) { + this.capacity.count = count + } + this.change() + } + }, + methods: { + change: function () { + this.$emit("change", this.capacity) + } + }, + template: `
+ +
+ +
+
+ +
+
` +}) \ No newline at end of file diff --git a/web/public/js/components/common/bandwidth-size-capacity-view.js b/web/public/js/components/common/bandwidth-size-capacity-view.js new file mode 100644 index 00000000..4c49415b --- /dev/null +++ b/web/public/js/components/common/bandwidth-size-capacity-view.js @@ -0,0 +1,15 @@ +Vue.component("bandwidth-size-capacity-view", { + props: ["v-value"], + data: function () { + let capacity = this.vValue + if (capacity != null && capacity.count > 0 && typeof capacity.unit === "string") { + capacity.unit = capacity.unit[0].toUpperCase() + capacity.unit.substring(1) + "ps" + } + return { + capacity: capacity + } + }, + template: ` + {{capacity.count}}{{capacity.unit}} +` +}) \ No newline at end of file