Explorar o código

feat: 字典类型处理 毛坯

lanceJiang hai 1 ano
pai
achega
8764e2124d

+ 1 - 0
src/api/system/dict.ts

@@ -60,6 +60,7 @@ function dictDeleteApi(data: any): AxiosPromise {
 export default {
 	dictPageApi,
 	dictListParentApi,
+	dictListSelectOptionApi,
 	dictAddOrEditSaveApi,
 	dictDeleteApi
 }

+ 8 - 2
src/components/packages/formEditor/index.vue

@@ -175,8 +175,8 @@ const getDepartmentList = async () => {
 getDepartmentList()
 // 字典下拉配置
 const getDictParentList = async () => {
-	let data = await dict.dictListParentApi().then(res => {
-		return (res || []).map(v => {
+	let data = await dict.dictListParentApi().then(async res => {
+		const options = (res || []).map(v => {
 			return {
 				...v,
 				label: v.name,
@@ -185,6 +185,12 @@ const getDictParentList = async () => {
 				options: []
 			}
 		})
+		await Promise.all(options.map(v => dict.dictListSelectOptionApi(v.code))).then(codesOptions => {
+			options.map((v, i) => {
+				v.options = (codesOptions[i] || []).map(({ title, content }) => ({ label: title, value: content }))
+			})
+		})
+		return options
 	})
 	dictParentList.value = data
 }

+ 12 - 0
src/components/packages/hooks/use-props/index.js

@@ -6,6 +6,7 @@ import Region from '@ER/region/Region'
 import { areaList } from '@vant/area-data'
 import { useI18n } from '../use-i18n'
 import utils from '@ER/utils'
+// import dict from '@/api/system/dict'
 const findPosition = (node, parent) => {
 	for (let y = 0; y < parent.list.length; y++) {
 		const row = parent.list[y]
@@ -297,6 +298,16 @@ export const useProps = (state, data, isPc = true, isRoot = false, specialHandli
 				// 当前选中的值,如果是人员就获取人员的api,部门就获取部门的api
 				if ([2, 3].indexOf(renderType) > -1) {
 					result.options = options?.options
+				} else if (renderType === 4) {
+					// 字典类型
+					const _dictOption = (options?.options || []).find(v => v.code === options.dictCode)
+					// console.error(options?.options, 'options?.options  _dictOption', _dictOption)
+					/*if (_dictOption) {
+						if (!_dictOption.options.length) {
+							_dictOption.options = dict.dictListSelectOptionApi(options.dictCode).then(({ title, content }) => ({ label: title, value: content }))
+						}
+					}*/
+					result.options = _dictOption?.options
 				} else if (renderType === 1) {
 					result.options = _.get(state, `data[${options.dataKey}].list`, [])
 				}
@@ -387,6 +398,7 @@ export const useProps = (state, data, isPc = true, isRoot = false, specialHandli
 				break
 			case 'cascader':
 				if (renderType === 2) {
+					// 部门类型
 					result.options = options?.options
 				} else if (renderType === 1) {
 					result.options = _.get(state, `data[${options.dataKey}].list`, [])