ctrlTable.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. <template>
  2. <!-- 配置预警设备 -->
  3. <div class="warning-device-box">
  4. <div class="warning-box">
  5. <div v-for="item in ctrlList" class="link-item" :class="{ 'active-device-title': item.id == activeID }" :key="item.id">
  6. <span class="" @click="selectWarning(item.id)">{{ item.valuename }}</span>
  7. </div>
  8. </div>
  9. <div class="device-box">
  10. <a-button class="vent-margin-b-5" type="primary" @click="handleOpen(true, {})"> 新增 </a-button>
  11. <a-table :columns="ctrlColumns" :data-source="dataSource" bordered :scroll="{ y: 500 }" :pagination="false">
  12. <template #bodyCell="{ column, record }">
  13. <template v-if="column.dataIndex === 'operation'">
  14. <a class="action-link" @click="handleOpen('update', record)">编辑</a>
  15. <a-popconfirm title="确定删除?" @confirm="handleDelete(record)">
  16. <a class="table-action-link">删除</a>
  17. </a-popconfirm>
  18. </template>
  19. </template>
  20. </a-table>
  21. </div>
  22. </div>
  23. <BaseModal
  24. @register="register"
  25. @add="onSubmit"
  26. @update="onSubmit"
  27. :device-type="props.deviceType"
  28. :device-id="props.deviceId"
  29. :form-schemas="formSchemas"
  30. :monitor-type="''"
  31. />
  32. </template>
  33. <script lang="ts" setup>
  34. import { ref, onMounted } from 'vue';
  35. import { ctrlColumns, ctrlFormSchemas } from './warning.data';
  36. import { getCtrlDevicePointList, addCtrlDevicePoint, editCtrlDevicePoint, getCtrlDevicePointPage, deleteDevicePonit } from './warning.api';
  37. import BaseModal from './BaseModalCtrl.vue';
  38. import { useModal } from '/@/components/Modal';
  39. const emit = defineEmits(['register']);
  40. const props = defineProps({
  41. deviceId: { type: String },
  42. deviceType: { type: String },
  43. });
  44. const formSchemas = ctrlFormSchemas;
  45. const activeID = ref('');
  46. const dataSource = ref<any[]>([]);
  47. const ctrlList = ref<any[]>([]);
  48. const deviceType = ref('');
  49. const editRecord = ref<any>(null);
  50. function selectWarning(id) {
  51. activeID.value = id;
  52. getTableData(id);
  53. }
  54. async function getControlDevicePointList() {
  55. const param = {
  56. pageNo: 1,
  57. pageSize: 1000,
  58. devicetype: props.deviceType,
  59. valuetype: 10,
  60. };
  61. const res = await getCtrlDevicePointList(param);
  62. ctrlList.value = res.records || [];
  63. }
  64. const [register, { openModal, closeModal }] = useModal();
  65. function handleOpen(flag?, record?) {
  66. console.log(record, 'record');
  67. deviceType.value = props.deviceType;
  68. editRecord.value = flag == 'update' ? record : null;
  69. if (record) {
  70. if (flag == 'update') {
  71. openModal(true, {
  72. isUpdate: true,
  73. record,
  74. });
  75. } else {
  76. openModal(true, {
  77. isUpdate: false,
  78. record,
  79. });
  80. }
  81. } else {
  82. openModal(true, {
  83. isUpdate: false,
  84. record,
  85. });
  86. }
  87. }
  88. async function onSubmit(flag, values) {
  89. const currentItem = ctrlList.value.find((item) => item.id == activeID.value);
  90. if (currentItem) {
  91. values.monitorCode = currentItem.valuecode;
  92. values.monitorId = currentItem.id;
  93. values.monitorName = currentItem.valuename;
  94. }
  95. if (flag == 'update') {
  96. await editCtrlDevicePoint({ id: editRecord.value?.id, ...editRecord.value, ...values });
  97. } else {
  98. await addCtrlDevicePoint({ ...values });
  99. }
  100. editRecord.value = null;
  101. closeModal();
  102. await getTableData(activeID.value);
  103. }
  104. async function handleDelete(record) {
  105. await deleteDevicePonit({ id: record.id });
  106. getTableData(activeID.value);
  107. }
  108. async function getTableData(id?: string) {
  109. const param = {
  110. pageNo: 1,
  111. pageSize: 1000,
  112. monitorId: id,
  113. deviceId: props.deviceId,
  114. };
  115. const res = await getCtrlDevicePointPage(param);
  116. dataSource.value = res.records || [];
  117. }
  118. onMounted(async () => {
  119. await getControlDevicePointList();
  120. if (ctrlList.value.length > 0) {
  121. activeID.value = ctrlList.value[0].id;
  122. }
  123. await getTableData(activeID.value);
  124. });
  125. </script>
  126. <style lang="less" scoped>
  127. @ventSpace: zxm;
  128. .warning-device-box {
  129. width: 100%;
  130. height: 600px;
  131. overflow-y: auto;
  132. display: flex;
  133. .warning-box {
  134. width: 200px;
  135. height: 100%;
  136. overflow-y: auto;
  137. background: #ffffff11;
  138. padding: 5px;
  139. border-radius: 5px;
  140. .link-item {
  141. position: relative;
  142. cursor: pointer;
  143. line-height: 30px;
  144. padding-left: 30px;
  145. color: #fff;
  146. span:hover {
  147. color: #89ffff;
  148. }
  149. &::after {
  150. content: '';
  151. position: absolute;
  152. display: block;
  153. width: 8px;
  154. height: 8px;
  155. top: 12px;
  156. left: 10px;
  157. transform: rotateZ(45deg) skew(10deg, 10deg);
  158. background: #45d3fd;
  159. }
  160. }
  161. .active-device-title {
  162. color: aqua;
  163. }
  164. }
  165. .device-box {
  166. flex: 1;
  167. margin-left: 10px;
  168. }
  169. .action-link {
  170. color: #00e7ff;
  171. }
  172. }
  173. </style>