dialog.addThreshold.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. <template>
  2. <div class="edu-training-edit">
  3. <DialogCom :title="title" @close="onHide" :visible.sync="isShow" width="460px">
  4. <div class="page-body">
  5. <el-form :model="formData" :rules="formDataRules" size="small" ref="form" label-position="top"
  6. label-width="150px" label-prefix=":">
  7. <el-row>
  8. <el-col :span="19">
  9. <el-form-item prop="thresholdName" label="阈值名称">
  10. <el-input
  11. v-model="formData.thresholdName"
  12. :maxlength="32"
  13. placeholder="请输入阈值名称"
  14. clearable
  15. />
  16. </el-form-item>
  17. </el-col>
  18. <el-col :span="19">
  19. <el-form-item prop="timeRange" label="有效时段">
  20. <el-time-picker style="width:100%" v-model="formData.timeRange" value-format="HH:mm:ss"
  21. is-range start-placeholder="开始时间" end-placeholder="结束时间" @change="startDateChanged">
  22. </el-time-picker>
  23. </el-form-item>
  24. </el-col>
  25. </el-row>
  26. <el-row>
  27. <el-col :span="19">
  28. <el-form-item prop="nosignal" label="信号丢失">
  29. <el-input
  30. v-model="formData.nosignal"
  31. :maxlength="32"
  32. clearable
  33. />
  34. </el-form-item>
  35. </el-col>
  36. <el-col :span="19">
  37. <el-form-item prop="covered" label="遮挡">
  38. <el-input
  39. v-model="formData.covered"
  40. :maxlength="32"
  41. clearable
  42. />
  43. </el-form-item>
  44. </el-col>
  45. </el-row>
  46. </el-form>
  47. </div>
  48. <div slot="footer" class="dialog-footer">
  49. <el-button type="primary" @click="onSubmit">确 定</el-button>
  50. <el-button @click="onHide">取 消</el-button>
  51. </div>
  52. </DialogCom>
  53. </div>
  54. </template>
  55. <script>
  56. import {mapMutations, mapState} from "vuex";
  57. import {addThreshold,editThreshold} from "@/api/iot/diagnoseThreshold";
  58. import dayjs from "dayjs";
  59. export default {
  60. components: {},
  61. data() {
  62. return {
  63. isShow: false,
  64. title: '',
  65. formData: this.reset(),
  66. isEdit: false,
  67. formDataRules: {
  68. thresholdName: [{required: true, message: "请输入阈值名称", trigger: 'blur'}],
  69. timeRange: [{required: true, message: "请选择有效时段", trigger: 'blur'}],
  70. nosignal: [
  71. {required: true, message: '请输入信号丢失,格式为:@value==255', trigger: 'blur'},
  72. {validator: this.validatePort, trigger: 'blur'}
  73. ],
  74. covered: [
  75. {required: true, message: '请输入遮挡,格式为:@value>=255', trigger: 'blur'},
  76. {validator: this.validatePort, trigger: 'blur'}
  77. ],
  78. },
  79. };
  80. },
  81. props: {},
  82. watch: {},
  83. created() {
  84. },
  85. mounted() {
  86. },
  87. computed: {
  88. ...mapState(["loginUser", "org"]),
  89. },
  90. methods: {
  91. ...mapMutations([]),
  92. reset() {
  93. return {
  94. thresholdId: null,
  95. thresholdCode: null,
  96. thresholdName: null,
  97. timeRange: ['00:00:00', '23:59:59'],
  98. nosignal: "@value==255",
  99. covered: "@value>=255",
  100. };
  101. },
  102. async show(param) {
  103. this.title = '新增阈值';
  104. this.isEdit=false;
  105. if (param.thresholdCode){
  106. this.formData = {
  107. thresholdId: param.thresholdId,
  108. thresholdCode: param.thresholdCode,
  109. thresholdName: param.thresholdName,
  110. timeRange: [param.beginTime,param.endTime],
  111. nosignal: param.nosignal,
  112. covered: param.covered,
  113. }
  114. this.title = '编辑阈值';
  115. this.isEdit=true;
  116. }
  117. this.isShow = true;
  118. },
  119. // 事件
  120. onHide() {
  121. this.isShow = false;
  122. this.formData = this.reset();
  123. },
  124. async onSubmit() {
  125. this.$refs["form"].validate(async (valid) => {
  126. if (valid) {
  127. if (!this.formData.thresholdCode) {
  128. await addThreshold(this.formData).then(r => {
  129. this.$modal.msgSuccess("新增成功");
  130. })
  131. } else {
  132. await editThreshold(this.formData).then(r => {
  133. this.$modal.msgSuccess("修改成功");
  134. })
  135. }
  136. this.$emit("success");
  137. this.isShow = false;
  138. }
  139. });
  140. },
  141. validatePort(rule, value, callback) {
  142. if (!value) {
  143. return callback(new Error('请输入'));
  144. }
  145. const ipRegex = /^@value[<>=!]{1,1}[=]{0,1}\d+$/;
  146. if (!ipRegex.test(value)) {
  147. callback(new Error('格式错误,格式为:@value>=255'));
  148. } else {
  149. callback();
  150. }
  151. },
  152. },
  153. };
  154. </script>
  155. <style lang="scss" scoped>
  156. .el-form-item{
  157. justify-content:center;
  158. align-items:center;
  159. }
  160. </style>