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

Merge remote-tracking branch 'origin/master'

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