Skip to content

Commit

Permalink
feat(dict-component): 字典相关组件的props:data 属性支持传入函数
Browse files Browse the repository at this point in the history
  • Loading branch information
kanyxmo committed Nov 16, 2024
1 parent a50284c commit 321e507
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
5 changes: 3 additions & 2 deletions web/src/components/ma-dict-picker/ma-dict-checkbox.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<script setup lang="ts">
import type { Dictionary } from '#/global'
import type { TransType } from '@/hooks/auto-imports/useTrans.ts'
import { isFunction } from 'radash'

defineOptions({ name: 'MaDictCheckbox' })

Expand All @@ -22,15 +23,15 @@ const {
// 字典名称
dictName?: string
// 字典数据
data?: Dictionary[]
data?: Dictionary[] | (() => Dictionary[])
// 渲染模式:`normal: el-checkbox` | `button: el-checkbox-button`
renderMode?: 'normal' | 'button'
// 翻译范围
transScope?: 'global' | 'local'
}>()
const dictStore = useDictStore()
const dictionaryData = computed<Dictionary[] | null>(() => {
return dictName === '' ? data : dictStore.find(dictName)
return dictName === '' ? (isFunction(data) ? data() : data) : dictStore.find(dictName)
})

const i18n = useTrans() as TransType
Expand Down
5 changes: 3 additions & 2 deletions web/src/components/ma-dict-picker/ma-dict-radio.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<script setup lang="ts">
import type { Dictionary } from '#/global'
import type { TransType } from '@/hooks/auto-imports/useTrans.ts'
import { isFunction } from 'radash'

defineOptions({ name: 'MaDictRadio' })

Expand All @@ -22,15 +23,15 @@ const {
// 字典名称
dictName?: string
// 字典数据
data?: Dictionary[]
data?: Dictionary[] | (() => Dictionary[])
// 渲染模式:`normal: el-radio` | `button: el-radio-button`
renderMode?: 'normal' | 'button'
// 翻译范围
transScope?: 'global' | 'local'
}>()
const dictStore = useDictStore()
const dictionaryData = computed<Dictionary[] | null>(() => {
return dictName === '' ? data : dictStore.find(dictName)
return dictName === '' ? (isFunction(data) ? data() : data) : dictStore.find(dictName)
})

const i18n = useTrans() as TransType
Expand Down
5 changes: 3 additions & 2 deletions web/src/components/ma-dict-picker/ma-dict-select.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<script setup lang="ts">
import type { Dictionary } from '#/global'
import type { TransType } from '@/hooks/auto-imports/useTrans.ts'
import { isFunction } from 'radash'

defineOptions({ name: 'MaDictSelect' })

Expand All @@ -21,14 +22,14 @@ const {
// 字典名称
dictName?: string
// 字典数据
data?: Dictionary[]
data?: Dictionary[] | (() => Dictionary[])
// 翻译范围
transScope?: 'global' | 'local'
}>()

const dictStore = useDictStore()
const dictionaryData = computed<Dictionary[] | null>(() => {
return dictName === '' ? data : dictStore.find(dictName)
return dictName === '' ? (isFunction(data) ? data() : data) : dictStore.find(dictName)
})

const i18n = useTrans() as TransType
Expand Down

0 comments on commit 321e507

Please sign in to comment.