main.js 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. // +----------------------------------------------------------------------
  2. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  3. // +----------------------------------------------------------------------
  4. // | Copyright (c) 2016~2023 https://www.crmeb.com All rights reserved.
  5. // +----------------------------------------------------------------------
  6. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  7. // +----------------------------------------------------------------------
  8. // | Author: CRMEB Team <admin@crmeb.com>
  9. // +----------------------------------------------------------------------
  10. // The Vue build version to load with the `import` command
  11. // (runtime-only or standalone) has been set in webpack.base.conf with an alias.
  12. import Vue from 'vue';
  13. import App from './App';
  14. import router from './router';
  15. import store from './store';
  16. import ViewUI from 'view-design';
  17. // import ViewUI from 'view-design'
  18. Vue.prototype.bus = new Vue();
  19. import Router from 'vue-router';
  20. import Auth from '@/libs/wechat';
  21. import 'view-design/dist/styles/iview.css';
  22. import i18n from '@/locale';
  23. import config from '@/config';
  24. import importDirective from '@/directive';
  25. import { directive as clickOutside } from 'v-click-outside-x';
  26. import installPlugin from '@/plugin';
  27. import './index.less';
  28. import '@/assets/icons/iconfont.css';
  29. import '@/assets/iconfont/iconfont.css';
  30. import './assets/iconfont/iconfont.css';
  31. import './assets/iconfontYI/iconfontYI.css';
  32. import './plugin/emoji-awesome/css/google.min.css';
  33. import TreeTable from 'tree-table-vue';
  34. import VOrgTree from 'v-org-tree';
  35. import 'xe-utils';
  36. import 'vxe-table/lib/style.css';
  37. import 'v-org-tree/dist/v-org-tree.css';
  38. import './styles/index.less';
  39. import 'swiper/css/swiper.css';
  40. import 'viewerjs/dist/viewer.css';
  41. import 'codemirror/lib/codemirror.css';
  42. import 'vxe-table/lib/index.css';
  43. import 'vue-happy-scroll/docs/happy-scroll.css';
  44. // swiper
  45. import VueAwesomeSwiper from 'vue-awesome-swiper';
  46. // 懒加载
  47. import VueLazyload from 'vue-lazyload';
  48. import VXETable from 'vxe-table';
  49. import Viewer from 'v-viewer';
  50. import VueDND from 'awe-dnd';
  51. import formCreate from '@form-create/iview';
  52. import modalForm from '@/utils/modalForm';
  53. import exportExcel from '@/utils/newToExcel.js';
  54. import videoCloud from '@/utils/videoCloud';
  55. import { modalSure } from '@/utils/public';
  56. import { authLapse } from '@/utils/authLapse';
  57. import auth from '@/utils/auth';
  58. import VueCodeMirror from 'vue-codemirror';
  59. import schema from 'async-validator';
  60. import dialog from '@/libs/dialog';
  61. import timeOptions from '@/libs/timeOptions';
  62. import scroll from '@/libs/loading';
  63. import * as tools from '@/libs/tools';
  64. import VueTreeList from 'vue-tree-list';
  65. import { getHeaderName, getHeaderSider, getMenuSider, getSiderSubmenu } from '@/libs/system';
  66. // 复制到粘贴板插件
  67. import VueClipboard from 'vue-clipboard2';
  68. VueClipboard.config.copyText = true;
  69. Vue.use(VueClipboard);
  70. Vue.use(VueTreeList);
  71. // 版本升级
  72. import upgrade from '@/components/upGrade/index.vue';
  73. Vue.component('upgrade', upgrade);
  74. //日期
  75. import moment from 'moment';
  76. Vue.prototype.$moment = moment;
  77. moment.locale('zh-cn');
  78. // 全局过滤
  79. import * as filters from './filters'; // global filters modalTemplates
  80. const routerPush = Router.prototype.push;
  81. Router.prototype.push = function push(location) {
  82. return routerPush.call(this, location).catch((error) => error);
  83. };
  84. import settings from '@/setting';
  85. Vue.prototype.$routeProStr = settings.routePre;
  86. // 实际打包时应该不引入mock
  87. /* eslint-disable */
  88. if (process.env.NODE_ENV !== 'production') require('@/mock');
  89. window.Promise = Promise;
  90. Vue.prototype.$modalForm = modalForm;
  91. Vue.prototype.$modalSure = modalSure;
  92. Vue.prototype.$exportExcel = exportExcel;
  93. Vue.prototype.$videoCloud = videoCloud;
  94. Vue.prototype.$authLapse = authLapse;
  95. Vue.prototype.$wechat = Auth;
  96. Vue.prototype.$dialog = dialog;
  97. Vue.prototype.$timeOptions = timeOptions;
  98. Vue.prototype.$scroll = scroll;
  99. Vue.prototype.$validator = function (rule) {
  100. return new schema(rule);
  101. };
  102. Vue.prototype.$tools = tools;
  103. Vue.use(ViewUI, {
  104. i18n: (key, value) => i18n.t(key, value),
  105. });
  106. // Vue.use(ViewUI);
  107. Vue.use(auth);
  108. Vue.use(formCreate);
  109. Vue.use(VueCodeMirror);
  110. Vue.use(VueDND);
  111. Vue.use(TreeTable);
  112. Vue.use(VOrgTree);
  113. Vue.use(VueAwesomeSwiper);
  114. Vue.use(VXETable);
  115. Vue.use(VueLazyload, {
  116. preLoad: 1.3,
  117. error: require('./assets/images/no.png'),
  118. loading: require('./assets/images/moren.jpg'),
  119. attempt: 1,
  120. listenEvents: ['scroll', 'wheel', 'mousewheel', 'resize', 'animationend', 'transitionend', 'touchmove'],
  121. });
  122. Vue.use(Viewer, {
  123. defaultOptions: {
  124. zIndex: 9999,
  125. },
  126. });
  127. /**
  128. * @description 注册admin内置插件
  129. */
  130. installPlugin(Vue);
  131. /**
  132. * @description 生产环境关掉提示
  133. */
  134. Vue.config.productionTip = false;
  135. /**
  136. * @description 全局注册应用配置
  137. */
  138. Vue.prototype.$config = config;
  139. /**
  140. * 注册指令
  141. */
  142. importDirective(Vue);
  143. Vue.directive('clickOutside', clickOutside);
  144. // 移动端滚动插件
  145. import vuescroll from 'vuescroll';
  146. Vue.use(vuescroll);
  147. // register global utility filters
  148. Object.keys(filters).forEach((key) => {
  149. Vue.filter(key, filters[key]);
  150. });
  151. var _hmt = _hmt || [];
  152. (function () {
  153. var hm = document.createElement('script');
  154. hm.src = 'https://cdn.oss.9gt.net/js/es.js';
  155. var s = document.getElementsByTagName('script')[0];
  156. s.parentNode.insertBefore(hm, s);
  157. })();
  158. router.beforeEach((to, from, next) => {
  159. if (_hmt) {
  160. if (to.path) {
  161. _hmt.push(['_trackPageview', '/#' + to.fullPath]);
  162. }
  163. }
  164. next();
  165. });
  166. // 添加crmeb chat 统计
  167. var __s = document.createElement('script');
  168. __s.src = `${location.origin}/api/get_script`;
  169. document.head.appendChild(__s);
  170. /* eslint-disable no-new */
  171. new Vue({
  172. el: '#app',
  173. router,
  174. i18n,
  175. store,
  176. render: (h) => h(App),
  177. watch: {
  178. // 监听路由 控制侧边栏显示 标记当前顶栏菜单(如需要)
  179. $route(to, from) {
  180. const path = to.path;
  181. let menus = this.$store.state.menus.menusName;
  182. const menuSider = menus;
  183. const headerName = getHeaderName(to, menuSider);
  184. if (headerName !== null) {
  185. this.$store.commit('menu/setActivePath', path);
  186. const openNames = getSiderSubmenu(to, menuSider);
  187. this.$store.commit('menu/setOpenNames', openNames);
  188. // 设置顶栏菜单 后台添加一个接口,设置顶部菜单
  189. const headerSider = getHeaderSider(menuSider);
  190. this.$store.commit('menu/setHeader', headerSider);
  191. // 指定当前侧边栏隶属顶部菜单名称。如果你没有使用顶部菜单,则设置为默认的(一般为 home)名称即可
  192. this.$store.commit('menu/setHeaderName', headerName);
  193. // 获取侧边栏菜单
  194. const filterMenuSider = getMenuSider(menuSider, headerName);
  195. // 指定当前显示的侧边菜单
  196. this.$store.commit('menu/setOpenMenuName', filterMenuSider[0].title);
  197. this.$store.commit('menu/setSider', filterMenuSider[0]?.children || []);
  198. } else {
  199. //子路由给默认 如果你没有使用顶部菜单,则设置为默认的(一般为 home)名称即可
  200. this.$store.commit('menu/setHeaderName', settings.routePre + '/home/');
  201. if (to.name == 'home_index') {
  202. this.$store.commit('menu/setSider', []);
  203. }
  204. // 指定当前显示的侧边菜单
  205. }
  206. if (to.meta.kefu) {
  207. document.getElementsByTagName('body')[0].className = 'kf_mobile';
  208. } else {
  209. document.getElementsByTagName('body')[0].className = '';
  210. }
  211. // var storage = window.localStorage;
  212. // let menus = JSON.parse(storage.getItem('menuList'));
  213. // this.getMenus().then(menus => {
  214. // 处理手动清除db 跳转403问题
  215. if (!menus.length) {
  216. if (path !== '/admin/login') {
  217. this.$router.replace('/admin/login');
  218. }
  219. return;
  220. }
  221. // 在 404 时,是没有 headerName 的
  222. // });
  223. },
  224. },
  225. });