base.js 3.24 KB
// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import ElementUI from 'element-ui'
import glsxTable from 'glsx-table'
import { Http, utils } from 'glsx-common'
import 'element-ui/lib/theme-chalk/index.css'
// import GlsxVueComponents from 'glsx-vue-components'
// import 'glsx-vue-components/dist/glsx-vue-components.css'
import { Request as request } from 'glsx-vue-common'
import notice from '@/common/notice'
import '@/styles/index.css'
// 组件
import '@/components'
import { Common } from '@/utils/common.js'
import Constants from '@/utils/constants.js'
// import axios from 'axios'
Vue.prototype.btn_size = 'mini'
Vue.prototype.$Common = Common
Vue.prototype.$Constants = Constants
Vue.prototype.notice = notice
Vue.use(ElementUI)
Vue.use(glsxTable)

var mixin = {
  data() {
    return {
      flag: true,
      eventBus: new Vue()
    }
  },
  mounted() {
    const _this = this
    const theme = new this.$Theme()
    const connection = this.$Penpal.connectToParent({
      methods: {
        setTheme(color) {
          theme.change(color)
        },
        height() {
          return document.height || document.body.offsetHeight // document.documentElement.clientHeight || document.body.clientHeight //
        },
        translate(params) {
          _this.eventBus.$emit('params', params)
        }
      }
    })
    connection.promise.then(parent => {
      const cfg = _this.$get_session_config()
      _this.$$parent = parent
      if (cfg) return
      parent.getResources().then(config => {
        _this.$set_session_config(config)
      })
    })
  },
  methods: {
    /**
     * 页面跳转方法 用法 :
     * this.$root.to(['MOCK系统A', '一键导航', '导航数据', 'MOCK数据B', 'localhost'],'1123')
     * 或:
     * this.$parent.to(['MOCK系统A', '一键导航', '导航数据', 'MOCK数据B', 'localhost'],'1123')
     *
     * @param {*} path  如:  ['一级菜单名称','二级菜单名称','三级菜单名称','四级菜单名称','五级菜单名称']
     * @param {*} params 传给下一个页面的参数
     */
    to(path, params) {
      if (this.$$parent) {
        this.$$parent.to(path, params)
      } else {
        this.$$connection.promise.then(parent => {
          parent.to(path, params)
        })
      }
    },
    close() {
      this.$$parent.close()
    }
  }
}

const getConfig = () => {
  // return new Promise((resolve, reject) => {
  //   request({ url }).then(res => {
  //     if (res.status === 'success') {
  //       resolve({ 'vue': Vue, 'config': JSON.parse(res.data) })
  //     } else {
  //       reject('ERROR.')
  //     }
  //   })
  // })
  let params = {
    moduleName: 'glsx-oss-configuration',
    mockUrl: 'http://192.168.3.171:7300/mock/5be17454f31545347559d499/config',
    httpOptions: {
      Headers: { refererurl: location.href },
      request: { timeout: 30000 }
    }
  }
  return new Promise((resolve, reject) => {
    utils.getConfig(params).then(res => {
      resolve({ vue: Vue, config: res })
    })
  })
}

/* eslint-disable no-new */
const render = App => {
  window.vm = new Vue({
    el: '#app',
    mixins: [mixin],
    render: h => h(App)
  })
}

export default { render, getConfig }