From 4bf4620a3328c817742b4adfa4b190608bd1b235 Mon Sep 17 00:00:00 2001 From: Rocka Date: Sun, 10 Oct 2021 20:54:29 +0800 Subject: [PATCH] chore: major type annotation improvement we now have auto completion and type checking in all components now see https://github.com/vuejs/vetur/issues/1707 --- src/api/mqtt.js | 11 +-- src/components/battery.vue | 9 +- src/components/card.vue | 1 + src/components/control.vue | 9 +- src/components/countdown-button.vue | 4 +- src/components/custom/custom.vue | 3 + src/components/debug.vue | 5 +- src/components/depot/status.vue | 4 + src/components/drone/map.vue | 19 ++-- src/components/drone/monitor.vue | 19 +++- src/components/drone/status.vue | 4 + src/components/job-file/job-file.vue | 1 + src/components/monitor/monitor.vue | 5 + src/components/monitor/webrtc.vue | 7 +- src/components/monitor/webrtc2-client.js | 2 +- src/components/monitor/webrtc2.vue | 7 +- src/components/monitor/webrtc3-client.js | 9 ++ src/components/monitor/webrtc3.vue | 7 +- src/components/monitor/webrtc4-client.js | 9 ++ src/components/monitor/webrtc4.vue | 7 +- .../plan-dialog/plan-dialog-item.vue | 2 + src/components/plan-dialog/plan-dialog.vue | 2 + src/components/plan/editable.vue | 9 +- src/components/plan/plan-files.vue | 6 +- src/components/plan/readonly.vue | 9 +- src/components/sd-icon.vue | 5 +- src/components/settings/node-parameters.vue | 19 ++-- src/components/settings/settings-slider.vue | 7 +- src/components/settings/settings.vue | 7 +- src/components/slide-confirm.vue | 6 ++ src/components/status/status-meter.vue | 2 + src/components/status/status-notify-item.vue | 2 + src/components/status/status-notify.vue | 6 +- src/components/status/status.vue | 8 +- src/components/weather/alert-badge.vue | 5 + src/components/weather/rain-chart.vue | 1 + src/components/weather/weather.vue | 3 + src/components/weather/wind-chart.vue | 2 + src/components/weather/wind-icon.vue | 2 + src/pages/node/node.vue | 9 +- src/pages/overview/overview-map.vue | 37 +++++-- src/pages/overview/overview-notify.vue | 8 +- src/pages/overview/overview-popover.vue | 1 + src/pages/overview/overview.vue | 12 +-- src/pages/panel/aside.vue | 23 ++--- src/pages/panel/header.vue | 31 +++--- src/pages/plan/edit.vue | 1 + src/pages/plan/plan.vue | 13 ++- src/pages/plan/view.vue | 42 ++++---- src/sdwc.d.ts | 96 ++++++++++++------- src/store/actions.js | 1 + src/store/modules/plan.js | 3 +- src/util/plugin-mqtt.js | 2 +- 53 files changed, 333 insertions(+), 191 deletions(-) diff --git a/src/api/mqtt.js b/src/api/mqtt.js index 628b6686..42e35cf3 100644 --- a/src/api/mqtt.js +++ b/src/api/mqtt.js @@ -33,8 +33,7 @@ export class MqttClient extends EventEmitter2 { * - `nodes/:id/msg/{position,battery,weather,...}` * - `plans/:id/{term,dialog,running}` * @param {string} topic - * @typedef {{ entity: 'nodes'|'plans'|string, id: number, category: string, param: string }} TopicInfo - * @returns {TopicInfo} + * @returns {SDWC.MqttTopicInfo} */ static parseTopic(topic) { const parts = topic.split('/'); @@ -150,7 +149,7 @@ export class MqttClient extends EventEmitter2 { * @param {number|string} target target node id * @param {string} method method name * @param {any} arg method argument - * @param {SDWC.MqttControlOptions} [options] + * @param {SDWC.MqttRpcOptions} [options] * @returns {Promise} */ invoke(target, method, arg, options) { @@ -169,7 +168,7 @@ export class MqttClient extends EventEmitter2 { * @param {number|string} target target node id * @param {string} method method name * @param {any} arg method argument - * @param {SDWC.MqttControlOptions} [options] + * @param {SDWC.MqttRpcOptions} [options] */ _invoke(target, method, arg, options = {}) { const rpcId = this.nextRpcId(); @@ -192,7 +191,7 @@ export class MqttClient extends EventEmitter2 { } /** - * @param {TopicInfo} topic + * @param {SDWC.MqttTopicInfo} topic * @param {string} str */ onNode(topic, str) { @@ -264,7 +263,7 @@ export class MqttClient extends EventEmitter2 { } /** - * @param {TopicInfo} topic + * @param {SDWC.MqttTopicInfo} topic * @param {string} str */ onPlan(topic, str) { diff --git a/src/components/battery.vue b/src/components/battery.vue index f2a03238..d9f95edc 100644 --- a/src/components/battery.vue +++ b/src/components/battery.vue @@ -72,18 +72,23 @@ export default { } }, computed: { + /** @returns {SDWC.NodeBattery} */ battery() { return this.msg.battery; }, + /** @returns {string} */ current() { - const I = ((this.battery.cur || 0) / 1000); + const I = (this.battery.cur || 0) / 1000; return Math.abs(I) > 1 ? I.toFixed(1) : I.toFixed(2); }, + /** @returns {string} */ voltage() { return (this.battery.vol_cell || '').replace(/\//g, ' / '); }, + /** @returns {string} */ totalVoltage() { - return (this.battery.vol_cell || '').split('/').reduce((a, b) => +b + a, 0) / 1000; + const U = (this.battery.vol_cell || '').split('/').reduce((a, b) => +b + a, 0) / 1000; + return U.toFixed(3); } }, watch: { diff --git a/src/components/card.vue b/src/components/card.vue index 70f7b403..cdf4c639 100644 --- a/src/components/card.vue +++ b/src/components/card.vue @@ -34,6 +34,7 @@ export default { } }, computed: { + /** @returns {{ [key: string]: boolean }} */ className() { return { 'sd-card--dense': this.dense diff --git a/src/components/control.vue b/src/components/control.vue index 96e6069d..2c000786 100644 --- a/src/components/control.vue +++ b/src/components/control.vue @@ -30,7 +30,7 @@ import Icon from '@/components/sd-icon.vue'; /** * custom control group - * @type {{ icon: string, item: SDWC.ControlButton[] }[]} + * @type {ControlButtonGroup[]} */ const Controls = [ { @@ -61,15 +61,22 @@ export default { }; }, computed: { + /** @returns {boolean} */ disabled() { return this.status.code !== 0; }, + /** @returns {string} */ disabledText() { return this.$t('control.abnormal'); }, + /** + * override in derived class + * @returns {SDWC.ControlButtonGroup[]} + */ staticControls() { return Controls; }, + /** @returns {SDWC.ControlButtonGroup[]} */ controls() { return this.point.params || this.staticControls; } diff --git a/src/components/countdown-button.vue b/src/components/countdown-button.vue index 945a34e0..0361c5da 100644 --- a/src/components/countdown-button.vue +++ b/src/components/countdown-button.vue @@ -1,7 +1,7 @@ @@ -37,9 +37,11 @@ export default { }; }, computed: { + /** @returns {boolean} */ disabled() { return this.mode === 'delay' && this.remain > 0; }, + /** @returns {string} */ confirmSuffix() { return this.remain > 0 ? ` (${this.remain})` : ''; } diff --git a/src/components/custom/custom.vue b/src/components/custom/custom.vue index 982e3e8e..6c9d4415 100644 --- a/src/components/custom/custom.vue +++ b/src/components/custom/custom.vue @@ -27,12 +27,15 @@ export default { } }, computed: { + /** @returns {string} */ icon() { return this.point.params.icon || 'views'; }, + /** @returns {string} */ title() { return this.point.params.title || 'custom.title'; }, + /** @returns {{ label: string, field: string, unit?: string, value: any }[]} */ items() { const { topic = 'custom', items = [] } = this.point.params; const pool = this.msg[topic] || {}; diff --git a/src/components/debug.vue b/src/components/debug.vue index 89cab2b7..013afada 100644 --- a/src/components/debug.vue +++ b/src/components/debug.vue @@ -61,12 +61,15 @@ export default { }; }, computed: { + /** @returns {boolean} */ disabled() { return this.status.code !== 0; }, + /** @returns {string} */ disabledText() { return this.$t('control.abnormal'); }, + /** @returns {{ value: string }[]} */ commands() { return this.point.name.trim().split(' ').filter(c => c !== '').map(value => ({ value })); } @@ -118,7 +121,7 @@ export default { * @param {KeyboardEvent} e */ onKeyPress(e) { - if (e.keyCode === 13 || e.key === 'Enter') { + if (e.key === 'Enter') { this.handleSend(); } } diff --git a/src/components/depot/status.vue b/src/components/depot/status.vue index e9bef047..fb0bbe07 100644 --- a/src/components/depot/status.vue +++ b/src/components/depot/status.vue @@ -36,14 +36,17 @@ export default { name: 'sd-depot-status', inheritAttrs: false, props: { + /** @type {Vue.PropOptions} */ point: { type: Object, required: true }, + /** @type {Vue.PropOptions} */ status: { type: Object, required: true }, + /** @type {Vue.PropOptions} */ msg: { type: Object, required: true @@ -61,6 +64,7 @@ export default { } }), computed: { + /** @returns {SDWC.StatusItem[]} */ items() { const s = this.msg.depot_status; const c = this.msg.charger; diff --git a/src/components/drone/map.vue b/src/components/drone/map.vue index 5606a39d..d521449e 100644 --- a/src/components/drone/map.vue +++ b/src/components/drone/map.vue @@ -67,7 +67,7 @@