dialog.addThreshold.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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. const params = this.$route.params;
  63. return {
  64. missionId: params ? params.missionId : null,
  65. isShow: false,
  66. title: '',
  67. formData: this.reset(),
  68. isEdit: false,
  69. formDataRules: {
  70. thresholdName: [{required: true, message: "请输入阈值名称", trigger: 'blur'}],
  71. timeRange: [{required: true, message: "请选择有效时段", trigger: 'blur'}],
  72. nosignal: [
  73. {required: true, message: '请输入信号丢失,格式为:@value==255', trigger: 'blur'},
  74. {validator: this.validatePort, trigger: 'blur'}
  75. ],
  76. covered: [
  77. {required: true, message: '请输入遮挡,格式为:@value>=255', trigger: 'blur'},
  78. {validator: this.validatePort, trigger: 'blur'}
  79. ],
  80. },
  81. };
  82. },
  83. props: {},
  84. watch: {},
  85. created() {
  86. },
  87. mounted() {
  88. },
  89. computed: {
  90. ...mapState(["loginUser", "org"]),
  91. },
  92. methods: {
  93. ...mapMutations([]),
  94. reset() {
  95. return {
  96. thresholdCode: null,
  97. thresholdName: null,
  98. timeRange: ['00:00:00', '23:59:59'],
  99. nosignal: "@value==255",
  100. covered: "@value>=255",
  101. };
  102. },
  103. async show(formData) {
  104. this.title = '新增阈值';
  105. this.isEdit=false;
  106. if (formData.thresholdCode){
  107. this.formData = formData;
  108. this.formData.timeRange=[formData.beginTime,formData.endTime];
  109. this.title = '编辑阈值';
  110. this.isEdit=true;
  111. }
  112. this.isShow = true;
  113. },
  114. // 事件
  115. onHide() {
  116. this.isShow = false;
  117. this.formData = this.reset();
  118. },
  119. async onSubmit() {
  120. this.$refs["form"].validate(async (valid) => {
  121. if (valid) {
  122. if (!this.formData.thresholdCode) {
  123. await addThreshold(this.formData).then(r => {
  124. this.$modal.msgSuccess("新增成功");
  125. })
  126. } else {
  127. await editThreshold(this.formData).then(r => {
  128. this.$modal.msgSuccess("修改成功");
  129. })
  130. }
  131. this.$emit("success");
  132. this.isShow = false;
  133. }
  134. });
  135. },
  136. validatePort(rule, value, callback) {
  137. if (!value) {
  138. return callback(new Error('请输入'));
  139. }
  140. const ipRegex = /^@value[<>=!]{1,1}[=]{0,1}\d+$/;
  141. if (!ipRegex.test(value)) {
  142. callback(new Error('格式错误,格式为:@value>=255'));
  143. } else {
  144. callback();
  145. }
  146. },
  147. },
  148. };
  149. </script>
  150. <style lang="scss" scoped>
  151. .el-form-item{
  152. justify-content:center;
  153. align-items:center;
  154. }
  155. </style>