From 9e94573046d9a7ab75fa62c9f0e81d06ab832a63 Mon Sep 17 00:00:00 2001 From: zlong <953829746@qq.com> Date: Wed, 20 Nov 2024 11:36:52 +0800 Subject: [PATCH 1/4] =?UTF-8?q?fix:=E6=96=B0=E5=A2=9E=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E5=AF=BC=E5=85=A5=E5=8A=9F=E8=83=BD,=E5=9B=9E=E9=80=80?= =?UTF-8?q?=E5=88=B0main=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components.d.ts | 11 ------- src/auto-import.d.ts | 71 ++++++++++++++++++++++++++++++++++++++++++++ vite.config.ts | 4 +++ 3 files changed, 75 insertions(+), 11 deletions(-) create mode 100644 src/auto-import.d.ts diff --git a/components.d.ts b/components.d.ts index cf28278..6e59df9 100644 --- a/components.d.ts +++ b/components.d.ts @@ -8,20 +8,14 @@ export {} declare module 'vue' { export interface GlobalComponents { Copyright: typeof import('./src/components/Copyright.vue')['default'] - Dialog: typeof import('./src/components/Dialog.vue')['default'] RegularPage: typeof import('./src/components/RegularPage.vue')['default'] RouterLink: typeof import('vue-router')['RouterLink'] RouterView: typeof import('vue-router')['RouterView'] TAside: typeof import('tdesign-vue-next')['Aside'] TAvatar: typeof import('tdesign-vue-next')['Avatar'] TButton: typeof import('tdesign-vue-next')['Button'] - TCard: typeof import('tdesign-vue-next')['Card'] TCheckbox: typeof import('tdesign-vue-next')['Checkbox'] - TCol: typeof import('tdesign-vue-next')['Col'] - TDialog: typeof import('tdesign-vue-next')['Dialog'] TDropdown: typeof import('tdesign-vue-next')['Dropdown'] - TForm: typeof import('tdesign-vue-next')['Form'] - TFormItem: typeof import('tdesign-vue-next')['FormItem'] THeader: typeof import('tdesign-vue-next')['Header'] TIcon: typeof import('tdesign-vue-next')['Icon'] TInput: typeof import('tdesign-vue-next')['Input'] @@ -29,11 +23,6 @@ declare module 'vue' { TLink: typeof import('tdesign-vue-next')['Link'] TMenu: typeof import('tdesign-vue-next')['Menu'] TMenuItem: typeof import('tdesign-vue-next')['MenuItem'] - TPagination: typeof import('tdesign-vue-next')['Pagination'] - TRow: typeof import('tdesign-vue-next')['Row'] - TSelect: typeof import('tdesign-vue-next')['Select'] TSpace: typeof import('tdesign-vue-next')['Space'] - TTable: typeof import('tdesign-vue-next')['Table'] - TTag: typeof import('tdesign-vue-next')['Tag'] } } diff --git a/src/auto-import.d.ts b/src/auto-import.d.ts new file mode 100644 index 0000000..5371070 --- /dev/null +++ b/src/auto-import.d.ts @@ -0,0 +1,71 @@ +/* eslint-disable */ +/* prettier-ignore */ +// @ts-nocheck +// noinspection JSUnusedGlobalSymbols +// Generated by unplugin-auto-import +// biome-ignore lint: disable +export {} +declare global { + const EffectScope: typeof import('vue')['EffectScope'] + const computed: typeof import('vue')['computed'] + const createApp: typeof import('vue')['createApp'] + const customRef: typeof import('vue')['customRef'] + const defineAsyncComponent: typeof import('vue')['defineAsyncComponent'] + const defineComponent: typeof import('vue')['defineComponent'] + const effectScope: typeof import('vue')['effectScope'] + const getCurrentInstance: typeof import('vue')['getCurrentInstance'] + const getCurrentScope: typeof import('vue')['getCurrentScope'] + const h: typeof import('vue')['h'] + const inject: typeof import('vue')['inject'] + const isProxy: typeof import('vue')['isProxy'] + const isReactive: typeof import('vue')['isReactive'] + const isReadonly: typeof import('vue')['isReadonly'] + const isRef: typeof import('vue')['isRef'] + const markRaw: typeof import('vue')['markRaw'] + const nextTick: typeof import('vue')['nextTick'] + const onActivated: typeof import('vue')['onActivated'] + const onBeforeMount: typeof import('vue')['onBeforeMount'] + const onBeforeUnmount: typeof import('vue')['onBeforeUnmount'] + const onBeforeUpdate: typeof import('vue')['onBeforeUpdate'] + const onDeactivated: typeof import('vue')['onDeactivated'] + const onErrorCaptured: typeof import('vue')['onErrorCaptured'] + const onMounted: typeof import('vue')['onMounted'] + const onRenderTracked: typeof import('vue')['onRenderTracked'] + const onRenderTriggered: typeof import('vue')['onRenderTriggered'] + const onScopeDispose: typeof import('vue')['onScopeDispose'] + const onServerPrefetch: typeof import('vue')['onServerPrefetch'] + const onUnmounted: typeof import('vue')['onUnmounted'] + const onUpdated: typeof import('vue')['onUpdated'] + const onWatcherCleanup: typeof import('vue')['onWatcherCleanup'] + const provide: typeof import('vue')['provide'] + const reactive: typeof import('vue')['reactive'] + const readonly: typeof import('vue')['readonly'] + const ref: typeof import('vue')['ref'] + const resolveComponent: typeof import('vue')['resolveComponent'] + const shallowReactive: typeof import('vue')['shallowReactive'] + const shallowReadonly: typeof import('vue')['shallowReadonly'] + const shallowRef: typeof import('vue')['shallowRef'] + const toRaw: typeof import('vue')['toRaw'] + const toRef: typeof import('vue')['toRef'] + const toRefs: typeof import('vue')['toRefs'] + const toValue: typeof import('vue')['toValue'] + const triggerRef: typeof import('vue')['triggerRef'] + const unref: typeof import('vue')['unref'] + const useAttrs: typeof import('vue')['useAttrs'] + const useCssModule: typeof import('vue')['useCssModule'] + const useCssVars: typeof import('vue')['useCssVars'] + const useId: typeof import('vue')['useId'] + const useModel: typeof import('vue')['useModel'] + const useSlots: typeof import('vue')['useSlots'] + const useTemplateRef: typeof import('vue')['useTemplateRef'] + const watch: typeof import('vue')['watch'] + const watchEffect: typeof import('vue')['watchEffect'] + const watchPostEffect: typeof import('vue')['watchPostEffect'] + const watchSyncEffect: typeof import('vue')['watchSyncEffect'] +} +// for type re-export +declare global { + // @ts-ignore + export type { Component, ComponentPublicInstance, ComputedRef, ExtractDefaultPropTypes, ExtractPropTypes, ExtractPublicPropTypes, InjectionKey, PropType, Ref, VNode, WritableComputedRef } from 'vue' + import('vue') +} diff --git a/vite.config.ts b/vite.config.ts index c3ed3e9..158c544 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -14,6 +14,10 @@ export default defineConfig(({ command, mode }) => { return { plugins: [ vue(), + AutoImport({ + imports:['vue'], + dts:"src/auto-import.d.ts" // 会自动生成此文件 + }), vueDevTools(), AutoImport({ resolvers: [ From 37a8db005515d89aeafa7ef08a34c33bb4292a6e Mon Sep 17 00:00:00 2001 From: chen <1443977802@qq.com> Date: Thu, 21 Nov 2024 13:06:52 +0800 Subject: [PATCH 2/4] =?UTF-8?q?feature:=E5=88=86=E7=B1=BB=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E6=8E=A5=E5=8F=A3=E5=AF=B9=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components.d.ts | 4 +- src/api/category.ts | 23 ++++ src/api/httpClient.ts | 22 ++-- src/composables/useSearchable.ts | 6 +- src/model/base.ts | 8 +- src/model/category.ts | 23 ++++ src/model/classify.ts | 8 -- .../components/CategoryDialog.vue} | 54 +++++--- src/pages/category/index.vue | 121 ++++++++++++++++++ src/pages/classify/index.vue | 107 ---------------- src/pages/common/login.vue | 1 + src/router/index.ts | 8 +- 12 files changed, 231 insertions(+), 154 deletions(-) create mode 100644 src/api/category.ts create mode 100644 src/model/category.ts delete mode 100644 src/model/classify.ts rename src/pages/{classify/components/ClassifyDialog.vue => category/components/CategoryDialog.vue} (65%) create mode 100644 src/pages/category/index.vue delete mode 100644 src/pages/classify/index.vue diff --git a/components.d.ts b/components.d.ts index bbec505..c554722 100644 --- a/components.d.ts +++ b/components.d.ts @@ -15,7 +15,6 @@ declare module 'vue' { TAvatar: typeof import('tdesign-vue-next')['Avatar'] TButton: typeof import('tdesign-vue-next')['Button'] TCard: typeof import('tdesign-vue-next')['Card'] - TCheckbox: typeof import('tdesign-vue-next')['Checkbox'] TDialog: typeof import('tdesign-vue-next')['Dialog'] TDropdown: typeof import('tdesign-vue-next')['Dropdown'] TForm: typeof import('tdesign-vue-next')['Form'] @@ -23,10 +22,11 @@ declare module 'vue' { THeader: typeof import('tdesign-vue-next')['Header'] TIcon: typeof import('tdesign-vue-next')['Icon'] TInput: typeof import('tdesign-vue-next')['Input'] + TInputNumber: typeof import('tdesign-vue-next')['InputNumber'] TLayout: typeof import('tdesign-vue-next')['Layout'] - TLink: typeof import('tdesign-vue-next')['Link'] TMenu: typeof import('tdesign-vue-next')['Menu'] TMenuItem: typeof import('tdesign-vue-next')['MenuItem'] + TPopconfirm: typeof import('tdesign-vue-next')['Popconfirm'] TSpace: typeof import('tdesign-vue-next')['Space'] TTable: typeof import('tdesign-vue-next')['Table'] TTag: typeof import('tdesign-vue-next')['Tag'] diff --git a/src/api/category.ts b/src/api/category.ts new file mode 100644 index 0000000..20bf5a3 --- /dev/null +++ b/src/api/category.ts @@ -0,0 +1,23 @@ +import httpClient from '@/api/httpClient' +import type { PageResult } from '@/model/base' +import type { Category,CategorySearchFilter,CategoryDeleteRequest } from '@/model/category' + +export const searchCategoryRequest = (categoryFilterParam:CategorySearchFilter ) => { + return httpClient.get>('/categories',categoryFilterParam) +} + +export const createCategoryRequest = (category: Pick) => { + return httpClient.post('/categories',category) +} + +export const deleteCategoryRequest = (categoryDeleteParam:CategoryDeleteRequest) => { + return httpClient.delete(`/categories`,categoryDeleteParam) +} + +export const searchCategoryByIdRequest = (id: string) => { + return httpClient.get(`/categories/${id}`) +} + +export const updateCategoryByIdRequest = (id: string,category: Pick) => { + return httpClient.put(`/categories/${id}`,category) +} \ No newline at end of file diff --git a/src/api/httpClient.ts b/src/api/httpClient.ts index 609c338..7aa0f3a 100644 --- a/src/api/httpClient.ts +++ b/src/api/httpClient.ts @@ -1,5 +1,5 @@ -import axios, { type AxiosInstance } from 'axios' -import type { ErrorResponse } from '@/model/base' +import axios, { type AxiosInstance, } from 'axios' +import type { ErrorResponse,ErrorResponseList } from '@/model/base' import { MessagePlugin } from 'tdesign-vue-next' import { useAppStore } from '@/stores/app' @@ -9,18 +9,22 @@ const client: AxiosInstance = axios.create({ }) const handleError = (errorResponse: ErrorResponse) => { + MessagePlugin.error(errorResponse.message) } client.interceptors.response.use( (response) => { - if (response.data.code) { - handleError(response.data) - return Promise.reject(response.data) - } return response }, (error) => { - const errorResponse = error.response.data as ErrorResponse + let errorResponse: ErrorResponse; + if (Array.isArray(error.response.data)) { + const errorResponseList = error.response.data as ErrorResponseList; + errorResponse = errorResponseList[0]; + } else { + // 否则,将其视为单个 ErrorResponse + errorResponse = error.response.data as ErrorResponse; + } handleError(errorResponse) return Promise.reject(errorResponse) } @@ -43,8 +47,8 @@ export default { const response = await client.post(url, data) return response.data as T }, - delete: async (url: string) => { - await client.delete(url) + delete: async (url: string,params?:any) => { + await client.delete(url,{params}) }, put: async (url: string, data: Record = {}) => { const response = await client.put(url, data) diff --git a/src/composables/useSearchable.ts b/src/composables/useSearchable.ts index 6e99955..265de59 100644 --- a/src/composables/useSearchable.ts +++ b/src/composables/useSearchable.ts @@ -15,9 +15,9 @@ export const useSearchable = ( loading.value = true const result = await api({...filter.value, page: pagination.page, size: pagination.size, ...defaultFilter}) data.value = result.data - pagination.page = result.paging.page - pagination.size = result.paging.size - pagination.total = result.paging.total + pagination.page = result.pagination.page + pagination.size = result.pagination.size + pagination.total = result.pagination.total loading.value = false } diff --git a/src/model/base.ts b/src/model/base.ts index e6adf25..2e9600d 100644 --- a/src/model/base.ts +++ b/src/model/base.ts @@ -5,7 +5,7 @@ export interface ErrorResponse { message: string; } export interface BaseModel { - id: number + id: string createdTime: string updateTime: string } @@ -25,6 +25,8 @@ export interface BaseFilterRequest extends Partial{ } export interface PageResult { - paging: Paging, + pagination: Paging, data: T[] -} \ No newline at end of file +} + +export interface ErrorResponseList extends Array {} \ No newline at end of file diff --git a/src/model/category.ts b/src/model/category.ts new file mode 100644 index 0000000..78e4094 --- /dev/null +++ b/src/model/category.ts @@ -0,0 +1,23 @@ +import type { AuditBaseModel,Paging } from '@/model/base' + + +export interface Category extends AuditBaseModel{ + name: string + code:string + order: number +} + + +export interface CategorySearchFilter extends Partial{ + order?: string +} + +export interface CategoryDeleteRequest{ + id:string +} + +export interface UpdateCategoryRequest{ + name: string + code:string + order: number +} diff --git a/src/model/classify.ts b/src/model/classify.ts deleted file mode 100644 index c1b5d1e..0000000 --- a/src/model/classify.ts +++ /dev/null @@ -1,8 +0,0 @@ -import type { BaseModel } from '@/model/base' - -export interface Classify extends BaseModel{ - numbering:string - name: string - sort: string -} - diff --git a/src/pages/classify/components/ClassifyDialog.vue b/src/pages/category/components/CategoryDialog.vue similarity index 65% rename from src/pages/classify/components/ClassifyDialog.vue rename to src/pages/category/components/CategoryDialog.vue index 8d6e8d1..9f81fc5 100644 --- a/src/pages/classify/components/ClassifyDialog.vue +++ b/src/pages/category/components/CategoryDialog.vue @@ -5,36 +5,45 @@ :confirmBtn="confirmBtn" :closeOnOverlayClick="false" @close="handleCloseDialog" - @confirm="fetchSaveClassifyData" + @confirm="SaveCategoryData" > - + - + - - + + - - + + + + + + diff --git a/src/pages/classify/index.vue b/src/pages/classify/index.vue deleted file mode 100644 index ed89e4b..0000000 --- a/src/pages/classify/index.vue +++ /dev/null @@ -1,107 +0,0 @@ - - - - - diff --git a/src/pages/common/login.vue b/src/pages/common/login.vue index 5932965..b2998ff 100644 --- a/src/pages/common/login.vue +++ b/src/pages/common/login.vue @@ -20,6 +20,7 @@ const handleLogin = async () => { return } try { + loading.value = true await appStore.login(loginForm) } finally { loading.value = false diff --git a/src/router/index.ts b/src/router/index.ts index c1a3dd8..da251dd 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -6,9 +6,9 @@ import Layout from '@/layouts/Layout.vue' export const asyncRoutes: RouteRecordRaw[] = [ { - name: 'classify', - path: 'classify', - component: () => import('@/pages/classify/index.vue'), + name: 'category', + path: 'category', + component: () => import('@/pages/category/index.vue'), meta: { title: '分类管理', icon: 'system-3' @@ -24,7 +24,7 @@ const router = createRouter({ component: Layout, path: '/', redirect: { - name: 'classify' + name: 'category' }, children: asyncRoutes }, From 0cfcebdebdfc203cb578559782f5709de1cfee87 Mon Sep 17 00:00:00 2001 From: chen <1443977802@qq.com> Date: Thu, 21 Nov 2024 22:56:56 +0800 Subject: [PATCH 3/4] =?UTF-8?q?feature:=E5=88=86=E7=B1=BB=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E6=8E=A5=E5=8F=A3=E5=AF=B9=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components.d.ts | 1 + src/api/category.ts | 6 +++--- src/model/category.ts | 3 --- src/pages/category/index.vue | 13 +++---------- 4 files changed, 7 insertions(+), 16 deletions(-) diff --git a/components.d.ts b/components.d.ts index c554722..4df2405 100644 --- a/components.d.ts +++ b/components.d.ts @@ -27,6 +27,7 @@ declare module 'vue' { TMenu: typeof import('tdesign-vue-next')['Menu'] TMenuItem: typeof import('tdesign-vue-next')['MenuItem'] TPopconfirm: typeof import('tdesign-vue-next')['Popconfirm'] + TSelectInput: typeof import('tdesign-vue-next')['SelectInput'] TSpace: typeof import('tdesign-vue-next')['Space'] TTable: typeof import('tdesign-vue-next')['Table'] TTag: typeof import('tdesign-vue-next')['Tag'] diff --git a/src/api/category.ts b/src/api/category.ts index 20bf5a3..92ee47f 100644 --- a/src/api/category.ts +++ b/src/api/category.ts @@ -1,6 +1,6 @@ import httpClient from '@/api/httpClient' import type { PageResult } from '@/model/base' -import type { Category,CategorySearchFilter,CategoryDeleteRequest } from '@/model/category' +import type { Category,CategorySearchFilter, } from '@/model/category' export const searchCategoryRequest = (categoryFilterParam:CategorySearchFilter ) => { return httpClient.get>('/categories',categoryFilterParam) @@ -10,8 +10,8 @@ export const createCategoryRequest = (category: Pick('/categories',category) } -export const deleteCategoryRequest = (categoryDeleteParam:CategoryDeleteRequest) => { - return httpClient.delete(`/categories`,categoryDeleteParam) +export const deleteCategoryRequest = (id: string) => { + return httpClient.delete(`/categories/${id}`,) } export const searchCategoryByIdRequest = (id: string) => { diff --git a/src/model/category.ts b/src/model/category.ts index 78e4094..26fb042 100644 --- a/src/model/category.ts +++ b/src/model/category.ts @@ -12,9 +12,6 @@ export interface CategorySearchFilter extends Partial{ order?: string } -export interface CategoryDeleteRequest{ - id:string -} export interface UpdateCategoryRequest{ name: string diff --git a/src/pages/category/index.vue b/src/pages/category/index.vue index 9129504..fa7e813 100644 --- a/src/pages/category/index.vue +++ b/src/pages/category/index.vue @@ -51,8 +51,8 @@ const handleCategoryDialogClosed = () => { isEdit.value = false currentTableData.value = {} } -const deleteCategoryClick = async (category: Category) => { - await deleteCategoryRequest({ id: category.id }) +const deleteCategoryClick = async (id: string) => { + await deleteCategoryRequest(id) fetchData() MessagePlugin.success('删除分类成功') } @@ -80,13 +80,6 @@ const deleteCategoryClick = async (category: Category) => { onChange: onPageChange }" > -