dictionary.js 582 B

12345678910111213141516171819
  1. import { useDictionaryStore } from '@/pinia/modules/dictionary'
  2. // 获取字典方法 使用示例 getDict('sex').then(res) 或者 async函数下 const res = await getDict('sex')
  3. export const getDict = async(type) => {
  4. const dictionaryStore = useDictionaryStore()
  5. await dictionaryStore.getDictionary(type)
  6. return dictionaryStore.dictionaryMap[type]
  7. }
  8. // 字典文字展示方法
  9. export const showDictLabel = (dict, code) => {
  10. if (!dict) {
  11. return ''
  12. }
  13. const dictMap = {}
  14. dict.forEach(item => {
  15. dictMap[item.value] = item.label
  16. })
  17. return dictMap[code]
  18. }