index.vue
3.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<!--
* @Date: 2022-09-14 11:00:01
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2024-08-07 18:13:33
* @FilePath: /data-table/src/components/CalendarField/index.vue
* @Description: 日历选择控件
-->
<template>
<div class="calendar-page">
<div class="label">
<span v-if="item.component_props.disabled_show"><van-icon name="https://cdn.ipadbiz.cn/custom_form/icon/closed-eye1.png" /></span>
<span v-if="item.component_props.required" style="color: red"> *</span>
<span :class="[ReadonlyShow ? 'readonly-show' : '']">{{ item.component_props.label }}</span>
</div>
<van-field
v-model="item.value"
is-link
readonly
:name="item.key"
:required="item.component_props.required"
:placeholder="item.component_props.placeholder"
:rules="item.rules"
@click="show = true"
/>
<van-calendar
v-model:show="show"
:type="item.component_props.type"
:max-range="item.component_props.max_range"
:min-date="item.component_props.min_date"
:max-date="item.component_props.max_date"
:formatter="formatter"
first-day-of-week="1"
@month-show="onMonthShow"
@confirm="onConfirm"
allow-same-day
/>
</div>
</template>
<script setup>
import { useRoute } from "vue-router";
const $route = useRoute();
const props = defineProps({
item: Object,
});
// 只读显示-流程模式
const ReadonlyShow = computed(() => {
return $route.query.page_type === 'flow' && !props.item.component_props.readonly;
});
const show = ref(false);
const formatDate = (date) =>
`${date.getFullYear()}/${date.getMonth() + 1}/${date.getDate()}`;
const onConfirm = (value) => {
console.warn(props.item.component_props.type);
show.value = false;
if (props.item.component_props.type === "range") {
// 日期区间
const [start, end] = value;
props.item.value = `${formatDate(start)} ~ ${formatDate(end)}`;
} else if (props.item.component_props.type === "multiple") {
// 多个日期
const arr = [];
value.forEach((element) => {
arr.push(formatDate(element));
});
props.item.value = arr.join(",");
} else {
props.item.value = formatDate(value);
}
};
// 每一格内容格式化
const formatter = (day) => {
const month = day.date.getMonth() + 1;
const date = day.date.getDate();
const year = day.date.getFullYear();
if (month === 5) {
if (date === 1) {
day.topInfo = "劳动节";
} else if (date === 4) {
day.topInfo = "青年节";
} else if (date === 11) {
day.text = "今天";
}
}
if (month === 10) {
if (date === 1) {
day.topInfo = "国庆节";
day.type = "disabled";
}
}
if (day.type === "start") {
day.bottomInfo = "开始";
} else if (day.type === "end") {
day.bottomInfo = "结束";
}
return day;
};
const onMonthShow = ({ date, title }) => {
// console.warn(date);
// console.warn(title);
if (title === "2022年12月") {
}
};
</script>
<style lang="less" scoped>
.calendar-page {
.label {
padding: 1rem 1rem 0 1rem;
font-size: 0.9rem;
font-weight: bold;
}
}
</style>