Commit 84a8a7a2 by 姜雷

改造项目由容器建立

parent 49c872f6
......@@ -6,6 +6,8 @@
<meta name="viewport" content="width=device-width,initial-scale=1.0" />
<link rel="icon" href="<%= BASE_URL %>favicon.ico" />
<script src="https://cdn.jsdelivr.net/npm/vue@2.6.10/dist/vue.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vuex@3.1.0/dist/vuex.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vue-router@3.0.1/dist/vue-router.js"></script>
<script src="<%= VUE_APP_LIB_MANAGER %>/customerManage/lib/customerManage.umd.js"></script>
<script src="<%= VUE_APP_LIB_MANAGER %>/baseManage/lib/baseManage.umd.js"></script>
<script src="<%= VUE_APP_LIB_MANAGER %>/systemManage/lib/systemManage.umd.js"></script>
......
import axios from 'axios';
import { Message, MessageBox } from 'element-ui';
// import store from '../store';
import { SUCCESS_CODE } from '@/config';
import { errorHandle } from '@/api/validate';
import { getYourIP } from '@/utils/getIp.js';
let ip = '127.0.0.1';
getYourIP(ipVal => {
ip = ipVal;
});
const createBaseFetch = (config, store) => {
// 创建axios实例
const service = axios.create({
timeout: 10000,
...config,
});
let logout = false;
// request拦截器
service.interceptors.request.use(
conf => {
store.dispatch('fetchStart');
if (store.getters.token) {
conf.headers = {
...conf.headers,
reqSource: 'pc',
token: store.getters.token,
ip: ip,
};
} else {
conf.headers = {
...conf.headers,
reqSource: 'pc',
ip: ip,
};
}
return conf;
},
error => {
// Do something with request error
console.log(error); // for debug
Promise.reject(error);
}
);
// respone拦截器
service.interceptors.response.use(response => {
const res = response.data;
/**
* code为非'0'是抛错
*/
setTimeout(() => {
store.dispatch('fetchDone');
}, 500);
if (res.code !== SUCCESS_CODE) {
if (
response.headers &&
response.headers['content-type'] === 'application/octet-stream'
) {
return response;
}
Message({
message: res.msg || '网络错误!',
type: 'error',
duration: 5 * 1000,
});
// -2:其他客户端登录了;Token 过期了;
if (res.code === '-2') {
if (logout) return;
logout = true;
MessageBox.confirm(
'你已被登出,可以取消继续留在该页面,或者重新登录',
'确定登出',
{
confirmButtonText: '重新登录',
cancelButtonText: '取消',
type: 'warning',
}
)
.then(() => {
store.dispatch('FedLogOut').then(() => {
location.reload(); // 为了重新实例化vue-router对象 避免bug
});
})
.catch(err => {
console.log(err);
logout = false;
});
}
return Promise.reject(response.data);
} else {
return response.data;
}
}, errorHandle);
return service;
};
export default createBaseFetch;
import 'normalize.css/normalize.css';
import App from './App';
import App from '../App';
import router, { constantRouterMap, routeStore } from '../router';
import store from '../store';
routeStore.install(store);
import createBaseFetch from './Api';
import configRoutePermission from './permission';
import '@/assets/styles/index.scss'; // global css
import '@/permission'; // 用户登录认证
// import './mock' // mockjs
import extendCom from '@/utils/extends';
import { formatRouteLink } from '@/utils/route';
const createSystem = ({ routers, routeConfig }) => {
extendCom(Vue);
import storeModule from './storeModule';
import mixinModule from './mixins';
const createSystem = ({ routers, routeFilter }) => {
class SystemShell {
constructor() {
this.createBaseFetch = createBaseFetch;
this.fetch = createBaseFetch(
{
timeout: 10000,
},
store
);
this.initSystem();
}
mixins = mixinModule;
storeModule = storeModule;
initSystem() {
routeStore.install(store);
extendCom(Vue);
configRoutePermission(router, store, routers);
Vue.config.productionTip = false;
}
mount() {
/* eslint-disable no-new */
return new Vue({
let app = new Vue({
el: '#app',
router,
store,
render: h => {
let routes = [...constantRouterMap];
let allRoute = store.getters.asyncRoutes;
routeConfig && routeConfig(routes, allRoute);
if (typeof routeFilter === 'function') {
allRoute = routeFilter(allRoute);
}
if (allRoute && allRoute.length) {
let addRoute = formatRouteLink(allRoute);
for (let index = 0; index < addRoute.length; index++) {
const element = addRoute[index];
if (element.children) {
routes = routes.concat(element.children);
}
}
}
return <App route={routes} allRoutes={allRoute} />;
},
});
return app;
}
}
const systemShell = new SystemShell();
window.$$SystemShell = systemShell;
return systemShell;
};
export default createSystem;
import Dialog from '../mixins/dialog';
import ListPage from '../mixins/listPage';
import CampusListPage from '../mixins/campusListPage';
import Operator from '../mixins/operator';
import Admin from '../mixins/admins/admins';
import Menu from '../mixins/menu/menus';
import UserInfoLabel from '../mixins/user/getUserInfoLabel';
import UserBaseInfo from '../mixins/user/userBaseInfo';
export default {
Dialog,
ListPage,
CampusListPage,
Operator,
Admin,
Menu,
UserInfoLabel,
UserBaseInfo,
};
import { asyncRouterMap } from '../router';
import NProgress from 'nprogress'; // Progress 进度条
import 'nprogress/nprogress.css'; // Progress 进度条样式
import { getToken } from '@/utils/auth'; // 验权
import { getAuthRoute } from '../utils/route';
const configRoutePermission = (router, store, allAasyncRouterMap) => {
NProgress.configure({ showSpinner: false }); // NProgress Configuration
const whiteList = process.env.VUE_APP_WHITE_LIST.split(','); // 不重定向白名单
const getRouteAdd = () => {
let allRoute = store.getters.asyncRoutes;
let asyncRouters = getAuthRoute(allAasyncRouterMap, allRoute);
router.addRoutes(asyncRouters); // 动态添加可访问路由表
router.addRoutes(asyncRouterMap);
};
router.beforeEach((to, from, next) => {
NProgress.start(); // 进度条Progress
if (getToken()) {
if (to.path === '/login') {
next({ path: '/' });
NProgress.done();
} else {
if (store.getters.isRouteDone) {
next(); //
} else {
let addRoute = store.getters.asyncRoutes;
if (addRoute && addRoute.length) {
getRouteAdd();
store.dispatch('GenerateRoutes');
next({ ...to, replace: true });
} else {
store
.dispatch('TokenLogin', {
data: { token: getToken() },
})
.then(() => {
getRouteAdd();
store.dispatch('GenerateRoutes');
next({ ...to, replace: true });
})
.catch(err => {
console.log(err);
store.dispatch('FedLogOut').then(() => {
next({ path: '/login' });
});
});
}
}
}
} else {
if (whiteList.indexOf(to.path) !== -1) {
next();
} else {
next('/login');
NProgress.done();
}
}
});
router.afterEach(() => {
NProgress.done(); // 结束Progress
});
};
export default configRoutePermission;
import filterStore from '../store/modules/filters';
import paginationStore from '../store/modules/pagination';
export default {
filter: filterStore,
pagination: paginationStore,
};
import Vue from 'vue';
import 'normalize.css/normalize.css';
import createSystem from './lib/main';
import App from './App';
import router, { constantRouterMap, routeStore } from './router';
import store from './store';
import { formatRouteLink } from './utils/route';
let allAasyncRouterMap = [
...customerManage.default,
...baseManage.default,
...systemManage.default,
];
routeStore.install(store);
import '@/assets/styles/index.scss'; // global css
import '@/permission'; // 用户登录认证
// import './mock' // mockjs
import extendCom from '@/utils/extends';
extendCom(Vue);
Vue.config.productionTip = false;
/* eslint-disable no-new */
new Vue({
el: '#app',
router,
store,
render: h => {
let routes = [...constantRouterMap];
let allRoute = store.getters.asyncRoutes;
if (allRoute && allRoute.length) {
let addRoute = formatRouteLink(allRoute);
for (let index = 0; index < addRoute.length; index++) {
const element = addRoute[index];
if (element.children) {
routes = routes.concat(element.children);
}
}
}
return <App route={routes} allRoutes={allRoute} />;
},
let app = createSystem({
routers: allAasyncRouterMap,
// routeFilter: allRoute => {
// let filterRoute = allRoute.find(menu => menu.menuCode == '0001');
// return filterRoute ? [filterRoute] : [];
// },
});
app.mount();
import Vue from 'vue';
import Router from 'vue-router';
import _import from './_import';
import routeStore from './store';
import Login from '@/containers/login/index';
......@@ -7,7 +5,7 @@ import errorPage404 from '@/containers/errorPage/404';
import errorPage401 from '@/containers/errorPage/401';
import HomeIcon from '@/assets/images/menu/home.png';
Vue.use(Router);
Vue.use(VueRouter);
const constantRouterMap = [
{ path: '/login', component: Login, hidden: true },
......@@ -35,7 +33,7 @@ const asyncRouterMap = [{ path: '*', redirect: '/404', hidden: true }];
export { constantRouterMap, asyncRouterMap, routeStore };
export default new Router({
export default new VueRouter({
mode: 'history',
base: process.env.VUE_APP_BASE_URL,
scrollBehavior: () => ({ y: 0 }),
......
import Vue from 'vue';
import Vuex from 'vuex';
import createLogger from 'vuex/dist/logger';
import app from './modules/app/index';
import user from './modules/user/index';
import base from './modules/base/index';
import customer from './modules/customer/index';
Vue.use(Vuex);
......@@ -14,7 +11,6 @@ const store = new Vuex.Store({
modules: {
app,
user,
base,
customerBase: customer,
},
strict: debug,
......
import { fetchSelectList } from '@/api/base/index';
const GIVE_TYPE_LIST = 'GIVE_TYPE_LIST';
const CONSUME_TYPE_LIST = 'CONSUME_TYPE_LIST';
const PAYMENT_CONSUME_PAY_WAY_LIST = 'PAYMENT_CONSUME_PAY_WAY_LIST';
const state = () => ({
list: [],
consumeTypeList : [],//消费类型
paymentConsumePayWayList : [],//执法方式
});
const getters = {
giveTypeList: state => state.list,
consumeTypeList :state => state.consumeTypeList,
paymentConsumePayWayList :state=>state.paymentConsumePayWayList,
};
const actions = {
//赠送类型
fetchGiveTypeList({ commit }) {
return fetchSelectList({
params: {
type:"2",
},
}).then(res => {
const list = res.data;
commit(GIVE_TYPE_LIST, list);
});
},
//消费类型
fetchConsumeTypeList({ commit }) {
return fetchSelectList({
params: {
type:"3",
},
}).then(res => {
const list = res.data;
commit(CONSUME_TYPE_LIST, list);
});
},
//支付方式
fetchPaymentConsumePayWayList({ commit }) {
return fetchSelectList({
params: {
type:"4",
},
}).then(res => {
const list = res.data;
commit(PAYMENT_CONSUME_PAY_WAY_LIST, list);
});
},
};
const mutations = {
[GIVE_TYPE_LIST](state, list) {
state.list = list;
},
[CONSUME_TYPE_LIST](state, list) {
state.consumeTypeList = list;
},
[PAYMENT_CONSUME_PAY_WAY_LIST](state, paymentConsumePayWayList) {
state.paymentConsumePayWayList = paymentConsumePayWayList;
},
};
export default {
state,
getters,
actions,
mutations,
};
import giveTypeOption from './giveTypeOption.js';
export default {
modules: {
giveTypeOption,
},
};
......@@ -16,6 +16,8 @@ module.exports = {
externals: [
{
vue: 'Vue',
vuex: 'Vuex',
'vue-router': 'VueRouter',
},
],
},
......
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