main.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. import Vue from 'vue'
  2. import App from './App.vue'
  3. import router from './router'
  4. import store from './store'
  5. import ElementUI from 'element-ui';
  6. import moment from 'moment' // 时间库
  7. import 'element-ui/lib/theme-chalk/index.css';
  8. import * as dd from 'dingtalk-jsapi';
  9. import VConsole from 'vconsole'
  10. import './icons' // icon
  11. import axios from 'axios'
  12. import service from './api/axios'
  13. import echarts from 'echarts'
  14. import NProgress from 'nprogress';
  15. import 'nprogress/nprogress.css'
  16. import {
  17. getEmployeeList,
  18. setEmployeeList,
  19. getDeptTree,
  20. setDeptTree,
  21. getToken,
  22. setToken,
  23. getUserData,
  24. setUserData,
  25. getIsCreator,
  26. supremeAuthority,
  27. isAuthoritys,
  28. authoritys,
  29. generateUUID,
  30. getCache,
  31. setCache,
  32. removeCache,
  33. getCycleType,
  34. getRole,
  35. returnCode
  36. } from './api/auth';
  37. Vue.prototype.$isAuthoritys = isAuthoritys
  38. Vue.prototype.$getCycleType = getCycleType
  39. Vue.prototype.$getRole = getRole
  40. Vue.prototype.$getEmployeeList = getEmployeeList
  41. Vue.prototype.$setEmployeeList = setEmployeeList
  42. Vue.prototype.$getDeptTree = getDeptTree
  43. Vue.prototype.$setDeptTree = setDeptTree
  44. Vue.prototype.$getToken = getToken
  45. Vue.prototype.$setToken = setToken
  46. Vue.prototype.$getUserData = getUserData
  47. Vue.prototype.$setUserData = setUserData
  48. Vue.prototype.$getIsCreator = getIsCreator
  49. Vue.prototype.$supremeAuthority = supremeAuthority
  50. Vue.prototype.$authoritys = authoritys
  51. Vue.prototype.$getCache = getCache
  52. Vue.prototype.$setCache = setCache
  53. Vue.prototype.$returnCode = returnCode //UID 唯一标识
  54. Vue.prototype.$removeCache = removeCache
  55. Vue.prototype.$generateUUID = generateUUID //UID 唯一标识
  56. import * as socketApi from './api/websocket'
  57. // 新绩效系统相关
  58. import Pagination from '@/components/public/Pagination'
  59. import PreBox from '@/components/public/PreBox'
  60. Vue.component('Pagination', Pagination)
  61. Vue.component('PreBox', PreBox)
  62. // 头像
  63. import userImage from '@/components/public/UserImage'
  64. import NoData from '@/components/public/NoData'
  65. import BrawerBox from '@/components/public/BrawerBox';
  66. Vue.component('userImage', userImage)
  67. Vue.component('NoData', NoData)
  68. Vue.component('BrawerBox', BrawerBox)
  69. Vue.use(ElementUI);
  70. // if (process.env.NODE_ENV === 'development') {
  71. new VConsole()
  72. // }
  73. Vue.prototype.$moment = moment
  74. Vue.prototype.$echarts = echarts
  75. Vue.prototype.$dd = dd;
  76. Vue.prototype.$socketApi = socketApi //长连接
  77. Vue.prototype.$appId = process.env.VUE_APP_APPID //小程序APPID
  78. Vue.prototype.$serverdomain = process.env.VUE_APP_BASE_API //导出地址
  79. Vue.prototype.$1 = 1
  80. Vue.prototype.$2 = 2
  81. Vue.prototype.$3 = 3
  82. Vue.prototype.$4 = 4
  83. Vue.prototype.$5 = 5
  84. Vue.prototype.$6 = 6
  85. Vue.prototype.$7 = 7
  86. Vue.prototype.$8 = 8
  87. Vue.prototype.$9 = 9
  88. Vue.prototype.$10 = 10
  89. Vue.prototype.$11 = 11
  90. Vue.prototype.$12 = 12
  91. Vue.prototype.$13 = 13
  92. Vue.prototype.$14 = 14
  93. Vue.prototype.$15 = 15
  94. Vue.prototype.$16 = 16
  95. Vue.prototype.$17 = 17
  96. Vue.prototype.$18 = 18
  97. Vue.prototype.$http = service;
  98. var CancelToken = axios.CancelToken;
  99. Vue.$httpRequestList = [];
  100. Vue.prototype.$axios = (type, url, data, heaStr) => {
  101. if (url != '/api/ding/login' && url != '/api/integral/types') {
  102. var Accept = '';
  103. switch (heaStr) {
  104. case 'v2':
  105. Accept = 'application/vnd.test.v2+json'
  106. break;
  107. case 'v3':
  108. Accept = 'application/vnd.test.v3+json'
  109. break;
  110. case 'v4':
  111. Accept = 'application/vnd.test.v4+json'
  112. break;
  113. }
  114. if (getToken()) {
  115. return new Promise((resolve, reject) => { //封装ajax
  116. var aa = {
  117. method: type,
  118. url: url,
  119. headers: {
  120. 'Accept': Accept
  121. },
  122. cancelToken: new CancelToken(c => { //强行中断请求要用到的
  123. Vue.$httpRequestList.push(c);
  124. })
  125. }
  126. var json = (type == 'get') ? Object.assign(aa, {
  127. params: data
  128. }) : Object.assign(aa, {
  129. data: data
  130. });
  131. var ajax = Vue.prototype.$http(json).then(res => {
  132. resolve(res);
  133. }).catch(error => { //中断请求和请求出错的处理
  134. if (error == "interrupt") {
  135. console.log('已中断请求');
  136. return;
  137. } else {
  138. reject(error);
  139. }
  140. })
  141. return ajax;
  142. })
  143. } else {
  144. return Promise.reject('无token')
  145. }
  146. } else {
  147. return new Promise((resolve, reject) => { //封装ajax
  148. var aa = {
  149. method: type,
  150. url: url,
  151. cancelToken: new CancelToken(c => { //强行中断请求要用到的
  152. Vue.$httpRequestList.push(c);
  153. })
  154. }
  155. var json = (type == 'get') ? Object.assign(aa, {
  156. params: data
  157. }) : Object.assign(aa, {
  158. data: data
  159. });
  160. var ajax = Vue.prototype.$http(json).then(res => {
  161. resolve(res);
  162. }).catch(error => { //中断请求和请求出错的处理
  163. if (error.message == "interrupt") {
  164. console.log('已中断请求');
  165. return;
  166. } else {
  167. reject(error);
  168. }
  169. })
  170. return ajax;
  171. })
  172. }
  173. };
  174. router.beforeEach((to, from, next) => { //路由切换检测是否强行中断,
  175. NProgress.start();
  176. if (Vue.$httpRequestList.length > 0) { //强行中断时才向下执行
  177. Vue.$httpRequestList.forEach(item => {
  178. item('interrupt'); //给个标志,中断请求
  179. })
  180. }
  181. // console.log(to.path)
  182. next();
  183. });
  184. router.afterEach(() => {
  185. NProgress.done();
  186. });
  187. Vue.config.productionTip = false
  188. new Vue({
  189. router,
  190. store,
  191. render: h => h(App)
  192. }).$mount('#app')