From 3ceef2f0e0ecef4c9525d5b68f6a6eb62216b902 Mon Sep 17 00:00:00 2001 From: AaronWu <2463371514@qq.com> Date: Tue, 15 Apr 2025 16:05:10 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=9D=83=E9=99=90=E5=8F=8A=E5=AE=A2?= =?UTF-8?q?=E6=88=B7=E7=AB=AF=E9=A1=B5=E9=9D=A2=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env.development | 3 +- src/api/account/model.d.ts | 1 + src/api/dict/model.d.ts | 7 +- src/api/issue/index.ts | 18 ++ src/api/knowledgeBase/index.ts | 21 +- src/api/login/index.ts | 2 +- src/api/user/index.ts | 11 + src/router/constant.ts | 12 +- src/router/generator-router.tsx | 9 +- src/router/index.ts | 4 +- src/router/outsideLayout.ts | 6 +- src/router/router-guards.ts | 14 +- src/views/client/entrance/index.vue | 234 +++++++++++++-- src/views/client/issue/index.vue | 296 ++++++++++++++++-- src/views/client/knowledgeBase/index.vue | 363 +++++++++++++++++------ src/views/login/index.vue | 21 +- src/views/question/commom/tools.ts | 103 +++++++ src/views/question/issue/detail.vue | 4 + src/views/question/issue/index.vue | 12 +- src/views/question/knowledge/index.vue | 53 +++- src/views/system/user/columns.tsx | 15 +- src/views/system/user/formSchemas.ts | 30 +- 22 files changed, 1043 insertions(+), 196 deletions(-) create mode 100644 src/views/question/commom/tools.ts diff --git a/.env.development b/.env.development index b4ca053..4e32643 100644 --- a/.env.development +++ b/.env.development @@ -9,7 +9,8 @@ # 只在开发模式中被载入 # 网站前缀 -VITE_BASE_API_URL = http://192.168.2.116:8089/server/ +VITE_BASE_API_URL = http://192.168.2.92:8089/server/ +# VITE_BASE_API_URL = http://43.137.2.78:8082/server/ # base api VITE_BASE_API = '/server/' diff --git a/src/api/account/model.d.ts b/src/api/account/model.d.ts index 5afea19..1d21e87 100644 --- a/src/api/account/model.d.ts +++ b/src/api/account/model.d.ts @@ -46,5 +46,6 @@ declare namespace API { status: number; roles: number[]; departmentName: string; + isAdmin: number; }; } diff --git a/src/api/dict/model.d.ts b/src/api/dict/model.d.ts index 8312804..4e525ff 100644 --- a/src/api/dict/model.d.ts +++ b/src/api/dict/model.d.ts @@ -10,10 +10,11 @@ declare namespace API { type DictValueType = { id?: string; - dictTypeId: string; - dictValue: string; - enable: number; + dictTypeId?: string; + dictValue?: string; + enable?: number; pendingStatus?: boolean; + typeId?: number; }; type DeleteDictValueParams = { diff --git a/src/api/issue/index.ts b/src/api/issue/index.ts index 3161cf3..f31948e 100644 --- a/src/api/issue/index.ts +++ b/src/api/issue/index.ts @@ -44,6 +44,24 @@ export function fetchIssuePageList(data: API.SearchPageListParams) { ); } +/** + * @description 查询分页列表 + * @param {SearchPageListParams} data + * @returns + */ +export function fetchMyIssuePageList(data: API.SearchPageListParams) { + return request>( + { + url: 'question/myList', + method: 'post', + data, + }, + { + isGetDataDirectly: false, + }, + ); +} + /** * @description 新增单条 * @param {IssueType} data diff --git a/src/api/knowledgeBase/index.ts b/src/api/knowledgeBase/index.ts index 9be9529..3f3bb90 100644 --- a/src/api/knowledgeBase/index.ts +++ b/src/api/knowledgeBase/index.ts @@ -13,17 +13,12 @@ import { request } from '@/utils/request'; * @param {SearchListParams} params * @returns */ -export function fetchKnowledgeBaseList(params: API.SearchListParams) { - return request>( - { - url: 'knowledge/list', - method: 'get', - params, - }, - { - isGetDataDirectly: false, - }, - ); +export function fetchKnowledgeBaseList(params: any) { + return request({ + url: 'knowledge/list', + method: 'get', + params, + }); } /** @@ -86,8 +81,8 @@ export function findOneById(params: { id: string }) { */ export function deleteKnowledgeBaseById(params: API.DeleteKnowledgeBaseParams) { return request({ - url: `knowledge/delById`, - method: 'post', + url: `knowledge/delete/${params.id}`, + method: 'delete', params, }); } diff --git a/src/api/login/index.ts b/src/api/login/index.ts index 59c28a9..c5310fe 100644 --- a/src/api/login/index.ts +++ b/src/api/login/index.ts @@ -7,7 +7,7 @@ import { request } from '@/utils/request'; * @returns */ export function login(data: API.LoginParams) { - return request>({ + return request({ url: 'login', method: 'post', data, diff --git a/src/api/user/index.ts b/src/api/user/index.ts index 7b960d3..d019c26 100644 --- a/src/api/user/index.ts +++ b/src/api/user/index.ts @@ -70,6 +70,17 @@ export function updateUser(data: API.UserInfoType) { }); } +/** + * @description 修改状态 + */ +export function updateState(params: { id: string; state: number }) { + return request({ + url: `user/updateState`, + method: 'get', + params, + }); +} + /** * @description 查询单条 */ diff --git a/src/router/constant.ts b/src/router/constant.ts index e984796..bf1d3b3 100644 --- a/src/router/constant.ts +++ b/src/router/constant.ts @@ -13,7 +13,17 @@ export const PARENT_LAYOUT_NAME = 'ParentLayout'; export const PAGE_NOT_FOUND_NAME = 'PageNotFound'; // 路由白名单 -export const whiteNameList = [LOGIN_NAME, 'icons', 'error', 'error-404'] as const; // no redirect whitelist +export const whiteNameList = [ + LOGIN_NAME, + KNOWLEDGE_NAME, + ISSUE_NAME, + ENTRANCE_NAME, + 'icons', + 'error', + 'error-404', +] as const; // no redirect whitelist + +export const withoutLoginNameList = [LOGIN_NAME, 'icons', 'error', 'error-404'] as const; export type WhiteNameList = typeof whiteNameList; diff --git a/src/router/generator-router.tsx b/src/router/generator-router.tsx index f6ac609..95777cd 100644 --- a/src/router/generator-router.tsx +++ b/src/router/generator-router.tsx @@ -32,7 +32,7 @@ function asyncImportRoute(routes: any[] | undefined) { const { children } = item; if (component) { item.component = dynamicImport(dynamicViewsModules, component as string); - } + } children && asyncImportRoute(children); }); } @@ -90,7 +90,6 @@ export function filterAsyncRoute( //transformObjToRoute console.log('请正确配置路由:' + route?.name + '的component属性'); } route.children && asyncImportRoute(route.children); - }); return routeList as any; @@ -109,11 +108,7 @@ export const generatorDynamicRouter = (asyncMenus: API.Menu[]) => { console.log(routeList, '根据后端返回的权限路由生成'); // 给公共路由添加namePath generatorNamePath(common); - const menus = [ - ...common, - ...routeList, - ...endRoutes, - ]; + const menus = [...common, ...routeList, ...endRoutes]; layout.children = menus; const removeRoute = router.addRoute(layout); // 获取所有没有包含children的路由,上面addRoute的时候,vue-router已经帮我们拍平了所有路由 diff --git a/src/router/index.ts b/src/router/index.ts index 3e3fcb5..1074e7f 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -4,7 +4,7 @@ import { createRouter, createWebHashHistory } from 'vue-router'; import { createRouterGuards } from './router-guards'; import outsideLayout from './outsideLayout'; -import { whiteNameList } from './constant'; +import { whiteNameList, withoutLoginNameList } from './constant'; import type { App } from 'vue'; import type { RouteRecordRaw } from 'vue-router'; @@ -41,7 +41,7 @@ export function resetRouter() { export async function setupRouter(app: App) { // 创建路由守卫 - createRouterGuards(router, whiteNameList); + createRouterGuards(router, withoutLoginNameList); app.use(router); diff --git a/src/router/outsideLayout.ts b/src/router/outsideLayout.ts index dd5558b..ff280ca 100644 --- a/src/router/outsideLayout.ts +++ b/src/router/outsideLayout.ts @@ -22,7 +22,7 @@ export const KnowledgeRoute: RouteRecordRaw = { }, }; -export const Issue: RouteRecordRaw = { +export const IssueRoute: RouteRecordRaw = { path: '/issue', name: ISSUE_NAME, component: () => import(/* webpackChunkName: "login" */ '@/views/client/issue/index.vue'), @@ -31,7 +31,7 @@ export const Issue: RouteRecordRaw = { }, }; -export const Entrance: RouteRecordRaw = { +export const EntranceRoute: RouteRecordRaw = { path: '/entrance', name: ENTRANCE_NAME, component: () => import(/* webpackChunkName: "login" */ '@/views/client/entrance/index.vue'), @@ -40,4 +40,4 @@ export const Entrance: RouteRecordRaw = { }, }; -export default [LoginRoute, KnowledgeRoute, Issue, Entrance]; +export default [LoginRoute, KnowledgeRoute, IssueRoute, EntranceRoute]; diff --git a/src/router/router-guards.ts b/src/router/router-guards.ts index d2d2dde..26670d4 100644 --- a/src/router/router-guards.ts +++ b/src/router/router-guards.ts @@ -13,12 +13,22 @@ NProgress.configure({ showSpinner: false }); // NProgress Configuration const defaultRoutePath = '/dashboard/welcome'; -export function createRouterGuards(router: Router, whiteNameList: WhiteNameList) { +export function createRouterGuards(router: Router, withoutLoginNameList: WhiteNameList) { router.beforeEach(async (to, _, next) => { NProgress.start(); // start progress bar const userStore = useUserStore(); const token = Storage.get(ACCESS_TOKEN_KEY, null); if (token) { + const isAdmin = userStore.userInfo.isAdmin; + if (isAdmin === 0) { + // 判断是否是管理员,如果不是管理员,则不允许访问系统管理相关的路由 + const clientRoutes = ['/entrance', '/issue', '/knowledge']; + if (!clientRoutes.includes(to.path)) { + return next({ path: '/entrance' }); + } else { + return next(); + } + } if (to.name === LOGIN_NAME) { next({ path: defaultRoutePath }); } else { @@ -42,7 +52,7 @@ export function createRouterGuards(router: Router, whiteNameList: WhiteNameList) } } else { // not login - if (whiteNameList.some((n) => n === to.name)) { + if (withoutLoginNameList.some((n) => n === to.name)) { // 在免登录名单,直接进入 next(); } else { diff --git a/src/views/client/entrance/index.vue b/src/views/client/entrance/index.vue index bc94ef6..cef7601 100644 --- a/src/views/client/entrance/index.vue +++ b/src/views/client/entrance/index.vue @@ -14,6 +14,18 @@ + + {{ userInfo.name }} + + @@ -54,16 +66,34 @@

👋 嗨,有什么可以帮你?

- +
+ + +
+
+
+ + {{ item.title }} +
+

{{ item.description }}

+
+
+
- {{ tag }} + {{ tag.label }}
@@ -92,8 +122,9 @@ - diff --git a/src/views/client/issue/index.vue b/src/views/client/issue/index.vue index 0345ec9..5c9db05 100644 --- a/src/views/client/issue/index.vue +++ b/src/views/client/issue/index.vue @@ -1,5 +1,12 @@ + + + @@ -44,9 +63,9 @@
-