Showing
4 changed files
with
90 additions
and
18 deletions
src/components/TimePickerField/index.vue
0 → 100644
| 1 | +<!-- | ||
| 2 | + * @Date: 2022-08-31 11:45:30 | ||
| 3 | + * @LastEditors: hookehuyr hookehuyr@gmail.com | ||
| 4 | + * @LastEditTime: 2022-09-08 10:06:46 | ||
| 5 | + * @FilePath: /data-table/src/components/TimePickerField/index.vue | ||
| 6 | + * @Description: 日期选择组件 | ||
| 7 | +--> | ||
| 8 | +<template> | ||
| 9 | + <div class="time-picker-field"> | ||
| 10 | + <div class="label">{{ item.label }}<span v-if="item.required"> *</span></div> | ||
| 11 | + <van-field v-model="item.value" is-link readonly :name="item.key" :required="item.required" | ||
| 12 | + :placeholder="item.placeholder" :rules="item.rules" @click="showPicker = true" /> | ||
| 13 | + <van-popup v-model:show="showPicker" position="bottom"> | ||
| 14 | + <van-time-picker v-model="currentTime" :title="item.component_props.title" :columns-type="item.component_props.columns_type" @confirm="onConfirm" | ||
| 15 | + @cancel="showPicker = false" /> | ||
| 16 | + </van-popup> | ||
| 17 | + </div> | ||
| 18 | +</template> | ||
| 19 | + | ||
| 20 | +<script setup> | ||
| 21 | +import dayjs from 'dayjs'; | ||
| 22 | + | ||
| 23 | +const props = defineProps({ | ||
| 24 | + item: Object | ||
| 25 | +}) | ||
| 26 | + | ||
| 27 | +const showPicker = ref(false); | ||
| 28 | +const currentTime = ref([]); | ||
| 29 | + | ||
| 30 | +const onConfirm = ({ selectedValues, selectedOptions }) => { | ||
| 31 | + props.item.value = selectedValues[0] + ':' + selectedValues[1]; | ||
| 32 | + showPicker.value = false; | ||
| 33 | +}; | ||
| 34 | + | ||
| 35 | +onMounted(() => { | ||
| 36 | + currentTime.value = props.item.value.split(':') | ||
| 37 | +}) | ||
| 38 | +</script> | ||
| 39 | + | ||
| 40 | +<style lang="less" scoped> | ||
| 41 | +.time-picker-field { | ||
| 42 | + .label { | ||
| 43 | + padding: 1rem 1rem 0 1rem; | ||
| 44 | + font-size: 0.9rem; | ||
| 45 | + font-weight: bold; | ||
| 46 | + | ||
| 47 | + span { | ||
| 48 | + color: red; | ||
| 49 | + } | ||
| 50 | + } | ||
| 51 | +} | ||
| 52 | +</style> |
| ... | @@ -7,6 +7,7 @@ import CheckboxField from '@/components/CheckboxField/index.vue' | ... | @@ -7,6 +7,7 @@ import CheckboxField from '@/components/CheckboxField/index.vue' |
| 7 | import PickerField from '@/components/PickerField/index.vue' | 7 | import PickerField from '@/components/PickerField/index.vue' |
| 8 | import AreaPickerField from '@/components/AreaPickerField/index.vue' | 8 | import AreaPickerField from '@/components/AreaPickerField/index.vue' |
| 9 | import DatePickerField from '@/components/DatePickerField/index.vue' | 9 | import DatePickerField from '@/components/DatePickerField/index.vue' |
| 10 | +import TimePickerField from '@/components/TimePickerField/index.vue' | ||
| 10 | import ImageUploaderField from '@/components/ImageUploaderField/index.vue' | 11 | import ImageUploaderField from '@/components/ImageUploaderField/index.vue' |
| 11 | import PhoneField from '@/components/PhoneField/index.vue' | 12 | import PhoneField from '@/components/PhoneField/index.vue' |
| 12 | import EmailField from '@/components/EmailField/index.vue' | 13 | import EmailField from '@/components/EmailField/index.vue' |
| ... | @@ -22,6 +23,7 @@ import SignField from '@/components/SignField/index.vue' | ... | @@ -22,6 +23,7 @@ import SignField from '@/components/SignField/index.vue' |
| 22 | * @type picker 单列选择器 PickerField | 23 | * @type picker 单列选择器 PickerField |
| 23 | * @type area_picker 地址选择器 AreaPickerField | 24 | * @type area_picker 地址选择器 AreaPickerField |
| 24 | * @type date_picker 日期选择器 DatePickerField | 25 | * @type date_picker 日期选择器 DatePickerField |
| 26 | + * @type time_picker 时间选择器 TimePickerField | ||
| 25 | * @type image_uploader 图片上传 ImageUploaderField | 27 | * @type image_uploader 图片上传 ImageUploaderField |
| 26 | * @type phone 手机输入框 PhoneField | 28 | * @type phone 手机输入框 PhoneField |
| 27 | * @type email 邮箱输入框 EmailField | 29 | * @type email 邮箱输入框 EmailField |
| ... | @@ -66,6 +68,9 @@ export function createComponentType(data) { | ... | @@ -66,6 +68,9 @@ export function createComponentType(data) { |
| 66 | if (item.component_props.name === 'date_picker') { | 68 | if (item.component_props.name === 'date_picker') { |
| 67 | item.component = DatePickerField; | 69 | item.component = DatePickerField; |
| 68 | } | 70 | } |
| 71 | + if (item.component_props.name === 'time_picker') { | ||
| 72 | + item.component = TimePickerField; | ||
| 73 | + } | ||
| 69 | if (item.component_props.name === 'image_uploader') { | 74 | if (item.component_props.name === 'image_uploader') { |
| 70 | item.component = ImageUploaderField; | 75 | item.component = ImageUploaderField; |
| 71 | } | 76 | } | ... | ... |
| ... | @@ -2,12 +2,12 @@ | ... | @@ -2,12 +2,12 @@ |
| 2 | * @Author: hookehuyr hookehuyr@gmail.com | 2 | * @Author: hookehuyr hookehuyr@gmail.com |
| 3 | * @Date: 2022-05-31 12:06:19 | 3 | * @Date: 2022-05-31 12:06:19 |
| 4 | * @LastEditors: hookehuyr hookehuyr@gmail.com | 4 | * @LastEditors: hookehuyr hookehuyr@gmail.com |
| 5 | - * @LastEditTime: 2022-09-07 15:14:40 | 5 | + * @LastEditTime: 2022-09-08 10:05:14 |
| 6 | * @FilePath: /data-table/src/main.js | 6 | * @FilePath: /data-table/src/main.js |
| 7 | * @Description: | 7 | * @Description: |
| 8 | */ | 8 | */ |
| 9 | import { createApp } from 'vue'; | 9 | import { createApp } from 'vue'; |
| 10 | -import { Button, Image as VanImage, Col, Row, Icon, Form, Field, CellGroup, ConfigProvider, Toast, Uploader, Empty, Tab, Tabs, Overlay, NumberKeyboard, Lazyload, List, PullRefresh, Popup, Picker, Sticky, Stepper, Tag, Swipe, SwipeItem, Dialog, ActionSheet, Loading, Checkbox, Search, NavBar, Collapse, CollapseItem, RadioGroup, Radio, CheckboxGroup, Area, DatePicker } from 'vant'; | 10 | +import { Button, Image as VanImage, Col, Row, Icon, Form, Field, CellGroup, ConfigProvider, Toast, Uploader, Empty, Tab, Tabs, Overlay, NumberKeyboard, Lazyload, List, PullRefresh, Popup, Picker, Sticky, Stepper, Tag, Swipe, SwipeItem, Dialog, ActionSheet, Loading, Checkbox, Search, NavBar, Collapse, CollapseItem, RadioGroup, Radio, CheckboxGroup, Area, DatePicker, TimePicker } from 'vant'; |
| 11 | import router from './router'; | 11 | import router from './router'; |
| 12 | import App from './App.vue'; | 12 | import App from './App.vue'; |
| 13 | // import axios from './utils/axios'; | 13 | // import axios from './utils/axios'; |
| ... | @@ -25,6 +25,6 @@ app.config.warnHandler = () => null; | ... | @@ -25,6 +25,6 @@ app.config.warnHandler = () => null; |
| 25 | 25 | ||
| 26 | app.config.globalProperties.$http = axios; // 关键语句 | 26 | app.config.globalProperties.$http = axios; // 关键语句 |
| 27 | 27 | ||
| 28 | -app.use(pinia).use(router).use(Button).use(VanImage).use(Col).use(Row).use(Icon).use(Form).use(Field).use(CellGroup).use(Toast).use(Uploader).use(Empty).use(Tab).use(Tabs).use(Overlay).use(NumberKeyboard).use(Lazyload).use(List).use(PullRefresh).use(Popup).use(Picker).use(Sticky).use(Stepper).use(Tag).use(Swipe).use(SwipeItem).use(Dialog).use(ActionSheet).use(Loading).use(Checkbox).use(Search).use(ConfigProvider).use(NavBar).use(Collapse).use(CollapseItem).use(Radio).use(RadioGroup).use(CheckboxGroup).use(Area).use(DatePicker); | 28 | +app.use(pinia).use(router).use(Button).use(VanImage).use(Col).use(Row).use(Icon).use(Form).use(Field).use(CellGroup).use(Toast).use(Uploader).use(Empty).use(Tab).use(Tabs).use(Overlay).use(NumberKeyboard).use(Lazyload).use(List).use(PullRefresh).use(Popup).use(Picker).use(Sticky).use(Stepper).use(Tag).use(Swipe).use(SwipeItem).use(Dialog).use(ActionSheet).use(Loading).use(Checkbox).use(Search).use(ConfigProvider).use(NavBar).use(Collapse).use(CollapseItem).use(Radio).use(RadioGroup).use(CheckboxGroup).use(Area).use(DatePicker).use(TimePicker); |
| 29 | app.use(vueEsign) | 29 | app.use(vueEsign) |
| 30 | app.mount('#app'); | 30 | app.mount('#app'); | ... | ... |
| 1 | <!-- | 1 | <!-- |
| 2 | * @Date: 2022-07-18 10:22:22 | 2 | * @Date: 2022-07-18 10:22:22 |
| 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com | 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com |
| 4 | - * @LastEditTime: 2022-09-07 16:47:28 | 4 | + * @LastEditTime: 2022-09-08 10:17:43 |
| 5 | * @FilePath: /data-table/src/views/index.vue | 5 | * @FilePath: /data-table/src/views/index.vue |
| 6 | * @Description: 首页 | 6 | * @Description: 首页 |
| 7 | --> | 7 | --> |
| ... | @@ -138,17 +138,17 @@ onMounted(() => { | ... | @@ -138,17 +138,17 @@ onMounted(() => { |
| 138 | // ], | 138 | // ], |
| 139 | // required: true, | 139 | // required: true, |
| 140 | // }, | 140 | // }, |
| 141 | - { | 141 | + // { |
| 142 | - key: 'sign', | 142 | + // key: 'sign', |
| 143 | - value: '', | 143 | + // value: '', |
| 144 | - label: '电子签名', | 144 | + // label: '电子签名', |
| 145 | - placeholder: '', | 145 | + // placeholder: '', |
| 146 | - component: '', | 146 | + // component: '', |
| 147 | - component_props: { | 147 | + // component_props: { |
| 148 | - name: 'sign', | 148 | + // name: 'sign', |
| 149 | - }, | 149 | + // }, |
| 150 | - required: true, | 150 | + // required: true, |
| 151 | - }, | 151 | + // }, |
| 152 | // { | 152 | // { |
| 153 | // key: 'city', | 153 | // key: 'city', |
| 154 | // value: '天津市/天津市/和平区', | 154 | // value: '天津市/天津市/和平区', |
| ... | @@ -172,6 +172,18 @@ onMounted(() => { | ... | @@ -172,6 +172,18 @@ onMounted(() => { |
| 172 | // columns_type: ['year', 'month'] | 172 | // columns_type: ['year', 'month'] |
| 173 | // }, | 173 | // }, |
| 174 | // }, | 174 | // }, |
| 175 | + { | ||
| 176 | + key: 'time', | ||
| 177 | + value: '', | ||
| 178 | + label: '时间选择', | ||
| 179 | + placeholder: '请选择时间', | ||
| 180 | + component_props: { | ||
| 181 | + name: 'time_picker', | ||
| 182 | + title: '请选择', | ||
| 183 | + columns_type: ['hour', 'minute'] | ||
| 184 | + }, | ||
| 185 | + required: true, | ||
| 186 | + }, | ||
| 175 | // { | 187 | // { |
| 176 | // key: 'image_src', | 188 | // key: 'image_src', |
| 177 | // value: '', | 189 | // value: '', |
| ... | @@ -192,11 +204,11 @@ const sign = ref(null); | ... | @@ -192,11 +204,11 @@ const sign = ref(null); |
| 192 | const onSubmit = (values) => { | 204 | const onSubmit = (values) => { |
| 193 | // 合并自定义字段到提交表单字段 | 205 | // 合并自定义字段到提交表单字段 |
| 194 | postData.value = _.assign(postData.value, values); | 206 | postData.value = _.assign(postData.value, values); |
| 195 | - // console.warn(postData.value); | ||
| 196 | // console.warn(mockData.value); | 207 | // console.warn(mockData.value); |
| 197 | // 检查非表单输入项 | 208 | // 检查非表单输入项 |
| 198 | if (validOther()) { // 通过验证 | 209 | if (validOther()) { // 通过验证 |
| 199 | console.warn('通过验证'); | 210 | console.warn('通过验证'); |
| 211 | + console.warn(postData.value); | ||
| 200 | } else { | 212 | } else { |
| 201 | console.warn('不通过验证'); | 213 | console.warn('不通过验证'); |
| 202 | } | 214 | } |
| ... | @@ -210,8 +222,11 @@ const onActive = (item) => { | ... | @@ -210,8 +222,11 @@ const onActive = (item) => { |
| 210 | } | 222 | } |
| 211 | 223 | ||
| 212 | const validOther = () => { | 224 | const validOther = () => { |
| 213 | - // 检查电子签名输入项 | 225 | + // 检验没有绑定name的输入项 |
| 214 | - const flag = sign.value[0].validSign(); | 226 | + let flag = true; |
| 227 | + if (sign.value) { // 检验电子签名 | ||
| 228 | + flag = sign.value[0].validSign(); | ||
| 229 | + } | ||
| 215 | return flag; | 230 | return flag; |
| 216 | } | 231 | } |
| 217 | </script> | 232 | </script> | ... | ... |
-
Please register or login to post a comment