main.ts 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. import Vue from 'vue'
  2. import App from './App.vue'
  3. import './registerServiceWorker'
  4. import router from './router'
  5. import store from './store/index'
  6. import request from '@/benyun/utils/request'
  7. import {download} from '@/benyun/utils/request'
  8. import Cookies from 'js-cookie'
  9. import lodash from 'lodash'
  10. import plugins from '@/benyun/plugins'
  11. import directive from './directive' // directive
  12. import {getDicts} from "@/api/system/dict/data";
  13. import {getToken} from '@/benyun/utils/auth'
  14. import {getQueryObject} from '@/benyun/utils'
  15. import '@/assets/styles/index.scss' // global css
  16. import '@/assets/styles/benyuntech.scss' // young css
  17. import './assets/icons' // icon
  18. import './permission' // permission control
  19. // import './permission2'
  20. import Element from 'element-ui'
  21. import './assets/styles/element-variables.scss'
  22. import { Message,MessageBox } from 'element-ui';
  23. // import VXETable from 'vxe-table'
  24. import XEUtils from 'xe-utils'
  25. import 'vxe-table/lib/style.css'
  26. // import { VXETable, Column,Table,Modal,Button,Input,Validator,Filter } from 'vxe-table'
  27. import VXETable from 'vxe-table'
  28. import zhCN from 'vxe-table/lib/locale/lang/zh-CN'
  29. // 按需加载的方式默认是不带国际化的,自定义国际化需要自行解析占位符 '{0}',例如:
  30. VXETable.setup({
  31. i18n: (key, args) => XEUtils.toFormatString(XEUtils.get(zhCN, key), args)
  32. })
  33. import {addDateRange, handleTree, parseTime, resetForm, selectDictLabel, selectDictLabels, getQueryString} from "@/benyun/utils/benyuntech";
  34. import {getConfigKey} from "@/api/system/config";
  35. import gmComponent from './benyun/plugins/componentRegister'
  36. // 字典数据组件
  37. import DictData from '@/components/DictData'
  38. DictData.install()
  39. // 分页组件
  40. import Pagination from "@/components/Pagination/index.vue";
  41. // 自定义表格工具组件
  42. import RightToolbar from "@/components/RightToolbar/index.vue"
  43. // 字典标签组件
  44. import DictTag from '@/components/DictTag/index.vue'
  45. // 全局组件挂载
  46. Vue.component('DictTag', DictTag)
  47. Vue.component('Pagination', Pagination)
  48. Vue.component('RightToolbar', RightToolbar)
  49. //组件注册
  50. import productDialog from './components/productDialog/productDialog.vue'
  51. Vue.component('productDialog', productDialog);
  52. import productStore from './components/productStore/productStore.vue'
  53. Vue.component('productStore', productStore);
  54. import buyer from './components/buyer/buyer.vue'
  55. Vue.component('by-buyer', buyer);
  56. import productSkuModal from './components/skuModal/productModal.vue';
  57. Vue.component('product-sku-modal', productSkuModal);
  58. import supplierModal from './components/supplierModal/supplierModal.vue';
  59. Vue.component('supplier-modal', supplierModal);
  60. import warehouse from './components/warehouse/warehouse.vue';
  61. Vue.component('warehouse', warehouse);
  62. import warehousePosition from './components/warehousePosition/warehousePosition.vue';
  63. Vue.component('warehousePosition', warehousePosition);
  64. import byLog from './components/byLog/byLog.vue';
  65. Vue.component('byLog', byLog);
  66. import userModal from './components/userModal/userModal.vue';
  67. Vue.component('user-modal', userModal);
  68. Vue.use(Element, {
  69. size: Cookies.get('size') || 'medium' // set element-ui default size
  70. })
  71. Vue.use(VXETable)
  72. // Vue.use(Validator).use(Column).use(Table).use(Modal).use(Button).use(Input);
  73. Vue.use(gmComponent);
  74. Vue.use(plugins);
  75. Vue.use(directive);
  76. Vue.config.productionTip = false
  77. // 全局方法挂载
  78. Vue.prototype.getDicts = getDicts
  79. Vue.prototype.$request = request;
  80. Vue.prototype.$lodash = lodash;
  81. // Vue.prototype.$download = download; //下载
  82. Vue.prototype.$XModal = VXETable.modal
  83. // 全局方法挂载
  84. Vue.prototype.getDicts = getDicts
  85. Vue.prototype.getConfigKey = getConfigKey
  86. Vue.prototype.parseTime = parseTime
  87. Vue.prototype.resetForm = resetForm
  88. Vue.prototype.addDateRange = addDateRange
  89. Vue.prototype.selectDictLabel = selectDictLabel
  90. Vue.prototype.selectDictLabels = selectDictLabels
  91. Vue.prototype.download = download
  92. Vue.prototype.handleTree = handleTree
  93. function importJS() { // 引入 "天地图"
  94. return new Promise((resolve) => {
  95. const importHandle = (url:String) => {
  96. const head = document.getElementsByTagName('head')[0]
  97. const script:any = document.createElement('script')
  98. script.type = 'text/javascript'
  99. script.src = url
  100. script.onload = function() {
  101. resolve(true)
  102. }
  103. script.onerror = () => {
  104. resolve(false)
  105. }
  106. head.appendChild(script)
  107. }
  108. // importHandle('http://api.tianditu.gov.cn/api?v=4.0&tk=873e4a15f0f80945cd0ba56f069c19bc')
  109. importHandle('/static/js/xlsx.full.min.js')
  110. })
  111. }
  112. function omsLogin() {
  113. let params = getQueryObject();
  114. const ticket = params.ticket;
  115. const ssoToken = params.ssoToken;
  116. if(ticket || ssoToken){
  117. let data:any = {}
  118. const url = ticket ? '/sso/doLoginByTicket' : '/sso/doLoginByToken'
  119. if(ticket) {
  120. data.ticket = ticket
  121. }
  122. if(ssoToken) {
  123. data.token = ssoToken
  124. }
  125. store.dispatch('GetToken',{
  126. url,data
  127. }).then(() => {
  128. unitVue()
  129. }).catch((err:any) => {
  130. let msg = '未知错误,请联系管理员!'
  131. if(err && err.msg) {
  132. msg = err.msg
  133. }
  134. MessageBox.alert(msg, '提示', {
  135. confirmButtonText: '确定',
  136. callback: () => {
  137. store.dispatch('LogOut').then(() => {})
  138. }
  139. });
  140. })
  141. }else if(getToken()){
  142. unitVue()
  143. }else{
  144. const redirect = location.origin;
  145. location.href = `${process.env.VUE_APP_LOGIN_URL}?&redirect=${encodeURIComponent(redirect)}`
  146. }
  147. }
  148. function unitVue() {
  149. Promise.all([importJS()]).then(result => {
  150. new Vue({
  151. router,
  152. store,
  153. render: h => h(App),
  154. data: {
  155. eventHub: new Vue()
  156. }
  157. }).$mount('#app')
  158. })
  159. }
  160. // unitVue()
  161. omsLogin()