mirror of
https://gitee.com/dromara/go-view.git
synced 2025-04-06 03:58:04 +08:00
type: 定义全局返回值类型
This commit is contained in:
parent
93727a0ac7
commit
fb0ff50837
@ -8,12 +8,6 @@ import { redirectErrorPage, getLocalStorage, routerTurnByName, httpErrorHandle }
|
||||
import { fetchAllowList } from './axios.config'
|
||||
import includes from 'lodash/includes'
|
||||
|
||||
interface MyResponseType {
|
||||
code: number;
|
||||
msg: string;
|
||||
data: any;
|
||||
}
|
||||
|
||||
const axiosInstance = axios.create({
|
||||
baseURL: `${import.meta.env.PROD ? import.meta.env.VITE_PRO_PATH : ''}${axiosPre}`,
|
||||
timeout: ResultEnum.TIMEOUT,
|
||||
|
@ -43,7 +43,7 @@ export const useChartDataFetch = (
|
||||
if (!completePath) return
|
||||
|
||||
fetchInterval = setInterval(async () => {
|
||||
const res:any = await http(requestHttpType.value)(completePath || '', {})
|
||||
const res = await http(requestHttpType.value)(completePath || '', {}) as unknown as MyResponseType
|
||||
if (res.data) {
|
||||
// 是否是 Echarts 组件
|
||||
const isECharts =
|
||||
|
@ -10,7 +10,7 @@ export const useSystemInit = async () => {
|
||||
|
||||
// 获取 OSS 信息
|
||||
const getOssUrl = async () => {
|
||||
const res: any = await ossUrlApi({})
|
||||
const res = await ossUrlApi({}) as unknown as MyResponseType
|
||||
if (res.code === ResultEnum.SUCCESS) {
|
||||
systemStore.setItem(SystemStoreEnum.FETCH_INFO, {
|
||||
OSSUrl: res.data?.bucketURL
|
||||
|
@ -106,7 +106,7 @@ export const reloadRoutePage = () => {
|
||||
*/
|
||||
export const logout = async () => {
|
||||
try {
|
||||
const res:any = await logoutApi()
|
||||
const res = await logoutApi() as unknown as MyResponseType
|
||||
if(res.code === ResultEnum.SUCCESS) {
|
||||
window['$message'].success(window['$t']('global.logout_success'))
|
||||
clearCookie(RequestHttpHeaderEnum.COOKIE)
|
||||
|
@ -288,7 +288,7 @@ const customRequest = (options: UploadCustomRequestOptions) => {
|
||||
)
|
||||
let uploadParams = new FormData()
|
||||
uploadParams.append('object', newNameFile)
|
||||
const uploadRes:any = await uploadFile(systemStore.getFetchInfo.OSSUrl ,uploadParams)
|
||||
const uploadRes = await uploadFile(systemStore.getFetchInfo.OSSUrl ,uploadParams) as unknown as MyResponseType
|
||||
|
||||
if(uploadRes.code === ResultEnum.SUCCESS) {
|
||||
chartEditStore.setEditCanvasConfig(
|
||||
|
@ -61,10 +61,10 @@ const handleFocus = () => {
|
||||
const handleBlur = async () => {
|
||||
focus.value = false
|
||||
chartEditStore.setProjectInfo(ProjectInfoEnum.PROJECT_NAME, title.value || '')
|
||||
const res:any = await updateProjectApi({
|
||||
const res = await updateProjectApi({
|
||||
id: fetchRouteParamsLocation(),
|
||||
projectName: title.value,
|
||||
})
|
||||
}) as unknown as MyResponseType
|
||||
if(res.code === ResultEnum.SUCCESS) {
|
||||
dataSyncUpdate()
|
||||
} else {
|
||||
|
@ -95,7 +95,7 @@ export const useSync = () => {
|
||||
const dataSyncFetch = async () => {
|
||||
chartEditStore.setEditCanvas(EditCanvasTypeEnum.SAVE_STATUS, SyncEnum.START)
|
||||
try {
|
||||
const res: any = await fetchProjectApi({ projectId: fetchRouteParamsLocation() })
|
||||
const res = await fetchProjectApi({ projectId: fetchRouteParamsLocation() }) as unknown as MyResponseType
|
||||
if (res.code === ResultEnum.SUCCESS) {
|
||||
if (res.data) {
|
||||
updateStoreInfo(res.data)
|
||||
@ -135,7 +135,7 @@ export const useSync = () => {
|
||||
// 上传预览图
|
||||
let uploadParams = new FormData()
|
||||
uploadParams.append('object', base64toFile(canvasImage.toDataURL(), `${fetchRouteParamsLocation()}_index_preview.png`))
|
||||
const uploadRes:any = await uploadFile(systemStore.getFetchInfo.OSSUrl, uploadParams)
|
||||
const uploadRes = await uploadFile(systemStore.getFetchInfo.OSSUrl, uploadParams) as unknown as MyResponseType
|
||||
// 保存预览图
|
||||
if(uploadRes.code === ResultEnum.SUCCESS) {
|
||||
await updateProjectApi({
|
||||
@ -148,7 +148,7 @@ export const useSync = () => {
|
||||
let params = new FormData()
|
||||
params.append('projectId', fetchRouteParamsLocation())
|
||||
params.append('content', JSON.stringify(chartEditStore.getStorageInfo || {}))
|
||||
const res: any = await saveProjectApi(params)
|
||||
const res= await saveProjectApi(params) as unknown as MyResponseType
|
||||
|
||||
if (res.code === ResultEnum.SUCCESS) {
|
||||
// 成功状态
|
||||
|
@ -204,10 +204,10 @@ const handleSubmit = async (e: Event) => {
|
||||
const { username, password } = formInline
|
||||
loading.value = true
|
||||
// 提交请求
|
||||
const res:any = await loginApi({
|
||||
const res = await loginApi({
|
||||
username,
|
||||
password
|
||||
})
|
||||
}) as unknown as MyResponseType
|
||||
if(res.data) {
|
||||
const { tokenValue } = res.data.token
|
||||
const { nickname, username, id } = res.data.userinfo
|
||||
|
@ -18,7 +18,7 @@ export const getSessionStorageInfo = async () => {
|
||||
// 是否本地预览
|
||||
if (!storageList) {
|
||||
// 接口调用
|
||||
const res: any = await fetchProjectApi({ projectId: id })
|
||||
const res = await fetchProjectApi({ projectId: id }) as unknown as MyResponseType
|
||||
if (res.code === ResultEnum.SUCCESS) {
|
||||
const { content, state } = res.data
|
||||
if (state === -1) {
|
||||
|
@ -24,10 +24,10 @@ export const useDataListInit = () => {
|
||||
// 数据请求
|
||||
const fetchList = async () => {
|
||||
loading.value = true
|
||||
const res: any = await projectListApi({
|
||||
const res = await projectListApi({
|
||||
page: paginat.page,
|
||||
limit: paginat.limit
|
||||
})
|
||||
}) as unknown as MyResponseType
|
||||
if (res.data) {
|
||||
const { count } = res
|
||||
paginat.count = count
|
||||
@ -86,11 +86,11 @@ export const useDataListInit = () => {
|
||||
// 发布处理
|
||||
const releaseHandle = async (cardData: Chartype, index: number) => {
|
||||
const { id, release } = cardData
|
||||
const res: any = await changeProjectReleaseApi({
|
||||
const res = await changeProjectReleaseApi({
|
||||
id: id,
|
||||
// [-1未发布, 1发布]
|
||||
state: !release ? 1 : -1
|
||||
})
|
||||
}) as unknown as MyResponseType
|
||||
if (res.code === ResultEnum.SUCCESS) {
|
||||
list.value = []
|
||||
fetchList()
|
||||
|
@ -89,14 +89,14 @@ const btnHandle = async (key: string) => {
|
||||
case ChartEnum.CHART_HOME_NAME:
|
||||
try {
|
||||
// 新增项目
|
||||
const res:any = await createProjectApi({
|
||||
const res = await createProjectApi({
|
||||
// 项目名称
|
||||
projectName: getUUID(),
|
||||
// remarks
|
||||
remarks: null,
|
||||
// 图片地址
|
||||
indexImage: null,
|
||||
})
|
||||
}) as unknown as MyResponseType
|
||||
if(res.code === ResultEnum.SUCCESS) {
|
||||
window['$message'].success(window['$t']('project.create_success'))
|
||||
|
||||
|
7
types/global.d.ts
vendored
7
types/global.d.ts
vendored
@ -7,4 +7,11 @@ interface Window {
|
||||
$vue: any
|
||||
}
|
||||
|
||||
|
||||
declare interface MyResponseType {
|
||||
code: number;
|
||||
msg: string;
|
||||
data: any;
|
||||
}
|
||||
|
||||
declare type Recordable<T = any> = Record<string, T>
|
Loading…
x
Reference in New Issue
Block a user