main.js 8.5 KB

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