NvrList.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. <template>
  2. <div class="nvr-page">
  3. <div class="nvr-list">
  4. <BasicTable :columns="columns" :data-source="nvrList" :row-key="(row) => row.code" :action-column="actionColumn"
  5. :pagination="{
  6. total: total,
  7. pageSize: pagesize,
  8. currentPage: page,
  9. hideOnSinglePage: !nvrList.length,
  10. }" :tableSetting="{
  11. size: false,
  12. redo: false,
  13. fullscreen: false,
  14. striped: false,
  15. setting: false,
  16. }" :striped="true" ref="tableRef" @page-num-change="handlePageNumChange"
  17. @page-size-change="handlePageSizeChange">
  18. <template #tableTitle>
  19. <el-button type="primary" @click="openCreateDrawer" :icon="Plus" v-permission="{ action: [PERM_DEVICE.NVR_ADD] }">添加</el-button>
  20. </template>
  21. <template #empty>
  22. <div class="empty-content flex flex-col items-center">
  23. <img :src="emptyImg" class="empty-img" />
  24. <span class="empty-text">暂未添加NVR设备</span>
  25. </div>
  26. </template>
  27. </BasicTable>
  28. </div>
  29. <CreateDrawer ref="createDrawerRef" :title="drawerTitle" @form-submit="handleFormSubmit"
  30. @form-edit="handleFormEdit" />
  31. </div>
  32. </template>
  33. <script lang="ts" setup>
  34. import { h, ref, reactive, onMounted } from 'vue';
  35. import { Plus } from '@element-plus/icons-vue';
  36. import { ElMessage, ElMessageBox } from 'element-plus';
  37. import editIcon from '@/assets/images/table/table-edit.png';
  38. import deleteIcon from '@/assets/images/table/table-delete.png';
  39. import emptyImg from '@/assets/images/table/table-empty.png';
  40. import { columns } from './overviewColumns';
  41. import { BasicTable, TableActionIcons, BasicColumn } from '@/components/Table';
  42. import CreateDrawer from './components/CreateDrawer.vue';
  43. import { deleteNVRListItem, getNVRList, NVRListItemAll } from '@/api/camera/camera-nvr';
  44. import { PERM_DEVICE } from '@/types/permission/constants';
  45. import { useUserStore } from '@/store/modules/user';
  46. const nvrList = ref<NVRListItemAll[]>([]);
  47. const total = ref(0);
  48. const page = ref(1);
  49. const pagesize = ref(10);
  50. const getNvrList = () => {
  51. const queryForm = {
  52. pageNumber: page.value,
  53. pageSize: pagesize.value,
  54. };
  55. getNVRList(queryForm).then((res) => {
  56. total.value = res.totalRow;
  57. nvrList.value = res.records;
  58. });
  59. }
  60. const drawerTitle = ref('添加NVR');
  61. const createDrawerRef = ref();
  62. //添加数据
  63. const openCreateDrawer = () => {
  64. drawerTitle.value = '添加NVR';
  65. const { openDrawer } = createDrawerRef.value;
  66. openDrawer();
  67. };
  68. // 编辑
  69. const handleEdit = (row) => {
  70. drawerTitle.value = '编辑NVR';
  71. const { openDrawer } = createDrawerRef.value;
  72. openDrawer(row);
  73. };
  74. // 删除
  75. const handleDelete = (row) => {
  76. ElMessageBox.confirm(
  77. '删除后使用该NVR设备的车间内相关相机历史视频内容将无法查看',
  78. '请确认是否删除NVR设备信息?',
  79. {
  80. confirmButtonText: '确定',
  81. cancelButtonText: '取消',
  82. type: 'warning',
  83. customClass: 'deleteMessage',
  84. center: true
  85. }
  86. )
  87. .then(() => {
  88. deleteNVRListItem(row.id).then(() => {
  89. ElMessage({
  90. message: '删除NVR设备成功.',
  91. type: 'success',
  92. });
  93. getNvrList();
  94. })
  95. })
  96. .catch(() => {
  97. ElMessage({
  98. type: 'info',
  99. message: '取消删除',
  100. })
  101. })
  102. };
  103. const userStore = useUserStore();
  104. //操作列
  105. const actionColumn: BasicColumn = reactive({
  106. width: 200,
  107. title: '操作',
  108. prop: 'action',
  109. key: 'action',
  110. fixed: 'right',
  111. render(record) {
  112. const actions: any[] = [];
  113. if (userStore.checkPermission(PERM_DEVICE.NVR_EDIT)) {
  114. actions.push({
  115. label: '修改',
  116. icon: editIcon,
  117. onClick: handleEdit.bind(null, record.row),
  118. });
  119. }
  120. if (userStore.checkPermission(PERM_DEVICE.NVR_DELETE)) {
  121. actions.push({
  122. label: '删除',
  123. icon: deleteIcon,
  124. onClick: handleDelete.bind(null, record.row),
  125. });
  126. }
  127. return h(TableActionIcons as any, {
  128. space: 20,
  129. color: '#629bf9',
  130. iconStyle: 'img',
  131. size: 16,
  132. actionIcons: [
  133. {
  134. label: '修改',
  135. icon: editIcon,
  136. onClick: handleEdit.bind(null, record.row),
  137. ifShow: userStore.checkPermission(PERM_DEVICE.NVR_EDIT)
  138. },
  139. {
  140. label: '删除',
  141. icon: deleteIcon,
  142. onClick: handleDelete.bind(null, record.row),
  143. ifShow: userStore.checkPermission(PERM_DEVICE.NVR_DELETE)
  144. }
  145. ]
  146. });
  147. },
  148. });
  149. const handleFormSubmit = () => {
  150. ElMessage({
  151. message: '添加NVR设备成功.',
  152. type: 'success',
  153. });
  154. getNvrList();
  155. };
  156. const handleFormEdit = () => {
  157. ElMessage({
  158. message: '修改NVR设备成功.',
  159. type: 'success',
  160. });
  161. getNvrList();
  162. };
  163. const handlePageNumChange = (pageNum) => {
  164. page.value = pageNum;
  165. getNvrList();
  166. };
  167. const handlePageSizeChange = (size) => {
  168. page.value = 1;
  169. pagesize.value = size;
  170. getNvrList();
  171. };
  172. onMounted(() => {
  173. getNvrList();
  174. });
  175. </script>
  176. <style lang="scss" scoped>
  177. .nvr-page {
  178. position: relative;
  179. height: calc(100vh - 64px - 12px);
  180. background-color: #ffffff;
  181. .nvr-list {
  182. padding: 35px 21px;
  183. }
  184. }
  185. .empty-content {
  186. margin: auto;
  187. padding: 125px 0;
  188. }
  189. .empty-img {
  190. width: 396px;
  191. }
  192. .empty-text {
  193. font-size: 22px;
  194. color: #8e8e8e;
  195. line-height: 30px;
  196. text-align: center;
  197. }
  198. </style>
  199. <style lang="scss">
  200. .deleteMessage {
  201. padding: 20px 24px;
  202. box-shadow: 0px 12px 48px 16px rgba(0, 0, 0, 0.03), 0px 9px 28px 0px rgba(0, 0, 0, 0.05), 0px 6px 16px -8px rgba(0, 0, 0, 0.08);
  203. border-radius: 8px;
  204. .el-message-box__headerbtn {
  205. margin-top: 12px;
  206. margin-right: 12px;
  207. }
  208. .el-message-box__title {
  209. justify-content: start;
  210. color: rgba(0, 0, 0, 0.88);
  211. font-size: 16px;
  212. font-weight: 500;
  213. }
  214. .el-message-box__container {
  215. justify-content: start;
  216. margin-left: 23px;
  217. }
  218. .el-message-box__btns {
  219. display: block;
  220. float: right;
  221. }
  222. }
  223. </style>