index.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <template>
  2. <div class="fault-config">
  3. <a-button type="primary" @click="handleAdd">新增</a-button>
  4. <a-table size="small" :dataSource="dataSource" :columns="columns" :scroll="{ y: 620 }" :pagination="pagination"
  5. @change="pageChange">
  6. <template #action="{ record }">
  7. <a class="table-action-link" @click="handleEdit(record)">编辑</a>
  8. <a class="table-action-link" @click="handleDelete(record)">删除</a>
  9. </template>
  10. </a-table>
  11. <!-- 新增、编辑弹窗 -->
  12. <a-modal v-model:visible="visibleModal" width="650px" :title="titleModal" :footer="null" centered destroyOnClose
  13. @cancel="handleCancel">
  14. <OperationTable ref="operationModal" :gateId="deviceId" :recordData="recordData" :cameraData="cameraData" @handleClose="handleClose">
  15. </OperationTable>
  16. </a-modal>
  17. </div>
  18. </template>
  19. <script setup lang="ts">
  20. import { reactive, ref, onMounted } from 'vue'
  21. import { columns } from './faultConfig.data'
  22. import { list, deleteById, cameraList } from './faultConfig.api'
  23. import OperationTable from './components/operationTable.vue'
  24. let props = defineProps({
  25. deviceId: {
  26. type: String,
  27. default: ''
  28. }
  29. })
  30. let operationModal = ref()
  31. let dataSource = ref<any[]>([]);
  32. //分页参数配置
  33. let pagination = reactive({
  34. current: 1, // 当前页码
  35. pageSize: 10, // 每页显示条数
  36. total: 0, // 总条目数,后端返回
  37. // showTotal: (total, range) => `${range[0]}-${range[1]} 条,总共 ${total} 条`, // 分页右下角显示信息
  38. showSizeChanger: true, // 是否可改变每页显示条数
  39. pageSizeOptions: ['10', '20', '50'], // 可选的每页显示条数
  40. });
  41. let visibleModal = ref(false)//是否显示新增、编辑弹窗
  42. let titleModal = ref('')
  43. let recordData = reactive({})
  44. let cameraData = ref<any[]>([])
  45. //列表查询
  46. async function getList() {
  47. let res = await list({ pageNo: pagination.current, pageSize: pagination.pageSize, gateId: props.deviceId })
  48. console.log(res, '风门故障配置列表---')
  49. dataSource.value=res.records || []
  50. pagination.total=res.total
  51. }
  52. //分页切换
  53. function pageChange(val) {
  54. pagination.current = val.current;
  55. pagination.pageSize = val.pageSize;
  56. getList()
  57. }
  58. //新增
  59. function handleAdd() {
  60. titleModal.value = '新增'
  61. visibleModal.value = true
  62. }
  63. function handleCancel() {
  64. operationModal.value.resetFields()
  65. visibleModal.value = false
  66. }
  67. //编辑
  68. function handleEdit(record) {
  69. titleModal.value = '编辑'
  70. recordData = Object.assign({}, record)
  71. visibleModal.value = true
  72. }
  73. //删除
  74. async function handleDelete(record) {
  75. let res = await deleteById({ id: record.id })
  76. console.log(res, '删除')
  77. getList()
  78. }
  79. function handleClose() {
  80. visibleModal.value = false
  81. getList()
  82. }
  83. //获取摄像头列表
  84. async function getCameraList() {
  85. let res = await cameraList({ pageNo: 1, pageSize: 100, deviceid: props.deviceId })
  86. if (res && res.records.length) {
  87. cameraData.value = res.records.map(el => {
  88. return {
  89. label: el.name,
  90. value: el.id
  91. }
  92. })
  93. }
  94. }
  95. onMounted(() => {
  96. getList()
  97. getCameraList()
  98. })
  99. </script>
  100. <style lang="less" scoped></style>