From e977df58e87cf0af607f20b70469681f68e6750e Mon Sep 17 00:00:00 2001 From: IchliebedichZhu <54796446@qq.com> Date: Wed, 13 Mar 2024 23:20:14 +0000 Subject: [PATCH 1/3] feat: add github api type --- src/api/github.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/api/github.ts b/src/api/github.ts index 4e19e71..92160e6 100644 --- a/src/api/github.ts +++ b/src/api/github.ts @@ -11,15 +11,15 @@ const cutToken = 'ghp_qpV8PUxwY7as4jc' const reader = new FileReader() function getBase64(file: File) { return new Promise((resolve) => { - reader.onload = function (event: any) { - const fileContent = event.target.result - resolve(fileContent.split(',')[1]) + reader.onload = function (event) { + const fileContent = event.target && event.target.result + resolve((fileContent as string).split(',')[1]) } reader.readAsDataURL(file) }) } -const putPic = async (file: any) => { +const putPic = async (file: File) => { const repo = 'shawnphang/files' const d = new Date() const content = typeof file === 'string' ? file : await getBase64(file) From 6ee1ab78edfd9be34d2d0d281ddc356f7ddaae18 Mon Sep 17 00:00:00 2001 From: IchliebedichZhu <54796446@qq.com> Date: Wed, 13 Mar 2024 23:52:47 +0000 Subject: [PATCH 2/3] feat: convert CompListWrap component to composition API --- src/api/home.ts | 14 +- .../modules/panel/wrap/CompListWrap.vue | 276 ++++++++++-------- 2 files changed, 158 insertions(+), 132 deletions(-) diff --git a/src/api/home.ts b/src/api/home.ts index 1532edf..8dd3639 100644 --- a/src/api/home.ts +++ b/src/api/home.ts @@ -41,12 +41,12 @@ type IGetTempListResult = TPageRequestResult // 获取模板列表 export const getTempList = (params: IGetTempListParam) => fetch('design/list', params, 'get') -type TGetTempDetail = { +export type TGetTempDetail = { id: number type?: number } -type TTempDetail = { +export type TTempDetail = { /** 分类 */ category: number /** 封面 */ @@ -93,7 +93,7 @@ type TGetCompListParam = { page?: number type?: number pageSize: number - cate: number + cate?: number | string } /** 获取组件返回类型 */ @@ -104,13 +104,19 @@ export type TGetCompListResult = { state: number title: string width: number + name?: string } type getCompListReturn = TPageRequestResult // 组件相关接口 export const getCompList = (params: TGetCompListParam) => fetch('design/list', params, 'get') -export const removeComp = (params: Type.Object = {}) => fetch('design/del', params, 'post') + +type TRemoveComp = { + id: string | number +} + +export const removeComp = (params: TRemoveComp) => fetch('design/del', params, 'post') // export const getCompDetail = (params: Type.Object = {}) => fetch('/api/template/temp_info', params, 'get') // 保存作品 diff --git a/src/components/modules/panel/wrap/CompListWrap.vue b/src/components/modules/panel/wrap/CompListWrap.vue index b20c423..67048bb 100644 --- a/src/components/modules/panel/wrap/CompListWrap.vue +++ b/src/components/modules/panel/wrap/CompListWrap.vue @@ -15,152 +15,175 @@ 推荐组件 --> - + -
    - {{ currentCategory.name }} +
      + {{ state.currentCategory.name }} -
      +
      -
      拼命加载中
      -
      全部加载完毕
      +
      拼命加载中
      +
      全部加载完毕
    - From 7538b6b2ac03fdd363f97af01dafa923ca315b1b Mon Sep 17 00:00:00 2001 From: IchliebedichZhu <54796446@qq.com> Date: Wed, 13 Mar 2024 23:56:43 +0000 Subject: [PATCH 3/3] feat: convert CompListWrap component to composition API --- .../modules/panel/wrap/CompListWrap.vue | 64 ++++++++++--------- 1 file changed, 35 insertions(+), 29 deletions(-) diff --git a/src/components/modules/panel/wrap/CompListWrap.vue b/src/components/modules/panel/wrap/CompListWrap.vue index 67048bb..270e0be 100644 --- a/src/components/modules/panel/wrap/CompListWrap.vue +++ b/src/components/modules/panel/wrap/CompListWrap.vue @@ -34,7 +34,13 @@
      {{ state.currentCategory.name }} -
      +
      @@ -98,7 +104,7 @@ onMounted(async () => { } } }) -const mouseup = (e: any) => { +const mouseup = (e: MouseEvent) => { e.preventDefault() // setTimeout(() => { isDrag = false @@ -185,34 +191,34 @@ const dragStart = async (e: MouseEvent, { id, width, height, cover }: TGetCompLi } } - const selectItem = async (item: any) => { - if (isDrag) { - return - } - store.commit('setShowMoveable', false) // 清理掉上一次的选择 - tempDetail = tempDetail || (await getCompDetail({ id: item.id, type: 1 })) - // let group = JSON.parse(tempDetail.data) - const group: any = await getComponentsData(tempDetail.data) - let parent: any = { x: 0, y: 0 } - const { width: pW, height: pH } = store.getters.dPage +const selectItem = async (item: TGetCompListResult) => { + if (isDrag) { + return + } + store.commit('setShowMoveable', false) // 清理掉上一次的选择 + tempDetail = tempDetail || (await getCompDetail({ id: item.id, type: 1 })) + // let group = JSON.parse(tempDetail.data) + const group: any = await getComponentsData(tempDetail.data) + let parent: Record = { x: 0, y: 0 } + const { width: pW, height: pH } = store.getters.dPage - Array.isArray(group) && - group.forEach((element: any) => { - element.type === 'w-group' && (parent = element) - }) - if (parent.isContainer) { - group.forEach((element: any) => { - element.left += (pW - parent.width) / 2 - element.top += (pH - parent.height) / 2 - }) - store.dispatch('addGroup', group) - } else { - group.text && (group.text = decodeURIComponent(group.text)) - group.left = pW / 2 - group.fontSize * (group.text.length / 2) - group.top = pH / 2 - group.fontSize / 2 - store.dispatch('addWidget', group) - } - } + Array.isArray(group) && + group.forEach((element) => { + element.type === 'w-group' && (parent = element) + }) + if (parent.isContainer) { + group.forEach((element: any) => { + element.left += (pW - parent.width) / 2 + element.top += (pH - parent.height) / 2 + }) + store.dispatch('addGroup', group) + } else { + group.text && (group.text = decodeURIComponent(group.text)) + group.left = pW / 2 - group.fontSize * (group.text.length / 2) + group.top = pH / 2 - group.fontSize / 2 + store.dispatch('addWidget', group) + } +} function getCompDetail(params: TGetTempDetail): Promise { // 有缓存则直接返回组件数据,否则请求获取数据