Showing
3 changed files
with
18 additions
and
7 deletions
| 1 | <!-- | 1 | <!-- |
| 2 | * @Date: 2023-03-29 14:55:46 | 2 | * @Date: 2023-03-29 14:55:46 |
| 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com | 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com |
| 4 | - * @LastEditTime: 2024-06-06 15:53:10 | 4 | + * @LastEditTime: 2024-07-01 11:53:37 |
| 5 | * @FilePath: /data-table/src/components/PickerField/MyComponent.vue | 5 | * @FilePath: /data-table/src/components/PickerField/MyComponent.vue |
| 6 | * @Description: 文件描述 | 6 | * @Description: 文件描述 |
| 7 | --> | 7 | --> |
| ... | @@ -34,6 +34,7 @@ import { useCustomFieldValue } from '@vant/use'; | ... | @@ -34,6 +34,7 @@ import { useCustomFieldValue } from '@vant/use'; |
| 34 | 34 | ||
| 35 | // 获取父组件传值 | 35 | // 获取父组件传值 |
| 36 | const props = inject('props'); | 36 | const props = inject('props'); |
| 37 | +const emit = defineEmits(["active"]); | ||
| 37 | 38 | ||
| 38 | const showPicker = ref(false); | 39 | const showPicker = ref(false); |
| 39 | const picker_value = ref(props.component_props.default); | 40 | const picker_value = ref(props.component_props.default); |
| ... | @@ -45,11 +46,12 @@ const onClick = () => { | ... | @@ -45,11 +46,12 @@ const onClick = () => { |
| 45 | }; | 46 | }; |
| 46 | 47 | ||
| 47 | const onConfirm = ({ selectedOptions }) => { | 48 | const onConfirm = ({ selectedOptions }) => { |
| 49 | + // console.warn(props); | ||
| 48 | picker_value.value = selectedOptions[0]?.value; | 50 | picker_value.value = selectedOptions[0]?.value; |
| 49 | showPicker.value = false; | 51 | showPicker.value = false; |
| 50 | // 触发点自定义监听事件,配合规则显示隐藏其他字段 | 52 | // 触发点自定义监听事件,配合规则显示隐藏其他字段 |
| 51 | - // props.item.value = { key: props.item.key, value: picker_value.value, type: "picker" }; | 53 | + props.value = { key: props.key, value: picker_value.value, type: "picker" }; |
| 52 | - // emit("active", props.item.value); | 54 | + emit("active", props.value); |
| 53 | // if (add_info_key.value === props.item.value) { | 55 | // if (add_info_key.value === props.item.value) { |
| 54 | // has_add_info.value = true; | 56 | // has_add_info.value = true; |
| 55 | // } | 57 | // } | ... | ... |
| 1 | <!-- | 1 | <!-- |
| 2 | * @Date: 2022-08-30 13:46:51 | 2 | * @Date: 2022-08-30 13:46:51 |
| 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com | 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com |
| 4 | - * @LastEditTime: 2023-03-29 15:07:12 | 4 | + * @LastEditTime: 2024-07-01 12:33:33 |
| 5 | * @FilePath: /data-table/src/components/PickerField/index.vue | 5 | * @FilePath: /data-table/src/components/PickerField/index.vue |
| 6 | * @Description: 单列选择器组件 | 6 | * @Description: 单列选择器组件 |
| 7 | --> | 7 | --> |
| ... | @@ -13,7 +13,7 @@ | ... | @@ -13,7 +13,7 @@ |
| 13 | </div> | 13 | </div> |
| 14 | <van-field :name="item.name" :rules="item.rules" style="padding: 0;"> | 14 | <van-field :name="item.name" :rules="item.rules" style="padding: 0;"> |
| 15 | <template #input> | 15 | <template #input> |
| 16 | - <my-component /> | 16 | + <my-component @active="onActive" /> |
| 17 | </template> | 17 | </template> |
| 18 | </van-field> | 18 | </van-field> |
| 19 | </div> | 19 | </div> |
| ... | @@ -25,6 +25,7 @@ import MyComponent from './MyComponent.vue'; | ... | @@ -25,6 +25,7 @@ import MyComponent from './MyComponent.vue'; |
| 25 | const props = defineProps({ | 25 | const props = defineProps({ |
| 26 | item: Object, | 26 | item: Object, |
| 27 | }); | 27 | }); |
| 28 | +const emit = defineEmits(["active"]); | ||
| 28 | 29 | ||
| 29 | // 注入子组件属性 | 30 | // 注入子组件属性 |
| 30 | provide('props', props.item); | 31 | provide('props', props.item); |
| ... | @@ -32,7 +33,12 @@ provide('props', props.item); | ... | @@ -32,7 +33,12 @@ provide('props', props.item); |
| 32 | // 隐藏显示 | 33 | // 隐藏显示 |
| 33 | const HideShow = computed(() => { | 34 | const HideShow = computed(() => { |
| 34 | return !props.item.component_props.disabled | 35 | return !props.item.component_props.disabled |
| 35 | -}) | 36 | +}); |
| 37 | + | ||
| 38 | +// 子组件通信,适配规则触发 | ||
| 39 | +const onActive = (val) => { | ||
| 40 | + emit("active", val); | ||
| 41 | +}; | ||
| 36 | 42 | ||
| 37 | </script> | 43 | </script> |
| 38 | 44 | ... | ... |
| 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: 2024-06-28 17:07:28 | 4 | + * @LastEditTime: 2024-07-01 12:32:31 |
| 5 | * @FilePath: /data-table/src/views/index.vue | 5 | * @FilePath: /data-table/src/views/index.vue |
| 6 | * @Description: 首页 | 6 | * @Description: 首页 |
| 7 | --> | 7 | --> |
| ... | @@ -831,6 +831,9 @@ const onActive = (item) => { | ... | @@ -831,6 +831,9 @@ const onActive = (item) => { |
| 831 | if (item?.type === "volunteer_group") { // 义工组别选择控件 | 831 | if (item?.type === "volunteer_group") { // 义工组别选择控件 |
| 832 | postData.value = _.assign(postData.value, { [item.key]: item.affix ? item.affix : item.value }); | 832 | postData.value = _.assign(postData.value, { [item.key]: item.affix ? item.affix : item.value }); |
| 833 | } | 833 | } |
| 834 | + if (item?.type === "picker") { // 下拉框控件 | ||
| 835 | + postData.value[item.key] = item.value; | ||
| 836 | + } | ||
| 834 | // 检查规则,会影响字段显示 | 837 | // 检查规则,会影响字段显示 |
| 835 | checkRules(); | 838 | checkRules(); |
| 836 | }; | 839 | }; | ... | ... |
-
Please register or login to post a comment