base.js
4.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
// 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 './styles/common.scss'
// import axios from 'axios'
import VeeValidate from 'vee-validate'
import './date.js'
import { utils } from 'glsx-common'
Vue.use(GlsxVueComponents)
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(',')}`,
is_phone: () => '请输入11位正确的手机号码'
}
}
},
errorBagName: 'errorBags',
fieldsBagName: 'fieldBags',
events: 'blur|input'
})
var mixin = {
data() {
return {
flag: true,
// paramsTrans: '',
/**
* 定义一个事件传输总线
* 提示:页面与子组件间的参数都可以用之来互相传递
* 如:
* this.$root.eventBus.$emit('params', {id:123});
*
this.$root.eventBus.$on('params', (params)=>{
console.log(params);
});
*/
eventBus: new Vue()
}
},
mounted() {
const _this = this
const theme = new this.$Theme()
this.$$connection = this.$Penpal.connectToParent({
methods: {
setTheme(color) {
theme.change(color)
},
height() {
return document.height || document.body.offsetHeight // document.documentElement.clientHeight || document.body.clientHeight //
},
/**
* 添加glsx-vue-admin 父框架传过来的参数 并广播这些参数
* @param {} params 接收到的参数 例如 列表页面 传到详情页面的ID
*/
translate(params) {
_this.eventBus.$emit('params', params)
}
}
})
this.$$connection.promise.then(parent => {
const cfg = _this.$get_session_config()
_this.$$parent = parent // 缓存parent 也就是glsx-vue-admin 为该页面创建的 iframe
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)
})
}
}
// getParamsTrans() {
// console.log(this.paramsTrans)
// return this.paramsTrans
// }
}
}
// const URL = 'https://oss-config.test.glsx.com.cn/mock/5be17454f31545347559d499/config'
// const getConfig = (url = URL + '/business_data_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-business-data',
mockUrl:
'https://oss-config.test.glsx.com.cn/mock/5be17454f31545347559d499/config/business_data_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 }