Merge pull request #87 from JeremyYu-cn/feat-upgrade-vue3

feat: add api types
This commit is contained in:
Jeremy Yu 2024-03-14 14:22:18 +00:00 committed by GitHub
commit 0739965150
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 24 additions and 7 deletions

View File

@ -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', {

View File

@ -119,14 +119,30 @@ type TRemoveComp = {
export const removeComp = (params: TRemoveComp) => fetch<void>('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<TSaveWorksResult>('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<TTempDetail>('design/poster', params, 'get')
type TGetMyDesignParams = {
page: number

View File

@ -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<string>((resolve) => {
if (!canvasImage.value) resolve('')
else {
canvasImage.value.createCover(({ key }: {key: string}) => {

View File

@ -66,7 +66,7 @@ useFontStore.init() // 初始化加载字体
//
const draw = () => {
return new Promise((resolve) => {
return new Promise<string>((resolve) => {
if (!canvasImage.value) {
resolve('')
} else {