import './by-table.scss' export default { data() { return { } }, props: { //数据源 data: { type: Array, default: () => [] }, // table配置信息 columns: { type: Array, default: () => [] }, // 每页条数 pageSize: { type: Number, default: 10 }, // 总条数 total: { type: Number, default: 0 }, // 当前页码 pageNum: { type: Number, default: 1 }, //搜索配置 selectConfig: { type: Array, default: () => [] }, //请求参数 req: { type: Object, default: () => { return { pageNum: 1, pageSize: 10, total:0, } } } }, methods: { //操作按钮 renderActionColumn(h, actions) { return { //循环按钮,触发配置方法 return actions.actions.map(item => { return item.fn ? item.fn(row) : console.log('请配置fn方法') } style={actions.style || 'color:#0084FF'}> {item.text} }) } } }} > }, //拼接table renderTable(h) { return ( { this.columns.map(item => { if (item.actions) { console.log(item.actions) return this.renderActionColumn(h, item) } else if (item.render) { return { return item.render(h,row) } }, }} > } else { return { return item.fn ? item.fn(row) : console.log('请配置fn方法') }> {row[item.prop]} } }, }} > } }) } ) }, //render分页 renderPage(h) { return 0} total={this.total} page={this.pageNum} limit={this.pageSize} /> }, renderDropDown(h,item) { const v = this return {item.label} { v.req[item.prop] = null item.label = item.labelCopy.label //item.label = item.labelCopy }}>全部 { item.data.map(i => { return { v.req[item.prop] = i.value item.label = i.label } }>{i.label} }) } }, //render搜索 renderSearch(h) { if(!this.selectConfig) return return { this.selectConfig.map( item => { return this.renderDropDown(h,item) }) } 更多 this.req.keyword = $event}> }, renderSearchInit(){ this.selectConfig.map(item => { item.labelCopy = JSON.parse(JSON.stringify(item)) console.log(item.labelCopy) }) }, }, created(){ this.renderSearchInit() }, name: 'by-table', render(h) { const search = this.renderSearch(h) const table = this.renderTable(h) const page = this.renderPage(h) return {search} {table} {page} }, }