base.js 3.26 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 GlsxVueComponents from 'glsx-vue-components'
import 'glsx-vue-components/dist/glsx-vue-components.css'
import './styles/index.scss'
// import zh_CN from 'vee-validate/dist/locale/zh_CN'
import VeeValidate from 'vee-validate'
import VueClipboard2 from 'vue-clipboard2'
import { utils } from 'glsx-common'
// const {
//   Validator
// } = VeeValidate
// import VueI18n from 'vue-i18n'
// Vue.use(VueI18n)
// const i18n = new VueI18n({
//   locale: 'zh_CN'
// })
Vue.use(VueClipboard2)
Vue.use(VeeValidate, {
  // i18n,
  // i18nRootKey: 'validation',
  dictionary: {
    en: {
      messages: {
        required: field => `${field}不能为空`,
        between: (field, data) => `${field}必须在${data[0]}~${data[1]}之间`,
        confirmed: (field, data) => `${field}必须与${data[0]}相匹配`,
        max: (field, data) => `${field}最大长度不能超过${data[0]}`,
        min: (field, data) => `${field}最小长度不能小于${data[0]}`,
        digits: (field, data) => `${field}必须为数字,且长度必须等于${data[0]}`,
        min_value: (field, data) => `${field}数值不能小于${data[0]}`,
        max_value: (field, data) => `${field}数值不能大于${data[0]}`,
        not_in: (field, data) => `${field}不能为${data.join(',')}`
      }
    }
  },
  errorBagName: 'errorBags',
  fieldsBagName: 'fieldBags',
  events: 'blur|input'
})

Vue.use(GlsxVueComponents)
import './date.js'
var mixin = {
  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 //
        }
      }
    })
    connection.promise.then(parent => {
      const cfg = _this.$get_session_config()
      if (cfg) return
      parent.getResources().then(config => {
        _this.$set_session_config(config)
      })
    })
  }
}
// const URL = 'https://oss-config.test.glsx.com.cn/mock/5be17454f31545347559d499/config'
// const getConfig = (url = URL + '/ai_manager_config') => {
//   return new Promise(resolve => {
//     const xhr = new XMLHttpRequest()
//     xhr.onreadystatechange = () => {
//       if (xhr.readyState === 4 && xhr.status === 200) {
//         resolve({
//           'vue': Vue,
//           'config': JSON.parse(xhr.responseText)
//         })
//       }
//     }
//     xhr.open('GET', url)
//     xhr.send()
//   })
// }
const getConfig = () => {
  let params = {
    moduleName: 'glsx-oss-ai',
    mockUrl:
      'https://oss-config.test.glsx.com.cn/mock/5be17454f31545347559d499/config/ai_manager_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 => {
  new Vue({
    el: '#app',
    mixins: [mixin],
    render: h => h(App)
  })
}

export default {
  render,
  getConfig
}