feat: 修改接口

This commit is contained in:
huanghao1412 2023-12-26 20:32:11 +08:00
parent 8e38d1c84d
commit d2c8ed1c20
15 changed files with 197 additions and 133 deletions

5
.env
View File

@ -3,8 +3,9 @@ VITE_DEV_PORT = '8080'
# development path
# VITE_DEV_PATH = 'https://demo.mtruning.club'
VITE_DEV_PATH = 'http://192.168.0.120:3001'
VITE_DEV_PATH = 'http://192.168.0.34:8024'
# VITE_DEV_PATH = 'http://192.168.0.120:3001'
# production path
# VITE_PRO_PATH = 'https://demo.mtruning.club'
VITE_PRO_PATH = 'http://192.168.0.120:3001'
VITE_PRO_PATH = 'http://192.168.0.34:8024'

View File

@ -4,15 +4,10 @@
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta name="renderer" content="webkit" />
<meta name="description" content="GoView 是高效、高性能的拖拽式低代码数据可视化开发平台,将页面元素封装为基础组件,无需编写代码即可完成业务需求。">
<meta name="keywords" content="GoViewgoview低代码可视化">
<meta name="author" content="奔跑的面条,面条">
<meta
name="viewport"
content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=0"
/>
<link rel="icon" href="./favicon.ico" />
<title>GoView</title>
<link rel="stylesheet" href="./index.css" />
</head>
<body>

View File

@ -18,6 +18,9 @@ import { NConfigProvider } from 'naive-ui'
import { GoAppProvider } from '@/components/GoAppProvider'
import { I18n } from '@/components/I18n'
import { useSystemInit, useDarkThemeHook, useThemeOverridesHook, useCode, useLang } from '@/hooks'
import { getToken } from '@/api/path'
getToken()
//
const darkTheme = useDarkThemeHook()

View File

@ -13,7 +13,7 @@ export interface MyResponseType<T> {
data: T
message: string
// 兼顾主系统
errcode: any
errcode: string
}
export interface MyRequestInstance extends Axios {

View File

@ -3,32 +3,23 @@ import { http } from "@/api/http";
import { RequestHttpEnum } from "@/enums/httpEnum";
import { httpErrorHandle } from '@/utils'
const allCookies = document.cookie;
function getCookie(name: string) {
const cookies = document.cookie.split(';');
for (const cookie of cookies) {
const [cookieName, cookieValue] = cookie.trim().split('=');
if (cookieName === name) {
return decodeURIComponent(cookieValue);
}
}
return null;
}
console.log(allCookies, getCookie('access_token'));
export function getToken() {
const TokenKey = 'access_token'
if (getCookie(TokenKey)) {
return getCookie(TokenKey)
} else {
return sessionStorage.getItem(TokenKey)
}
let queryStr = window.location.href
queryStr = queryStr.split('?')[1]
if(queryStr.indexOf('#') > -1) queryStr = queryStr.split('#')[0]
console.log(queryStr)
let query:{[key:string]: string} = {}
queryStr.split('&').forEach((item:string) => {
query[item.split('=')[0]] = item.split('=')[1]
})
return query.access_token
}
export const publicInterface = async (paramType:string, interfaceType:string, paramData:unknown) =>{
export const publicInterface = async (paramType:string, interfaceType:string, paramData?:unknown) =>{
try {
const access_token = getToken()
const res = await http(RequestHttpEnum.POST)<unknown>(paramType, {
console.log(access_token, window)
const res = await http(RequestHttpEnum.POST)<any>(paramType, {
access_token,
type: interfaceType,
data: paramData

View File

@ -1,99 +1,50 @@
import { http } from '@/api/http'
import { httpErrorHandle } from '@/utils'
import { ContentTypeEnum, RequestHttpEnum, ModuleTypeEnum } from '@/enums/httpEnum'
import { ProjectItem, ProjectDetail } from './project'
import {publicInterface} from './business.api'
import {http} from "@/api/http";
import {ContentTypeEnum, RequestHttpEnum} from "@/enums/httpEnum";
import {httpErrorHandle} from "@/utils";
// * 项目列表
export const projectListApi = async (data: object) => {
try {
const res = await http(RequestHttpEnum.GET)<ProjectItem[]>(`${ModuleTypeEnum.PROJECT}/list`, data)
return res
} catch {
httpErrorHandle()
}
return publicInterface('/dcim/system/custom_large_screen', 'get', data)
}
// * 新增项目
export const createProjectApi = async (data: object) => {
try {
const res = await http(RequestHttpEnum.POST)<{
/**
* id
*/
id: number
}>(`${ModuleTypeEnum.PROJECT}/create`, data)
return res
} catch {
httpErrorHandle()
}
return publicInterface('/dcim/system/custom_large_screen', 'add', data)
}
// * 获取项目
export const fetchProjectApi = async (data: object) => {
try {
const res = await http(RequestHttpEnum.GET)<ProjectDetail>(`${ModuleTypeEnum.PROJECT}/getData`, data)
return res
} catch {
httpErrorHandle()
}
return publicInterface('/dcim/system/custom_large_screen', 'get_one', data)
}
// * 保存项目
export const saveProjectApi = async (data: object) => {
try {
const res = await http(RequestHttpEnum.POST)(
`${ModuleTypeEnum.PROJECT}/save/data`,
data,
ContentTypeEnum.FORM_URLENCODED
)
return res
} catch {
httpErrorHandle()
}
return publicInterface('/dcim/system/custom_large_screen', 'mod', data)
}
// * 修改项目基础信息
export const updateProjectApi = async (data: object) => {
try {
const res = await http(RequestHttpEnum.POST)(`${ModuleTypeEnum.PROJECT}/edit`, data)
return res
} catch {
httpErrorHandle()
}
return publicInterface('/dcim/system/custom_large_screen', 'mod', data)
}
// * 删除项目
export const deleteProjectApi = async (data: object) => {
try {
const res = await http(RequestHttpEnum.DELETE)(`${ModuleTypeEnum.PROJECT}/delete`, data)
return res
} catch {
httpErrorHandle()
}
return publicInterface('/dcim/system/custom_large_screen', 'del', data)
}
// * 修改发布状态 [-1未发布,1发布]
export const changeProjectReleaseApi = async (data: object) => {
try {
const res = await http(RequestHttpEnum.PUT)(`${ModuleTypeEnum.PROJECT}/publish`, data)
return res
} catch {
httpErrorHandle()
}
return publicInterface('/dcim/system/custom_large_screen', 'mod', data)
}
// * 上传文件
export const uploadFile = async (data: object) => {
try {
const res = await http(RequestHttpEnum.POST)<{
/**
*
*/
fileName: string,
fileurl: string,
}>(`${ModuleTypeEnum.PROJECT}/upload`, data, ContentTypeEnum.FORM_DATA)
const res = await http(RequestHttpEnum.POST)<any>('/dcim/system/custom_large_screen/upload_file', data, ContentTypeEnum.FORM_DATA)
return res
} catch {
httpErrorHandle()
}
// return publicInterface('/dcim/system/custom_large_screen/upload_file', 'get', data)
}

View File

@ -0,0 +1,99 @@
import { http } from '@/api/http'
import { httpErrorHandle } from '@/utils'
import { ContentTypeEnum, RequestHttpEnum, ModuleTypeEnum } from '@/enums/httpEnum'
import { ProjectItem, ProjectDetail } from './project'
// * 项目列表
export const projectListApi = async (data: object) => {
try {
const res = await http(RequestHttpEnum.GET)<ProjectItem[]>(`${ModuleTypeEnum.PROJECT}/list`, data)
return res
} catch {
httpErrorHandle()
}
}
// * 新增项目
export const createProjectApi = async (data: object) => {
try {
const res = await http(RequestHttpEnum.POST)<{
/**
* id
*/
id: number
}>(`${ModuleTypeEnum.PROJECT}/create`, data)
return res
} catch {
httpErrorHandle()
}
}
// * 获取项目
export const fetchProjectApi = async (data: object) => {
try {
const res = await http(RequestHttpEnum.GET)<ProjectDetail>(`${ModuleTypeEnum.PROJECT}/getData`, data)
return res
} catch {
httpErrorHandle()
}
}
// * 保存项目
export const saveProjectApi = async (data: object) => {
try {
const res = await http(RequestHttpEnum.POST)(
`${ModuleTypeEnum.PROJECT}/save/data`,
data,
ContentTypeEnum.FORM_URLENCODED
)
return res
} catch {
httpErrorHandle()
}
}
// * 修改项目基础信息
export const updateProjectApi = async (data: object) => {
try {
const res = await http(RequestHttpEnum.POST)(`${ModuleTypeEnum.PROJECT}/edit`, data)
return res
} catch {
httpErrorHandle()
}
}
// * 删除项目
export const deleteProjectApi = async (data: object) => {
try {
const res = await http(RequestHttpEnum.DELETE)(`${ModuleTypeEnum.PROJECT}/delete`, data)
return res
} catch {
httpErrorHandle()
}
}
// * 修改发布状态 [-1未发布,1发布]
export const changeProjectReleaseApi = async (data: object) => {
try {
const res = await http(RequestHttpEnum.PUT)(`${ModuleTypeEnum.PROJECT}/publish`, data)
return res
} catch {
httpErrorHandle()
}
}
// * 上传文件
export const uploadFile = async (data: object) => {
try {
const res = await http(RequestHttpEnum.POST)<{
/**
*
*/
fileName: string,
fileurl: string,
}>(`${ModuleTypeEnum.PROJECT}/upload`, data, ContentTypeEnum.FORM_DATA)
return res
} catch {
httpErrorHandle()
}
}

View File

@ -10,13 +10,17 @@ export const useSystemInit = async () => {
// 获取 OSS 信息的 url 地址,用来拼接展示图片的地址
const getOssUrl = async () => {
const res = await ossUrlApi({})
if (res && res.code === ResultEnum.SUCCESS) {
// const res = await ossUrlApi({})
// if (res && res.code === ResultEnum.SUCCESS) {
// systemStore.setItem(SystemStoreEnum.FETCH_INFO, {
// OSSUrl: res.data?.bucketURL
// })
// }
const url = window.location.origin
systemStore.setItem(SystemStoreEnum.FETCH_INFO, {
OSSUrl: res.data?.bucketURL
OSSUrl: url
})
}
}
// 执行
getOssUrl()

View File

@ -267,9 +267,9 @@ type ValueType = ItemType[]
const { value } = defineProps(['value']) as { value: ValueType }
const color = ref('#4dca59')
const getRotate = (horizontal, data) => {
const getRotate = (horizontal:string, data:number) => {
// 0
const pue = parseFloat(data) //
const pue = parseFloat(data.toString()) //
if (pue >= 0 && pue < 1.7) {
color.value = '#4dca59'
} else if (pue >= 1.7 && pue < 2.2) {

View File

@ -277,10 +277,10 @@ const customRequest = (options: UploadCustomRequestOptions) => {
type: file.file.type
})
let uploadParams = new FormData()
uploadParams.append('object', newNameFile)
uploadParams.append('files', newNameFile)
const uploadRes = await uploadFile(uploadParams)
if (uploadRes && uploadRes.code === ResultEnum.SUCCESS) {
if (uploadRes && uploadRes.errcode === '00000') {
if (uploadRes.data.fileurl) {
chartEditStore.setEditCanvasConfig(
EditCanvasConfigEnum.BACKGROUND_IMAGE,

View File

@ -251,11 +251,20 @@ export const useSync = () => {
chartEditStore.setEditCanvas(EditCanvasTypeEnum.SAVE_STATUS, SyncEnum.START)
try {
const res = await fetchProjectApi({ projectId: fetchRouteParamsLocation() })
if (res && res.code === ResultEnum.SUCCESS) {
console.log(res)
if (res) {
// type dataType = {
// id: string
// projectName: string,
// indexImage: string,
// remarks: string,
// state: number,
// content: string,
// }
if (res.data) {
updateStoreInfo(res.data)
updateStoreInfo(res.data as any)
// 更新全局数据
await updateComponent(JSONParse(res.data.content))
await updateComponent(JSONParse((res.data as any).content))
return
}else {
chartEditStore.setProjectInfo(ProjectInfoEnum.PROJECT_ID, fetchRouteParamsLocation())
@ -267,6 +276,7 @@ export const useSync = () => {
}
chartEditStore.setEditCanvas(EditCanvasTypeEnum.SAVE_STATUS, SyncEnum.FAILURE)
} catch (error) {
console.log(error)
chartEditStore.setEditCanvas(EditCanvasTypeEnum.SAVE_STATUS, SyncEnum.FAILURE)
httpErrorHandle()
}
@ -298,19 +308,19 @@ export const useSync = () => {
// 上传预览图
let uploadParams = new FormData()
uploadParams.append('object', base64toFile(canvasImage.toDataURL(), `${fetchRouteParamsLocation()}_index_preview.png`))
uploadParams.append('files', base64toFile(canvasImage.toDataURL(), `${fetchRouteParamsLocation()}_index_preview.png`))
const uploadRes = await uploadFile(uploadParams)
// 保存预览图
if(uploadRes && uploadRes.code === ResultEnum.SUCCESS) {
if (uploadRes.data.fileurl) {
if(uploadRes && uploadRes.data) {
if (uploadRes.data.length) {
await updateProjectApi({
id: fetchRouteParamsLocation(),
indexImage: `${uploadRes.data.fileurl}`
id: Number(fetchRouteParamsLocation()),
indexImage: `${uploadRes.data[0]}`
})
} else {
await updateProjectApi({
id: fetchRouteParamsLocation(),
indexImage: `${systemStore.getFetchInfo.OSSUrl}${uploadRes.data.fileName}`
id: Number(fetchRouteParamsLocation()),
indexImage: `${systemStore.getFetchInfo.OSSUrl}${uploadRes.data[0]}`
})
}
}
@ -320,12 +330,16 @@ export const useSync = () => {
}
// 保存数据
let params = new FormData()
params.append('projectId', projectId)
params.append('content', JSONStringify(chartEditStore.getStorageInfo() || {}))
// let params = new FormData()
// params.append('projectId', projectId)
// params.append('content', JSONStringify(chartEditStore.getStorageInfo() || {}))
const params = {
id: projectId,
content: JSONStringify(chartEditStore.getStorageInfo() || {})
}
const res= await saveProjectApi(params)
if (res && res.code === ResultEnum.SUCCESS) {
if (res && res.data) {
// 成功状态
setTimeout(() => {
chartEditStore.setEditCanvas(EditCanvasTypeEnum.SAVE_STATUS, SyncEnum.SUCCESS)

View File

@ -20,14 +20,14 @@ export const getSessionStorageInfo = async () => {
if (!storageList || storageList.findIndex(e => e.id === id.toString()) === -1) {
// 接口调用
const res = await fetchProjectApi({ projectId: id })
if (res && res.code === ResultEnum.SUCCESS) {
if (res) {
const { content, state } = res.data
if (state === -1) {
// 跳转未发布页
return { isRelease: false }
}
// if (state === -1) {
// // 跳转未发布页
// return { isRelease: false }
// }
console.log(content)
const parseData = { ...JSONParse(content), id }
const parseData = { ...JSONParse(content ? content : '{}'), id }
const { editCanvasConfig, requestGlobalConfig, componentList } = parseData
chartEditStore.editCanvasConfig = editCanvasConfig
chartEditStore.requestGlobalConfig = requestGlobalConfig

View File

@ -30,7 +30,7 @@ export const useDataListInit = () => {
if (res && res.data) {
const { count } = res as any // 这里的count与data平级不在Response结构中
paginat.count = count
list.value = res.data.map(e => {
list.value = res.data.map((e:any) => {
const { id, projectName, state, createTime, indexImage, createUserId } = e
return {
id: id,
@ -69,13 +69,11 @@ export const useDataListInit = () => {
onPositiveCallback: () =>
new Promise(res => {
res(
deleteProjectApi({
ids: cardData.id
})
deleteProjectApi([cardData.id])
)
}),
promiseResCallback: (res: any) => {
if (res.code === ResultEnum.SUCCESS) {
if (res.errcode === '00000') {
window['$message'].success(window['$t']('global.r_delete_success'))
fetchList()
return

View File

@ -95,7 +95,7 @@ const btnHandle = async (key: string) => {
//
indexImage: null,
})
if(res && res.code === ResultEnum.SUCCESS) {
if(res && res.data) {
window['$message'].success(window['$t']('project.create_success'))
const { id } = res.data

View File

@ -47,6 +47,14 @@ export default ({ mode }) => defineConfig({
port: 3000,
proxy: {
[axiosPre]: {
// @ts-ignore
target: loadEnv(mode, process.cwd()).VITE_DEV_PATH,
changeOrigin: true,
rewrite: (path) => path.replace(new RegExp(`^${axiosPre}`), ''),
ws: true,
secure: true,
},
'/data/file': {
// @ts-ignore
target: loadEnv(mode, process.cwd()).VITE_DEV_PATH,
changeOrigin: true,