type: 定义全局返回值类型

This commit is contained in:
奔跑的面条 2022-06-01 22:41:11 +08:00
parent 93727a0ac7
commit fb0ff50837
12 changed files with 25 additions and 24 deletions

View File

@ -8,12 +8,6 @@ import { redirectErrorPage, getLocalStorage, routerTurnByName, httpErrorHandle }
import { fetchAllowList } from './axios.config' import { fetchAllowList } from './axios.config'
import includes from 'lodash/includes' import includes from 'lodash/includes'
interface MyResponseType {
code: number;
msg: string;
data: any;
}
const axiosInstance = axios.create({ const axiosInstance = axios.create({
baseURL: `${import.meta.env.PROD ? import.meta.env.VITE_PRO_PATH : ''}${axiosPre}`, baseURL: `${import.meta.env.PROD ? import.meta.env.VITE_PRO_PATH : ''}${axiosPre}`,
timeout: ResultEnum.TIMEOUT, timeout: ResultEnum.TIMEOUT,

View File

@ -43,7 +43,7 @@ export const useChartDataFetch = (
if (!completePath) return if (!completePath) return
fetchInterval = setInterval(async () => { 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) { if (res.data) {
// 是否是 Echarts 组件 // 是否是 Echarts 组件
const isECharts = const isECharts =

View File

@ -10,7 +10,7 @@ export const useSystemInit = async () => {
// 获取 OSS 信息 // 获取 OSS 信息
const getOssUrl = async () => { const getOssUrl = async () => {
const res: any = await ossUrlApi({}) const res = await ossUrlApi({}) as unknown as MyResponseType
if (res.code === ResultEnum.SUCCESS) { if (res.code === ResultEnum.SUCCESS) {
systemStore.setItem(SystemStoreEnum.FETCH_INFO, { systemStore.setItem(SystemStoreEnum.FETCH_INFO, {
OSSUrl: res.data?.bucketURL OSSUrl: res.data?.bucketURL

View File

@ -106,7 +106,7 @@ export const reloadRoutePage = () => {
*/ */
export const logout = async () => { export const logout = async () => {
try { try {
const res:any = await logoutApi() const res = await logoutApi() as unknown as MyResponseType
if(res.code === ResultEnum.SUCCESS) { if(res.code === ResultEnum.SUCCESS) {
window['$message'].success(window['$t']('global.logout_success')) window['$message'].success(window['$t']('global.logout_success'))
clearCookie(RequestHttpHeaderEnum.COOKIE) clearCookie(RequestHttpHeaderEnum.COOKIE)

View File

@ -288,7 +288,7 @@ const customRequest = (options: UploadCustomRequestOptions) => {
) )
let uploadParams = new FormData() let uploadParams = new FormData()
uploadParams.append('object', newNameFile) 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) { if(uploadRes.code === ResultEnum.SUCCESS) {
chartEditStore.setEditCanvasConfig( chartEditStore.setEditCanvasConfig(

View File

@ -61,10 +61,10 @@ const handleFocus = () => {
const handleBlur = async () => { const handleBlur = async () => {
focus.value = false focus.value = false
chartEditStore.setProjectInfo(ProjectInfoEnum.PROJECT_NAME, title.value || '') chartEditStore.setProjectInfo(ProjectInfoEnum.PROJECT_NAME, title.value || '')
const res:any = await updateProjectApi({ const res = await updateProjectApi({
id: fetchRouteParamsLocation(), id: fetchRouteParamsLocation(),
projectName: title.value, projectName: title.value,
}) }) as unknown as MyResponseType
if(res.code === ResultEnum.SUCCESS) { if(res.code === ResultEnum.SUCCESS) {
dataSyncUpdate() dataSyncUpdate()
} else { } else {

View File

@ -95,7 +95,7 @@ export const useSync = () => {
const dataSyncFetch = async () => { const dataSyncFetch = async () => {
chartEditStore.setEditCanvas(EditCanvasTypeEnum.SAVE_STATUS, SyncEnum.START) chartEditStore.setEditCanvas(EditCanvasTypeEnum.SAVE_STATUS, SyncEnum.START)
try { 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.code === ResultEnum.SUCCESS) {
if (res.data) { if (res.data) {
updateStoreInfo(res.data) updateStoreInfo(res.data)
@ -135,7 +135,7 @@ 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:any = await uploadFile(systemStore.getFetchInfo.OSSUrl, uploadParams) const uploadRes = await uploadFile(systemStore.getFetchInfo.OSSUrl, uploadParams) as unknown as MyResponseType
// 保存预览图 // 保存预览图
if(uploadRes.code === ResultEnum.SUCCESS) { if(uploadRes.code === ResultEnum.SUCCESS) {
await updateProjectApi({ await updateProjectApi({
@ -148,7 +148,7 @@ export const useSync = () => {
let params = new FormData() let params = new FormData()
params.append('projectId', fetchRouteParamsLocation()) params.append('projectId', fetchRouteParamsLocation())
params.append('content', JSON.stringify(chartEditStore.getStorageInfo || {})) 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) { if (res.code === ResultEnum.SUCCESS) {
// 成功状态 // 成功状态

View File

@ -204,10 +204,10 @@ const handleSubmit = async (e: Event) => {
const { username, password } = formInline const { username, password } = formInline
loading.value = true loading.value = true
// //
const res:any = await loginApi({ const res = await loginApi({
username, username,
password password
}) }) as unknown as MyResponseType
if(res.data) { if(res.data) {
const { tokenValue } = res.data.token const { tokenValue } = res.data.token
const { nickname, username, id } = res.data.userinfo const { nickname, username, id } = res.data.userinfo

View File

@ -18,7 +18,7 @@ export const getSessionStorageInfo = async () => {
// 是否本地预览 // 是否本地预览
if (!storageList) { if (!storageList) {
// 接口调用 // 接口调用
const res: any = await fetchProjectApi({ projectId: id }) const res = await fetchProjectApi({ projectId: id }) as unknown as MyResponseType
if (res.code === ResultEnum.SUCCESS) { if (res.code === ResultEnum.SUCCESS) {
const { content, state } = res.data const { content, state } = res.data
if (state === -1) { if (state === -1) {

View File

@ -24,10 +24,10 @@ export const useDataListInit = () => {
// 数据请求 // 数据请求
const fetchList = async () => { const fetchList = async () => {
loading.value = true loading.value = true
const res: any = await projectListApi({ const res = await projectListApi({
page: paginat.page, page: paginat.page,
limit: paginat.limit limit: paginat.limit
}) }) as unknown as MyResponseType
if (res.data) { if (res.data) {
const { count } = res const { count } = res
paginat.count = count paginat.count = count
@ -86,11 +86,11 @@ export const useDataListInit = () => {
// 发布处理 // 发布处理
const releaseHandle = async (cardData: Chartype, index: number) => { const releaseHandle = async (cardData: Chartype, index: number) => {
const { id, release } = cardData const { id, release } = cardData
const res: any = await changeProjectReleaseApi({ const res = await changeProjectReleaseApi({
id: id, id: id,
// [-1未发布, 1发布] // [-1未发布, 1发布]
state: !release ? 1 : -1 state: !release ? 1 : -1
}) }) as unknown as MyResponseType
if (res.code === ResultEnum.SUCCESS) { if (res.code === ResultEnum.SUCCESS) {
list.value = [] list.value = []
fetchList() fetchList()

View File

@ -89,14 +89,14 @@ const btnHandle = async (key: string) => {
case ChartEnum.CHART_HOME_NAME: case ChartEnum.CHART_HOME_NAME:
try { try {
// //
const res:any = await createProjectApi({ const res = await createProjectApi({
// //
projectName: getUUID(), projectName: getUUID(),
// remarks // remarks
remarks: null, remarks: null,
// //
indexImage: null, indexImage: null,
}) }) as unknown as MyResponseType
if(res.code === ResultEnum.SUCCESS) { if(res.code === ResultEnum.SUCCESS) {
window['$message'].success(window['$t']('project.create_success')) window['$message'].success(window['$t']('project.create_success'))

7
types/global.d.ts vendored
View File

@ -7,4 +7,11 @@ interface Window {
$vue: any $vue: any
} }
declare interface MyResponseType {
code: number;
msg: string;
data: any;
}
declare type Recordable<T = any> = Record<string, T> declare type Recordable<T = any> = Record<string, T>