123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204 |
- import Vue from 'vue'
- import App from './App.vue'
- import router from './router'
- import store from '@/store'
- import * as API_User from '@/apis/user'
- import {
- clear,
- } from '@/utils/storage'
- //引入mui
- import mui from '@/assets/js/mui.js'
- import '@/assets/css/mui.min.css'
- import Vconsole from 'vconsole'
- import '@/assets/css/icons-extra.css'
- window.mui = mui;
- window.mui.init();
- if (location.hostname === 'localhost') {
- Vue.prototype.HTTPLOCAT = ''
- } else {
- const http = window.location.protocol + '//' + location.hostname + ':' + location.port
- Vue.prototype.HTTPLOCAT = http + ''
- }
- Vue.config.productionTip = false
- //图片预览
- import VueDirectiveImagePreviewer from 'vue-directive-image-previewer'
- import 'vue-directive-image-previewer/dist/assets/style.css'
- Vue.use(VueDirectiveImagePreviewer, {
- background: {
- color: '#000'
- },
- // transition
- animate: {
- duration: 600,
- delay: 500
- },
- // loading (not supported)
- loading: {
- image: ''
- },
- // cursor(css)
- cursor: 'pointer',
- clickMethod: 'doubleClick'
- })
- import Viewer from 'v-viewer'
- import 'viewerjs/dist/viewer.css'
- Vue.use(Viewer)
- Viewer.setDefaults({
- Options: {
- "inline": true,
- "button": true,
- "navbar": false,
- "title": true,
- "toolbar": false,
- "tooltip": true,
- "movable": true,
- "zoomable": true,
- "rotatable": true,
- "scalable": true,
- "transition": true,
- "fullscreen": true,
- "keyboard": true,
- "url": "data-source"
- }
- });
- //获取纯权限路由数组,由函数每次获取
- function getAuthFunList() {
- let funList = [];
- let fun_list = store.state.auth_fun_list;
- if (fun_list && fun_list.length > 0) {
- fun_list.forEach(function(item) {
- funList.push(item)
- })
- }
- return funList;
- }
- //console.log(funList)
- const checkAuth = (to, from, next) => {
- if (to.meta != null && to.meta.requireAuth) {
- if (store.state.person_data || store.state.auth_fun_list) {
- if ((to.meta.form != null && to.meta.form) || (to.meta.mode != null && to.meta.mode)) {
- let funList = getAuthFunList();
- //验证
- if (funList.indexOf(to.name) > -1) {
- next();
- } else {
- //测试环境不验证权限
- if (process.env.VUE_APP_NODE_NAME == 'devlopment') {
- next();
- } else {
- mui.toast('无权访问');
- router.replace({
- name: 'Master'
- })
- }
- }
- } else {
- //不验证
- next();
- }
- } else {
- //window.location.href = '../home/#/user/login';
- // window.location.href = '#/user/login';
- router.push({
- name: 'UserLogin',
- query: {
-
- }
- })
- }
- } else {
- next();
- }
- }
- const checkRole = (to, from, next) => {
- //切换当前场景
- if (to.query.exchange == '1' && to.query.role_id) {
- API_User.exchangePopedom({
- id: to.query.role_id
- }).then(response => {
- checkFun(to, from, next)
- }).catch(error => {
- mui.toast(error);
- })
- } else {
- checkFun(to, from, next)
- }
- }
- const checkFun = (to, from, next) => {
- //如果funlist不存在,在更新版本号清空后,先重新请求再判断
- var token = to.query.token;
- if (token) {
- if (store.state.auth_fun_list) {
- checkAuth(to, from, next);
- } else {
- //这里token一定要存在,从微信模板消息带过来的
- API_User.getAuthFunList(token).then(response => {
- if (response && response.allIconRoute) {
- var allIconRoute = response.allIconRoute;
- store.commit('SET_AUTH_FUN_LIST', allIconRoute);
- checkAuth(to, from, next);
- } else {
- mui.toast('链接已失效,请重新登录');
- router.replace({
- name: 'Master'
- })
- }
- }).catch(error => {
- mui.toast(error);
- })
- }
- } else {
- checkAuth(to, from, next);
- }
- }
- router.beforeEach((to, from, next) => {
- if (to.query.test) {
- if (to.query.test == 'test') {
- let vConsole = new Vconsole()
- }
- }
- //更新版本号,清除本地数据
- if (store.state.app_version != process.env.VUE_APP_VERSION) {
- clear();
- //写入当前版本号
- store.commit('SET_APP_VERSION', process.env.VUE_APP_VERSION);
- }
- //如果传递过来了token则写入
- if (to.query.token) {
- console.log(to.query.token)
- store.commit('SET_TOKEN', to.query.token);
- }
- if (process.env.VUE_APP_NODE_NAME == 'production') {
- //window._hmt.push(['_trackEvent', '页面跳转', 'click', to.meta.title, 1]);
- }
- checkRole(to, from, next);
- })
- new Vue({
- router,
- store,
- render: h => h(App)
- }).$mount('#app')
|