|
@ -1,15 +1,16 @@ |
|
|
<template> |
|
|
<template> |
|
|
<el-menu ref="menuInstRef" class="menu" background-color="transparent" text-color="#84e0f7" |
|
|
<el-menu ref="menuInstRef" class="menu" background-color="transparent" text-color="#84e0f7" active-text-color="#ffd04b" |
|
|
active-text-color="#ffd04b" :default-active="selectedKey" @open="openClick" @close="closeClick" @select="selectClick"> |
|
|
:default-active="selectedKey" unique-opened @open="openClick" @close="closeClick" @select="selectClick"> |
|
|
<el-sub-menu :index="`${item.deptId}`" v-for="(item, index) in menuOptions" :key="item.deptId"> |
|
|
<el-sub-menu :index="`${item.deptId}`" v-for="(item, index) in menuOptions" :key="item.deptId"> |
|
|
<template #title> |
|
|
<template #title> |
|
|
<el-tooltip class="box-item" effect="dark" :content="item.deptName" placement="top-start"> |
|
|
<el-tooltip class="box-item" effect="dark" :content="item.deptName" placement="top-start"> |
|
|
<span>{{ item.deptName }}</span> |
|
|
<span>{{ item.deptName }}</span> |
|
|
</el-tooltip> |
|
|
</el-tooltip> |
|
|
</template> |
|
|
</template> |
|
|
<el-sub-menu :index="`${result.deptId}`" v-for="(result, index) in item.children" :key="result.deptId" |
|
|
<el-sub-menu :index="`${result.deptId}`" v-for="(result, index) in item.children" :key="result.deptId"> |
|
|
@click.native="clickNative"> |
|
|
<template #title> |
|
|
<template #title>{{ result.deptName }}</template> |
|
|
<div @click.native="clickNative(result)">{{ result.deptName }}</div> |
|
|
|
|
|
</template> |
|
|
<el-menu-item :index="`${res.deptId}`" v-for="(res, index) in result.children" :key="res.deptId"> |
|
|
<el-menu-item :index="`${res.deptId}`" v-for="(res, index) in result.children" :key="res.deptId"> |
|
|
<el-tooltip class="box-item" effect="dark" :content="res.deptName" placement="right-start"> |
|
|
<el-tooltip class="box-item" effect="dark" :content="res.deptName" placement="right-start"> |
|
|
<span>{{ res.deptName }}</span> |
|
|
<span>{{ res.deptName }}</span> |
|
@ -21,7 +22,7 @@ |
|
|
</template> |
|
|
</template> |
|
|
|
|
|
|
|
|
<script lang="ts" setup> |
|
|
<script lang="ts" setup> |
|
|
import { useRouter } from "vue-router"; |
|
|
import { useRoute } from "vue-router"; |
|
|
import { getDept, getDeviceList } from '@/api/device/index'; |
|
|
import { getDept, getDeviceList } from '@/api/device/index'; |
|
|
import { menuVo, deviceVo } from '@/api/device/types'; |
|
|
import { menuVo, deviceVo } from '@/api/device/types'; |
|
|
import mitt from '@/plugins/bus'; |
|
|
import mitt from '@/plugins/bus'; |
|
@ -29,29 +30,38 @@ const deptData = ref([]); |
|
|
const selectedKey = ref(); |
|
|
const selectedKey = ref(); |
|
|
const menuOptions = ref<menuVo[]>(); |
|
|
const menuOptions = ref<menuVo[]>(); |
|
|
const deviceData = ref<deviceVo[]>(); |
|
|
const deviceData = ref<deviceVo[]>(); |
|
|
const id= |
|
|
const router = useRoute() |
|
|
|
|
|
|
|
|
const emit = defineEmits(['tableMenuData']); |
|
|
const emit = defineEmits(['tableMenuData']); |
|
|
|
|
|
|
|
|
onMounted(() => { |
|
|
onMounted(() => { |
|
|
menuApi(); |
|
|
if (router.query?.id === undefined) { |
|
|
|
|
|
menuApi('0'); |
|
|
|
|
|
} else { |
|
|
|
|
|
menuApi('2'); |
|
|
|
|
|
} |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
function menuApi() { |
|
|
function menuApi(type: string) { |
|
|
//获取部门 |
|
|
//获取部门 |
|
|
getDept().then((res: any) => { |
|
|
getDept().then((res: any) => { |
|
|
if (res.code === 200) { |
|
|
if (res.code === 200) { |
|
|
const key = |
|
|
|
|
|
res.data[0] && res.data[0].children && res.data[0].children.length > 0 |
|
|
|
|
|
? res.data[0].children[0].deptId |
|
|
|
|
|
: res.data[0].deptId; |
|
|
|
|
|
// removeChildren(res.data); |
|
|
// removeChildren(res.data); |
|
|
deptData.value = res.data; |
|
|
deptData.value = res.data; |
|
|
menuOptions.value=res.data |
|
|
// menuOptions.value = res.data |
|
|
gitDevice(key, '0') |
|
|
|
|
|
// selectedKey.value = key; |
|
|
// selectedKey.value = key; |
|
|
// mitt.emit('menuKey', key); |
|
|
// mitt.emit('deviceMenuKey', key); |
|
|
emit('tableMenuData', res.data); |
|
|
emit('tableMenuData', res.data); |
|
|
|
|
|
if (type === '0') { |
|
|
|
|
|
const key = |
|
|
|
|
|
res.data[0] && res.data[0].children && res.data[0].children.length > 0 |
|
|
|
|
|
? res.data[0].children[0].deptId |
|
|
|
|
|
: res.data[0].deptId; |
|
|
|
|
|
gitDevice(key, '0') |
|
|
|
|
|
} else { |
|
|
|
|
|
const deptId = Number(sessionStorage.getItem('deptId')) |
|
|
|
|
|
gitDevice(deptId, '2') |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
@ -78,14 +88,18 @@ function gitDevice(key: number, type: string) { |
|
|
if (type === '0') { |
|
|
if (type === '0') { |
|
|
const deptIdKey = res.data[0].deptId; |
|
|
const deptIdKey = res.data[0].deptId; |
|
|
selectedKey.value = deptIdKey.toString(); |
|
|
selectedKey.value = deptIdKey.toString(); |
|
|
mitt.emit('menuKey', deptIdKey); |
|
|
mitt.emit('deviceMenuKey', deptIdKey); |
|
|
|
|
|
} else if (type === '2') { |
|
|
|
|
|
const deptIdKey = router.query?.id; |
|
|
|
|
|
selectedKey.value = deptIdKey?.toString(); |
|
|
|
|
|
mitt.emit('deviceMenuKey', deptIdKey); |
|
|
} |
|
|
} |
|
|
// menuOptions.value = deptData.value |
|
|
menuOptions.value = deptData.value |
|
|
deviceData.value = res.data; |
|
|
deviceData.value = res.data; |
|
|
// console.log(menuOptions.value) |
|
|
// console.log(menuOptions.value) |
|
|
// if (type === '0') { |
|
|
// if (type === '0') { |
|
|
// selectedKey.value = res.data[0].deptId; |
|
|
// selectedKey.value = res.data[0].deptId; |
|
|
// mitt.emit('menuKey', res.data[0].deptId); |
|
|
// mitt.emit('deviceMenuKey', res.data[0].deptId); |
|
|
// } |
|
|
// } |
|
|
} |
|
|
} |
|
|
}); |
|
|
}); |
|
@ -109,14 +123,14 @@ function gitDevice(key: number, type: string) { |
|
|
// function menuUpdateValue(key: number, item: MenuOption) { |
|
|
// function menuUpdateValue(key: number, item: MenuOption) { |
|
|
// //点击菜单 |
|
|
// //点击菜单 |
|
|
// // gitDevice(key, '1') |
|
|
// // gitDevice(key, '1') |
|
|
// mitt.emit('menuKey', key); |
|
|
// mitt.emit('deviceMenuKey', key); |
|
|
// console.log(key, item); |
|
|
// console.log(key, item); |
|
|
// } |
|
|
// } |
|
|
|
|
|
|
|
|
const openClick = (key: string, indexPath: string[]) => { |
|
|
const openClick = (key: string, indexPath: string[]) => { |
|
|
//sub-menu 展开的回调 |
|
|
//sub-menu 展开的回调 |
|
|
console.log("open-", key, indexPath) |
|
|
console.log("open-", key, indexPath) |
|
|
gitDevice(Number(key), '1') |
|
|
// gitDevice(Number(key), '1') |
|
|
} |
|
|
} |
|
|
const closeClick = (key: string, keyPath: string[]) => { |
|
|
const closeClick = (key: string, keyPath: string[]) => { |
|
|
//sub-menu 收起的回调 |
|
|
//sub-menu 收起的回调 |
|
@ -125,11 +139,12 @@ const closeClick = (key: string, keyPath: string[]) => { |
|
|
const selectClick = (key: string, keyPath: string[], item: any) => { |
|
|
const selectClick = (key: string, keyPath: string[], item: any) => { |
|
|
//菜单激活回调 |
|
|
//菜单激活回调 |
|
|
console.log("select-", key, keyPath, item) |
|
|
console.log("select-", key, keyPath, item) |
|
|
mitt.emit('menuKey', key); |
|
|
mitt.emit('deviceMenuKey', key); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
function clickNative(item: any) { |
|
|
function clickNative(item: any) { |
|
|
console.log("clickNative-",item) |
|
|
gitDevice(item.deptId, '1') |
|
|
|
|
|
console.log("clickNative-", item) |
|
|
} |
|
|
} |
|
|
</script> |
|
|
</script> |
|
|
<style lang="scss" scoped> |
|
|
<style lang="scss" scoped> |
|
|