|
@@ -60,7 +60,7 @@
|
|
</template>
|
|
</template>
|
|
|
|
|
|
<script setup lang="ts" name="ScoreRangeTimeEditor">
|
|
<script setup lang="ts" name="ScoreRangeTimeEditor">
|
|
-import { ref, watch, computed } from 'vue'
|
|
|
|
|
|
+import { ref, watch, computed, nextTick } from 'vue'
|
|
import { ElInputNumber, ElButton } from 'element-plus'
|
|
import { ElInputNumber, ElButton } from 'element-plus'
|
|
|
|
|
|
interface ScoreRange {
|
|
interface ScoreRange {
|
|
@@ -161,10 +161,16 @@ const removeRange = (index: number) => {
|
|
errorMessage.value = ''
|
|
errorMessage.value = ''
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+// 标记是否正在内部更新,避免死循环
|
|
|
|
+const isInternalUpdate = ref(false)
|
|
|
|
+
|
|
// 监听变化并向父组件发送更新
|
|
// 监听变化并向父组件发送更新
|
|
watch(
|
|
watch(
|
|
ranges,
|
|
ranges,
|
|
(newRanges) => {
|
|
(newRanges) => {
|
|
|
|
+ if (isInternalUpdate.value) {
|
|
|
|
+ return
|
|
|
|
+ }
|
|
// validateAllRanges()
|
|
// validateAllRanges()
|
|
emit('update:modelValue', [...newRanges])
|
|
emit('update:modelValue', [...newRanges])
|
|
emit('change', [...newRanges])
|
|
emit('change', [...newRanges])
|
|
@@ -177,7 +183,18 @@ watch(
|
|
() => props.modelValue,
|
|
() => props.modelValue,
|
|
(newValue) => {
|
|
(newValue) => {
|
|
if (newValue && newValue.length > 0) {
|
|
if (newValue && newValue.length > 0) {
|
|
- ranges.value = [...newValue]
|
|
|
|
|
|
+ // 检查是否真的需要更新,避免不必要的赋值
|
|
|
|
+ const currentRanges = JSON.stringify(ranges.value)
|
|
|
|
+ const newRanges = JSON.stringify(newValue)
|
|
|
|
+
|
|
|
|
+ if (currentRanges !== newRanges) {
|
|
|
|
+ isInternalUpdate.value = true
|
|
|
|
+ ranges.value = [...newValue]
|
|
|
|
+ // 使用 nextTick 确保在下一个事件循环中重置标记
|
|
|
|
+ nextTick(() => {
|
|
|
|
+ isInternalUpdate.value = false
|
|
|
|
+ })
|
|
|
|
+ }
|
|
}
|
|
}
|
|
},
|
|
},
|
|
{ deep: true }
|
|
{ deep: true }
|