Newer
Older
robot_dog_patrol_front / src / views / home / rule / special / index.vue
liyaguang on 25 Dec 5 KB 需求与问题修改
<!--
  Description: 规则引擎-特殊报警规则管理
  Author: 李亚光
  Date: 2024-09-04
 -->
<script lang="ts" setup name="RuleAlarmSpecialManage">
import { ElLoading, ElMessage, ElMessageBox } from 'element-plus'
import editDialog from './components/editDialog.vue'
import { getDeviceTypeListPage } from '@/api/home/device/type'
import { getSpecialAlarmRuleListPage, removeSpecialAlarmRule } from '@/api/home/rule/special'
const deviceTypeList = ref<any[]>([]) // 设备类型列表
// 表格数据
const list = ref([])
const total = ref(0)
// 初始展示列
const columns = ref<any>([
  { text: '设备编号', value: 'devcode', align: 'center', width: '140' },
  { text: '设备类型', value: 'devTypeName', align: 'center', width: '200' },
  { text: '绑定点位', value: 'tagNumber', align: 'center', width: '160' },
  { text: '详细位置', value: 'position', align: 'center' },
  { text: '报警规则', value: 'alarmRuleName', align: 'center' },
  { text: '操作时间', value: 'ts', align: 'center', width: '180' },
  { text: '操作人', value: 'createUser', align: 'center', width: '110' },
])
// 最终展示列
const columnsConfig = ref([])
// 修改列
const editColumns = (data: any) => {
  columnsConfig.value = data
}
const loadingTable = ref(true)
//  查询条件
const listQuery = ref({
  limit: 20,
  offset: 1,
  devCode: '',
  devTypeId: '',
})
// 查询数据
const fetchData = () => {
  loadingTable.value = true
  getSpecialAlarmRuleListPage(listQuery.value).then((res) => {
    list.value = res.data.rows
    total.value = res.data.total
    loadingTable.value = false
  }).catch(() => {
    loadingTable.value = false
  })
}
// 重置查询条件f
const reset = () => {
  listQuery.value = {
    limit: 20,
    offset: 1,
    devCode: '',
    devTypeId: '',
  }
  fetchData()
}
// 页数发生变化后的操作,可能是页码变化,可能是每页容量变化,此函数必写
const changePage = (val: { size: number; page: number }) => {
  if (val && val.size) {
    listQuery.value.limit = val.size
  }
  if (val && val.page) {
    listQuery.value.offset = val.page
  }
  fetchData()
}
// 查看详情
const editRef = ref()
const detail = (type: string, row: any) => {
  editRef.value.initDialog(type, row)
}
// 删除行
const removeRow = (row: any) => {
  ElMessageBox.confirm(
    '确定要删除该数据吗?',
    '确认操作',
    {
      confirmButtonText: '确定',
      cancelButtonText: '取消',
      type: 'warning',
    },
  ).then(() => {
    removeSpecialAlarmRule(row.id).then(() => {
      ElMessage.success('操作成功')
      fetchData()
    })
  })
}
// 获取字典
const fetchDict = async () => {
  // 获取设备类型
  getDeviceTypeListPage({ limit: 9999, offset: 1 }).then(res => {
    deviceTypeList.value = res.data.rows
  })

}
onMounted(async () => {
  fetchData()
  fetchDict()
})
const { proxy } = getCurrentInstance() as any
</script>

<template>
  <!-- 布局 -->
  <app-container>
    <edit-dialog ref="editRef" @refresh="fetchData" />
    <!-- 筛选条件 -->
    <search-area :need-clear="true" @search="fetchData" @clear="reset">
      <search-item>
        <el-input v-model="listQuery.devCode" placeholder="设备编号" clearable />
      </search-item>
      <search-item>
        <el-select v-model="listQuery.devTypeId" placeholder="设备类型" clearable filterable class="select"
          style="width: 192px;">
          <el-option v-for="item in deviceTypeList" :key="item.id" :label="item.typeName" :value="item.id" />
        </el-select>
      </search-item>
    </search-area>
    <!-- 表头标题 -->
    <table-container :is-config="true" config-title="alarm-rule-special" :columns="columns"
      :config-columns="columnsConfig" :edit="editColumns">
      <template #btns-right>
        <!-- 操作 -->
        <div>
          <el-button v-if="proxy.hasPerm('/rule/special/add')" type="primary" @click="detail('create', {})">
            新增
          </el-button>
        </div>
      </template>
      <!-- 查询结果Table显示 -->
      <normal-table :data="list" :total="total" :columns="columnsConfig" :query="listQuery" :list-loading="loadingTable"
        @change="changePage">
        <template #preColumns>
          <el-table-column label="序号" width="70" align="center">
            <template #default="scope">
              {{ (listQuery.offset - 1) * listQuery.limit + scope.$index + 1 }}
            </template>
          </el-table-column>
        </template>
        <template #columns>
          <el-table-column label="操作" width="140" align="center">
            <template #default="scope">
              <el-button v-if="proxy.hasPerm('/rule/special/detail')" type="primary" link size="small"
                @click="detail('detail', scope.row)">
                查看
              </el-button>
              <el-button v-if="proxy.hasPerm('/rule/special/update')" type="primary" link size="small"
                @click="detail('edit', scope.row)">
                编辑
              </el-button>
              <el-button v-if="proxy.hasPerm('/rule/special/delete')" type="danger" link size="small"
                @click="removeRow(scope.row)">
                删除
              </el-button>
            </template>
          </el-table-column>
        </template>
      </normal-table>
    </table-container>
  </app-container>
</template>