2018-03-23 10:21:49 +08:00
|
|
|
<template>
|
|
|
|
|
<Container type="card-full">
|
2018-03-23 10:34:52 +08:00
|
|
|
<template slot="header">
|
2018-03-26 20:09:30 +08:00
|
|
|
当前激活的单元格
|
2018-03-23 10:34:52 +08:00
|
|
|
</template>
|
2018-03-23 11:00:48 +08:00
|
|
|
<el-table v-bind="table">
|
2018-03-23 11:13:12 +08:00
|
|
|
<el-table-column prop="id" label="id" width="50" align="center"></el-table-column>
|
|
|
|
|
<el-table-column prop="name" label="姓名" width="100">
|
2018-03-23 11:00:48 +08:00
|
|
|
<template slot-scope="scope">
|
2018-03-28 15:38:22 +08:00
|
|
|
<el-input v-bind="inputSettingMaker(scope)"></el-input>
|
|
|
|
|
<!-- <button @click="log(scope)">测试</button> -->
|
2018-03-23 11:00:48 +08:00
|
|
|
</template>
|
|
|
|
|
</el-table-column>
|
2018-03-23 11:13:12 +08:00
|
|
|
<el-table-column prop="address1" label="出生地" align="center">
|
2018-03-23 11:00:48 +08:00
|
|
|
<template slot-scope="scope">
|
2018-03-28 15:38:22 +08:00
|
|
|
<el-input v-bind="inputSettingMaker(scope)"></el-input>
|
2018-03-23 11:00:48 +08:00
|
|
|
</template>
|
|
|
|
|
</el-table-column>
|
2018-03-23 11:13:12 +08:00
|
|
|
<el-table-column prop="address2" label="现居地" align="center">
|
2018-03-23 11:00:48 +08:00
|
|
|
<template slot-scope="scope">
|
2018-03-28 15:38:22 +08:00
|
|
|
<el-input v-bind="inputSettingMaker(scope)"></el-input>
|
|
|
|
|
</template>
|
|
|
|
|
</el-table-column>
|
|
|
|
|
<el-table-column label="操作" width="100" align="center">
|
|
|
|
|
<template slot-scope="scope">
|
2018-03-28 16:41:47 +08:00
|
|
|
<el-button v-bind="editButtonSettingMaker(scope)">编辑</el-button>
|
2018-03-23 11:00:48 +08:00
|
|
|
</template>
|
|
|
|
|
</el-table-column>
|
|
|
|
|
</el-table>
|
2018-03-23 10:21:49 +08:00
|
|
|
</Container>
|
|
|
|
|
</template>
|
2018-03-23 10:34:52 +08:00
|
|
|
|
|
|
|
|
<script>
|
2018-03-28 15:38:22 +08:00
|
|
|
// import sleep from '@/utils/sleep.js'
|
2018-03-23 10:34:52 +08:00
|
|
|
import Mock from 'mockjs'
|
|
|
|
|
export default {
|
|
|
|
|
data () {
|
|
|
|
|
return {
|
2018-03-24 22:02:23 +08:00
|
|
|
// 绑定到表格的数据
|
2018-03-23 10:34:52 +08:00
|
|
|
table: {
|
|
|
|
|
data: [],
|
|
|
|
|
size: 'mini',
|
|
|
|
|
stripe: true,
|
|
|
|
|
border: true
|
2018-03-28 17:06:06 +08:00
|
|
|
},
|
|
|
|
|
// 请求得到的原始数据
|
|
|
|
|
dataBackUp: {}
|
2018-03-23 10:34:52 +08:00
|
|
|
}
|
|
|
|
|
},
|
2018-03-26 21:16:34 +08:00
|
|
|
created () {
|
2018-03-23 11:13:12 +08:00
|
|
|
// 自动请求数据
|
|
|
|
|
this.getData()
|
|
|
|
|
},
|
2018-03-23 10:34:52 +08:00
|
|
|
methods: {
|
2018-03-23 11:17:13 +08:00
|
|
|
// 请求数据
|
|
|
|
|
async getData () {
|
2018-03-23 14:26:17 +08:00
|
|
|
this.table.data = this.dataFilter(await this.dataMaker())
|
2018-03-23 11:17:13 +08:00
|
|
|
},
|
2018-03-28 15:38:22 +08:00
|
|
|
// 过滤数据部分 模拟过滤掉 star 字段 并且添加 __edit 字段
|
2018-03-23 14:26:17 +08:00
|
|
|
dataFilter (val) {
|
|
|
|
|
const rowFilter = ({
|
|
|
|
|
id = '',
|
|
|
|
|
name = '',
|
|
|
|
|
address1 = '',
|
|
|
|
|
address2 = ''
|
2018-03-28 15:38:22 +08:00
|
|
|
}) => ({
|
|
|
|
|
id,
|
|
|
|
|
name,
|
|
|
|
|
address1,
|
|
|
|
|
address2,
|
2018-03-28 16:41:47 +08:00
|
|
|
__edit: false // 在这里可以添加额外的判断逻辑
|
2018-03-28 15:38:22 +08:00
|
|
|
})
|
2018-03-25 18:17:19 +08:00
|
|
|
return val.map(e => rowFilter(e))
|
2018-03-23 14:26:17 +08:00
|
|
|
},
|
|
|
|
|
// 模拟返回数据。没有必要写在全局 mock 设置中,就在这里这样写了,这样删文件的时候也好处理
|
2018-03-23 11:17:13 +08:00
|
|
|
dataMaker () {
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
resolve(Mock.mock({
|
|
|
|
|
'list|4-10': [{
|
|
|
|
|
'id|+1': 1,
|
|
|
|
|
'name': '@CNAME',
|
|
|
|
|
'address1': '@CITY',
|
2018-03-23 14:26:17 +08:00
|
|
|
'address2': '@CITY',
|
|
|
|
|
'star|1-5': '★'
|
2018-03-23 11:17:13 +08:00
|
|
|
}]
|
|
|
|
|
}).list)
|
|
|
|
|
})
|
2018-03-27 21:01:47 +08:00
|
|
|
},
|
2018-03-28 15:38:22 +08:00
|
|
|
// 返回输入组件需要的参数
|
|
|
|
|
inputSettingMaker (scope) {
|
|
|
|
|
return {
|
|
|
|
|
value: scope.row[scope.column.property],
|
|
|
|
|
placeholder: scope.column.label,
|
|
|
|
|
size: 'small',
|
|
|
|
|
style: {
|
|
|
|
|
maxWidth: '200px'
|
2018-03-27 21:01:47 +08:00
|
|
|
}
|
|
|
|
|
}
|
2018-03-28 15:38:22 +08:00
|
|
|
},
|
2018-03-28 16:41:47 +08:00
|
|
|
// 返回编辑按钮需要的参数
|
|
|
|
|
editButtonSettingMaker (scope) {
|
|
|
|
|
const isEdit = scope.row.__edit
|
|
|
|
|
return {
|
|
|
|
|
size: 'small'
|
|
|
|
|
}
|
|
|
|
|
},
|
2018-03-28 15:38:22 +08:00
|
|
|
// 测试
|
|
|
|
|
log (scope) {
|
|
|
|
|
console.log(scope)
|
2018-03-23 10:34:52 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</script>
|