fix: 调整重构 setters 组件下几处 watch 初始值引发无法监听问题 (#178)
This commit is contained in:
parent
a64e820e80
commit
de2af7931f
@ -38,32 +38,34 @@ const handleCheckboxChange = (value: boolean) => {
|
|||||||
emit(FORM_CHANGE_EVENT_KEY, { key, value })
|
emit(FORM_CHANGE_EVENT_KEY, { key, value })
|
||||||
}
|
}
|
||||||
|
|
||||||
const watchOptionOrigin = computed(() => props.moduleConfig.optionOrigin)
|
watch(
|
||||||
const watchExtraOptions = computed(() => props.moduleConfig?.extraOptions?.length || [])
|
() => props.moduleConfig.optionOrigin,
|
||||||
const watchValue = computed(() => props.formConfig.value)
|
(newVal) => {
|
||||||
|
const key = props.formConfig.key
|
||||||
|
const extraLen = props.moduleConfig?.extraOptions?.length
|
||||||
|
|
||||||
watch(watchOptionOrigin, (newVal) => {
|
if (key === 'randomSort' && newVal && extraLen === 0) {
|
||||||
const key = props.formConfig.key
|
emit(FORM_CHANGE_EVENT_KEY, { key: 'randomSort', value: false })
|
||||||
const extraLen = props.moduleConfig?.extraOptions?.length
|
modelValue.value = false
|
||||||
|
}
|
||||||
if (key === 'randomSort' && newVal && extraLen === 0) {
|
|
||||||
emit(FORM_CHANGE_EVENT_KEY, { key: 'randomSort', value: false })
|
|
||||||
modelValue.value = false
|
|
||||||
}
|
}
|
||||||
})
|
)
|
||||||
|
|
||||||
watch(watchExtraOptions, (newVal) => {
|
|
||||||
const key = props.formConfig.key
|
|
||||||
const origin = props.moduleConfig?.optionOrigin
|
|
||||||
|
|
||||||
if (key === 'randomSort' && origin && newVal === 0) {
|
|
||||||
emit(FORM_CHANGE_EVENT_KEY, { key: 'randomSort', value: false })
|
|
||||||
modelValue.value = false
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
watchValue,
|
() => props.moduleConfig?.extraOptions?.length || [],
|
||||||
|
(newVal) => {
|
||||||
|
const key = props.formConfig.key
|
||||||
|
const origin = props.moduleConfig?.optionOrigin
|
||||||
|
|
||||||
|
if (key === 'randomSort' && origin && newVal === 0) {
|
||||||
|
emit(FORM_CHANGE_EVENT_KEY, { key: 'randomSort', value: false })
|
||||||
|
modelValue.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
watch(
|
||||||
|
() => props.formConfig.value,
|
||||||
(newVal: boolean) => {
|
(newVal: boolean) => {
|
||||||
if (newVal !== modelValue.value) {
|
if (newVal !== modelValue.value) {
|
||||||
modelValue.value == !!newVal
|
modelValue.value == !!newVal
|
||||||
|
@ -62,19 +62,21 @@ const handleSwitchChange = (value: string | null) => {
|
|||||||
emit(FORM_CHANGE_EVENT_KEY, { key: formdataBackfillHourKey, value: value ? '24' : null })
|
emit(FORM_CHANGE_EVENT_KEY, { key: formdataBackfillHourKey, value: value ? '24' : null })
|
||||||
}
|
}
|
||||||
|
|
||||||
const watchValue = computed(() => props.formConfig.value)
|
watch(
|
||||||
watch(watchValue, (config) => {
|
() => props.formConfig.value,
|
||||||
const formdataBackfill = config[formdataBackfillKey]
|
(config) => {
|
||||||
const formdataBackfillHour = !!config[formdataBackfillHourKey]
|
const formdataBackfill = config[formdataBackfillKey]
|
||||||
|
const formdataBackfillHour = !!config[formdataBackfillHourKey]
|
||||||
|
|
||||||
if (formdataBackfill !== selectModelValue.value) {
|
if (formdataBackfill !== selectModelValue.value) {
|
||||||
selectModelValue.value = formdataBackfill
|
selectModelValue.value = formdataBackfill
|
||||||
}
|
}
|
||||||
|
|
||||||
if (formdataBackfillHour !== switchModelValue.value) {
|
if (formdataBackfillHour !== switchModelValue.value) {
|
||||||
switchModelValue.value = formdataBackfillHour
|
switchModelValue.value = formdataBackfillHour
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
)
|
||||||
</script>
|
</script>
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
.row {
|
.row {
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
></el-input>
|
></el-input>
|
||||||
</template>
|
</template>
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref, watch, computed } from 'vue'
|
import { ref, watch } from 'vue'
|
||||||
import { FORM_CHANGE_EVENT_KEY } from '@/materials/setters/constant'
|
import { FORM_CHANGE_EVENT_KEY } from '@/materials/setters/constant'
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
@ -21,7 +21,6 @@ const emit = defineEmits<Emit>()
|
|||||||
const props = defineProps<Props>()
|
const props = defineProps<Props>()
|
||||||
|
|
||||||
const modelValue = ref(props.formConfig.value || '')
|
const modelValue = ref(props.formConfig.value || '')
|
||||||
const lazyValue = computed(() => props.formConfig.value)
|
|
||||||
|
|
||||||
const handleInputBlur = () => {
|
const handleInputBlur = () => {
|
||||||
const { key, validate, value } = props.formConfig
|
const { key, validate, value } = props.formConfig
|
||||||
@ -40,9 +39,12 @@ const handleInputBlur = () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
watch(lazyValue, (value) => {
|
watch(
|
||||||
if (value !== modelValue.value) {
|
() => props.formConfig.value,
|
||||||
modelValue.value = value
|
(value) => {
|
||||||
|
if (value !== modelValue.value) {
|
||||||
|
modelValue.value = value
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
)
|
||||||
</script>
|
</script>
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { computed, ref, watch } from 'vue'
|
import { ref, watch } from 'vue'
|
||||||
import moment from 'moment'
|
import moment from 'moment'
|
||||||
import 'moment/locale/zh-cn'
|
import 'moment/locale/zh-cn'
|
||||||
import zhCn from 'element-plus/es/locale/lang/zh-cn'
|
import zhCn from 'element-plus/es/locale/lang/zh-cn'
|
||||||
@ -49,14 +49,11 @@ const begTimeStr = ref(moment(defaultBeginTime).format(format))
|
|||||||
const endTimeStr = ref(moment(defaultEndTime).format(format))
|
const endTimeStr = ref(moment(defaultEndTime).format(format))
|
||||||
|
|
||||||
const handleDatePickerChange = (key: string, value: string) => {
|
const handleDatePickerChange = (key: string, value: string) => {
|
||||||
console.log(key, value)
|
|
||||||
emit(FORM_CHANGE_EVENT_KEY, { key, value })
|
emit(FORM_CHANGE_EVENT_KEY, { key, value })
|
||||||
}
|
}
|
||||||
|
|
||||||
const watchValue = computed(() => props.formConfig.value)
|
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
watchValue,
|
() => props.formConfig.value,
|
||||||
([begTime, endTime]: any) => {
|
([begTime, endTime]: any) => {
|
||||||
if (!!begTime && begTime !== begTimeStr.value) {
|
if (!!begTime && begTime !== begTimeStr.value) {
|
||||||
begTimeStr.value = begTime
|
begTimeStr.value = begTime
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref, computed, watch } from 'vue'
|
import { ref, watch } from 'vue'
|
||||||
import moment from 'moment'
|
import moment from 'moment'
|
||||||
import 'moment/locale/zh-cn'
|
import 'moment/locale/zh-cn'
|
||||||
import zhCn from 'element-plus/es/locale/lang/zh-cn'
|
import zhCn from 'element-plus/es/locale/lang/zh-cn'
|
||||||
@ -52,9 +52,8 @@ const handleTimePickerChange = (values: Array<string>) => {
|
|||||||
times.forEach((value, idx) => emit(FORM_CHANGE_EVENT_KEY, { key: keys[idx], value }))
|
times.forEach((value, idx) => emit(FORM_CHANGE_EVENT_KEY, { key: keys[idx], value }))
|
||||||
}
|
}
|
||||||
|
|
||||||
const watchValue = computed(() => props.formConfig.value)
|
|
||||||
watch(
|
watch(
|
||||||
watchValue,
|
() => props.formConfig.value,
|
||||||
([startTime = '00:00:00', endTime = '23:59:59']: Array<string>) => {
|
([startTime = '00:00:00', endTime = '23:59:59']: Array<string>) => {
|
||||||
if (startTime !== timeValue.value[0] || endTime !== timeValue.value[1]) {
|
if (startTime !== timeValue.value[0] || endTime !== timeValue.value[1]) {
|
||||||
const times = [startTime, endTime]
|
const times = [startTime, endTime]
|
||||||
|
@ -42,7 +42,10 @@ const handleRadioGroupChange = (value: string) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
props.formConfig,
|
() => ({
|
||||||
|
value: props.formConfig?.value,
|
||||||
|
defaultValue: props.formConfig?.defaultValue
|
||||||
|
}),
|
||||||
(config) => {
|
(config) => {
|
||||||
if (config.value == null || config.value == undefined) {
|
if (config.value == null || config.value == undefined) {
|
||||||
modelValue.value = config.defaultValue
|
modelValue.value = config.defaultValue
|
||||||
|
@ -53,7 +53,10 @@ const handleRadioGroupChange = (value: string) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
props.formConfig,
|
() => ({
|
||||||
|
value: props.formConfig?.value,
|
||||||
|
defaultValue: props.formConfig?.defaultValue
|
||||||
|
}),
|
||||||
(config) => {
|
(config) => {
|
||||||
if (config.value == null || config.value == undefined) {
|
if (config.value == null || config.value == undefined) {
|
||||||
modelValue.value = config.defaultValue
|
modelValue.value = config.defaultValue
|
||||||
|
@ -77,10 +77,10 @@ const handleSelectChange = (value: string) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
props.formConfig,
|
() => props.formConfig?.value,
|
||||||
(newValue) => {
|
(val) => {
|
||||||
if (modelValue.value != newValue.value) {
|
if (modelValue.value != val) {
|
||||||
modelValue.value = newValue.value
|
modelValue.value = val
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{ deep: true }
|
{ deep: true }
|
||||||
|
Loading…
Reference in New Issue
Block a user