diff --git a/src/api/github.ts b/src/api/github.ts index 92160e6..5bcedd3 100644 --- a/src/api/github.ts +++ b/src/api/github.ts @@ -19,11 +19,12 @@ function getBase64(file: File) { }) } -const putPic = async (file: File) => { +const putPic = async (file: File | string) => { const repo = 'shawnphang/files' const d = new Date() const content = typeof file === 'string' ? file : await getBase64(file) - const path = `${d.getFullYear()}/${d.getMonth()}/${d.getTime()}${file.name?.split('.').pop() || '.png'}` + const extra = typeof file === 'string' ? '.png' : file.name?.split('.').pop() + const path = `${d.getFullYear()}/${d.getMonth()}/${d.getTime()}${extra}` const imageUrl = 'https://api.github.com/repos/' + repo + '/contents/' + path const body = { branch: 'main', message: 'upload', content, path } const res = await fetch(imageUrl, body, 'put', { diff --git a/src/api/home.ts b/src/api/home.ts index 8dd3639..dcdf957 100644 --- a/src/api/home.ts +++ b/src/api/home.ts @@ -119,14 +119,30 @@ type TRemoveComp = { export const removeComp = (params: TRemoveComp) => fetch('design/del', params, 'post') // export const getCompDetail = (params: Type.Object = {}) => fetch('/api/template/temp_info', params, 'get') +type TSaveWorksParams = { + title: string + temp_id?: string + width: number + height: number + data: string + cover?: string + id?: string | number +} + +export type TSaveWorksResult = { + id: number | string, + stat?: number, + msg: string +} + // 保存作品 -export const saveWorks = (params: Type.Object = {}) => fetch('design/save', params, 'post') +export const saveWorks = (params: TSaveWorksParams) => fetch('design/save', params, 'post') // 保存个人模板 export const saveMyTemp = (params: Type.Object = {}) => fetch('design/user/temp', params, 'post') // 获取作品 -export const getWorks = (params: Type.Object = {}) => fetch('design/poster', params, 'get') +export const getWorks = (params: TGetTempDetail) => fetch('design/poster', params, 'get') type TGetMyDesignParams = { page: number diff --git a/src/views/components/HeaderOptions.vue b/src/views/components/HeaderOptions.vue index 8c4076e..7f7d5ea 100644 --- a/src/views/components/HeaderOptions.vue +++ b/src/views/components/HeaderOptions.vue @@ -82,7 +82,7 @@ async function save(hasCover: boolean = false) { const { id, tempid } = route.query const cover = hasCover ? await draw() : undefined const widgets = dWidgets.value // reviseData() - const { id: newId, stat, msg } = await api.home.saveWorks({ cover, id, title: state.title || '未命名设计', data: JSON.stringify({ page: dPage.value, widgets }), temp_id: tempid, width: dPage.value.width, height: dPage.value.height }) + const { id: newId, stat, msg } = await api.home.saveWorks({ cover, id: (id as string), title: state.title || '未命名设计', data: JSON.stringify({ page: dPage.value, widgets }), temp_id: (tempid as string), width: dPage.value.width, height: dPage.value.height }) stat !== 0 ? useNotification('保存成功', '可在"我的作品"中查看') : useNotification('保存失败', msg, { type: 'error' }) !id && router.push({ path: '/home', query: { id: newId }, replace: true }) store.commit('setShowMoveable', true) @@ -199,7 +199,7 @@ async function load(id: number, tempId: number, type: number, cb: () => void) { } function draw() { - return new Promise((resolve) => { + return new Promise((resolve) => { if (!canvasImage.value) resolve('') else { canvasImage.value.createCover(({ key }: {key: string}) => { diff --git a/src/views/components/UploadTemplate.vue b/src/views/components/UploadTemplate.vue index 3fb2562..202c61d 100644 --- a/src/views/components/UploadTemplate.vue +++ b/src/views/components/UploadTemplate.vue @@ -66,7 +66,7 @@ useFontStore.init() // 初始化加载字体 // 生成封面 const draw = () => { - return new Promise((resolve) => { + return new Promise((resolve) => { if (!canvasImage.value) { resolve('') } else {