20260726225220

This commit is contained in:
oneao committed 2026-07-26 22:52:21 +08:00
1 parent e3c7c6f8da
commit a8478d60ed
170 files changed
+6786 -1678

No files matched your search

@@ -7,6 +7,7 @@ import {
cloneData,
diffRows,
allocateTemporaryIds,
remapForeignKeys,
tableChange,
hasChanges,
} from "@/utils/dataChanges";
@@ -22,7 +23,6 @@ const emit = defineEmits(["update:visible", "update"]);
const localGroups = ref([]);
const selectedGroupId = ref(null);
const editForm = ref(null);
watch(
() => props.groups,
@@ -37,34 +37,29 @@ const treeData = computed(() => {
});
function buildTreeData(items) {
const map = new Map();
const nodes = new Map();
const roots = [];
items.forEach((item) => {
item.key = String(item.b_id);
map.set(item.key, item);
});
items.forEach((item) => {
if (item.b_parent_id && map.has(String(item.b_parent_id))) {
const parent = map.get(String(item.b_parent_id));
if (!parent.children) parent.children = [];
parent.children.push(item);
for (const item of items) {
const key = String(item.b_id);
nodes.set(key, {
key,
title: item.b_title || `分组-${item.b_id}`,
children: [],
});
}
for (const item of items) {
const node = nodes.get(String(item.b_id));
const parent = item.b_parent_id ? nodes.get(String(item.b_parent_id)) : null;
if (parent && parent !== node) {
parent.children.push(node);
} else {
roots.push(item);
roots.push(node);
}
});
return roots.map((r) => ({
key: r.key,
title: r.b_title || `分组-${r.b_id}`,
children:
r.children?.map((c) => ({
key: c.key,
title: c.b_title || `分组-${c.b_id}`,
children: c.children?.map((gc) => ({
key: gc.key,
title: gc.b_title || `分组-${gc.b_id}`,
})),
})) || [],
}));
}
return roots;
}
const selectedGroup = computed(() =>
@@ -74,11 +69,8 @@ const selectedGroup = computed(() =>
function onTreeSelect(keys) {
if (keys.length > 0) {
selectedGroupId.value = String(keys[0]);
const g = selectedGroup.value;
editForm.value = g ? { ...g } : null;
} else {
selectedGroupId.value = null;
editForm.value = null;
}
}
@@ -94,26 +86,33 @@ function addGroup(parentId) {
};
localGroups.value.push(newGroup);
selectedGroupId.value = String(newGroup.b_id);
editForm.value = { ...newGroup };
}
function deleteGroup() {
if (!selectedGroupId.value) return;
localGroups.value = localGroups.value.filter((g) => String(g.b_id) !== selectedGroupId.value);
selectedGroupId.value = null;
editForm.value = null;
}
async function saveAllGroups() {
if (localGroups.value.some((group) => !String(group.b_title || "").trim())) {
message.warning("请填写分组标题");
return;
}
const original = cloneData(props.groups || []);
const changes = diffRows(localGroups.value, original);
const req = tableChange("b_module_field_group", changes);
const req = tableChange("s_module_field_group", changes);
if (!hasChanges(req)) {
message.info("没有需要保存的变更");
return;
}
try {
await allocateTemporaryIds([req.inserts || [], req.updates || [], req.deletes || []]);
const idMapping = await allocateTemporaryIds([
req.inserts || [],
req.updates || [],
req.deletes || [],
]);
remapForeignKeys(localGroups.value, ["b_parent_id"], idMapping);
await saveObjectApi([req]);
emit("update", cloneData(localGroups.value));
message.success("分组已保存");
@@ -155,28 +154,24 @@ function onClose() {
</FmsTree>
<a-empty v-else description="暂无分组" />
</div>
<div class="group-detail" v-if="editForm">
<div v-if="selectedGroup" class="group-detail">
<a-form layout="vertical">
<a-form-item label="分组标题" required>
<a-input :value="editForm.b_title" @update:value="(v) => (editForm.b_title = v)" />
<a-input v-model:value="selectedGroup.b_title" />
</a-form-item>
<a-form-item label="多语言键">
<a-input
:value="editForm.b_i18n"
@update:value="(v) => (editForm.b_i18n = v || null)"
:value="selectedGroup.b_i18n"
@update:value="(v) => (selectedGroup.b_i18n = v || null)"
/>
</a-form-item>
<a-form-item label="排序号">
<a-input-number
:value="editForm.b_xh"
:min="0"
@update:value="(v) => (editForm.b_xh = v)"
/>
<a-input-number v-model:value="selectedGroup.b_xh" :min="0" />
</a-form-item>
<a-form-item label="启用">
<a-switch
:checked="editForm.b_canuse === 1"
@update:checked="(v) => (editForm.b_canuse = v ? 1 : 0)"
:checked="selectedGroup.b_canuse === 1"
@update:checked="(v) => (selectedGroup.b_canuse = v ? 1 : 0)"
/>
</a-form-item>
<a-form-item>