Showing
1 changed file
with
79 additions
and
22 deletions
| 1 | <!-- | 1 | <!-- |
| 2 | * @Date: 2022-09-08 15:02:45 | 2 | * @Date: 2022-09-08 15:02:45 |
| 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com | 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com |
| 4 | - * @LastEditTime: 2024-08-07 18:13:52 | 4 | + * @LastEditTime: 2024-08-09 11:40:31 |
| 5 | * @FilePath: /data-table/src/components/DateTimePickerField/index.vue | 5 | * @FilePath: /data-table/src/components/DateTimePickerField/index.vue |
| 6 | * @Description: 日期时间选择器 | 6 | * @Description: 日期时间选择器 |
| 7 | --> | 7 | --> |
| ... | @@ -31,7 +31,7 @@ | ... | @@ -31,7 +31,7 @@ |
| 31 | @cancel="onCancel" | 31 | @cancel="onCancel" |
| 32 | > | 32 | > |
| 33 | <van-date-picker v-model="currentDate" :min-date="minDate" :max-date="maxDate" :columns-type="columns_date_type" /> | 33 | <van-date-picker v-model="currentDate" :min-date="minDate" :max-date="maxDate" :columns-type="columns_date_type" /> |
| 34 | - <van-time-picker v-model="currentTime" :columns-type="columns_time_type" /> | 34 | + <van-time-picker v-if="columns_time_type.length" v-model="currentTime" :min-time="minTime" :max-time="maxTime" :columns-type="columns_time_type" /> |
| 35 | </van-picker-group> | 35 | </van-picker-group> |
| 36 | </van-popup> | 36 | </van-popup> |
| 37 | </div> | 37 | </div> |
| ... | @@ -65,7 +65,11 @@ const currentDate = ref([]); | ... | @@ -65,7 +65,11 @@ const currentDate = ref([]); |
| 65 | const currentTime = ref([]); | 65 | const currentTime = ref([]); |
| 66 | 66 | ||
| 67 | const onConfirm = () => { | 67 | const onConfirm = () => { |
| 68 | - props.item.value = `${currentDate.value.join("-")} ${currentTime.value.join(":")}`; | 68 | + if (columns_time_type.value.length) { |
| 69 | + props.item.value = `${currentDate.value.join("-")} ${currentTime.value.join(":")}`; | ||
| 70 | + } else { | ||
| 71 | + props.item.value = `${currentDate.value.join("-")}`; | ||
| 72 | + } | ||
| 69 | showPicker.value = false; | 73 | showPicker.value = false; |
| 70 | }; | 74 | }; |
| 71 | const onCancel = () => { | 75 | const onCancel = () => { |
| ... | @@ -83,9 +87,15 @@ const formatZero = (num, len) => { | ... | @@ -83,9 +87,15 @@ const formatZero = (num, len) => { |
| 83 | return (Array(len).join(0) + num).slice(-len) | 87 | return (Array(len).join(0) + num).slice(-len) |
| 84 | } | 88 | } |
| 85 | 89 | ||
| 90 | +const data_minvalue = props.item.component_props.data_minvalue; | ||
| 91 | +const data_maxvalue = props.item.component_props.data_maxvalue; | ||
| 92 | + | ||
| 86 | const minDate = ref() | 93 | const minDate = ref() |
| 87 | const maxDate = ref() | 94 | const maxDate = ref() |
| 88 | 95 | ||
| 96 | +const minTime = ref() | ||
| 97 | +const maxTime = ref() | ||
| 98 | + | ||
| 89 | onMounted(() => { | 99 | onMounted(() => { |
| 90 | // 根据默认值时间调整显示 | 100 | // 根据默认值时间调整显示 |
| 91 | props.item.value = props.item.component_props.default ? props.item.component_props.default : ''; | 101 | props.item.value = props.item.component_props.default ? props.item.component_props.default : ''; |
| ... | @@ -122,16 +132,43 @@ onMounted(() => { | ... | @@ -122,16 +132,43 @@ onMounted(() => { |
| 122 | columns_date_type.value = ['year'] | 132 | columns_date_type.value = ['year'] |
| 123 | // 设置默认值 | 133 | // 设置默认值 |
| 124 | currentDate.value = [Year]; | 134 | currentDate.value = [Year]; |
| 135 | + // 设置默认最大最小日期 | ||
| 136 | + if (data_minvalue.split(" ")[0].length) { | ||
| 137 | + const min = data_minvalue.split(" ")[0].split("-"); | ||
| 138 | + minDate.value = new Date(+min[0] + 1, 0, 0); | ||
| 139 | + } | ||
| 140 | + if (data_maxvalue.split(" ")[0].length) { | ||
| 141 | + const max = data_maxvalue.split(" ")[0].split("-") | ||
| 142 | + maxDate.value = new Date(+max[0] + 1, 0, 0) | ||
| 143 | + } | ||
| 125 | break; | 144 | break; |
| 126 | case "YYYY-MM": | 145 | case "YYYY-MM": |
| 127 | columns_date_type.value = ['year', 'month'] | 146 | columns_date_type.value = ['year', 'month'] |
| 128 | // 设置默认值 | 147 | // 设置默认值 |
| 129 | currentDate.value = [Year, Month]; | 148 | currentDate.value = [Year, Month]; |
| 149 | + // 设置默认最大最小日期 | ||
| 150 | + if (data_minvalue.split(" ")[0].length) { | ||
| 151 | + const min = data_minvalue.split(" ")[0].split("-"); | ||
| 152 | + minDate.value = new Date(+min[0], +min[1], 0); | ||
| 153 | + } | ||
| 154 | + if (data_maxvalue.split(" ")[0].length) { | ||
| 155 | + const max = data_maxvalue.split(" ")[0].split("-") | ||
| 156 | + maxDate.value = new Date(+max[0], +max[1], 0) | ||
| 157 | + } | ||
| 130 | break; | 158 | break; |
| 131 | case "YYYY-MM-DD": | 159 | case "YYYY-MM-DD": |
| 132 | columns_date_type.value = ['year', 'month', 'day'] | 160 | columns_date_type.value = ['year', 'month', 'day'] |
| 133 | // 设置默认值 | 161 | // 设置默认值 |
| 134 | currentDate.value = [Year, Month, Day]; | 162 | currentDate.value = [Year, Month, Day]; |
| 163 | + // 设置默认最大最小日期 | ||
| 164 | + if (data_minvalue.split(" ")[0].length) { | ||
| 165 | + const min = data_minvalue.split(" ")[0].split("-"); | ||
| 166 | + minDate.value = new Date(+min[0], +min[1] - 1, +min[2]); | ||
| 167 | + } | ||
| 168 | + if (data_maxvalue.split(" ")[0].length) { | ||
| 169 | + const max = data_maxvalue.split(" ")[0].split("-") | ||
| 170 | + maxDate.value = new Date(+max[0], +max[1] - 1, +max[2]) | ||
| 171 | + } | ||
| 135 | break; | 172 | break; |
| 136 | case "YYYY-MM-DD HH": | 173 | case "YYYY-MM-DD HH": |
| 137 | columns_date_type.value = ['year', 'month', 'day'] | 174 | columns_date_type.value = ['year', 'month', 'day'] |
| ... | @@ -139,6 +176,22 @@ onMounted(() => { | ... | @@ -139,6 +176,22 @@ onMounted(() => { |
| 139 | // 设置默认值 | 176 | // 设置默认值 |
| 140 | currentDate.value = [Year, Month, Day]; | 177 | currentDate.value = [Year, Month, Day]; |
| 141 | currentTime.value = [Hour]; | 178 | currentTime.value = [Hour]; |
| 179 | + // 设置默认最大最小日期 | ||
| 180 | + if (data_minvalue.split(" ")[0].length) { | ||
| 181 | + const min = data_minvalue.split(" ")[0].split("-"); | ||
| 182 | + minDate.value = new Date(+min[0], +min[1] - 1, +min[2]); | ||
| 183 | + } | ||
| 184 | + if (data_maxvalue.split(" ")[0].length) { | ||
| 185 | + const max = data_maxvalue.split(" ")[0].split("-") | ||
| 186 | + maxDate.value = new Date(+max[0], +max[1] - 1, +max[2]) | ||
| 187 | + } | ||
| 188 | + // 设置默认最大最小时间 | ||
| 189 | + if (data_minvalue.split(" ")[1]) { | ||
| 190 | + minTime.value = data_minvalue.split(" ")[1]; | ||
| 191 | + } | ||
| 192 | + if (data_maxvalue.split(" ")[1]) { | ||
| 193 | + maxTime.value = data_maxvalue.split(" ")[1]; | ||
| 194 | + } | ||
| 142 | break; | 195 | break; |
| 143 | case "YYYY-MM-DD HH:mm": | 196 | case "YYYY-MM-DD HH:mm": |
| 144 | columns_date_type.value = ['year', 'month', 'day'] | 197 | columns_date_type.value = ['year', 'month', 'day'] |
| ... | @@ -146,6 +199,13 @@ onMounted(() => { | ... | @@ -146,6 +199,13 @@ onMounted(() => { |
| 146 | // 设置默认值 | 199 | // 设置默认值 |
| 147 | currentDate.value = [Year, Month, Day]; | 200 | currentDate.value = [Year, Month, Day]; |
| 148 | currentTime.value = [Hour, Minute]; | 201 | currentTime.value = [Hour, Minute]; |
| 202 | + // 设置默认最大最小时间 | ||
| 203 | + if (data_minvalue.split(" ")[1]) { | ||
| 204 | + minTime.value = data_minvalue.split(" ")[1]; | ||
| 205 | + } | ||
| 206 | + if (data_maxvalue.split(" ")[1]) { | ||
| 207 | + maxTime.value = data_maxvalue.split(" ")[1]; | ||
| 208 | + } | ||
| 149 | break; | 209 | break; |
| 150 | case "YYYY-MM-DD HH:mm:ss": | 210 | case "YYYY-MM-DD HH:mm:ss": |
| 151 | columns_date_type.value = ['year', 'month', 'day'] | 211 | columns_date_type.value = ['year', 'month', 'day'] |
| ... | @@ -153,30 +213,27 @@ onMounted(() => { | ... | @@ -153,30 +213,27 @@ onMounted(() => { |
| 153 | // 设置默认值 | 213 | // 设置默认值 |
| 154 | currentDate.value = [Year, Month, Day]; | 214 | currentDate.value = [Year, Month, Day]; |
| 155 | currentTime.value = [Hour, Minute, Second]; | 215 | currentTime.value = [Hour, Minute, Second]; |
| 216 | + // 设置默认最大最小日期 | ||
| 217 | + if (data_minvalue.split(" ")[0].length) { | ||
| 218 | + const min = data_minvalue.split(" ")[0].split("-"); | ||
| 219 | + minDate.value = new Date(+min[0], +min[1] - 1, +min[2]); | ||
| 220 | + } | ||
| 221 | + if (data_maxvalue.split(" ")[0].length) { | ||
| 222 | + const max = data_maxvalue.split(" ")[0].split("-") | ||
| 223 | + maxDate.value = new Date(+max[0], +max[1] - 1, +max[2]) | ||
| 224 | + } | ||
| 225 | + // 设置默认最大最小时间 | ||
| 226 | + if (data_minvalue.split(" ")[1]) { | ||
| 227 | + minTime.value = data_minvalue.split(" ")[1]; | ||
| 228 | + } | ||
| 229 | + if (data_maxvalue.split(" ")[1]) { | ||
| 230 | + maxTime.value = data_maxvalue.split(" ")[1]; | ||
| 231 | + } | ||
| 156 | break; | 232 | break; |
| 157 | } | 233 | } |
| 158 | - // 设置默认最大最小日期 | ||
| 159 | - if (data_minvalue.split(" ")[0].length) { | ||
| 160 | - const min = data_minvalue.split(" ")[0].split("-") | ||
| 161 | - if (date_format === 'YYYY-MM') { | ||
| 162 | - minDate.value = new Date(+min[0], +min[1] - 1) | ||
| 163 | - } else { | ||
| 164 | - minDate.value = new Date(+min[0], +min[1] - 1, +min[2]) | ||
| 165 | - } | ||
| 166 | - } | ||
| 167 | - if (data_maxvalue.split(" ")[0].length) { | ||
| 168 | - const max = data_maxvalue.split(" ")[0].split("-") | ||
| 169 | - if (date_format === 'YYYY-MM') { | ||
| 170 | - maxDate.value = new Date(+max[0], +max[1] - 1) | ||
| 171 | - } else { | ||
| 172 | - maxDate.value = new Date(+max[0], +max[1] - 1, +max[2]) | ||
| 173 | - } | ||
| 174 | - } | ||
| 175 | }); | 234 | }); |
| 176 | 235 | ||
| 177 | const required = props.item.component_props.required; | 236 | const required = props.item.component_props.required; |
| 178 | -const data_minvalue = props.item.component_props.data_minvalue; | ||
| 179 | -const data_maxvalue = props.item.component_props.data_maxvalue; | ||
| 180 | const validator = (val) => { | 237 | const validator = (val) => { |
| 181 | if (required && !val) { | 238 | if (required && !val) { |
| 182 | return false; | 239 | return false; | ... | ... |
-
Please register or login to post a comment