main.js 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  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.mixin(mixins);
  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. // 设置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. if (to.path === "/analyseVariety") {
  184. to.matched[1].name = to.query.type === "look" ? "查看品种" : "分析品种";
  185. }
  186. if (to.path) {
  187. //百度统计
  188. if (window._hmt) {
  189. window._hmt.push(["_trackPageview", "/#" + to.fullPath]);
  190. }
  191. //获取权限按钮
  192. to.path != "/login"&&to.path!='/temppage'&&await store.dispatch('getPermissionButtons')
  193. next();
  194. } else {
  195. next({ path: "/404" });
  196. }
  197. });
  198. router.afterEach((to, from, next) => {
  199. // 改变页面标题
  200. document.title = to.matched[to.matched.length - 1].name
  201. ? `${setting.name}-${to.matched[to.matched.length - 1].name}`
  202. : setting.name;
  203. window.scrollTo(0, 0);
  204. if(stores.state.hasTrialUserPermisson){
  205. sessionStorage.setItem('preTitle',from.name||'')
  206. if(!stores.state.hasDoPageListening){
  207. // 初始化需要放在 页面设置标题后,才能拿到正确的标题
  208. init()
  209. stores.mutations.SET_PAGE_EVENT_LISTENER(stores.state,true)
  210. }
  211. const routerChangeType = sessionStorage.getItem('routerChangeType')
  212. if(routerChangeType==='popstate'){
  213. const IsActive = sessionStorage.getItem('IsActive')
  214. if(IsActive=='1'){
  215. endCalc('popstate',Number(sessionStorage.getItem('popStayTime')||0))
  216. }
  217. optionTimeCalc()
  218. sessionStorage.removeItem('routerChangeType')
  219. sessionStorage.removeItem('popStayTime')
  220. }
  221. }
  222. });
  223. Vue.config.devtools = true;
  224. new Vue({
  225. router,
  226. store,
  227. i18n,
  228. render: (h) => h(App),
  229. }).$mount("#app");
  230. router.onError((error) => {
  231. // 当更新服务器上打包资源时,浏览器不刷新会报错,故当监听到错误刷新浏览器
  232. window.location.reload();
  233. // const pattern = /Loading chunk (\d)+ failed/g;
  234. // const isChunkLoadFailed = error.message.match(pattern);
  235. // const targetPath = router.history.pending.fullPath;
  236. // if(isChunkLoadFailed){
  237. // router.replace(targetPath);
  238. // }
  239. });
  240. /* ie11 router jump */
  241. if (
  242. "-ms-scroll-limit" in document.documentElement.style &&
  243. "-ms-ime-align" in document.documentElement.style
  244. ) {
  245. // detect it's IE11
  246. window.addEventListener(
  247. "hashchange",
  248. function (event) {
  249. var currentPath = window.location.hash.slice(1);
  250. if (store.state.route.path !== currentPath) {
  251. router.push(currentPath);
  252. }
  253. },
  254. false
  255. );
  256. }