Commit 987fd753 authored by 赵啸非's avatar 赵啸非

Merge remote-tracking branch 'origin/master'

parents 2126796e a07e6e4a
...@@ -133,4 +133,4 @@ export default { ...@@ -133,4 +133,4 @@ export default {
background: #fff; background: #fff;
border-radius: 4px; border-radius: 4px;
} }
</style> </style>
\ No newline at end of file
import Vue from "vue"; import Vue from "vue";
import App from "./App.vue"; import App from "./App.vue";
import { initRouter } from "./router";
import "./theme/index.less"; import "./theme/index.less";
import Antd from "ant-design-vue"; import Antd from "ant-design-vue";
import store from "./store"; import store from "./store";
...@@ -9,7 +8,8 @@ import "./assets/css/common.less"; ...@@ -9,7 +8,8 @@ import "./assets/css/common.less";
import "./assets/css/relas.less"; import "./assets/css/relas.less";
import "./assets/css/use.less"; import "./assets/css/use.less";
import Plugins from "@/plugins"; import Plugins from "@/plugins";
import { initI18n } from "@/utils/i18n"; import { router } from "@/router";
import { i18n } from "@/utils/i18n";
import bootstrap from "@/bootstrap"; import bootstrap from "@/bootstrap";
import "moment/locale/zh-cn"; import "moment/locale/zh-cn";
import VueResource from "vue-resource"; import VueResource from "vue-resource";
...@@ -56,14 +56,11 @@ Vue.prototype.$nanoid = nanoid; ...@@ -56,14 +56,11 @@ Vue.prototype.$nanoid = nanoid;
import * as echarts from "echarts"; import * as echarts from "echarts";
Vue.prototype.$echarts = echarts; Vue.prototype.$echarts = echarts;
export const router = initRouter(store.state.setting.asyncRoutes);
const i18n = initI18n("CN", "US");
Vue.use(Antd); Vue.use(Antd);
Vue.config.productionTip = false; Vue.config.productionTip = false;
// Vue.use(Viser) // Vue.use(Viser)
Vue.use(Plugins); Vue.use(Plugins);
Vue.use(VueResource); Vue.use(VueResource);
bootstrap({ router, store, i18n, message: Vue.prototype.$message }); bootstrap({ router, store, i18n, message: Vue.prototype.$message });
new Vue({ new Vue({
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
<script> <script>
import local from "@/utils/local"; import local from "@/utils/local";
import { mapMutations } from "vuex"; import { mapMutations } from "vuex";
import { createMenus } from "@/router";
export default { export default {
data() { data() {
return {}; return {};
...@@ -26,8 +27,15 @@ export default { ...@@ -26,8 +27,15 @@ export default {
]), ]),
// 获取token // 获取token
getToken() { getToken() {
let { token, userInfo, siteid, siteName, sysName, sysLogo, path } = let {
this.$route.query; token,
userInfo,
siteid,
siteName,
sysName,
sysLogo,
path,
} = this.$route.query;
if (token && userInfo) { if (token && userInfo) {
userInfo = JSON.parse(userInfo); userInfo = JSON.parse(userInfo);
this.SET_userInfo(userInfo); this.SET_userInfo(userInfo);
...@@ -39,6 +47,8 @@ export default { ...@@ -39,6 +47,8 @@ export default {
this.SET_path(path); this.SET_path(path);
local.setLocal("siteId", siteid); local.setLocal("siteId", siteid);
local.setLocal("siteName", siteName); local.setLocal("siteName", siteName);
// 动态菜单
createMenus();
this.$router.push("/website"); this.$router.push("/website");
} else { } else {
this.$message.warning("跳转失败,请重新登录"); this.$message.warning("跳转失败,请重新登录");
......
...@@ -6,21 +6,6 @@ import Layouts from "@/layouts/Layouts"; ...@@ -6,21 +6,6 @@ import Layouts from "@/layouts/Layouts";
// 路由配置 // 路由配置
const options = { const options = {
routes: [ routes: [
{
path: "/jump",
name: "跳转页面",
component: () => import("@/pages/basicset/jump/jump"),
},
{
path: "*",
name: "404",
component: () => import("@/pages/exception/404"),
},
{
path: "/403",
name: "403",
component: () => import("@/pages/exception/403"),
},
{ {
path: "/apppreview", path: "/apppreview",
name: "预览页面", name: "预览页面",
...@@ -33,7 +18,7 @@ const options = { ...@@ -33,7 +18,7 @@ const options = {
redirect: "/website", redirect: "/website",
children: [ children: [
{ {
path: "website", path: "/website",
name: "站点管理", name: "站点管理",
meta: { meta: {
icon: "bank", icon: "bank",
...@@ -41,7 +26,7 @@ const options = { ...@@ -41,7 +26,7 @@ const options = {
component: () => import("@/pages/basicset/site/website"), component: () => import("@/pages/basicset/site/website"),
}, },
{ {
path: "business", path: "/business",
meta: { meta: {
icon: "book", icon: "book",
}, },
...@@ -118,7 +103,7 @@ const options = { ...@@ -118,7 +103,7 @@ const options = {
], ],
}, },
{ {
path: "department", path: "/department",
meta: { meta: {
icon: "audit", icon: "audit",
}, },
...@@ -141,7 +126,7 @@ const options = { ...@@ -141,7 +126,7 @@ const options = {
], ],
}, },
{ {
path: "personnel", path: "/personnel",
name: "工作人员管理", name: "工作人员管理",
meta: { meta: {
icon: "idcard", icon: "idcard",
...@@ -149,7 +134,7 @@ const options = { ...@@ -149,7 +134,7 @@ const options = {
component: () => import("@/pages/basicset/workman/personnel"), component: () => import("@/pages/basicset/workman/personnel"),
}, },
{ {
path: "festival", path: "/festival",
name: "节假日管理", name: "节假日管理",
meta: { meta: {
icon: "carry-out", icon: "carry-out",
...@@ -157,16 +142,17 @@ const options = { ...@@ -157,16 +142,17 @@ const options = {
component: () => import("@/pages/basicset/holiday/festival"), component: () => import("@/pages/basicset/holiday/festival"),
}, },
{ {
path: "deploy", path: "/deploy",
name: "部署模块管理", name: "部署模块管理",
meta: { meta: {
icon: "appstore", icon: "appstore",
roles: ["admin"],
}, },
component: () => import("@/pages/basicset/deploy/deploy"), component: () => import("@/pages/basicset/deploy/deploy"),
}, },
{ {
path: "hall", path: "/hall",
name: "大厅管理", name: "大厅管理",
meta: { meta: {
icon: "gateway", icon: "gateway",
...@@ -196,7 +182,7 @@ const options = { ...@@ -196,7 +182,7 @@ const options = {
}, },
{ {
path: "surface", path: "/surface",
component: () => import("@/pages/basicset/surface/index"), component: () => import("@/pages/basicset/surface/index"),
meta: { meta: {
icon: "skin", icon: "skin",
...@@ -210,7 +196,7 @@ const options = { ...@@ -210,7 +196,7 @@ const options = {
}, },
{ {
path: "addsurfacetemplate", path: "addsurfacetemplate",
name: "新增皮肤m模板", name: "新增皮肤模板",
component: () => component: () =>
import("@/pages/basicset/surface/AddSurfaceTemplate"), import("@/pages/basicset/surface/AddSurfaceTemplate"),
meta: { invisible: true }, meta: { invisible: true },
...@@ -218,7 +204,7 @@ const options = { ...@@ -218,7 +204,7 @@ const options = {
], ],
}, },
{ {
path: "configurat", path: "/configurat",
name: "短信配置", name: "短信配置",
meta: { meta: {
icon: "mail", icon: "mail",
...@@ -227,7 +213,7 @@ const options = { ...@@ -227,7 +213,7 @@ const options = {
}, },
{ {
path: "appmarket", path: "/appmarket",
component: () => import("@/pages/basicset/appmarket/Index"), component: () => import("@/pages/basicset/appmarket/Index"),
meta: { meta: {
icon: "shop", icon: "shop",
...@@ -314,7 +300,7 @@ const options = { ...@@ -314,7 +300,7 @@ const options = {
], ],
}, },
{ {
path: "system", path: "/system",
name: "系统设置", name: "系统设置",
component: () => import("@/pages/basicset/system/System"), component: () => import("@/pages/basicset/system/System"),
meta: { meta: {
......
import Vue from 'vue' import Vue from "vue";
import Router from 'vue-router' import VueRouter from "vue-router";
import {formatRoutes} from '@/utils/routerUtil' import { formatRoutes } from "@/utils/routerUtil";
import { i18n } from "@/utils/i18n";
Vue.use(Router) import store from "@/store";
import { mergeI18nFromRoutes } from "@/utils/i18n";
Vue.use(VueRouter);
//解决重复路由报错 //解决重复路由报错
const originalPush = Router.prototype.push const originalPush = VueRouter.prototype.push;
// 修改原型对象中的push方法 // 修改原型对象中的push方法
Router.prototype.push = function push(location) { VueRouter.prototype.push = function push(location) {
return originalPush.call(this, location).catch(err => err) return originalPush.call(this, location).catch((err) => err);
} };
const routes = [
{
path: "/jump",
name: "跳转页面",
component: () => import("@/pages/basicset/jump/jump"),
},
{
path: "*",
name: "404",
component: () => import("@/pages/exception/404"),
},
{
path: "/403",
name: "403",
component: () => import("@/pages/exception/403"),
},
];
formatRoutes(routes);
const router = new VueRouter({
routes,
});
// 不需要登录拦截的路由配置 // 不需要登录拦截的路由配置
const loginIgnore = { const loginIgnore = {
names: ['404', '403'], //根据路由名称匹配 names: ["404", "403"], //根据路由名称匹配
paths: ['/login'], //根据路由fullPath匹配 paths: ["/login", "/jump"], //根据路由fullPath匹配
/** /**
* 判断路由是否包含在该配置中 * 判断路由是否包含在该配置中
* @param route vue-router 的 route 对象 * @param route vue-router 的 route 对象
* @returns {boolean} * @returns {boolean}
*/ */
includes(route) { includes(route) {
return this.names.includes(route.name) || this.paths.includes(route.path) return this.names.includes(route.name) || this.paths.includes(route.path);
} },
} };
/** /**
* 初始化路由实例 * 初始化路由实例
* @param isAsync 是否异步路由模式
* @returns {VueRouter} * @returns {VueRouter}
*/ */
function initRouter(isAsync) { function initRouter() {
const options = isAsync ? require('./async/config.async').default : require('./config').default // 是否异步路由模式
formatRoutes(options.routes) const options = store.state.setting.asyncRoutes
return new Router(options) ? require("./async/config.async").default
: require("./config").default;
formatRoutes(options.routes);
return options;
}
// 判断权限
function permission(router, role) {
if (router.meta && router.meta.roles) {
return router.meta.roles.includes(role);
} else {
return true;
}
}
// 计算动态路由
function calcRouters(dynamicRouter, role) {
// 过滤
let res = dynamicRouter.filter((v) => {
// 判断是否有权限访问此路由
if (permission(v, role)) {
// 判断有没有子路由
if (v.children) {
// 递归
v.children = calcRouters(v.children, role);
}
return true;
} else {
return false;
}
});
return res;
}
// 动态菜单
function createMenus() {
let role = store.getters["site/userInfo"].name;
if (!role) return;
let options = initRouter();
let routesArr = calcRouters(options.routes, role);
const rootRoute = routesArr.find((item) => item.path === "/");
const menuRoutes = rootRoute && rootRoute.children;
mergeI18nFromRoutes(i18n, menuRoutes);
if (menuRoutes) {
routesArr.forEach((v) => {
router.addRoute(v);
});
store.commit("setting/setMenuData", menuRoutes);
}
} }
export {loginIgnore, initRouter} createMenus();
export { loginIgnore, initRouter, createMenus, router };
import config from '@/config' import config from "@/config";
import { ADMIN } from '@/config/default' import { ADMIN } from "@/config/default";
import { formatFullPath } from '@/utils/i18n' import { formatFullPath } from "@/utils/i18n";
import { filterMenu } from '@/utils/authority-utils' import { filterMenu } from "@/utils/authority-utils";
import { getLocalSetting } from '@/utils/themeUtil' import { getLocalSetting } from "@/utils/themeUtil";
import deepClone from 'lodash.clonedeep' import deepClone from "lodash.clonedeep";
const localSetting = getLocalSetting(true) const localSetting = getLocalSetting(true);
// console.log(localSetting) // console.log(localSetting)
const customTitlesStr = sessionStorage.getItem(process.env.VUE_APP_TBAS_TITLES_KEY) const customTitlesStr = sessionStorage.getItem(
const customTitles = (customTitlesStr && JSON.parse(customTitlesStr)) || [] process.env.VUE_APP_TBAS_TITLES_KEY
);
const customTitles = (customTitlesStr && JSON.parse(customTitlesStr)) || [];
export default { export default {
namespaced: true, namespaced: true,
...@@ -20,96 +22,99 @@ export default { ...@@ -20,96 +22,99 @@ export default {
activatedFirst: undefined, activatedFirst: undefined,
customTitles, customTitles,
...config, ...config,
...localSetting ...localSetting,
}, },
getters: { getters: {
menuData (state, getters, rootState) { menuData(state, getters, rootState) {
if (state.filterMenu) { if (state.filterMenu) {
const { permissions, roles } = rootState.account const { permissions, roles } = rootState.account;
return filterMenu(deepClone(state.menuData), permissions, roles) return filterMenu(deepClone(state.menuData), permissions, roles);
} }
return state.menuData return state.menuData;
}, },
firstMenu (state, getters) { firstMenu(state, getters) {
const { menuData } = getters const { menuData } = getters;
if (menuData.length > 0 && !menuData[0].fullPath) { if (menuData.length > 0 && !menuData[0].fullPath) {
formatFullPath(menuData) formatFullPath(menuData);
} }
return menuData.map(item => { return menuData.map((item) => {
const menuItem = { ...item } const menuItem = { ...item };
delete menuItem.children delete menuItem.children;
return menuItem return menuItem;
}) });
}, },
subMenu (state) { subMenu(state) {
const { menuData, activatedFirst } = state const { menuData, activatedFirst } = state;
if (menuData.length > 0 && !menuData[0].fullPath) { if (menuData.length > 0 && !menuData[0].fullPath) {
formatFullPath(menuData) formatFullPath(menuData);
} }
const current = menuData.find(menu => menu.fullPath === activatedFirst) const current = menuData.find((menu) => menu.fullPath === activatedFirst);
return current && current.children || [] return (current && current.children) || [];
} },
}, },
mutations: { mutations: {
setDevice (state, isMobile) { setDevice(state, isMobile) {
state.isMobile = isMobile state.isMobile = isMobile;
}, },
setTheme (state, theme) { setTheme(state, theme) {
// console.log(theme) // console.log(theme)
state.theme = theme state.theme = theme;
}, },
setLayout (state, layout) { setLayout(state, layout) {
state.layout = layout state.layout = layout;
}, },
setMultiPage (state, multiPage) { setMultiPage(state, multiPage) {
state.multiPage = multiPage state.multiPage = multiPage;
}, },
setAnimate (state, animate) { setAnimate(state, animate) {
state.animate = animate state.animate = animate;
}, },
setWeekMode (state, weekMode) { setWeekMode(state, weekMode) {
state.weekMode = weekMode state.weekMode = weekMode;
}, },
setFixedHeader (state, fixedHeader) { setFixedHeader(state, fixedHeader) {
state.fixedHeader = fixedHeader state.fixedHeader = fixedHeader;
}, },
setFixedSideBar (state, fixedSideBar) { setFixedSideBar(state, fixedSideBar) {
state.fixedSideBar = fixedSideBar state.fixedSideBar = fixedSideBar;
}, },
setLang (state, lang) { setLang(state, lang) {
state.lang = lang state.lang = lang;
}, },
setHideSetting (state, hideSetting) { setHideSetting(state, hideSetting) {
state.hideSetting = hideSetting state.hideSetting = hideSetting;
}, },
correctPageMinHeight (state, minHeight) { correctPageMinHeight(state, minHeight) {
state.pageMinHeight += minHeight state.pageMinHeight += minHeight;
}, },
setMenuData (state, menuData) { setMenuData(state, menuData) {
state.menuData = menuData state.menuData = menuData;
}, },
setAsyncRoutes (state, asyncRoutes) { setAsyncRoutes(state, asyncRoutes) {
state.asyncRoutes = asyncRoutes state.asyncRoutes = asyncRoutes;
}, },
setPageWidth (state, pageWidth) { setPageWidth(state, pageWidth) {
state.pageWidth = pageWidth state.pageWidth = pageWidth;
}, },
setActivatedFirst (state, activatedFirst) { setActivatedFirst(state, activatedFirst) {
state.activatedFirst = activatedFirst state.activatedFirst = activatedFirst;
}, },
setFixedTabs (state, fixedTabs) { setFixedTabs(state, fixedTabs) {
state.fixedTabs = fixedTabs state.fixedTabs = fixedTabs;
}, },
setCustomTitle (state, { path, title }) { setCustomTitle(state, { path, title }) {
if (title) { if (title) {
const obj = state.customTitles.find(item => item.path === path) const obj = state.customTitles.find((item) => item.path === path);
if (obj) { if (obj) {
obj.title = title obj.title = title;
} else { } else {
state.customTitles.push({ path, title }) state.customTitles.push({ path, title });
} }
sessionStorage.setItem(process.env.VUE_APP_TBAS_TITLES_KEY, JSON.stringify(state.customTitles)) sessionStorage.setItem(
process.env.VUE_APP_TBAS_TITLES_KEY,
JSON.stringify(state.customTitles)
);
} }
} },
} },
} };
import Vue from 'vue' import Vue from "vue";
import VueI18n from 'vue-i18n' import VueI18n from "vue-i18n";
import routesI18n from '@/router/i18n' import routesI18n from "@/router/i18n";
import './Objects' import "./Objects";
import { getI18nKey } from '@/utils/routerUtil' import { getI18nKey } from "@/utils/routerUtil";
/** /**
* 创建 i18n 配置 * 创建 i18n 配置
...@@ -10,16 +10,18 @@ import { getI18nKey } from '@/utils/routerUtil' ...@@ -10,16 +10,18 @@ import { getI18nKey } from '@/utils/routerUtil'
* @param fallback 回退语言 * @param fallback 回退语言
* @returns {VueI18n} * @returns {VueI18n}
*/ */
function initI18n (locale, fallback) { function initI18n(locale, fallback) {
Vue.use(VueI18n) Vue.use(VueI18n);
let i18nOptions = { let i18nOptions = {
locale, locale,
fallbackLocale: fallback, fallbackLocale: fallback,
silentFallbackWarn: true, silentFallbackWarn: true,
} };
return new VueI18n(i18nOptions) return new VueI18n(i18nOptions);
} }
const i18n = initI18n("CN", "US");
/** /**
* 根据 router options 配置生成 国际化语言 * 根据 router options 配置生成 国际化语言
* @param lang * @param lang
...@@ -27,16 +29,22 @@ function initI18n (locale, fallback) { ...@@ -27,16 +29,22 @@ function initI18n (locale, fallback) {
* @param valueKey * @param valueKey
* @returns {*} * @returns {*}
*/ */
function generateI18n (lang, routes, valueKey) { function generateI18n(lang, routes, valueKey) {
routes.forEach(route => { routes.forEach((route) => {
let keys = getI18nKey(route.fullPath).split('.') let keys = getI18nKey(route.fullPath).split(".");
let value = valueKey === 'path' ? route[valueKey].split('/').filter(item => !item.startsWith(':') && item != '').join('.') : route[valueKey] let value =
lang.assignProps(keys, value) valueKey === "path"
? route[valueKey]
.split("/")
.filter((item) => !item.startsWith(":") && item != "")
.join(".")
: route[valueKey];
lang.assignProps(keys, value);
if (route.children) { if (route.children) {
generateI18n(lang, route.children, valueKey) generateI18n(lang, route.children, valueKey);
} }
}) });
return lang return lang;
} }
/** /**
...@@ -44,14 +52,18 @@ function generateI18n (lang, routes, valueKey) { ...@@ -44,14 +52,18 @@ function generateI18n (lang, routes, valueKey) {
* @param routes * @param routes
* @param parentPath * @param parentPath
*/ */
function formatFullPath (routes, parentPath = '') { function formatFullPath(routes, parentPath = "") {
routes.forEach(route => { routes.forEach((route) => {
let isFullPath = route.path.substring(0, 1) === '/' let isFullPath = route.path.substring(0, 1) === "/";
route.fullPath = isFullPath ? route.path : (parentPath === '/' ? parentPath + route.path : parentPath + '/' + route.path) route.fullPath = isFullPath
? route.path
: parentPath === "/"
? parentPath + route.path
: parentPath + "/" + route.path;
if (route.children) { if (route.children) {
formatFullPath(route.children, route.fullPath) formatFullPath(route.children, route.fullPath);
} }
}) });
} }
/** /**
...@@ -59,20 +71,16 @@ function formatFullPath (routes, parentPath = '') { ...@@ -59,20 +71,16 @@ function formatFullPath (routes, parentPath = '') {
* @param i18n * @param i18n
* @param routes * @param routes
*/ */
function mergeI18nFromRoutes (i18n, routes) { function mergeI18nFromRoutes(i18n, routes) {
formatFullPath(routes) formatFullPath(routes);
const CN = generateI18n(new Object(), routes, 'name') const CN = generateI18n(new Object(), routes, "name");
const US = generateI18n(new Object(), routes, 'path') const US = generateI18n(new Object(), routes, "path");
i18n.mergeLocaleMessage('CN', CN) i18n.mergeLocaleMessage("CN", CN);
i18n.mergeLocaleMessage('US', US) i18n.mergeLocaleMessage("US", US);
const messages = routesI18n.messages const messages = routesI18n.messages;
Object.keys(messages).forEach(lang => { Object.keys(messages).forEach((lang) => {
i18n.mergeLocaleMessage(lang, messages[lang]) i18n.mergeLocaleMessage(lang, messages[lang]);
}) });
} }
export { export { initI18n, mergeI18nFromRoutes, formatFullPath, i18n };
initI18n,
mergeI18nFromRoutes,
formatFullPath
}
...@@ -136,11 +136,11 @@ function loadRoutes(routesConfig) { ...@@ -136,11 +136,11 @@ function loadRoutes(routesConfig) {
// 提取路由国际化数据 // 提取路由国际化数据
mergeI18nFromRoutes(i18n, router.options.routes); mergeI18nFromRoutes(i18n, router.options.routes);
// 初始化Admin后台菜单数据 // 初始化Admin后台菜单数据
const rootRoute = router.options.routes.find((item) => item.path === "/"); // const rootRoute = router.options.routes.find((item) => item.path === "/");
const menuRoutes = rootRoute && rootRoute.children; // const menuRoutes = rootRoute && rootRoute.children;
if (menuRoutes) { // if (menuRoutes) {
store.commit("setting/setMenuData", menuRoutes); // store.commit("setting/setMenuData", menuRoutes);
} // }
} }
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment