123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223 |
- <template>
- <a-card>
- <a-form :label-col="{ span: 6 }" :wrapper-col="{ span: 12 }" :class="$style.form">
- <a-form-item v-for="(item, i) in formInfo" :key="i" :label="item.label">
- <a-input
- v-if="item.name === 'platformName'"
- v-model="item.value"
- placeholder="平台名最多设置20个字符"
- :max-length="20"
- />
- <a-upload
- name="avatar"
- list-type="picture-card"
- class="avatar-uploader"
- accept=".png,.jpg,.jpeg"
- :show-upload-list="false"
- :custom-request="({ action, file }) => selfUpload(file, item)"
- :before-upload="beforeUpload"
- @change="(info) => handleChange(info, item)"
- >
- <a-tooltip v-if="item.name !== 'platformName'">
- <template slot="title"> 建议图片尺寸大小{{ size[item.name] }} </template>
- <div v-if="item.value" :class="$style.imgContent">
- <img :src="item.value" />
- <span :class="$style.actions">
- <a-icon type="eye" @click.stop="preview(item)" />
- <a-icon type="delete" @click.stop="deletePic(item)" />
- </span>
- </div>
- <div v-else>
- <a-icon :type="formInfo[i].loading ? 'loading' : 'plus'" />
- <div class="ant-upload-text">
- 上传
- </div>
- </div>
- </a-tooltip>
- </a-upload>
- </a-form-item>
- <div :class="$style.button">
- <a-button type="primary" :loading="isSubmitting" @click="btnClick">
- 保存
- </a-button>
- </div>
- </a-form>
- <a-modal
- title="预览图片"
- :visible="previewVisible"
- :dialog-class="$style.preview"
- :footer="null"
- @cancel="previewVisible = false"
- >
- <img :src="previewUrl" />
- </a-modal>
- </a-card>
- </template>
- <script>
- import { xmLocalStorage } from '@/common/services/storage-service'
- import { message } from 'ant-design-vue'
- import IamWorkbenchService from './iam-workbench-service'
- import components from './_import-components/iam-logo-config-import'
- function getBase64(img, callback) {
- const reader = new FileReader()
- reader.addEventListener('load', () => callback(reader.result))
- reader.readAsDataURL(img)
- }
- export default {
- name: 'OaLogoConfig',
- metaInfo: {
- title: 'Logo配置',
- },
- components,
- data() {
- return {
- formInfo: [
- {
- name: 'backgroundImg',
- label: '登录页背景图',
- loading: false,
- value: '',
- },
- {
- name: 'platformName',
- label: '登录页系统名称',
- value: '',
- },
- {
- name: 'loginLogo',
- label: '登录页Logo',
- loading: false,
- value: '',
- },
- {
- name: 'homeLogo',
- label: '首页Logo',
- loading: false,
- value: '',
- },
- ],
- pageflowId: '',
- isSubmitting: false,
- previewVisible: false,
- previewUrl: '',
- size: { backgroundImg: '1922x688', loginLogo: '185x27', homeLogo: '200x28' },
- }
- },
- created() {
- this.getConfig()
- },
- methods: {
- deletePic(item) {
- item.value = ''
- },
- preview(item) {
- this.previewUrl = item.value
- this.previewVisible = true
- },
- getConfig() {
- IamWorkbenchService.getLogoConfig().then((res) => {
- if (res.data) {
- const data = res.data
- this.formInfo.forEach((f) => {
- f.value = data[f.name]
- })
- }
- })
- },
- btnClick() {
- xmLocalStorage.removeItem('homeLogo')
- const params = this.formInfo.reduce((res, item) => {
- res = { ...res, ...{ [item.name]: item.value } }
- return res
- }, {})
- this.isSubmitting = true
- IamWorkbenchService.saveLogoConfig(params).then((res) => {
- this.isSubmitting = false
- message.success('保存成功')
- })
- if (params.homeLogo) xmLocalStorage.setItem('homeLogo', true)
- },
- beforeUpload(file) {
- const isLt10M = file.size / 1024 / 1024 < 10
- if (!isLt10M) {
- message.error('图片大小不可超过10M,请重新上传!')
- }
- return isLt10M
- },
- selfUpload(file, record) {
- const base64 = new Promise((resolve) => {
- const fileReader = new FileReader()
- fileReader.readAsDataURL(file)
- fileReader.onload = () => {
- resolve(fileReader.result)
- }
- })
- return base64
- },
- handleChange(info, record) {
- getBase64(info.file.originFileObj, (imageUrl) => {
- record.value = imageUrl
- record.loading = true
- })
- },
- },
- }
- </script>
- <style module lang="scss">
- @use '@/common/design' as *;
- $back-color: rgba(0, 0, 0, 0.5);
- .form {
- width: 50%;
- margin: 0 auto;
- .button {
- text-align: center;
- }
- }
- .img-content {
- position: relative;
- width: 110px;
- height: 110px;
- &:hover {
- background-color: $back-color;
- .actions {
- opacity: 1;
- }
- &::before {
- position: absolute;
- z-index: 1;
- width: 100%;
- height: 100%;
- content: ' ';
- background-color: $back-color;
- opacity: 1;
- transition: all 0.3s;
- }
- }
- img {
- width: 100%;
- height: 100%;
- }
- .actions {
- position: absolute;
- top: 50%;
- left: 50%;
- z-index: 10;
- white-space: nowrap;
- opacity: 0;
- transition: all 0.3s;
- transform: translate(-50%, -50%);
- :global(.anticon) {
- margin: 0 4px;
- color: $white;
- cursor: pointer;
- }
- }
- }
- .preiew {
- img {
- width: 100%;
- }
- }
- </style>
|