Skip to content

Commit f2d3035

Browse files
committed
chore: backup
1 parent e16399c commit f2d3035

File tree

3 files changed

+215
-0
lines changed

3 files changed

+215
-0
lines changed

hello-bike.gif

1.18 MB
Loading

packages/antd/public/favicon.svg

+43
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
<template>
2+
<el-form
3+
ref="formRef"
4+
:model="formModel"
5+
>
6+
<el-table :data="formModel.tableData">
7+
<template v-for="(col, idx) of columns">
8+
<el-table-column
9+
v-if="col.input"
10+
:key="idx + 'input'"
11+
:label="col.label"
12+
:prop="col.prop"
13+
:width="col.width"
14+
>
15+
<template slot-scope="scope">
16+
<el-form-item
17+
:rules="col.input.rules"
18+
:prop="`tableData.${scope.$index}.${col.prop}`"
19+
>
20+
<el-input
21+
v-model="scope.row[col.prop]"
22+
:placeholder="col.input.placeholder || '请输入'"
23+
/>
24+
</el-form-item>
25+
</template>
26+
</el-table-column>
27+
<el-table-column
28+
v-else-if="col.select"
29+
:key="idx + 'select'"
30+
:label="col.label"
31+
:prop="col.prop"
32+
:width="col.width"
33+
>
34+
<template slot-scope="scope">
35+
<el-form-item
36+
:rules="col.select.rules"
37+
:prop="`tableData.${scope.$index}.${col.prop}`"
38+
>
39+
<el-select
40+
v-model="scope.row[col.prop]"
41+
filterable
42+
:placeholder="col.select.placeholder || '请选择'"
43+
@change="onEvent({ name: 'select', action: 'change', $event, scope, column: col })"
44+
@focus="onEvent({ name: 'select', action: 'focus', $event, scope, column: col })"
45+
@blur="onEvent({ name: 'select', action: 'blur', $event, scope, column: col })"
46+
>
47+
<el-option
48+
v-for="(opt, optIdx) of optionsCallable(col.select.options, scope)"
49+
:key="optIdx"
50+
:label="opt.label"
51+
:value="opt.value"
52+
/>
53+
</el-select>
54+
</el-form-item>
55+
</template>
56+
</el-table-column>
57+
<el-table-column
58+
v-else-if="col.render"
59+
:key="idx + 'render'"
60+
:label="col.label"
61+
:prop="col.prop"
62+
:width="col.width"
63+
>
64+
<template slot-scope="scope">
65+
<render-cell
66+
:props="col"
67+
:scope="scope"
68+
/>
69+
</template>
70+
</el-table-column>
71+
<el-table-column
72+
v-else
73+
:key="idx + 'column'"
74+
:label="col.label"
75+
:prop="col.prop"
76+
:width="col.width"
77+
/>
78+
</template>
79+
</el-table>
80+
</el-form>
81+
</template>
82+
83+
<script>
84+
/**
85+
* TODO 功能完善 211129
86+
*/
87+
export default {
88+
name: 'EnhanceTableWithFormVue',
89+
components: {
90+
RenderCell: {
91+
props: {
92+
props: Object,
93+
scope: Object,
94+
},
95+
render() {
96+
return this.$props.props.render(this.$props.scope)
97+
},
98+
},
99+
},
100+
props: {
101+
columns: {
102+
type: Array,
103+
default: () => [],
104+
},
105+
data: {
106+
type: Array,
107+
default: () => [],
108+
},
109+
pagination: {
110+
type: [Boolean, Object],
111+
default: () => ({}),
112+
},
113+
query: {
114+
type: Object,
115+
default: () => ({}),
116+
},
117+
handle: {
118+
type: Object,
119+
default: () => ({}),
120+
},
121+
},
122+
data() {
123+
return {
124+
formModel: {
125+
tableData: this.$props.data,
126+
},
127+
}
128+
},
129+
watch: {
130+
data(val) {
131+
this.formModel.tableData = val
132+
},
133+
},
134+
mounted() {
135+
Object.assign(this.$props.handle, {
136+
// TODO
137+
refresh() {},
138+
// TODO
139+
pagination: {},
140+
form: this.$refs.formRef,
141+
})
142+
},
143+
methods: {
144+
optionsCallable(arg0, scope) {
145+
return typeof arg0 === 'function' ? arg0(this.argsify(scope)) : arg0
146+
},
147+
argsify(scope) {
148+
return {
149+
$index: scope.$index,
150+
column: { ...scope.column, prop: scope.column.property },
151+
row: this.formModel.tableData[scope.$index],
152+
}
153+
},
154+
onEvent({
155+
name,
156+
$event,
157+
action,
158+
scope,
159+
column,
160+
}) {
161+
const args = { $event, ...this.argsify(scope) }
162+
if (action === 'blur') {
163+
if (column[name].onBlur) { column[name].onBlur(args) }
164+
} else if (action === 'focus') {
165+
if (column[name].onFocus) { column[name].onFocus(args) }
166+
} else if (action === 'change') {
167+
if (column[name].onChange) { column[name].onChange(args) }
168+
}
169+
},
170+
},
171+
}
172+
</script>

0 commit comments

Comments
 (0)