mirror of
https://github.com/continew-org/continew-admin-ui.git
synced 2025-09-08 12:57:11 +08:00
feat: 系统配置-基础配置 logo 及 favicon 改为 base64 存储
This commit is contained in:
@@ -261,3 +261,21 @@ export const copyText = (text: any) => {
|
||||
document.body.removeChild(textarea)
|
||||
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,
|
||||
listOption,
|
||||
resetOptionValue,
|
||||
updateOption,
|
||||
uploadFile
|
||||
updateOption
|
||||
} from '@/apis'
|
||||
import { useAppStore } from '@/stores'
|
||||
import { useForm } from '@/hooks'
|
||||
import { fileToBase64 } from '@/utils'
|
||||
|
||||
defineOptions({ name: 'BasicSetting' })
|
||||
|
||||
@@ -212,15 +212,16 @@ const onResetValue = () => {
|
||||
// 上传 favicon
|
||||
const handleUploadFavicon = (options: RequestOption) => {
|
||||
const controller = new AbortController()
|
||||
; (async function requestWrap() {
|
||||
const { onProgress, onError, onSuccess, fileItem, name = 'file' } = options
|
||||
;(async function requestWrap() {
|
||||
const { onProgress, onError, onSuccess, fileItem } = options
|
||||
onProgress(20)
|
||||
const formData = new FormData()
|
||||
formData.append(name as string, fileItem.file as Blob)
|
||||
uploadFile(formData)
|
||||
if (!fileItem.file) {
|
||||
return
|
||||
}
|
||||
fileToBase64(fileItem.file).then()
|
||||
.then((res) => {
|
||||
onSuccess(res)
|
||||
form.SITE_FAVICON = res.data.url
|
||||
onSuccess()
|
||||
form.SITE_FAVICON = res
|
||||
Message.success('上传成功')
|
||||
})
|
||||
.catch((error) => {
|
||||
@@ -242,15 +243,16 @@ const handleChangeFavicon = (_: any, currentFile: any) => {
|
||||
// 上传 Logo
|
||||
const handleUploadLogo = (options: RequestOption) => {
|
||||
const controller = new AbortController()
|
||||
; (async function requestWrap() {
|
||||
const { onProgress, onError, onSuccess, fileItem, name = 'file' } = options
|
||||
;(async function requestWrap() {
|
||||
const { onProgress, onError, onSuccess, fileItem } = options
|
||||
onProgress(20)
|
||||
const formData = new FormData()
|
||||
formData.append(name as string, fileItem.file as Blob)
|
||||
uploadFile(formData)
|
||||
if (!fileItem.file) {
|
||||
return
|
||||
}
|
||||
fileToBase64(fileItem.file).then()
|
||||
.then((res) => {
|
||||
onSuccess(res)
|
||||
form.SITE_LOGO = res.data.url
|
||||
onSuccess()
|
||||
form.SITE_LOGO = res
|
||||
Message.success('上传成功')
|
||||
})
|
||||
.catch((error) => {
|
||||
|
Reference in New Issue
Block a user