diff options
| author | Henry Jameson <me@hjkos.com> | 2024-07-25 11:53:58 +0300 |
|---|---|---|
| committer | Henry Jameson <me@hjkos.com> | 2024-07-25 11:53:58 +0300 |
| commit | e8d7d341f03846a3faf85670866b2cb8d9d12cc9 (patch) | |
| tree | bdb2d0d8cd673ef6ee13df47f0cd3f986da0b248 /src/components/settings_modal/helpers/unit_setting.js | |
| parent | 0ca9a2c8c0d04b3468c93de4a53fac8197581d8b (diff) | |
| parent | 4797b13625f5848e3f7d437ec9dcf6073607a647 (diff) | |
Merge remote-tracking branch 'origin/develop' into fix-develop-issues
Diffstat (limited to 'src/components/settings_modal/helpers/unit_setting.js')
| -rw-r--r-- | src/components/settings_modal/helpers/unit_setting.js | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/src/components/settings_modal/helpers/unit_setting.js b/src/components/settings_modal/helpers/unit_setting.js index c9c23cb0..daeddd81 100644 --- a/src/components/settings_modal/helpers/unit_setting.js +++ b/src/components/settings_modal/helpers/unit_setting.js @@ -21,15 +21,23 @@ export default { unitSet: { type: String, default: 'none' + }, + step: { + type: Number, + default: 1 + }, + resetDefault: { + type: Object, + default: null } }, computed: { ...Setting.computed, stateUnit () { - return this.state.replace(/\d+/, '') + return typeof this.state === 'string' ? this.state.replace(/[0-9,.]+/, '') : '' }, stateValue () { - return this.state.replace(/\D+/, '') + return typeof this.state === 'string' ? this.state.replace(/[^0-9,.]+/, '') : '' } }, methods: { @@ -39,10 +47,18 @@ export default { return this.$t(['settings', 'units', this.unitSet, value].join('.')) }, updateValue (e) { - this.configSink(this.path, parseInt(e.target.value) + this.stateUnit) + this.configSink(this.path, parseFloat(e.target.value) + this.stateUnit) }, updateUnit (e) { - this.configSink(this.path, this.stateValue + e.target.value) + let value = this.stateValue + const newUnit = e.target.value + if (this.resetDefault) { + const replaceValue = this.resetDefault[newUnit] + if (replaceValue != null) { + value = replaceValue + } + } + this.configSink(this.path, value + newUnit) } } } |
