Skip to content

Commit

Permalink
Merge pull request #145 from jujijigo/main
Browse files Browse the repository at this point in the history
优化crud组件的form-picker子组件
  • Loading branch information
kanyxmo authored Apr 2, 2024
2 parents ea16891 + 5df7412 commit 784b98a
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions src/components/ma-crud/components/searchFormItem/form-picker.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,31 +23,37 @@
</template>

<script setup>
import { ref, inject, watch } from 'vue'
import { inject, computed } from 'vue'
import { get, set } from 'lodash'
const props = defineProps({
component: Object,
})
const searchForm = inject('searchForm')
const emit = defineEmits(['update:modelValue'])

const getComponentName = () => {
if (['date', 'month', 'year', 'week', 'quarter', 'range', 'time'].includes(props.component.formType)) {
return `a-${props.component.formType}-picker`
}
}

let defaultValue

if (props.component.formType === 'range') {
defaultValue = props.component.searchDefaultValue ?? []
} else {
defaultValue = props.component.searchDefaultValue ?? ''
}

const value = ref(get(searchForm.value, props.component.dataIndex, defaultValue))
set(searchForm.value, props.component.dataIndex, value.value)

watch( () => get(searchForm.value, props.component.dataIndex), vl => value.value = vl )
watch( () => value.value, v => set(searchForm.value, props.component.dataIndex, v) )
const value = computed({
get() {
let val = get(searchForm.value, props.component.dataIndex)
if (val === undefined) {
if (props.component.formType === 'range') {
return props.component.searchDefaultValue ?? []
} else {
return props.component.searchDefaultValue ?? ''
}
} else {
return val
}
},
set(newVal) {
emit('update:modelValue', newVal)
set(searchForm.value, props.component.dataIndex, newVal)
}
})

</script>

0 comments on commit 784b98a

Please sign in to comment.