ahdevicemgt-ui/src/components/TableModel/index.vue

238 lines
7.0 KiB
Vue
Raw Normal View History

2024-08-07 09:53:21 +08:00
<template>
<!-- 表格公共组件 -->
<div>
<!-- 表单搜索 -->
<el-form
:model="queryParams"
ref="queryFormRef"
size="small"
:inline="true"
label-width="100px"
v-show="showSearch"
>
<el-form-item
v-for="(item, v) in formLabel"
:key="v"
:label="item.f_label"
:prop="item.f_model"
>
<el-input
v-if="item.f_type === 'ipt'"
v-model="queryParams[item.f_model]"
:placeholder="`请输入${item.f_label}`"
clearable
style="width: 240px"
/>
<el-select
v-if="item.f_type === 'sel'"
v-model="queryParams[item.f_model]"
clearable
filterable
style="width: 240px"
:placeholder="`请选择${item.f_label}`"
>
<el-option
v-for="(sel, v) in item.f_selList"
:key="v"
:label="sel.label"
:value="sel.value"
/>
</el-select>
<el-cascader
v-if="item.f_type === 'selCas'"
v-model="queryParams[item.f_model]"
:options="item.f_selList"
:props="item.optionProps"
:show-all-levels="false"
clearable
style="width: 240px"
/>
<el-date-picker
v-if="item.f_type === 'date'"
v-model="queryParams[item.f_model]"
style="width: 240px"
value-format="yyyy-MM-dd"
type="daterange"
range-separator="-"
start-placeholder="开始日期"
end-placeholder="结束日期"
/>
</el-form-item>
<el-form-item>
<el-button
type="primary"
icon="el-icon-search"
size="mini"
@click="handleQuery"
>查询</el-button
>
<el-button
type="warning"
icon="el-icon-refresh"
size="mini"
@click="resetQuery"
>重置</el-button
>
</el-form-item>
</el-form>
<!-- 按钮集群 -->
<el-row class="btn-container">
<div class="btn-handler">
<slot name="btn" :pageParams="queryParams"></slot>
</div>
<ToolbarModel
2024-08-07 09:53:21 +08:00
:showSearch.sync="showSearch"
:indexNumShow.sync="indexNumShow"
:selectionShow.sync="selectionShow"
:handleShow.sync="handleShow"
:columns="columCheckList"
2024-08-07 09:53:21 +08:00
@queryTable="getTableList"
/>
</el-row>
<!-- 表格 -->
<el-table
:data="tableList"
border
ref="tableRef"
select-on-indeterminate
2024-08-07 09:53:21 +08:00
>
<el-table-column
type="selection"
width="45"
align="center"
v-if="selectionShow"
/>
<el-table-column
width="55"
align="center"
label="序号"
type="index"
v-if="indexNumShow"
/>
<el-table-column
v-for="(item, v) in tableColumCheckProps"
:key="v"
:label="item.t_label"
:prop="item.t_props"
:width="item.t_width"
align="center"
show-overflow-tooltip
>
<template slot-scope="scope">
<!-- 判断当前列数据是否需要使用插槽的数据 -->
<template v-if="item.t_slot">
<slot :data="scope.row" :name="item.t_slot"></slot>
</template>
<template v-else>
{{ scope.row[item.t_props] || '-' }}
</template>
2024-08-07 09:53:21 +08:00
</template>
</el-table-column>
<el-table-column align="center" label="操作" v-show="handleShow">
<template slot-scope="{ row }">
<slot :data="row" name="handle"></slot>
2024-08-07 09:53:21 +08:00
</template>
</el-table-column>
</el-table>
2024-08-07 09:53:21 +08:00
</div>
</template>
<script>
import ToolbarModel from '../ToolbarModel'
2024-08-07 09:53:21 +08:00
export default {
components: { ToolbarModel },
2024-08-07 09:53:21 +08:00
props: {
/** 表单查询条件 */
formLabel: {
type: Array,
default: () => [],
},
/** 列表请求接口 */
requestApi: {
type: Function,
default: () => function () {},
},
/* 列表配置项 */
columnsList: {
type: Array,
2024-08-07 09:53:21 +08:00
default: () => [],
},
},
computed: {
/* 根据操作栏控制表头是否显示 */
tableColumCheckProps() {
return this.columCheckList.filter((e) => {
return e.checked != false
})
},
},
data() {
return {
// 列表接口查询参数
queryParams: {},
// 搜索区域是否隐藏
showSearch: true,
// 是否显示复选框
selectionShow: true,
// 是否显示序号
indexNumShow: true,
// 是否显示操作列
handleShow: true,
columCheckList: [],
tableList: [],
2024-08-07 09:53:21 +08:00
}
},
created() {
this.columCheckList = this.columnsList
this.columCheckList = this.columCheckList.map((e) => {
this.$set(e, 'checked', true)
return e
})
/* 生成查询参数 */
this.formLabel.map((e) => {
this.$set(this.queryParams, e.f_model, '')
})
this.getTableList()
},
methods: {
/** 获取列表数据 */
async getTableList() {
const res = await this.requestApi({ ...this.queryParams })
console.log(res, '列表数据')
},
/** 查询按钮 */
handleQuery() {
this.getTableList()
},
/** 重置按钮 */
resetQuery() {
// this.$refs.queryFormRef.resetFields()
2024-08-07 09:53:21 +08:00
this.getTableList()
},
/** 筛选列 */
checkboxChange(list) {
this.columCheckList = list
},
2024-08-07 09:53:21 +08:00
},
}
</script>
<style scoped lang="scss">
.btn-container {
margin-bottom: 6px;
display: flex;
align-items: center;
}
::v-deep .btn-handler {
flex: 1;
.el-button {
padding: 6px 18px;
}
}
</style>