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') showNotification(error?.code, error?.response?.data?.message, '404')
} }
} else if (error.response === undefined) { } 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) return Promise.reject(error)
} }

View File

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

View File

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

View File

@ -304,3 +304,17 @@ export const getNodeDepth = (node: any) => {
} }
return depth; 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: { proxy: {
[env.VITE_APP_BASE_API]: { [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://192.168.32.244:8881',
target: 'http://120.77.179.54:8844', // 120测试 target: 'http://120.77.179.54:8844', // 120测试
// target: 'http://192.168.33.46:8844', // 本地开发环境 // target: 'http://192.168.33.46:8844', // 本地开发环境