main.ts 5.6 KB

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