main.js 7.33 KB
Newer Older
fukai committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263
// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
// import devtools from '@vue/devtools'


//引入js桥
//import './util/isc-common/isc-bridge-ext.js'
import "babel-polyfill";
import Vue from 'vue'
// 重置elementui
import './styles/elementui-reset.less'
//重置css
import 'minireset.css'
import App from './App'
//导入对BopRule的扩展
import "./BopRuleEx"

import 'quill/dist/quill.core.css' // import styles
import 'quill/dist/quill.snow.css' // for snow theme
import '@wangeditor/editor/dist/css/style.css'
//引入路由
import router from './router'

import '@/util/dialogDrag'
//日期对象格式化方法
import '@/util/date/Date.Format.js'
//引入无限滚动组件
import { InfiniteScroll } from 'element-ui';
Vue.use(InfiniteScroll)

import Print from "./common/print"
Vue.use(Print)

import RewriteNotify from "./rewriteNotify"

//引入vuex
import store from './vuex/store'
// 含有size属性的组件统一设置为small
Vue.prototype.$ELEMENT = { size: 'small', zIndex: 3000 };
import ElementUI, {
  Loading,
  MessageBox,
  Message,
  Button,
  ButtonGroup
} from 'element-ui'
//重复点击某个按钮,message消息始终只提示一次
let messageInstance = null;
const resetMessage = (options) => {
    if(messageInstance) {
        messageInstance.close()
    }
    messageInstance = Message(options)
}
['error','success','info','warning'].forEach(type => {
    resetMessage[type] = options => {
        options = {
            message:options,
            type:type
        }
        return resetMessage(options)
    }
})
const message = resetMessage
// plugins
Vue.prototype.$loading = Loading.service;
Vue.prototype.$msgbox = MessageBox;
Vue.prototype.$alert = MessageBox.alert;
Vue.prototype.$confirm = MessageBox.confirm;
Vue.prototype.$prompt = MessageBox.prompt;
// Vue.prototype.$notify = Notification;
Vue.prototype.$message = message
Vue.use(Button);
Vue.use(ButtonGroup);
// 内部非全局遮罩
Vue.use(Loading.directive);

//es6-promise的兼容性搭配
var Promise = require('es6-promise').Promise;
Promise.polyfill()
//多语言编辑器
import VueCodeMirror from 'vue-codemirror'
import 'codemirror/lib/codemirror.css'
Vue.use(VueCodeMirror)
import CodeEditor from 'bin-code-editor';
Vue.use(CodeEditor);

Vue.config.debug = false;
// 如果在开发时需要使用vue-devtools来调试,请将下面的devtools配置为true
Vue.config.devtools = true;
Vue.config.productionTip = false;

//配置信息
import baseData from "./config/isc-baseData.js"

router.beforeEach((to, from, next) => {
	if (to.path && to.path.indexOf("/index.html") > -1) {
	    next({
	        name: 'login',//这里就是进入子应用的第一页面的路由
	        query: to.query
	    })
	} else {
		// 开发环境不做验证
		if (process.env.NODE_ENV === 'production') {
			if (to.matched.some(r => r.meta && ((typeof r.meta.auth === 'boolean' && r.meta.auth) || r.meta.auth === 'true'))) {
				// 请根据自身业务需要修改
				const hasLogin = sessionStorage.getItem("system_param_login");
				if ('true' == hasLogin) {
					//  开发模式改好了,这里也需要改
					next()
				} else {
					// 没有登录的时候跳转到登录界面
					// 携带上登陆成功之后需要跳转的页面完整路径
					next({
						name: 'login',
						query: {
							redirect: to.path,
							query: to.query
						},
						params: {
							params: to.params
						}
					})
				}
			} else {
				next();
			}
			
		} else {
			// 不需要身份校验 直接通过
			// next()

			if (to.matched.some(r => r.meta && ((typeof r.meta.auth === 'boolean' && r.meta.auth) || r.meta.auth === 'true'))) {
				// 请根据自身业务需要修改
				const hasLogin = sessionStorage.getItem("system_param_login");
				if ('true' == hasLogin) {
					//  开发模式改好了,这里也需要改
					next()
				} else {
					// 没有登录的时候跳转到登录界面
					// 携带上登陆成功之后需要跳转的页面完整路径
					next({
						name: 'login',
						query: {
							redirect: to.path,
							query: to.query
						},
						params: {
							params: to.params
						}
					})
				}
			} else {
				next();
			}
		}
	}
	
});
router.afterEach(to => {
	// 更改标题
	let title = 'POIN';
	if (to.meta && to.meta.title) {
		title = typeof to.meta.title === 'function' ? to.meta.title(to) : to.meta.title
	} else if (to.name) {
		title = to.name
	}
	store.commit('SET_BROWSER_TITLE',title);
	
	// 根据菜单判断当前页面是否需要禁用复制、打印、另存功能。
	let printStyle = document.getElementById("controlPrint");
	let isShowContextMenu = true, displayType = "block";
	if(baseData.isOpenDisabledCopy == "false") {
		// 所有页面不开启禁用
		isShowContextMenu = true;
		displayType = "block";
	}else if(baseData.isOpenDisabledCopy == "true") {
		// 禁用所有页面
		isShowContextMenu = false;
		displayType = "none";
	}else if(baseData.isOpenDisabledCopy == "routerConfig") {
		// 通过路由配置禁用部分页面
		if(to.meta && to.meta.isDisablePageOpt == true) {
			isShowContextMenu = false;
			displayType = "none";
		}else {
			isShowContextMenu = true;
			displayType = "block";
		}
	}else if(baseData.isOpenDisabledCopy == "menuConfig") {
		// 通过菜单配置禁用部分页面
		const menu = JSON.parse(sessionStorage.getItem("menu_data"));
		if(menu && menu.length != 0) {
			// 查找当前页面对应的菜单信息
			let currentPageMenu;
			to.matched.some(match => {
				// 循环matched中的path,以解决为通过菜单配置的子路由无法实现禁用的问题,如果父级路由是禁用状态,那么他的子路由也应该是禁用状态
				currentPageMenu = menu.find(item => match.path == item.authorityscript);
				return currentPageMenu
			})
			const isDisablePageOperation =  currentPageMenu?currentPageMenu.isDisablePageOpt: false
			// 若菜单信息中禁用标识为1,则禁用相关功能;若为0,则不禁用。
			if(isDisablePageOperation) {
				isShowContextMenu = false;
				displayType = "none";
			}else {
				isShowContextMenu = true;
				displayType = "block";
			}
		}
	}
	document.body.onselectstart = document.body.oncontextmenu = function() { return isShowContextMenu; };
	printStyle.innerHTML = `@media print { body { display: ${displayType} } }`
});


// 国结适配
import "~/assets/css/common.css";
import i18n from "./lang";
import CustomComponent from "./components/business";
import vuefunc from "~/utils/vuefunc";
import EventService,{LOGIN,LOGOUT} from "~/service/EventService";
import ButtonControlService from "~/common/ButtonControlService.js";
Vue.prototype.$buttonControlService = ButtonControlService;


window.SUCCESS = "AAAAAA";
window.PageSize = 10;
window.validMsg={
	title:'失败',
	message:'请检查必输项!'
}
window.cancelMsg="点击“返回”后录入的信息将丢失,确定要返回吗?"

Vue.use(ElementUI, { size: "small", i18n: (key, value) => i18n.t(key, value) });
Vue.use(CustomComponent);
Vue.use(vuefunc);

function resetCache(){
  window.GLOBAL_CACHE = {PAGEID_CACHE:new Set()};
}
//初始化cache
resetCache();
//登录后重置
EventService.on(LOGIN,()=>{
  resetCache();
});
//退出后重置
EventService.on(LOGOUT,()=>{
  resetCache();
});

RewriteNotify()

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  store,
  i18n,
  template: '<App/>',
  components: { App }
})