<template>
|
<el-card shadow="never">
|
<!--工具条-->
|
<div class="table-tool-bar">
|
<!--自定义工具-->
|
<my-button
|
v-for="(custom,idx) in myTable.tools.custom"
|
:key="idx"
|
:check-permission="custom.checkPermission"
|
:name="custom.name"
|
site="tools"
|
@click="custom.click"
|
/>
|
<!--列控制-->
|
<el-popover
|
placement="bottom"
|
style="float: right;"
|
trigger="click"
|
width="150"
|
>
|
<el-form label-width="10px" style="max-height: 500px;overflow-y: auto;">
|
<el-form-item label="">
|
<el-checkbox-group v-model="checkColumns" @change="changeColumns">
|
<el-checkbox v-for="(column,index) in myTable.columns" :key="index" :label="index">{{ column.title }}
|
</el-checkbox>
|
</el-checkbox-group>
|
</el-form-item>
|
</el-form>
|
<el-button slot="reference" icon="el-icon-setting" size="mini">设置列</el-button>
|
</el-popover>
|
</div>
|
<!--table列表-->
|
<el-table
|
ref="myTable"
|
v-loading="myTable.loading"
|
:data="myTable.data"
|
row-key="id"
|
:default-expand-all="myTable.expandAll"
|
:tree-props="{children: 'children'}"
|
:fit="false"
|
:highlight-current-row="true"
|
border
|
size="medium"
|
>
|
<!--列内容-->
|
<el-table-column
|
v-for="(column, index) in myTable.columns"
|
v-if="!column.hidden"
|
:key="index"
|
:align="column.align"
|
:header-align="column.align"
|
:label="column.title"
|
:min-width="column.width"
|
:sortable="column.sortable"
|
:type="column.type"
|
:width="column.width"
|
>
|
<template slot-scope="scope">
|
<!--图片展示-->
|
<template v-if="column.img">
|
<preview-picture img-style="width:40px;height:40px;" :imgs="column.img(scope.row).imgs" />
|
</template>
|
<!--开关(生成开关按钮)-->
|
<template v-else-if="column.switch">
|
<my-switch
|
:check-permission="column.checkPermission"
|
:disabled="column.switch(scope.row).disabled"
|
:value="column.switch(scope.row).value"
|
@click="switchClick(column.switch(scope.row).click)"
|
/>
|
</template>
|
<!--格式化(显示颜色,内容,点击事件控制)-->
|
<template v-else-if="column.formatter">
|
<span
|
slot="reference"
|
:style="setStyle(column.formatter(scope.row))"
|
class="content-text"
|
@click="handleClick(column.formatter(scope.row))"
|
>{{ column.formatter(scope.row).value }}</span>
|
</template>
|
<template v-else>
|
<!--点击弹出单元格内容-->
|
<el-popover
|
:content="getPopoverContent(scope.row,column)"
|
placement="top-start"
|
trigger="click"
|
>
|
<span slot="reference" class="content-text">{{ scope.row[column.field] }}</span>
|
</el-popover>
|
</template>
|
</template>
|
</el-table-column>
|
|
<!--操作列-->
|
<el-table-column
|
v-if="myTable.operation.show"
|
:width="myTable.operation.width"
|
align="center"
|
label="操作"
|
>
|
<template slot-scope="scope">
|
<template v-for="(operation, index) in myTable.operation.attr">
|
<my-button-v2
|
v-if="!(operation.hidden && operation.hidden(scope.row))"
|
:key="index"
|
:check-permission="operation.checkPermission"
|
:name="operation.title"
|
:type="operation.type"
|
site="operation"
|
@click="operation.events(scope.row)"
|
/>
|
</template>
|
<template v-if="myTable.operation.more && myTable.operation.more.length>0">
|
<a-dropdown :trigger="['click']" style="margin-left: 5px;">
|
<a-button size="small">
|
更多
|
<a-icon type="down" />
|
</a-button>
|
<a-menu slot="overlay">
|
<template v-for="(m,i) in myTable.operation.more">
|
<a-menu-item :key="i" @click="m.events(scope.row)">
|
<my-button-v2
|
v-if="!(m.hidden && m.hidden(scope.row))"
|
:check-permission="m.checkPermission"
|
:name="m.title"
|
/>
|
</a-menu-item>
|
</template>
|
</a-menu>
|
</a-dropdown>
|
</template>
|
</template>
|
</el-table-column>
|
</el-table>
|
</el-card>
|
</template>
|
|
<script>
|
import myButton from '@/views/components/myButton'
|
import myButtonV2 from '@/views/components/myButtonV2'
|
import mySwitch from '@/views/components/mySwitch'
|
import request from '@/utils/request'
|
import previewPicture from '@/views/components/previewPicture'
|
|
export default {
|
components: { myButton, mySwitch, previewPicture, myButtonV2 },
|
props: {
|
table: {
|
type: Object,
|
default() {
|
return null
|
}
|
},
|
filter: {
|
type: Object,
|
default() {
|
return null
|
}
|
}
|
},
|
data() {
|
return {
|
/** table列表数据*/
|
myTable: {
|
url: '',
|
params: {},
|
expandAll: true, // 展开
|
loading: false, // 加载效果
|
size: 'small', // Table 的尺寸 medium / small / mini
|
// 工具条
|
tools: {
|
custom: [] // 自定义工具条按钮
|
},
|
columns: [], // 列属性配置
|
operation: { // 操作列
|
show: false, // 显示操作列
|
width: '250', // 宽度
|
attr: [], // 操作
|
more: []// 更多
|
},
|
data: [], // 列表数据
|
paging: {
|
show: true, // 显示分页
|
// 分页信息
|
page: {
|
small: false,
|
pageNumber: 1,
|
pageSize: 10,
|
total: 0
|
}
|
}
|
},
|
checkColumns: [] // 记录列控制中选中的列
|
}
|
},
|
watch: {
|
filter: {
|
handler() {
|
this.search()
|
},
|
deep: true
|
}
|
},
|
created() {
|
if (this.table != null) {
|
Object.assign(this.myTable, this.table)
|
this.myTable.columns.forEach((column, idx) => {
|
if (!column.hidden) {
|
this.checkColumns.push(idx)
|
}
|
})
|
}
|
},
|
methods: {
|
// 搜索
|
search() {
|
this.myTable.loading = true
|
const params = Object.assign({}, this.filter)
|
request({
|
url: this.myTable.url,
|
method: 'get',
|
params: params
|
}).then(res => {
|
this.$set(this.myTable, 'data', res.data)
|
this.myTable.loading = false
|
})
|
},
|
// 获取设置列表弹层内容
|
getPopoverContent(row, column) {
|
if (column.formatterHigh) {
|
return column.formatterHigh(row).value + ''
|
} else if (column.formatter) {
|
return column.formatter(row) + ''
|
} else {
|
return row[column.field] + ''
|
}
|
},
|
// 单元格内容格式化样式
|
setStyle(format) {
|
let styles = ''
|
if (format.click != undefined) {
|
styles += 'cursor: pointer;'
|
}
|
if (format.type != undefined) {
|
if (format.type == 'primary') {
|
styles += 'color:#409EFF;'
|
} else if (format.type == 'danger') {
|
styles += 'color:#F56C6C;'
|
} else if (format.type == 'success') {
|
styles += 'color:#67C23A;'
|
} else if (format.type == 'warning') {
|
styles += 'color:#E6A23C;'
|
} else if (format.type == 'info') {
|
styles += 'color:#909399;'
|
}
|
}
|
return styles
|
},
|
// formatter 点击事件
|
handleClick(format) {
|
if (format.click != undefined) {
|
format.click()
|
}
|
},
|
// 开关点击事件
|
switchClick(click) {
|
if (typeof click === 'function') {
|
click()
|
}
|
},
|
// 列控制
|
changeColumns() {
|
this.myTable.columns.forEach((column, idx) => {
|
if (this.checkColumns.includes(idx)) {
|
column.hidden = false
|
} else {
|
column.hidden = true
|
}
|
this.$set(this.myTable.columns, idx, column)
|
})
|
}
|
}
|
}
|
</script>
|
|
<style scoped>
|
/*详情表单*/
|
.demo-table-expand .el-form-item{
|
width: 100%;
|
}
|
|
/*列表内文字过长加省略*/
|
.content-text{
|
overflow:hidden;
|
text-overflow:ellipsis;
|
white-space:nowrap
|
}
|
|
/*分页上边距*/
|
.el-pagination {
|
white-space: nowrap;
|
padding: 2px 5px;
|
color: #303133;
|
font-weight: 700;
|
margin-top: 10px;
|
}
|
.el-radio {
|
margin-right: 10px;
|
}
|
.el-radio__label {
|
font-size: 14px;
|
padding-left: 2px !important;
|
}
|
|
.a-button-cus{
|
font-size: 12px;
|
}
|
.ant-btn-sm {
|
padding: 0px 7px;
|
font-size: 12px;
|
border-radius: 3px;
|
height: 20px;
|
}
|
.ant-btn > .anticon + span, .ant-btn > span + .anticon {
|
margin-left: unset;
|
}
|
|
</style>
|