CamerasOverview.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522
  1. <template>
  2. <div class="camera-page">
  3. <ConditionQuery />
  4. <div class="camera-list">
  5. <div v-if="showActionBar" class="action-bar">
  6. <span class="num-text">已选{{ chooseNum }}项</span>
  7. <el-button :class="isActiveExport ? 'btn-active' : 'btn-normal'" @click="handleBatchExport"
  8. >导出</el-button
  9. >
  10. <el-button :class="isActiveDelete ? 'btn-active' : 'btn-normal'" @click="handleBatchDelete"
  11. >删除</el-button
  12. >
  13. <span class="close-btn" @click="handleSelectNone"></span>
  14. </div>
  15. <BasicTable
  16. :columns="columns"
  17. :data-source="cameraItems"
  18. :row-key="(row) => row.code"
  19. :action-column="actionColumn"
  20. :pagination="{
  21. total: total,
  22. currentPage: page,
  23. pageSize: size,
  24. hideOnSinglePage: !cameraItems.length,
  25. }"
  26. :loading="loading"
  27. :tableSetting="{
  28. size: false,
  29. redo: false,
  30. fullscreen: false,
  31. striped: false,
  32. setting: false,
  33. }"
  34. :striped="true"
  35. ref="tableRef"
  36. @order-change="orderByItem"
  37. @selection-change="handleSelectionChange"
  38. @page-num-change="handlePageNumChange"
  39. @page-size-change="handlePageSizeChange"
  40. >
  41. <template #tableTitle>
  42. <el-button type="primary" :icon="Plus" @click="showAddPopover = true">添加</el-button>
  43. <el-button
  44. color="#1890FF"
  45. @click="showBatchImportPopover = true"
  46. style="margin-left: 18px"
  47. plain
  48. >
  49. <template #icon>
  50. <el-icon>
  51. <DocumentAdd />
  52. </el-icon>
  53. </template>
  54. 批量添加
  55. </el-button>
  56. <el-button
  57. color="#1890FF"
  58. @click="showBatchEditPopover = true"
  59. style="margin-left: 18px"
  60. plain
  61. >
  62. <template #icon>
  63. <el-icon>
  64. <Edit />
  65. </el-icon>
  66. </template>
  67. 批量修改
  68. </el-button>
  69. <el-badge :value="totalRow" :hidden="totalRow < 1" class="item">
  70. <el-button color="#1890FF" @click="showSharedPopover = true" plain>共享相机</el-button>
  71. </el-badge>
  72. </template>
  73. <template #empty>
  74. <div class="empty-content flex flex-col items-center">
  75. <img :src="emptyImg" class="empty-img" />
  76. <span class="empty-text">目前无内容,请先添加相机</span>
  77. </div>
  78. </template>
  79. </BasicTable>
  80. </div>
  81. <AddCamera class="add-popover" v-model="showAddPopover" />
  82. <BatchImportCamera
  83. class="batch-import"
  84. v-if="showBatchImportPopover"
  85. @update="handleUpdateBatchImport"
  86. @close="handleCloseBatchImport"
  87. />
  88. <BatchEditCamera
  89. class="batch-import"
  90. v-if="showBatchEditPopover"
  91. @update="handleUpdateBatchEdit"
  92. @close="handleCloseBatchEdit"
  93. />
  94. <EditCamera class="add-popover" v-model="showEditPopover" :edit-data="editCameraData" />
  95. <EditSRSCamera class="add-popover" v-model="showEditSRSPopover" :edit-data="editCameraData" />
  96. <EditNVRCamera class="add-popover" v-model="showEditNVRPopover" :edit-data="editCameraData" />
  97. <ShareCamera class="add-popover" v-model="addSharedPopover" :share-data="shareCameraData" />
  98. <EditSharedCamera
  99. class="add-popover"
  100. v-model="showSharedPopover"
  101. @update-unadd="updateUnaddAmount"
  102. />
  103. </div>
  104. </template>
  105. <script setup lang="ts">
  106. import { h, onBeforeUnmount, onMounted, reactive, ref } from 'vue';
  107. import { BasicTable, TableActionIcons } from '@/components/Table';
  108. import { BasicColumn } from '@/components/Table';
  109. import { columns } from './hooks/overviewColumns';
  110. import ConditionQuery from './components/ConditionQuery.vue';
  111. import AddCamera from './components/CameraAddPopover.vue';
  112. import BatchImportCamera from './components/BatchImportCamera.vue';
  113. import BatchEditCamera from './components/BatchEditCamera.vue';
  114. import ShareCamera from './components/CameraSharePopover.vue';
  115. import EditCamera from './components/CameraEditPopover.vue';
  116. import EditSRSCamera from './components/CameraEditSRSPopover.vue';
  117. import EditNVRCamera from './components/CameraEditNVRPopover.vue';
  118. import EditSharedCamera from './components/CameraSharedEdit.vue';
  119. import emptyImg from '@/assets/images/table/table-empty.png';
  120. import { Plus, DocumentAdd, Edit } from '@element-plus/icons-vue';
  121. import shareIcon from '@/assets/images/table/table-share.png';
  122. import previewIcon from '@/assets/images/table/table-preview.png';
  123. import editIcon from '@/assets/images/table/table-edit.png';
  124. import deleteIcon from '@/assets/images/table/table-delete.png';
  125. import useCameraOverview from './stores/useCameraOverview';
  126. import { storeToRefs } from 'pinia';
  127. import { CameraDetailServer } from '@/types/camera/type';
  128. import { deleteCameraItem, deleteCameraItems } from '@/api/camera/camera-overview';
  129. import { ElMessage, ElMessageBox } from 'element-plus';
  130. import useCameraShare from './hooks/useCameraShare';
  131. import router from '@/router';
  132. import { AddType } from '@/types/camera/constant';
  133. import axios, { AxiosRequestConfig } from 'axios';
  134. import { getHeaders } from '@/utils/http/axios';
  135. import { useGlobSetting } from '@/hooks/setting';
  136. import { useSceneTemplateList } from './stores/useSceneTemplateList';
  137. const sceneTemplateListInfo = useSceneTemplateList();
  138. const { getSceneTemplateList } = sceneTemplateListInfo;
  139. const { urlPrefix } = useGlobSetting();
  140. const useShare = useCameraShare();
  141. const { totalRow, queryToTenantId, isAddState, conditionSearch } = useShare;
  142. onMounted(() => {
  143. isAddState.value = false;
  144. console.log('isAddState', isAddState.value);
  145. queryToTenantId.value = -10;
  146. conditionSearch();
  147. });
  148. const cameraOverview = useCameraOverview();
  149. const { cameraItems, loading, total, page, size } = storeToRefs(cameraOverview);
  150. const { getCameraItems, openInterval, closeInterval, reset } = cameraOverview;
  151. const tableRef = ref();
  152. // 添加弹窗相关
  153. const showAddPopover = ref(false);
  154. // 批量添加弹窗
  155. const showBatchImportPopover = ref(false);
  156. // 批量删除弹窗
  157. const showBatchEditPopover = ref(false);
  158. const showSharedPopover = ref(false);
  159. const addSharedPopover = ref(false);
  160. const showEditPopover = ref(false);
  161. const showEditSRSPopover = ref(false);
  162. const showEditNVRPopover = ref(false);
  163. const editCameraData = ref<CameraDetailServer>();
  164. const shareCameraData = ref<CameraDetailServer | null>();
  165. // 多选操作
  166. const showActionBar = ref(false);
  167. const chooseNum = ref(0);
  168. const chooseId = ref<number[]>([]);
  169. const isActiveExport = ref(false);
  170. const isActiveDelete = ref(false);
  171. const updateUnaddAmount = () => {
  172. isAddState.value = false;
  173. console.log('isAddState', isAddState.value);
  174. queryToTenantId.value = -10;
  175. conditionSearch();
  176. };
  177. //操作列
  178. const actionColumn: BasicColumn = reactive({
  179. width: 200,
  180. title: '操作',
  181. prop: 'action',
  182. key: 'action',
  183. fixed: 'right',
  184. render(record) {
  185. return h(TableActionIcons as any, {
  186. space: 20,
  187. color: '#629bf9',
  188. style: 'img',
  189. size: 16,
  190. actionIcons: [
  191. {
  192. label: '分享',
  193. icon: shareIcon,
  194. onClick: handleShare.bind(null, record.row),
  195. },
  196. {
  197. label: '预览',
  198. icon: previewIcon,
  199. onClick: handlePreview.bind(null, record.row),
  200. },
  201. {
  202. label: '编辑',
  203. icon: editIcon,
  204. onClick: handleEdit.bind(null, record.row),
  205. },
  206. {
  207. label: '删除',
  208. icon: deleteIcon,
  209. onClick: handleDelete.bind(null, record.row),
  210. },
  211. ],
  212. });
  213. },
  214. });
  215. // 列排序操作
  216. const orderByItem = () => {};
  217. // 多选操作
  218. const handleSelectionChange = (selection) => {
  219. chooseNum.value = selection.length;
  220. showActionBar.value = chooseNum.value > 0 ? true : false;
  221. chooseId.value = [];
  222. selection.forEach((item) => {
  223. if (chooseId.value.indexOf(item.id) === -1) chooseId.value.push(item.id);
  224. });
  225. };
  226. const handleBatchExport = async () => {
  227. try {
  228. const requestBody = {
  229. cameraIdList: chooseId.value,
  230. };
  231. const config: AxiosRequestConfig = {
  232. headers: getHeaders(),
  233. responseType: 'blob',
  234. };
  235. const response = await axios.post(
  236. urlPrefix + '/addCameraList/downloadCameraList',
  237. requestBody,
  238. config,
  239. );
  240. const blob = new Blob([response.data], {
  241. type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
  242. });
  243. // 创建下载链接
  244. let downloadLink: HTMLAnchorElement | null = document.createElement('a');
  245. const url = window.URL.createObjectURL(blob);
  246. downloadLink.href = url;
  247. downloadLink.download = '相机导出信息.xlsx';
  248. downloadLink.click();
  249. // 移除下载链接
  250. window.URL.revokeObjectURL(url);
  251. downloadLink = null;
  252. } catch (error) {
  253. console.error('Error downloading file:', error);
  254. }
  255. };
  256. const handleBatchDelete = () => {
  257. if (showActionBar.value) isActiveDelete.value = !isActiveDelete.value;
  258. ElMessageBox.confirm('删除后,相机数据无法恢复', '请确认是否删除相机数据', {
  259. confirmButtonText: '确定',
  260. cancelButtonText: '取消',
  261. type: 'warning',
  262. customClass: 'deleteMessage',
  263. center: true,
  264. })
  265. .then(() => {
  266. deleteCameraItems(chooseId.value).then(() => {
  267. ElMessage({
  268. type: 'success',
  269. message: '删除成功',
  270. });
  271. page.value = 1;
  272. getCameraItems();
  273. handleSelectNone();
  274. isActiveDelete.value = !isActiveDelete.value;
  275. });
  276. })
  277. .catch(() => {
  278. ElMessage({
  279. type: 'info',
  280. message: '取消删除',
  281. });
  282. isActiveDelete.value = !isActiveDelete.value;
  283. });
  284. };
  285. // 清除多选
  286. const handleSelectNone = () => {
  287. chooseId.value = [];
  288. chooseNum.value = 0;
  289. tableRef.value?.clearAll();
  290. showActionBar.value = false;
  291. };
  292. const handlePageNumChange = (pageNum) => {
  293. page.value = pageNum;
  294. getCameraItems();
  295. };
  296. const handlePageSizeChange = (pageSize) => {
  297. page.value = 1;
  298. size.value = pageSize;
  299. getCameraItems();
  300. };
  301. const handleShare = (row) => {
  302. addSharedPopover.value = true;
  303. shareCameraData.value = row;
  304. };
  305. const handlePreview = (_row) => {
  306. router.push(`/algorithm/config?cameraId=${_row.id}`);
  307. };
  308. const handleDelete = (row) => {
  309. ElMessageBox.confirm(`您想删除相机${row.code}`, '提示', {
  310. confirmButtonText: '确定',
  311. cancelButtonText: '取消',
  312. type: 'warning',
  313. draggable: true,
  314. })
  315. .then(() => {
  316. deleteCameraItem({ cameraId: row.id }).then(() => {
  317. ElMessage.success('删除成功');
  318. getCameraItems();
  319. });
  320. })
  321. .catch(() => {});
  322. };
  323. const handleEdit = (row) => {
  324. if (row.sourceType === AddType.srs) {
  325. showEditSRSPopover.value = true;
  326. } else if (row.sourceType === AddType.ip) {
  327. showEditPopover.value = true;
  328. } else {
  329. showEditNVRPopover.value = true;
  330. }
  331. editCameraData.value = row;
  332. };
  333. // 批量导入相关事件
  334. const handleUpdateBatchImport = () => {
  335. showBatchImportPopover.value = false;
  336. page.value = 1;
  337. size.value = 10;
  338. getCameraItems();
  339. };
  340. const handleCloseBatchImport = () => {
  341. showBatchImportPopover.value = false;
  342. };
  343. // 批量修改相关事件
  344. const handleUpdateBatchEdit = () => {
  345. showBatchEditPopover.value = false;
  346. page.value = 1;
  347. size.value = 10;
  348. getCameraItems();
  349. };
  350. const handleCloseBatchEdit = () => {
  351. showBatchEditPopover.value = false;
  352. };
  353. onMounted(() => {
  354. getCameraItems();
  355. openInterval();
  356. getSceneTemplateList();
  357. });
  358. onBeforeUnmount(() => {
  359. closeInterval();
  360. reset();
  361. });
  362. </script>
  363. <style scoped lang="less">
  364. .action-bar {
  365. display: flex;
  366. align-items: center;
  367. position: absolute;
  368. top: 48px;
  369. min-width: calc(100vw - 266px);
  370. height: 50px;
  371. border-radius: 4px 4px 0px 0px;
  372. background-color: #ddefff;
  373. z-index: 10;
  374. .num-text {
  375. margin: 0 34px 0 25px;
  376. color: rgba(0, 0, 0, 0.85);
  377. font-weight: 500;
  378. }
  379. .btn-normal {
  380. color: #1890ff;
  381. background: transparent;
  382. border: 1px solid #1890ff;
  383. border-radius: 2px;
  384. }
  385. .btn-active {
  386. color: #ffffff;
  387. background-color: #1890ff;
  388. }
  389. .close-btn {
  390. margin-left: auto;
  391. margin-right: 20px;
  392. }
  393. .close-btn:before {
  394. content: '\2716';
  395. color: #000;
  396. cursor: pointer;
  397. }
  398. }
  399. .camera-page {
  400. position: relative;
  401. height: calc(100vh - 64px - 12px);
  402. background-color: #ffffff;
  403. }
  404. .camera-list {
  405. padding: 0 21px;
  406. position: relative;
  407. }
  408. .empty-content {
  409. margin: auto;
  410. padding: 125px 0;
  411. }
  412. .empty-img {
  413. width: 396px;
  414. }
  415. .empty-text {
  416. font-size: 22px;
  417. color: #8e8e8e;
  418. line-height: 30px;
  419. text-align: center;
  420. }
  421. .add-tip {
  422. position: absolute;
  423. left: 187px;
  424. top: 64px;
  425. font-size: 16px;
  426. color: red;
  427. }
  428. .add-popover {
  429. position: absolute;
  430. width: calc(100% - 21px);
  431. height: 622px;
  432. top: 0;
  433. bottom: 0;
  434. margin: auto;
  435. z-index: 99;
  436. }
  437. .batch-import {
  438. position: absolute;
  439. width: 593px;
  440. height: 435px;
  441. left: 50%;
  442. top: 50%;
  443. margin-top: -218px;
  444. margin-left: -297px;
  445. z-index: 99;
  446. }
  447. .item {
  448. margin: 0px 40px 0px 15px;
  449. }
  450. </style>
  451. <style lang="less">
  452. .deleteMessage {
  453. padding: 20px 24px;
  454. box-shadow: 0px 12px 48px 16px rgba(0, 0, 0, 0.03), 0px 9px 28px 0px rgba(0, 0, 0, 0.05),
  455. 0px 6px 16px -8px rgba(0, 0, 0, 0.08);
  456. border-radius: 8px;
  457. .el-message-box__headerbtn {
  458. margin-top: 12px;
  459. margin-right: 12px;
  460. }
  461. .el-message-box__title {
  462. justify-content: start;
  463. color: rgba(0, 0, 0, 0.88);
  464. font-size: 16px;
  465. font-weight: 500;
  466. }
  467. .el-message-box__container {
  468. justify-content: start;
  469. margin-left: 23px;
  470. }
  471. .el-message-box__btns {
  472. display: block;
  473. float: right;
  474. }
  475. }
  476. </style>