AppInfoDialog.vue 10.2 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
<template>
  <el-dialog
    :title="title"
    :visible.sync="dialogVisible"
    width="650px"
    :close-on-click-modal="false"
    append-to-body
  >
    <el-form
      :model="appModel"
      data-vv-scope="appForm"
      label-position="left"
      v-if="dialogVisible"
    >
      <ht-form-item label="应用名称">
        <ht-input
          v-model="appModel.name"
          validate="required"
          style="width: 100%"
          :maxlength="50"
          :showWordLimit="true"
        />
      </ht-form-item>
      <ht-form-item label="应用别名">
        <ht-input
          :disabled="!!appModel.id"
          v-model="appModel.alias"
          validate="required"
          style="width: 100%"
          :maxlength="50"
          :showWordLimit="true"
          v-pinyin="appModel.name"
        />
      </ht-form-item>
      <ht-form-item label="所属分类" class="is-required">
        <tree-select
          style="width: 456px"
          :appendToBody="true"
          v-model="appModel.menuId"
          :normalizer="normalizer"
          :multiple="false"
          :options="appTypes"
          noOptionsText=" "
          noChildrenText=" "
          z-index="9999"
          placeholder="请选择父节点"
          :clearable="false"
        />
      </ht-form-item>
      <ht-form-item label="应用Logo">
        <div class="icon-wrap">
          <div class="icon-main" :style="{background: appModel.iconColor}">
            <el-image class="image" :src="image" v-if="image"></el-image>
            <i
              v-else
              :class="appModel.icon"
              :style="{fontSize: '30px', color: 'white'}"
              class="app-icon"
            ></i>
          </div>
          <icon-dialog class="icon-select_wrap" @selected="selectIcon" />
          <el-upload
            action="string"
            :http-request="updateImage"
            :show-file-list="false"
            accept="image/gif,image/jpeg,image/png,image/jpg,image/bmp"
          >
            <el-button size="small">上传图标</el-button>
          </el-upload>
          <el-button
            style="margin-left: 16px"
            class="upload-bt"
            size="small"
            @click="handleClear"
            >清空</el-button
          >
        </div>
      </ht-form-item>
      <ht-form-item label="Logo颜色">
        <el-input
          v-model="appModel.iconColor"
          style="width: 414px; vertical-align: middle"
          clearable
          placeholder=""
        />
        <el-color-picker
          class="layout_md"
          v-model="appModel.iconColor"
        ></el-color-picker>
        <div class="default-color--list">
          <div
            class="color-item"
            v-for="(item, index) in colorList"
            :key="index"
            @click="handleColor(item)"
            :style="{background: item}"
          ></div>
        </div>
      </ht-form-item>
      <ht-form-item label="排序">
        <ht-input
          class="input-text"
          v-model="appModel.sn"
          :min="0"
          :max="999"
          style="width: 100%"
          type="number"
          controls-position="right"
        />
      </ht-form-item>
      <ht-form-item label="应用说明">
        <el-upload
          style="display: inline-block"
          :action="uploadUrl"
          :on-success="handleUploadResult"
          :on-error="handleUploadResult"
          :headers="uploadHeaders"
          :on-exceed="onExceed"
          accept=".pdf,.png,.jpg"
          :before-upload="beforeUpload"
          :on-remove="onRemove"
          :limit="1"
          :file-list="fileList"
          ref="uploadRef"
        >
          <div style="display: flex">
            <el-button size="small" icon="icon-my-todo-upload">上传</el-button>
            <div style="color: #5f5f5f; margin-left: 8px">可上传图片或pdf</div>
          </div>
        </el-upload></ht-form-item
      >
      <ht-form-item label="应用描述">
        <ht-input
          v-model="appModel.desc"
          type="textarea"
          :rows="3"
          :maxlength="200"
          :showWordLimit="true"
          style="width: 100%"
        />
      </ht-form-item>
    </el-form>
    <div slot="footer">
      <el-button @click="beforeClose">取消</el-button>
      <ht-submit-button
        url="${portal}/portal/sysApp/v1/save"
        :model="appModel"
        scope-name="appForm"
        @after-response-value="afterSaveData"
        @before-save-data="beforeSaveData"
        :is-submit="isSubmit"
        >确定
      </ht-submit-button>
    </div>
  </el-dialog>
</template>

<script>
import uc from '@/api/uc.js'
import portal from '@/api/portal'
import utils from '@/hotent-ui-util'
import {mapState} from 'vuex'
const IconDialog = () => import('@/components/dialog/IconDialog.vue')
const TreeSelect = () => import('@riophae/vue-treeselect')
import _ from 'lodash'
export default {
  name: 'AppInfoDialog',
  components: {
    IconDialog,
    TreeSelect,
  },
  data() {
    return {
      dialogVisible: false,
      appModel: {
        id: '',
        name: '',
        alias: '',
        icon: '',
        iconColor: '#1339E0',
        type: '',
        content: '',
        sn: 1,
        createTime: '',
        updateTime: '',
        createBy: '',
        updateBy: '',
        isPublish: '',
        desc: '',
        menuAlias: '',
        menuName: '',
        contentAlias: '',
      },
      image: '',
      wrapWidth: '434px',
      title: '添加应用信息',
      colorList: [
        '#409EFF',
        '#07C160',
        '#4053FF',
        '#F6B85A',
        '#FF8A46',
        '#8550E1',
      ],
      action: 'add',
      menus: [],
      isSubmit: true,
      fullscreenLoading: false,
      fileList: [],
    }
  },
  computed: mapState({
    appTypes: (state) => {
      let stateAppTypes = _.cloneDeep(state.menu.appTypes)
      utils.nestForEach(stateAppTypes, 'children', (item) => {
        if (!item.children || item.children.length === 0) {
          delete item.children
        }
      })

      return stateAppTypes || []
    },
    uploadUrl: function () {
      return `${context.portal}/system/file/v1/upload`
    },
    uploadHeaders: function (mapState) {
      return {Authorization: 'Bearer ' + mapState.login.currentUser.token}
    },
  }),
  mounted() {
    this.loadMenus()
  },
  methods: {
    open(data) {
      if (data) {
        this.action = 'edit'
        this.title = '编辑应用信息'
        portal.getSysApp(data.id).then((data) => {
          data.icon = data.icon || ''
          this.appModel = data
          this.image = ''
          if (this.appModel.icon && this.appModel.icon.indexOf('icon') < 0) {
            this.image = this.appModel.icon
          }
          if (this.appModel.fileInfo) {
            this.fileList = [JSON.parse(this.appModel.fileInfo)].map((item) => {
              return {
                name: item.fileName,
              }
            })
          }
        })
        this.dialogVisible = true
      } else {
        this.action = 'add'
        this.title = '添加应用信息'
        this.appModel.icon = 'icon-application1'
        this.appModel.iconColor = '#409EFF'
        this.appModel.type = 1
        this.appModel.sn = 1
        this.image = ''
        this.dialogVisible = true
      }
    },
    getRandomColor() {
      return '#' + Math.floor(Math.random() * 16777215).toString(16)
    },
    updateImage(param) {
      const formData = new FormData()
      formData.append('files', param.file)
      uc.fileUpload(formData)
        .then((response) => {
          this.$store
            .dispatch('menu/downloadImg', response.fileId)
            .then((res) => {
              if (res !== '') {
                this.image = res
                param.onSuccess()
              }
            })
            .catch(() => {
              param.onError()
            })
        })
        .catch(() => {
          param.onError()
        })
    },
    handleClear() {
      this.appModel.icon = ''
      this.image = ''
    },
    selectIcon(icon) {
      this.image = ''
      this.appModel.icon = icon
    },
    beforeClose() {
      this.dialogVisible = false
      Object.assign(this.$data, this.$options.data())
    },
    afterSaveData(data) {
      this.$emit('refresh')
      if (this.action === 'add') {
        this.$emit('after-add', data)
      }
      this.beforeClose()
    },
    beforeSaveData() {
      this.isSubmit = true
      if (!this.appModel.menuId) {
        this.$message.error('分类菜单为必填')
        this.isSubmit = false
        return
      }
      if (this.image) {
        this.appModel.icon = this.image
      }
    },
    handleColor(color) {
      this.appModel.iconColor = color
    },
    normalizer(node) {
      return {
        id: node.id,
        label: node.name,
        children: node.children,
        isDefaultExpanded: false,
      }
    },
    loadMenus() {
      this.$store.dispatch('menu/getAppTypes')
    },
    handleUploadResult(data) {
      if (data.success) {
        this.appModel.fileInfo = JSON.stringify(data)
      } else {
        this.$message.error('上传失败')
      }
      this.fullscreenLoading = false
    },
    onExceed(files) {
      this.$refs.uploadRef.clearFiles()
      this.$nextTick(() => {
        this.$refs.uploadRef.handleStart(files[0])
        this.$refs.uploadRef.submit()
      })
    },
    beforeUpload(file) {
      this.fullscreenLoading = true
    },
    onRemove(file) {
      this.appModel.fileInfo = null
    },
  },
}
</script>

<style lang="scss" scoped>
.icon-wrap {
  display: flex;
  align-items: center;
  margin-top: -5px;
  .icon-main {
    width: 40px;
    height: 40px;
    background: rgb(244, 244, 244);
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 5px;
    text-align: center;
  }
}
.icon-select_wrap {
  margin: 0 16px;
  flex: 0 0 87px;
  height: 34px;
}
.layout_md {
  vertical-align: middle;
  /deep/.el-color-picker__trigger {
    border-color: #dcdfe6;
  }
}
::v-deep {
  .el-dialog__footer {
    text-align: right;
  }
}

::v-deep .el-upload-list__item {
  max-width: 456px;
}

.default-color--list {
  display: flex;
  margin-top: 10px;
  .color-item {
    margin-right: 8px;
    height: 24px;
    width: 24px;
    border-radius: 4px;
    cursor: pointer;
  }
}
</style>