|
|
@@ -93,6 +93,11 @@ const props = defineProps({
|
|
|
type: Array as PropType<string[]>,
|
|
|
default: () => [t("小时"), t("分钟"), t("秒数")]
|
|
|
},
|
|
|
+ // 类型,控制选择的粒度
|
|
|
+ type: {
|
|
|
+ type: String as PropType<"hour" | "minute" | "second">,
|
|
|
+ default: "second"
|
|
|
+ },
|
|
|
// 选择器标题
|
|
|
title: {
|
|
|
type: String,
|
|
|
@@ -135,8 +140,8 @@ const props = defineProps({
|
|
|
},
|
|
|
// 时间标签格式化
|
|
|
labelFormat: {
|
|
|
- type: String as PropType<string>,
|
|
|
- default: "{H}:{m}:{s}"
|
|
|
+ type: String as PropType<string | null>,
|
|
|
+ default: null
|
|
|
}
|
|
|
});
|
|
|
|
|
|
@@ -155,6 +160,23 @@ type PassThrough = {
|
|
|
// 解析透传样式配置
|
|
|
const pt = computed(() => parsePt<PassThrough>(props.pt));
|
|
|
|
|
|
+// 标签格式化
|
|
|
+const labelFormat = computed(() => {
|
|
|
+ if (props.labelFormat != null) {
|
|
|
+ return props.labelFormat;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (props.type == "hour") {
|
|
|
+ return "{H}";
|
|
|
+ }
|
|
|
+
|
|
|
+ if (props.type == "minute") {
|
|
|
+ return "{H}:{m}";
|
|
|
+ }
|
|
|
+
|
|
|
+ return "{H}:{m}:{s}";
|
|
|
+});
|
|
|
+
|
|
|
// 当前选中的值
|
|
|
const value = ref<string[]>([]);
|
|
|
|
|
|
@@ -162,7 +184,7 @@ const value = ref<string[]>([]);
|
|
|
const indexes = ref<number[]>([]);
|
|
|
|
|
|
// 时间选择器列表
|
|
|
-const columns = computed(() => {
|
|
|
+const list = computed(() => {
|
|
|
const arr = [[], [], []] as ClSelectOption[][];
|
|
|
|
|
|
for (let i = 0; i < 60; i++) {
|
|
|
@@ -184,6 +206,16 @@ const columns = computed(() => {
|
|
|
return arr;
|
|
|
});
|
|
|
|
|
|
+// 列数,决定显示多少列(时、分、秒)
|
|
|
+const columnNum = computed(() => {
|
|
|
+ return ["hour", "minute", "second"].findIndex((e) => e == props.type) + 1;
|
|
|
+});
|
|
|
+
|
|
|
+// 列数据,取出需要显示的列
|
|
|
+const columns = computed(() => {
|
|
|
+ return list.value.slice(0, columnNum.value);
|
|
|
+});
|
|
|
+
|
|
|
// 显示文本
|
|
|
const text = computed(() => {
|
|
|
// 获取当前v-model绑定的时间字符串
|
|
|
@@ -198,7 +230,7 @@ const text = computed(() => {
|
|
|
const [h, m, s] = val.split(":");
|
|
|
|
|
|
// 按照labelFormat格式化显示文本
|
|
|
- return props.labelFormat.replace("{H}", h).replace("{m}", m).replace("{s}", s);
|
|
|
+ return labelFormat.value.replace("{H}", h).replace("{m}", m).replace("{s}", s);
|
|
|
});
|
|
|
|
|
|
// 选择器值改变事件
|
|
|
@@ -218,7 +250,7 @@ function onChange(a: number[]) {
|
|
|
// 更新组件内部维护的索引数组
|
|
|
indexes.value = b;
|
|
|
// 根据最新的索引数组,更新选中的值数组
|
|
|
- value.value = b.map((e, i) => columns.value[i][e].value as string);
|
|
|
+ value.value = b.map((e, i) => list.value[i][e].value as string);
|
|
|
}
|
|
|
|
|
|
// 选择器显示状态
|
|
|
@@ -293,10 +325,10 @@ watch(
|
|
|
_indexes.push(0);
|
|
|
|
|
|
// 添加默认值
|
|
|
- _value.push(columns.value[i][0].value as string);
|
|
|
+ _value.push(list.value[i][0].value as string);
|
|
|
} else {
|
|
|
// 查找当前值对应的索引
|
|
|
- let index = columns.value[i].findIndex((e) => e.value == _value[i]);
|
|
|
+ let index = list.value[i].findIndex((e) => e.value == _value[i]);
|
|
|
|
|
|
// 索引无效时重置为0
|
|
|
if (index < 0) {
|