Skip to content

Commit bf577c6

Browse files
committed
fix: clean up imports and improve normalization in CustomRangePicker
1 parent cc4ff6e commit bf577c6

3 files changed

Lines changed: 24 additions & 43 deletions

File tree

adminforth/spa/src/components/CustomRangePicker.vue

Lines changed: 19 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
</div>
3232
</template>
3333
<script setup lang="ts">
34-
import {computed, onMounted, ref, watch} from "vue";
34+
import { computed, ref, watch } from "vue";
3535
import debounce from 'debounce'
3636
import RangePicker from './RangePicker.vue';
3737
@@ -54,59 +54,41 @@ const maxFormatted = computed(() => {
5454
return isNaN(v) ? 100 : Math.ceil(v);
5555
});
5656
57-
const start = ref<number | null>(
58-
props.valueStart === "" || props.valueStart === null ? null : Number(props.valueStart)
59-
);
60-
const end = ref<number | null>(
61-
props.valueEnd === "" || props.valueEnd === null ? null : Number(props.valueEnd)
62-
);
57+
const normalize = (val: any) => (val === "" || val === null || val === undefined) ? null : Number(val);
6358
64-
const sliderValue = ref<[number, number]>([minFormatted.value, maxFormatted.value]);
59+
const start = ref<number | null>(normalize(props.valueStart));
60+
const end = ref<number | null>(normalize(props.valueEnd));
61+
62+
const sliderValue = ref<[number, number]>([
63+
start.value ?? minFormatted.value,
64+
end.value ?? maxFormatted.value
65+
]);
6566
6667
function setSliderValues(s: number | null, e: number | null) {
6768
sliderValue.value = [s ?? minFormatted.value, e ?? maxFormatted.value];
6869
}
6970
7071
watch([start, end], () => {
7172
setSliderValues(start.value, end.value);
72-
});
73+
}, { immediate: true });
7374
7475
const updateFromSlider = debounce((value: [number, number]) => {
7576
start.value = value[0] === minFormatted.value ? null : value[0];
7677
end.value = value[1] === maxFormatted.value ? null : value[1];
7778
}, 500);
7879
79-
function updateStartFromProps() {
80-
const normalized = (props.valueStart === "" || props.valueStart === null || props.valueStart === undefined)
81-
? null : Number(props.valueStart);
82-
if (normalized !== start.value) {
83-
start.value = normalized;
84-
}
85-
}
86-
87-
function updateEndFromProps() {
88-
const normalized = (props.valueEnd === "" || props.valueEnd === null || props.valueEnd === undefined)
89-
? null : Number(props.valueEnd);
90-
if (normalized !== end.value) {
91-
end.value = normalized;
92-
}
93-
}
94-
95-
onMounted(() => {
96-
updateStartFromProps();
97-
updateEndFromProps();
98-
99-
watch(() => props.valueStart, updateStartFromProps);
100-
watch(() => props.valueEnd, updateEndFromProps);
80+
watch(() => props.valueStart, (newVal) => {
81+
const v = normalize(newVal);
82+
if (v !== start.value) start.value = v;
10183
});
10284
103-
watch(start, (newVal) => {
104-
emit('update:valueStart', newVal);
105-
})
85+
watch(() => props.valueEnd, (newVal) => {
86+
const v = normalize(newVal);
87+
if (v !== end.value) end.value = v;
88+
});
10689
107-
watch(end, (newVal) => {
108-
emit('update:valueEnd', newVal);
109-
})
90+
watch(start, (newVal) => emit('update:valueStart', newVal));
91+
watch(end, (newVal) => emit('update:valueEnd', newVal));
11092
11193
watch([minFormatted, maxFormatted], () => {
11294
setSliderValues(start.value, end.value);

adminforth/spa/src/utils/utils.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -351,10 +351,11 @@ export function protectAgainstXSS(value: string) {
351351
ALLOWED_ATTR: [
352352
"data-list",
353353
"src","srcset","alt","title","width","height","loading",
354-
"controls","autoplay","loop","muted","poster","playsinline",
355-
"class","style",
356-
"data-*","aria-*"
357-
]
354+
"controls","autoplay","loop","muted","poster","playsinline","type",
355+
"class","style"
356+
],
357+
ALLOW_DATA_ATTR: true,
358+
ALLOW_ARIA_ATTR: true
358359
});
359360
}
360361

adminforth/spa/src/views/ListView.vue

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,6 @@ import {
235235
import Filters from '@/components/Filters.vue';
236236
import { useAdminforth } from '@/adminforth';
237237
238-
const { t } = useI18n();
239-
240238
const filtersShow = ref(false);
241239
const { list, alert } = useAdminforth();
242240
const coreStore = useCoreStore();

0 commit comments

Comments
 (0)