Configuration.vue 12.6 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
<template>
  <el-dialog
    title="配置"
    :visible.sync="isShowDialog"
    :before-close="handleClose"
    append-to-body
    :close-on-click-modal="false"
    top="5vh"
  >
    <el-tabs v-model="activeName" type="card" @tab-click="handleClick">
      <el-tab-pane label="通讯录同步配置" name="addressBook">
        <el-form
          :model="addressForm"
          v-form="{formItemAlign: 'left'}"
          label-width="140px"
          class="address-form"
          data-vv-scope="configurationForm"
        >
          <ht-form-item label="是否同步组织架构">
            <el-radio-group v-model="addressForm.syncFlag">
              <el-radio :label="true">是</el-radio>
              <el-radio :label="false">否</el-radio>
            </el-radio-group>
          </ht-form-item>
          <template v-if="addressForm.syncFlag">
            <ht-form-item label="同步范围">
              <el-select v-model="addressForm.syncScope" placeholder="请选择">
                <el-option
                  v-for="item in syncScopeOptions"
                  :key="item.key"
                  :label="item.label"
                  :value="item.value"
                >
                </el-option>
              </el-select>
            </ht-form-item>
            <ht-form-item
              label="选择部门"
              v-if="addressForm.syncScope === 2"
            >
              <tree-Select
                v-if="addressForm.syncDirection === 0"
                v-model="addressForm.syncOrgId"
                :normalizer="normalizer"
                :multiple="false"
                :options="treeData"
                noOptionsText="正在获取第三方组织树..."
                noChildrenText=" "
                placeholder="请选择部门"
                @select="selectOrg"
                :show-count="true"
                append-to-body
                z-index="9999">
                <div slot="value-label" slot-scope="{ node }">{{ getSyncOrgName(node.label) }}</div>
              </tree-Select>
              <ht-org-selector-input
                v-else
                v-model="addressForm.syncOrg"
                :config="{id: 'addressForm.syncOrgId'}"
                append-to-body
                single
              />

            </ht-form-item>
            <ht-form-item label="同步方式">
              <el-radio-group v-model="addressForm.syncDirection" @change="onSyncDirectionChanged">
                <el-radio :label="0">拉取</el-radio>
                <el-radio :label="1">上传</el-radio>
              </el-radio-group>
            </ht-form-item>
            <ht-form-item label="同步方法">
              <el-radio-group v-model="addressForm.autoSync">
                <el-radio :label="true" v-show="false">自动</el-radio>
                <el-radio :label="false">手动</el-radio>
              </el-radio-group>
            </ht-form-item>
            <template v-if="addressForm.autoSync">
              <ht-form-item label="同步频率">
                <el-select
                  v-model="addressForm.syncFrequency"
                  placeholder="请选择"
                >
                  <el-option
                    v-for="item in syncFrequencyOptions"
                    :key="item.label"
                    :label="item.label"
                    :value="item.value"
                  >
                  </el-option>
                </el-select>
                <ul class="week" v-if="addressForm.syncFrequency === 0">
                  <li
                    class="week-item"
                    :class="{'is-active-item': currentWeek === key}"
                    v-for="(value, key) in weekMap"
                    :key="key"
                    @click="handleClickWeek(key)"
                  >
                    {{ value }}
                  </li>
                </ul>
                <div>
                  <el-date-picker
                    v-if="addressForm.syncFrequency === 1"
                    v-model="selectDate"
                    type="date"
                    placeholder="请选择"
                  >
                  </el-date-picker>
                </div>
              </ht-form-item>
              <ht-form-item
                label="同步起始时间"
                v-if="addressForm.syncFrequency !== 2"
              >
                <el-time-picker
                  v-model="addressForm.syncStartingTime"
                  placeholder="请选择时间"
                >
                </el-time-picker>
              </ht-form-item>
            </template>
          </template>
        </el-form>
      </el-tab-pane>
      <el-tab-pane label="产品应用配置" name="product">
        <product-app-form
          :app-type="appType"
          :productAppForm="addressForm"
          form-scope="configurationForm"
        ></product-app-form>
      </el-tab-pane>
      <el-tab-pane label="第三方应用配置" name="thirdParty" hidden v-if="false">
        <ht-table
          :data="tableData"
          :pageResult="pageResult"
          :selection="false"
          :show-export="false"
          :show-custom-column="false"
          ref="htTable"
          @load="loadData"
        >
          <template v-slot:toolbar>
            <el-button type="primary" @click="handleAddApp" icon="el-icon-plus">添加应用</el-button>
          </template>
          <template>
            <ht-table-column property="agentName" label="应用名称">
              <template v-slot="{row}">
                <el-link
                  type="primary"
                  @click="showDialog(row.id)"
                  title="查看详情"
                  >{{ row.agentName }}</el-link
                >
              </template>
            </ht-table-column>
            <ht-table-column
              prop="alias"
              label="应用别名"
              :show-overflow-tooltip="true"
            >
            </ht-table-column>
            <ht-table-column
              prop="agentId"
              label="AgentId"
              :show-overflow-tooltip="true"
            >
            </ht-table-column>
            <ht-table-column
              prop="agentKey"
              label="应用key"
              :show-overflow-tooltip="true"
              v-if="appType == 'dingtalk'"
            >
            </ht-table-column>
            <ht-table-column
              prop="agentSecret"
              label="应用secret"
              :show-overflow-tooltip="true"
            >
            </ht-table-column>
            <ht-table-column
              prop="menuName"
              label="菜单名称"
              :show-overflow-tooltip="true"
              v-if="appType == 'weChatWork'"
            >
            </ht-table-column>
            <ht-table-column
              prop="menuUrl"
              label="菜单URL"
              :show-overflow-tooltip="true"
            >
            </ht-table-column>
            <ht-table-column
              prop="createTime"
              label="创建时间"
              :show-overflow-tooltip="true"
            >
            </ht-table-column>
          </template>
        </ht-table>
        <el-dialog 
          :visible.sync="appDetailDialog" 
          :title="currentTitle"
          width="30%"
          append-to-body
          :before-close="handleCloseAppDetailDialog"
        >
          <product-app-form
          :app-type="appType"
          ref="productAppForm"
          form-scope="thirdPartyAppForm"
        ></product-app-form>
        <span slot="footer" class="dialog-footer">
          <el-button @click="handleCloseAppDetailDialog">取 消</el-button>
          <el-button type="primary" @click="handleSubmit">确 定</el-button>
        </span>
        </el-dialog>
      </el-tab-pane>
    </el-tabs>
    <div slot="footer" class="dialog-footer">
      <el-button @click="handleClose">{{ $t('eip.common.cancel') }}</el-button>
      <el-button type="primary" @click="submitForm">{{ $t('eip.common.save') }}</el-button>
    </div>
  </el-dialog>
</template>

<script>
import req from '@/request.js'
import {SYNC_FREQUENCY_OPTIONS, SYNC_SCOPE_OPTIONS, WEEK_MAP} from './const'
import ProductAppForm from './ProductAppForm.vue'
import '@riophae/vue-treeselect/dist/vue-treeselect.css'

const eipOrgSelector = () => import('@/components/selector/EipOrgSelector.vue')
const treeSelect = () => import('@riophae/vue-treeselect')
export default {
  name: 'Configuration',
  components: {
    ProductAppForm,
    eipOrgSelector,
    treeSelect,
  },
  props: {
    isShowDialog: {
      type: Boolean,
      default: false
    },
    appType: String,
    addressForm:{},
    cancelConfig:{},
    treeData: {
      type: Array,
      default: () => ([])
    },
  },
  data() {
    return {
      activeName: 'addressBook',
      selectDate: '',
      syncFrequencyOptions: SYNC_FREQUENCY_OPTIONS,
      syncScopeOptions: SYNC_SCOPE_OPTIONS,
      departmentOptions: [],
      weekMap: WEEK_MAP,
      currentWeek: '',
      pageResult: {
        page: 1,
        pageSize: 10,
        total: 0
      },
      tableData: [],
      appDetailDialog:false,
      currentTitle:'添加应用',
    }
  },

  methods: {
    submitForm() {
      this.$root.$validator.validateAll('configurationForm').then(result=>{
        if(result){
          req.post(this.saveSysExternalUnite(), this.addressForm).then(response => {
            if (response.data && response.data.state) {
              this.$message.success(response.data.message || "操作成功");
              this.afterSaveData()
            } else {
              this.$message.warning(response.data.message || "操作失败");
            }
          })
        } else {
          let arr = this.$validator.errors.items.filter(
              (item) => item.scope == 'configurationForm'
            )
            let errorLength = arr.length
            this.$message({
              showClose: true,
              message: `有${errorLength}个字段未通过校验,请正确填写表单内容。`,
              type: 'warning',
            })
          this.activeName = 'product'
        }
      })
    },
    getSyncOrgName(label){
      if (label && label.lastIndexOf("unknown") > -1) {
      //当treeselect翻译不了值时,获取上次保存的组织名称
        return this.addressForm.syncOrg;
      } else {
        return label;
      }
    },
    onSyncDirectionChanged(){
      this.$set(this.addressForm, 'syncOrgId', null)
      this.$set(this.addressForm, 'syncOrg', null)
    },
    normalizer(node) {
      if (node.children && !node.children.length) {
        delete node.children;
      }
      return {
        id: node.id,
        label: node.name,
        children: node.children,
        isDefaultExpanded: false,
      }
    },
    selectOrg(node){
      this.$set(this.addressForm, 'syncOrgId', node.id)
      this.$set(this.addressForm, 'syncOrg', node.name)
    },
    afterSaveData() {
      this.$emit('update:isShowDialog', false)
    },
    edit(val){
      console.log(val)
    },
    saveSysExternalUnite: function() {
      return window.context.portal + '/portal/sysExternalUnite/v1/save'
    },
    handleClose() {
      this.$emit('update:isShowDialog', false)
      this.cancelConfig()
    },
    handleClick(tab) {},
    handleClickWeek(key) {
      this.currentWeek = key
    },
    handleAddApp() {
      this.currentTitle = '添加应用'
      this.appDetailDialog = true
    },
    handleEdit(row) {
      this.currentTitle = '编辑应用'
    },
    handleDelete(row) {},
    loadData(params,cb){
      cb()
    },
    handleCloseAppDetailDialog(){
      this.appDetailDialog = false
    },
    handleSubmit(){
      this.$root.$validator.validateAll('thirdPartyAppForm').then(result=>{
        if(result){
          const formData =  this.$refs.productAppForm.getFormData()
          console.log(formData)
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.address-form{
  ::v-deep{
    .el-select,.el-date-editor.el-input{
      width: 448px;
    }
  }
}
.week {
  list-style: none;
  display: flex;
  .week-item {
    width: 72px;
    height: 32px;
    line-height: 32px;
    text-align: center;
    color: #666666;
    border: 1px solid #dcdee0;
    border-right: none;
    margin-top: 12px;
    &:hover {
      cursor: pointer;
      color: $--color-primary;
      border: 1px solid $--color-primary;
    }
    &:first-child {
      border-radius: 2px 0px 0px 2px;
    }
    &:last-child {
      border-right: 1px solid #dcdee0;
      border-radius: 0px 2px 2px 0px;
      &:hover {
        border-right-color: $--color-primary;
      }
    }
  }
  .is-active-item {
    color: $--color-primary;
    border: 1px solid $--color-primary;
    &:last-child {
      border-right-color: $--color-primary;
    }
  }
  .hide{
    display: none;
  }
}
</style>