1
lzhe
2024-06-05 dcf9c9e0410fe1186239e3f8d6f7bdc789c08010
src/views/notification/editconfiguration.vue
@@ -4,7 +4,7 @@
         <span>通知类型 {{addBusinessForm.name}}</span>
         <span>
            服务商
            <el-select style="width: 80%"  v-model="serviceproviders" disabled>
            <el-select style="width: 80%"  v-model="serviceproviders" :disabled="mode != 'add'">
               <el-option v-for="item in addBusinessForm.providerInfos" :key="item.id" :label="item.name" :value="item.id"/>
            </el-select>
         </span>
@@ -12,7 +12,7 @@
      <el-form :model="addBusinessForm" :rules="addBusinessRules" :disabled="mode=='show'" ref="dialogForm" label-width="140px" label-position="center">
         <el-row>
            <el-col :span="24">
               <el-form-item label="请输入配置名称" prop="notifyTemplateName">
               <el-form-item label="请输入配置名称" prop="pname">
                  <el-input v-model="addBusinessForm.pname" placeholder="模版名称" clearable></el-input>
               </el-form-item>
            </el-col>
@@ -57,7 +57,7 @@
            serviceproviders: "",
            mode: "add",
            titleMap: {
               add: '新增',
               add: '新增配置',
               edit: '编辑配置',
               show: '查看'
            },
@@ -73,7 +73,7 @@
            },
            //验证规则
            addBusinessRules: {
               notifyTemplateName:[{required: true, message: '请输入模版名称'}]
               pname:[{required: true, message: '请输入模版名称'}]
            },
         }
      },
@@ -91,29 +91,57 @@
            this.addBusinessForm.configuration[index].value.splice(index1,1);
         },
         //显示
         open(mode='add'){
         open(mode='add',obj){
            if(mode == 'add') {
               this.addBusinessForm = obj;
               this.$nextTick(()=> {
                  this.serviceproviders = this.addBusinessForm.providerInfos[0].id;
               })
               var setArr = [];
               obj.properties.forEach(item=> {
                  setArr.push({pname:item.name,value: "",name: item.name})
               })
               this.addBusinessForm.configuration = setArr;
            }
            this.mode = mode;
            this.visible = true;
            return this
         },
         //表单提交方法
         businessSubmit(){
            var obj = Object.assign({},this.addBusinessForm);
            obj.notifyType = obj.notifyType;
            obj.id = obj.notifyTemplateId;
            obj.business = obj.businessKey;
            obj.name = obj.notifyTemplateName;
            obj.provider = obj.providerType;
            obj.type = obj.notifyType;
            var template = JSON.parse(obj.template);
            for(var key in template) {
               template[key] = obj[key];
            var configuration = {};
            this.addBusinessForm.configuration.forEach(item=> {
               configuration[item.name] = item.value;
            })
            var obj = {
               configuration: configuration,
            }
            obj.template = JSON.stringify(template);
            if(this.mode == 'edit') {
               obj.id = this.addBusinessForm.configEntity.id;
               obj.name = this.addBusinessForm.configEntity.name;
               obj.provider = this.addBusinessForm.configEntity.provider;
               obj.type = this.addBusinessForm.configEntity.type;
               if(this.addBusinessForm.configEntity.type == "email") {  //邮件
                  var newArr = [];
                  configuration.properties.forEach(item=> {
                      var formattedObject = {};
                      item.forEach(item => {
                        formattedObject[item.name] = item.value;
                      });
                      newArr.push(formattedObject);
                  })
                  configuration.properties = newArr;
               }
            }
            if(this.mode == 'add') {  //新增
               obj.name = this.addBusinessForm.pname;
               obj.provider = this.serviceproviders;
               obj.type = this.addBusinessForm.id;
            }
            this.$refs.dialogForm.validate(async (valid) => {
               if (valid) {
                  this.isSaveing = true;
                  this.$HTTP.put("/api/blade-notify/business-notify/modify",obj).then(res=> {
                  this.$HTTP.put("/api/blade-notify/notifier/config",obj).then(res=> {
                     this.isSaveing = false;
                     if(res.code == 200) {
                        this.$emit('success', this.addBusinessForm, this.mode);
@@ -165,19 +193,11 @@
                  }
               })
            })
            console.log(data.configuration,data)
            // for(var key in res.data.configEntity.configuration) {
            //    res.data.configEntity.configuration['name'] = key;
            //    res.data.configEntity.configuration['value'] = res.data.configEntity.configuration[key];
            //    res.data.configEntity.configuration['type'] = res.data.id;
            // }
            //可以和上面一样单个注入,也可以像下面一样直接合并进去
            Object.assign(this.addBusinessForm,data);
            // this.$nextTick(()=> {
            //    this.serviceproviders = this.addBusinessForm.providerInfos[0].id;
            // })
            // console.log(this.addBusinessForm)
            this.$nextTick(()=> {
               this.serviceproviders = this.addBusinessForm.providerInfos[0].id;
            })
         }
      },
      components: {