|
@@ -7,25 +7,25 @@
|
|
|
*
|
|
|
-->
|
|
|
<script setup lang="ts">
|
|
|
-import type { PropsParams, TableFieldInfo, TablePaginationSetting } from '@/types/table'
|
|
|
-import type { ReqConfig } from '@/types/dataAnalysis'
|
|
|
+import type { PropsParams, TableFieldInfo, TablePaginationSetting } from '@/types/table.ts'
|
|
|
+import type { ReqConfig } from '@/types/dataAnalysis.ts'
|
|
|
import type { FormInstance } from 'element-plus'
|
|
|
-import { FilterType } from '@/types/table'
|
|
|
-import { FieldSpecialEffectType } from '@/types/tableText'
|
|
|
+import { FilterType } from '@/types/table.ts'
|
|
|
+import { FieldSpecialEffectType } from '@/types/tableText.ts'
|
|
|
|
|
|
import { initLoadResource } from '@/utils/resource'
|
|
|
import { fuzzySearch, throttleFunc } from '@/utils/common'
|
|
|
import { useCustomFilter } from '@/hooks/useCustomFilter.ts'
|
|
|
-import { useTable } from '@/hooks/useTable'
|
|
|
-import { useRequest } from '@/hooks/useRequest'
|
|
|
+import { useTable } from '@/hooks/useTable.ts'
|
|
|
+import { useRequest } from '@/hooks/useRequest.ts'
|
|
|
import { computed, onMounted, reactive, ref, toRaw, watch } from 'vue'
|
|
|
import { Filter } from '@element-plus/icons-vue'
|
|
|
|
|
|
-import CustomFilter from './form/CustomFilter.vue'
|
|
|
-import FilterPopover from './toolsBtn/FilterPopover.vue'
|
|
|
-import RefreshBtn from './toolsBtn/RefreshBtn.vue'
|
|
|
-import TableFieldText from './table/TableFieldText.vue'
|
|
|
-import axiosInstance from '@/utils/axios/axiosInstance'
|
|
|
+import CustomFilter from '../form/CustomFilter.vue'
|
|
|
+import FilterPopover from '../toolsBtn/FilterPopover.vue'
|
|
|
+import RefreshBtn from '../toolsBtn/RefreshBtn.vue'
|
|
|
+import TableFieldText from './TableFieldText.vue'
|
|
|
+import axiosInstance from '@/utils/axios/axiosInstance.ts'
|
|
|
|
|
|
type CustomFilterRef = InstanceType<typeof CustomFilter>
|
|
|
|
|
@@ -41,7 +41,6 @@ const {
|
|
|
activeCustomFilterKey,
|
|
|
initCustomFilterInfo,
|
|
|
openCustomFilter,
|
|
|
-
|
|
|
confirmCustomFilter
|
|
|
} = useCustomFilter(customFilterRef)
|
|
|
// 节流的延迟时间
|
|
@@ -53,22 +52,20 @@ const toolsIconSize = ref(25)
|
|
|
// 查询表单
|
|
|
const queryFormRef = ref<FormInstance>()
|
|
|
|
|
|
-// 传过来的配置
|
|
|
const props = withDefaults(defineProps<PropsParams>(), {
|
|
|
needRowindex: true,
|
|
|
needAverage: false,
|
|
|
needLeftTools: false,
|
|
|
needRightTools: false,
|
|
|
openFilterQuery: false,
|
|
|
- openPageQuery: false,
|
|
|
+ openPageQuery: true,
|
|
|
+ openRemoteQuery: true,
|
|
|
needUpload: false,
|
|
|
needDownLoad: false,
|
|
|
- openRemoteQuery: false,
|
|
|
+
|
|
|
loadingState: false
|
|
|
})
|
|
|
|
|
|
-// 父组件触发的方法
|
|
|
-// 删除了一个事件触发,loadSuccess
|
|
|
const emits = defineEmits(['addNewItem', 'upload', 'downLoad'])
|
|
|
|
|
|
// 加载动画
|
|
@@ -113,8 +110,12 @@ const blobUrlInfo = reactive<Record<string, string>>({})
|
|
|
// 一些公用方法
|
|
|
const { getTableData } = useTable(tableData, paginationConfig)
|
|
|
|
|
|
-// 没有开启分页查询的时候使用的数据
|
|
|
-const tableDataNoPaging = computed(() => {
|
|
|
+/**
|
|
|
+ * 计算表格数据,如果开启了分页查询,那么就返回一个空数组,否则返回当前页码的数据
|
|
|
+ */
|
|
|
+const tableDataNoPaging = computed<any[]>(() => {
|
|
|
+ // 开启分页查询则需要去远程查询,不使用此处的动态计算的数据
|
|
|
+ if (props.openRemoteQuery) return []
|
|
|
let curPage = paginationConfig.currentPage
|
|
|
let limit = paginationConfig.limit
|
|
|
let begin = curPage * limit - limit
|
|
@@ -171,14 +172,15 @@ const handleSizeChange = (val: number) => {
|
|
|
* @description 加载表格数据
|
|
|
*/
|
|
|
const loadTableData = async (): Promise<boolean> => {
|
|
|
- console.trace()
|
|
|
return new Promise(async (resolve, reject) => {
|
|
|
loading.value = true
|
|
|
// 如果是直接传入的数据
|
|
|
if (props.dataList) {
|
|
|
tableData.splice(0, tableData.length, ...props.dataList)
|
|
|
+ if (props.paginationConfig) {
|
|
|
+ paginationConfig.total = props.paginationConfig.total
|
|
|
+ }
|
|
|
|
|
|
- paginationConfig.total = props.paginationConfig.total
|
|
|
loading.value = false
|
|
|
|
|
|
resolve(true)
|
|
@@ -189,13 +191,13 @@ const loadTableData = async (): Promise<boolean> => {
|
|
|
// 如果开启了分页查询,那么要计算出需要展示的页码位置所对应的偏移量
|
|
|
// 同时要将查询的条数改为对应的用户选择的展示条数
|
|
|
|
|
|
- if (props.openPageQuery) {
|
|
|
+ if (props.openRemoteQuery) {
|
|
|
reqConfig.otherOptions.offset =
|
|
|
(paginationConfig.currentPage - 1) * paginationConfig.limit
|
|
|
reqConfig.otherOptions.limit = paginationConfig.limit
|
|
|
}
|
|
|
// console.log(reqConfig.otherOptions)
|
|
|
- await getTableData(reqConfig.url, reqConfig.otherOptions, props.openPageQuery)
|
|
|
+ await getTableData(reqConfig.url, reqConfig.otherOptions, props.openRemoteQuery)
|
|
|
|
|
|
backupTableData.splice(0, backupTableData.length, ...tableData)
|
|
|
resolve(true)
|
|
@@ -223,6 +225,7 @@ const getData = () => {
|
|
|
try {
|
|
|
// 等待数据加载完成
|
|
|
await loadTableData()
|
|
|
+ // 如果需要平均值字段,则需要在表格头部插入一行计算平均值
|
|
|
if (props.needAverage) {
|
|
|
let rowData: any = {}
|
|
|
let oldList: Array<any> = JSON.parse(JSON.stringify(tableData))
|
|
@@ -264,22 +267,7 @@ const resetTableData = () => {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 删除没有用的自定义筛选字段,如果不删后端会查询不到(可以不用)
|
|
|
- *
|
|
|
- */
|
|
|
-// const delUnusedCustomFilter = () => {
|
|
|
-// let customKeys = customFieldsList.value?.map((item) => {
|
|
|
-// return item.name
|
|
|
-// })
|
|
|
-// for (let [k, v] of Object.entries(queryFormData)) {
|
|
|
-// if (customKeys && customKeys.includes(k) && typeof v !== 'object') {
|
|
|
-// console.log(k)
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
-
|
|
|
-/**
|
|
|
- * @description: 按条件查询,如果开启了分页查询,那么会直接重新查询数据,否则,会根据现有数据进行查询
|
|
|
+ * @description 按条件查询,如果开启了分页查询,那么会直接重新查询数据,否则,会根据现有数据进行查询
|
|
|
*/
|
|
|
const queryTableData = () => {
|
|
|
console.log(props.openRemoteQuery, props.requestConfig)
|
|
@@ -320,7 +308,7 @@ const resetQueryFormData = () => {
|
|
|
JSON.stringify(backupQueryFormData, (_, v) => (typeof v === 'undefined' ? '' : v))
|
|
|
)
|
|
|
Object.assign(queryFormData, data)
|
|
|
- reqConfig.otherOptions = backupReqOtherOptions // 要把请求的参数也重置一次,不然切换平台等操作,会带着原来的查询参数请求
|
|
|
+ reqConfig.otherOptions = backupReqOtherOptions // 要把请求的参数也重置一次,不然切换平台等操作,会带着原来地查询参数请求
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -328,7 +316,7 @@ const resetQueryFormData = () => {
|
|
|
*/
|
|
|
const resetQueryForm = () => {
|
|
|
resetQueryFormData()
|
|
|
- queryTableData()
|
|
|
+ throttleQueryTableData()
|
|
|
}
|
|
|
|
|
|
// 把重置方法包装一下,节流
|
|
@@ -340,7 +328,8 @@ const throttleResetQueryForm = throttleFunc(resetQueryForm, throttleTime)
|
|
|
* @param rowData 插入的数据
|
|
|
*/
|
|
|
const insertRow = (start: number, rowData: any) => {
|
|
|
- if (props.openPageQuery) {
|
|
|
+ console.log(tableData)
|
|
|
+ if (props.openRemoteQuery) {
|
|
|
tableData[start].splice(0, 0, rowData)
|
|
|
} else {
|
|
|
tableData.splice(start, 0, rowData)
|
|
@@ -417,7 +406,7 @@ const watchCurPage = watch(
|
|
|
)
|
|
|
|
|
|
// 如果没有开启分页查询,直接关闭这两个监听
|
|
|
-if (!props.openPageQuery) {
|
|
|
+if (!props.openRemoteQuery) {
|
|
|
watchLimit()
|
|
|
watchCurPage()
|
|
|
}
|
|
@@ -770,7 +759,7 @@ onMounted(() => {
|
|
|
</el-icon>
|
|
|
下载
|
|
|
</el-button>
|
|
|
- <!-- throttleFunc(queryTableData, 200) -->
|
|
|
+
|
|
|
<RefreshBtn @refresh-table="throttleGetData" :icon-size="toolsIconSize"></RefreshBtn>
|
|
|
|
|
|
<FilterPopover
|
|
@@ -783,13 +772,14 @@ onMounted(() => {
|
|
|
<div class="tableBox">
|
|
|
<!-- 没有分页的时候需要重新计算一下data -->
|
|
|
<el-table
|
|
|
- :data="openPageQuery ? tableData[paginationConfig.currentPage] : tableDataNoPaging"
|
|
|
+ :data="openRemoteQuery ? tableData[paginationConfig.currentPage] : tableDataNoPaging"
|
|
|
style="width: 100%"
|
|
|
class="tableBody"
|
|
|
:cell-style="tableCellStyle"
|
|
|
v-loading="loading"
|
|
|
:row-key="createRowKey()"
|
|
|
@sort-change="tableSortChange"
|
|
|
+ table-layout="auto"
|
|
|
>
|
|
|
<el-table-column
|
|
|
v-if="props.needRowindex"
|
|
@@ -870,7 +860,7 @@ onMounted(() => {
|
|
|
|
|
|
<slot name="tableOperation"></slot>
|
|
|
</el-table>
|
|
|
- <div class="userTablePaginationBox">
|
|
|
+ <div class="userTablePaginationBox" v-if="openPageQuery">
|
|
|
<el-pagination
|
|
|
class="userTablePagination"
|
|
|
background
|