Skip to content

Commit

Permalink
feat: 内容重构更新
Browse files Browse the repository at this point in the history
  • Loading branch information
oljc committed Jan 23, 2024
1 parent d79a942 commit a287f24
Show file tree
Hide file tree
Showing 12 changed files with 136 additions and 108 deletions.
5 changes: 0 additions & 5 deletions src/api/user.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import axios from 'axios';
import type { RouteRecordNormalized } from 'vue-router';
import type { UserState } from '@/store/modules/user/types';

export interface LoginData {
Expand All @@ -22,10 +21,6 @@ export function getUserInfo() {
return axios.post<UserState>('/api/user/info');
}

export function getMenuList() {
return axios.post<RouteRecordNormalized[]>('/api/user/menu');
}

// 获取验证码
export function getCaptcha(data: { tel: string }) {
return axios.post<{ captcha?: string }>('/api/login/captcha', data);
Expand Down
3 changes: 0 additions & 3 deletions src/components/global-setting/block.vue
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,6 @@ const handleChange = async ({
if (key === 'colorWeak') {
document.body.style.filter = value ? 'invert(80%)' : 'none';
}
if (key === 'menuFromServer' && value) {
await appStore.fetchServerMenuConfig();
}
if (key === 'topMenu') {
appStore.updateSettings({
menuCollapse: false
Expand Down
5 changes: 0 additions & 5 deletions src/components/global-setting/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,6 @@ const contentOpts = computed(() => [
},
{ name: 'settings.footer', key: 'footer', defaultVal: appStore.footer },
{ name: 'settings.tabBar', key: 'tabBar', defaultVal: appStore.tabBar },
{
name: 'settings.menuFromServer',
key: 'menuFromServer',
defaultVal: appStore.menuFromServer
},
{
name: 'settings.menuWidth',
key: 'menuWidth',
Expand Down
2 changes: 1 addition & 1 deletion src/components/tab-bar/tab-item.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
@select="actionSelect"
>
<span
class="arco-tag arco-tag-size-medium arco-tag-checked"
class="arco-tag arco-tag-size-large arco-tag-checked"
:class="{ 'link-activated': itemData.fullPath === $route.fullPath }"
@click="goto(itemData)"
>
Expand Down
4 changes: 1 addition & 3 deletions src/config/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,5 @@
"menuWidth": 220,
"globalSettings": false,
"device": "desktop",
"tabBar": false,
"menuFromServer": false,
"serverMenu": []
"tabBar": true
}
64 changes: 62 additions & 2 deletions src/locale/en-US/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,29 @@
"login.form.username.msg": "Please enter account/email",
"login.form.username.placeholder": "Account/Email",
"login.more": "More",
"menu.arcoWebsite": "Arco Design",
"menu.dashboard": "Dashboard",
"menu.dashboard.workplace": "Workplace",
"menu.exception": "Exception",
"menu.faq": "FAQ",
"menu.form": "Form",
"menu.list": "List",
"menu.profile": "Profile",
"menu.result": "Result",
"menu.server.dashboard": "Dashboard-Server",
"menu.server.monitor": "Monitor-Server",
"menu.server.workplace": "Workplace-Server",
"menu.user": "User Center",
"menu.visualization": "Data Visualization",
"messageBox.logout": "Logout",
"messageBox.switchRoles": "Switch Roles",
"messageBox.userCenter": "User Center",
"messageBox.userSettings": "User Settings",
"navbar.action.locale": "Switch to English",
"navbar.docs": "Docs",
"settings.alertContent": "The current modifications serve for previewing configuration changes in real-time. To apply them permanently to the project, click the \"Copy Configuration\" button below and paste the configuration into the src/config/settings.ts file.",
"settings.close": "",
"settings.close": "Close",
"settings.content": "",
"settings.copySettings": "Copy Settings",
"settings.language": "language",
"settings.navbar.alerts": "Alerts",
Expand All @@ -48,5 +65,48 @@
"settings.source": "Source",
"settings.sync": "Sync",
"settings.title": "Application configuration",
"signin": ""
"settings.search": "Search",
"settings.navbar": "Navbar",
"settings.menuWidth": "Menu Width (px)",
"settings.menu": "Menu",
"settings.topMenu": "Top Menu",
"settings.tabBar": "Tab Bar",
"settings.footer": "Footer",
"settings.otherSettings": "Other Settings",
"settings.colorWeak": "Color Weak",
"signin": "Sign In",
"workplace.advanced": "Advanced",
"workplace.allProject": "All",
"workplace.announcement": "Announcement",
"workplace.balance": "Balance (CNY)",
"workplace.categoriesPercent": "Categories Percent",
"workplace.contentData": "Content Data",
"workplace.contentManagement": "Content Management",
"workplace.contentPutIn": "Put In",
"workplace.contentStatistical": "Content Statistical",
"workplace.docs": "Documents",
"workplace.docs.interfaceDocs": "Interface Docs",
"workplace.docs.productOverview": "Product Overview",
"workplace.docs.userGuide": "User Guide",
"workplace.docs.workflow": "Workflow",
"workplace.loadMore": "More",
"workplace.minute": "Min",
"workplace.newDay": "Daily Additional Comments",
"workplace.newFromYesterday": "New From Yesterday",
"workplace.onlineContent": "Online Content",
"workplace.onlinePromotion": "Online Promotion",
"workplace.order.pending": "Pending",
"workplace.order.pendingRenewal": "Renewal Order",
"workplace.pecs": "pecs",
"workplace.popularContent": "Popular Content",
"workplace.popularContent.image": "image",
"workplace.popularContent.text": "text",
"workplace.popularContent.video": "video",
"workplace.putIn": "Put In",
"workplace.quick.operation": "Quick Operation",
"workplace.quickOperation.setup": "Setup",
"workplace.recently.visited": "Recently Visited",
"workplace.record.nodata": "No data",
"workplace.viewMore": "More",
"workplace.welcome": "Welcome!"
}
62 changes: 61 additions & 1 deletion src/locale/zh-CN/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,40 @@
"login.form.username.msg": "请输入账号/邮箱",
"login.form.username.placeholder": "账号/邮箱",
"login.more": "更多方式",
"menu.arcoWebsite": "Arco Design",
"menu.dashboard": "仪表盘",
"menu.dashboard.workplace": "工作台",
"menu.exception": "异常页",
"menu.faq": "常见问题",
"menu.form": "表单页",
"menu.list": "列表页",
"menu.profile": "详情页",
"menu.result": "结果页",
"menu.server.dashboard": "仪表盘-服务端",
"menu.server.monitor": "实时监控-服务端",
"menu.server.workplace": "工作台-服务端",
"menu.user": "个人中心",
"menu.visualization": "数据可视化",
"messageBox.logout": "退出登录",
"messageBox.switchRoles": "切换权限",
"messageBox.userCenter": "用户中心",
"messageBox.userSettings": "用户设置",
"navbar.action.locale": "切换为中文",
"navbar.docs": "文档中心",
"settings.alertContent": "当前更改仅是实时预览配置效果。要真正作用于项目,点击下方的「复制配置」按钮,将配置粘贴到 src/config/settings.ts 中即可。",
"settings.close": "关闭",
"settings.content": "内容区域",
"settings.copySettings": "复制配置",
"settings.language": "语言",
"settings.search": "搜索",
"settings.navbar": "导航栏",
"settings.menuWidth": "菜单宽度 (px)",
"settings.menu": "菜单栏",
"settings.topMenu": "顶部菜单栏",
"settings.tabBar": "多页签",
"settings.footer": "底部",
"settings.otherSettings": "其他设置",
"settings.colorWeak": "色弱模式",
"settings.navbar.alerts": "消息通知",
"settings.navbar.screen.toExit": "退出全屏",
"settings.navbar.screen.toFull": "全屏",
Expand All @@ -48,5 +74,39 @@
"settings.source": "源码",
"settings.sync": "刷新",
"settings.title": "应用配置",
"signin": "注册"
"signin": "注册",
"workplace.advanced": "高级管理",
"workplace.allProject": "所有项目",
"workplace.announcement": "公告",
"workplace.balance": "余额(元)",
"workplace.categoriesPercent": "内容类型占比",
"workplace.contentData": "内容数据",
"workplace.contentManagement": "内容管理",
"workplace.contentPutIn": "内容投放",
"workplace.contentStatistical": "内容分析",
"workplace.docs": "帮助文档",
"workplace.docs.interfaceDocs": "接口文档",
"workplace.docs.productOverview": "产品概要",
"workplace.docs.userGuide": "使用指南",
"workplace.docs.workflow": "接入流程",
"workplace.loadMore": "加载更多",
"workplace.minute": "分钟",
"workplace.newDay": "日新增评论",
"workplace.newFromYesterday": "较昨日新增",
"workplace.onlineContent": "线上总内容",
"workplace.onlinePromotion": "线上推广",
"workplace.order.pending": "待支付",
"workplace.order.pendingRenewal": "待续费订单",
"workplace.pecs": "",
"workplace.popularContent": "线上热门内容",
"workplace.popularContent.image": "图片",
"workplace.popularContent.text": "文本",
"workplace.popularContent.video": "视频",
"workplace.putIn": "投放中内容",
"workplace.quick.operation": "快捷操作",
"workplace.quickOperation.setup": "管理",
"workplace.recently.visited": "最近访问",
"workplace.record.nodata": "暂无数据",
"workplace.viewMore": "查看更多",
"workplace.welcome": "欢迎回来!"
}
52 changes: 10 additions & 42 deletions src/router/guard/permission.ts
Original file line number Diff line number Diff line change
@@ -1,54 +1,22 @@
import type { Router, RouteRecordNormalized } from 'vue-router';
import NProgress from 'nprogress'; // progress bar
import type { Router } from 'vue-router';
import NProgress from 'nprogress';

import usePermission from '@/hooks/permission';
import { useUserStore, useAppStore } from '@/store';
import { useUserStore } from '@/store';
import { appRoutes } from '../routes';
import { WHITE_LIST, NOT_FOUND } from '../constants';
import { 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);
if (appStore.menuFromServer) {
// 针对来自服务端的菜单配置进行处理
// Handle routing configuration from the server

// 根据需要自行完善来源于服务端的菜单配置的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)
) {
await appStore.fetchServerMenuConfig();
}
const serverMenuConfig = [...appStore.appAsyncMenus, ...WHITE_LIST];

let exist = false;
while (serverMenuConfig.length && !exist) {
const element = serverMenuConfig.shift();
if (element?.name === to.name) exist = true;

if (element?.children) {
serverMenuConfig.push(
...(element.children as unknown as RouteRecordNormalized[])
);
}
}
if (exist && permissionsAllow) {
next();
} else next(NOT_FOUND);
} else {
// eslint-disable-next-line no-lonely-if
if (permissionsAllow) next();
else {
const destination =
Permission.findFirstPermissionRoute(appRoutes, userStore.role) ||
NOT_FOUND;
next(destination);
}
if (permissionsAllow) next();
else {
const destination =
Permission.findFirstPermissionRoute(appRoutes, userStore.role) ||
NOT_FOUND;
next(destination);
}
NProgress.done();
});
Expand Down
39 changes: 0 additions & 39 deletions src/store/modules/app/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
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 type { AppState } from './types';

const useAppStore = defineStore('app', {
Expand All @@ -15,19 +11,14 @@ const useAppStore = defineStore('app', {
},
appDevice(state: AppState) {
return state.device;
},
appAsyncMenus(state: AppState): RouteRecordNormalized[] {
return state.serverMenu as unknown as RouteRecordNormalized[];
}
},

actions: {
// Update app settings
updateSettings(partial: Partial<AppState>) {
this.$patch(partial);
},

// Change theme color
toggleTheme(dark: boolean) {
if (dark) {
this.theme = 'dark';
Expand All @@ -42,36 +33,6 @@ const useAppStore = defineStore('app', {
},
toggleMenu(value: boolean) {
this.hideMenu = value;
},
async fetchServerMenuConfig() {
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;
notifyInstance = Notification.success({
id: 'menuNotice',
content: 'success',
closable: true
});
} catch (error) {
notifyInstance = Notification.error({
id: 'menuNotice',
content: 'error',
closable: true
});
} finally {
if (notifyInstance) {
notifyInstance.close();
}
}
},
clearServerMenu() {
this.serverMenu = [];
}
}
});
Expand Down
4 changes: 0 additions & 4 deletions src/store/modules/app/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import type { RouteRecordNormalized } from 'vue-router';

export interface AppState {
theme: string;
colorWeak: boolean;
Expand All @@ -14,7 +12,5 @@ export interface AppState {
globalSettings: boolean;
device: string;
tabBar: boolean;
menuFromServer: boolean;
serverMenu: RouteRecordNormalized[];
[key: string]: unknown;
}
3 changes: 0 additions & 3 deletions src/store/modules/user/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
import { setToken, clearToken } from '@/utils/auth';
import { removeRouteListener } from '@/utils/route-listener';
import type { UserState } from './types';
import useAppStore from '../app';

const useUserStore = defineStore('user', {
state: (): UserState => ({
Expand Down Expand Up @@ -71,11 +70,9 @@ const useUserStore = defineStore('user', {
}
},
logoutCallBack() {
const appStore = useAppStore();
this.resetInfo();
clearToken();
removeRouteListener();
appStore.clearServerMenu();
},
// Logout
async logout() {
Expand Down
1 change: 1 addition & 0 deletions src/types/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ declare module 'vue' {
ABreadcrumbItem: typeof import('@arco-design/web-vue')['BreadcrumbItem']
AButton: typeof import('@arco-design/web-vue')['Button']
ACard: typeof import('@arco-design/web-vue')['Card']
ACardMeta: typeof import('@arco-design/web-vue')['CardMeta']
ACarousel: typeof import('@arco-design/web-vue')['Carousel']
ACarouselItem: typeof import('@arco-design/web-vue')['CarouselItem']
ACascader: typeof import('@arco-design/web-vue')['Cascader']
Expand Down

0 comments on commit a287f24

Please sign in to comment.