base.js 2.76 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 '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 '@/styles/index.css'
// 组件
import '@/components'
import { Util } from './common/util'
// import _ from 'lodash'
// import axios from 'axios'
Vue.prototype.btn_size = 'mini'
Vue.prototype.$Utils = Util
Vue.use(ElementUI)

var mixin = {
  data() {
    return {
      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) {
      console.log(path, params, '000')
      if (this.$$parent) {
        this.$$parent.to(path, params)
      } else {
        this.$$connection.promise.then((parent) => {
          parent.to(path, params)
        })
      }
    },
    close(title) {
      this.$$parent.close(title)
    },
  },
}
const URL =
  'https://config-center-backend.glsx.com.cn/glsxAdmin/config?moduleUrl=glsx-oss-task'
const getConfig = (url = URL) => {
  return new Promise((resolve, reject) => {
    request({ url }).then((res) => {
      if (res.status === 'success') {
        resolve({ vue: Vue, config: JSON.parse(res.data) })
      } else {
        reject('ERROR.')
      }
    })
  })
}
/* eslint-disable no-new */
const render = (App) => {
  window.vm = new Vue({
    el: '#app',
    mixins: [mixin],
    render: (h) => h(App),
  })
}

export default { render, getConfig }