index3.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. <template>
  2. <div class="warning-device-box">
  3. <div class="warning-box">
  4. <div v-for="item in warningList" class="link-item" :class="{ 'active-device-title': item.id == activeID }" :key="item.id">
  5. <span class="" @click="selectWarning(item.id)">{{ item.alarmName }}</span>
  6. </div>
  7. </div>
  8. <div class="device-box">
  9. <a-button class="vent-margin-b-5" type="primary" @click="handleOpen"> 新增 </a-button>
  10. <a-table v-if="show" :columns="MonitorColumns" :data-source="dataSource" bordered :scroll="{ y: 500 }" :pagination="false">
  11. <template #bodyCell="{ column, record }">
  12. <template v-if="column.dataIndex === 'operation'">
  13. <a class="action-link" @click="handleOpen('update', record)">编辑</a>
  14. <a class="action-link vent-margin-l-10" @click="handleDelete(record)">删除</a>
  15. </template>
  16. <template v-if="column.dataIndex === 'operation1'">
  17. <a class="action-link" @click="handleOpen('add', record)">新增</a>
  18. </template>
  19. </template>
  20. </a-table>
  21. </div>
  22. </div>
  23. <BaseModal @register="register" @add="onSubmit" @update="onSubmit" :form-schemas="formSchemas" />
  24. </template>
  25. <script lang="ts" setup>
  26. import { ref, onMounted } from 'vue';
  27. import { rowOrColSpanMap, MonitorColumns, monitorWarningFormSchemas } from './warning.data';
  28. import { warningLogList, workFaceWarningList, workFaceWarningAdd, workFaceWarningEdit, workFaceWarningDelete } from './warning.api';
  29. import BaseModal from './BaseModal.vue';
  30. import { useModal } from '/@/components/Modal';
  31. import { message } from 'ant-design-vue';
  32. const emit = defineEmits(['register']);
  33. const props = defineProps({
  34. deviceId: { type: String },
  35. });
  36. const show = ref(false);
  37. const formSchemas = monitorWarningFormSchemas({ id: props.deviceId });
  38. const activeID = ref('');
  39. const warningList = ref<{ id: string; alarmName: string }[]>([]);
  40. const dataSource = ref<any[]>([]);
  41. function selectWarning(id) {
  42. activeID.value = id;
  43. }
  44. async function getWarningList() {
  45. const result = await warningLogList({ sysId: props.deviceId, pageSize: 100000 }); //id: props.deviceId
  46. warningList.value = result.records;
  47. activeID.value = warningList.value[0]['id'];
  48. }
  49. async function getDataSource() {
  50. show.value = false;
  51. rowOrColSpanMap.clear();
  52. const result = await workFaceWarningList({ sysId: props.deviceId, monitorType: 2, alarmId: activeID.value, pageSize: 100000 });
  53. let flag = 0;
  54. let groupNum = 0;
  55. let resultDataSource: any[] = [];
  56. const value1 = [
  57. {
  58. code: 'key',
  59. rowSpan: 0,
  60. colSpan: 1,
  61. },
  62. {
  63. code: 'alarmName',
  64. rowSpan: 0,
  65. colSpan: 1,
  66. },
  67. {
  68. code: 'operation1',
  69. rowSpan: 0,
  70. colSpan: 1,
  71. },
  72. ];
  73. // 根据relId 排序
  74. for (let i = 0; i < result.records.length; i++) {
  75. const item = result.records[i];
  76. if (!item.relId) {
  77. groupNum++;
  78. resultDataSource.push(item);
  79. let itemChildArr: any[] = [];
  80. for (let j = 0; j < result.records.length; j++) {
  81. const itemChild = result.records[j];
  82. if (itemChild.relId == item.id) {
  83. resultDataSource.push(itemChild);
  84. itemChildArr.push(itemChild);
  85. }
  86. }
  87. const value0 = [
  88. {
  89. code: 'key',
  90. rowSpan: itemChildArr.length + 1,
  91. colSpan: 1,
  92. },
  93. {
  94. code: 'alarmName',
  95. rowSpan: itemChildArr.length + 1,
  96. colSpan: 1,
  97. },
  98. {
  99. code: 'operation1',
  100. rowSpan: itemChildArr.length + 1,
  101. colSpan: 1,
  102. },
  103. ];
  104. rowOrColSpanMap.set(item['id'], value0);
  105. item['key'] = `${groupNum}`;
  106. for (let m = 0; m < itemChildArr.length; m++) {
  107. rowOrColSpanMap.set(itemChildArr[m]['id'], value1);
  108. }
  109. }
  110. }
  111. show.value = true;
  112. dataSource.value = resultDataSource;
  113. }
  114. async function handleDelete(record) {
  115. await workFaceWarningDelete({ id: record.id });
  116. getDataSource();
  117. }
  118. const [register, { openModal, closeModal }] = useModal();
  119. function handleOpen(flag?, record?) {
  120. if (record) {
  121. if (flag == 'update') {
  122. openModal(true, {
  123. isUpdate: true,
  124. record,
  125. });
  126. } else {
  127. if (!activeID.value) {
  128. message.warning('请先选择预警条目!');
  129. return;
  130. }
  131. // 新增并关系数据
  132. openModal(true, {
  133. isUpdate: false,
  134. record,
  135. });
  136. }
  137. } else {
  138. if (!activeID.value) {
  139. message.warning('请先选择预警条目!');
  140. return;
  141. }
  142. openModal(true, {
  143. isUpdate: false,
  144. });
  145. }
  146. }
  147. async function onSubmit(flag, values) {
  148. if (activeID.value) {
  149. // 提交数据弹窗
  150. if (flag == 'update') {
  151. await workFaceWarningEdit({ ...values });
  152. } else {
  153. await workFaceWarningAdd({ ...values, monitorType: 2, sysId: props.deviceId, alarmId: activeID.value });
  154. }
  155. getDataSource();
  156. }
  157. closeModal();
  158. }
  159. onMounted(async () => {
  160. await getWarningList();
  161. await getDataSource();
  162. });
  163. </script>
  164. <style lang="less" scoped>
  165. @ventSpace: zxm;
  166. .warning-device-box {
  167. width: 100%;
  168. height: 600px;
  169. overflow-y: auto;
  170. display: flex;
  171. .warning-box {
  172. width: 200px;
  173. height: 100%;
  174. overflow-y: auto;
  175. background: #ffffff11;
  176. padding: 5px;
  177. border-radius: 5px;
  178. .link-item {
  179. position: relative;
  180. cursor: pointer;
  181. line-height: 30px;
  182. padding-left: 30px;
  183. color: #fff;
  184. span:hover {
  185. color: #89ffff;
  186. }
  187. &::after {
  188. content: '';
  189. position: absolute;
  190. display: block;
  191. width: 8px;
  192. height: 8px;
  193. top: 12px;
  194. left: 10px;
  195. transform: rotateZ(45deg) skew(10deg, 10deg);
  196. background: #45d3fd;
  197. }
  198. }
  199. .active-device-title {
  200. color: aqua;
  201. }
  202. }
  203. .device-box {
  204. flex: 1;
  205. margin-left: 10px;
  206. }
  207. .action-link {
  208. color: #00e7ff;
  209. }
  210. }
  211. </style>