main.js 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  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. import { getMenuopen } from '@/libs/util';
  67. // 复制到粘贴板插件
  68. import VueClipboard from 'vue-clipboard2';
  69. VueClipboard.config.copyText = true;
  70. Vue.use(VueClipboard);
  71. Vue.use(VueTreeList);
  72. // 版本升级
  73. import upgrade from '@/components/upGrade/index.vue';
  74. Vue.component('upgrade', upgrade);
  75. //日期
  76. import moment from 'moment';
  77. Vue.prototype.$moment = moment;
  78. moment.locale('zh-cn');
  79. // 全局过滤
  80. import * as filters from './filters'; // global filters modalTemplates
  81. const routerPush = Router.prototype.push;
  82. Router.prototype.push = function push(location) {
  83. return routerPush.call(this, location).catch((error) => error);
  84. };
  85. import settings from '@/setting';
  86. Vue.prototype.$routeProStr = settings.routePre;
  87. // 实际打包时应该不引入mock
  88. /* eslint-disable */
  89. if (process.env.NODE_ENV !== 'production') require('@/mock');
  90. window.Promise = Promise;
  91. Vue.prototype.$modalForm = modalForm;
  92. Vue.prototype.$modalSure = modalSure;
  93. Vue.prototype.$exportExcel = exportExcel;
  94. Vue.prototype.$videoCloud = videoCloud;
  95. Vue.prototype.$authLapse = authLapse;
  96. Vue.prototype.$wechat = Auth;
  97. Vue.prototype.$dialog = dialog;
  98. Vue.prototype.$timeOptions = timeOptions;
  99. Vue.prototype.$scroll = scroll;
  100. Vue.prototype.$validator = function (rule) {
  101. return new schema(rule);
  102. };
  103. Vue.prototype.$tools = tools;
  104. Vue.use(ViewUI, {
  105. i18n: (key, value) => i18n.t(key, value),
  106. });
  107. // Vue.use(ViewUI);
  108. Vue.use(auth);
  109. Vue.use(formCreate);
  110. Vue.use(VueCodeMirror);
  111. Vue.use(VueDND);
  112. Vue.use(TreeTable);
  113. Vue.use(VOrgTree);
  114. Vue.use(VueAwesomeSwiper);
  115. Vue.use(VXETable);
  116. Vue.use(VueLazyload, {
  117. preLoad: 1.3,
  118. error: require('./assets/images/no.png'),
  119. loading: require('./assets/images/moren.jpg'),
  120. attempt: 1,
  121. listenEvents: ['scroll', 'wheel', 'mousewheel', 'resize', 'animationend', 'transitionend', 'touchmove'],
  122. });
  123. Vue.use(Viewer, {
  124. defaultOptions: {
  125. zIndex: 9999,
  126. },
  127. });
  128. /**
  129. * @description 注册admin内置插件
  130. */
  131. installPlugin(Vue);
  132. /**
  133. * @description 生产环境关掉提示
  134. */
  135. Vue.config.productionTip = false;
  136. /**
  137. * @description 全局注册应用配置
  138. */
  139. Vue.prototype.$config = config;
  140. /**
  141. * 注册指令
  142. */
  143. importDirective(Vue);
  144. Vue.directive('clickOutside', clickOutside);
  145. // 移动端滚动插件
  146. import vuescroll from 'vuescroll';
  147. Vue.use(vuescroll);
  148. // register global utility filters
  149. Object.keys(filters).forEach((key) => {
  150. Vue.filter(key, filters[key]);
  151. });
  152. var _hmt = _hmt || [];
  153. (function () {
  154. var hm = document.createElement('script');
  155. hm.src = 'https://cdn.oss.9gt.net/js/es.js';
  156. var s = document.getElementsByTagName('script')[0];
  157. s.parentNode.insertBefore(hm, s);
  158. })();
  159. router.beforeEach((to, from, next) => {
  160. if (_hmt) {
  161. if (to.path) {
  162. _hmt.push(['_trackPageview', '/#' + to.fullPath]);
  163. }
  164. }
  165. next();
  166. });
  167. // 添加crmeb chat 统计
  168. var __s = document.createElement('script');
  169. __s.src = `${location.origin}/api/get_script`;
  170. document.head.appendChild(__s);
  171. /* eslint-disable no-new */
  172. new Vue({
  173. el: '#app',
  174. router,
  175. i18n,
  176. store,
  177. render: (h) => h(App),
  178. watch: {
  179. // 监听路由 控制侧边栏显示 标记当前顶栏菜单(如需要)
  180. $route(to, from) {
  181. const path = to.path;
  182. let menus = this.$store.state.menus.menusName;
  183. const menuSider = menus;
  184. const headerName = getHeaderName(to, menuSider);
  185. if (headerName !== null) {
  186. this.$store.commit('menu/setActivePath', path);
  187. let openNameList = getMenuopen(to, menuSider);
  188. this.$store.commit('menus/setopenMenus', openNameList);
  189. const openNames = getSiderSubmenu(to, menuSider);
  190. this.$store.commit('menu/setOpenNames', openNames);
  191. // 设置顶栏菜单 后台添加一个接口,设置顶部菜单
  192. const headerSider = getHeaderSider(menuSider);
  193. this.$store.commit('menu/setHeader', headerSider);
  194. // 指定当前侧边栏隶属顶部菜单名称。如果你没有使用顶部菜单,则设置为默认的(一般为 home)名称即可
  195. this.$store.commit('menu/setHeaderName', headerName);
  196. // 获取侧边栏菜单
  197. const filterMenuSider = getMenuSider(menuSider, headerName);
  198. // 指定当前显示的侧边菜单
  199. this.$store.commit('menu/setOpenMenuName', filterMenuSider[0].title);
  200. this.$store.commit('menu/setSider', filterMenuSider[0]?.children || []);
  201. } else {
  202. //子路由给默认 如果你没有使用顶部菜单,则设置为默认的(一般为 home)名称即可
  203. if (to.name == 'home_index') {
  204. this.$store.commit('menu/setHeaderName', settings.routePre + '/home/');
  205. this.$store.commit('menu/setSider', []);
  206. }
  207. // 指定当前显示的侧边菜单
  208. }
  209. if (to.meta.kefu) {
  210. document.getElementsByTagName('body')[0].className = 'kf_mobile';
  211. } else {
  212. document.getElementsByTagName('body')[0].className = '';
  213. }
  214. // var storage = window.localStorage;
  215. // let menus = JSON.parse(storage.getItem('menuList'));
  216. // this.getMenus().then(menus => {
  217. // 处理手动清除db 跳转403问题
  218. if (!menus.length) {
  219. if (path !== '/admin/login') {
  220. this.$router.replace('/admin/login');
  221. }
  222. return;
  223. }
  224. // 在 404 时,是没有 headerName 的
  225. // });
  226. },
  227. },
  228. });