pleroma-fe/src/components/settings_modal/helpers/number_setting.js

57 行
1.3 KiB
JavaScript
Raw 通常表示 履歴

2022-03-08 10:02:53 +09:00
import { get, set } from 'lodash'
import ModifiedIndicator from './modified_indicator.vue'
export default {
components: {
ModifiedIndicator
},
props: {
path: String,
disabled: Boolean,
min: Number,
step: Number,
truncate: Number,
2022-03-29 06:02:02 +09:00
expert: [Number, String]
2022-03-08 10:02:53 +09:00
},
computed: {
pathDefault () {
const [firstSegment, ...rest] = this.path.split('.')
return [firstSegment + 'DefaultValue', ...rest].join('.')
},
parent () {
return this.$parent.$parent
},
2022-03-08 10:02:53 +09:00
state () {
const value = get(this.parent, this.path)
2022-03-08 10:02:53 +09:00
if (value === undefined) {
return this.defaultState
} else {
return value
}
},
defaultState () {
return get(this.parent, this.pathDefault)
2022-03-08 10:02:53 +09:00
},
isChanged () {
return this.state !== this.defaultState
},
matchesExpertLevel () {
return (this.expert || 0) <= this.parent.expertLevel
2022-03-08 10:02:53 +09:00
}
},
methods: {
truncateValue (value) {
if (!this.truncate) {
return value
}
return Math.trunc(value / this.truncate) * this.truncate
},
2022-03-08 10:02:53 +09:00
update (e) {
set(this.parent, this.path, this.truncateValue(parseFloat(e.target.value)))
},
reset () {
set(this.parent, this.path, this.defaultState)
2022-03-08 10:02:53 +09:00
}
}
}