| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269 |
- <template>
- <div class="ele-body">
- <el-card shadow="never">
- <!-- 搜索表单 -->
- <camera-search ref="searchRef" @search="reload" />
- <!-- 数据表格 -->
- <ele-pro-table
- ref="table"
- :columns="columns"
- :datasource="datasource"
- :selection.sync="selection"
- :cache-key="cacheKeyUrl"
- :response="{
- dataName: 'data.records', // 数据列表的字段名称,支持嵌套,例如:data.rows
- countName: 'data.total' // 数据总数的字段名称,例如:data.total
- }"
- >
- <!-- 表头工具栏 -->
- <template v-slot:toolbar>
- <el-button
- type="primary"
- icon="el-icon-plus"
- class="ele-btn-icon"
- v-if="$hasPermission('ledgerAssets:camera:create')"
- @click="openForm('create')"
- >
- 新建
- </el-button>
- <el-button
- type="danger"
- icon="el-icon-delete"
- class="ele-btn-icon"
- v-if="
- $hasPermission('ledgerAssets:camera:delete') && selection.length
- "
- @click="handleBatchDelete"
- >
- 批量删除
- </el-button>
- </template>
- <!-- 摄像机状态列 -->
- <template v-slot:activityStatus="{ row }">
- <el-switch
- v-model="row.activityStatus"
- :active-value="1"
- :inactive-value="0"
- @change="handleStatusChange(row)"
- />
- </template>
- <!-- 操作列 -->
- <template v-slot:action="{ row }">
- <el-link
- type="primary"
- :underline="false"
- icon="el-icon-edit"
- v-if="$hasPermission('ledgerAssets:camera:update')"
- @click="openForm('update', row.id)"
- >
- 编辑
- </el-link>
- <el-link
- type="primary"
- :underline="false"
- icon="el-icon-delete"
- :style="{ color: delColor }"
- v-if="$hasPermission('ledgerAssets:camera:delete')"
- @click="handleDelete(row.id)"
- >
- 删除
- </el-link>
- </template>
- </ele-pro-table>
- </el-card>
- <!-- 表单弹窗:添加/修改 -->
- <formModel ref="formRef" @success="reload" />
- </div>
- </template>
- <script>
- import * as CameraApi from '@/api/ledgerAssets/camera';
- import formModel from './components/formModel.vue';
- import cameraSearch from './components/camera-search.vue';
- export default {
- name: 'LedgerCamera',
- components: {
- formModel,
- cameraSearch
- },
- data() {
- return {
- cacheKeyUrl: 'ledgerCameraTable',
- delColor: '#F56C6C',
- selection: [],
- // 表格列配置
- columns: [
- {
- width: 45,
- type: 'selection',
- columnKey: 'selection',
- align: 'center',
- fixed: 'left'
- },
- {
- columnKey: 'index',
- label: '序号',
- type: 'index',
- width: 55,
- align: 'center',
- showOverflowTooltip: true,
- fixed: 'left'
- },
- {
- prop: 'deviceCode',
- label: '摄像机编号',
- headerAlign: 'center',
- align: 'center',
- showOverflowTooltip: true,
- width: 180
- },
- {
- prop: 'name',
- label: '摄像机名称',
- headerAlign: 'center',
- align: 'center',
- showOverflowTooltip: true,
- minWidth: 200
- },
- {
- prop: 'brandName',
- label: '设备品牌',
- headerAlign: 'center',
- align: 'center',
- showOverflowTooltip: true,
- width: 180
- },
- {
- prop: 'modelName',
- label: '设备型号',
- headerAlign: 'center',
- align: 'center',
- showOverflowTooltip: true,
- width: 180
- },
- {
- prop: 'classifyName',
- label: '摄像机类型',
- headerAlign: 'center',
- align: 'center',
- showOverflowTooltip: true,
- width: 180
- },
- // {
- // prop: 'loadDeviceName',
- // label: '关联设备',
- // headerAlign: 'center',
- // align: 'center',
- // showOverflowTooltip: true,
- // width: 150
- // },
- {
- prop: 'activityStatus',
- label: '摄像机状态',
- align: 'center',
- showOverflowTooltip: true,
- width: 120,
- slot: 'activityStatus'
- },
- {
- columnKey: 'action',
- fixed: 'right',
- label: '操作',
- width: 160,
- align: 'center',
- resizable: false,
- slot: 'action',
- showOverflowTooltip: true
- }
- ],
- loading: false
- };
- },
- methods: {
- /* 表格数据源 */
- async datasource({ page, limit, where }) {
- return await CameraApi.getDevicePage({
- pageNum: page,
- size: limit,
- ...where
- });
- console.log('获取摄像机分页数据', res);
- return res.data.records;
- },
- /* 刷新表格 */
- reload(where) {
- this.$refs.table.reload({ page: 1, where });
- },
- /** 添加/修改操作 */
- openForm(type, id) {
- this.$refs.formRef.open(type, id);
- },
- /** 状态切换 */
- handleStatusChange(row) {
- const text = row.activityStatus === 1 ? '启用' : '停用';
- this.$confirm('确认要' + text + '摄像机"' + row.name + '"吗?', '提示', {
- confirmButtonText: '确定',
- cancelButtonText: '取消',
- type: 'warning'
- })
- .then(async () => {
- row.extInfo = row.extInfo || '{}';
- await CameraApi.updateDevice(row);
- this.$message.success(text + '成功');
- this.reload();
- })
- .catch(() => {
- row.activityStatus = row.activityStatus === 1 ? 0 : 1;
- });
- },
- /** 删除按钮操作 */
- handleDelete(id) {
- this.$confirm('是否确认删除该数据项?', '警告', {
- confirmButtonText: '确定',
- cancelButtonText: '取消',
- type: 'warning'
- })
- .then(async () => {
- await CameraApi.deletedDevice(id);
- this.$message.success('删除成功');
- this.reload();
- })
- .catch(() => {});
- },
- /** 批量删除按钮操作 */
- handleBatchDelete() {
- if (this.selection.length === 0) {
- this.$message.warning('请选择要删除的数据项');
- return;
- }
- this.$confirm('是否确认删除选中的数据项?', '警告', {
- confirmButtonText: '确定',
- cancelButtonText: '取消',
- type: 'warning'
- })
- .then(async () => {
- const ids = this.selection.map((item) => item.id);
- for (const id of ids) {
- await CameraApi.deletedDevice(id);
- }
- this.$message.success('删除成功');
- this.reload();
- })
- .catch(() => {});
- }
- }
- };
- </script>
- <style lang="scss" scoped></style>
|