This commit is contained in:
lzc 2025-03-31 14:44:34 +08:00
commit 4c6569db65
6 changed files with 71 additions and 27 deletions

View File

@ -10,15 +10,6 @@ export function GetEntityList(params = {}) {
});
}
/**
* @Title: 根据字典类型查询字典数据信息
*/
export function GetDict(dictType) {
return request(`/system/dict/data/list/${dictType}`, {
method: 'GET',
});
}
/**
* @Title: 新增
*/
@ -47,3 +38,12 @@ export function DeleteEntity(params = {}) {
method: 'DELETE',
});
}
/**
* @Title: 根据字典类型查询字典数据信息
*/
export function GetDict(dictType) {
return request(`/system/dict/data/list/${dictType}`, {
method: 'GET',
});
}

View File

@ -10,15 +10,6 @@ export function GetEntityList(params = {}) {
});
}
/**
* @Title: 信息
*/
export function GetEntity(dictId) {
return request(`/system/dict/type/list/${dictId}`, {
method: 'GET',
});
}
/**
* @Title: 新增
*/
@ -56,3 +47,12 @@ export function GetEntityOption() {
method: 'GET',
});
}
/**
* @Title: 信息
*/
export function GetDictType(dictId) {
return request(`/system/dict/type/list/${dictId}`, {
method: 'GET',
});
}

View File

@ -3,7 +3,7 @@
* @Author: zenghua.wang
* @Date: 2022-02-23 21:12:37
* @LastEditors: zenghua.wang
* @LastEditTime: 2025-03-27 15:43:36
* @LastEditTime: 2025-03-28 14:18:58
*/
import lodash from 'lodash';
import dayjs from 'dayjs';
@ -123,6 +123,16 @@ export const setDicLabel = (dicData, value) => {
}
return label;
};
/**
* @Title 设置字段显隐
* @param {*} column
* @param {*} fields
*/
export const setPropDisplay = (column, fields) => {
column.forEach((item) => {
item.display = fields.includes(item.prop) ? false : true;
});
};
/**
* @Title 将tree数据结构打平
* @param {*} tree
@ -283,6 +293,38 @@ export const getTree = (data, id = 'id', parentId = 'parentId', children = 'chil
return tree;
};
/**
* @Title 根据节点 id 查找其父级祖父级等所有上级节点 id
* @param {*} treeData
* @param {*} targetId
* @returns
*/
export const getParentIds = (treeData, targetId, id = 'id', children = 'children') => {
const parentMap = {};
function buildParentMap(node, parentId = null) {
if (node[id]) {
parentMap[node[id]] = parentId;
}
if (node[children]) {
for (const child of node[children]) {
buildParentMap(child, node[id]);
}
}
}
for (const rootNode of treeData) {
buildParentMap(rootNode);
}
const parentIds = [];
let currentId = targetId;
while (parentMap[currentId] !== null) {
parentIds.push(parentMap[currentId]);
currentId = parentMap[currentId];
}
return parentIds.reverse();
};
/**
* @Title 获取路由中的参数
* @param name

View File

@ -58,7 +58,7 @@ import { useApp } from '@/hooks';
import { CRUD_OPTIONS } from '@/config';
import { getLandTypeTree, landTypeSave, getLandType, exportLandType, delLandType, editLandType } from '@/apis/baseInfo';
import { useUserStore } from '@/store/modules/user';
import { isEmpty, flattenTree, setDicLabel, downloadFile } from '@/utils';
import { isEmpty, getParentIds, flattenTree, setDicLabel, downloadFile } from '@/utils';
const { VITE_APP_BASE_API } = import.meta.env;
const app = useApp();
@ -125,7 +125,7 @@ const state = reactive({
dicHeaders: {
authorization: UserStore.token,
},
dicFormatter: (res) => [{ id: null, landType: '土地分类', children: res.data }],
dicFormatter: (res) => [{ id: '0', landType: '土地分类', children: res.data }],
span: 24,
rules: [
{
@ -188,7 +188,7 @@ watch(
if (!isEmpty(val)) {
const list = flattenTree(val);
treeDicData.value = list.map((item) => {
return { label: item.landType, value: item.id };
return { label: item.landType, value: item.id, id: item.id, parentId: item.pid };
});
}
}
@ -198,7 +198,7 @@ const getLandTree = async () => {
try {
const res = await getLandTypeTree();
if (res.code == 200) {
treeData.value = [{ id: null, landType: '土地分类', children: res.data }];
treeData.value = [{ id: '0', landType: '土地分类', children: res.data }];
}
} catch (err) {
app.$message.error(err.msg);
@ -210,7 +210,7 @@ getLandTree();
const loadData = () => {
state.loading = true;
getLandType({
pid: treeSelected.value?.id ?? null,
pid: treeSelected.value?.id ?? '0',
...state.query,
})
.then((res) => {
@ -307,7 +307,7 @@ async function rowDel(row, done, loading) {
const setPid = (row) => {
if (!isEmpty(row.pids)) {
const len = row.pids.length;
row.pid = row?.pids[len - 1] ?? null;
row.pid = row?.pids[len - 1] ?? '0';
}
};
@ -333,6 +333,8 @@ const rowSave = async (row, done, loading) => {
//
const rowEdit = (row) => {
row.pids = getParentIds(treeData.value, row.id);
console.log('pids=', row.pids);
crudRef.value && crudRef.value.rowEdit(row);
};

View File

@ -112,7 +112,7 @@ const state = reactive({
value: '0',
rules: {
required: true,
message: '请输入',
message: '请选择',
trigger: 'blur',
},
},

View File

@ -83,7 +83,7 @@ const state = reactive({
value: '0',
rules: {
required: true,
message: '请输入',
message: '请选择',
trigger: 'blur',
},
},