mirror of
https://github.com/continew-org/continew-admin-ui.git
synced 2025-09-09 18:59:26 +08:00
feat: 系统配置-基础配置 logo 及 favicon 改为 base64 存储
This commit is contained in:
@@ -261,3 +261,21 @@ export const copyText = (text: any) => {
|
|||||||
document.body.removeChild(textarea)
|
document.body.removeChild(textarea)
|
||||||
Message.success('复制成功')
|
Message.success('复制成功')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @desc 文件的转换base64 */
|
||||||
|
export const fileToBase64 = (file: File): Promise<string> => {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
const reader = new FileReader()
|
||||||
|
reader.onload = () => {
|
||||||
|
if (reader.result) {
|
||||||
|
resolve(reader.result.toString())
|
||||||
|
} else {
|
||||||
|
reject(new Error('文件转base64失败'))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
reader.onerror = (error) => {
|
||||||
|
reject(error)
|
||||||
|
}
|
||||||
|
reader.readAsDataURL(file)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
@@ -106,11 +106,11 @@ import {
|
|||||||
type SiteConfig,
|
type SiteConfig,
|
||||||
listOption,
|
listOption,
|
||||||
resetOptionValue,
|
resetOptionValue,
|
||||||
updateOption,
|
updateOption
|
||||||
uploadFile
|
|
||||||
} from '@/apis'
|
} from '@/apis'
|
||||||
import { useAppStore } from '@/stores'
|
import { useAppStore } from '@/stores'
|
||||||
import { useForm } from '@/hooks'
|
import { useForm } from '@/hooks'
|
||||||
|
import { fileToBase64 } from '@/utils'
|
||||||
|
|
||||||
defineOptions({ name: 'BasicSetting' })
|
defineOptions({ name: 'BasicSetting' })
|
||||||
|
|
||||||
@@ -213,14 +213,15 @@ const onResetValue = () => {
|
|||||||
const handleUploadFavicon = (options: RequestOption) => {
|
const handleUploadFavicon = (options: RequestOption) => {
|
||||||
const controller = new AbortController()
|
const controller = new AbortController()
|
||||||
;(async function requestWrap() {
|
;(async function requestWrap() {
|
||||||
const { onProgress, onError, onSuccess, fileItem, name = 'file' } = options
|
const { onProgress, onError, onSuccess, fileItem } = options
|
||||||
onProgress(20)
|
onProgress(20)
|
||||||
const formData = new FormData()
|
if (!fileItem.file) {
|
||||||
formData.append(name as string, fileItem.file as Blob)
|
return
|
||||||
uploadFile(formData)
|
}
|
||||||
|
fileToBase64(fileItem.file).then()
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
onSuccess(res)
|
onSuccess()
|
||||||
form.SITE_FAVICON = res.data.url
|
form.SITE_FAVICON = res
|
||||||
Message.success('上传成功')
|
Message.success('上传成功')
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
@@ -243,14 +244,15 @@ const handleChangeFavicon = (_: any, currentFile: any) => {
|
|||||||
const handleUploadLogo = (options: RequestOption) => {
|
const handleUploadLogo = (options: RequestOption) => {
|
||||||
const controller = new AbortController()
|
const controller = new AbortController()
|
||||||
;(async function requestWrap() {
|
;(async function requestWrap() {
|
||||||
const { onProgress, onError, onSuccess, fileItem, name = 'file' } = options
|
const { onProgress, onError, onSuccess, fileItem } = options
|
||||||
onProgress(20)
|
onProgress(20)
|
||||||
const formData = new FormData()
|
if (!fileItem.file) {
|
||||||
formData.append(name as string, fileItem.file as Blob)
|
return
|
||||||
uploadFile(formData)
|
}
|
||||||
|
fileToBase64(fileItem.file).then()
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
onSuccess(res)
|
onSuccess()
|
||||||
form.SITE_LOGO = res.data.url
|
form.SITE_LOGO = res
|
||||||
Message.success('上传成功')
|
Message.success('上传成功')
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
|
Reference in New Issue
Block a user