From 7c7e4f18ead1cc04d2811305b87658fcc0b80e47 Mon Sep 17 00:00:00 2001 From: huangpeng <1764183241@qq.com> Date: Thu, 11 Sep 2025 22:33:15 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/question-category.js | 24 +++ src/layout/Layout.vue | 4 + src/router/index.js | 5 + src/utils/date.js | 13 ++ .../components/CategoryForm.vue | 121 ++++++++++++++ .../components/CategoryTable.vue | 115 +++++++++++++ .../question-category/components/Create.vue | 99 +++++++++++ .../question-category/components/Edit.vue | 110 ++++++++++++ .../components/SearchBar.vue | 80 +++++++++ .../question-category/constants/constant.js | 29 ++++ src/views/question-category/index.vue | 158 +++++++++++++++++- vite.config.js | 7 + 12 files changed, 760 insertions(+), 5 deletions(-) create mode 100644 src/api/question-category.js create mode 100644 src/utils/date.js create mode 100644 src/views/question-category/components/CategoryForm.vue create mode 100644 src/views/question-category/components/CategoryTable.vue create mode 100644 src/views/question-category/components/Create.vue create mode 100644 src/views/question-category/components/Edit.vue create mode 100644 src/views/question-category/components/SearchBar.vue create mode 100644 src/views/question-category/constants/constant.js diff --git a/src/api/question-category.js b/src/api/question-category.js new file mode 100644 index 0000000..55dd478 --- /dev/null +++ b/src/api/question-category.js @@ -0,0 +1,24 @@ +import apiClient from './index'; + +export const questionCategoryApi = { + // 获取分类树列表 + getTreeList: () => apiClient.get('/question-category/tree-list'), + + // 获取分类详情 + getDetail: (id) => apiClient.get(`/question-category/${id}`), + + // 创建分类 + create: (data) => apiClient.post('/question-category', data), + + // 更新分类 + update: (id, data) => apiClient.put(`/question-category/${id}`, data), + + // 删除分类 + delete: (id) => apiClient.delete(`/question-category/${id}`), + + // 更新状态 + updateState: (id, state) => apiClient.patch(`/question-category/${id}/state`, { state }), + + // 获取分类选项(用于下拉选择) + getOptions: () => apiClient.get('/question-category/options') +} \ No newline at end of file diff --git a/src/layout/Layout.vue b/src/layout/Layout.vue index 435a068..e91d207 100644 --- a/src/layout/Layout.vue +++ b/src/layout/Layout.vue @@ -33,6 +33,10 @@ 题库管理 + + + 题库分类 + 会话历史 diff --git a/src/router/index.js b/src/router/index.js index 4715ac5..8666baf 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -37,6 +37,11 @@ const routes = [ name: 'AnswerRecord', component: () => import('../views/AnswerRecord.vue'), }, + { + path: 'question-category', + name: 'QuestionCategory', + component: () => import('@/views/question-category/index.vue'), + }, ], }, ]; diff --git a/src/utils/date.js b/src/utils/date.js new file mode 100644 index 0000000..d0b0f0a --- /dev/null +++ b/src/utils/date.js @@ -0,0 +1,13 @@ +export const formatDate = (dateString) => { + if (!dateString) return '-' + + const date = new Date(dateString) + return date.toLocaleString('zh-CN', { + year: 'numeric', + month: '2-digit', + day: '2-digit', + hour: '2-digit', + minute: '2-digit', + second: '2-digit' + }) +} \ No newline at end of file diff --git a/src/views/question-category/components/CategoryForm.vue b/src/views/question-category/components/CategoryForm.vue new file mode 100644 index 0000000..e5e427a --- /dev/null +++ b/src/views/question-category/components/CategoryForm.vue @@ -0,0 +1,121 @@ + + + + + \ No newline at end of file diff --git a/src/views/question-category/components/CategoryTable.vue b/src/views/question-category/components/CategoryTable.vue new file mode 100644 index 0000000..f2c1f6f --- /dev/null +++ b/src/views/question-category/components/CategoryTable.vue @@ -0,0 +1,115 @@ + + + + + \ No newline at end of file diff --git a/src/views/question-category/components/Create.vue b/src/views/question-category/components/Create.vue new file mode 100644 index 0000000..e49d054 --- /dev/null +++ b/src/views/question-category/components/Create.vue @@ -0,0 +1,99 @@ + + + + + \ No newline at end of file diff --git a/src/views/question-category/components/Edit.vue b/src/views/question-category/components/Edit.vue new file mode 100644 index 0000000..4edb76d --- /dev/null +++ b/src/views/question-category/components/Edit.vue @@ -0,0 +1,110 @@ + + + + + \ No newline at end of file diff --git a/src/views/question-category/components/SearchBar.vue b/src/views/question-category/components/SearchBar.vue new file mode 100644 index 0000000..64956d8 --- /dev/null +++ b/src/views/question-category/components/SearchBar.vue @@ -0,0 +1,80 @@ + + + + + \ No newline at end of file diff --git a/src/views/question-category/constants/constant.js b/src/views/question-category/constants/constant.js new file mode 100644 index 0000000..ec61c74 --- /dev/null +++ b/src/views/question-category/constants/constant.js @@ -0,0 +1,29 @@ +// 分类状态 +export const CATEGORY_STATUS = { + DISABLED: 0, + ENABLED: 1 +} + +export const CATEGORY_STATUS_MAP = { + [CATEGORY_STATUS.DISABLED]: '禁用', + [CATEGORY_STATUS.ENABLED]: '启用' +} + +export const CATEGORY_STATUS_OPTIONS = [ + { label: '启用', value: CATEGORY_STATUS.ENABLED }, + { label: '禁用', value: CATEGORY_STATUS.DISABLED } +] + +// 表单验证规则 +export const FORM_RULES = { + name: [ + { required: true, message: '请输入分类名称', trigger: 'blur' }, + { min: 1, max: 32, message: '长度在 1 到 32 个字符', trigger: 'blur' } + ], + parent_id: [ + { required: true, message: '请选择上级分类', trigger: 'change' } + ], + sort: [ + { required: true, message: '请输入排序值', trigger: 'blur' } + ] +} \ No newline at end of file diff --git a/src/views/question-category/index.vue b/src/views/question-category/index.vue index f79cdd8..d0ee8c8 100644 --- a/src/views/question-category/index.vue +++ b/src/views/question-category/index.vue @@ -1,11 +1,159 @@ - - - \ No newline at end of file diff --git a/vite.config.js b/vite.config.js index 084ad9a..14c4010 100644 --- a/vite.config.js +++ b/vite.config.js @@ -1,9 +1,16 @@ import { defineConfig } from 'vite' import vue from '@vitejs/plugin-vue' +import { fileURLToPath, URL } from 'node:url' + // https://vitejs.dev/config/ export default defineConfig({ plugins: [vue()], + resolve: { + alias: { + '@': fileURLToPath(new URL('./src', import.meta.url)) + } + }, server: { host: '0.0.0.0', proxy: {