PortalBizSystemManagerEdit.vue 14.7 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426
<template>
  <div class="fullheight">
    <ht-sidebar-dialog
      width="48%"
      title="外部系统管理"
      class="sp-manager__dialog"
      :visible="dialogVisible"
      v-if="dialogVisible"
      :before-close="beforeCloseDialog"
    >
      <el-form
        v-form
        v-model="PortalBizSystem"
        data-vv-scope="PortalBizSystemForm"
      >
        <ht-form-item label="系统编码" label-width="140px">
          <ht-input
            v-model="PortalBizSystem.sysCode"
            :maxlength="50"
            show-word-limit
            validate="required: true|regex:^[a-zA-Z][a-zA-Z0-9_]*$,只能输入字母、数字、下划线,且以字母开头"
            placeholder="请输入系统编码,系统编码不可重复"
            :width="450"
            :disabled="disabled"
          />
        </ht-form-item>
        <ht-form-item label="系统名称" label-width="140px">
          <ht-input
            v-model="PortalBizSystem.sysName"
            :validate="{required: true}"
            placeholder="请输入系统名称..."
            :width="450"
            :maxlength="50"
            show-word-limit
          />
        </ht-form-item>
        <ht-form-item label="系统密匙" label-width="140px" class="item-width">
          <ht-input
            v-model="PortalBizSystem.secretKey"
            validate="required: true|regex:^[a-zA-Z][a-zA-Z0-9_]*$,只能输入字母、数字、下划线,且以字母开头"
            placeholder="请输入系统密匙..."
            :width="450"
            :maxlength="100"
            show-word-limit
          />
        </ht-form-item>
        <!-- <ht-form-item label="管理员名称"> -->
        <!-- <ht-input v-model="PortalBizSystem.managerName" validate="required" /> -->
        <!-- </ht-form-item> -->

        <ht-form-item label="管理员名称" label-width="140px">
          <ht-user-selector-input
            v-model="PortalBizSystem.users"
            :config="{id: 'userIds', fullname: 'userNames'}"
            :validate="{required: true}"
            :single="false"
            append-to-body
            select-label="id"
            @valueChange="input"
          />
          <!--          <ht-select-->
          <!--              placeholder="请选择管理员"-->
          <!--              v-model="PortalBizSystem.managerId"-->
          <!--              class="m-r"-->
          <!--              :options="options"-->
          <!--              :validate="{required:true}"-->
          <!--          />-->
        </ht-form-item>

        <ht-form-item label="系统根路径" label-width="140px">
          <ht-input
            v-model="PortalBizSystem.rootAddress"
            validate="required: true"
            placeholder="如  http://127.0.0.1"
            :width="450"
            :maxlength="200"
            show-word-limit
          />
        </ht-form-item>
        <ht-form-item label="系统首页地址" label-width="140px">
          <ht-input
            v-model="PortalBizSystem.homeAddress"
            :validate="{required: true}"
            :maxlength="200"
            show-word-limit
            placeholder="如  http://127.0.0.1/index"
            :width="450"
          />
        </ht-form-item>
        <ht-form-item label="流程消息队列" label-width="140px">
          <ht-input
            v-model="PortalBizSystem.bpmMsgQueue"
            validate="regex:^[a-zA-Z][a-zA-Z0-9_]*$,只能输入字母、数字、下划线,且以字母开头"
            :maxlength="50"
            show-word-limit
            placeholder="如  flowQueue"
            :width="450"
          />
        </ht-form-item>
        <ht-form-item label="系统描述" label-width="140px">
          <ht-input
            v-model="PortalBizSystem.description"
            :validate="{required: true}"
            type="textarea"
            placeholder="请输入系统描述..."
            :width="450"
            :maxlength="200"
            show-word-limit
          />
        </ht-form-item>
        <ht-form-item label="接口授权账号" label-width="140px">
          <ht-user-selector-input
            v-model="PortalBizSystem.robotId"
            :config="{id: 'robotId', fullname: 'robotName'}"
            :validate="{required: true}"
            :single="true"
            append-to-body
          />
          <!--          <ht-select-->
          <!--              v-model="PortalBizSystem.robotId"-->
          <!--              class="m-r"-->
          <!--              :options="robotId"-->
          <!--              :validate="{required:true}"-->
          <!--          />-->
        </ht-form-item>
        <ht-form-item label="是否启用" label-width="140px">
          <el-switch
            v-model="PortalBizSystem.enabled"
            active-text="启用"
            inactive-text="关闭"
          >
          </el-switch>
          <!-- <ht-input v-model="PortalBizSystem.enabled" validate="required" /> -->
        </ht-form-item>
        <el-divider>配置认证接口</el-divider>
        <ht-form-item label="入参方式" label-width="140px">
          <ht-radio
            v-model="PortalBizSystem.tokenType"
            class="ht"
            :options="[
              {key: 0, value: '头部参数'},
              {key: 1, value: 'URL参数'}
            ]"
          />
        </ht-form-item>
        <ht-form-item label="票据入参KEY" label-width="140px">
          <ht-input
            v-model="PortalBizSystem.tokenKey"
            validate="regex:^[a-zA-Z][a-zA-Z0-9_]*$,只能输入字母、数字、下划线,且以字母开头"
            :maxlength="50"
            show-word-limit
            placeholder="如  token"
            :width="450"
          />
        </ht-form-item>
        <ht-form-item label="票据入参VALUE" label-width="140px">
          <el-button type="primary" plain @click="showBizAuthDialog"
            >配置认证接口
          </el-button>
          <el-button @click="clearBizAuthDialog" size="small" type="text"
            >清除</el-button
          >
        </ht-form-item>
        <ht-form-item label="票据过期时间" label-width="140px">
          <ht-input
            v-model="PortalBizSystem.tokenExpire"
            validate="regex:^[0-9]*$,只能输入数字"
            :maxlength="6"
            show-word-limit
          />
          <span> 秒</span>
        </ht-form-item>
      </el-form>
      <div slot="footer" style="text-align: right">
        <el-button @click="beforeCloseDialog"
          >{{ $t('eip.common.cancel') }}
        </el-button>
        <el-button type="primary" @click="submitData"
          >{{ $t('eip.common.save') }}
        </el-button>
      </div>
    </ht-sidebar-dialog>
    <!-- 配置认证接口对话框 -->
    <biz-auth-dialog
      v-if="dialogVisible"
      @onConfirm="authDialogConfirm"
      ref="bizAuthDialog"
    />
  </div>
</template>
<script>
import utils from '@/hotent-ui-util.js'
const bizAuthDialog = () => import('@/components/dialog/BizAuthDialog.vue')
export default {
  components: {
    bizAuthDialog
  },
  data() {
    return {
      dialogVisible: false,
      apiInfo: {},
      PortalBizSystem: {users: '', enabled: true},
      saveMethod: 'POST',
      options: [],
      robotId: '',
      managerName: '',
      users: '',
      userIds: '',
      robotName: '',
      deletedUserId: [],
      originUsers: '',
      disabled: false
    }
  },
  mounted() {},
  created() {
    // this.loadMangerName()
    this.$validator = this.$root.$validator
  },
  methods: {
    //显示 配置认证接口对话框
    showBizAuthDialog() {
      this.$refs.bizAuthDialog.showDialog(this.apiInfo)
    },
    //配置认证接口对话框 确认保存
    authDialogConfirm(apiInfo) {
      this.apiInfo = apiInfo
    },
    input(value) {},
    showDialog(id) {
      this.PortalBizSystem.users = ''
      this.userNames = ''
      this.userIds = ''
      if (id) {
        this.saveMethod = 'PUT'
        this.$http
          .get('${portal}/portalBizSystem/v1/searchById?id=' + id)
          .then(resp => {
            this.robotId = resp.data.value.robotId
            this.PortalBizSystem = {...this.PortalBizSystem, ...resp.data.value}
            this.disabled = this.PortalBizSystem.sysCode ? true : false
            for (let item of this.PortalBizSystem.managerList) {
              if (this.userIds && this.userNames) {
                this.userIds = this.userIds + ',' + item.managerId
                this.userNames = this.userNames + ',' + item.managerName
                this.PortalBizSystem.users =
                  this.PortalBizSystem.users + ',' + item.managerName
              } else {
                this.userIds = item.managerId
                this.userNames = item.managerName
                this.PortalBizSystem.users = item.managerName
              }
            }
            this.PortalBizSystem.robotId = this.PortalBizSystem.robotName
            //认证接口
            this.apiInfo = {}
            if (this.PortalBizSystem.tokenApiInfo) {
              this.apiInfo = JSON.parse(this.PortalBizSystem.tokenApiInfo)
            }
            this.dialogVisible = true
            this.originUsers = this.userIds
            if (this.PortalBizSystem) {
              this.PortalBizSystem.enabled =
                this.PortalBizSystem.enabled == '0' ? true : false
            }
          })
      } else {
        this.apiInfo = {}
        this.saveMethod = 'POST'
        this.dialogVisible = true
        this.disabled = false
      }
    },
    clearBizAuthDialog() {
      this.apiInfo = {}
    },
    loadData(param) {
      this.$http.post('${portal}/portalBizSystem/v1/query', param).then(
        resp => {
          let response = resp.data
          this.data = response.rows
          this.pageResult = {
            page: response.page,
            pageSize: response.pageSize,
            total: response.total
          }
        },
        error => {
          reject(error)
        }
      )
    },
    beforeCloseDialog() {
      this.PortalBizSystem = {}
      this.dialogVisible = false
    },
    afterSaveData() {
      setTimeout(() => {
        // ("---")
        this.$emit('loadData', {})
        this.beforeCloseDialog()
      }, 500)
    },
    submitData() {
      if (this.saveMethod == 'POST') {
        utils
          .validateForm(this, 'PortalBizSystemForm')
          .then(valid => {
            let userList = []
            let manageNames = this.userNames.split(',')
            let manageIds = this.userIds.split(',')
            for (let i = 0; i < manageNames.length; i++) {
              let user = {managerId: manageIds[i], managerName: manageNames[i]}
              userList.push(user)
            }
            this.PortalBizSystem.managerList = userList
            this.PortalBizSystem.robotName = this.robotName
            this.PortalBizSystem.robotId = this.robotId
            this.PortalBizSystem.tokenApiInfo = this.apiInfo
              ? JSON.stringify(this.apiInfo)
              : ''
            if (valid) {
              var httpReg = /http(s)?:\/\/([\w-]+\.)+[\w-]+(\/[\w- .\/?%&=]*)?/
              var queueReg = /^[a-zA-Z][a-zA-Z0-9_]*$/
              if (!httpReg.test(this.PortalBizSystem.rootAddress)) {
                this.$message.error('系统根路径输入不合法')
                return
              }
              if (!httpReg.test(this.PortalBizSystem.homeAddress)) {
                this.$message.error('系统首页地址输入不合法')
                return
              }
              // if (!queueReg.test(this.PortalBizSystem.bpmMsgQueue)) {
              //   this.$message.error(
              //     '流程消息队列输入不合法,只能输入字母、数字、下划线,且以字母开头'
              //   )
              //   return
              // }

              let PortalBizSystemDeep = _.cloneDeep(this.PortalBizSystem)
              delete PortalBizSystemDeep.users
              this.$http
                .post('${portal}/portalBizSystem/v1/save', PortalBizSystemDeep)
                .then(res => {
                  if (res.data.state) {
                    this.$message.success(res.data.message)
                    setTimeout(() => {
                      this.afterSaveData()
                    }, 1000)
                  }
                })
            }
          })
          .catch(items => {
            this.$message.error(`还有内容未填写,无法提交表单。`)
          })
      } else {
        let _this = this
        utils
          .validateForm(this, 'PortalBizSystemForm')
          .then(valid => {
            let userList = []
            let manageNames = this.userNames.split(',')
            let manageIds = this.userIds.split(',')
            for (let i = 0; i < manageNames.length; i++) {
              let user = {managerId: manageIds[i], managerName: manageNames[i]}
              userList.push(user)
            }
            this.PortalBizSystem.managerList = userList
            this.PortalBizSystem.robotId = this.robotId
            this.PortalBizSystem.robotName = this.robotName
            this.PortalBizSystem.tokenApiInfo = this.apiInfo
              ? JSON.stringify(this.apiInfo)
              : ''
            if (valid) {
              var reg = /http(s)?:\/\/([\w-]+\.)+[\w-]+(\/[\w- .\/?%&=]*)?/
              var queueReg = /^[a-zA-Z][a-zA-Z0-9_]*$/
              if (!reg.test(this.PortalBizSystem.rootAddress)) {
                this.$message.error('系统根路径输入不合法')
                return
              }
              if (!reg.test(this.PortalBizSystem.homeAddress)) {
                this.$message.error('系统首页地址输入不合法')
                return
              }
              // if (!queueReg.test(this.PortalBizSystem.bpmMsgQueue)) {
              //   this.$message.error(
              //     '流程消息队列输入不合法,只能输入字母、数字、下划线,且以字母开头'
              //   )
              //   return
              // }
              let PortalBizSystemDeep = _.cloneDeep(this.PortalBizSystem)
              delete PortalBizSystemDeep.users
              _this.$http
                .post(
                  '${portal}/portalBizSystem/v1/update',
                  PortalBizSystemDeep
                )
                .then(res => {
                  this.$message.success(res.data.message)
                  setTimeout(() => {
                    this.afterSaveData()
                  }, 1000)
                })
            }
          })
          .catch(items => {
            this.$message.error(`还有内容未填写,无法提交表单。`)
          })
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.sp-manager__dialog /deep/ > .el-dialog > .el-dialog__body {
  height: calc(100% - 190px);
}
/deep/.item-width .ht-form-inputs__inline {
  width: 240px;
}
.inputs.ht-form-inputs__inline {
  width: 300px;
}
</style>