|
@@ -1,35 +1,40 @@
|
|
|
import useDictStore from '@/stores/dict.js'
|
|
|
import request from '@/utils/request.js'
|
|
|
-import { ref, toRefs } from 'vue'
|
|
|
+import {
|
|
|
+ ref,
|
|
|
+ toRefs
|
|
|
+} from 'vue'
|
|
|
|
|
|
/**
|
|
|
* 获取字典数据
|
|
|
*/
|
|
|
export function useDict(...args) {
|
|
|
- const res = ref({})
|
|
|
- return (() => {
|
|
|
- args.forEach((dictType, index) => {
|
|
|
- res.value[dictType] = []
|
|
|
- const dicts = useDictStore().getDict(dictType)
|
|
|
- if (dicts) {
|
|
|
- res.value[dictType] = dicts
|
|
|
- } else {
|
|
|
- request({
|
|
|
- url: '/sys/sys-dict/list2',
|
|
|
- data: {
|
|
|
- paterCode: dictType,
|
|
|
- },
|
|
|
- }).then((resp) => {
|
|
|
- res.value[dictType] = resp.map((p) => ({
|
|
|
- label: p.msg,
|
|
|
- value: p.value,
|
|
|
- elTagType: p.cssClass,
|
|
|
- elTagClass: p.cssClass,
|
|
|
- }))
|
|
|
- useDictStore().setDict(dictType, res.value[dictType])
|
|
|
- })
|
|
|
- }
|
|
|
- })
|
|
|
- return toRefs(res.value)
|
|
|
- })()
|
|
|
-}
|
|
|
+ const res = ref({})
|
|
|
+ return (() => {
|
|
|
+ args.forEach((dictType, index) => {
|
|
|
+ res.value[dictType] = []
|
|
|
+ const dicts = useDictStore().getDict(dictType)
|
|
|
+ if (dicts) {
|
|
|
+ res.value[dictType] = dicts
|
|
|
+ } else {
|
|
|
+ request({
|
|
|
+ url: '/sys/sys-dict/list2',
|
|
|
+ data: {
|
|
|
+ paterCode: dictType,
|
|
|
+ },
|
|
|
+ }).then((resp) => {
|
|
|
+ console.log('resp', resp)
|
|
|
+ res.value[dictType] = resp.map((p) => ({
|
|
|
+ label: p.msg,
|
|
|
+ value: p.value,
|
|
|
+ elTagType: p.cssClass,
|
|
|
+ elTagClass: p.cssClass,
|
|
|
+ }))
|
|
|
+ useDictStore().setDict(dictType, res.value[dictType])
|
|
|
+ })
|
|
|
+ }
|
|
|
+ })
|
|
|
+ console.log('res.value', res.value)
|
|
|
+ return toRefs(res.value)
|
|
|
+ })()
|
|
|
+}
|