mirror of
https://github.com/palxiao/poster-design.git
synced 2025-07-28 04:10:31 +08:00
feat: add common fetch type
This commit is contained in:
parent
420f29a272
commit
9dad9fa28c
@ -11,10 +11,41 @@ import _config from '@/config'
|
|||||||
// const screenshot_url = window.location.protocol + '//' + window.location.host + '/draw'
|
// 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}`
|
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 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 saveTemp = (params: Type.Object = {}) => fetch('design/edit', params, 'post')
|
||||||
// export const delTemp = (params: Type.Object = {}) => fetch('/api/template/temp_del', params)
|
// export const delTemp = (params: Type.Object = {}) => fetch('/api/template/temp_del', params)
|
||||||
|
@ -10,8 +10,36 @@ import fetch from '@/utils/axios'
|
|||||||
// 获取素材分类:
|
// 获取素材分类:
|
||||||
export const getKinds = (params: Type.Object = {}) => fetch('design/cate', params)
|
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)
|
export const getFonts = (params: Type.Object = {}) => fetch('design/fonts', params)
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
* @Author: ShawnPhang
|
* @Author: ShawnPhang
|
||||||
* @Date: 2022-03-03 14:13:16
|
* @Date: 2022-03-03 14:13:16
|
||||||
* @Description:
|
* @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
|
* @LastEditTime: 2024-02-26 17:54:00
|
||||||
*/
|
*/
|
||||||
import { createApp } from 'vue'
|
import { createApp } from 'vue'
|
||||||
|
8
src/types/global.d.ts
vendored
Normal file
8
src/types/global.d.ts
vendored
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
|
||||||
|
/** 公共API返回结果 */
|
||||||
|
type TCommResResult<T> = {
|
||||||
|
code: number
|
||||||
|
msg: string
|
||||||
|
result: T
|
||||||
|
}
|
||||||
|
|
@ -2,7 +2,7 @@
|
|||||||
* @Author: ShawnPhang
|
* @Author: ShawnPhang
|
||||||
* @Date: 2021-07-13 02:48:38
|
* @Date: 2021-07-13 02:48:38
|
||||||
* @Description: 本地测试项目请勿修改此文件
|
* @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
|
* @LastEditTime: 2024-02-26 17:54:00
|
||||||
*/
|
*/
|
||||||
import axios, { AxiosRequestConfig, AxiosResponse, AxiosStatic } from 'axios'
|
import axios, { AxiosRequestConfig, AxiosResponse, AxiosStatic } from 'axios'
|
||||||
@ -79,13 +79,13 @@ type TFetchMethod = keyof Pick<
|
|||||||
>
|
>
|
||||||
|
|
||||||
// export default axios;
|
// export default axios;
|
||||||
const fetch = (
|
const fetch = <T = any> (
|
||||||
url: string,
|
url: string,
|
||||||
params: TFetchRequestConfigParams,
|
params: TFetchRequestConfigParams,
|
||||||
type: TFetchMethod = 'get',
|
type: TFetchMethod = 'get',
|
||||||
exheaders: Record<string, any> = {},
|
exheaders: Record<string, any> = {},
|
||||||
extra: Record<string, any> = {}
|
extra: Record<string, any> = {}
|
||||||
) => {
|
): Promise<AxiosResponse<T>> => {
|
||||||
if (params?._noLoading) {
|
if (params?._noLoading) {
|
||||||
delete params._noLoading
|
delete params._noLoading
|
||||||
} else {
|
} else {
|
||||||
@ -106,7 +106,7 @@ const fetch = (
|
|||||||
return axios[type](url, params, {
|
return axios[type](url, params, {
|
||||||
headers: Object.assign(headerObject, exheaders),
|
headers: Object.assign(headerObject, exheaders),
|
||||||
...extra,
|
...extra,
|
||||||
})
|
}) as Promise<AxiosResponse<T>>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
* @Author: ShawnPhang
|
* @Author: ShawnPhang
|
||||||
* @Date: 2021-07-13 02:48:38
|
* @Date: 2021-07-13 02:48:38
|
||||||
* @Description:
|
* @Description:
|
||||||
* @LastEditors: ShawnPhang
|
* @LastEditors: ShawnPhang <https://m.palxp.cn>, Jeremy Yu <https://github.com/JeremyYu-cn>
|
||||||
* @LastEditTime: 2022-03-07 20:25:54
|
* @LastEditTime: 2022-03-07 20:25:54
|
||||||
*/
|
*/
|
||||||
// import store from '../store'
|
// import store from '../store'
|
||||||
|
@ -40,12 +40,10 @@ type TComObj = Record<string,any>
|
|||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
// 判断是否在数组中并返回下标
|
// 判断是否在数组中并返回下标
|
||||||
export const isInArray = (arr: Type.Object[], value: any) => {
|
export const isInArray = (arr: (string | number)[], value: (string | number)) => {
|
||||||
if (arr.indexOf && typeof arr.indexOf === 'function') {
|
const index = arr.indexOf(value)
|
||||||
const index = arr.indexOf(value)
|
if (index >= 0) {
|
||||||
if (index >= 0) {
|
return index
|
||||||
return index
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
@ -2,8 +2,8 @@
|
|||||||
* @Author: ShawnPhang
|
* @Author: ShawnPhang
|
||||||
* @Date: 2023-08-23 17:37:16
|
* @Date: 2023-08-23 17:37:16
|
||||||
* @Description: 提取字体子集
|
* @Description: 提取字体子集
|
||||||
* @LastEditors: ShawnPhang <https://m.palxp.cn>
|
* @LastEditors: ShawnPhang <https://m.palxp.cn>, Jeremy Yu <https://github.com/JeremyYu-cn>
|
||||||
* @LastEditTime: 2023-10-14 18:31:29
|
* @LastEditTime: 2024-02-27 10:32:00
|
||||||
*/
|
*/
|
||||||
/**
|
/**
|
||||||
* 只有ttf/otf这种原始字体支持提取,如果服务端不支持该功能请设置false,以保证页面能加载字体。
|
* 只有ttf/otf这种原始字体支持提取,如果服务端不支持该功能请设置false,以保证页面能加载字体。
|
||||||
|
Loading…
x
Reference in New Issue
Block a user