qiankun.js 2.64 KB
import Vue from 'vue'
import { message, messageBox } from '@/plugins/element.js'
import { fetchConfig } from '@/config'
import { GLButton, GLTable , GLCombiForm, GLTableButton,GLDialog} from 'glsx-components' //权限按钮 (根据权限动态创建)
import { getRoutes } from '@/router'
import render from './render'
import 'glsx-components/dist/glsx-components.css'
// import 'glsx-components/src/theme/theme.scss'
let routes = []
let router = null
let instance = null
Vue.use(GLTable).use(GLCombiForm).use(GLTableButton).use(GLDialog)
export async function bootstrap({ history, common, messenger, globalState, routerBase }) {
  const { response, request, other_request, sign, secret } = await fetchConfig()
  // request.baseURL = 'https://scrm.dev.glsx.com.cn'
  // request_brand.baseURL = 'https://scrm.dev.glsx.com.cn'
  // request.baseURL = 'http://192.168.1.53:7226'
  // request_brand.baseURL = 'http://192.168.1.53:7226'
  Vue.prototype.$history = history
  Vue.prototype.$messenger = messenger
  Vue.prototype.$globalState = globalState
  Vue.prototype.$common = common
  Vue.prototype.$message = message
  Vue.prototype.$messageBox = messageBox
  // // Vue.prototype.$defaultStartDate = '2021-07-01'
  Vue.prototype.$http = new common.Http({ response, request, sign, secret, alert: message.error, headers: { token: globalState.session.token } })
  Vue.prototype.$other_http = new common.Http({ response, request: other_request, sign, secret, alert: message.error, headers: { token: globalState.session.token } })
  // Vue.prototype.$http = new common.Http({ response, request, sign, secret, alert: message.error, headers: { token: 'scrm-base-811305a2-49a3-4e8a-b6dc-fb925c65c95c-rop' } })
  // Vue.prototype.$http_brand = new common.Http({ response, request: request_brand, sign, secret, alert: message.error, headers: { token: 'scrm-base-811305a2-49a3-4e8a-b6dc-fb925c65c95c-rop' } })
  // Vue.prototype.$http = new common.Http({ response, request, sign, secret, alert: message.error, headers: { token: '781f08c5-c443-46fd-80e1-f98d94673a73' } })
  // Vue.prototype.$setGlobalState = globalState.actions.setGlobalState
  const routesData = common.utils.deepClone(globalState.routers)
  routes = getRoutes(routesData)
  subscribe({ messenger })
  Vue.use(GLButton, { routes, routerBase })
}
export async function mount({ routerBase }) {
  const insts = render(routerBase, routes)
  router = insts.router
  instance = insts.vm
}

export async function unmount() {
  instance.$destroy()
  instance.$el.innerHTML = ''
  instance = null
  router = null
}

function subscribe({ messenger }) {
  messenger.subscribe(v => {
    // console.log(`监听到子应用${v.from}发来消息:`, v)
  })
}