index.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. <template>
  2. <div class="ele-body">
  3. <el-card shadow="never">
  4. <!-- 搜索表单 -->
  5. <camera-search ref="searchRef" @search="reload" />
  6. <!-- 数据表格 -->
  7. <ele-pro-table
  8. ref="table"
  9. :columns="columns"
  10. :datasource="datasource"
  11. :selection.sync="selection"
  12. :cache-key="cacheKeyUrl"
  13. :response="{
  14. dataName: 'data.records', // 数据列表的字段名称,支持嵌套,例如:data.rows
  15. countName: 'data.total' // 数据总数的字段名称,例如:data.total
  16. }"
  17. >
  18. <!-- 表头工具栏 -->
  19. <template v-slot:toolbar>
  20. <el-button
  21. type="primary"
  22. icon="el-icon-plus"
  23. class="ele-btn-icon"
  24. v-if="$hasPermission('ledgerAssets:camera:create')"
  25. @click="openForm('create')"
  26. >
  27. 新建
  28. </el-button>
  29. <el-button
  30. type="danger"
  31. icon="el-icon-delete"
  32. class="ele-btn-icon"
  33. v-if="
  34. $hasPermission('ledgerAssets:camera:delete') && selection.length
  35. "
  36. @click="handleBatchDelete"
  37. >
  38. 批量删除
  39. </el-button>
  40. </template>
  41. <!-- 摄像机状态列 -->
  42. <template v-slot:activityStatus="{ row }">
  43. <el-switch
  44. v-model="row.activityStatus"
  45. :active-value="1"
  46. :inactive-value="0"
  47. @change="handleStatusChange(row)"
  48. />
  49. </template>
  50. <!-- 操作列 -->
  51. <template v-slot:action="{ row }">
  52. <el-link
  53. type="primary"
  54. :underline="false"
  55. icon="el-icon-edit"
  56. v-if="$hasPermission('ledgerAssets:camera:update')"
  57. @click="openForm('update', row.id)"
  58. >
  59. 编辑
  60. </el-link>
  61. <el-link
  62. type="primary"
  63. :underline="false"
  64. icon="el-icon-delete"
  65. :style="{ color: delColor }"
  66. v-if="$hasPermission('ledgerAssets:camera:delete')"
  67. @click="handleDelete(row.id)"
  68. >
  69. 删除
  70. </el-link>
  71. </template>
  72. </ele-pro-table>
  73. </el-card>
  74. <!-- 表单弹窗:添加/修改 -->
  75. <formModel ref="formRef" @success="reload" />
  76. </div>
  77. </template>
  78. <script>
  79. import * as CameraApi from '@/api/ledgerAssets/camera';
  80. import formModel from './components/formModel.vue';
  81. import cameraSearch from './components/camera-search.vue';
  82. export default {
  83. name: 'LedgerCamera',
  84. components: {
  85. formModel,
  86. cameraSearch
  87. },
  88. data() {
  89. return {
  90. cacheKeyUrl: 'ledgerCameraTable',
  91. delColor: '#F56C6C',
  92. selection: [],
  93. // 表格列配置
  94. columns: [
  95. {
  96. width: 45,
  97. type: 'selection',
  98. columnKey: 'selection',
  99. align: 'center',
  100. fixed: 'left'
  101. },
  102. {
  103. columnKey: 'index',
  104. label: '序号',
  105. type: 'index',
  106. width: 55,
  107. align: 'center',
  108. showOverflowTooltip: true,
  109. fixed: 'left'
  110. },
  111. {
  112. prop: 'deviceCode',
  113. label: '摄像机编号',
  114. headerAlign: 'center',
  115. align: 'center',
  116. showOverflowTooltip: true,
  117. width: 180
  118. },
  119. {
  120. prop: 'name',
  121. label: '摄像机名称',
  122. headerAlign: 'center',
  123. align: 'center',
  124. showOverflowTooltip: true,
  125. minWidth: 200
  126. },
  127. {
  128. prop: 'brandName',
  129. label: '设备品牌',
  130. headerAlign: 'center',
  131. align: 'center',
  132. showOverflowTooltip: true,
  133. width: 180
  134. },
  135. {
  136. prop: 'modelName',
  137. label: '设备型号',
  138. headerAlign: 'center',
  139. align: 'center',
  140. showOverflowTooltip: true,
  141. width: 180
  142. },
  143. {
  144. prop: 'classifyName',
  145. label: '摄像机类型',
  146. headerAlign: 'center',
  147. align: 'center',
  148. showOverflowTooltip: true,
  149. width: 180
  150. },
  151. // {
  152. // prop: 'loadDeviceName',
  153. // label: '关联设备',
  154. // headerAlign: 'center',
  155. // align: 'center',
  156. // showOverflowTooltip: true,
  157. // width: 150
  158. // },
  159. {
  160. prop: 'activityStatus',
  161. label: '摄像机状态',
  162. align: 'center',
  163. showOverflowTooltip: true,
  164. width: 120,
  165. slot: 'activityStatus'
  166. },
  167. {
  168. columnKey: 'action',
  169. fixed: 'right',
  170. label: '操作',
  171. width: 160,
  172. align: 'center',
  173. resizable: false,
  174. slot: 'action',
  175. showOverflowTooltip: true
  176. }
  177. ],
  178. loading: false
  179. };
  180. },
  181. methods: {
  182. /* 表格数据源 */
  183. async datasource({ page, limit, where }) {
  184. return await CameraApi.getDevicePage({
  185. pageNum: page,
  186. size: limit,
  187. ...where
  188. });
  189. console.log('获取摄像机分页数据', res);
  190. return res.data.records;
  191. },
  192. /* 刷新表格 */
  193. reload(where) {
  194. this.$refs.table.reload({ page: 1, where });
  195. },
  196. /** 添加/修改操作 */
  197. openForm(type, id) {
  198. this.$refs.formRef.open(type, id);
  199. },
  200. /** 状态切换 */
  201. handleStatusChange(row) {
  202. const text = row.activityStatus === 1 ? '启用' : '停用';
  203. this.$confirm('确认要' + text + '摄像机"' + row.name + '"吗?', '提示', {
  204. confirmButtonText: '确定',
  205. cancelButtonText: '取消',
  206. type: 'warning'
  207. })
  208. .then(async () => {
  209. row.extInfo = row.extInfo || '{}';
  210. await CameraApi.updateDevice(row);
  211. this.$message.success(text + '成功');
  212. this.reload();
  213. })
  214. .catch(() => {
  215. row.activityStatus = row.activityStatus === 1 ? 0 : 1;
  216. });
  217. },
  218. /** 删除按钮操作 */
  219. handleDelete(id) {
  220. this.$confirm('是否确认删除该数据项?', '警告', {
  221. confirmButtonText: '确定',
  222. cancelButtonText: '取消',
  223. type: 'warning'
  224. })
  225. .then(async () => {
  226. await CameraApi.deletedDevice(id);
  227. this.$message.success('删除成功');
  228. this.reload();
  229. })
  230. .catch(() => {});
  231. },
  232. /** 批量删除按钮操作 */
  233. handleBatchDelete() {
  234. if (this.selection.length === 0) {
  235. this.$message.warning('请选择要删除的数据项');
  236. return;
  237. }
  238. this.$confirm('是否确认删除选中的数据项?', '警告', {
  239. confirmButtonText: '确定',
  240. cancelButtonText: '取消',
  241. type: 'warning'
  242. })
  243. .then(async () => {
  244. const ids = this.selection.map((item) => item.id);
  245. for (const id of ids) {
  246. await CameraApi.deletedDevice(id);
  247. }
  248. this.$message.success('删除成功');
  249. this.reload();
  250. })
  251. .catch(() => {});
  252. }
  253. }
  254. };
  255. </script>
  256. <style lang="scss" scoped></style>