NvrList.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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">添加</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. const nvrList = ref<NVRListItemAll[]>([]);
  45. const total = ref(0);
  46. const page = ref(1);
  47. const pagesize = ref(10);
  48. const getNvrList = () => {
  49. const queryForm = {
  50. pageNumber: page.value,
  51. pageSize: pagesize.value,
  52. };
  53. getNVRList(queryForm).then((res) => {
  54. console.log('获取表格数据', res);
  55. total.value = res.totalRow;
  56. nvrList.value = res.records;
  57. });
  58. }
  59. const drawerTitle = ref('添加NVR');
  60. const createDrawerRef = ref();
  61. //添加数据
  62. const openCreateDrawer = () => {
  63. drawerTitle.value = '添加NVR';
  64. const { openDrawer } = createDrawerRef.value;
  65. openDrawer();
  66. };
  67. // 编辑
  68. const handleEdit = (row) => {
  69. drawerTitle.value = '编辑NVR';
  70. const { openDrawer } = createDrawerRef.value;
  71. openDrawer(row);
  72. };
  73. // 删除
  74. const handleDelete = (row) => {
  75. ElMessageBox.confirm(
  76. '删除后使用该NVR设备的车间内相关相机历史视频内容将无法查看',
  77. '请确认是否删除NVR设备信息?',
  78. {
  79. confirmButtonText: '确定',
  80. cancelButtonText: '取消',
  81. type: 'warning',
  82. customClass: 'deleteMessage',
  83. center: true
  84. }
  85. )
  86. .then(() => {
  87. deleteNVRListItem(row.id).then(() => {
  88. ElMessage({
  89. message: '删除NVR设备成功.',
  90. type: 'success',
  91. });
  92. getNvrList();
  93. })
  94. })
  95. .catch(() => {
  96. ElMessage({
  97. type: 'info',
  98. message: '取消删除',
  99. })
  100. })
  101. };
  102. //操作列
  103. const actionColumn: BasicColumn = reactive({
  104. width: 200,
  105. title: '操作',
  106. prop: 'action',
  107. key: 'action',
  108. fixed: 'right',
  109. render(record) {
  110. return h(TableActionIcons as any, {
  111. space: 20,
  112. color: '#629bf9',
  113. style: 'img',
  114. size: 16,
  115. actionIcons: [
  116. {
  117. label: '修改',
  118. icon: editIcon,
  119. onClick: handleEdit.bind(null, record.row),
  120. },
  121. {
  122. label: '删除',
  123. icon: deleteIcon,
  124. onClick: handleDelete.bind(null, record.row),
  125. },
  126. ],
  127. });
  128. },
  129. });
  130. const handleFormSubmit = () => {
  131. ElMessage({
  132. message: '添加NVR设备成功.',
  133. type: 'success',
  134. });
  135. getNvrList();
  136. };
  137. const handleFormEdit = () => {
  138. ElMessage({
  139. message: '修改NVR设备成功.',
  140. type: 'success',
  141. });
  142. getNvrList();
  143. };
  144. const handlePageNumChange = (pageNum) => {
  145. page.value = pageNum;
  146. getNvrList();
  147. };
  148. const handlePageSizeChange = (size) => {
  149. page.value = 1;
  150. pagesize.value = size;
  151. getNvrList();
  152. };
  153. onMounted(() => {
  154. getNvrList();
  155. });
  156. </script>
  157. <style lang="scss" scoped>
  158. .nvr-page {
  159. position: relative;
  160. height: calc(100vh - 64px - 12px);
  161. background-color: #ffffff;
  162. .nvr-list {
  163. padding: 35px 21px;
  164. }
  165. }
  166. .empty-content {
  167. margin: auto;
  168. padding: 125px 0;
  169. }
  170. .empty-img {
  171. width: 396px;
  172. }
  173. .empty-text {
  174. font-size: 22px;
  175. color: #8e8e8e;
  176. line-height: 30px;
  177. text-align: center;
  178. }
  179. </style>
  180. <style lang="scss">
  181. .deleteMessage {
  182. padding: 20px 24px;
  183. 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);
  184. border-radius: 8px;
  185. .el-message-box__headerbtn {
  186. margin-top: 12px;
  187. margin-right: 12px;
  188. }
  189. .el-message-box__title {
  190. justify-content: start;
  191. color: rgba(0, 0, 0, 0.88);
  192. font-size: 16px;
  193. font-weight: 500;
  194. }
  195. .el-message-box__container {
  196. justify-content: start;
  197. margin-left: 23px;
  198. }
  199. .el-message-box__btns {
  200. display: block;
  201. float: right;
  202. }
  203. }
  204. </style>