mirror of
https://github.com/palxiao/poster-design.git
synced 2025-07-15 16:02:19 +08:00
Merge branch 'feat-upgrade-vue3' into feat-pinia
This commit is contained in:
commit
d346f4e3a9
@ -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', {
|
||||
|
@ -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
|
||||
|
@ -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}) => {
|
||||
|
@ -66,7 +66,7 @@ useFontStore.init() // 初始化加载字体
|
||||
|
||||
// 生成封面
|
||||
const draw = () => {
|
||||
return new Promise((resolve) => {
|
||||
return new Promise<string>((resolve) => {
|
||||
if (!canvasImage.value) {
|
||||
resolve('')
|
||||
} else {
|
||||
|
Loading…
x
Reference in New Issue
Block a user