no message
Former-commit-id: dea7d02b32e7cf813a0535cf4d7697ee343efe8b Former-commit-id: 8741006345875b4d3283f7fe5ca1e0132ad6001e Former-commit-id: 3d6a851fae2e6b4294e523282c5b27bb339e4c78
This commit is contained in:
@@ -7,32 +7,23 @@
|
|||||||
<el-table-column prop="id" label="id" width="50" align="center"></el-table-column>
|
<el-table-column prop="id" label="id" width="50" align="center"></el-table-column>
|
||||||
<el-table-column prop="name" label="姓名" width="100">
|
<el-table-column prop="name" label="姓名" width="100">
|
||||||
<template slot-scope="scope">
|
<template slot-scope="scope">
|
||||||
<el-input
|
<el-input v-bind="inputSettingMaker(scope)"></el-input>
|
||||||
v-bind="inputSetting"
|
<!-- <button @click="log(scope)">测试</button> -->
|
||||||
placeholder="姓名"
|
|
||||||
:ref="refMaker(scope)"
|
|
||||||
@focus="handleFocus(scope)">
|
|
||||||
</el-input>
|
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
<el-table-column prop="address1" label="出生地" align="center">
|
<el-table-column prop="address1" label="出生地" align="center">
|
||||||
<template slot-scope="scope">
|
<template slot-scope="scope">
|
||||||
<el-input
|
<el-input v-bind="inputSettingMaker(scope)"></el-input>
|
||||||
v-bind="inputSetting"
|
|
||||||
placeholder="出生地"
|
|
||||||
:ref="refMaker(scope)"
|
|
||||||
@focus="handleFocus(scope)">
|
|
||||||
</el-input>
|
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
<el-table-column prop="address2" label="现居地" align="center">
|
<el-table-column prop="address2" label="现居地" align="center">
|
||||||
<template slot-scope="scope">
|
<template slot-scope="scope">
|
||||||
<el-input
|
<el-input v-bind="inputSettingMaker(scope)"></el-input>
|
||||||
v-bind="inputSetting"
|
</template>
|
||||||
placeholder="现居地"
|
</el-table-column>
|
||||||
:ref="refMaker(scope)"
|
<el-table-column label="操作" width="100" align="center">
|
||||||
@focus="handleFocus(scope)">
|
<template slot-scope="scope">
|
||||||
</el-input>
|
<el-button size="small">编辑</el-button>
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
</el-table>
|
</el-table>
|
||||||
@@ -40,7 +31,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import sleep from '@/utils/sleep.js'
|
// import sleep from '@/utils/sleep.js'
|
||||||
import Mock from 'mockjs'
|
import Mock from 'mockjs'
|
||||||
export default {
|
export default {
|
||||||
data () {
|
data () {
|
||||||
@@ -51,13 +42,6 @@ export default {
|
|||||||
size: 'mini',
|
size: 'mini',
|
||||||
stripe: true,
|
stripe: true,
|
||||||
border: true
|
border: true
|
||||||
},
|
|
||||||
// 表格中输入框的通用设置
|
|
||||||
inputSetting: {
|
|
||||||
size: 'small',
|
|
||||||
style: {
|
|
||||||
maxWidth: '200px'
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -65,22 +49,25 @@ export default {
|
|||||||
// 自动请求数据
|
// 自动请求数据
|
||||||
this.getData()
|
this.getData()
|
||||||
},
|
},
|
||||||
mounted () {
|
|
||||||
this.keyboardExtentInit()
|
|
||||||
},
|
|
||||||
methods: {
|
methods: {
|
||||||
// 请求数据
|
// 请求数据
|
||||||
async getData () {
|
async getData () {
|
||||||
this.table.data = this.dataFilter(await this.dataMaker())
|
this.table.data = this.dataFilter(await this.dataMaker())
|
||||||
},
|
},
|
||||||
// 过滤数据部分 模拟过滤掉 star 字段
|
// 过滤数据部分 模拟过滤掉 star 字段 并且添加 __edit 字段
|
||||||
dataFilter (val) {
|
dataFilter (val) {
|
||||||
const rowFilter = ({
|
const rowFilter = ({
|
||||||
id = '',
|
id = '',
|
||||||
name = '',
|
name = '',
|
||||||
address1 = '',
|
address1 = '',
|
||||||
address2 = ''
|
address2 = ''
|
||||||
}) => ({id, name, address1, address2})
|
}) => ({
|
||||||
|
id,
|
||||||
|
name,
|
||||||
|
address1,
|
||||||
|
address2,
|
||||||
|
__edit: true // 在这里可以添加额外的判断逻辑
|
||||||
|
})
|
||||||
return val.map(e => rowFilter(e))
|
return val.map(e => rowFilter(e))
|
||||||
},
|
},
|
||||||
// 模拟返回数据。没有必要写在全局 mock 设置中,就在这里这样写了,这样删文件的时候也好处理
|
// 模拟返回数据。没有必要写在全局 mock 设置中,就在这里这样写了,这样删文件的时候也好处理
|
||||||
@@ -97,27 +84,20 @@ export default {
|
|||||||
}).list)
|
}).list)
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
// 返回ref名称
|
// 返回输入组件需要的参数
|
||||||
refMaker (scope) {
|
inputSettingMaker (scope) {
|
||||||
return `kb-${scope.$index}-${scope.column.property}-kb`
|
return {
|
||||||
},
|
value: scope.row[scope.column.property],
|
||||||
// 接收用户在表格元素上的“focus”事件 (也可能是别的事件触发)
|
placeholder: scope.column.label,
|
||||||
handleFocus (scope) {
|
size: 'small',
|
||||||
console.log(scope)
|
style: {
|
||||||
},
|
maxWidth: '200px'
|
||||||
// 初始化键盘访问
|
|
||||||
async keyboardExtentInit () {
|
|
||||||
await sleep(1000)
|
|
||||||
for (const propName in this.$refs) {
|
|
||||||
if (/^kb-\d+-[a-zA-Z0-9-]+-kb$/.test(propName) && this.$refs.hasOwnProperty(propName)) {
|
|
||||||
const input = require('lodash.get')(this.$refs[propName], '$refs.input', false)
|
|
||||||
if (input) {
|
|
||||||
input.addEventListener('keydown', e => {
|
|
||||||
console.log(e)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
// 测试
|
||||||
|
log (scope) {
|
||||||
|
console.log(scope)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -43,14 +43,14 @@ export const menu = {
|
|||||||
icon: 'table',
|
icon: 'table',
|
||||||
children: [
|
children: [
|
||||||
{
|
{
|
||||||
title: '键盘访问',
|
title: '可编辑',
|
||||||
icon: 'file-o',
|
icon: 'file-o',
|
||||||
path: 'table/keyboard',
|
path: 'table/edit',
|
||||||
name: 'demo-business-table-keyboard',
|
name: 'demo-business-table-edit',
|
||||||
meta: {
|
meta: {
|
||||||
requiresAuth: true
|
requiresAuth: true
|
||||||
},
|
},
|
||||||
component: resolve => { require(['@/pages/demo/business/table/keyboard/inedx.vue'], resolve) }
|
component: resolve => { require(['@/pages/demo/business/table/edit/index.vue'], resolve) }
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user