main.js 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  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. import VueI18n from 'vue-i18n';
  16. import messagesLocal from './lang/index';
  17. import langEN from 'element-ui/lib/locale/lang/en'
  18. import langZH from 'element-ui/lib/locale/lang/zh-CN'
  19. import locale from 'element-ui/lib/locale'
  20. Vue.use(VueI18n);
  21. const i18n = new VueI18n({
  22. locale: localStorage.getItem('i18n')||'zh', // 默认语言
  23. messages:{
  24. zh:{
  25. ...langZH,
  26. ...messagesLocal.zh,
  27. },
  28. en:{
  29. ...langEN,
  30. ...messagesLocal.en
  31. }
  32. },
  33. // 隐藏警告
  34. silentTranslationWarn: true
  35. });
  36. Vue.use(ElementUI);
  37. Vue.use(VueRouter);
  38. Vue.use(Vuex);
  39. Vue.prototype.$i18nt = i18n;
  40. Vue.mixin(mixins);
  41. // 设置element语言
  42. // locale.use(localStorage.getItem('i18n')!='zh' ? langEN:langZH )
  43. locale.i18n((key, value) => i18n.t(key, value))
  44. import{endCalc,optionTimeCalc,init}from'@/utils/TimeOnPage.js';
  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. // flat
  122. Array.prototype.flat = function (count) {
  123. let c = count || 1;
  124. let len = this.length;
  125. let exe = [];
  126. if (this.length == 0) return this;
  127. while (c--) {
  128. let _arr = [];
  129. let flag = false;
  130. if (exe.length == 0) {
  131. flag = true;
  132. for (let i = 0; i < len; i++) {
  133. if (this[i] instanceof Array) {
  134. exe.push(...this[i]);
  135. } else {
  136. exe.push(this[i]);
  137. }
  138. }
  139. } else {
  140. for (let i = 0; i < exe.length; i++) {
  141. if (exe[i] instanceof Array) {
  142. flag = true;
  143. _arr.push(...exe[i]);
  144. } else {
  145. _arr.push(exe[i]);
  146. }
  147. }
  148. exe = _arr;
  149. }
  150. if (!flag && c == Infinity) {
  151. break;
  152. }
  153. }
  154. return exe;
  155. };
  156. export const router = new VueRouter({
  157. mode: "history",
  158. routes,
  159. });
  160. export const store = new Vuex.Store({
  161. ...stores,
  162. });
  163. //import { getUserUuid } from "./api/api";
  164. router.beforeEach(async(to, from, next) => {
  165. // 判断本地是否有uuid
  166. /* const uuid = localStorage.getItem("uuid");
  167. if (!uuid) {
  168. getUserUuid().then((res) => {
  169. if (res.Ret == 200) {
  170. localStorage.setItem("uuid", res.Data);
  171. }
  172. });
  173. } */
  174. let auth = localStorage.getItem("auth") || false;
  175. if (to.path != "/login" && to.path!='/temppage' &&to.path!='/fogetpassword' && !auth) {
  176. window.location.href = window.location.origin + '/login';
  177. return false;
  178. }
  179. /* 沙盘详情name添加 */
  180. if (to.path === "/sandflow") {
  181. to.matched[1].name = to.query.SandboxId? "编辑逻辑": "添加逻辑";
  182. //支持英文
  183. to.matched[1].meta.name_en = to.query.SandboxId? "Edit Logic": "Add Logic";
  184. }
  185. if (to.path === "/analyseVariety") {
  186. to.matched[1].name = to.query.type === "look" ? "查看品种" : "分析品种";
  187. //支持英文
  188. to.matched[1].meta.name_en = to.query.type === "look" ? "View Variety" : "Analyse Variety";
  189. }
  190. if (to.path) {
  191. //百度统计
  192. if (window._hmt) {
  193. window._hmt.push(["_trackPageview", "/#" + to.fullPath]);
  194. }
  195. /* //store没做持久化存储,在请求前先获取旧的
  196. store.dispatch('getPermissionButtonsOld') */
  197. //获取权限按钮
  198. to.path != "/login"&&to.path!='/temppage'&&await store.dispatch('getPermissionButtons')
  199. next();
  200. } else {
  201. next({ path: "/404" });
  202. }
  203. });
  204. router.afterEach((to, from, next) => {
  205. /* // 改变页面标题
  206. document.title = to.matched[to.matched.length - 1].name
  207. ? `${to.matched[to.matched.length - 1].name}`
  208. : setting.name; */
  209. //改变页面标题-中英文
  210. const titleZh = to.matched[to.matched.length - 1].name||''
  211. const titleEn = to.matched[to.matched.length - 1].meta.name_en||''
  212. const title = i18n.locale==='zh'?titleZh:titleEn
  213. document.title = title||setting.name
  214. window.scrollTo(0, 0);
  215. if(stores.state.hasTrialUserPermisson){
  216. sessionStorage.setItem('preTitle',from.name||'')
  217. if(!stores.state.hasDoPageListening){
  218. // 初始化需要放在 页面设置标题后,才能拿到正确的标题
  219. init()
  220. stores.mutations.SET_PAGE_EVENT_LISTENER(stores.state,true)
  221. }
  222. const routerChangeType = sessionStorage.getItem('routerChangeType')
  223. if(routerChangeType==='popstate'){
  224. const IsActive = sessionStorage.getItem('IsActive')
  225. if(IsActive=='1'){
  226. endCalc('popstate',Number(sessionStorage.getItem('popStayTime')||0))
  227. }
  228. optionTimeCalc()
  229. sessionStorage.removeItem('routerChangeType')
  230. sessionStorage.removeItem('popStayTime')
  231. }
  232. }
  233. });
  234. Vue.config.devtools = true;
  235. new Vue({
  236. router,
  237. store,
  238. i18n,
  239. render: (h) => h(App),
  240. }).$mount("#app");
  241. router.onError((error) => {
  242. // 当更新服务器上打包资源时,浏览器不刷新会报错,故当监听到错误刷新浏览器
  243. window.location.reload();
  244. // const pattern = /Loading chunk (\d)+ failed/g;
  245. // const isChunkLoadFailed = error.message.match(pattern);
  246. // const targetPath = router.history.pending.fullPath;
  247. // if(isChunkLoadFailed){
  248. // router.replace(targetPath);
  249. // }
  250. });
  251. /* ie11 router jump */
  252. if (
  253. "-ms-scroll-limit" in document.documentElement.style &&
  254. "-ms-ime-align" in document.documentElement.style
  255. ) {
  256. // detect it's IE11
  257. window.addEventListener(
  258. "hashchange",
  259. function (event) {
  260. var currentPath = window.location.hash.slice(1);
  261. if (store.state.route.path !== currentPath) {
  262. router.push(currentPath);
  263. }
  264. },
  265. false
  266. );
  267. }
  268. /* window.addEventListener('beforeunload',()=>{
  269. sessionStorage.setItem('permissionBtn',JSON.stringify(store.state.permissionButton.permissionButtons))
  270. }) */