forked from sachatrauwaen/vuecrud
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfield.vue
119 lines (107 loc) · 2.88 KB
/
field.vue
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
<template>
<el-form-item :label="label" :prop="prop" :label-width="labelWidth">
<component v-bind:is="currentView" v-model="model" v-bind="$props" @propChange="propChange"></component>
</el-form-item>
</template>
<script>
import Vue from "vue";
import VueForms from "../vueforms";
export default {
name: "oa-field",
template: " ",
props: {
value: {},
schema: {},
prop: {
type:String,
default:function () {
return "";
}
},
messages: {
type:Object,
default: function (){
return {};
}
},
connector: {},
resource: {}
},
computed: {
currentView: function() {
var sch = VueForms.jsonSchema.getNotNull(this.schema);
var type = Array.isArray(sch.type)
? sch.type[0] == "null" ? sch.type[1] : sch.type[0]
: sch.type;
if (sch["x-type"]) {
type = sch["x-type"];
} else if (sch["x-rel-action"]) {
type = "relation";
} else if (sch["x-rel-to-many-action"]) {
type = "relation-to-many";
} else if (sch.enum || sch["x-enum-action"]) {
if (type == "array") {
type = "checkbox-group";
} else {
type = "select";
}
} else if (type == "boolean") {
type = "switch";
} else if (type == "integer" || type == "number") {
type = "inputnumber";
} else if (type == "array" && this.schema.items.format == "date-time") {
type = "daterange";
} else if (sch.format == "date-time") {
type = "datetime";
} else if (sch["x-ui-multiline"]) {
type = "textarea";
} else if (type == "address") {
type = "address";
} else if (type == "array") {
type = "list";
} else {
type = "input";
}
var compName = "oa-" + type;
var comp = Vue.component(compName);
//var comp = VueCrud.components[compName];
if (!comp) {
comp = function(resolve, reject) {
Vue.$loadComponent({
name: compName,
path: this.connector.componentsPath + type + ".js",
onLoad: resolve,
onError: reject
});
};
}
return comp;
},
model: {
get: function() {
return this.value;
},
set: function(val) {
this.$emit("input", val);
}
},
label: function() {
if (this.hideLabel) return "";
var name = this.schema.title ? this.schema.title : this.prop.capitalize();
if (this.messages && this.messages[name]) return this.messages[name];
else return this.schema.title ? this.schema.title : name;
},
hideLabel: function() {
return this.schema["x-ui-hideLabel"];
},
labelWidth: function() {
return this.hideLabel ? "0px" : "120px";
}
},
methods: {
propChange: function(key, value) {
this.$emit("propChange", key, value);
}
}
};
</script>