优化资产分类选择功能,限制只能选择最下级分类节点,同时在资产表单中新增categoryPath字段用于记录分类路径,在分类变更时自动从分类树或接口获取并保存分类路径信息,移除订阅页面中的调试日志输出

This commit is contained in:
WUSIJIAN
2026-01-23 15:48:46 +08:00
parent b9795c2cc4
commit a16081f1fa
2 changed files with 41 additions and 4 deletions

View File

@@ -665,8 +665,8 @@
// 延迟跳转回原页面
const targetUrl = decodeURIComponent(returnUrl);
console.log('[subscribe] 开通成功,即将跳转到:', targetUrl);
console.log('[subscribe] 原始 returnUrl:', returnUrl);
// console.log('[subscribe] 开通成功,即将跳转到:', targetUrl);
// console.log('[subscribe] 原始 returnUrl:', returnUrl);
setTimeout(() => {
let finalUrl;

View File

@@ -24,7 +24,7 @@
<el-cascader
v-model="ruleForm.categoryId"
:options="categoryOptions"
:props="{ checkStrictly: true, emitPath: false, value: 'id', label: 'name', children: 'children' }"
:props="categoryProps"
placeholder="请选择资产分类"
clearable
class="w100"
@@ -500,6 +500,7 @@ interface RuleForm {
name: string;
type: string;
categoryId: string;
categoryPath: string;
description: string;
onlineTime: string;
offlineTime: string;
@@ -556,6 +557,16 @@ const submitLoading = ref(false);
const formLoading = ref(false);
const categoryOptions = ref<any[]>([]);
const categoryAttrs = ref<CategoryAttr[]>([]);
// 分类选择器配置 - 只能选择最下级节点(isLeafNode: true)
const categoryProps = {
checkStrictly: true,
emitPath: false,
value: 'id',
label: 'name',
children: 'children',
disabled: (data: any) => !data.isLeafNode,
};
const isTimeSlotLimitReached = computed(() => ruleForm.serviceAssetConfig.serviceAssetArrivalConfig.schedule.timeSlots.length >= MAX_TIME_SLOTS);
// 获取属性的key
@@ -609,6 +620,7 @@ const getInitialForm = (): RuleForm => ({
name: '',
type: 'physical',
categoryId: '',
categoryPath: '',
description: '',
onlineTime: '',
offlineTime: '',
@@ -872,15 +884,38 @@ const fetchCategories = () => {
});
};
// 分类变更时获取分类属性
// 递归查找分类节点
const findCategoryNode = (nodes: any[], id: string): any => {
for (const node of nodes) {
if (node.id === id) return node;
if (node.children?.length) {
const found = findCategoryNode(node.children, id);
if (found) return found;
}
}
return null;
};
// 分类变更时获取分类属性和path
const onCategoryChange = (categoryId: string) => {
categoryAttrs.value = [];
ruleForm.metadata = {};
ruleForm.categoryPath = '';
if (!categoryId) return;
// 从分类树中查找选中节点获取path
const node = findCategoryNode(categoryOptions.value, categoryId);
if (node?.path !== undefined) {
ruleForm.categoryPath = node.path;
}
getCategory(categoryId)
.then((res: any) => {
const data = res.data;
// 如果接口返回了path优先使用接口返回的
if (data?.path !== undefined) {
ruleForm.categoryPath = data.path;
}
if (data?.attrs && Array.isArray(data.attrs)) {
categoryAttrs.value = data.attrs;
// 初始化属性值,确保 boolean 类型默认为 false
@@ -915,6 +950,7 @@ const openDialog = (row?: any, edit?: boolean) => {
ruleForm.name = data.name || '';
ruleForm.type = data.type || 'physical';
ruleForm.categoryId = data.categoryId || '';
ruleForm.categoryPath = data.categoryPath || '';
ruleForm.description = data.description || '';
ruleForm.onlineTime = data.onlineTime || '';
ruleForm.offlineTime = data.offlineTime || '';
@@ -1116,6 +1152,7 @@ const buildRequestBody = async (): Promise<any> => {
name: ruleForm.name,
type: ruleForm.type,
categoryId: ruleForm.categoryId,
categoryPath: ruleForm.categoryPath || '',
description: ruleForm.description || '',
};