SysSignetManager.vue 11.3 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
<template>
  <div class="fullheight">
    <ht-table
      @load="loadData"
      :data="data"
      :pageResult="pageResult"
      :selection="true"
      :show-export="false"
      :show-custom-column="false"
      quick-search-props="name"
      :default-sorter="[{direction: 'DESC', property: 'updateTime'}]"
      ref="htTable"
      @row-click="rowClick"
      @selection-change="handleSelectionChanges"
    >
      <template v-slot:toolbar>
        <!-- <el-button-group> -->
        <el-button
          size="small"
          @click="showDialog()"
          icon="el-icon-plus"
          type="primary"
          >添加</el-button
        >
        <el-button
          icon="el-icon-back"
          @click="handleCommand({command: 'import'})"
          >导入</el-button
        >
        <el-button
          icon="el-icon-right"
          @click="handleCommand({command: 'export'})"
          :disabled="isDisabled"
          >导出</el-button
        >
        <ht-delete-button
          :url="'${portal}/sys/sysSignet/v1/remove?tenantId=' + tenantId"
          :disabled="isDisabled"
          :htTable="$refs.htTable"
          style="margin-left:10;"
          >删除</ht-delete-button
        >
        <!-- </el-button-group> -->
      </template>
      <template>
        <ht-table-column type="index" width="50" align="center" label="序号" />
        <ht-table-column prop="id" label="主键" hidden />
        <ht-table-column
          prop="name"
          width="250"
          label="印章名称"
          :sortable="true"
        />
        <ht-table-column
          prop="alias"
          width="250"
          label="印章别名"
          :sortable="true"
        />
        <ht-table-column label="印章标识符">
          <template v-slot="{row}">
            {{ signStart }}#signet_{{ row.alias }}{{ signEnd }}
          </template>
        </ht-table-column>
        <ht-table-column prop="desc" label="印章说明" />
        <ht-table-column label="操作">
          <template v-slot="{row}">
            <el-button
              type="text"
              @click="handleCommand({row: row, command: 'edit'})"
              >编辑</el-button
            >
          </template>
        </ht-table-column>
      </template>
    </ht-table>

    <ht-sidebar-dialog
      width="32%"
      :title="(model.id ? '编辑' : '添加') + '印章标识'"
      :visible="dialogVisible"
      :append-to-body="true"
      :before-close="handleClose"
    >
      <el-form v-model="model" data-vv-scope="editModelForm">
        <ht-form-item label="印章名称" label-width="120px">
          <ht-input
            v-model="model.name"
            autocomplete="off"
            :validate="{required: true}"
            placeholder="请输入印章名称"
            :maxlength="50"
            :showWordLimit="true"
          ></ht-input>
        </ht-form-item>
        <ht-form-item label="印章别名" label-width="120px">
          <ht-input
            v-model="model.alias"
            autocomplete="off"
            :disabled="model.id ? true : false"
            :validate="{required: true, alpha_dash: true}"
            placeholder="请输入印章别名"
            :maxlength="50"
            :showWordLimit="true"
          ></ht-input>
        </ht-form-item>
        <ht-form-item label="印章说明" label-width="120px">
          <ht-input
            type="textarea"
            v-model="model.desc"
            placeholder="请输入印章说明"
            :maxlength="300"
            :showWordLimit="true"
          />
        </ht-form-item>
        <ht-form-item label="印章图片" label-width="120px" required>
          <HtViewer v-if="signetShow" v-model="model.fileId" />
        </ht-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="handleClose()">{{
          $t('eip.common.cancel')
        }}</el-button>
        <ht-submit-button
          :url="'/sys/sysSignet/v1/save?tenantId=' + tenantId"
          context="portal"
          :model="model"
          :is-submit="isSubmit"
          scope-name="editModelForm"
          @before-save-data="beforeSaveData"
          @after-save-data="afterSaveData"
          >{{ $t('eip.common.save') }}</ht-submit-button
        >
      </div>
    </ht-sidebar-dialog>
    <el-dialog
      title="上传文件"
      :visible="uploadDialogVisible"
      :before-close="beforeClose"
      name="uploadDialog"
      top="30vh"
      width="40%"
      custom-class="upload-dialog"
      append-to-body
    >
      <el-upload
        :action="uploadUrl"
        :on-exceed="onExceed"
        :http-request="handleImport"
        accept=".zip"
        :file-list="fileList"
        :limit="1"
        :auto-upload="false"
        ref="elUpload"
        class="upload-dialog__content"
      >
        <el-button size="small" icon="el-icon-upload">点击上传</el-button>
        <div slot="tip" class="el-upload__tip">只能上传zip文件</div>
      </el-upload>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="uploadSubmit">上传</el-button>
        <el-button type="default" @click="beforeClose">取消</el-button>
      </span>
    </el-dialog>
    <el-dialog
      title="温馨提示"
      :visible="myDialogVisible"
      :before-close="beforeClose2"
      name="myDialogVisible"
      width="30%"
      custom-class="upload-dialog"
      top="30vh"
    >
      <span>部分印章已存在,请确认重复项的导入操作!</span>
      <span slot="footer" class="dialog-footer">
        <el-button type="default" @click="beforeClose2">取消</el-button>
        <el-button type="primary" @click="confirmSubmit('jump')"
          >跳过重复项</el-button
        >
        <el-button type="primary" @click="confirmSubmit('cover')"
          >覆盖更新</el-button
        >
      </span>
    </el-dialog>
  </div>
</template>
<script>
import portalApi from '@/api/portal.js'
import req from '@/request.js'
import HtViewer from '@/components/common/HtViewer'
export default {
  name: 'sysSignetManager',
  components: {
    HtViewer
  },
  props: {
    tenantId: String
  },
  computed: {},
  data() {
    return {
      dialogVisible: false,
      model: {
        name: '',
        groupKey: '',
        type: 1
      },
      data: [],
      pageResult: {
        page: 1,
        pageSize: 20,
        total: 0
      },
      signStart: '{{',
      signEnd: '}}',
      isSubmit: true,
      signetShow: true,
      uploadDialogVisible: false,
      uploadUrl: window.context.portal + '/sys/sysSignet/v1/import',
      fileList: [],
      myDialogVisible: false,
      uploadAddress: '',
      // 禁用
      isDisabled: true,
      selectedList: []
    }
  },
  watch: {
    selectedList: {
      handler(val) {
        this.isDisabled = val.length < 1 ? true : false
      },
      deep: true
    }
  },

  mounted() {
    this.$validator = this.$root.$validator
  },
  methods: {
    handleSelectionChanges(selection) {
      this.selectedList = selection
    },
    rowClick(row, column, event) {
      this.$refs.htTable.$refs.htTable.toggleRowSelection(row)
    },
    handleClose() {
      this.dialogVisible = false
    },
    showDialog(row) {
      this.dialogVisible = true
      let this_ = this
      req
        .get('${portal}/sys/sysSignet/v1/getJson?id=' + (row ? row.id : ''))
        .then(response => {
          if (response.data) {
            this_.model = response.data
            this_.signetShow = false
            setTimeout(function() {
              this_.signetShow = true
            }, 100)
          }
        })
    },
    loadData(param, cb) {
      this.$http
        .post(
          '${portal}/sys/sysSignet/v1/listJson?tenantId=' + this.tenantId,
          param
        )
        .then(
          resp => {
            let response = resp.data
            if (this.tenantId) this.data = response.rows
            this.pageResult = {
              page: response.page,
              pageSize: response.pageSize,
              total: response.total
            }
          },
          error => {
            reject(error)
          }
        )
        .finally(() => {
          cb()
        })
    },
    export() {
      let selection = this.$refs.htTable.selection
      if (!selection || selection.length == 0) {
        this.$message({type: 'warning', message: '请至少选择一条记录'})
        return
      }
      let ids = []
      for (let i = 0; i < selection.length; i++) {
        ids.push(selection[i].id)
      }
      req.download(
        window.context.portal +
          '/sys/sysSignet/v1' +
          '/export?ids=' +
          ids.join(',')
      )
    },
    beforeClose() {
      this.uploadDialogVisible = false
      this.fileList = []
      this.loadData()
    },
    handleImport(param) {
      let formData = new FormData()
      formData.append('file', param.file)
      req
        .post(window.context.portal + '/sys/sysSignet/v1/import', formData)
        .then(response => {
          let resp = response.data
          if (resp.state) {
            if (resp.message && resp.message == 'confirmUpload') {
              this.uploadAddress = resp.value
              this.myDialogVisible = true
            } else {
              this.$message({type: 'success', message: resp.message})
              this.fileList = []
              this.uploadDialogVisible = false
              this.$refs.htTable.load() //重新加载列表数据
            }
          } else {
            this.beforeClose()
          }
        })
    },
    handleCommand(params) {
      switch (params.command) {
        case 'edit':
          this.showDialog(params.row)
          break
        case 'import':
          this.uploadDialogVisible = true
          break
        case 'export':
          this.export()
          break
        default:
          break
      }
    },
    uploadSubmit() {
      if (this.$refs.elUpload.uploadFiles.length == 0) {
        this.$message({type: 'warning', message: '请上传文件'})
      }
      this.$refs.elUpload.submit()
    },
    async beforeSaveData() {
      this.isSubmit = true
      if (!this.model.fileId) {
        this.$message.error('请上传印章图片')
        this.isSubmit = false
        return
      }
    },
    afterSaveData() {
      this.dialogVisible = false
      this.$refs.htTable.load()
    },
    beforeClose2() {
      this.myDialogVisible = false
    },
    confirmSubmit(arg) {
      let url =
        window.context.portal +
        '/sys/sysSignet/v1/confirmImport?unZipFilePath=' +
        this.uploadAddress +
        '&status=' +
        arg
      req.post(url).then(rep => {
        rep = rep.data
        if (rep && rep.state) {
          this.$message.success(rep.message)
        } else {
          this.$message.error(rep.message || '保存失败')
        }
        this.myDialogVisible = false
        this.beforeClose()
      })
    },
    onExceed() {
      this.$message.warning('只能选择一个zip文件!')
    }
  }
}
</script>
<style lang="scss" scoped>
div[aria-invalid='true'] >>> .el-input__inner,
div[aria-invalid='true'] >>> .el-input__inner:focus {
  border-color: #f56c6c;
}
.ht-viewer {
  margin-left: 15px;
}
.ht-tab-pane {
  width: 99.9%;
}
::v-deep {
   .el-table {
    height: calc(100% - 170px) !important;
    max-height: calc(100% - 170px) !important;
  }
  .el-table > .el-table__body-wrapper {
    height: calc(100% - 37px) !important;
    max-height: calc(100% - 37px) !important;
  }
}

</style>