diff --git a/src/api/home.ts b/src/api/home.ts index 1b0aa9d..3df9c66 100644 --- a/src/api/home.ts +++ b/src/api/home.ts @@ -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 + // 获取模板列表 -export const getTempList = (params: Type.Object = {}) => fetch('design/list', params, 'get') +export const getTempList = (params: IGetTempListParam) => fetch('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 + +export const getCategories = (params: TGetCategoriesParams) => fetch('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) diff --git a/src/api/material.ts b/src/api/material.ts index 21a0e8c..ec5fdb3 100644 --- a/src/api/material.ts +++ b/src/api/material.ts @@ -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('design/material', params) // 获取字体 export const getFonts = (params: Type.Object = {}) => fetch('design/fonts', params) diff --git a/src/main.ts b/src/main.ts index 5ef707c..d960b07 100644 --- a/src/main.ts +++ b/src/main.ts @@ -2,7 +2,7 @@ * @Author: ShawnPhang * @Date: 2022-03-03 14:13:16 * @Description: - * @LastEditors: Jeremy Yu + * @LastEditors: ShawnPhang , Jeremy Yu * @LastEditTime: 2024-02-26 17:54:00 */ import { createApp } from 'vue' diff --git a/src/types/global.d.ts b/src/types/global.d.ts new file mode 100644 index 0000000..789280e --- /dev/null +++ b/src/types/global.d.ts @@ -0,0 +1,8 @@ + +/** 公共API返回结果 */ +type TCommResResult = { + code: number + msg: string + result: T +} + diff --git a/src/utils/axios.ts b/src/utils/axios.ts index 6f2d8a7..68a49af 100644 --- a/src/utils/axios.ts +++ b/src/utils/axios.ts @@ -2,7 +2,7 @@ * @Author: ShawnPhang * @Date: 2021-07-13 02:48:38 * @Description: 本地测试项目请勿修改此文件 - * @LastEditors: Jeremy Yu + * @LastEditors: ShawnPhang , Jeremy Yu * @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 = ( url: string, params: TFetchRequestConfigParams, type: TFetchMethod = 'get', exheaders: Record = {}, extra: Record = {} -) => { +): Promise> => { 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> } } diff --git a/src/utils/index.ts b/src/utils/index.ts index c274639..146ddb4 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -2,7 +2,7 @@ * @Author: ShawnPhang * @Date: 2021-07-13 02:48:38 * @Description: - * @LastEditors: ShawnPhang + * @LastEditors: ShawnPhang , Jeremy Yu * @LastEditTime: 2022-03-07 20:25:54 */ // import store from '../store' diff --git a/src/utils/utils.ts b/src/utils/utils.ts index d2de8de..30b9d07 100644 --- a/src/utils/utils.ts +++ b/src/utils/utils.ts @@ -40,12 +40,10 @@ type TComObj = Record // } // } // 判断是否在数组中并返回下标 -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 } diff --git a/src/utils/widgets/loadFontRule.ts b/src/utils/widgets/loadFontRule.ts index 6556a72..a35d0bb 100644 --- a/src/utils/widgets/loadFontRule.ts +++ b/src/utils/widgets/loadFontRule.ts @@ -2,8 +2,8 @@ * @Author: ShawnPhang * @Date: 2023-08-23 17:37:16 * @Description: 提取字体子集 - * @LastEditors: ShawnPhang - * @LastEditTime: 2023-10-14 18:31:29 + * @LastEditors: ShawnPhang , Jeremy Yu + * @LastEditTime: 2024-02-27 10:32:00 */ /** * 只有ttf/otf这种原始字体支持提取,如果服务端不支持该功能请设置false,以保证页面能加载字体。