Browse Source

feat: 分组管理设备树

deploy-dev
xuziqiang 5 months ago
parent
commit
717b2aad72
  1. 1
      hx-ai-intelligent/src/api/deviceManage.ts
  2. 6
      hx-ai-intelligent/src/view/equipmentManage/group/config.ts
  3. 42
      hx-ai-intelligent/src/view/equipmentManage/group/index.vue
  4. 8
      lib/component/tree/tree-api.vue

1
hx-ai-intelligent/src/api/deviceManage.ts

@ -10,4 +10,5 @@ export enum group {
queryDeviceGroupTree = `${BASE_URL}/deviceGroup/queryDeviceGroupTree`, // 左侧树 queryDeviceGroupTree = `${BASE_URL}/deviceGroup/queryDeviceGroupTree`, // 左侧树
creatOrUpdate = `${BASE_URL}/deviceGroup/creatOrUpdate`, // 左侧树节点新增编辑 creatOrUpdate = `${BASE_URL}/deviceGroup/creatOrUpdate`, // 左侧树节点新增编辑
del = `${BASE_URL}/deviceGroup/del`, // 左侧树节点新增编辑 del = `${BASE_URL}/deviceGroup/del`, // 左侧树节点新增编辑
move = `${BASE_URL}/deviceGroup/move`, // 左侧树节点新增编辑
} }

6
hx-ai-intelligent/src/view/equipmentManage/group/config.ts

@ -76,6 +76,11 @@ export const formSchema = [
show: false, show: false,
}, },
{ {
field: 'energyType',
component: 'NsInput',
show: false,
},
{
field: 'id', field: 'id',
component: 'NsInput', component: 'NsInput',
show: false, show: false,
@ -155,6 +160,7 @@ export const treeConfig = (orgId) => {
labelField: 'cnValue', labelField: 'cnValue',
valueField: 'cnValue', valueField: 'cnValue',
placeholder: '请选择能耗种类', placeholder: '请选择能耗种类',
autoSelectFirst: true,
}, },
}, },
{ {

42
hx-ai-intelligent/src/view/equipmentManage/group/index.vue

@ -21,11 +21,9 @@
<ns-icon name="actionMore" size="14" class="actionMore" /> <ns-icon name="actionMore" size="14" class="actionMore" />
<template #overlay> <template #overlay>
<a-menu> <a-menu>
<template v-for="(item, index) in actionList" :key="index"> <template v-for="(item, index) in filterAction(actionList, data)" :key="index">
<!-- 全部节点只需要新增子节点 --> <!-- 全部节点只需要新增子节点 -->
<a-menu-item <a-menu-item @click="item.func(data)">
v-if="data.id !== 'all' || item.key === 'addNodeSon'"
@click="item.func(data)">
<span>{{ item.title }}</span> <span>{{ item.title }}</span>
</a-menu-item> </a-menu-item>
</template> </template>
@ -82,10 +80,12 @@
const addNodeSon = (data) => { const addNodeSon = (data) => {
console.log(data); console.log(data);
nsModalFormConfig.value.title = '新增'; nsModalFormConfig.value.title = '新增';
nsModalFormConfig.value.data = { nsModalFormConfig.value.data = {
isCreate: true, isCreate: true,
orgId: result, orgId: result,
energyType: data.formModel?.energyType,
}; };
if (data.id !== 'all') { if (data.id !== 'all') {
nsModalFormConfig.value.data.pid = data.id; nsModalFormConfig.value.data.pid = data.id;
@ -94,13 +94,18 @@
modalFormRef.value?.toggle(); modalFormRef.value?.toggle();
}; };
const editNode = (data) => { const editNode = (data) => {
console.log(data);
nsModalFormConfig.value.title = '编辑'; nsModalFormConfig.value.title = '编辑';
setTimeout(() => {
nsModalFormConfig.value.data = data; nsModalFormConfig.value.data = data;
}, 1);
modalFormRef.value?.toggle(); modalFormRef.value?.toggle();
}; };
const moveNode = (data, type: opType) => { const moveNode = (data, type: opType) => {
console.log(data); const flag = type === 'up';
http.post(group.move, { ...data, isUp: flag }).then(() => {
treeRef.value?.treeReload();
NsMessage.success('操作成功');
});
}; };
const deleteNode = (record) => { const deleteNode = (record) => {
@ -111,12 +116,33 @@
onOk: () => { onOk: () => {
http.post(group.del, { id: record.id }).then(() => { http.post(group.del, { id: record.id }).then(() => {
treeRef.value?.treeReload(); treeRef.value?.treeReload();
NsMessage.success('删除成功'); treeRef.value?.clearSelectedKeys();
NsMessage.success('操作成功');
}); });
}, },
}); });
}; };
const filterAction = (data) => {}; const filterAction = (actions, data) => {
let list: string | any[] = ['addNodeSon', 'editNode', 'deleteNode'];
//
// isFirst
if (!data?.isFirst) {
list.push('moveUp');
}
// isEnd
if (!data?.isEnd) {
list.push('moveDown');
}
//
if (data.isOnlyOne) {
list = ['addNodeSon', 'editNode', 'deleteNode'];
}
//
if (data.id === 'all') {
list = ['addNodeSon'];
}
return actions.filter(({ key }) => list.includes(key));
};
const actionList = [ const actionList = [
{ title: '新增子节点', key: 'addNodeSon', func: (data) => addNodeSon(data) }, { title: '新增子节点', key: 'addNodeSon', func: (data) => addNodeSon(data) },
{ title: '编辑', key: 'editNode', func: (data) => editNode(data) }, { title: '编辑', key: 'editNode', func: (data) => editNode(data) },

8
lib/component/tree/tree-api.vue

@ -80,7 +80,7 @@
treeState.loading = loading; treeState.loading = loading;
}; };
const httpPrams = computed(() => { const httpPrams = computed(() => {
return { ...route.params, ...route.query, ...props.params }; return { ...route.params, ...route.query, ...props.params, ...formModel };
}); });
const getData = (params = {}) => { const getData = (params = {}) => {
@ -109,7 +109,11 @@
getData(params); getData(params);
}; };
defineExpose({ treeReload }); const clearSelectedKeys = () => {
selectedKeys.value = [];
};
defineExpose({ treeReload, clearSelectedKeys });
</script> </script>
<style lang="less" scoped> <style lang="less" scoped>
@gap: 16px; @gap: 16px;

Loading…
Cancel
Save