fix(菜单管理): 上移下移修改

This commit is contained in:
sheng
2023-07-31 10:23:46 +08:00
parent e790882ab6
commit d2811a1f87
2 changed files with 15 additions and 10 deletions

View File

@@ -3,7 +3,7 @@ ENV = 'development'
# 本地环境接口地址 # 本地环境接口地址
#`VITE_API_URL = 'https://demo.dvadmin.com/api' #`VITE_API_URL = 'https://demo.dvadmin.com/api'
VITE_API_URL = 'http://192.168.1.160:8002' VITE_API_URL = 'http://192.168.1.160:8003'
# 是否启用按钮权限 # 是否启用按钮权限
VITE_PM_ENABLED = true VITE_PM_ENABLED = true

View File

@@ -199,6 +199,7 @@ const filterText = ref('');
const treeRef = ref<InstanceType<typeof ElTree>>(); const treeRef = ref<InstanceType<typeof ElTree>>();
let drawerVisible = ref(false); let drawerVisible = ref(false);
let treeSelectNode = ref<Node | null>(null); let treeSelectNode = ref<Node | null>(null);
let sortDisable = ref(false);
let formData = reactive({ let formData = reactive({
name: '', name: '',
@@ -424,27 +425,31 @@ const handleDeleteMenu = () => {
/** /**
* 移动操作 * 移动操作
*/ */
const handleSort = (type: string) => { const handleSort = async (type: string) => {
if (!form.id && treeSelectNode.value) { if (!form.id && treeSelectNode.value) {
warningMessage('请选择菜单!'); warningMessage('请选择菜单!');
return; return;
} }
if (sortDisable.value) return;
const parentList = treeSelectNode.value?.parent.childNodes || []; const parentList = treeSelectNode.value?.parent.childNodes || [];
const index = parentList.findIndex((i) => i.data.id === form.id); const index = parentList.findIndex((i) => i.data.id === form.id);
const record = parentList.find((i) => i.data.id === form.id); const record = parentList.find((i) => i.data.id === form.id);
if (type === 'up') { if (type === 'up') {
if (index === 0) return; if (index === 0) return;
api.moveUp({ menu_id: form.id }).then((res: APIResponseData) => { parentList.splice(index - 1, 0, record as any);
getData(); parentList.splice(index + 1, 1);
successMessage(res.msg as string); sortDisable.value = true;
}); await api.moveUp({ menu_id: form.id });
sortDisable.value = false;
} }
if (type === 'down') { if (type === 'down') {
api.moveDown({ menu_id: form.id }).then((res: APIResponseData) => { parentList.splice(index + 2, 0, record as any);
getData(); parentList.splice(index, 1);
successMessage(res.msg as string); sortDisable.value = true;
}); await api.moveDown({ menu_id: form.id });
sortDisable.value = false;
} }
}; };