iam-logo-config.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. <template>
  2. <a-card>
  3. <a-form :label-col="{ span: 6 }" :wrapper-col="{ span: 12 }" :class="$style.form">
  4. <a-form-item v-for="(item, i) in formInfo" :key="i" :label="item.label">
  5. <a-input
  6. v-if="item.name === 'platformName'"
  7. v-model="item.value"
  8. placeholder="平台名最多设置20个字符"
  9. :max-length="20"
  10. />
  11. <a-upload
  12. name="avatar"
  13. list-type="picture-card"
  14. class="avatar-uploader"
  15. accept=".png,.jpg,.jpeg"
  16. :show-upload-list="false"
  17. :custom-request="({ action, file }) => selfUpload(file, item)"
  18. :before-upload="beforeUpload"
  19. @change="(info) => handleChange(info, item)"
  20. >
  21. <a-tooltip v-if="item.name !== 'platformName'">
  22. <template slot="title"> 建议图片尺寸大小{{ size[item.name] }} </template>
  23. <div v-if="item.value" :class="$style.imgContent">
  24. <img :src="item.value" />
  25. <span :class="$style.actions">
  26. <a-icon type="eye" @click.stop="preview(item)" />
  27. <a-icon type="delete" @click.stop="deletePic(item)" />
  28. </span>
  29. </div>
  30. <div v-else>
  31. <a-icon :type="formInfo[i].loading ? 'loading' : 'plus'" />
  32. <div class="ant-upload-text">
  33. 上传
  34. </div>
  35. </div>
  36. </a-tooltip>
  37. </a-upload>
  38. </a-form-item>
  39. <div :class="$style.button">
  40. <a-button type="primary" :loading="isSubmitting" @click="btnClick">
  41. 保存
  42. </a-button>
  43. </div>
  44. </a-form>
  45. <a-modal
  46. title="预览图片"
  47. :visible="previewVisible"
  48. :dialog-class="$style.preview"
  49. :footer="null"
  50. @cancel="previewVisible = false"
  51. >
  52. <img :src="previewUrl" />
  53. </a-modal>
  54. </a-card>
  55. </template>
  56. <script>
  57. import { xmLocalStorage } from '@/common/services/storage-service'
  58. import { message } from 'ant-design-vue'
  59. import IamWorkbenchService from './iam-workbench-service'
  60. import components from './_import-components/iam-logo-config-import'
  61. function getBase64(img, callback) {
  62. const reader = new FileReader()
  63. reader.addEventListener('load', () => callback(reader.result))
  64. reader.readAsDataURL(img)
  65. }
  66. export default {
  67. name: 'OaLogoConfig',
  68. metaInfo: {
  69. title: 'Logo配置',
  70. },
  71. components,
  72. data() {
  73. return {
  74. formInfo: [
  75. {
  76. name: 'backgroundImg',
  77. label: '登录页背景图',
  78. loading: false,
  79. value: '',
  80. },
  81. {
  82. name: 'platformName',
  83. label: '登录页系统名称',
  84. value: '',
  85. },
  86. {
  87. name: 'loginLogo',
  88. label: '登录页Logo',
  89. loading: false,
  90. value: '',
  91. },
  92. {
  93. name: 'homeLogo',
  94. label: '首页Logo',
  95. loading: false,
  96. value: '',
  97. },
  98. ],
  99. pageflowId: '',
  100. isSubmitting: false,
  101. previewVisible: false,
  102. previewUrl: '',
  103. size: { backgroundImg: '1922x688', loginLogo: '185x27', homeLogo: '200x28' },
  104. }
  105. },
  106. created() {
  107. this.getConfig()
  108. },
  109. methods: {
  110. deletePic(item) {
  111. item.value = ''
  112. },
  113. preview(item) {
  114. this.previewUrl = item.value
  115. this.previewVisible = true
  116. },
  117. getConfig() {
  118. IamWorkbenchService.getLogoConfig().then((res) => {
  119. if (res.data) {
  120. const data = res.data
  121. this.formInfo.forEach((f) => {
  122. f.value = data[f.name]
  123. })
  124. }
  125. })
  126. },
  127. btnClick() {
  128. xmLocalStorage.removeItem('homeLogo')
  129. const params = this.formInfo.reduce((res, item) => {
  130. res = { ...res, ...{ [item.name]: item.value } }
  131. return res
  132. }, {})
  133. this.isSubmitting = true
  134. IamWorkbenchService.saveLogoConfig(params).then((res) => {
  135. this.isSubmitting = false
  136. message.success('保存成功')
  137. })
  138. if (params.homeLogo) xmLocalStorage.setItem('homeLogo', true)
  139. },
  140. beforeUpload(file) {
  141. const isLt10M = file.size / 1024 / 1024 < 10
  142. if (!isLt10M) {
  143. message.error('图片大小不可超过10M,请重新上传!')
  144. }
  145. return isLt10M
  146. },
  147. selfUpload(file, record) {
  148. const base64 = new Promise((resolve) => {
  149. const fileReader = new FileReader()
  150. fileReader.readAsDataURL(file)
  151. fileReader.onload = () => {
  152. resolve(fileReader.result)
  153. }
  154. })
  155. return base64
  156. },
  157. handleChange(info, record) {
  158. getBase64(info.file.originFileObj, (imageUrl) => {
  159. record.value = imageUrl
  160. record.loading = true
  161. })
  162. },
  163. },
  164. }
  165. </script>
  166. <style module lang="scss">
  167. @use '@/common/design' as *;
  168. $back-color: rgba(0, 0, 0, 0.5);
  169. .form {
  170. width: 50%;
  171. margin: 0 auto;
  172. .button {
  173. text-align: center;
  174. }
  175. }
  176. .img-content {
  177. position: relative;
  178. width: 110px;
  179. height: 110px;
  180. &:hover {
  181. background-color: $back-color;
  182. .actions {
  183. opacity: 1;
  184. }
  185. &::before {
  186. position: absolute;
  187. z-index: 1;
  188. width: 100%;
  189. height: 100%;
  190. content: ' ';
  191. background-color: $back-color;
  192. opacity: 1;
  193. transition: all 0.3s;
  194. }
  195. }
  196. img {
  197. width: 100%;
  198. height: 100%;
  199. }
  200. .actions {
  201. position: absolute;
  202. top: 50%;
  203. left: 50%;
  204. z-index: 10;
  205. white-space: nowrap;
  206. opacity: 0;
  207. transition: all 0.3s;
  208. transform: translate(-50%, -50%);
  209. :global(.anticon) {
  210. margin: 0 4px;
  211. color: $white;
  212. cursor: pointer;
  213. }
  214. }
  215. }
  216. .preiew {
  217. img {
  218. width: 100%;
  219. }
  220. }
  221. </style>