吉安感知网项目-前端
罗广辉
2026-01-30 bb52b013fa9ffd86124ddc79abd42fb26f48baca
applications/drone-command/src/views/permissionManage/permissionDept/ShareDiaLog.vue
@@ -21,7 +21,11 @@
                        <el-table-column type="index" show-overflow-tooltip width="64" label="序号" />
                        <el-table-column prop="deviceName" show-overflow-tooltip label="设备名称" />
                        <el-table-column prop="deviceSn" show-overflow-tooltip label="设备SN" />
                        <el-table-column prop="deviceType" show-overflow-tooltip label="设备类型" />
                        <el-table-column prop="deviceType" show-overflow-tooltip label="设备类型">
                           <template v-slot="{ row }">
                              {{ getDictLabel(row.deviceType, dictObj.deviceType) }}
                           </template>
                        </el-table-column>
                        <el-table-column prop="belongDeptName" show-overflow-tooltip label="所属部门" />
                     </el-table>
                  </div>
@@ -44,6 +48,8 @@
import { ref, nextTick } from 'vue'
import { ElMessage } from 'element-plus'
import { nonDeptAreaDevicesApi, fwDevicePerShareSaveApi, fwDevicePerShareRemoveApi } from './fwDevicePerShareApi'
import { getDictionaryByCode } from '@/api/system/dictbiz'
import { getDictLabel } from '@ztzf/utils'
const emit = defineEmits(['success'])
const visible = defineModel() // 弹框显隐
@@ -53,7 +59,18 @@
const tableRef = ref(null) // 表格实例
const selectedRows = ref([]) // 当前选中的行
const originalSharedIds = ref([]) // 原始已共享的设备ID集合
const originalSharedMap = ref({}) // 原始已共享的设备ID与shareId的映射
const currentDeptId = ref(null) // 当前操作的部门ID
const dictObj = ref({
   deviceType: [], // 设备类型
})
// 获取字典
function getDictList() {
   getDictionaryByCode('deviceType').then(res => {
      dictObj.value = res.data.data
   })
}
// 选中变化
function handleSelectionChange(rows) {
@@ -71,8 +88,13 @@
   try {
      const res = await nonDeptAreaDevicesApi({ loanToDeptId: currentDeptId.value })
      deviceList.value = res?.data?.data ?? []
      // 记录原始已共享的设备ID
      originalSharedIds.value = deviceList.value.filter(item => item.isShared).map(item => item.id)
      // 记录原始已共享的设备ID和shareId映射
      const sharedDevices = deviceList.value.filter(item => item.isShared)
      originalSharedIds.value = sharedDevices.map(item => item.id)
      originalSharedMap.value = sharedDevices.reduce((map, item) => {
         map[item.id] = item.shareId
         return map
      }, {})
      // 回显已共享的设备勾选状态
      nextTick(() => {
         deviceList.value.forEach(item => {
@@ -95,8 +117,11 @@
      // 计算需要新增的设备(当前选中但原来未共享)
      const toAddDevices = selectedRows.value.filter(item => !originalSharedIds.value.includes(item.id))
      // 计算需要删除的设备(原来共享但当前未选中)
      const toRemoveIds = originalSharedIds.value.filter(id => !currentSelectedIds.includes(id))
      // 计算需要删除的设备(原来共享但当前未选中),使用shareId
      const toRemoveShareIds = originalSharedIds.value
         .filter(id => !currentSelectedIds.includes(id))
         .map(id => originalSharedMap.value[id])
         .filter(Boolean)
      const promises = []
@@ -112,8 +137,8 @@
      }
      // 调用删除接口
      if (toRemoveIds.length > 0) {
         promises.push(fwDevicePerShareRemoveApi({ ids: toRemoveIds.join(',') }))
      if (toRemoveShareIds.length > 0) {
         promises.push(fwDevicePerShareRemoveApi({ ids: toRemoveShareIds.join(',') }))
      }
      if (promises.length > 0) {
@@ -134,6 +159,7 @@
async function open({ row } = {}) {
   currentDeptId.value = row?.id
   selectedRows.value = []
   getDictList()
   await getDeviceList()
}