|
|
@@ -2,7 +2,7 @@
|
|
|
* @Author: fxs bjnsfxs@163.com
|
|
|
* @Date: 2024-08-20 18:16:18
|
|
|
* @LastEditors: fxs bjnsfxs@163.com
|
|
|
- * @LastEditTime: 2024-09-13 15:11:03
|
|
|
+ * @LastEditTime: 2024-09-13 18:07:38
|
|
|
* @FilePath: \Game-Backstage-Management-System\src\components\Table.vue
|
|
|
* @Description:
|
|
|
*
|
|
|
@@ -12,6 +12,7 @@ import type { PropsParams, TablePaginationSetting } from '@/types/table'
|
|
|
import type { ReqConfig } from '@/types/dataAnalysis'
|
|
|
import { FilterType, FieldSpecialEffectType } from '@/types/table'
|
|
|
import { initLoadResouce } from '@/utils/resource'
|
|
|
+import { fuzzySearch } from '@/utils/common'
|
|
|
|
|
|
import { computed, onMounted, reactive, ref, toRaw, watch } from 'vue'
|
|
|
import { useTable } from '@/hooks/useTable'
|
|
|
@@ -53,6 +54,9 @@ const loading = ref(false)
|
|
|
// 表格数据
|
|
|
const tableData: Array<any> = reactive([])
|
|
|
|
|
|
+// 备份表格数据,用于在不分页查询的时候,恢复数据
|
|
|
+const backupTableData: Array<any> = []
|
|
|
+
|
|
|
// 查询表单的数据
|
|
|
const queryFormData = reactive<{ [key: string]: any }>({})
|
|
|
|
|
|
@@ -150,6 +154,7 @@ const getData = () => {
|
|
|
getTableData(reqconfig.url, reqconfig.otherOptions, props.openPageQuery)
|
|
|
.then(() => {
|
|
|
emits('loadSuccess', tableData)
|
|
|
+ backupTableData.splice(0, backupTableData.length, ...tableData)
|
|
|
resolve(true)
|
|
|
})
|
|
|
.catch((err) => {
|
|
|
@@ -203,9 +208,22 @@ const resetTableData = () => {
|
|
|
const queryTableData = () => {
|
|
|
if (props.requestConfig) {
|
|
|
reqconfig.otherOptions = { ...props.requestConfig.otherOptions, ...queryFormData }
|
|
|
- getData()
|
|
|
- } else {
|
|
|
- throw new Error('no match requestConfig')
|
|
|
+ }
|
|
|
+ if (props.openPageQuery) getData()
|
|
|
+ else {
|
|
|
+ let filteredTable = []
|
|
|
+ filteredTable = backupTableData.filter((item) => {
|
|
|
+ let state = true
|
|
|
+ for (let [k, v] of Object.entries(queryFormData)) {
|
|
|
+ if (!fuzzySearch(v, item[k])) {
|
|
|
+ state = false
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return state
|
|
|
+ })
|
|
|
+
|
|
|
+ tableData.splice(0, tableData.length, ...filteredTable)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -268,34 +286,48 @@ const tableCellStyle = (info: any) => {
|
|
|
// 根据分页大小的切换来更新数据
|
|
|
// 这里将他赋值,用于根据传入的配置来选择是否开启该监听
|
|
|
/**
|
|
|
- * @description: 监听litmit,currentpage,gid的变化,改变后去重新请求数据
|
|
|
+ * @description: 监听litmit,currentpage的变化,改变后去重新请求数据
|
|
|
* 如果是limit的变化,则需要把当前页置为1
|
|
|
*
|
|
|
* 对于Gid需要去监听props的,而不是本地的,因为是外部的改变
|
|
|
* @return {*}
|
|
|
*/
|
|
|
const changePageLimit = watch(
|
|
|
- () => [
|
|
|
- paginationConfig2.limit,
|
|
|
- props.requestConfig?.otherOptions.gid,
|
|
|
- paginationConfig2.currentPage
|
|
|
- ],
|
|
|
- ([newLimit, newGid], [oldLimit, oldGid]) => {
|
|
|
+ () => [paginationConfig2.limit, paginationConfig2.currentPage],
|
|
|
+ ([newLimit, newCurPage], [oldLimit, oldCruPage]) => {
|
|
|
if (newLimit != oldLimit) {
|
|
|
// 需要给分页按钮加上:current-page.sync="current_page" 配置,不然不生效
|
|
|
// 当改变每页大小时把之前的缓存全部清除,重新开始
|
|
|
paginationConfig2.currentPage = 1
|
|
|
// resetTableData()
|
|
|
}
|
|
|
- if (newGid != oldGid) reqconfig.otherOptions.gid = newGid
|
|
|
|
|
|
- if (newLimit != oldLimit || !tableData[paginationConfig2.currentPage] || newGid != oldGid) {
|
|
|
+ if (newCurPage != oldCruPage) paginationConfig2.currentPage = newCurPage
|
|
|
+
|
|
|
+ // if (newGid != oldGid) reqconfig.otherOptions.gid = newGid
|
|
|
+ // || newGid != oldGid
|
|
|
+
|
|
|
+ if (newLimit != oldLimit || !tableData[paginationConfig2.currentPage]) {
|
|
|
getData()
|
|
|
}
|
|
|
},
|
|
|
{ deep: true }
|
|
|
)
|
|
|
|
|
|
+/**
|
|
|
+ * @description: 监听gid的变化,重新请求数据,这里很奇怪,跟上面的limit和page放到一起不起作用
|
|
|
+ * @return {*}
|
|
|
+ */
|
|
|
+watch(
|
|
|
+ () => props.requestConfig?.otherOptions.gid,
|
|
|
+ (newGid, oldGid) => {
|
|
|
+ if (newGid != oldGid) {
|
|
|
+ reqconfig.otherOptions.gid = newGid
|
|
|
+ getData()
|
|
|
+ }
|
|
|
+ }
|
|
|
+)
|
|
|
+
|
|
|
// 监听传入的datalist的变化,然后去更新数据
|
|
|
const changeDataList = watch(
|
|
|
() => [props.dataList],
|
|
|
@@ -430,9 +462,9 @@ onMounted(() => {
|
|
|
if (props.loadingState !== undefined) {
|
|
|
loading.value = props.loadingState
|
|
|
}
|
|
|
- if (!props.openPageQuery) {
|
|
|
- getData()
|
|
|
- }
|
|
|
+ // if (!props.openPageQuery) {
|
|
|
+ // getData()
|
|
|
+ // }
|
|
|
// 去加载所有需要的资源
|
|
|
initLoadResouce(resourceInfo).then((data) => {
|
|
|
Object.assign(blobUrlInfo, data)
|