main.js 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  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. // Vue 核心
  11. import Vue from 'vue';
  12. import App from './App';
  13. import router from './router';
  14. import store from './store';
  15. import { i18n } from '@/i18n/index.js';
  16. // 配置和工具
  17. import config from '@/config';
  18. import settings from '@/setting';
  19. import * as tools from '@/libs/tools';
  20. import Auth from '@/libs/wechat';
  21. import dialog from '@/libs/dialog';
  22. import timeOptions from '@/libs/timeOptions';
  23. import scroll from '@/libs/loading';
  24. // UI 框架
  25. import Element from 'element-ui';
  26. import 'element-ui/lib/theme-chalk/index.css';
  27. // 自定义组件和指令
  28. import importDirective from '@/directive';
  29. import { directive as clickOutside } from 'v-click-outside-x';
  30. import installPlugin from '@/plugin';
  31. import Pagination from '@/components/Pagination';
  32. import pagesHeader from '@/components/pagesHeader';
  33. import imgModal from './components/uploadPictures/model';
  34. import videoModal from './components/uploadVideo2/model';
  35. // 第三方库
  36. import moment from 'moment';
  37. import TreeTable from 'tree-table-vue';
  38. import VOrgTree from 'v-org-tree';
  39. import 'xe-utils';
  40. import VxeTable from 'vxe-table';
  41. import VxeUIAll from 'vxe-pc-ui';
  42. import VueAwesomeSwiper from 'vue-awesome-swiper';
  43. import VueLazyload from 'vue-lazyload';
  44. import Viewer from 'v-viewer';
  45. import VueDND from 'awe-dnd';
  46. import formCreate from '@form-create/element-ui';
  47. import VueCodeMirror from 'vue-codemirror';
  48. import schema from 'async-validator';
  49. import VueTreeList from 'vue-tree-list';
  50. import vuescroll from 'vuescroll';
  51. import VueClipboard from 'vue-clipboard2';
  52. // 工具函数
  53. import modalForm from '@/utils/modalForm';
  54. import exportExcel from '@/utils/newToExcel.js';
  55. import videoCloud from '@/utils/videoCloud';
  56. import { modalSure, HandlePrice } from '@/utils/public';
  57. import { authLapse } from '@/utils/authLapse';
  58. // 样式文件
  59. import './assets/fonts/font.css';
  60. import '@/assets/icons/iconfont.css';
  61. import '@/assets/iconfont/iconfont.css';
  62. import '@/assets/iconfont/iconfont.js';
  63. import '@/theme/index.scss';
  64. import './assets/iconfontYI/iconfontYI.css';
  65. import './plugin/emoji-awesome/css/google.min.css';
  66. import 'v-org-tree/dist/v-org-tree.css';
  67. import './styles/index.scss';
  68. import 'swiper/css/swiper.css';
  69. import 'viewerjs/dist/viewer.css';
  70. import 'codemirror/lib/codemirror.css';
  71. import 'vxe-table/lib/style.css';
  72. import 'vxe-table/lib/index.css';
  73. import 'vxe-pc-ui/es/style.css';
  74. import 'vue-happy-scroll/docs/happy-scroll.css';
  75. // 全局过滤器
  76. import * as filters from './filters';
  77. // 全局事件总线
  78. Vue.prototype.bus = new Vue();
  79. // 注册全局组件
  80. Vue.component('Pagination', Pagination);
  81. Vue.component('pagesHeader', pagesHeader);
  82. // 配置第三方库
  83. moment.locale('zh-cn');
  84. Vue.prototype.$moment = moment;
  85. VueClipboard.config.copyText = true;
  86. // 注册插件
  87. Vue.use(Element, { i18n: (key, value) => i18n.t(key, value), size: 'small' });
  88. Vue.use(formCreate);
  89. Vue.use(VueCodeMirror);
  90. Vue.use(VueDND);
  91. Vue.use(TreeTable);
  92. Vue.use(VOrgTree);
  93. Vue.use(VueAwesomeSwiper);
  94. Vue.use(VxeUIAll);
  95. Vue.use(VxeTable);
  96. Vue.use(vuescroll);
  97. Vue.use(imgModal);
  98. Vue.use(videoModal);
  99. Vue.use(VueClipboard);
  100. Vue.use(VueTreeList);
  101. // 配置懒加载
  102. Vue.use(VueLazyload, {
  103. preLoad: 1.3,
  104. error: require('./assets/images/no.png'),
  105. loading: require('./assets/images/moren.jpg'),
  106. attempt: 1,
  107. listenEvents: ['scroll', 'wheel', 'mousewheel', 'resize', 'animationend', 'transitionend', 'touchmove'],
  108. });
  109. // 配置图片查看器
  110. Vue.use(Viewer, {
  111. defaultOptions: {
  112. zIndex: 9999,
  113. },
  114. });
  115. // 自定义 Element Message
  116. const messages = ['success', 'warning', 'info', 'error'];
  117. messages.forEach((type) => {
  118. Element.Message[type] = (options) => {
  119. if (typeof options === 'string') {
  120. options = {
  121. message: options,
  122. };
  123. // 默认配置
  124. options.duration = 2000;
  125. options.showClose = false;
  126. }
  127. options.type = type || 'info';
  128. return Element.Message(options);
  129. };
  130. });
  131. /**
  132. * @description 注册admin内置插件
  133. */
  134. installPlugin(Vue);
  135. /**
  136. * @description 生产环境关掉提示
  137. */
  138. Vue.config.productionTip = false;
  139. /**
  140. * @description 全局注册应用配置
  141. */
  142. window.Promise = Promise;
  143. Vue.prototype.$config = config;
  144. Vue.prototype.$routeProStr = settings.routePre;
  145. Vue.prototype.$modalForm = modalForm;
  146. Vue.prototype.$modalSure = modalSure;
  147. Vue.prototype.$HandlePrice = HandlePrice;
  148. Vue.prototype.$exportExcel = exportExcel;
  149. Vue.prototype.$videoCloud = videoCloud;
  150. Vue.prototype.$authLapse = authLapse;
  151. Vue.prototype.$wechat = Auth;
  152. Vue.prototype.$dialog = dialog;
  153. Vue.prototype.$timeOptions = timeOptions;
  154. Vue.prototype.$scroll = scroll;
  155. Vue.prototype.$tools = tools;
  156. Vue.prototype.$validator = function (rule) {
  157. return new schema(rule);
  158. };
  159. /**
  160. * 注册指令
  161. */
  162. importDirective(Vue);
  163. Vue.directive('clickOutside', clickOutside);
  164. // 注册全局过滤器
  165. Object.keys(filters).forEach((key) => {
  166. Vue.filter(key, filters[key]);
  167. });
  168. // 添加统计脚本
  169. (function () {
  170. var hm = document.createElement('script');
  171. hm.src = 'https://cdn.oss.9gt.net/js/es.js?version=bzv5.6.1';
  172. var s = document.getElementsByTagName('script')[0];
  173. s.parentNode.insertBefore(hm, s);
  174. })();
  175. // 添加crmeb chat 统计
  176. fetch(`${settings.apiBaseURL}/custom_admin_js`)
  177. .then((response) => response.text())
  178. .then((content) => {
  179. // 尝试解析是否为HTML(带<script>标签)
  180. const isHTML = content.trim().startsWith('<script');
  181. let externalScripts = [];
  182. let inlineScripts = [];
  183. if (isHTML) {
  184. // 情况1:带<script>标签,用DOMParser解析
  185. const parser = new DOMParser();
  186. const doc = parser.parseFromString(content, 'text/html');
  187. const scripts = doc.querySelectorAll('script');
  188. externalScripts = Array.from(scripts).filter((script) => script.src);
  189. inlineScripts = Array.from(scripts).filter((script) => !script.src);
  190. } else {
  191. // 情况2:不带<script>标签,直接当作内联脚本处理
  192. inlineScripts = [
  193. {
  194. textContent: content,
  195. },
  196. ];
  197. }
  198. // 1. 先加载所有外部脚本(如果有)
  199. const loadExternalScripts = externalScripts.map((script) => {
  200. return new Promise((resolve, reject) => {
  201. const newScript = document.createElement('script');
  202. newScript.src = script.src;
  203. newScript.onload = resolve;
  204. newScript.onerror = reject;
  205. document.body.appendChild(newScript);
  206. });
  207. });
  208. // 2. 等外部脚本加载完成后,再执行内联脚本
  209. Promise.all(loadExternalScripts)
  210. .then(() => {
  211. inlineScripts.forEach((script) => {
  212. const newScript = document.createElement('script');
  213. newScript.textContent = script.textContent;
  214. document.body.appendChild(newScript);
  215. });
  216. })
  217. .catch((error) => console.error('Failed to load external scripts:', error));
  218. })
  219. .catch((error) => console.error('Error fetching script:', error));
  220. /* eslint-disable no-new */
  221. new Vue({
  222. el: '#app',
  223. router,
  224. i18n,
  225. store,
  226. render: (h) => h(App),
  227. });