base.js 4.02 KB
/*
 * @Description:
 * @Author: huyue
 * @Date: 2022-11-08 10:23:20
 * @LastEditors: huyue
 * @LastEditTime: 2022-11-09 16:42:11
 */
// 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 { utils } from 'glsx-common'
// 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)
    }
  }
}
Date.prototype.format = function (fmt) {
  let o = {
    "M+": this.getMonth() + 1, //月份
    "d+": this.getDate(), //日
    "h+": this.getHours(), //小时
    "m+": this.getMinutes(), //分
    "s+": this.getSeconds(), //秒
    //季度
    "q+": Math.floor((this.getMonth() + 3) / 3),
    "S": this.getMilliseconds() //毫秒
  }
  if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length))
  for (let k in o) {
    if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)))
  }
  return fmt
}
// const URL =
//   'https://oss-config.test.glsx.com.cn/mock/5be17454f31545347559d499/config'
// const getConfig = (url = URL + '/record-config') => {
//   return new Promise((resolve, reject) => {
//     request({ url }).then((res) => {
//       if (res.status === 'success') {
//         resolve({ vue: Vue, config: JSON.parse(res.data) })
//       } else {
//         reject('ERROR.')
//       }
//     })
//   })
// }
const getConfig = () => {
  let params = {
    moduleName: 'glsx-oss-record',
    mockUrl:
      'https://oss-config.test.glsx.com.cn/mock/5be17454f31545347559d499/config/record-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 }