mixin.js
1.13 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
import { isNumberStr } from '@/components/Generator/utils'
export default {
data() {
return {}
},
methods: {
onDefaultValueInput(str) {
if (Array.isArray(this.activeData.__config__.defaultValue)) {
// 数组
this.$set(
this.activeData.__config__,
'defaultValue',
str.split(',').map(val => (isNumberStr(val) ? +val : val))
)
} else if (['true', 'false'].indexOf(str) > -1) {
// 布尔
this.$set(this.activeData.__config__, 'defaultValue', JSON.parse(str))
} else {
// 字符串和数字
this.$set(
this.activeData.__config__,
'defaultValue',
isNumberStr(str) ? +str : str
)
}
},
setDefaultValue(val) {
if (Array.isArray(val)) {
return val.join(',')
}
// if (['string', 'number'].indexOf(typeof val) > -1) {
// return val
// }
if (typeof val === 'boolean') {
return `${val}`
}
return val
},
addReg() {
this.activeData.__config__.regList.push({
pattern: '',
message: ''
})
}
}
}