优化资产分类选择功能,限制只能选择最下级分类节点,同时在资产表单中新增categoryPath字段用于记录分类路径,在分类变更时自动从分类树或接口获取并保存分类路径信息,移除订阅页面中的调试日志输出
This commit is contained in:
@@ -665,8 +665,8 @@
|
|||||||
|
|
||||||
// 延迟跳转回原页面
|
// 延迟跳转回原页面
|
||||||
const targetUrl = decodeURIComponent(returnUrl);
|
const targetUrl = decodeURIComponent(returnUrl);
|
||||||
console.log('[subscribe] 开通成功,即将跳转到:', targetUrl);
|
// console.log('[subscribe] 开通成功,即将跳转到:', targetUrl);
|
||||||
console.log('[subscribe] 原始 returnUrl:', returnUrl);
|
// console.log('[subscribe] 原始 returnUrl:', returnUrl);
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
let finalUrl;
|
let finalUrl;
|
||||||
|
|||||||
@@ -24,7 +24,7 @@
|
|||||||
<el-cascader
|
<el-cascader
|
||||||
v-model="ruleForm.categoryId"
|
v-model="ruleForm.categoryId"
|
||||||
:options="categoryOptions"
|
:options="categoryOptions"
|
||||||
:props="{ checkStrictly: true, emitPath: false, value: 'id', label: 'name', children: 'children' }"
|
:props="categoryProps"
|
||||||
placeholder="请选择资产分类"
|
placeholder="请选择资产分类"
|
||||||
clearable
|
clearable
|
||||||
class="w100"
|
class="w100"
|
||||||
@@ -500,6 +500,7 @@ interface RuleForm {
|
|||||||
name: string;
|
name: string;
|
||||||
type: string;
|
type: string;
|
||||||
categoryId: string;
|
categoryId: string;
|
||||||
|
categoryPath: string;
|
||||||
description: string;
|
description: string;
|
||||||
onlineTime: string;
|
onlineTime: string;
|
||||||
offlineTime: string;
|
offlineTime: string;
|
||||||
@@ -556,6 +557,16 @@ const submitLoading = ref(false);
|
|||||||
const formLoading = ref(false);
|
const formLoading = ref(false);
|
||||||
const categoryOptions = ref<any[]>([]);
|
const categoryOptions = ref<any[]>([]);
|
||||||
const categoryAttrs = ref<CategoryAttr[]>([]);
|
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);
|
const isTimeSlotLimitReached = computed(() => ruleForm.serviceAssetConfig.serviceAssetArrivalConfig.schedule.timeSlots.length >= MAX_TIME_SLOTS);
|
||||||
|
|
||||||
// 获取属性的key
|
// 获取属性的key
|
||||||
@@ -609,6 +620,7 @@ const getInitialForm = (): RuleForm => ({
|
|||||||
name: '',
|
name: '',
|
||||||
type: 'physical',
|
type: 'physical',
|
||||||
categoryId: '',
|
categoryId: '',
|
||||||
|
categoryPath: '',
|
||||||
description: '',
|
description: '',
|
||||||
onlineTime: '',
|
onlineTime: '',
|
||||||
offlineTime: '',
|
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) => {
|
const onCategoryChange = (categoryId: string) => {
|
||||||
categoryAttrs.value = [];
|
categoryAttrs.value = [];
|
||||||
ruleForm.metadata = {};
|
ruleForm.metadata = {};
|
||||||
|
ruleForm.categoryPath = '';
|
||||||
if (!categoryId) return;
|
if (!categoryId) return;
|
||||||
|
|
||||||
|
// 从分类树中查找选中节点,获取path
|
||||||
|
const node = findCategoryNode(categoryOptions.value, categoryId);
|
||||||
|
if (node?.path !== undefined) {
|
||||||
|
ruleForm.categoryPath = node.path;
|
||||||
|
}
|
||||||
|
|
||||||
getCategory(categoryId)
|
getCategory(categoryId)
|
||||||
.then((res: any) => {
|
.then((res: any) => {
|
||||||
const data = res.data;
|
const data = res.data;
|
||||||
|
// 如果接口返回了path,优先使用接口返回的
|
||||||
|
if (data?.path !== undefined) {
|
||||||
|
ruleForm.categoryPath = data.path;
|
||||||
|
}
|
||||||
if (data?.attrs && Array.isArray(data.attrs)) {
|
if (data?.attrs && Array.isArray(data.attrs)) {
|
||||||
categoryAttrs.value = data.attrs;
|
categoryAttrs.value = data.attrs;
|
||||||
// 初始化属性值,确保 boolean 类型默认为 false
|
// 初始化属性值,确保 boolean 类型默认为 false
|
||||||
@@ -915,6 +950,7 @@ const openDialog = (row?: any, edit?: boolean) => {
|
|||||||
ruleForm.name = data.name || '';
|
ruleForm.name = data.name || '';
|
||||||
ruleForm.type = data.type || 'physical';
|
ruleForm.type = data.type || 'physical';
|
||||||
ruleForm.categoryId = data.categoryId || '';
|
ruleForm.categoryId = data.categoryId || '';
|
||||||
|
ruleForm.categoryPath = data.categoryPath || '';
|
||||||
ruleForm.description = data.description || '';
|
ruleForm.description = data.description || '';
|
||||||
ruleForm.onlineTime = data.onlineTime || '';
|
ruleForm.onlineTime = data.onlineTime || '';
|
||||||
ruleForm.offlineTime = data.offlineTime || '';
|
ruleForm.offlineTime = data.offlineTime || '';
|
||||||
@@ -1116,6 +1152,7 @@ const buildRequestBody = async (): Promise<any> => {
|
|||||||
name: ruleForm.name,
|
name: ruleForm.name,
|
||||||
type: ruleForm.type,
|
type: ruleForm.type,
|
||||||
categoryId: ruleForm.categoryId,
|
categoryId: ruleForm.categoryId,
|
||||||
|
categoryPath: ruleForm.categoryPath || '',
|
||||||
description: ruleForm.description || '',
|
description: ruleForm.description || '',
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user