feat: add common fetch type

This commit is contained in:
IchliebedichZhu 2024-02-29 13:10:32 +00:00
parent 420f29a272
commit 9dad9fa28c
8 changed files with 82 additions and 17 deletions

View File

@ -11,10 +11,41 @@ import _config from '@/config'
// const screenshot_url = window.location.protocol + '//' + window.location.host + '/draw'
export const download = (params: Type.Object = {}) => `${_config.SCREEN_URL}/api/screenshots?id=${params.id}&width=${params.width}&height=${params.height}`
type IGetTempListParam = {
search: string
page: number
pageSize: number
cate:number
}
type IGetTempListData = {
cover: string
height: number
id: number
state: number
title: string
width: number
}
type IGetTempListResult = TCommResResult<IGetTempListData>
// 获取模板列表
export const getTempList = (params: Type.Object = {}) => fetch('design/list', params, 'get')
export const getTempList = (params: IGetTempListParam) => fetch<IGetTempListResult>('design/list', params, 'get')
export const getTempDetail = (params: Type.Object = {}) => fetch('design/temp', params, 'get')
export const getCategories = (params: Type.Object = {}) => fetch('design/cate', params, 'get')
type TGetCategoriesParams = {
type?: number
}
export type TGetCategoriesData = {
id: number
name: string
pid: number
type: number
}
type TgetCategoriesResult = TCommResResult<TGetCategoriesData>
export const getCategories = (params: TGetCategoriesParams) => fetch<TgetCategoriesResult[]>('design/cate', params, 'get')
// 保存模板
export const saveTemp = (params: Type.Object = {}) => fetch('design/edit', params, 'post')
// export const delTemp = (params: Type.Object = {}) => fetch('/api/template/temp_del', params)

View File

@ -10,8 +10,36 @@ import fetch from '@/utils/axios'
// 获取素材分类:
export const getKinds = (params: Type.Object = {}) => fetch('design/cate', params)
type TGetListParam = {
cate: number
pageSize: number
}
export type TGetListData = {
category: number
created_time: string
height: number
id: number
model: string
original: string
state: number
thumb: string
title: string
type: string
updated_time: string
url: string
width: number
}
type TGetListResult = TCommResResult<{
list: TGetListData
total: number
}>
// 获取素材列表:
export const getList = (params: Type.Object = {}) => fetch('design/material', params)
export const getList = (params: TGetListParam) => fetch<TGetListResult>('design/material', params)
// 获取字体
export const getFonts = (params: Type.Object = {}) => fetch('design/fonts', params)

View File

@ -2,7 +2,7 @@
* @Author: ShawnPhang
* @Date: 2022-03-03 14:13:16
* @Description:
* @LastEditors: Jeremy Yu <https://github.com/JeremyYu-cn>
* @LastEditors: ShawnPhang <https://m.palxp.cn>, Jeremy Yu <https://github.com/JeremyYu-cn>
* @LastEditTime: 2024-02-26 17:54:00
*/
import { createApp } from 'vue'

8
src/types/global.d.ts vendored Normal file
View File

@ -0,0 +1,8 @@
/** 公共API返回结果 */
type TCommResResult<T> = {
code: number
msg: string
result: T
}

View File

@ -2,7 +2,7 @@
* @Author: ShawnPhang
* @Date: 2021-07-13 02:48:38
* @Description:
* @LastEditors: Jeremy Yu <https://github.com/JeremyYu-cn>
* @LastEditors: ShawnPhang <https://m.palxp.cn>, Jeremy Yu <https://github.com/JeremyYu-cn>
* @LastEditTime: 2024-02-26 17:54:00
*/
import axios, { AxiosRequestConfig, AxiosResponse, AxiosStatic } from 'axios'
@ -79,13 +79,13 @@ type TFetchMethod = keyof Pick<
>
// export default axios;
const fetch = (
const fetch = <T = any> (
url: string,
params: TFetchRequestConfigParams,
type: TFetchMethod = 'get',
exheaders: Record<string, any> = {},
extra: Record<string, any> = {}
) => {
): Promise<AxiosResponse<T>> => {
if (params?._noLoading) {
delete params._noLoading
} else {
@ -106,7 +106,7 @@ const fetch = (
return axios[type](url, params, {
headers: Object.assign(headerObject, exheaders),
...extra,
})
}) as Promise<AxiosResponse<T>>
}
}

View File

@ -2,7 +2,7 @@
* @Author: ShawnPhang
* @Date: 2021-07-13 02:48:38
* @Description:
* @LastEditors: ShawnPhang
* @LastEditors: ShawnPhang <https://m.palxp.cn>, Jeremy Yu <https://github.com/JeremyYu-cn>
* @LastEditTime: 2022-03-07 20:25:54
*/
// import store from '../store'

View File

@ -40,12 +40,10 @@ type TComObj = Record<string,any>
// }
// }
// 判断是否在数组中并返回下标
export const isInArray = (arr: Type.Object[], value: any) => {
if (arr.indexOf && typeof arr.indexOf === 'function') {
const index = arr.indexOf(value)
if (index >= 0) {
return index
}
export const isInArray = (arr: (string | number)[], value: (string | number)) => {
const index = arr.indexOf(value)
if (index >= 0) {
return index
}
return false
}

View File

@ -2,8 +2,8 @@
* @Author: ShawnPhang
* @Date: 2023-08-23 17:37:16
* @Description:
* @LastEditors: ShawnPhang <https://m.palxp.cn>
* @LastEditTime: 2023-10-14 18:31:29
* @LastEditors: ShawnPhang <https://m.palxp.cn>, Jeremy Yu <https://github.com/JeremyYu-cn>
* @LastEditTime: 2024-02-27 10:32:00
*/
/**
* ttf/otf这种原始字体支持提取false