main.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. import 'babel-polyfill';
  2. import Vue from 'vue';
  3. import App from './App';
  4. import ElementUI from 'element-ui';
  5. import VueRouter from 'vue-router';
  6. import stores from './vuex';
  7. import Vuex from 'vuex';
  8. import routes from './routes/routes';
  9. import 'font-awesome/css/font-awesome.min.css';
  10. import '@/utils/dialog.js';
  11. import '@/utils/option-scroll.js';
  12. import 'element-ui/lib/theme-chalk/index.css';
  13. import {mixins} from '@/mixins'; //引入混合
  14. Vue.mixin(mixins); //使用混合
  15. Vue.use(ElementUI);
  16. Vue.use(VueRouter);
  17. Vue.use(Vuex);
  18. //Import Froala Editor
  19. import 'froala-editor/js/plugins.pkgd.min.js';
  20. import 'froala-editor/js/plugins/quick_insert.min.js';
  21. import 'froala-editor/js/plugins/font_size.min.js';
  22. // import 'froala-editor/js/languages/hr.js';
  23. //Import third party plugins
  24. import 'froala-editor/js/third_party/embedly.min';
  25. import 'froala-editor/js/third_party/font_awesome.min';
  26. import 'froala-editor/js/third_party/spell_checker.min';
  27. import 'froala-editor/js/third_party/image_tui.min';
  28. //引入中文语言包
  29. require('froala-editor/js/languages/zh_cn');
  30. require('froala-editor/js/languages/hr.js');
  31. require('froala-editor/css/froala_style.min.css');
  32. // Import Froala Editor css files.
  33. import 'froala-editor/css/froala_editor.pkgd.min.css';
  34. import 'froala-editor/css/plugins/quick_insert.css';
  35. // Import and use Vue Froala lib.
  36. import VueFroala from 'vue-froala-wysiwyg';
  37. Vue.use(VueFroala);
  38. /* 请求数据解密 */
  39. import { parseData } from '@/utils/parseData';
  40. Vue.prototype.$parseData = parseData;
  41. import icons from '@/utils/icon.js'
  42. Vue.prototype.$icons = icons
  43. import Clipboard from 'clipboard' // 复制
  44. Vue.prototype.Clipboard=Clipboard
  45. /* 全局挂载component */
  46. import '@/utils/registryComponents';
  47. /* */
  48. import Vue2OrgTree from 'vue2-org-tree'
  49. import './styles/org.scss'
  50. // 公共样式
  51. import './styles/index.scss'
  52. Vue.use(Vue2OrgTree)
  53. /* lodash */
  54. import _ from 'lodash'
  55. Vue.prototype._ = _
  56. /* moment */
  57. import moment from 'moment'
  58. moment.locale('zh-cn')
  59. Vue.prototype.$moment = moment
  60. /* VueClipboard 用于拷贝 */
  61. import VueClipboard from 'vue-clipboard2'
  62. Vue.use(VueClipboard)
  63. // 瀑布流
  64. import { VueMasonryPlugin } from 'vue-masonry';
  65. Vue.use(VueMasonryPlugin);
  66. // flat
  67. Array.prototype.flat = function (count) {
  68. let c = count || 1;
  69. let len = this.length;
  70. let exe = [];
  71. if (this.length == 0) return this;
  72. while (c--) {
  73. let _arr = [];
  74. let flag = false;
  75. if (exe.length == 0) {
  76. flag = true;
  77. for (let i = 0; i < len; i++) {
  78. if (this[i] instanceof Array) {
  79. exe.push(...this[i]);
  80. } else {
  81. exe.push(this[i]);
  82. }
  83. }
  84. } else {
  85. for (let i = 0; i < exe.length; i++) {
  86. if (exe[i] instanceof Array) {
  87. flag = true;
  88. _arr.push(...exe[i]);
  89. } else {
  90. _arr.push(exe[i]);
  91. }
  92. }
  93. exe = _arr;
  94. }
  95. if (!flag && c == Infinity) {
  96. break;
  97. }
  98. }
  99. return exe;
  100. };
  101. export const router = new VueRouter({
  102. mode:"history",
  103. routes
  104. })
  105. export const store = new Vuex.Store({
  106. ...stores
  107. });
  108. // 菜单mock
  109. // import meundata from '@/assets/json/meundata.json';
  110. // let data = JSON.stringify(meundata);
  111. import {getUserUuid} from "./api/api";
  112. router.beforeEach((to, from, next) => {
  113. // 判断本地是否有uuid
  114. const uuid=localStorage.getItem('uuid')
  115. if(!uuid){
  116. getUserUuid().then(res=>{
  117. if(res.Ret==200){
  118. localStorage.setItem('uuid',res.Data)
  119. }
  120. })
  121. }
  122. // let rddp_user_name=http.getCookie('rddp_user_name') || false;
  123. // let rddp_admin_access_token=http.getCookie('rddp_admin_access_token') || false;
  124. let auth = localStorage.getItem('auth') || false;
  125. if( to.path!='/login'&&to.path!='/temppage'&&(!auth)){
  126. window.location.href=process.env.Login;
  127. return false;
  128. }
  129. //面包屑
  130. if(to.meta.pathFrom &&
  131. ['/customList','/customSearch','/approvalList','/potentialList','/pickList','/contractapprovallist','/contractmanagelist',
  132. '/expiringlist','/incrementalist','/stocklist','/chartJurisdiction','/readClassify','/contractlist','/incomelist','/newCustomlist',
  133. '/contractCustomlist'].includes(from.path)) {
  134. to.meta.pathFrom = from.path.replace('/','')
  135. to.meta.pathName = from.path == '/readClassify' ? '图库阅读统计' : from.name
  136. }
  137. if(to.path=='/customDetail'){
  138. if(from.matched[0]){
  139. to.matched[0].name=from.matched[0].name
  140. }
  141. }
  142. // 续约审批审批和补充协议审批
  143. if(to.path=='/approvalUpdate'&&to.query.ApplyMethod==6){
  144. to.matched[1].name='补充协议'
  145. }
  146. /* 沙盘详情name添加 */
  147. if(to.path === '/sandflow') {
  148. to.matched[1].name = to.query.type==='view' ? '查看沙盘' : to.query.id ? '编辑沙盘': '添加沙盘';
  149. }
  150. if(to.path === '/analyseVariety') {
  151. to.matched[1].name = to.query.type==='look' ? '查看品种' : '分析品种';
  152. }
  153. /* 图库阅读统计 修改下级name */
  154. if(to.path === '/readClassify') {
  155. to.matched[1].name = to.query.name;
  156. }
  157. /* ETA试用 修改面包屑 */
  158. if(to.path==='/etaAddApproval'){
  159. to.matched[1].name = sessionStorage.getItem('applyInfo')?'重新申请':'新增申请'
  160. }
  161. /* 全量客户列表 修改面包屑 */
  162. if(to.path==='/customDetail'&&to.query.IsFullCompany==1){
  163. to.meta.pathName = '全量客户列表'
  164. to.meta.pathFrom = 'customAllList'
  165. }
  166. if( to.path ){
  167. //百度统计
  168. if (window._hmt) {
  169. window._hmt.push(['_trackPageview', '/#' + to.fullPath])
  170. }
  171. next();
  172. }else{
  173. next({ path:'/404' });
  174. }
  175. });
  176. router.afterEach((to,from,next) => {
  177. // 改变页面标题
  178. document.title = to.matched[to.matched.length-1].name ?
  179. `弘则-${to.matched[to.matched.length-1].name}`:'弘则管理后台'
  180. window.scrollTo(0,0);
  181. // 或
  182. // window.scroll(0, 0);
  183. });
  184. Vue.config.devtools=true
  185. new Vue({
  186. router,
  187. store,
  188. render: h => h(App)
  189. }).$mount('#app');
  190. router.onError((error) => {
  191. // 当更新服务器上打包资源时,浏览器不刷新会报错,故当监听到错误刷新浏览器
  192. window.location.reload();
  193. // const pattern = /Loading chunk (\d)+ failed/g;
  194. // const isChunkLoadFailed = error.message.match(pattern);
  195. // const targetPath = router.history.pending.fullPath;
  196. // if(isChunkLoadFailed){
  197. // router.replace(targetPath);
  198. // }
  199. })
  200. /* ie11 router jump */
  201. if (
  202. '-ms-scroll-limit' in document.documentElement.style &&
  203. '-ms-ime-align' in document.documentElement.style
  204. ) { // detect it's IE11
  205. window.addEventListener("hashchange", function(event) {
  206. var currentPath = window.location.hash.slice(1);
  207. if (store.state.route.path !== currentPath) {
  208. router.push(currentPath)
  209. }
  210. }, false)
  211. }