mirror of
https://gitee.com/dromara/go-view.git
synced 2025-04-06 03:58:04 +08:00
chore: 修改上传地址的接口和图片的展示地址拼接
This commit is contained in:
parent
8ab64846d4
commit
f9ed391c81
@ -74,9 +74,9 @@ export const changeProjectReleaseApi = async (data: object) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// * 上传文件
|
// * 上传文件
|
||||||
export const uploadFile = async (url:string, data: object) => {
|
export const uploadFile = async (data: object) => {
|
||||||
try {
|
try {
|
||||||
const res = await http(RequestHttpEnum.POST)(url, data, ContentTypeEnum.FORM_DATA);
|
const res = await http(RequestHttpEnum.POST)(`${ModuleTypeEnum.PROJECT}/upload`, data, ContentTypeEnum.FORM_DATA);
|
||||||
return res;
|
return res;
|
||||||
} catch {
|
} catch {
|
||||||
httpErrorHandle();
|
httpErrorHandle();
|
||||||
|
@ -1,14 +1,14 @@
|
|||||||
import { useSystemStore } from '@/store/modules/systemStore/systemStore'
|
import { useSystemStore } from '@/store/modules/systemStore/systemStore'
|
||||||
import { SystemStoreEnum } from '@/store/modules/systemStore/systemStore.d'
|
import { SystemStoreEnum } from '@/store/modules/systemStore/systemStore.d'
|
||||||
import { ResultEnum } from '@/enums/httpEnum'
|
import { ResultEnum } from '@/enums/httpEnum'
|
||||||
import { ossUrlApi } from '@/api/path/'
|
import { ossUrlApi } from '@/api/path'
|
||||||
|
|
||||||
|
|
||||||
// * 初始化
|
// * 初始化
|
||||||
export const useSystemInit = async () => {
|
export const useSystemInit = async () => {
|
||||||
const systemStore = useSystemStore()
|
const systemStore = useSystemStore()
|
||||||
|
|
||||||
// 获取 OSS 信息
|
// 获取 OSS 信息的 url 地址,用来拼接展示图片的地址
|
||||||
const getOssUrl = async () => {
|
const getOssUrl = async () => {
|
||||||
const res = await ossUrlApi({}) as unknown as MyResponseType
|
const res = await ossUrlApi({}) as unknown as MyResponseType
|
||||||
if (res.code === ResultEnum.SUCCESS) {
|
if (res.code === ResultEnum.SUCCESS) {
|
||||||
|
@ -134,7 +134,7 @@ import { EditCanvasConfigEnum } from '@/store/modules/chartEditStore/chartEditSt
|
|||||||
import { useSystemStore } from '@/store/modules/systemStore/systemStore'
|
import { useSystemStore } from '@/store/modules/systemStore/systemStore'
|
||||||
import { StylesSetting } from '@/components/Pages/ChartItemSetting'
|
import { StylesSetting } from '@/components/Pages/ChartItemSetting'
|
||||||
import { UploadCustomRequestOptions } from 'naive-ui'
|
import { UploadCustomRequestOptions } from 'naive-ui'
|
||||||
import { fileToUrl, loadAsyncComponent, fetchRouteParamsLocation } from '@/utils'
|
import { loadAsyncComponent, fetchRouteParamsLocation } from '@/utils'
|
||||||
import { PreviewScaleEnum } from '@/enums/styleEnum'
|
import { PreviewScaleEnum } from '@/enums/styleEnum'
|
||||||
import { ResultEnum } from '@/enums/httpEnum'
|
import { ResultEnum } from '@/enums/httpEnum'
|
||||||
import { icon } from '@/plugins'
|
import { icon } from '@/plugins'
|
||||||
@ -273,10 +273,6 @@ const clearColor = () => {
|
|||||||
const customRequest = (options: UploadCustomRequestOptions) => {
|
const customRequest = (options: UploadCustomRequestOptions) => {
|
||||||
const { file } = options
|
const { file } = options
|
||||||
nextTick(async () => {
|
nextTick(async () => {
|
||||||
if(!systemStore.getFetchInfo.OSSUrl) {
|
|
||||||
window['$message'].error('添加图片失败,请刷新页面重试!')
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if (file.file) {
|
if (file.file) {
|
||||||
// 修改名称
|
// 修改名称
|
||||||
const newNameFile = new File(
|
const newNameFile = new File(
|
||||||
@ -286,12 +282,12 @@ const customRequest = (options: UploadCustomRequestOptions) => {
|
|||||||
)
|
)
|
||||||
let uploadParams = new FormData()
|
let uploadParams = new FormData()
|
||||||
uploadParams.append('object', newNameFile)
|
uploadParams.append('object', newNameFile)
|
||||||
const uploadRes = await uploadFile(systemStore.getFetchInfo.OSSUrl ,uploadParams) as unknown as MyResponseType
|
const uploadRes = await uploadFile(uploadParams) as unknown as MyResponseType
|
||||||
|
|
||||||
if(uploadRes.code === ResultEnum.SUCCESS) {
|
if(uploadRes.code === ResultEnum.SUCCESS) {
|
||||||
chartEditStore.setEditCanvasConfig(
|
chartEditStore.setEditCanvasConfig(
|
||||||
EditCanvasConfigEnum.BACKGROUND_IMAGE,
|
EditCanvasConfigEnum.BACKGROUND_IMAGE,
|
||||||
`${uploadRes.data.objectContent.httpRequest.uri}?time=${new Date().getTime()}`
|
`${systemStore.getFetchInfo.OSSUrl}${uploadRes.data.fileName}?time=${new Date().getTime()}`
|
||||||
)
|
)
|
||||||
chartEditStore.setEditCanvasConfig(
|
chartEditStore.setEditCanvasConfig(
|
||||||
EditCanvasConfigEnum.SELECT_COLOR,
|
EditCanvasConfigEnum.SELECT_COLOR,
|
||||||
|
@ -4,6 +4,7 @@ import { getUUID, httpErrorHandle, fetchRouteParamsLocation, base64toFile } from
|
|||||||
import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore'
|
import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore'
|
||||||
import { EditCanvasTypeEnum, ChartEditStoreEnum, ProjectInfoEnum, ChartEditStorage } from '@/store/modules/chartEditStore/chartEditStore.d'
|
import { EditCanvasTypeEnum, ChartEditStoreEnum, ProjectInfoEnum, ChartEditStorage } from '@/store/modules/chartEditStore/chartEditStore.d'
|
||||||
import { useChartHistoryStore } from '@/store/modules/chartHistoryStore/chartHistoryStore'
|
import { useChartHistoryStore } from '@/store/modules/chartHistoryStore/chartHistoryStore'
|
||||||
|
import { StylesSetting } from '@/components/Pages/ChartItemSetting'
|
||||||
import { useSystemStore } from '@/store/modules/systemStore/systemStore'
|
import { useSystemStore } from '@/store/modules/systemStore/systemStore'
|
||||||
import { fetchChartComponent, fetchConfigComponent, createComponent } from '@/packages/index'
|
import { fetchChartComponent, fetchConfigComponent, createComponent } from '@/packages/index'
|
||||||
import { saveInterval } from '@/settings/designSetting'
|
import { saveInterval } from '@/settings/designSetting'
|
||||||
@ -197,11 +198,6 @@ export const useSync = () => {
|
|||||||
const dataSyncUpdate = throttle(async () => {
|
const dataSyncUpdate = throttle(async () => {
|
||||||
if(!fetchRouteParamsLocation()) return
|
if(!fetchRouteParamsLocation()) return
|
||||||
|
|
||||||
if(!systemStore.getFetchInfo.OSSUrl) {
|
|
||||||
window['$message'].error('数据保存失败,请刷新页面重试!')
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
let projectId = chartEditStore.getProjectInfo[ProjectInfoEnum.PROJECT_ID];
|
let projectId = chartEditStore.getProjectInfo[ProjectInfoEnum.PROJECT_ID];
|
||||||
if(projectId === null || projectId === ''){
|
if(projectId === null || projectId === ''){
|
||||||
window['$message'].error('数据初未始化成功,请刷新页面!')
|
window['$message'].error('数据初未始化成功,请刷新页面!')
|
||||||
@ -222,12 +218,12 @@ export const useSync = () => {
|
|||||||
// 上传预览图
|
// 上传预览图
|
||||||
let uploadParams = new FormData()
|
let uploadParams = new FormData()
|
||||||
uploadParams.append('object', base64toFile(canvasImage.toDataURL(), `${fetchRouteParamsLocation()}_index_preview.png`))
|
uploadParams.append('object', base64toFile(canvasImage.toDataURL(), `${fetchRouteParamsLocation()}_index_preview.png`))
|
||||||
const uploadRes = await uploadFile(systemStore.getFetchInfo.OSSUrl, uploadParams) as unknown as MyResponseType
|
const uploadRes = await uploadFile(uploadParams) as unknown as MyResponseType
|
||||||
// 保存预览图
|
// 保存预览图
|
||||||
if(uploadRes.code === ResultEnum.SUCCESS) {
|
if(uploadRes.code === ResultEnum.SUCCESS) {
|
||||||
await updateProjectApi({
|
await updateProjectApi({
|
||||||
id: fetchRouteParamsLocation(),
|
id: fetchRouteParamsLocation(),
|
||||||
indexImage: uploadRes.data.objectContent.httpRequest.uri
|
indexImage: `${systemStore.getFetchInfo.OSSUrl}${uploadRes.data.fileName}`
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user