main.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. // The Vue build version to load with the `import` command
  2. // (runtime-only or standalone) has been set in webpack.base.conf with an alias.
  3. import Vue from 'vue'
  4. import App from './App'
  5. import router from './router'
  6. import VueRouter from 'vue-router';
  7. import './public-path';
  8. import globalData from '@/components/common/globaldata/global.data';
  9. let instance = null
  10. import VueAMap from 'vue-amap'
  11. // import actions from './micro/actions.js'
  12. Vue.use(VueAMap);
  13. Vue.use(globalData);
  14. VueAMap.initAMapApiLoader({
  15. key: '0ef96708d5fb4a73de7e72be72cf7648',
  16. Plugin: ['AMap.Scale', 'AMap.OverView', 'AMap.ToolBar', 'AMap.MapType', 'AMap.MarkerClusterer']
  17. });
  18. // import Echarts from 'echarts'
  19. var Echarts = require('echarts');
  20. Vue.prototype.dateFormatA = function (row, column) {
  21. let date = row[column.property];
  22. if (Vue.prototype.isEmptyObjVue(date)) {
  23. return '';
  24. }
  25. return moment(date).format('YYYY-MM-DD HH:mm');
  26. }
  27. Vue.prototype.$echarts = Echarts;
  28. import dataV from '@jiaminghi/data-view'
  29. Vue.use(dataV)
  30. // console.log(window.location);
  31. import util from './script/util'
  32. // let token=util.getUrlKey('token');
  33. // console.log(token);
  34. import Axios from 'axios';
  35. import ElementUI from 'element-ui';
  36. import moment from 'moment'
  37. import {
  38. Message
  39. } from 'element-ui';
  40. import 'element-ui/lib/theme-chalk/index.css'; // 默认主题
  41. Vue.use(ElementUI, {
  42. size: 'small'
  43. });
  44. //列表斑马线显示
  45. ElementUI.Table.props.stripe = { type: Boolean, default: true }
  46. //判空
  47. Vue.prototype.isEmptyObjVue = function (obj) {
  48. if (obj == null || obj == undefined || ("" + obj) == "") {
  49. return true;
  50. }
  51. return false;
  52. };
  53. Vue.prototype.formateDay = function (date) {
  54. if (Vue.prototype.isEmptyObjVue(date)) {
  55. return '';
  56. }
  57. return moment(date).format('YYYY-MM-DD');
  58. }
  59. Vue.prototype.formateMonth = function (date) {
  60. if (Vue.prototype.isEmptyObjVue(date)) {
  61. return '';
  62. }
  63. return moment(date).format('YYYY-MM');
  64. }
  65. Vue.prototype.$axios = Axios;
  66. Vue.config.productionTip = false
  67. let apiUrl = process.env.baseUrl;
  68. // console.log(apiUrl);
  69. Axios.defaults.timeout = 300000; //设置请求时间
  70. Axios.defaults.baseURL = apiUrl;
  71. var loading;
  72. function startLoading() {
  73. loading = (new Vue()).$loading({
  74. lock: true,
  75. text: "拼命加载中...",
  76. background: "rgba(0,0,0,0.4)"
  77. });
  78. }
  79. function endLoading() {
  80. loading.close();
  81. }
  82. Vue.prototype.formatMinute = function (duration) {
  83. if (!duration) return "00小时00分00秒";
  84. let day = parseInt(duration / (60 * 60 * 24))
  85. let h = parseInt((duration % (60 * 60 * 24)) / (60 * 60))
  86. let m = parseInt((duration - h * 60 * 60 - day * (60 * 60 * 24)) / 60)
  87. let s = (duration % 60).toFixed(0);
  88. h = h.toString().length < 2 ? "0" + h.toString() : h.toString();
  89. m = m.toString().length < 2 ? "0" + m.toString() : m.toString();
  90. s = s.toString().length < 2 ? "0" + s.toString() : s.toString();
  91. return h + '小时' + m.toString() + '分' + s.toString() + '秒';
  92. }
  93. Axios.interceptors.request.use(
  94. config => {
  95. if (config.url.indexOf('/salesGmvAndBookcount') == -1 && config.url.indexOf('/bigScreen') == -1) {
  96. startLoading();
  97. }
  98. config.headers.token = window.localStorage.getItem('token');
  99. // config.headers.token = token;
  100. return config;
  101. },
  102. err => {
  103. Message.error('请求超时!');
  104. return Promise.reject(err);
  105. });
  106. //axios统一错误处理
  107. Axios.interceptors.response.use(data => {
  108. endLoading();
  109. // if (data.status && data.status == 200) {
  110. // }
  111. if (data.data.errno == 501) {
  112. Message.error({ message: '服务端错误: ' + data.data.errmsg });
  113. }
  114. if (data.data.errno == 502) {
  115. Message.error({ message: '服务端错误: ' + data.data.data + data.data.errmsg });
  116. }
  117. if (data.data.errno == 503) {
  118. Message.error({ message: '服务器异常,请联系相关人员!' })
  119. }
  120. if (data.data.errno == 400) {
  121. // Message.error({ message: '权限不够' });
  122. Message.error({ message: data.data.errmsg });
  123. }
  124. if (data.data.errno == 401) {
  125. Message.error({
  126. message: '身份过期,请重新登陆'
  127. });
  128. if (window.localStorage.getItem('token') == "") {
  129. Message.error({
  130. message: '身份过期,请重新登陆'
  131. });
  132. // router.push('/login');
  133. // window.localStorage.removeItem('token')
  134. }
  135. // router.push('/login');
  136. // window.localStorage.removeItem('token')
  137. }
  138. // return data;
  139. if (data.data.errno == 0) {
  140. return data
  141. } else if (data.data.errno == -1) {
  142. Message.error({
  143. message: data.data.data
  144. });
  145. return Promise.reject(data);
  146. } else {
  147. if (data.status == 200 && data.request.responseType == 'blob')
  148. return data;
  149. return Promise.reject(data);
  150. }
  151. }, err => {
  152. endLoading();
  153. (new Vue()).$message({
  154. showClose: true,
  155. message: '接口错误,请稍后重试',
  156. type: 'error'
  157. });
  158. return Promise.reject(err);
  159. })
  160. /* eslint-disable no-new */
  161. // new Vue({
  162. // el: '#app',
  163. // router,
  164. // components: { App },
  165. // template: '<App/>'
  166. // })
  167. let routers = null;
  168. function render(props = {}) {
  169. const { container } = props
  170. routers = new VueRouter({
  171. base: window.__POWERED_BY_QIANKUN__ ? '/report' : '/',
  172. mode: 'history',
  173. router,
  174. });
  175. instance = new Vue({
  176. router,
  177. data(){
  178. return {
  179. parentStore: props.parentStore,
  180. }
  181. },
  182. render: (h) => h(App),
  183. }).$mount(container ? container.querySelector("#sub-report") :'#sub-report');
  184. }
  185. // 独立运行时
  186. if (!window.__POWERED_BY_QIANKUN__) {
  187. render();
  188. }
  189. export async function bootstrap() {
  190. console.log('[vue] vue app bootstraped');
  191. }
  192. export async function mount(props) {
  193. render(props);
  194. }
  195. export async function unmount() {
  196. instance.$destroy();
  197. instance.$el.innerHTML = '';
  198. instance = null;
  199. }
  200. // onBeforeUnmount(() => {
  201. // state.microApp.unmount(); // state.microApp 为微应用实例
  202. // });
  203. ;