systemManage.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <template>
  2. <el-card class="box-card">
  3. <template #header>
  4. <div class="card-header">
  5. <span>报警配置</span>
  6. </div>
  7. </template>
  8. <el-tabs type="border-card" v-model="activeTab">
  9. <el-tab-pane
  10. v-for="(item, index) in alarmConfigArray"
  11. :key="index"
  12. :name="item.id"
  13. >
  14. <template #label>
  15. <div class="alartPaneLabel">
  16. <span>{{ item.alarmLevel }}级报警</span>
  17. <div class="alartBadge" :class="getAlartStatus(item)"></div>
  18. </div>
  19. </template>
  20. <el-form label-width="120px">
  21. <el-form-item label="报警弹窗:">
  22. <el-switch
  23. v-model="item.isAlart"
  24. active-text="弹出"
  25. inactive-text="不弹出"
  26. />
  27. </el-form-item>
  28. <el-form-item label="播放声音:">
  29. <el-switch
  30. v-model="item.isAlarmSound"
  31. active-text="播放"
  32. inactive-text="不播放"
  33. />
  34. </el-form-item>
  35. <el-form-item label="必须确认:">
  36. <el-switch
  37. v-model="item.isContinuousAlarm"
  38. active-text="是"
  39. inactive-text="否"
  40. />
  41. </el-form-item>
  42. </el-form>
  43. </el-tab-pane>
  44. </el-tabs>
  45. <div class="btnBox">
  46. <el-button type="primary" @click="save">保存规则</el-button>
  47. </div>
  48. </el-card>
  49. </template>
  50. <script>
  51. import { getAlartConfig, saveAlartConfig } from "@api/api.js";
  52. export default {
  53. data() {
  54. return {
  55. activeTab: "",
  56. alarmConfigArray: [],
  57. };
  58. },
  59. created() {
  60. this.getConfigArray();
  61. },
  62. methods: {
  63. getConfigArray() {
  64. this.alarmConfigArray = [];
  65. getAlartConfig().then((res) => {
  66. res.data.forEach((ele) => {
  67. for (let key in ele) {
  68. if (
  69. this.BASE.getType(ele[key]) === "number" &&
  70. key !== "alarmLevel"
  71. ) {
  72. ele[key] = !!ele[key];
  73. }
  74. }
  75. });
  76. this.alarmConfigArray = res.data;
  77. this.activeTab = this.activeTab || res?.data?.[0]?.id;
  78. });
  79. },
  80. getAlartStatus(alartItem) {
  81. if (
  82. alartItem.isAlart ||
  83. alartItem.isAlarmSound ||
  84. alartItem.isContinuousAlarm
  85. ) {
  86. return "badgeWork";
  87. } else {
  88. return "badgeNotworK";
  89. }
  90. },
  91. save() {
  92. let configArray = this.BASE.deepCopy(this.alarmConfigArray);
  93. let promiseArray = [];
  94. configArray.forEach((ele) => {
  95. for (let key in ele) {
  96. if (ele[key] == true) {
  97. ele[key] = 1;
  98. } else if (ele[key] == false) {
  99. ele[key] = 0;
  100. }
  101. }
  102. promiseArray.push(saveAlartConfig(ele));
  103. });
  104. Promise.all(promiseArray).then(() => {
  105. this.BASE.showMsg({
  106. type: "success",
  107. msg: "修改成功",
  108. });
  109. this.$store.commit("changeAlarmResetFlg");
  110. this.getConfigArray();
  111. });
  112. },
  113. },
  114. };
  115. </script>
  116. <style lang="scss" scoped>
  117. .alartPaneLabel {
  118. position: relative;
  119. .alartBadge {
  120. position: absolute;
  121. right: -10px;
  122. top: 8px;
  123. width: 8px;
  124. height: 8px;
  125. border-radius: 50%;
  126. overflow: hidden;
  127. }
  128. }
  129. .badgeWork {
  130. background: var(--el-color-success);
  131. }
  132. .badgeNotworK {
  133. background: var(--el-color-error);
  134. }
  135. .btnBox {
  136. margin-top: 12px;
  137. }
  138. </style>