main.js 8.5 KB

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