main.js 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  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 "@/utils/buttonPermission.js";
  13. import { dataBaseInterface } from '@/api/api.js';
  14. import { mixins } from "@/mixins";
  15. Vue.mixin(mixins);
  16. Vue.use(ElementUI);
  17. Vue.use(VueRouter);
  18. Vue.use(Vuex);
  19. import{endCalc,optionTimeCalc,init}from'@/utils/TimeOnPage.js';
  20. import setting from '@/mixins/theme.js'
  21. Vue.prototype.$setting = setting;
  22. Vue.prototype.toHistoryPage = async(EdbInfoId,from=[])=>{
  23. console.log('from',from)
  24. let pathArr = from.map(p=>{
  25. return {
  26. name:p.name||'',
  27. path:p.path||''
  28. }
  29. })
  30. pathArr.push({
  31. name:'指标溯源',
  32. path:'/edbHistory'
  33. })
  34. sessionStorage.setItem('edbHistoryPath',JSON.stringify(pathArr))
  35. //改为传code获取溯源 改的地方太多了在这里直接获取code算了
  36. const {Ret,Data} = await dataBaseInterface.targetDetail({EdbInfoId})
  37. if(Ret!==200) return
  38. const href = router.resolve({
  39. path:'/edbHistory',
  40. query:{
  41. code:Data.UniqueCode,
  42. }
  43. }).href
  44. window.open(href,"_blank")
  45. }
  46. //Import Froala Editor
  47. import "froala-editor/js/plugins.pkgd.min.js";
  48. import "froala-editor/js/plugins/quick_insert.min.js";
  49. import "froala-editor/js/plugins/font_size.min.js";
  50. // import 'froala-editor/js/languages/hr.js';
  51. //Import third party plugins
  52. import "froala-editor/js/third_party/embedly.min";
  53. import "froala-editor/js/third_party/font_awesome.min";
  54. import "froala-editor/js/third_party/spell_checker.min";
  55. import "froala-editor/js/third_party/image_tui.min";
  56. //引入中文语言包
  57. require("froala-editor/js/languages/zh_cn");
  58. require("froala-editor/js/languages/hr.js");
  59. require("froala-editor/css/froala_style.min.css");
  60. // Import Froala Editor css files.
  61. import "froala-editor/css/froala_editor.pkgd.min.css";
  62. import "froala-editor/css/plugins/quick_insert.css";
  63. // Import and use Vue Froala lib.
  64. import VueFroala from "vue-froala-wysiwyg";
  65. Vue.use(VueFroala);
  66. /* 请求数据解密 */
  67. import { parseData } from "@/utils/parseData";
  68. Vue.prototype.$parseData = parseData;
  69. /* icon */
  70. import icons from "@/utils/icon.js";
  71. Vue.prototype.$icons = icons;
  72. import Clipboard from "clipboard"; // 复制
  73. Vue.prototype.Clipboard = Clipboard;
  74. /* 全局挂载component */
  75. import "@/utils/registryComponents";
  76. /* */
  77. import Vue2OrgTree from "vue2-org-tree";
  78. import "./styles/org.scss";
  79. Vue.use(Vue2OrgTree);
  80. /* lodash */
  81. import _ from "lodash";
  82. Vue.prototype._ = _;
  83. /* moment */
  84. import moment from "moment";
  85. moment.locale("zh-cn");
  86. Vue.prototype.$moment = moment;
  87. /* VueClipboard 用于拷贝 */
  88. import VueClipboard from "vue-clipboard2";
  89. Vue.use(VueClipboard);
  90. // 瀑布流
  91. import { VueMasonryPlugin } from "vue-masonry";
  92. Vue.use(VueMasonryPlugin);
  93. import * as permissionBtn from "@/utils/buttonConfig";
  94. Vue.prototype.permissionBtn = permissionBtn
  95. // flat
  96. Array.prototype.flat = function (count) {
  97. let c = count || 1;
  98. let len = this.length;
  99. let exe = [];
  100. if (this.length == 0) return this;
  101. while (c--) {
  102. let _arr = [];
  103. let flag = false;
  104. if (exe.length == 0) {
  105. flag = true;
  106. for (let i = 0; i < len; i++) {
  107. if (this[i] instanceof Array) {
  108. exe.push(...this[i]);
  109. } else {
  110. exe.push(this[i]);
  111. }
  112. }
  113. } else {
  114. for (let i = 0; i < exe.length; i++) {
  115. if (exe[i] instanceof Array) {
  116. flag = true;
  117. _arr.push(...exe[i]);
  118. } else {
  119. _arr.push(exe[i]);
  120. }
  121. }
  122. exe = _arr;
  123. }
  124. if (!flag && c == Infinity) {
  125. break;
  126. }
  127. }
  128. return exe;
  129. };
  130. export const router = new VueRouter({
  131. mode: "history",
  132. routes,
  133. });
  134. export const store = new Vuex.Store({
  135. ...stores,
  136. });
  137. //import { getUserUuid } from "./api/api";
  138. router.beforeEach(async(to, from, next) => {
  139. // 判断本地是否有uuid
  140. /* const uuid = localStorage.getItem("uuid");
  141. if (!uuid) {
  142. getUserUuid().then((res) => {
  143. if (res.Ret == 200) {
  144. localStorage.setItem("uuid", res.Data);
  145. }
  146. });
  147. } */
  148. let auth = localStorage.getItem("auth") || false;
  149. if (to.path != "/login" && to.path!='/temppage' &&to.path!='/fogetpassword' && !auth) {
  150. window.location.href = window.location.origin + '/login';
  151. return false;
  152. }
  153. /* 沙盘详情name添加 */
  154. if (to.path === "/sandflow") {
  155. to.matched[1].name = to.query.SandboxId? "编辑逻辑": "添加逻辑";
  156. }
  157. if (to.path === "/analyseVariety") {
  158. to.matched[1].name = to.query.type === "look" ? "查看品种" : "分析品种";
  159. }
  160. if (to.path) {
  161. //百度统计
  162. if (window._hmt) {
  163. window._hmt.push(["_trackPageview", "/#" + to.fullPath]);
  164. }
  165. //获取权限按钮
  166. to.path != "/login"&&to.path!='/temppage'&&await store.dispatch('getPermissionButtons')
  167. next();
  168. } else {
  169. next({ path: "/404" });
  170. }
  171. });
  172. router.afterEach((to, from, next) => {
  173. // 改变页面标题
  174. document.title = to.matched[to.matched.length - 1].name
  175. ? `${setting.name}-${to.matched[to.matched.length - 1].name}`
  176. : setting.name;
  177. window.scrollTo(0, 0);
  178. if(stores.state.hasTrialUserPermisson){
  179. sessionStorage.setItem('preTitle',from.name||'')
  180. if(!stores.state.hasDoPageListening){
  181. // 初始化需要放在 页面设置标题后,才能拿到正确的标题
  182. init()
  183. stores.mutations.SET_PAGE_EVENT_LISTENER(stores.state,true)
  184. }
  185. const routerChangeType = sessionStorage.getItem('routerChangeType')
  186. if(routerChangeType==='popstate'){
  187. const IsActive = sessionStorage.getItem('IsActive')
  188. if(IsActive=='1'){
  189. endCalc('popstate',Number(sessionStorage.getItem('popStayTime')||0))
  190. }
  191. optionTimeCalc()
  192. sessionStorage.removeItem('routerChangeType')
  193. sessionStorage.removeItem('popStayTime')
  194. }
  195. }
  196. });
  197. Vue.config.devtools = true;
  198. new Vue({
  199. router,
  200. store,
  201. render: (h) => h(App),
  202. }).$mount("#app");
  203. router.onError((error) => {
  204. // 当更新服务器上打包资源时,浏览器不刷新会报错,故当监听到错误刷新浏览器
  205. window.location.reload();
  206. // const pattern = /Loading chunk (\d)+ failed/g;
  207. // const isChunkLoadFailed = error.message.match(pattern);
  208. // const targetPath = router.history.pending.fullPath;
  209. // if(isChunkLoadFailed){
  210. // router.replace(targetPath);
  211. // }
  212. });
  213. /* ie11 router jump */
  214. if (
  215. "-ms-scroll-limit" in document.documentElement.style &&
  216. "-ms-ime-align" in document.documentElement.style
  217. ) {
  218. // detect it's IE11
  219. window.addEventListener(
  220. "hashchange",
  221. function (event) {
  222. var currentPath = window.location.hash.slice(1);
  223. if (store.state.route.path !== currentPath) {
  224. router.push(currentPath);
  225. }
  226. },
  227. false
  228. );
  229. }