From 795591487c3ac6d320e7c0575a89e59957eb1dce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E4=BB=A4?= <2603820757@qq.com> Date: Tue, 12 Jul 2022 14:00:51 +0800 Subject: [PATCH 01/28] docs: .gitignore --- .gitignore | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 5e14ce6..c9dadc9 100644 --- a/.gitignore +++ b/.gitignore @@ -3,8 +3,7 @@ node_modules dist dist-ssr *.local -node_modules -.DS_Store -dist -dist-ssr -*.local + +*.log +/.idea +/.vscode -- Gitee From bf9b5ea08454cc9c12041b7ba2ae2bca179aa169 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E4=BB=A4?= <2603820757@qq.com> Date: Tue, 12 Jul 2022 18:12:34 +0800 Subject: [PATCH 02/28] =?UTF-8?q?feat:=20=E7=94=A8=E6=88=B7=E4=B8=AD?= =?UTF-8?q?=E5=BF=83-=E6=90=9C=E7=B4=A2=E8=A1=A8=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/config/settings.json | 2 +- src/locale/en-US.ts | 3 + src/locale/zh-CN.ts | 3 + src/router/routes/modules/systemAdmin.ts | 28 +++++ src/views/dashboard/workplace/index.vue | 21 ++-- src/views/system-admin/user/index.vue | 118 ++++++++++++++++++++ src/views/system-admin/user/locale/en-US.ts | 16 +++ src/views/system-admin/user/locale/zh-CN.ts | 16 +++ 8 files changed, 198 insertions(+), 9 deletions(-) create mode 100644 src/router/routes/modules/systemAdmin.ts create mode 100644 src/views/system-admin/user/index.vue create mode 100644 src/views/system-admin/user/locale/en-US.ts create mode 100644 src/views/system-admin/user/locale/zh-CN.ts diff --git a/src/config/settings.json b/src/config/settings.json index aabd7f0..482fecd 100644 --- a/src/config/settings.json +++ b/src/config/settings.json @@ -10,7 +10,7 @@ "menuWidth": 220, "globalSettings": false, "device": "desktop", - "tabBar": false, + "tabBar": true, "menuFromServer": false, "serverMenu": [] } diff --git a/src/locale/en-US.ts b/src/locale/en-US.ts index 89e9705..5a8f4d7 100644 --- a/src/locale/en-US.ts +++ b/src/locale/en-US.ts @@ -2,6 +2,7 @@ import localeMessageBox from '@/components/message-box/locale/en-US'; import localeLogin from '@/views/login/locale/en-US'; import localeWorkplace from '@/views/dashboard/workplace/locale/en-US'; +import localeUserCenter from '@/views/system-admin/user/locale/en-US'; import localeSettings from './en-US/settings'; @@ -25,4 +26,6 @@ export default { ...localeMessageBox, ...localeLogin, ...localeWorkplace, + ...localeUserCenter, + 'menu.sys-admin': 'System Admin', }; diff --git a/src/locale/zh-CN.ts b/src/locale/zh-CN.ts index 65d564d..91d4afb 100644 --- a/src/locale/zh-CN.ts +++ b/src/locale/zh-CN.ts @@ -2,6 +2,7 @@ import localeMessageBox from '@/components/message-box/locale/zh-CN'; import localeLogin from '@/views/login/locale/zh-CN'; import localeWorkplace from '@/views/dashboard/workplace/locale/zh-CN'; +import localeUserCenter from '@/views/system-admin/user/locale/zh-CN'; import localeSettings from './zh-CN/settings'; @@ -25,4 +26,6 @@ export default { ...localeMessageBox, ...localeLogin, ...localeWorkplace, + ...localeUserCenter, + 'menu.sys-admin': '系统管理', }; diff --git a/src/router/routes/modules/systemAdmin.ts b/src/router/routes/modules/systemAdmin.ts new file mode 100644 index 0000000..58b2a4e --- /dev/null +++ b/src/router/routes/modules/systemAdmin.ts @@ -0,0 +1,28 @@ +import { DEFAULT_LAYOUT } from '@/router/constants'; +import { AppRouteRecordRaw } from '../types'; + +const SYSADMIN: AppRouteRecordRaw = { + path: '/sys-admin', + name: 'sys-admin', + component: DEFAULT_LAYOUT, + meta: { + locale: 'menu.sys-admin', + requiresAuth: true, + icon: 'icon-apps', + order: 0, + }, + children: [ + { + path: 'user', + name: 'User', + component: () => import('@/views/system-admin/user/index.vue'), + meta: { + locale: 'menu.sys-admin.user', + requiresAuth: true, + roles: ['developer', 'admin'], + }, + }, + ], +}; + +export default SYSADMIN; diff --git a/src/views/dashboard/workplace/index.vue b/src/views/dashboard/workplace/index.vue index 379e5ce..6829aff 100644 --- a/src/views/dashboard/workplace/index.vue +++ b/src/views/dashboard/workplace/index.vue @@ -62,10 +62,9 @@ diff --git a/src/views/system-admin/user/index.vue b/src/views/system-admin/user/index.vue new file mode 100644 index 0000000..5c12021 --- /dev/null +++ b/src/views/system-admin/user/index.vue @@ -0,0 +1,118 @@ + + + + + diff --git a/src/views/system-admin/user/locale/en-US.ts b/src/views/system-admin/user/locale/en-US.ts new file mode 100644 index 0000000..4496246 --- /dev/null +++ b/src/views/system-admin/user/locale/en-US.ts @@ -0,0 +1,16 @@ +export default { + 'menu.sys-admin.user': 'User Center', + 'searchTable.form.label.id': 'number', + 'searchTable.form.label.username': 'username', + 'searchTable.form.label.phone': 'phone', + 'searchTable.form.label.gender': 'gender', + 'searchTable.form.placeholder.id': 'Please enter user number', + 'searchTable.form.placeholder.username': 'Please enter username', + 'searchTable.form.placeholder.phone': 'Please enter user phone', + 'searchTable.form.placeholder.gender': 'Please enter user gender', + 'searchTable.form.search': 'Search', + 'searchTable.form.reset': 'Reset', + 'all': 'All', + 'male': 'male', + 'female': 'female', +}; diff --git a/src/views/system-admin/user/locale/zh-CN.ts b/src/views/system-admin/user/locale/zh-CN.ts new file mode 100644 index 0000000..e8e838d --- /dev/null +++ b/src/views/system-admin/user/locale/zh-CN.ts @@ -0,0 +1,16 @@ +export default { + 'menu.sys-admin.user': '用户中心', + 'searchTable.form.label.id': '编号', + 'searchTable.form.label.username': '用户名', + 'searchTable.form.label.phone': '手机号', + 'searchTable.form.label.gender': '性别', + 'searchTable.form.placeholder.id': '请输入用户编号', + 'searchTable.form.placeholder.username': '请输入用户名', + 'searchTable.form.placeholder.phone': '请输入用户手机号', + 'searchTable.form.placeholder.gender': '请输入用户性别', + 'searchTable.form.search': '搜索', + 'searchTable.form.reset': '重置', + 'all': '全部', + 'male': '男', + 'female': '女', +}; -- Gitee From 785b481f1e8f76ba12fe3ee6a19949dfdcb59a38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E4=BB=A4?= <2603820757@qq.com> Date: Wed, 13 Jul 2022 00:23:53 +0800 Subject: [PATCH 03/28] =?UTF-8?q?feat:=20=E5=8F=B3=E9=94=AE=E5=85=B3?= =?UTF-8?q?=E9=97=AD=E6=A0=87=E7=AD=BE=E9=A1=B5=E5=9B=BD=E9=99=85=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/tab-bar/locale/en-US.ts | 7 +++++++ src/components/tab-bar/locale/zh-CN.ts | 7 +++++++ src/components/tab-bar/tab-item.vue | 20 +++++++++++++------- src/locale/en-US.ts | 2 ++ src/locale/zh-CN.ts | 2 ++ src/views/system-admin/user/locale/en-US.ts | 2 +- src/views/system-admin/user/locale/zh-CN.ts | 2 +- 7 files changed, 33 insertions(+), 9 deletions(-) create mode 100644 src/components/tab-bar/locale/en-US.ts create mode 100644 src/components/tab-bar/locale/zh-CN.ts diff --git a/src/components/tab-bar/locale/en-US.ts b/src/components/tab-bar/locale/en-US.ts new file mode 100644 index 0000000..0e8ebe1 --- /dev/null +++ b/src/components/tab-bar/locale/en-US.ts @@ -0,0 +1,7 @@ +export default { + 'close.current.tab': 'closeCurrentTab', + 'close.left.tabs': 'closeLeftTabs', + 'close.right.tabs': 'closeRightTabs', + 'close.other.tabs': 'closeOtherTabs', + 'close.all.tabs': 'closeAllTabs', +}; diff --git a/src/components/tab-bar/locale/zh-CN.ts b/src/components/tab-bar/locale/zh-CN.ts new file mode 100644 index 0000000..634094f --- /dev/null +++ b/src/components/tab-bar/locale/zh-CN.ts @@ -0,0 +1,7 @@ +export default { + 'close.current.tab': '关闭当前标签页', + 'close.left.tabs': '关闭左侧标签页', + 'close.right.tabs': '关闭右侧标签页', + 'close.other.tabs': '关闭其它标签页', + 'close.all.tabs': '关闭全部标签页', +}; diff --git a/src/components/tab-bar/tab-item.vue b/src/components/tab-bar/tab-item.vue index 910ace4..d8498a7 100644 --- a/src/components/tab-bar/tab-item.vue +++ b/src/components/tab-bar/tab-item.vue @@ -18,31 +18,31 @@ diff --git a/src/api/dashboard.ts b/src/api/dashboard.ts index 773a104..4d466c4 100644 --- a/src/api/dashboard.ts +++ b/src/api/dashboard.ts @@ -1,5 +1,5 @@ -import axios from 'axios'; -import type { TableData } from '@arco-design/web-vue/es/table/interface'; +import axios from 'axios' +import type { TableData } from '@arco-design/web-vue/es/table/interface' export interface ContentDataRecord { x: string; @@ -7,7 +7,7 @@ export interface ContentDataRecord { } export function queryContentData() { - return axios.get('/api/content-data'); + return axios.get('/api/content-data') } export interface PopularRecord { @@ -18,5 +18,5 @@ export interface PopularRecord { } export function queryPopularList(params: { type: string }) { - return axios.get('/api/popular/list', { params }); + return axios.get('/api/popular/list', { params }) } diff --git a/src/api/interceptor.ts b/src/api/interceptor.ts index 1d8214f..1e4180e 100644 --- a/src/api/interceptor.ts +++ b/src/api/interceptor.ts @@ -1,8 +1,8 @@ -import axios from 'axios'; -import type { AxiosRequestConfig, AxiosResponse } from 'axios'; -import { Message, Modal } from '@arco-design/web-vue'; -import { useUserStore } from '@/store'; -import { getToken } from '@/utils/auth'; +import axios from 'axios' +import type { AxiosRequestConfig, AxiosResponse } from 'axios' +import { Message, Modal } from '@arco-design/web-vue' +import { useUserStore } from '@/store' +import { getToken } from '@/utils/auth' export interface HttpResponse { status: number; @@ -12,7 +12,7 @@ export interface HttpResponse { } if (import.meta.env.VITE_API_BASE_URL) { - axios.defaults.baseURL = import.meta.env.VITE_API_BASE_URL; + axios.defaults.baseURL = import.meta.env.VITE_API_BASE_URL } axios.interceptors.request.use( @@ -21,30 +21,30 @@ axios.interceptors.request.use( // this example using the JWT token // Authorization is a custom headers key // please modify it according to the actual situation - const token = getToken(); + const token = getToken() if (token) { if (!config.headers) { - config.headers = {}; + config.headers = {} } - config.headers.Authorization = `Bearer ${token}`; + config.headers.Authorization = `Bearer ${token}` } - return config; + return config }, (error) => { // do something - return Promise.reject(error); - } -); + return Promise.reject(error) + }, +) // add response interceptors axios.interceptors.response.use( (response: AxiosResponse) => { - const res = response.data; + const res = response.data // if the custom code is not 20000, it is judged as an error. if (res.code !== 20000) { Message.error({ content: res.msg || 'Error', duration: 5 * 1000, - }); + }) // 50008: Illegal token; 50012: Other clients logged in; 50014: Token expired; if ( [50008, 50012, 50014].includes(res.code) && @@ -56,22 +56,22 @@ axios.interceptors.response.use( 'You have been logged out, you can cancel to stay on this page, or log in again', okText: 'Re-Login', async onOk() { - const userStore = useUserStore(); + const userStore = useUserStore() - await userStore.logout(); - window.location.reload(); + await userStore.logout() + window.location.reload() }, - }); + }) } - return Promise.reject(new Error(res.msg || 'Error')); + return Promise.reject(new Error(res.msg || 'Error')) } - return res; + return res }, (error) => { Message.error({ content: error.msg || 'Request Error', duration: 5 * 1000, - }); - return Promise.reject(error); - } -); + }) + return Promise.reject(error) + }, +) diff --git a/src/api/message.ts b/src/api/message.ts index e2d60ee..efb3deb 100644 --- a/src/api/message.ts +++ b/src/api/message.ts @@ -1,4 +1,4 @@ -import axios from 'axios'; +import axios from 'axios' export interface MessageRecord { id: number; @@ -14,7 +14,7 @@ export interface MessageRecord { export type MessageListType = MessageRecord[]; export function queryMessageList() { - return axios.post('/api/message/list'); + return axios.post('/api/message/list') } interface MessageStatus { @@ -22,7 +22,7 @@ interface MessageStatus { } export function setMessageStatus(data: MessageStatus) { - return axios.post('/api/message/read', data); + return axios.post('/api/message/read', data) } export interface ChatRecord { @@ -34,5 +34,5 @@ export interface ChatRecord { } export function queryChatList() { - return axios.post('/api/chat/list'); + return axios.post('/api/chat/list') } diff --git a/src/api/user.ts b/src/api/user.ts index 35b8812..51c8594 100644 --- a/src/api/user.ts +++ b/src/api/user.ts @@ -1,27 +1,30 @@ -import axios from 'axios'; -import type { RouteRecordNormalized } from 'vue-router'; -import { UserState } from '@/store/modules/user/types'; +import axios from 'axios' +import type { RouteRecordNormalized } from 'vue-router' +import { UserState } from '@/store/modules/user/types' export interface LoginData { - username: string; - password: string; + username: string + password: string + client_id: string + client_secret: string + grant_type: string } export interface LoginRes { token: string; } export function login(data: LoginData) { - return axios.post('/api/user/login', data); + return axios.post('/auth/oauth/token', data) } export function logout() { - return axios.post('/api/user/logout'); + return axios.post('/api/user/logout') } export function getUserInfo() { - return axios.post('/api/user/info'); + return axios.post('/api/user/info') } export function getMenuList() { - return axios.post('/api/user/menu'); + return axios.post('/api/user/menu') } diff --git a/src/components/breadcrumb/index.vue b/src/components/breadcrumb/index.vue index e4c9f13..fdd9d09 100644 --- a/src/components/breadcrumb/index.vue +++ b/src/components/breadcrumb/index.vue @@ -10,23 +10,25 @@ diff --git a/src/components/global-setting/block.vue b/src/components/global-setting/block.vue index 3359774..596cfc6 100644 --- a/src/components/global-setting/block.vue +++ b/src/components/global-setting/block.vue @@ -14,9 +14,9 @@ diff --git a/src/locale/en-US.ts b/src/locale/en-US.ts index b6fc8cc..28c373f 100644 --- a/src/locale/en-US.ts +++ b/src/locale/en-US.ts @@ -1,11 +1,11 @@ -import localeMessageBox from '@/components/message-box/locale/en-US'; -import localeTabBar from '@/components/tab-bar/locale/en-US'; -import localeLogin from '@/views/login/locale/en-US'; +import localeMessageBox from '@/components/message-box/locale/en-US' +import localeTabBar from '@/components/tab-bar/locale/en-US' +import localeLogin from '@/views/login/locale/en-US' -import localeWorkplace from '@/views/dashboard/workplace/locale/en-US'; -import localeUserCenter from '@/views/system/user/locale/en-US'; +import localeWorkplace from '@/views/dashboard/workplace/locale/en-US' +import localeUserCenter from '@/views/system/user/locale/en-US' -import localeSettings from './en-US/settings'; +import localeSettings from './en-US/settings' export default { 'menu.dashboard': 'Dashboard', @@ -30,4 +30,4 @@ export default { ...localeWorkplace, ...localeUserCenter, 'menu.system': 'System', -}; +} diff --git a/src/locale/en-US/settings.ts b/src/locale/en-US/settings.ts index 89bb123..9968f04 100644 --- a/src/locale/en-US/settings.ts +++ b/src/locale/en-US/settings.ts @@ -25,4 +25,4 @@ export default { 'settings.color.tooltip': '10 gradient colors generated according to the theme color', 'settings.menuFromServer': 'Menu From Server', -}; +} diff --git a/src/locale/index.ts b/src/locale/index.ts index bd241b2..8781a55 100644 --- a/src/locale/index.ts +++ b/src/locale/index.ts @@ -1,12 +1,12 @@ -import { createI18n } from 'vue-i18n'; -import en from './en-US'; -import cn from './zh-CN'; +import { createI18n } from 'vue-i18n' +import en from './en-US' +import cn from './zh-CN' export const LOCALE_OPTIONS = [ { label: '中文', value: 'zh-CN' }, { label: 'English', value: 'en-US' }, -]; -const defaultLocale = localStorage.getItem('arco-locale') || 'zh-CN'; +] +const defaultLocale = localStorage.getItem('arco-locale') || 'zh-CN' const i18n = createI18n({ locale: defaultLocale, @@ -16,6 +16,6 @@ const i18n = createI18n({ 'en-US': en, 'zh-CN': cn, }, -}); +}) -export default i18n; +export default i18n diff --git a/src/locale/zh-CN.ts b/src/locale/zh-CN.ts index d6eb703..4527cfd 100644 --- a/src/locale/zh-CN.ts +++ b/src/locale/zh-CN.ts @@ -1,11 +1,11 @@ -import localeMessageBox from '@/components/message-box/locale/zh-CN'; -import localeTabBar from '@/components/tab-bar/locale/zh-CN'; -import localeLogin from '@/views/login/locale/zh-CN'; +import localeMessageBox from '@/components/message-box/locale/zh-CN' +import localeTabBar from '@/components/tab-bar/locale/zh-CN' +import localeLogin from '@/views/login/locale/zh-CN' -import localeWorkplace from '@/views/dashboard/workplace/locale/zh-CN'; -import localeUserCenter from '@/views/system/user/locale/zh-CN'; +import localeWorkplace from '@/views/dashboard/workplace/locale/zh-CN' +import localeUserCenter from '@/views/system/user/locale/zh-CN' -import localeSettings from './zh-CN/settings'; +import localeSettings from './zh-CN/settings' export default { 'menu.dashboard': '仪表盘', @@ -30,4 +30,4 @@ export default { ...localeWorkplace, ...localeUserCenter, 'menu.system': '系统管理', -}; +} diff --git a/src/locale/zh-CN/settings.ts b/src/locale/zh-CN/settings.ts index e762418..af2a7b4 100644 --- a/src/locale/zh-CN/settings.ts +++ b/src/locale/zh-CN/settings.ts @@ -25,4 +25,4 @@ export default { 'settings.color.tooltip': '根据主题颜色生成的 10 个梯度色(将配置复制到项目中,主题色才能对亮色 / 暗黑模式同时生效)', 'settings.menuFromServer': '菜单来源于后台', -}; +} diff --git a/src/main.ts b/src/main.ts index 4024bda..3099b24 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,26 +1,26 @@ -import { createApp } from 'vue'; -import ArcoVue from '@arco-design/web-vue'; -import ArcoVueIcon from '@arco-design/web-vue/es/icon'; -import globalComponents from '@/components'; -import router from './router'; -import store from './store'; -import i18n from './locale'; -import directive from './directive'; -import './mock'; -import App from './App.vue'; -import '@arco-design/web-vue/dist/arco.css'; -import '@/assets/style/global.less'; -import '@/api/interceptor'; +import { createApp } from 'vue' +import ArcoVue from '@arco-design/web-vue' +import ArcoVueIcon from '@arco-design/web-vue/es/icon' +import globalComponents from '@/components' +import router from './router' +import store from './store' +import i18n from './locale' +import directive from './directive' +import './mock' +import App from './App.vue' +import '@arco-design/web-vue/dist/arco.css' +import '@/assets/style/global.less' +import '@/api/interceptor' -const app = createApp(App); +const app = createApp(App) -app.use(ArcoVue, {}); -app.use(ArcoVueIcon); +app.use(ArcoVue, {}) +app.use(ArcoVueIcon) -app.use(router); -app.use(store); -app.use(i18n); -app.use(globalComponents); -app.use(directive); +app.use(router) +app.use(store) +app.use(i18n) +app.use(globalComponents) +app.use(directive) -app.mount('#app'); +app.mount('#app') diff --git a/src/mock/index.ts b/src/mock/index.ts index cf1af17..f50f97e 100644 --- a/src/mock/index.ts +++ b/src/mock/index.ts @@ -1,10 +1,10 @@ -import Mock from 'mockjs'; +import Mock from 'mockjs' -import './user'; -import './message-box'; +import './user' +import './message-box' -import '@/views/dashboard/workplace/mock'; +import '@/views/dashboard/workplace/mock' Mock.setup({ timeout: '600-1000', -}); +}) diff --git a/src/mock/message-box.ts b/src/mock/message-box.ts index 6449e68..60b48bc 100644 --- a/src/mock/message-box.ts +++ b/src/mock/message-box.ts @@ -1,7 +1,7 @@ -import Mock from 'mockjs'; -import setupMock, { successResponseWrap } from '@/utils/setup-mock'; +import Mock from 'mockjs' +import setupMock, { successResponseWrap } from '@/utils/setup-mock' -const haveReadIds: number[] = []; +const haveReadIds: number[] = [] const getMessageList = () => { return [ { @@ -67,19 +67,19 @@ const getMessageList = () => { ].map((item) => ({ ...item, status: haveReadIds.indexOf(item.id) === -1 ? 0 : 1, - })); -}; + })) +} setupMock({ setup: () => { Mock.mock(new RegExp('/api/message/list'), () => { - return successResponseWrap(getMessageList()); - }); + return successResponseWrap(getMessageList()) + }) Mock.mock(new RegExp('/api/message/read'), (params: { body: string }) => { - const { ids } = JSON.parse(params.body); - haveReadIds.push(...(ids || [])); - return successResponseWrap(true); - }); + const { ids } = JSON.parse(params.body) + haveReadIds.push(...(ids || [])) + return successResponseWrap(true) + }) }, -}); +}) diff --git a/src/mock/user.ts b/src/mock/user.ts index 45b2a1e..c712df6 100644 --- a/src/mock/user.ts +++ b/src/mock/user.ts @@ -1,20 +1,21 @@ -import Mock from 'mockjs'; +import Mock from 'mockjs' import setupMock, { successResponseWrap, failResponseWrap, -} from '@/utils/setup-mock'; +} from '@/utils/setup-mock' -import { MockParams } from '@/types/mock'; -import { isLogin } from '@/utils/auth'; +import { MockParams } from '@/types/mock' +import { isLogin } from '@/utils/auth' setupMock({ + mock: false, setup() { // Mock.XHR.prototype.withCredentials = true; // 用户信息 Mock.mock(new RegExp('/api/user/info'), () => { if (isLogin()) { - const role = window.localStorage.getItem('userRole') || 'admin'; + const role = window.localStorage.getItem('userRole') || 'admin' return successResponseWrap({ name: '王立群', avatar: @@ -33,39 +34,39 @@ setupMock({ accountId: '15012312300', certification: 1, role, - }); + }) } - return failResponseWrap(null, '未登录', 50008); - }); + return failResponseWrap(null, '未登录', 50008) + }) // 登录 Mock.mock(new RegExp('/api/user/login'), (params: MockParams) => { - const { username, password } = JSON.parse(params.body); + const { username, password } = JSON.parse(params.body) if (!username) { - return failResponseWrap(null, '用户名不能为空', 50000); + return failResponseWrap(null, '用户名不能为空', 50000) } if (!password) { - return failResponseWrap(null, '密码不能为空', 50000); + return failResponseWrap(null, '密码不能为空', 50000) } if (username === 'admin' && password === 'admin') { - window.localStorage.setItem('userRole', 'admin'); + window.localStorage.setItem('userRole', 'admin') return successResponseWrap({ token: '12345', - }); + }) } if (username === 'user' && password === 'user') { - window.localStorage.setItem('userRole', 'user'); + window.localStorage.setItem('userRole', 'user') return successResponseWrap({ token: '54321', - }); + }) } - return failResponseWrap(null, '账号或者密码错误', 50000); - }); + return failResponseWrap(null, '账号或者密码错误', 50000) + }) // 登出 Mock.mock(new RegExp('/api/user/logout'), () => { - return successResponseWrap(null); - }); + return successResponseWrap(null) + }) // 用户的服务端菜单 Mock.mock(new RegExp('/api/user/menu'), () => { @@ -98,8 +99,8 @@ setupMock({ }, ], }, - ]; - return successResponseWrap(menuList); - }); + ] + return successResponseWrap(menuList) + }) }, -}); +}) diff --git a/src/router/appMenus/index.ts b/src/router/appMenus/index.ts index 2136c96..a96968e 100644 --- a/src/router/appMenus/index.ts +++ b/src/router/appMenus/index.ts @@ -1,16 +1,16 @@ -import { appRoutes, appExternalRoutes } from '../routes'; +import { appRoutes, appExternalRoutes } from '../routes' -const mixinRoutes = [...appRoutes, ...appExternalRoutes]; +const mixinRoutes = [...appRoutes, ...appExternalRoutes] const appClientMenus = mixinRoutes.map((el) => { - const { name, path, meta, redirect, children } = el; + const { name, path, meta, redirect, children } = el return { name, path, meta, redirect, children, - }; -}); + } +}) -export default appClientMenus; +export default appClientMenus diff --git a/src/router/constants.ts b/src/router/constants.ts index 7c33ca4..84a24a1 100644 --- a/src/router/constants.ts +++ b/src/router/constants.ts @@ -1,10 +1,10 @@ -export const DEFAULT_LAYOUT = () => import('@/layout/default-layout.vue'); +export const DEFAULT_LAYOUT = () => import('@/layout/default-layout.vue') export const WHITE_LIST = [ { name: 'notFound', children: [] }, { name: 'login', children: [] }, -]; +] export const NOT_FOUND = { name: 'notFound', -}; +} diff --git a/src/router/guard/index.ts b/src/router/guard/index.ts index bedc28d..9fc0b9e 100644 --- a/src/router/guard/index.ts +++ b/src/router/guard/index.ts @@ -1,17 +1,17 @@ -import type { Router } from 'vue-router'; -import { setRouteEmitter } from '@/utils/route-listener'; -import setupUserLoginInfoGuard from './userLoginInfo'; -import setupPermissionGuard from './permission'; +import type { Router } from 'vue-router' +import { setRouteEmitter } from '@/utils/route-listener' +import setupUserLoginInfoGuard from './userLoginInfo' +import setupPermissionGuard from './permission' function setupPageGuard(router: Router) { router.beforeEach(async (to) => { // emit route change - setRouteEmitter(to); - }); + setRouteEmitter(to) + }) } export default function createRouteGuard(router: Router) { - setupPageGuard(router); - setupUserLoginInfoGuard(router); - setupPermissionGuard(router); + setupPageGuard(router) + setupUserLoginInfoGuard(router) + setupPermissionGuard(router) } diff --git a/src/router/guard/permission.ts b/src/router/guard/permission.ts index ad3724e..4014bc7 100644 --- a/src/router/guard/permission.ts +++ b/src/router/guard/permission.ts @@ -1,17 +1,17 @@ -import type { Router, RouteRecordNormalized } from 'vue-router'; -import NProgress from 'nprogress'; // progress bar +import type { Router, RouteRecordNormalized } from 'vue-router' +import NProgress from 'nprogress' // progress bar -import usePermission from '@/hooks/permission'; -import { useUserStore, useAppStore } from '@/store'; -import { appRoutes } from '../routes'; -import { WHITE_LIST, NOT_FOUND } from '../constants'; +import usePermission from '@/hooks/permission' +import { useUserStore, useAppStore } from '@/store' +import { appRoutes } from '../routes' +import { WHITE_LIST, NOT_FOUND } from '../constants' export default function setupPermissionGuard(router: Router) { router.beforeEach(async (to, from, next) => { - const appStore = useAppStore(); - const userStore = useUserStore(); - const Permission = usePermission(); - const permissionsAllow = Permission.accessRouter(to); + const appStore = useAppStore() + const userStore = useUserStore() + const Permission = usePermission() + const permissionsAllow = Permission.accessRouter(to) if (appStore.menuFromServer) { // 针对来自服务端的菜单配置进行处理 // Handle routing configuration from the server @@ -22,34 +22,34 @@ export default function setupPermissionGuard(router: Router) { !appStore.appAsyncMenus.length && !WHITE_LIST.find((el) => el.name === to.name) ) { - await appStore.fetchServerMenuConfig(); + await appStore.fetchServerMenuConfig() } - const serverMenuConfig = [...appStore.appAsyncMenus, ...WHITE_LIST]; + const serverMenuConfig = [...appStore.appAsyncMenus, ...WHITE_LIST] - let exist = false; + let exist = false while (serverMenuConfig.length && !exist) { - const element = serverMenuConfig.shift(); - if (element?.name === to.name) exist = true; + const element = serverMenuConfig.shift() + if (element?.name === to.name) exist = true if (element?.children) { serverMenuConfig.push( - ...(element.children as unknown as RouteRecordNormalized[]) - ); + ...(element.children as unknown as RouteRecordNormalized[]), + ) } } if (exist && permissionsAllow) { - next(); - } else next(NOT_FOUND); + next() + } else next(NOT_FOUND) } else { // eslint-disable-next-line no-lonely-if - if (permissionsAllow) next(); + if (permissionsAllow) next() else { const destination = Permission.findFirstPermissionRoute(appRoutes, userStore.role) || - NOT_FOUND; - next(destination); + NOT_FOUND + next(destination) } } - NProgress.done(); - }); + NProgress.done() + }) } diff --git a/src/router/guard/userLoginInfo.ts b/src/router/guard/userLoginInfo.ts index 72bb441..0d7526b 100644 --- a/src/router/guard/userLoginInfo.ts +++ b/src/router/guard/userLoginInfo.ts @@ -1,20 +1,20 @@ -import type { Router, LocationQueryRaw } from 'vue-router'; -import NProgress from 'nprogress'; // progress bar +import type { Router, LocationQueryRaw } from 'vue-router' +import NProgress from 'nprogress' // progress bar -import { useUserStore } from '@/store'; -import { isLogin } from '@/utils/auth'; +import { useUserStore } from '@/store' +import { isLogin } from '@/utils/auth' export default function setupUserLoginInfoGuard(router: Router) { router.beforeEach(async (to, from, next) => { - NProgress.start(); - const userStore = useUserStore(); + NProgress.start() + const userStore = useUserStore() if (isLogin()) { if (userStore.role) { - next(); + next() } else { try { - await userStore.info(); - next(); + await userStore.info() + next() } catch (error) { next({ name: 'login', @@ -22,13 +22,13 @@ export default function setupUserLoginInfoGuard(router: Router) { redirect: to.name, ...to.query, } as LocationQueryRaw, - }); + }) } } } else { if (to.name === 'login') { - next(); - return; + next() + return } next({ name: 'login', @@ -36,7 +36,7 @@ export default function setupUserLoginInfoGuard(router: Router) { redirect: to.name, ...to.query, } as LocationQueryRaw, - }); + }) } - }); + }) } diff --git a/src/router/index.ts b/src/router/index.ts index f0da459..6fe449a 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -1,11 +1,11 @@ -import { createRouter, createWebHistory } from 'vue-router'; -import NProgress from 'nprogress'; // progress bar -import 'nprogress/nprogress.css'; +import { createRouter, createWebHistory } from 'vue-router' +import NProgress from 'nprogress' // progress bar +import 'nprogress/nprogress.css' -import { appRoutes } from './routes'; -import createRouteGuard from './guard'; +import { appRoutes } from './routes' +import createRouteGuard from './guard' -NProgress.configure({ showSpinner: false }); // NProgress Configuration +NProgress.configure({ showSpinner: false }) // NProgress Configuration const router = createRouter({ history: createWebHistory(), @@ -30,10 +30,10 @@ const router = createRouter({ }, ], scrollBehavior() { - return { top: 0 }; + return { top: 0 } }, -}); +}) -createRouteGuard(router); +createRouteGuard(router) -export default router; +export default router diff --git a/src/router/routes/externalModules/arco.ts b/src/router/routes/externalModules/arco.ts index d9a76eb..e697f04 100644 --- a/src/router/routes/externalModules/arco.ts +++ b/src/router/routes/externalModules/arco.ts @@ -7,4 +7,4 @@ export default { requiresAuth: true, order: 8, }, -}; +} diff --git a/src/router/routes/externalModules/faq.ts b/src/router/routes/externalModules/faq.ts index 232b81d..9338108 100644 --- a/src/router/routes/externalModules/faq.ts +++ b/src/router/routes/externalModules/faq.ts @@ -7,4 +7,4 @@ export default { requiresAuth: true, order: 9, }, -}; +} diff --git a/src/router/routes/index.ts b/src/router/routes/index.ts index ab6e5f5..deba0a9 100644 --- a/src/router/routes/index.ts +++ b/src/router/routes/index.ts @@ -1,33 +1,33 @@ -import type { RouteRecordNormalized } from 'vue-router'; +import type { RouteRecordNormalized } from 'vue-router' -const modules = import.meta.globEager('./modules/*.ts'); -const externalModules = import.meta.globEager('./externalModules/*.ts'); +const modules = import.meta.globEager('./modules/*.ts') +const externalModules = import.meta.globEager('./externalModules/*.ts') function formatModules(_modules: any, result: RouteRecordNormalized[]) { Object.keys(_modules).forEach((key) => { - const defaultModule = _modules[key].default; - if (!defaultModule) return; + const defaultModule = _modules[key].default + if (!defaultModule) return const moduleList = Array.isArray(defaultModule) ? [...defaultModule] - : [defaultModule]; - result.push(...moduleList); - }); - return result; + : [defaultModule] + result.push(...moduleList) + }) + return result } -export const appRoutes: RouteRecordNormalized[] = formatModules(modules, []); +export const appRoutes: RouteRecordNormalized[] = formatModules(modules, []) export const appExternalRoutes: RouteRecordNormalized[] = formatModules( externalModules, - [] -); + [], +) // Avoid circular references, put here -export const DEFAULT_ROUTE_NAME = 'Workplace'; +export const DEFAULT_ROUTE_NAME = 'Workplace' export const DEFAULT_ROUTE = { title: 'menu.dashboard.workplace', name: DEFAULT_ROUTE_NAME, fullPath: '/dashboard/workplace', -}; +} diff --git a/src/router/routes/modules/dashboard.ts b/src/router/routes/modules/dashboard.ts index f97e7a0..11db168 100644 --- a/src/router/routes/modules/dashboard.ts +++ b/src/router/routes/modules/dashboard.ts @@ -1,5 +1,5 @@ -import { DEFAULT_LAYOUT } from '@/router/constants'; -import { AppRouteRecordRaw } from '../types'; +import { DEFAULT_LAYOUT } from '@/router/constants' +import { AppRouteRecordRaw } from '../types' const DASHBOARD: AppRouteRecordRaw = { path: '/dashboard', @@ -23,6 +23,6 @@ const DASHBOARD: AppRouteRecordRaw = { }, }, ], -}; +} -export default DASHBOARD; +export default DASHBOARD diff --git a/src/router/routes/modules/system.ts b/src/router/routes/modules/system.ts index 6185540..a48fa24 100644 --- a/src/router/routes/modules/system.ts +++ b/src/router/routes/modules/system.ts @@ -1,5 +1,5 @@ -import { DEFAULT_LAYOUT } from '@/router/constants'; -import { AppRouteRecordRaw } from '../types'; +import { DEFAULT_LAYOUT } from '@/router/constants' +import { AppRouteRecordRaw } from '../types' const SYSADMIN: AppRouteRecordRaw = { path: '/system', @@ -23,6 +23,6 @@ const SYSADMIN: AppRouteRecordRaw = { }, }, ], -}; +} -export default SYSADMIN; +export default SYSADMIN diff --git a/src/router/routes/types.ts b/src/router/routes/types.ts index 6b8e8d7..5903ce2 100644 --- a/src/router/routes/types.ts +++ b/src/router/routes/types.ts @@ -1,5 +1,5 @@ -import { defineComponent } from 'vue'; -import type { RouteMeta, NavigationGuard } from 'vue-router'; +import { defineComponent } from 'vue' +import type { RouteMeta, NavigationGuard } from 'vue-router' export type Component = | ReturnType diff --git a/src/router/typings.d.ts b/src/router/typings.d.ts index 5ccaa70..dd15efb 100644 --- a/src/router/typings.d.ts +++ b/src/router/typings.d.ts @@ -1,4 +1,4 @@ -import 'vue-router'; +import 'vue-router' declare module 'vue-router' { interface RouteMeta { diff --git a/src/store/index.ts b/src/store/index.ts index 3d3035f..2795871 100644 --- a/src/store/index.ts +++ b/src/store/index.ts @@ -1,9 +1,9 @@ -import { createPinia } from 'pinia'; -import useAppStore from './modules/app'; -import useUserStore from './modules/user'; -import useTabBarStore from './modules/tab-bar'; +import { createPinia } from 'pinia' +import useAppStore from './modules/app' +import useUserStore from './modules/user' +import useTabBarStore from './modules/tab-bar' -const pinia = createPinia(); +const pinia = createPinia() -export { useAppStore, useUserStore, useTabBarStore }; -export default pinia; +export { useAppStore, useUserStore, useTabBarStore } +export default pinia diff --git a/src/store/modules/app/index.ts b/src/store/modules/app/index.ts index 77c6c35..c3a3685 100644 --- a/src/store/modules/app/index.ts +++ b/src/store/modules/app/index.ts @@ -1,23 +1,23 @@ -import { defineStore } from 'pinia'; -import { Notification } from '@arco-design/web-vue'; -import type { NotificationReturn } from '@arco-design/web-vue/es/notification/interface'; -import type { RouteRecordNormalized } from 'vue-router'; -import defaultSettings from '@/config/settings.json'; -import { getMenuList } from '@/api/user'; -import { AppState } from './types'; +import { defineStore } from 'pinia' +import { Notification } from '@arco-design/web-vue' +import type { NotificationReturn } from '@arco-design/web-vue/es/notification/interface' +import type { RouteRecordNormalized } from 'vue-router' +import defaultSettings from '@/config/settings.json' +import { getMenuList } from '@/api/user' +import { AppState } from './types' const useAppStore = defineStore('app', { state: (): AppState => ({ ...defaultSettings }), getters: { appCurrentSetting(state: AppState): AppState { - return { ...state }; + return { ...state } }, appDevice(state: AppState) { - return state.device; + return state.device }, appAsyncMenus(state: AppState): RouteRecordNormalized[] { - return state.serverMenu as unknown as RouteRecordNormalized[]; + return state.serverMenu as unknown as RouteRecordNormalized[] }, }, @@ -25,53 +25,53 @@ const useAppStore = defineStore('app', { // Update app settings updateSettings(partial: Partial) { // @ts-ignore-next-line - this.$patch(partial); + this.$patch(partial) }, // Change theme color toggleTheme(dark: boolean) { if (dark) { - this.theme = 'dark'; - document.body.setAttribute('arco-theme', 'dark'); + this.theme = 'dark' + document.body.setAttribute('arco-theme', 'dark') } else { - this.theme = 'light'; - document.body.removeAttribute('arco-theme'); + this.theme = 'light' + document.body.removeAttribute('arco-theme') } }, toggleDevice(device: string) { - this.device = device; + this.device = device }, toggleMenu(value: boolean) { - this.hideMenu = value; + this.hideMenu = value }, async fetchServerMenuConfig() { - let notifyInstance: NotificationReturn | null = null; + let notifyInstance: NotificationReturn | null = null try { notifyInstance = Notification.info({ id: 'menuNotice', // Keep the instance id the same content: 'loading', closable: true, - }); - const { data } = await getMenuList(); - this.serverMenu = data; + }) + const { data } = await getMenuList() + this.serverMenu = data notifyInstance = Notification.success({ id: 'menuNotice', content: 'success', closable: true, - }); + }) } catch (error) { // eslint-disable-next-line @typescript-eslint/no-unused-vars notifyInstance = Notification.error({ id: 'menuNotice', content: 'error', closable: true, - }); + }) } }, clearServerMenu() { - this.serverMenu = []; + this.serverMenu = [] }, }, -}); +}) -export default useAppStore; +export default useAppStore diff --git a/src/store/modules/app/types.ts b/src/store/modules/app/types.ts index e45b2c4..e958c35 100644 --- a/src/store/modules/app/types.ts +++ b/src/store/modules/app/types.ts @@ -1,4 +1,4 @@ -import type { RouteRecordNormalized } from 'vue-router'; +import type { RouteRecordNormalized } from 'vue-router' export interface AppState { theme: string; diff --git a/src/store/modules/tab-bar/index.ts b/src/store/modules/tab-bar/index.ts index 2980952..eca3e60 100644 --- a/src/store/modules/tab-bar/index.ts +++ b/src/store/modules/tab-bar/index.ts @@ -1,18 +1,18 @@ -import type { RouteLocationNormalized } from 'vue-router'; -import { defineStore } from 'pinia'; -import { DEFAULT_ROUTE, DEFAULT_ROUTE_NAME } from '@/router/routes/index'; -import { TabBarState, TagProps } from './types'; +import type { RouteLocationNormalized } from 'vue-router' +import { defineStore } from 'pinia' +import { DEFAULT_ROUTE, DEFAULT_ROUTE_NAME } from '@/router/routes/index' +import { TabBarState, TagProps } from './types' const formatTag = (route: RouteLocationNormalized): TagProps => { - const { name, meta, fullPath, query } = route; + const { name, meta, fullPath, query } = route return { title: meta.locale || '', name: String(name), fullPath, query, ignoreCache: meta.ignoreCache, - }; -}; + } +} const useAppStore = defineStore('tabBar', { state: (): TabBarState => ({ @@ -22,39 +22,39 @@ const useAppStore = defineStore('tabBar', { getters: { getTabList(): TagProps[] { - return this.tagList; + return this.tagList }, getCacheList(): string[] { - return Array.from(this.cacheTabList); + return Array.from(this.cacheTabList) }, }, actions: { updateTabList(route: RouteLocationNormalized) { - this.tagList.push(formatTag(route)); + this.tagList.push(formatTag(route)) if (!route.meta.ignoreCache) { - this.cacheTabList.add(route.name as string); + this.cacheTabList.add(route.name as string) } }, deleteTag(idx: number, tag: TagProps) { - this.tagList.splice(idx, 1); - this.cacheTabList.delete(tag.name); + this.tagList.splice(idx, 1) + this.cacheTabList.delete(tag.name) }, freshTabList(tags: TagProps[]) { - this.tagList = tags; - this.cacheTabList.clear(); + this.tagList = tags + this.cacheTabList.clear() // 要先判断ignoreCache this.tagList .filter((el) => !el.ignoreCache) .map((el) => el.name) - .forEach((x) => this.cacheTabList.add(x)); + .forEach((x) => this.cacheTabList.add(x)) }, resetTabList() { - this.tagList = [DEFAULT_ROUTE]; - this.cacheTabList.clear(); - this.cacheTabList.add(DEFAULT_ROUTE_NAME); + this.tagList = [DEFAULT_ROUTE] + this.cacheTabList.clear() + this.cacheTabList.add(DEFAULT_ROUTE_NAME) }, }, -}); +}) -export default useAppStore; +export default useAppStore diff --git a/src/store/modules/user/index.ts b/src/store/modules/user/index.ts index 2c9316e..61f7472 100644 --- a/src/store/modules/user/index.ts +++ b/src/store/modules/user/index.ts @@ -1,14 +1,14 @@ -import { defineStore } from 'pinia'; +import { defineStore } from 'pinia' import { login as userLogin, logout as userLogout, getUserInfo, LoginData, -} from '@/api/user'; -import { setToken, clearToken } from '@/utils/auth'; -import { removeRouteListener } from '@/utils/route-listener'; -import { UserState } from './types'; -import useAppStore from '../app'; +} from '@/api/user' +import { setToken, clearToken } from '@/utils/auth' +import { removeRouteListener } from '@/utils/route-listener' +import { UserState } from './types' +import useAppStore from '../app' const useUserStore = defineStore('user', { state: (): UserState => ({ @@ -32,60 +32,66 @@ const useUserStore = defineStore('user', { getters: { userInfo(state: UserState): UserState { - return { ...state }; + return { ...state } }, }, actions: { switchRoles() { return new Promise((resolve) => { - this.role = this.role === 'user' ? 'admin' : 'user'; - resolve(this.role); - }); + this.role = this.role === 'user' ? 'admin' : 'user' + resolve(this.role) + }) }, // Set user's information setInfo(partial: Partial) { - this.$patch(partial); + this.$patch(partial) }, // Reset user's information resetInfo() { - this.$reset(); + this.$reset() }, // Get user's information async info() { - const res = await getUserInfo(); + const res = await getUserInfo() - this.setInfo(res.data); + this.setInfo(res.data) }, // Login async login(loginForm: LoginData) { try { - const res = await userLogin(loginForm); - setToken(res.data.token); + loginForm = { + ...loginForm, + grant_type: 'password', + client_id: 'example-ui', + client_secret: 'example-ui', + } + const res = await userLogin(loginForm) + setToken(res.data.token) } catch (err) { - clearToken(); - throw err; + clearToken() + throw err } }, logoutCallBack() { - const appStore = useAppStore(); - this.resetInfo(); - clearToken(); - removeRouteListener(); - appStore.clearServerMenu(); + const appStore = useAppStore() + this.resetInfo() + clearToken() + removeRouteListener() + appStore.clearServerMenu() }, // Logout async logout() { try { - await userLogout(); + await userLogout() } finally { - this.logoutCallBack(); + this.logoutCallBack() } }, }, -}); +}) -export default useUserStore; +export default useUserStore diff --git a/src/types/echarts.ts b/src/types/echarts.ts index ac4578a..e72dbaa 100644 --- a/src/types/echarts.ts +++ b/src/types/echarts.ts @@ -1,4 +1,4 @@ -import { CallbackDataParams } from 'echarts/types/dist/shared'; +import { CallbackDataParams } from 'echarts/types/dist/shared' export interface ToolTipFormatterParams extends CallbackDataParams { axisDim: string; diff --git a/src/utils/auth.ts b/src/utils/auth.ts index 1a87c0a..f2ea509 100644 --- a/src/utils/auth.ts +++ b/src/utils/auth.ts @@ -1,19 +1,19 @@ -const TOKEN_KEY = 'token'; +const TOKEN_KEY = 'token' const isLogin = () => { - return !!localStorage.getItem(TOKEN_KEY); -}; + return !!localStorage.getItem(TOKEN_KEY) +} const getToken = () => { - return localStorage.getItem(TOKEN_KEY); -}; + return localStorage.getItem(TOKEN_KEY) +} const setToken = (token: string) => { - localStorage.setItem(TOKEN_KEY, token); -}; + localStorage.setItem(TOKEN_KEY, token) +} const clearToken = () => { - localStorage.removeItem(TOKEN_KEY); -}; + localStorage.removeItem(TOKEN_KEY) +} -export { isLogin, getToken, setToken, clearToken }; +export { isLogin, getToken, setToken, clearToken } diff --git a/src/utils/env.ts b/src/utils/env.ts index 690d6c5..f371dc5 100644 --- a/src/utils/env.ts +++ b/src/utils/env.ts @@ -1,3 +1,3 @@ -const debug = process.env.NODE_ENV !== 'production'; +const debug = process.env.NODE_ENV !== 'production' -export default debug; +export default debug diff --git a/src/utils/event.ts b/src/utils/event.ts index c700d3d..a39f339 100644 --- a/src/utils/event.ts +++ b/src/utils/event.ts @@ -2,13 +2,13 @@ export function addEventListen( target: Window | HTMLElement, event: string, handler: EventListenerOrEventListenerObject, - capture = false + capture = false, ) { if ( target.addEventListener && typeof target.addEventListener === 'function' ) { - target.addEventListener(event, handler, capture); + target.addEventListener(event, handler, capture) } } @@ -16,12 +16,12 @@ export function removeEventListen( target: Window | HTMLElement, event: string, handler: EventListenerOrEventListenerObject, - capture = false + capture = false, ) { if ( target.removeEventListener && typeof target.removeEventListener === 'function' ) { - target.removeEventListener(event, handler, capture); + target.removeEventListener(event, handler, capture) } } diff --git a/src/utils/index.ts b/src/utils/index.ts index 197bab3..17616d8 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -2,24 +2,24 @@ type TargetContext = '_self' | '_parent' | '_blank' | '_top'; export const openWindow = ( url: string, - opts?: { target?: TargetContext; [key: string]: any } + opts?: { target?: TargetContext; [key: string]: any }, ) => { - const { target = '_blank', ...others } = opts || {}; + const { target = '_blank', ...others } = opts || {} window.open( url, target, Object.entries(others) .reduce((preValue: string[], curValue) => { - const [key, value] = curValue; - return [...preValue, `${key}=${value}`]; + const [key, value] = curValue + return [...preValue, `${key}=${value}`] }, []) - .join(',') - ); -}; + .join(','), + ) +} export const regexUrl = new RegExp( '^(?!mailto:)(?:(?:http|https|ftp)://)(?:\\S+(?::\\S*)?@)?(?:(?:(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}(?:\\.(?:[0-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))|(?:(?:[a-z\\u00a1-\\uffff0-9]+-?)*[a-z\\u00a1-\\uffff0-9]+)(?:\\.(?:[a-z\\u00a1-\\uffff0-9]+-?)*[a-z\\u00a1-\\uffff0-9]+)*(?:\\.(?:[a-z\\u00a1-\\uffff]{2,})))|localhost)(?::\\d{2,5})?(?:(/|\\?|#)[^\\s]*)?$', - 'i' -); + 'i', +) -export default null; +export default null diff --git a/src/utils/monitor.ts b/src/utils/monitor.ts index 7b49015..6bcc469 100644 --- a/src/utils/monitor.ts +++ b/src/utils/monitor.ts @@ -1,14 +1,14 @@ -import { App, ComponentPublicInstance } from 'vue'; -import axios from 'axios'; +import { App, ComponentPublicInstance } from 'vue' +import axios from 'axios' export default function handleError(Vue: App, baseUrl: string) { if (!baseUrl) { - return; + return } Vue.config.errorHandler = ( err: unknown, instance: ComponentPublicInstance | null, - info: string + info: string, ) => { // send error info axios.post(`${baseUrl}/report-error`, { @@ -23,6 +23,6 @@ export default function handleError(Vue: App, baseUrl: string) { // dom info // url info // ... - }); - }; + }) + } } diff --git a/src/utils/route-listener.ts b/src/utils/route-listener.ts index 0b79591..803ff4f 100644 --- a/src/utils/route-listener.ts +++ b/src/utils/route-listener.ts @@ -2,30 +2,30 @@ * Listening to routes alone would waste rendering performance. Use the publish-subscribe model for distribution management * 单独监听路由会浪费渲染性能。使用发布订阅模式去进行分发管理。 */ -import mitt, { Handler } from 'mitt'; -import type { RouteLocationNormalized } from 'vue-router'; +import mitt, { Handler } from 'mitt' +import type { RouteLocationNormalized } from 'vue-router' -const emitter = mitt(); +const emitter = mitt() -const key = Symbol('ROUTE_CHANGE'); +const key = Symbol('ROUTE_CHANGE') -let latestRoute: RouteLocationNormalized; +let latestRoute: RouteLocationNormalized export function setRouteEmitter(to: RouteLocationNormalized) { - emitter.emit(key, to); - latestRoute = to; + emitter.emit(key, to) + latestRoute = to } export function listenerRouteChange( handler: (route: RouteLocationNormalized) => void, - immediate = true + immediate = true, ) { - emitter.on(key, handler as Handler); + emitter.on(key, handler as Handler) if (immediate && latestRoute) { - handler(latestRoute); + handler(latestRoute) } } export function removeRouteListener() { - emitter.off(key); + emitter.off(key) } diff --git a/src/utils/setup-mock.ts b/src/utils/setup-mock.ts index 257da5d..4cec9cf 100644 --- a/src/utils/setup-mock.ts +++ b/src/utils/setup-mock.ts @@ -1,8 +1,8 @@ -import debug from './env'; +import debug from './env' export default ({ mock, setup }: { mock?: boolean; setup: () => void }) => { - if (mock !== false && debug) setup(); -}; + if (mock !== false && debug) setup() +} export const successResponseWrap = (data: unknown) => { return { @@ -10,8 +10,8 @@ export const successResponseWrap = (data: unknown) => { status: 'ok', msg: '请求成功', code: 20000, - }; -}; + } +} export const failResponseWrap = (data: unknown, msg: string, code = 50000) => { return { @@ -19,5 +19,5 @@ export const failResponseWrap = (data: unknown, msg: string, code = 50000) => { status: 'fail', msg, code, - }; -}; + } +} diff --git a/src/views/dashboard/workplace/components/announcement.vue b/src/views/dashboard/workplace/components/announcement.vue index e1d1a13..61562b3 100644 --- a/src/views/dashboard/workplace/components/announcement.vue +++ b/src/views/dashboard/workplace/components/announcement.vue @@ -46,7 +46,7 @@ label: '消息', content: '新增内容已经通过审核,详情请点击查看。', }, - ]; + ] diff --git a/src/views/dashboard/workplace/components/content-chart.vue b/src/views/dashboard/workplace/components/content-chart.vue index 98da70d..7010fc8 100644 --- a/src/views/dashboard/workplace/components/content-chart.vue +++ b/src/views/dashboard/workplace/components/content-chart.vue @@ -17,13 +17,13 @@ diff --git a/src/views/dashboard/workplace/components/popular-content.vue b/src/views/dashboard/workplace/components/popular-content.vue index 755e910..399db40 100644 --- a/src/views/dashboard/workplace/components/popular-content.vue +++ b/src/views/dashboard/workplace/components/popular-content.vue @@ -73,44 +73,48 @@ diff --git a/src/views/dashboard/workplace/components/recently-visited.vue b/src/views/dashboard/workplace/components/recently-visited.vue index 805c4f7..cc8edc1 100644 --- a/src/views/dashboard/workplace/components/recently-visited.vue +++ b/src/views/dashboard/workplace/components/recently-visited.vue @@ -34,7 +34,7 @@ text: 'workplace.advanced', icon: 'icon-settings', }, - ]; + ] diff --git a/src/views/system/user/index.vue b/src/views/system/user/index.vue index d2ddb03..ad6aec9 100644 --- a/src/views/system/user/index.vue +++ b/src/views/system/user/index.vue @@ -81,7 +81,7 @@ diff --git a/src/components/global-setting/block.vue b/src/components/global-setting/block.vue index 596cfc6..483405b 100644 --- a/src/components/global-setting/block.vue +++ b/src/components/global-setting/block.vue @@ -14,9 +14,9 @@ diff --git a/src/locale/en-US.ts b/src/locale/en-US.ts index 28c373f..f583548 100644 --- a/src/locale/en-US.ts +++ b/src/locale/en-US.ts @@ -9,9 +9,8 @@ import localeSettings from './en-US/settings' export default { 'menu.dashboard': 'Dashboard', - 'menu.server.dashboard': 'Dashboard-Server', - 'menu.server.workplace': 'Workplace-Server', - 'menu.server.monitor': 'Monitor-Server', + 'menu.dashboard.workplace': 'Workplace', + 'menu.monitor': 'Monitor', 'menu.list': 'List', 'menu.result': 'Result', 'menu.exception': 'Exception', diff --git a/src/locale/en-US/settings.ts b/src/locale/en-US/settings.ts index 9968f04..7f8b369 100644 --- a/src/locale/en-US/settings.ts +++ b/src/locale/en-US/settings.ts @@ -16,8 +16,8 @@ export default { 'settings.footer': 'Footer', 'settings.otherSettings': 'Other Settings', 'settings.colorWeak': 'Color Weak', - 'settings.alertContent': - 'After the configuration is only temporarily effective, if you want to really affect the project, click the "Copy Settings" button below and replace the configuration in settings.json.', + // eslint-disable-next-line max-len + 'settings.alertContent': 'After the configuration is only temporarily effective, if you want to really affect the project, click the "Copy Settings" button below and replace the configuration in settings.json.', 'settings.copySettings': 'Copy Settings', 'settings.copySettings.message': 'Copy succeeded, please paste to file src/settings.json.', diff --git a/src/locale/zh-CN.ts b/src/locale/zh-CN.ts index 4527cfd..e0f01f7 100644 --- a/src/locale/zh-CN.ts +++ b/src/locale/zh-CN.ts @@ -9,9 +9,8 @@ import localeSettings from './zh-CN/settings' export default { 'menu.dashboard': '仪表盘', - 'menu.server.dashboard': '仪表盘-服务端', - 'menu.server.workplace': '工作台-服务端', - 'menu.server.monitor': '实时监控-服务端', + 'menu.dashboard.workplace': '工作台', + 'menu.monitor': '实时监控', 'menu.list': '列表页', 'menu.result': '结果页', 'menu.exception': '异常页', diff --git a/src/mock/message-box.ts b/src/mock/message-box.ts index 60b48bc..2b6fb65 100644 --- a/src/mock/message-box.ts +++ b/src/mock/message-box.ts @@ -2,79 +2,75 @@ import Mock from 'mockjs' import setupMock, { successResponseWrap } from '@/utils/setup-mock' const haveReadIds: number[] = [] -const getMessageList = () => { - return [ - { - id: 1, - type: 'message', - title: '郑曦月', - subTitle: '的私信', - avatar: +const getMessageList = () => [ + { + id: 1, + type: 'message', + title: '郑曦月', + subTitle: '的私信', + avatar: '//p1-arco.byteimg.com/tos-cn-i-uwbnlip3yd/8361eeb82904210b4f55fab888fe8416.png~tplv-uwbnlip3yd-webp.webp', - content: '审批请求已发送,请查收', - time: '今天 12:30:01', - }, - { - id: 2, - type: 'message', - title: '宁波', - subTitle: '的回复', - avatar: + content: '审批请求已发送,请查收', + time: '今天 12:30:01', + }, + { + id: 2, + type: 'message', + title: '宁波', + subTitle: '的回复', + avatar: '//p1-arco.byteimg.com/tos-cn-i-uwbnlip3yd/3ee5f13fb09879ecb5185e440cef6eb9.png~tplv-uwbnlip3yd-webp.webp', - content: '此处 bug 已经修复', - time: '今天 12:30:01', - }, - { - id: 3, - type: 'message', - title: '宁波', - subTitle: '的回复', - avatar: + content: '此处 bug 已经修复', + time: '今天 12:30:01', + }, + { + id: 3, + type: 'message', + title: '宁波', + subTitle: '的回复', + avatar: '//p1-arco.byteimg.com/tos-cn-i-uwbnlip3yd/3ee5f13fb09879ecb5185e440cef6eb9.png~tplv-uwbnlip3yd-webp.webp', - content: '此处 bug 已经修复', - time: '今天 12:20:01', - }, - { - id: 4, - type: 'notice', - title: '续费通知', - subTitle: '', - avatar: '', - content: '您的产品使用期限即将截止,如需继续使用产品请前往购…', - time: '今天 12:20:01', - messageType: 3, - }, - { - id: 5, - type: 'notice', - title: '规则开通成功', - subTitle: '', - avatar: '', - content: '内容屏蔽规则于 2021-12-01 开通成功并生效', - time: '今天 12:20:01', - messageType: 1, - }, - { - id: 6, - type: 'todo', - title: '质检队列变更', - subTitle: '', - avatar: '', - content: '内容质检队列于 2021-12-01 19:50:23 进行变更,请重新…', - time: '今天 12:20:01', - messageType: 0, - }, - ].map((item) => ({ - ...item, - status: haveReadIds.indexOf(item.id) === -1 ? 0 : 1, - })) -} + content: '此处 bug 已经修复', + time: '今天 12:20:01', + }, + { + id: 4, + type: 'notice', + title: '续费通知', + subTitle: '', + avatar: '', + content: '您的产品使用期限即将截止,如需继续使用产品请前往购…', + time: '今天 12:20:01', + messageType: 3, + }, + { + id: 5, + type: 'notice', + title: '规则开通成功', + subTitle: '', + avatar: '', + content: '内容屏蔽规则于 2021-12-01 开通成功并生效', + time: '今天 12:20:01', + messageType: 1, + }, + { + id: 6, + type: 'todo', + title: '质检队列变更', + subTitle: '', + avatar: '', + content: '内容质检队列于 2021-12-01 19:50:23 进行变更,请重新…', + time: '今天 12:20:01', + messageType: 0, + }, +].map((item) => ({ + ...item, + status: haveReadIds.indexOf(item.id) === -1 ? 0 : 1, +})) setupMock({ setup: () => { - Mock.mock(new RegExp('/api/message/list'), () => { - return successResponseWrap(getMessageList()) - }) + Mock.mock(new RegExp('/api/message/list'), () => successResponseWrap(getMessageList())) Mock.mock(new RegExp('/api/message/read'), (params: { body: string }) => { const { ids } = JSON.parse(params.body) diff --git a/src/mock/user.ts b/src/mock/user.ts index c712df6..498aaa3 100644 --- a/src/mock/user.ts +++ b/src/mock/user.ts @@ -64,9 +64,7 @@ setupMock({ }) // 登出 - Mock.mock(new RegExp('/api/user/logout'), () => { - return successResponseWrap(null) - }) + Mock.mock(new RegExp('/api/user/logout'), () => successResponseWrap(null)) // 用户的服务端菜单 Mock.mock(new RegExp('/api/user/menu'), () => { @@ -75,7 +73,7 @@ setupMock({ path: '/dashboard', name: 'dashboard', meta: { - locale: 'menu.server.dashboard', + locale: 'menu.dashboard', requiresAuth: true, icon: 'icon-dashboard', order: 1, @@ -85,7 +83,7 @@ setupMock({ path: 'workplace', name: 'Workplace', meta: { - locale: 'menu.server.workplace', + locale: 'menu.workplace', requiresAuth: true, }, }, diff --git a/src/router/appMenus/index.ts b/src/router/appMenus/index.ts index a96968e..035cf5f 100644 --- a/src/router/appMenus/index.ts +++ b/src/router/appMenus/index.ts @@ -3,7 +3,9 @@ import { appRoutes, appExternalRoutes } from '../routes' const mixinRoutes = [...appRoutes, ...appExternalRoutes] const appClientMenus = mixinRoutes.map((el) => { - const { name, path, meta, redirect, children } = el + const { + name, path, meta, redirect, children, + } = el return { name, path, diff --git a/src/router/guard/permission.ts b/src/router/guard/permission.ts index 4014bc7..001da9f 100644 --- a/src/router/guard/permission.ts +++ b/src/router/guard/permission.ts @@ -19,8 +19,8 @@ export default function setupPermissionGuard(router: Router) { // 根据需要自行完善来源于服务端的菜单配置的permission逻辑 // Refine the permission logic from the server's menu configuration as needed if ( - !appStore.appAsyncMenus.length && - !WHITE_LIST.find((el) => el.name === to.name) + !appStore.appAsyncMenus.length + && !WHITE_LIST.find((el) => el.name === to.name) ) { await appStore.fetchServerMenuConfig() } @@ -44,9 +44,8 @@ export default function setupPermissionGuard(router: Router) { // eslint-disable-next-line no-lonely-if if (permissionsAllow) next() else { - const destination = - Permission.findFirstPermissionRoute(appRoutes, userStore.role) || - NOT_FOUND + const destination = Permission.findFirstPermissionRoute(appRoutes, userStore.role) + || NOT_FOUND next(destination) } } diff --git a/src/store/modules/app/index.ts b/src/store/modules/app/index.ts index c3a3685..f0b3171 100644 --- a/src/store/modules/app/index.ts +++ b/src/store/modules/app/index.ts @@ -3,7 +3,7 @@ import { Notification } from '@arco-design/web-vue' import type { NotificationReturn } from '@arco-design/web-vue/es/notification/interface' import type { RouteRecordNormalized } from 'vue-router' import defaultSettings from '@/config/settings.json' -import { getMenuList } from '@/api/user' +import { getMenuList } from '@/api/system/user' import { AppState } from './types' const useAppStore = defineStore('app', { diff --git a/src/store/modules/tab-bar/index.ts b/src/store/modules/tab-bar/index.ts index eca3e60..e6a9fdc 100644 --- a/src/store/modules/tab-bar/index.ts +++ b/src/store/modules/tab-bar/index.ts @@ -4,7 +4,9 @@ import { DEFAULT_ROUTE, DEFAULT_ROUTE_NAME } from '@/router/routes/index' import { TabBarState, TagProps } from './types' const formatTag = (route: RouteLocationNormalized): TagProps => { - const { name, meta, fullPath, query } = route + const { + name, meta, fullPath, query, + } = route return { title: meta.locale || '', name: String(name), diff --git a/src/store/modules/user/index.ts b/src/store/modules/user/index.ts index 61f7472..caea0c9 100644 --- a/src/store/modules/user/index.ts +++ b/src/store/modules/user/index.ts @@ -4,7 +4,7 @@ import { logout as userLogout, getUserInfo, LoginData, -} from '@/api/user' +} from '@/api/system/user' import { setToken, clearToken } from '@/utils/auth' import { removeRouteListener } from '@/utils/route-listener' import { UserState } from './types' @@ -12,21 +12,15 @@ import useAppStore from '../app' const useUserStore = defineStore('user', { state: (): UserState => ({ - name: undefined, + id: undefined, + username: undefined, + nickname: undefined, avatar: undefined, - job: undefined, - organization: undefined, - location: undefined, - email: undefined, - introduction: undefined, - personalWebsite: undefined, - jobName: undefined, - organizationName: undefined, - locationName: undefined, phone: undefined, - registrationDate: undefined, - accountId: undefined, - certification: undefined, + email: undefined, + gender: undefined, + createTime: undefined, + updateTime: undefined, role: '', }), @@ -37,12 +31,12 @@ const useUserStore = defineStore('user', { }, actions: { - switchRoles() { - return new Promise((resolve) => { - this.role = this.role === 'user' ? 'admin' : 'user' - resolve(this.role) - }) - }, + // switchRoles() { + // return new Promise((resolve) => { + // this.role = this.role === 'user' ? 'admin' : 'user' + // resolve(this.role) + // }) + // }, // Set user's information setInfo(partial: Partial) { this.$patch(partial) @@ -56,21 +50,14 @@ const useUserStore = defineStore('user', { // Get user's information async info() { const res = await getUserInfo() - this.setInfo(res.data) }, // Login async login(loginForm: LoginData) { try { - loginForm = { - ...loginForm, - grant_type: 'password', - client_id: 'example-ui', - client_secret: 'example-ui', - } const res = await userLogin(loginForm) - setToken(res.data.token) + setToken(res?.data?.access_token) } catch (err) { clearToken() throw err diff --git a/src/store/modules/user/types.ts b/src/store/modules/user/types.ts index 75fd784..024f71b 100644 --- a/src/store/modules/user/types.ts +++ b/src/store/modules/user/types.ts @@ -1,19 +1,12 @@ -export type RoleType = '' | '*' | 'admin' | 'user'; export interface UserState { - name?: string; - avatar?: string; - job?: string; - organization?: string; - location?: string; - email?: string; - introduction?: string; - personalWebsite?: string; - jobName?: string; - organizationName?: string; - locationName?: string; - phone?: string; - registrationDate?: string; - accountId?: string; - certification?: number; - role: RoleType; + id?: number + username?: string + nickname?: string + avatar?: string + phone?: string + email?: string + gender?: number + createTime?: string + updateTime?: string + role?: string } diff --git a/src/utils/auth.ts b/src/utils/auth.ts index f2ea509..dfee6a6 100644 --- a/src/utils/auth.ts +++ b/src/utils/auth.ts @@ -1,12 +1,8 @@ const TOKEN_KEY = 'token' -const isLogin = () => { - return !!localStorage.getItem(TOKEN_KEY) -} +const isLogin = () => !!localStorage.getItem(TOKEN_KEY) -const getToken = () => { - return localStorage.getItem(TOKEN_KEY) -} +const getToken = () => localStorage.getItem(TOKEN_KEY) const setToken = (token: string) => { localStorage.setItem(TOKEN_KEY, token) @@ -16,4 +12,6 @@ const clearToken = () => { localStorage.removeItem(TOKEN_KEY) } -export { isLogin, getToken, setToken, clearToken } +export { + isLogin, getToken, setToken, clearToken, +} diff --git a/src/utils/event.ts b/src/utils/event.ts index a39f339..c63be1a 100644 --- a/src/utils/event.ts +++ b/src/utils/event.ts @@ -5,8 +5,8 @@ export function addEventListen( capture = false, ) { if ( - target.addEventListener && - typeof target.addEventListener === 'function' + target.addEventListener + && typeof target.addEventListener === 'function' ) { target.addEventListener(event, handler, capture) } @@ -19,8 +19,8 @@ export function removeEventListen( capture = false, ) { if ( - target.removeEventListener && - typeof target.removeEventListener === 'function' + target.removeEventListener + && typeof target.removeEventListener === 'function' ) { target.removeEventListener(event, handler, capture) } diff --git a/src/utils/index.ts b/src/utils/index.ts index 17616d8..4db4454 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -18,6 +18,7 @@ export const openWindow = ( } export const regexUrl = new RegExp( + // eslint-disable-next-line max-len '^(?!mailto:)(?:(?:http|https|ftp)://)(?:\\S+(?::\\S*)?@)?(?:(?:(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}(?:\\.(?:[0-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))|(?:(?:[a-z\\u00a1-\\uffff0-9]+-?)*[a-z\\u00a1-\\uffff0-9]+)(?:\\.(?:[a-z\\u00a1-\\uffff0-9]+-?)*[a-z\\u00a1-\\uffff0-9]+)*(?:\\.(?:[a-z\\u00a1-\\uffff]{2,})))|localhost)(?::\\d{2,5})?(?:(/|\\?|#)[^\\s]*)?$', 'i', ) diff --git a/src/utils/setup-mock.ts b/src/utils/setup-mock.ts index 4cec9cf..f25ec7b 100644 --- a/src/utils/setup-mock.ts +++ b/src/utils/setup-mock.ts @@ -4,20 +4,16 @@ export default ({ mock, setup }: { mock?: boolean; setup: () => void }) => { if (mock !== false && debug) setup() } -export const successResponseWrap = (data: unknown) => { - return { - data, - status: 'ok', - msg: '请求成功', - code: 20000, - } -} +export const successResponseWrap = (data: unknown) => ({ + data, + status: 'ok', + msg: '请求成功', + code: 20000, +}) -export const failResponseWrap = (data: unknown, msg: string, code = 50000) => { - return { - data, - status: 'fail', - msg, - code, - } -} +export const failResponseWrap = (data: unknown, msg: string, code = 50000) => ({ + data, + status: 'fail', + msg, + code, +}) diff --git a/src/views/dashboard/workplace/components/announcement.vue b/src/views/dashboard/workplace/components/announcement.vue index 61562b3..3d96db3 100644 --- a/src/views/dashboard/workplace/components/announcement.vue +++ b/src/views/dashboard/workplace/components/announcement.vue @@ -20,33 +20,33 @@ diff --git a/src/views/dashboard/workplace/components/carousel.vue b/src/views/dashboard/workplace/components/carousel.vue index 0e0a5d8..e9a5bb2 100644 --- a/src/views/dashboard/workplace/components/carousel.vue +++ b/src/views/dashboard/workplace/components/carousel.vue @@ -7,18 +7,18 @@ >
- +
diff --git a/src/views/dashboard/workplace/components/categories-percent.vue b/src/views/dashboard/workplace/components/categories-percent.vue index 8de1a47..76bb51e 100644 --- a/src/views/dashboard/workplace/components/categories-percent.vue +++ b/src/views/dashboard/workplace/components/categories-percent.vue @@ -16,99 +16,97 @@ diff --git a/src/views/dashboard/workplace/components/content-chart.vue b/src/views/dashboard/workplace/components/content-chart.vue index 7010fc8..9d64538 100644 --- a/src/views/dashboard/workplace/components/content-chart.vue +++ b/src/views/dashboard/workplace/components/content-chart.vue @@ -17,184 +17,182 @@ diff --git a/src/views/dashboard/workplace/components/data-panel.vue b/src/views/dashboard/workplace/components/data-panel.vue index 43d8999..e3dbeb6 100644 --- a/src/views/dashboard/workplace/components/data-panel.vue +++ b/src/views/dashboard/workplace/components/data-panel.vue @@ -9,7 +9,7 @@ avatar + > + > + > + > diff --git a/src/views/dashboard/workplace/components/popular-content.vue b/src/views/dashboard/workplace/components/popular-content.vue index 399db40..94bcbb1 100644 --- a/src/views/dashboard/workplace/components/popular-content.vue +++ b/src/views/dashboard/workplace/components/popular-content.vue @@ -34,7 +34,7 @@ :scroll="{ x: '100%', y: '264px' }" > diff --git a/src/views/dashboard/workplace/index.vue b/src/views/dashboard/workplace/index.vue index 8af5338..4e9e51a 100644 --- a/src/views/dashboard/workplace/index.vue +++ b/src/views/dashboard/workplace/index.vue @@ -42,22 +42,22 @@ diff --git a/src/views/system/user/index.vue b/src/views/system/user/index.vue index d4f7e1e..9f0fdf7 100644 --- a/src/views/system/user/index.vue +++ b/src/views/system/user/index.vue @@ -8,13 +8,13 @@ - {{ $t('searchTable.form.search') }} + {{ $t('userTable.form.search') }} - {{ $t('searchTable.form.reset') }} + {{ $t('userTable.form.reset') }} @@ -26,42 +26,42 @@ > - + + + + + + + + {{ $t('userTable.operation.create') }} + + + + + + + + + + {{ $t('userTable.operation.download') }} + + + + + + + + diff --git a/src/views/system/role/locale/en-US.ts b/src/views/system/role/locale/en-US.ts new file mode 100644 index 0000000..e3372a9 --- /dev/null +++ b/src/views/system/role/locale/en-US.ts @@ -0,0 +1,3 @@ +export default { + 'menu.system.role': 'Role System', +} diff --git a/src/views/system/role/locale/zh-CN.ts b/src/views/system/role/locale/zh-CN.ts new file mode 100644 index 0000000..9fc5525 --- /dev/null +++ b/src/views/system/role/locale/zh-CN.ts @@ -0,0 +1,3 @@ +export default { + 'menu.system.role': '角色管理' +} diff --git a/src/views/system/user/components/info-modal.vue b/src/views/system/user/components/info-modal.vue index 5d5248d..984e440 100644 --- a/src/views/system/user/components/info-modal.vue +++ b/src/views/system/user/components/info-modal.vue @@ -102,12 +102,12 @@ const handleCancel = () => { const emit = defineEmits(['load-data']) -const transferLoadData = (e) => { +const transferLoadData = () => { setLoading(true) emit('load-data') setLoading(false) } -const onBeforeOkHandle = async (done) => { +const onBeforeOkHandle = async (done: (closed: boolean) => void) => { if (modalConfig.type === 1) { await create(userForm) transferLoadData() @@ -120,7 +120,7 @@ const onBeforeOkHandle = async (done) => { visible: false, title: '', }) - done() + done(true) } const rolesTree = async () => { diff --git a/src/views/system/user/index.vue b/src/views/system/user/index.vue index b552d9b..96c405d 100644 --- a/src/views/system/user/index.vue +++ b/src/views/system/user/index.vue @@ -8,13 +8,13 @@ - {{ $t('userTable.form.search') }} + {{ $t('search') }} - {{ $t('userTable.form.reset') }} + {{ $t('reset') }} @@ -114,10 +114,6 @@ @page-change="pageChangeHandle" > diff --git a/src/views/system/role/components/authority-modal.vue b/src/views/system/role/components/authority-modal.vue new file mode 100644 index 0000000..5345d65 --- /dev/null +++ b/src/views/system/role/components/authority-modal.vue @@ -0,0 +1,71 @@ + + + + + diff --git a/src/views/system/role/components/info-modal.vue b/src/views/system/role/components/info-modal.vue index 6ed834e..6c3cd97 100644 --- a/src/views/system/role/components/info-modal.vue +++ b/src/views/system/role/components/info-modal.vue @@ -60,7 +60,7 @@ const generateFormModel = (): RoleDto => ({ }) const roleForm = reactive(generateFormModel()) -const topRole = { id: 0, name: '顶级角色', children: [] } +const topRole: RoleVo = { id: 0, name: '顶级角色', children: [] } const roles = ref([]) const handleCancel = () => { diff --git a/src/views/system/role/index.vue b/src/views/system/role/index.vue index cf55daf..47366e1 100644 --- a/src/views/system/role/index.vue +++ b/src/views/system/role/index.vue @@ -37,7 +37,7 @@ - + + @@ -57,7 +58,7 @@ import useLoading from '@/hooks/loading' import { deleteById, getRolesTree } from '@/api/system/role' import { RoleVo } from '@/api/system/types' import InfoModal from '@/views/system/role/components/info-modal.vue' -import { deepClone } from '@/utils/objutils' +import AuthorityModal from '@/views/system/role/components/authority-modal.vue' const tableData = ref([]) const { loading, setLoading } = useLoading(true) @@ -71,6 +72,7 @@ const generateFormModel = () => ({ const formModel = ref(generateFormModel()) const infoModal = ref(null) +const authorityModal = ref(null) const tableColumns = [ { @@ -105,13 +107,16 @@ const tableColumns = [ const fetchData = async () => { tableData.value = (await getRolesTree()).data - console.log(deepClone(tableData.value)) } const openModalHandle = (type: 0 | 1 | 2, title: string, id = 0) => { infoModal.value.open(type, title, id) } +const grantAuthority = (id: number) => { + authorityModal.value.open(id) +} + const onSearch = () => { setLoading(true) fetchData() -- Gitee From 3dbe2efaa43132ff961f2b0bcd49de299b8b6126 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E4=BB=A4?= <2603820757@qq.com> Date: Thu, 25 Aug 2022 22:02:16 +0800 Subject: [PATCH 24/28] =?UTF-8?q?:bulb:=20=E6=9D=83=E9=99=90=E8=8F=9C?= =?UTF-8?q?=E5=8D=95=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/system/authority/index.ts | 16 ++- src/locale/en-US.ts | 2 + src/locale/zh-CN.ts | 2 + src/router/routes/modules/system.ts | 9 ++ src/store/modules/app/index.ts | 1 - src/types/global.ts | 2 + src/types/modules/system.ts | 18 +++ src/utils/tree-utils.ts | 4 +- .../authority/components/info-modal.vue | 60 ++++++++ src/views/system/authority/index.vue | 134 ++++++++++++++++++ src/views/system/authority/locale/en-US.ts | 3 + src/views/system/authority/locale/zh-CN.ts | 3 + .../role/components/authority-modal.vue | 3 +- .../system/role/components/info-modal.vue | 2 +- src/views/system/role/index.vue | 6 +- src/views/system/role/locale/zh-CN.ts | 2 +- 16 files changed, 256 insertions(+), 11 deletions(-) create mode 100644 src/views/system/authority/components/info-modal.vue create mode 100644 src/views/system/authority/index.vue create mode 100644 src/views/system/authority/locale/en-US.ts create mode 100644 src/views/system/authority/locale/zh-CN.ts diff --git a/src/api/system/authority/index.ts b/src/api/system/authority/index.ts index de86e09..1c285b5 100644 --- a/src/api/system/authority/index.ts +++ b/src/api/system/authority/index.ts @@ -1,6 +1,18 @@ import axios from 'axios' -import { System } from '@/types/modules/system' +import { AuthorityDto, AuthorityVo } from '@/types/modules/system' + +export function create(authorityDto: AuthorityDto) { + return axios.post('/system/authority', authorityDto) +} + +export function updateById(authorityDto: AuthorityDto) { + return axios.put('/system/authority', authorityDto) +} + +export function deleteById(id: number) { + return axios.delete(`/system/authority/${id}`) +} export function getTreeData() { - return axios.get('/system/authority/tree') + return axios.get('/system/authority/tree') } diff --git a/src/locale/en-US.ts b/src/locale/en-US.ts index af0832d..b4f60bf 100644 --- a/src/locale/en-US.ts +++ b/src/locale/en-US.ts @@ -5,6 +5,7 @@ import localeLogin from '@/views/login/locale/en-US' import localeWorkplace from '@/views/dashboard/workplace/locale/en-US' import localeUserSystem from '@/views/system/user/locale/en-US' import localeRoleSystem from '@/views/system/role/locale/en-US' +import localeAuthoritySystem from '@/views/system/authority/locale/en-US' import localeCommon from './common/en-US' import localeSettings from './en-US/settings' @@ -30,6 +31,7 @@ export default { ...localeWorkplace, ...localeUserSystem, ...localeRoleSystem, + ...localeAuthoritySystem, ...localeCommon, 'menu.system': 'System', } diff --git a/src/locale/zh-CN.ts b/src/locale/zh-CN.ts index ff19b91..0ab465a 100644 --- a/src/locale/zh-CN.ts +++ b/src/locale/zh-CN.ts @@ -5,6 +5,7 @@ import localeLogin from '@/views/login/locale/zh-CN' import localeWorkplace from '@/views/dashboard/workplace/locale/zh-CN' import localeUserSystem from '@/views/system/user/locale/zh-CN' import localeRoleSystem from '@/views/system/role/locale/zh-CN' +import localeAuthoritySystem from '@/views/system/authority/locale/zh-CN' import localeCommon from './common/zh-CN' import localeSettings from './zh-CN/settings' @@ -30,6 +31,7 @@ export default { ...localeWorkplace, ...localeUserSystem, ...localeRoleSystem, + ...localeAuthoritySystem, ...localeCommon, 'menu.system': '系统管理', } diff --git a/src/router/routes/modules/system.ts b/src/router/routes/modules/system.ts index ad82027..9bea66f 100644 --- a/src/router/routes/modules/system.ts +++ b/src/router/routes/modules/system.ts @@ -28,6 +28,15 @@ const SYSTEM: AppRouteRecordRaw = { requiresAuth: true, }, }, + { + path: 'authority', + name: 'authority', + component: () => import('@/views/system/authority/index.vue'), + meta: { + locale: 'menu.system.authority', + requiresAuth: true, + }, + }, ], } diff --git a/src/store/modules/app/index.ts b/src/store/modules/app/index.ts index 2c93b30..6651067 100644 --- a/src/store/modules/app/index.ts +++ b/src/store/modules/app/index.ts @@ -53,7 +53,6 @@ const useAppStore = defineStore('app', { closable: true, }) this.serverMenu = (await getMenuList()).data - console.log(this.serverMenu) notifyInstance = Notification.success({ id: 'menuNotice', content: 'success', diff --git a/src/types/global.ts b/src/types/global.ts index e2567f0..258df5e 100644 --- a/src/types/global.ts +++ b/src/types/global.ts @@ -53,6 +53,8 @@ export interface AModalConfig { title?: string visible?: boolean disabled?: boolean + type?: number + width?: number } export const initAModalConfig: AModalConfig = { diff --git a/src/types/modules/system.ts b/src/types/modules/system.ts index 8aba20d..243ffd4 100644 --- a/src/types/modules/system.ts +++ b/src/types/modules/system.ts @@ -8,3 +8,21 @@ export interface AuthorityVo extends TreeNode { path?: string meta?: string } + +export interface AuthorityDto extends TreeNode{ + id?: number + name?: string + code?: string + icon?: string + type?: number + path?: string + meta?: Meta +} + +export interface Meta { + locale?: string + icon?: string + requiresAuth?: boolean + roles?: string[] + order?: number +} diff --git a/src/utils/tree-utils.ts b/src/utils/tree-utils.ts index f414204..0681083 100644 --- a/src/utils/tree-utils.ts +++ b/src/utils/tree-utils.ts @@ -1,7 +1,7 @@ import { TreeNode } from '@/types/global' /** 找当前节点 */ -function _findNode(id, node: TreeNode) { +function _findNode(id: number, node: TreeNode): TreeNode | undefined { if (node.id === id) { return node } @@ -27,7 +27,7 @@ function _disableNode(node: TreeNode) { } /** 设置Tree当前节点和自己子节点不可选 */ -export function disableNode(currentId, treeData: TreeNode[]) { +export function disableNode(currentId: number, treeData: TreeNode[]) { for (let i = 0; i < treeData.length; i += 1) { const found = _findNode(currentId, treeData[i]) if (found) { diff --git a/src/views/system/authority/components/info-modal.vue b/src/views/system/authority/components/info-modal.vue new file mode 100644 index 0000000..962399a --- /dev/null +++ b/src/views/system/authority/components/info-modal.vue @@ -0,0 +1,60 @@ + + + + + diff --git a/src/views/system/authority/index.vue b/src/views/system/authority/index.vue new file mode 100644 index 0000000..7d96b23 --- /dev/null +++ b/src/views/system/authority/index.vue @@ -0,0 +1,134 @@ + + + + + diff --git a/src/views/system/authority/locale/en-US.ts b/src/views/system/authority/locale/en-US.ts new file mode 100644 index 0000000..2e7d45e --- /dev/null +++ b/src/views/system/authority/locale/en-US.ts @@ -0,0 +1,3 @@ +export default { + 'menu.system.authority': 'Authority System', +} diff --git a/src/views/system/authority/locale/zh-CN.ts b/src/views/system/authority/locale/zh-CN.ts new file mode 100644 index 0000000..81f199d --- /dev/null +++ b/src/views/system/authority/locale/zh-CN.ts @@ -0,0 +1,3 @@ +export default { + 'menu.system.authority': '权限与菜单管理', +} diff --git a/src/views/system/role/components/authority-modal.vue b/src/views/system/role/components/authority-modal.vue index 5345d65..a70bd1f 100644 --- a/src/views/system/role/components/authority-modal.vue +++ b/src/views/system/role/components/authority-modal.vue @@ -16,13 +16,14 @@ :field-names="{ key: 'id', title: 'name', + icon: '' }" /> + + diff --git a/src/views/system/authority/components/info-modal.vue b/src/views/system/authority/components/info-modal.vue index 962399a..804b9ef 100644 --- a/src/views/system/authority/components/info-modal.vue +++ b/src/views/system/authority/components/info-modal.vue @@ -6,7 +6,7 @@ :on-before-ok="onBeforeOkHandle" @cancel="handleCancel" > - + @@ -20,7 +20,25 @@ - + + + + + + + + + + + + 菜单 + 权限 + + + + + + @@ -30,8 +48,9 @@ @@ -70,7 +300,7 @@ const icons = ref([ .icon-picker-select { position: absolute; width: 100%; - max-height: 150px; + max-height: 200px; margin-top: 10px; overflow: scroll; z-index: 99999999999; -- Gitee From a939755d97b0a435cdc1b36fe4d48b3eff4efe55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E4=BB=A4?= <2603820757@qq.com> Date: Sun, 28 Aug 2022 14:47:36 +0800 Subject: [PATCH 28/28] =?UTF-8?q?:wheelchair:=20=E5=9B=BE=E6=A0=87?= =?UTF-8?q?=E9=80=89=E6=8B=A9=E5=99=A8=E5=AD=90=E7=88=B6=E7=BB=84=E4=BB=B6?= =?UTF-8?q?=E4=B9=8B=E9=97=B4=E6=95=B0=E6=8D=AE=E5=8F=8C=E5=90=91=E7=BB=91?= =?UTF-8?q?=E5=AE=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/system/authority/index.ts | 4 + src/components/icon-picker/index.vue | 53 ++++++++++--- src/types/global.ts | 4 + .../authority/components/info-modal.vue | 79 ++++++++++++++++--- src/views/system/authority/index.vue | 14 +++- .../role/components/authority-modal.vue | 2 - .../system/role/components/info-modal.vue | 2 +- 7 files changed, 128 insertions(+), 30 deletions(-) diff --git a/src/api/system/authority/index.ts b/src/api/system/authority/index.ts index 1c285b5..b6ee74f 100644 --- a/src/api/system/authority/index.ts +++ b/src/api/system/authority/index.ts @@ -13,6 +13,10 @@ export function deleteById(id: number) { return axios.delete(`/system/authority/${id}`) } +export function getById(id: number) { + return axios.get(`/system/authority/${id}`) +} + export function getTreeData() { return axios.get('/system/authority/tree') } diff --git a/src/components/icon-picker/index.vue b/src/components/icon-picker/index.vue index 42e6f19..7a757bc 100644 --- a/src/components/icon-picker/index.vue +++ b/src/components/icon-picker/index.vue @@ -1,15 +1,17 @@ - +