Skip to content

Commit 9cd20cb

Browse files
committed
fixed m-table中编辑因为值是空而没有设置initValue的bug
add 框架国际化为中文
1 parent 49f04e6 commit 9cd20cb

File tree

4 files changed

+58
-24
lines changed

4 files changed

+58
-24
lines changed

src/App.vue

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,26 @@
11
<template>
2-
<div id="app">
3-
<!-- <img src="./assets/logo.png"> -->
4-
<router-view/>
5-
</div>
2+
<a-locale-provider :locale="locale">
3+
<div id="app">
4+
<!-- <img src="./assets/logo.png"> -->
5+
<router-view/>
6+
</div>
7+
</a-locale-provider>
68
</template>
79

810
<script>
9-
export default {
10-
name: 'App'
11-
}
11+
import {LocaleProvider} from 'ant-design-vue'
12+
import zhCN from 'ant-design-vue/lib/locale-provider/zh_CN';
13+
export default {
14+
name: 'App',
15+
components: {
16+
ALocaleProvider: LocaleProvider
17+
},
18+
data() {
19+
return {
20+
locale: zhCN,
21+
}
22+
}
23+
}
1224
</script>
1325

1426
<style>

src/components/m-table/m-edit/m-edit.vue

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
:width="options.width ? options.width : 720"
66
@close="onClose"
77
:visible="visible"
8+
destroyOnClose
89
wrapClassName="sys-menu-create-wrap">
910
<!-- <m-form :options="options.form" @submit="handleSubmit"></m-form>-->
1011
<a-form :form="form" @submit="handleSubmit">
@@ -44,10 +45,11 @@
4445
// 在这里将record中的值合并到form中去
4546
let res = [];
4647
for(let i=0; i<this.options.form.children.length; i++) {
47-
let item = this.options.form.children[i];
48-
let value = this.record[item.id];
48+
let item = this.options.form.children[i]; // 从options的列表中获取当前操作的item
49+
let value = this.record[item.id]; // 从record中获取当前item id的值
4950
// console.log('找到',item.id, '值为',value)
50-
if(value) {
51+
// 这里不应当有非空判断,因为在value值为空的时候也不应该是上一次的值
52+
// if(value) {
5153
let tempDecorator = item.attribute.decorator;
5254
if(item.attribute.initialValueRender){
5355
// 如果存在初始化render,则按照render中的进行
@@ -57,7 +59,7 @@
5759
tempDecorator.initialValue = value;
5860
}
5961
item.attribute.decorator = tempDecorator;
60-
}
62+
// }
6163
res.push(item)
6264
}
6365
// console.log('通过editItem对decorator设置initVal', res)
@@ -100,7 +102,7 @@
100102
message: '更新成功'
101103
})
102104
// 置空表单,向父组件提交动作,更新表格
103-
// this.form.resetFields(); --- 编辑不用置空
105+
// this.form.resetFields();
104106
this.$emit('close', 'updated');
105107
}
106108
}).catch(err => {
@@ -111,6 +113,8 @@
111113
});
112114
},
113115
onClose() {
116+
// this.form.resetFields();
117+
// console.log('on edit close')
114118
this.$emit('close');
115119
},
116120
handleSubmitEvent (value) {

src/components/m-table/m-table.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,6 @@
180180
renderOptions (text, record, index) {
181181
// 通过text和record查出当前渲染的是哪一列
182182
let key = this.getKeyInRecord(text, record)
183-
// console.log(key)
184183
if(!key) return [];
185184
186185
// 通过key值去columns里边找到对应的render方法
@@ -189,13 +188,15 @@
189188
return res ? res : [];
190189
},
191190
getKeyInRecord (text, record) {
191+
// console.log('getKeyInRecord里text和record', text, typeof(text), record)
192192
for(let key in record) {
193193
if(typeof(text) === 'object') {
194194
if(JSON.stringify(text) == JSON.stringify(record[key])) {
195195
return key;
196196
}
197197
}else{
198198
if(text === record[key]){
199+
// console.log(key)
199200
return key;
200201
}
201202
}

src/pages/view-template/test-data/query-table布局.js

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,11 @@ export default [
106106
type: 'Table',
107107
// 每行数据的key值,由函数渲染,组件内部会执行eval,所以请书写正确可执行的函数
108108
rowKeys: 'record => record.record_id',
109-
// pagination: {}, //可以不用传或者false
109+
//可以不用传或者false
110+
pagination: {
111+
showSizeChanger : true,
112+
showQuickJumper: true
113+
},
110114
attribute: {
111115
bordered: true,
112116
size : 'small',
@@ -241,6 +245,19 @@ export default [
241245
}`
242246
}
243247
},
248+
{
249+
"title": "邮箱",
250+
"dataIndex": "email",
251+
"align": "roles",
252+
"width": "200px",
253+
"scopedSlots": {
254+
"customRender": "template",
255+
"render": `(text, record, index) => {
256+
// console.log('配置文件中的render方法', text, typeof(text), record)
257+
return [{id:'tag'+index,type:'tag',text: text ? text : 2,attribute:{color: 'geekblue'}}];
258+
}`
259+
}
260+
},
244261
// {
245262
// title: '邮箱',
246263
// dataIndex: 'email',
@@ -253,16 +270,16 @@ export default [
253270
// align: 'center',
254271
// width: '200px',
255272
// },
256-
{
257-
title: '创建时间',
258-
dataIndex: 'created_at',
259-
align: 'center',
260-
width: '220px',
261-
customRender: `(text, record, index)=>{
262-
return text.split('T')[0]+ ' ' + text.split('T')[1].split('+')[0];
263-
}`
264-
// scopedSlots: {customRender: 'created'},
265-
},
273+
// {
274+
// title: '创建时间',
275+
// dataIndex: 'created_at',
276+
// align: 'center',
277+
// width: '220px',
278+
// customRender: `(text, record, index)=>{
279+
// return text.split('T')[0]+ ' ' + text.split('T')[1].split('+')[0];
280+
// }`
281+
// // scopedSlots: {customRender: 'created'},
282+
// },
266283
{
267284
title: '操作',
268285
dataIndex: 'record_id',

0 commit comments

Comments
 (0)