update
This commit is contained in:
vanhempi
65ee2fe0d7
commit
c705b591b1
@ -46,7 +46,7 @@
|
||||
:key="'component_' + col.prop"
|
||||
@update:modelValue="handleComponentModelUpdate(col.prop, $event)"
|
||||
:modelValue="dataForm[col.prop]"
|
||||
:mode="detailMode ? 'detail' : dataForm.id ? 'edit' : 'create' "
|
||||
:mode="detailMode ? 'detail' : dataForm.id ? 'edit' : 'create'"
|
||||
/>
|
||||
</div>
|
||||
<!-- add more... -->
|
||||
@ -71,7 +71,32 @@
|
||||
import { pick as __pick } from "@/utils/filters";
|
||||
|
||||
function reConstructTreeData(listObj) {
|
||||
Object.keys(listObj).forEach((id) => {});
|
||||
// O(2n)
|
||||
|
||||
// 数据重排
|
||||
Object.keys(listObj).map((key) => {
|
||||
const currentNode = listObj[key];
|
||||
if (currentNode.parentId === "0") return // return { label: currentNode.name, value: currentNode.id, children: currentNode.children ?? [] };
|
||||
|
||||
const parentNode = listObj[currentNode.parentId];
|
||||
if (!parentNode.children) {
|
||||
parentNode.children = [];
|
||||
}
|
||||
parentNode.children.push(currentNode);
|
||||
});
|
||||
|
||||
// 数据整理
|
||||
function recursive(list) {
|
||||
// TODO: 2023.2.2
|
||||
list.forEach(item => {
|
||||
if (item.children) recursive(item.children)
|
||||
})
|
||||
}
|
||||
|
||||
return Object.keys(listObj).map(key => {
|
||||
const currentNode = listObj[key];
|
||||
if (currentNode.children) recursive(currentNode.children)
|
||||
})
|
||||
}
|
||||
|
||||
export default {
|
||||
@ -108,15 +133,16 @@ export default {
|
||||
// dataForm[col.prop] = col.default ?? null; // not perfect!
|
||||
});
|
||||
else if (col.fetchTreeData)
|
||||
// 获取设备类型时触发的,用于前端构建属性结构,约定,parentId 为0时是顶级节点
|
||||
col.fetchTreeData().then(({ data: res }) => {
|
||||
console.log("[Fetch Tree Data]", res.data.list);
|
||||
if (res.code === 0 && res.data.list) {
|
||||
// 把数据先重构成一个对象
|
||||
// 先把数据先重构成一个对象
|
||||
const obj = {};
|
||||
res.data.list.map((item) => {
|
||||
obj[item.id] = item;
|
||||
});
|
||||
// 过滤这个对象
|
||||
// 再过滤这个对象
|
||||
let filteredList = reConstructTreeData(obj);
|
||||
// 最后设置 options
|
||||
this.$set(col, "options", filteredList);
|
||||
|
@ -82,9 +82,9 @@ export default function () {
|
||||
// fetchData() 获取普通列表数据
|
||||
// fetchTreeData() 获取需要展示层级结构的数据
|
||||
fetchTreeData: () => {
|
||||
// TODO:前提是工厂里总的设备类型数不会超过 999
|
||||
return this.$http.get('/pms/equipmentType/page', {
|
||||
// TODO:前提是工厂里总的设备类型数不会超过 999
|
||||
limit: 999, page: 1, key: ""
|
||||
params: { limit: 999, page: 1, key: "" }
|
||||
})
|
||||
},
|
||||
label: "父类",
|
||||
|
Ladataan…
Viittaa uudesa ongelmassa
Block a user