|
@@ -2,7 +2,7 @@
|
|
|
import type { PropsParams, TablePaginationSetting, QueryInfo } from '@/types/table'
|
|
|
import { FilterType } from '@/types/table'
|
|
|
|
|
|
-import { computed, onMounted, reactive, ref } from 'vue'
|
|
|
+import { computed, onMounted, reactive, ref, watch } from 'vue'
|
|
|
import { useTable } from '@/hooks/useTable'
|
|
|
|
|
|
// 表格工具图标大小
|
|
@@ -22,9 +22,6 @@ const queryFormData = reactive<any>({})
|
|
|
// 一些公用方法
|
|
|
const { getTableData } = useTable(tableData, props.paginationConfig)
|
|
|
|
|
|
-// 查询操作
|
|
|
-const queryTable = () => {}
|
|
|
-
|
|
|
// 所有类型为input的表单控件信息
|
|
|
const inputFieldsList = computed(() => {
|
|
|
return props.queryInfo?.filter((item) => item.type === FilterType.INPUT)
|
|
@@ -32,7 +29,12 @@ const inputFieldsList = computed(() => {
|
|
|
|
|
|
// 所有类型为select的表单控件信息
|
|
|
const selectFieldsList = computed(() => {
|
|
|
- return props.queryInfo?.filter((item) => item.type === FilterType.SELECT)
|
|
|
+ return props.queryInfo?.filter((item) => {
|
|
|
+ if (item.default) {
|
|
|
+ queryFormData[item.name] = item.default
|
|
|
+ }
|
|
|
+ return item.type === FilterType.SELECT
|
|
|
+ })
|
|
|
})
|
|
|
|
|
|
// 所有类型为date的表单控件信息
|
|
@@ -50,23 +52,68 @@ const handleSizeChange = (val: number) => {
|
|
|
props.paginationConfig.limit = val
|
|
|
}
|
|
|
|
|
|
+// 获取数据
|
|
|
const getData = () => {
|
|
|
- getTableData(props.requestConfig.url, props.requestConfig.other)
|
|
|
+ if (props.openPageQuery) {
|
|
|
+ // 如果开启了分页查询,那么要计算出需要展示的页码位置所对应的偏移量
|
|
|
+ // 同时要将查询的条数改为对应的用户选择的展示条数
|
|
|
+ props.requestConfig.other.offset =
|
|
|
+ (props.paginationConfig.currentPage - 1) * props.paginationConfig.limit
|
|
|
+ props.requestConfig.other.limit = props.paginationConfig.limit
|
|
|
+ }
|
|
|
+
|
|
|
+ // 查询时要根据是否开启分页查询传入对应参数
|
|
|
+ getTableData(props.requestConfig.url, props.requestConfig.other, props.openPageQuery)
|
|
|
+}
|
|
|
+
|
|
|
+// 清空表格数据
|
|
|
+const resetTableData = () => {
|
|
|
+ tableData.splice(0, tableData.length)
|
|
|
+}
|
|
|
+
|
|
|
+// 根据分页大小的切换来更新数据
|
|
|
+// 这里将他赋值,用于根据传入的配置来选择是否开启该监听
|
|
|
+const changePageLimit = watch(
|
|
|
+ () => [props.paginationConfig.limit, props.paginationConfig.currentPage],
|
|
|
+ ([newLimit], [oldLimit]) => {
|
|
|
+ if (newLimit != oldLimit) {
|
|
|
+ // 需要给分页按钮加上:current-page.sync="current_page" 配置,不然不生效
|
|
|
+ // 当改变每页大小时把之前的缓存全部清除,重新开始
|
|
|
+ props.paginationConfig.currentPage = 1
|
|
|
+ resetTableData()
|
|
|
+ getData()
|
|
|
+ } else if (!tableData[props.paginationConfig.currentPage]) {
|
|
|
+ // 当对应的数组下标位置没有这页的数据的时候再去请求
|
|
|
+ getData()
|
|
|
+ }
|
|
|
+ },
|
|
|
+ { deep: true }
|
|
|
+)
|
|
|
+
|
|
|
+// 按条件查询
|
|
|
+const queryTableData = () => {
|
|
|
+ props.requestConfig.other = { ...props.requestConfig.other, ...queryFormData }
|
|
|
+ getData()
|
|
|
}
|
|
|
|
|
|
+// 没有开启分页查询就关闭掉这个监听
|
|
|
+if (!props.openPageQuery) changePageLimit()
|
|
|
+
|
|
|
// 定义暴露出去的方法
|
|
|
defineExpose({
|
|
|
- getData
|
|
|
+ getData,
|
|
|
+ resetTableData
|
|
|
})
|
|
|
|
|
|
onMounted(() => {
|
|
|
getData()
|
|
|
+ console.log(selectFieldsList)
|
|
|
})
|
|
|
</script>
|
|
|
|
|
|
<template>
|
|
|
<div class="tableContent">
|
|
|
- <div class="filterBox" v-if="isOpenQuery">
|
|
|
+ <div class="filterBox" v-if="openFilterQuery">
|
|
|
<!-- slot -->
|
|
|
<div class="filterHeader">
|
|
|
<span>查询条件</span>
|
|
@@ -87,7 +134,7 @@ onMounted(() => {
|
|
|
<el-form-item :label="item.label" v-for="item in selectFieldsList" class="filterItem">
|
|
|
<!-- {{ item.placeholder }} -->
|
|
|
<el-select v-model="queryFormData[item.name]" :placeholder="item.placeholder">
|
|
|
- <el-option v-for="val in item.otherOption" :label="val.cnName" :value="val.name" />
|
|
|
+ <el-option v-for="val in item.otherOption" :label="val.cnName" :value="val.value" />
|
|
|
</el-select>
|
|
|
</el-form-item>
|
|
|
|
|
@@ -106,7 +153,7 @@ onMounted(() => {
|
|
|
<div class="queryBox">
|
|
|
<el-divider class="queryPartition" content-position="center" direction="vertical" />
|
|
|
<div class="queryBtnBox">
|
|
|
- <el-button class="queryBtn" color="#165dff">
|
|
|
+ <el-button class="queryBtn" color="#165dff" @click="queryTableData">
|
|
|
<el-icon><Search /></el-icon>查询
|
|
|
</el-button>
|
|
|
<el-button class="refreshBtn" color="#f2f3f5">
|
|
@@ -120,7 +167,7 @@ onMounted(() => {
|
|
|
<el-divider class="partition" content-position="center" />
|
|
|
<div class="tableTools">
|
|
|
<div class="leftTools">
|
|
|
- <el-button type="primary" color="#165dff" @click="emits('addNewItem')">
|
|
|
+ <el-button v-if="needLeftTools" type="primary" color="#165dff" @click="emits('addNewItem')">
|
|
|
<el-icon><Plus /></el-icon>新增
|
|
|
</el-button>
|
|
|
</div>
|
|
@@ -134,15 +181,21 @@ onMounted(() => {
|
|
|
</div>
|
|
|
|
|
|
<div class="tableBox">
|
|
|
- <el-table :data="tableData" style="width: 100%">
|
|
|
- <el-table-column label="#" type="index" :index="1" />
|
|
|
+ <el-table
|
|
|
+ :data="openPageQuery ? tableData[paginationConfig.currentPage] : tableData"
|
|
|
+ style="width: 100%"
|
|
|
+ class="tableBody"
|
|
|
+ >
|
|
|
+ <el-table-column align="center" label="#" type="index" :index="1" />
|
|
|
<el-table-column
|
|
|
v-for="item in tableFieldsInfo"
|
|
|
:prop="item.name"
|
|
|
:label="item.cnName"
|
|
|
width="auto"
|
|
|
+ align="center"
|
|
|
show-overflow-tooltip
|
|
|
- />
|
|
|
+ >
|
|
|
+ </el-table-column>
|
|
|
<slot name="tableOperation"></slot>
|
|
|
</el-table>
|
|
|
<div class="userTablePaginationBox">
|
|
@@ -167,8 +220,7 @@ onMounted(() => {
|
|
|
.tableContent {
|
|
|
margin: 0 auto;
|
|
|
width: 98%;
|
|
|
- height: 98%;
|
|
|
- border: 1px solid #e5e6eb;
|
|
|
+ /* height: 100%; */
|
|
|
}
|
|
|
.filterBox,
|
|
|
.tableBox {
|
|
@@ -192,10 +244,10 @@ onMounted(() => {
|
|
|
display: flex;
|
|
|
align-items: center;
|
|
|
color: black;
|
|
|
- font-size: 18px;
|
|
|
+ font-size: 20px;
|
|
|
font-weight: bold;
|
|
|
/* background-color: lightblue; */
|
|
|
- margin-bottom: 30px;
|
|
|
+ /* margin-bottom: 1%; */
|
|
|
}
|
|
|
|
|
|
.filterBody {
|
|
@@ -218,6 +270,7 @@ onMounted(() => {
|
|
|
|
|
|
.refreshBtn {
|
|
|
margin-top: 10%;
|
|
|
+ margin-bottom: 10%;
|
|
|
}
|
|
|
|
|
|
.queryPartition {
|
|
@@ -252,9 +305,10 @@ onMounted(() => {
|
|
|
|
|
|
.leftTools,
|
|
|
.rightTools {
|
|
|
+ width: 10%;
|
|
|
display: flex;
|
|
|
align-items: center;
|
|
|
- justify-content: space-around;
|
|
|
+ justify-content: space-between;
|
|
|
}
|
|
|
|
|
|
.rightTools {
|
|
@@ -263,8 +317,10 @@ onMounted(() => {
|
|
|
|
|
|
.tableBox {
|
|
|
width: 98%;
|
|
|
+ /* height: 98%; */
|
|
|
margin: 0 auto;
|
|
|
- margin-top: 0.5%;
|
|
|
+ /* margin-top: 0.5%;
|
|
|
+ margin-bottom: 2%; */
|
|
|
}
|
|
|
|
|
|
.userTablePaginationBox {
|