From deeb3a472ccaf0a829da2eb9b770ab0e3509463b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A5=94=E8=B7=91=E7=9A=84=E9=9D=A2=E6=9D=A1?= <1262327911@qq.com> Date: Sun, 22 May 2022 16:38:22 +0800 Subject: [PATCH] =?UTF-8?q?feat=EF=BC=9A=E6=96=B0=E5=A2=9E=E5=8F=91?= =?UTF-8?q?=E5=B8=83=E5=92=8C=E5=8F=96=E6=B6=88=E5=8F=91=E5=B8=83=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/http.ts | 34 ++++++++--- src/api/path/project.ts | 10 ++++ src/i18n/zh/index.ts | 5 ++ src/plugins/customComponents.ts | 3 + .../components/ProjectItemsCard/index.vue | 12 +++- .../ProjectItemsList/hooks/useData.hook.ts | 47 +++++++++++++-- .../ProjectItemsList/hooks/useModal.hook.ts | 2 +- .../components/ProjectItemsList/index.vue | 57 +++++++++++++------ src/views/project/items/index.vue | 2 +- 9 files changed, 137 insertions(+), 35 deletions(-) diff --git a/src/api/http.ts b/src/api/http.ts index 1542ff3e..ff1bf95e 100644 --- a/src/api/http.ts +++ b/src/api/http.ts @@ -20,6 +20,17 @@ export const post = (url: string, data?: object, headersType?: string) => { }) } +export const put = (url: string, data?: object, headersType?: string) => { + return axiosInstance({ + url: url, + method: RequestHttpEnum.PUT, + data: data, + headers: { + 'Content-Type': headersType || ContentTypeEnum.JSON + } + }) +} + export const del = (url: string, params?: object) => { return axiosInstance({ url: url, @@ -30,11 +41,20 @@ export const del = (url: string, params?: object) => { // 获取请求函数,默认get export const http = (type?: RequestHttpEnum) => { - return type === RequestHttpEnum.GET - ? get - : type === RequestHttpEnum.POST - ? post - : type === RequestHttpEnum.DELETE - ? del - : get + switch (type) { + case RequestHttpEnum.GET: + return get + + case RequestHttpEnum.POST: + return post + + case RequestHttpEnum.PUT: + return put + + case RequestHttpEnum.DELETE: + return del + + default: + return get + } } diff --git a/src/api/path/project.ts b/src/api/path/project.ts index acf6762a..e6a8b18a 100644 --- a/src/api/path/project.ts +++ b/src/api/path/project.ts @@ -30,4 +30,14 @@ export const deleteProjectApi = async (data: object) => { } catch { httpErrorHandle(); } +} + +// * 修改发布状态 [-1未发布,1发布] +export const changeProjectReleaseApi = async (data: object) => { + try { + const res = await http(RequestHttpEnum.PUT)(`${ModuleTypeEnum.PROJECT}/publish`, data); + return res; + } catch { + httpErrorHandle(); + } } \ No newline at end of file diff --git a/src/i18n/zh/index.ts b/src/i18n/zh/index.ts index c67bb103..80653ded 100644 --- a/src/i18n/zh/index.ts +++ b/src/i18n/zh/index.ts @@ -20,11 +20,16 @@ const global = { r_edit: '编辑', r_preview: '预览', r_copy: '克隆', + r_copy_success: '克隆成功!', r_rename: '重命名', + r_rename_success: '重命名成功!', r_publish: '发布', + r_publish_success: '成功发布!', r_unpublish: '取消发布', + r_unpublish_success: '取消成功!', r_download: '下载', r_delete: '删除', + r_delete_success: '删除成功!', r_more: '更多', } diff --git a/src/plugins/customComponents.ts b/src/plugins/customComponents.ts index 0fad1075..81e67df1 100644 --- a/src/plugins/customComponents.ts +++ b/src/plugins/customComponents.ts @@ -8,7 +8,10 @@ import { SketchRule } from 'vue3-sketch-ruler' * @param app */ export function setupCustomComponents(app: App) { + // 骨架屏 app.component('GoSkeleton', GoSkeleton) + // 加载 app.component('GoLoading', GoLoading) + // 标尺 app.component('SketchRule', SketchRule) } diff --git a/src/views/project/items/components/ProjectItemsCard/index.vue b/src/views/project/items/components/ProjectItemsCard/index.vue index 1b996b7c..d5917b4a 100644 --- a/src/views/project/items/components/ProjectItemsCard/index.vue +++ b/src/views/project/items/components/ProjectItemsCard/index.vue @@ -98,7 +98,7 @@ const { SendIcon } = icon.ionicons5 -const emit = defineEmits(['delete', 'resize', 'edit']) +const emit = defineEmits(['delete', 'resize', 'edit', 'release']) const props = defineProps({ cardData: Object as PropType @@ -146,7 +146,7 @@ const selectOptions = ref([ label: props.cardData?.release ? renderLang('global.r_unpublish') : renderLang('global.r_publish'), - key: 'send', + key: 'release', icon: renderIcon(SendIcon) }, { @@ -170,6 +170,9 @@ const handleSelect = (key: string) => { case 'delete': deleteHanlde() break + case 'release': + releaseHandle() + break case 'edit': editHandle() break @@ -186,6 +189,11 @@ const editHandle = () => { emit('edit', props.cardData) } +// 编辑处理 +const releaseHandle = () => { + emit('release', props.cardData) +} + // 放大处理 const resizeHandle = () => { emit('resize', props.cardData) diff --git a/src/views/project/items/components/ProjectItemsList/hooks/useData.hook.ts b/src/views/project/items/components/ProjectItemsList/hooks/useData.hook.ts index 11bb0b8f..5fb234d0 100644 --- a/src/views/project/items/components/ProjectItemsList/hooks/useData.hook.ts +++ b/src/views/project/items/components/ProjectItemsList/hooks/useData.hook.ts @@ -1,15 +1,17 @@ import { ref, reactive } from 'vue'; import { goDialog, httpErrorHandle } from '@/utils' import { DialogEnum } from '@/enums/pluginEnum' -import { projectListApi, deleteProjectApi } from '@/api/path/project' +import { projectListApi, deleteProjectApi, changeProjectReleaseApi } from '@/api/path/project' import { Chartype, ChartList } from '../../../index.d' import { ResultEnum } from '@/enums/httpEnum' // 数据初始化 export const useDataListInit = () => { + const loading = ref(true) + const paginat = reactive({ - // 当前页数 + // 当前页数 page: 1, // 每页值 limit: 12, @@ -21,6 +23,7 @@ export const useDataListInit = () => { // 数据请求 const fetchList = async () => { + loading.value = true const res: any = await projectListApi({ page: paginat.page, limit: paginat.limit @@ -38,7 +41,12 @@ export const useDataListInit = () => { release: state !== -1 } }) + setTimeout(() => { + loading.value = false + }, 500) + return } + httpErrorHandle() } // 修改页数 @@ -53,8 +61,8 @@ export const useDataListInit = () => { fetchList() } - // 删除 - const deleteHandle = (cardData: Chartype, index: number) => { + // 删除处理 + const deleteHandle = (cardData: Chartype) => { goDialog({ type: DialogEnum.DELETE, promise: true, @@ -65,7 +73,7 @@ export const useDataListInit = () => { }), promiseResCallback: (res: any) => { if (res.code === ResultEnum.SUCCESS) { - window['$message'].success('删除成功') + window['$message'].success(window['$t']('global.r_delete_success')) fetchList() return } @@ -74,13 +82,40 @@ export const useDataListInit = () => { }) } + // 发布处理 + const releaseHandle = async (cardData: Chartype, index: number) => { + const { id, release } = cardData + const res: any = await changeProjectReleaseApi({ + id: id, + // [-1未发布, 1发布] + state: !release ? 1 : -1 + }) + if (res.code === ResultEnum.SUCCESS) { + list.value = [] + fetchList() + // 发布 -> 未发布 + if (release) { + window['$message'].success(window['$t']('global.r_unpublish_success')) + return + } + // 未发布 -> 发布 + window['$message'].success(window['$t']('global.r_publish_success')) + return + } + httpErrorHandle() + } + // 立即请求 fetchList() return { + loading, paginat, list, - fetchList, changeSize, changePage, + fetchList, + releaseHandle, + changeSize, + changePage, deleteHandle } } diff --git a/src/views/project/items/components/ProjectItemsList/hooks/useModal.hook.ts b/src/views/project/items/components/ProjectItemsList/hooks/useModal.hook.ts index fc940401..af74d44a 100644 --- a/src/views/project/items/components/ProjectItemsList/hooks/useModal.hook.ts +++ b/src/views/project/items/components/ProjectItemsList/hooks/useModal.hook.ts @@ -1,4 +1,4 @@ -import { ref, Ref } from 'vue' +import { ref } from 'vue' import { ChartEnum } from '@/enums/pageEnum' import { fetchPathByName, routerTurnByPath } from '@/utils' import { Chartype } from '../../../index.d' diff --git a/src/views/project/items/components/ProjectItemsList/index.vue b/src/views/project/items/components/ProjectItemsList/index.vue index 0013ff99..73783e8a 100644 --- a/src/views/project/items/components/ProjectItemsList/index.vue +++ b/src/views/project/items/components/ProjectItemsList/index.vue @@ -1,20 +1,30 @@