fix: 修复菜单配置无法调整顺序的问题

This commit is contained in:
XieYongHong 2023-04-28 17:24:11 +08:00 committed by GitHub
parent efded34ff2
commit a28b85d077
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 60 additions and 26 deletions

View File

@ -167,7 +167,11 @@ const errorHandler = (error: any) => {
showNotification(error?.code, error?.response?.data?.message, '404')
}
} else if (error.response === undefined) {
showNotification(error.message, (error.stack + '').substr(0, 90), undefined)
if (error.message.includes('timeout')) {
showNotification(error.message, '接口响应超时', undefined)
} else {
showNotification(error.message, (error.stack + '').substr(0, 90), undefined)
}
}
return Promise.reject(error)
}

View File

@ -686,7 +686,7 @@ const getData = async (accessId?: string) => {
productTypes.value = resp.result.map(item => {
if (pluginRes?.result?.externalId === item.id) {
productData.id = pluginRes?.result?.externalId
productData.metadata = JSON.stringify(item.metadata || {})
productData.metadata = item.metadata
}
return { ...item, label: item.name, value: item.id }
})
@ -724,7 +724,20 @@ const submitDevice = async () => {
const id = productStore.current?.id;
//
const _metadata = JSON.parse(productStore.current?.metadata || '{}')
if (_metadata.properties?.length || _metadata.events?.length || _metadata.functions?.length || _metadata.tags?.length) {
console.log(_metadata.properties, productData.metadata)
if (
(_metadata.properties?.length ||
_metadata.events?.length ||
_metadata.functions?.length ||
_metadata.tags?.length
) &&
(
productData.metadata?.properties?.length ||
productData.metadata?.events?.length ||
productData.metadata?.functions?.length ||
productData.metadata?.tags?.length
)
) {
metadataModalCacheData.value = {
id,
values,

View File

@ -10,30 +10,31 @@
<div class="content">
<j-card title="菜单配置" style="width: 80%">
<div class="tree">
<j-scrollbar>
<j-tree
v-if="treeData.length !== 0"
show-line
defaultExpandAll
multiple
draggable
:tree-data="treeData"
:height="520"
@select="onSelect"
:selectedKeys="selectedKeys"
@drop="onDrop"
@dragend="onDragend"
v-if="treeData.length !== 0"
show-line
defaultExpandAll
multiple
draggable
:tree-data="treeData"
@select="onSelect"
:selectedKeys="selectedKeys"
@drop="onDrop"
@dragend="onDragend"
>
<template #title="row">
<div class="tree-content">
<div class="tree-content-title">
<AIcon type="HolderOutlined" />
<div style="margin-left: 8px">
{{ row.name }}
</div>
</div>
<template #title="row">
<div class="tree-content">
<div class="tree-content-title">
<AIcon type="HolderOutlined" />
<div style="margin-left: 8px">
{{ row.name }}
</div>
</template>
</div>
</div>
</template>
</j-tree>
</j-scrollbar>
</div>
</j-card>
</div>
@ -70,6 +71,7 @@ import {
getMaxDepth,
mergeArr,
findAllParentsAndChildren,
handleSorts
} from './utils';
import BaseMenu from '@/views/init-home/data/baseMenu';
import type { AntTreeNodeDropEvent } from 'ant-design-vue/es/tree';
@ -134,9 +136,9 @@ function filterTree(nodes: Array<any>, selectedKeys: Array<any>) {
const handleOk = async () => {
const _dataArr = filterTree(cloneDeep(treeData.value), selectedKeys.value);
const _dataSorts = handleSorts(_dataArr)
loading.value = true;
const res = await updateMenus(_dataArr).catch(() => {});
const res = await updateMenus(_dataSorts).catch(() => {});
if (res?.status === 200) {
onlyMessage('操作成功', 'success');
}
@ -260,6 +262,7 @@ onMounted(() => {
border-radius: 4px;
overflow: hidden;
width: 100%;
height: 540px;
&-content {
display: flex;

View File

@ -304,3 +304,17 @@ export const getNodeDepth = (node: any) => {
}
return depth;
};
export const handleSorts = (node: any[]) => {
if (!node) return []
return node.map((item, index) => {
if (item.index !== index) {
item.sortIndex = index
if (item.children) {
item.children = handleSorts(item.children)
}
}
return item
})
}

View File

@ -92,7 +92,7 @@ export default defineConfig(({ mode}) => {
proxy: {
[env.VITE_APP_BASE_API]: {
// target: 'http://192.168.32.226:8844',
// target: 'http://192.168.32.70:8844',
// target: 'http://192.168.32.244:8881',
target: 'http://120.77.179.54:8844', // 120测试
// target: 'http://192.168.33.46:8844', // 本地开发环境