index3.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  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" > </BaseModal>
  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. const emit = defineEmits(['register'])
  32. const props = defineProps({
  33. deviceId: { type: String },
  34. });
  35. const show = ref(false)
  36. const formSchemas = monitorWarningFormSchemas({ id: props.deviceId })
  37. const activeID = ref('')
  38. const warningList = ref<{ id: string, alarmName: string }[]>([])
  39. const dataSource = ref([])
  40. function selectWarning(id) {
  41. activeID.value = id
  42. }
  43. async function getWarningList() {
  44. const result = await warningLogList({ sysId: props.deviceId, pageSize: 100000 }) //id: props.deviceId
  45. warningList.value = result.records
  46. activeID.value = warningList.value[0]['id']
  47. }
  48. async function getDataSource() {
  49. show.value = false
  50. rowOrColSpanMap.clear()
  51. const result = await workFaceWarningList({ sysId: props.deviceId, monitorType: 2, alarmId: activeID.value, pageSize: 100000 })
  52. let flag = 0
  53. let groupNum = 0
  54. //合并数据
  55. const resetRowOrColSpanMap = (i) => {
  56. let j = i - flag
  57. const value0 = [
  58. {
  59. code: 'key',
  60. rowSpan: flag + 1,
  61. colSpan: 1
  62. },
  63. {
  64. code: 'alarmName',
  65. rowSpan: flag + 1,
  66. colSpan: 1
  67. },
  68. {
  69. code: 'operation1',
  70. rowSpan: flag + 1,
  71. colSpan: 1
  72. },
  73. ]
  74. const value1 = [
  75. {
  76. code: 'key',
  77. rowSpan: 0,
  78. colSpan: 1
  79. },
  80. {
  81. code: 'alarmName',
  82. rowSpan: 0,
  83. colSpan: 1
  84. },
  85. {
  86. code: 'operation1',
  87. rowSpan: 0,
  88. colSpan: 1
  89. },
  90. ]
  91. if(i == result.records.length - 1){
  92. rowOrColSpanMap.set(result.records[j]['id'], value0)
  93. j += 1
  94. while (j <= i) {
  95. rowOrColSpanMap.set(result.records[j]['id'], value1)
  96. ++j
  97. }
  98. }else{
  99. rowOrColSpanMap.set(result.records[j - 1]['id'], value0)
  100. while (j < i) {
  101. rowOrColSpanMap.set(result.records[j]['id'], value1)
  102. ++j
  103. }
  104. }
  105. }
  106. for(let i=0; i< result.records.length; i++){
  107. const item = result.records[i]
  108. item['key'] = `${groupNum}`
  109. if(item.relId){
  110. ++flag
  111. if(i == result.records.length - 1){
  112. resetRowOrColSpanMap(i)
  113. }
  114. }else{
  115. groupNum++
  116. if(flag){
  117. resetRowOrColSpanMap(i)
  118. }
  119. flag = 0
  120. }
  121. }
  122. console.log(rowOrColSpanMap)
  123. show.value = true
  124. dataSource.value = result.records
  125. }
  126. async function handleDelete(record) {
  127. await workFaceWarningDelete({id: record.id })
  128. getDataSource()
  129. }
  130. const [register, { openModal, closeModal }] = useModal()
  131. function handleOpen(flag?, record?) {
  132. if (record) {
  133. if(flag == 'update'){
  134. openModal(true, {
  135. isUpdate: true,
  136. record
  137. });
  138. }else {
  139. // 新增并关系数据
  140. openModal(true, {
  141. isUpdate: false,
  142. record
  143. });
  144. }
  145. }else{
  146. openModal(true, {
  147. isUpdate: false,
  148. });
  149. }
  150. }
  151. async function onSubmit(flag, values) {
  152. if(activeID.value){
  153. // 提交数据弹窗
  154. if (flag == 'update') {
  155. await workFaceWarningEdit({ ...values })
  156. } else {
  157. await workFaceWarningAdd({ ...values, monitorType: 2, sysId: props.deviceId, alarmId: activeID.value})
  158. }
  159. getDataSource()
  160. }
  161. closeModal();
  162. }
  163. onMounted(async() => {
  164. await getWarningList()
  165. await getDataSource()
  166. })
  167. </script>
  168. <style lang="less" scoped>
  169. @ventSpace: zxm;
  170. .warning-device-box{
  171. width: 100%;
  172. height: 600px;
  173. overflow-y: auto;
  174. display: flex;
  175. .warning-box{
  176. width: 200px;
  177. height: 100%;
  178. overflow-y: auto;
  179. background: #ffffff11;
  180. padding: 5px;
  181. border-radius: 5px;
  182. .link-item{
  183. position: relative;
  184. cursor: pointer;
  185. line-height: 30px;
  186. padding-left: 30px;
  187. color: #fff;
  188. span:hover{
  189. color: #89ffff;
  190. }
  191. &::after{
  192. content: '';
  193. position: absolute;
  194. display: block;
  195. width: 8px;
  196. height: 8px;
  197. top: 12px;
  198. left: 10px;
  199. transform: rotateZ(45deg) skew(10deg, 10deg);
  200. background: #45d3fd;
  201. }
  202. }
  203. .active-device-title {
  204. color: aqua;
  205. }
  206. }
  207. .device-box{
  208. flex: 1;
  209. margin-left: 10px;
  210. }
  211. .action-link{
  212. color: #00e7ff;
  213. }
  214. }
  215. </style>