|
@@ -2,7 +2,7 @@
|
|
* @Author: fxs bjnsfxs@163.com
|
|
* @Author: fxs bjnsfxs@163.com
|
|
* @Date: 2024-08-20 18:16:18
|
|
* @Date: 2024-08-20 18:16:18
|
|
* @LastEditors: fxs bjnsfxs@163.com
|
|
* @LastEditors: fxs bjnsfxs@163.com
|
|
- * @LastEditTime: 2024-10-14 11:06:43
|
|
|
|
|
|
+ * @LastEditTime: 2024-10-14 14:36:44
|
|
* @FilePath: \Game-Backstage-Management-System\src\components\Table.vue
|
|
* @FilePath: \Game-Backstage-Management-System\src\components\Table.vue
|
|
* @Description:
|
|
* @Description:
|
|
*
|
|
*
|
|
@@ -69,7 +69,7 @@ const queryFormData = reactive<{ [key: string]: any }>({})
|
|
const backupQueryFormData = reactive<{ [key: string]: any }>({})
|
|
const backupQueryFormData = reactive<{ [key: string]: any }>({})
|
|
|
|
|
|
// 分页数据
|
|
// 分页数据
|
|
-const paginationConfig2 = reactive<TablePaginationSetting>({
|
|
|
|
|
|
+const paginationConfig = reactive<TablePaginationSetting>({
|
|
currentPage: 1,
|
|
currentPage: 1,
|
|
limit: 0,
|
|
limit: 0,
|
|
total: 0,
|
|
total: 0,
|
|
@@ -91,12 +91,12 @@ const resourceInfo: Record<string, string> = {
|
|
const blobUrlInfo = reactive<Record<string, string>>({})
|
|
const blobUrlInfo = reactive<Record<string, string>>({})
|
|
|
|
|
|
// 一些公用方法
|
|
// 一些公用方法
|
|
-const { getTableData } = useTable(tableData, paginationConfig2)
|
|
|
|
|
|
+const { getTableData } = useTable(tableData, paginationConfig)
|
|
|
|
|
|
// 没有开启分页查询的时候使用的数据
|
|
// 没有开启分页查询的时候使用的数据
|
|
const tableDataNoPaging = computed(() => {
|
|
const tableDataNoPaging = computed(() => {
|
|
- let curPage = paginationConfig2.currentPage
|
|
|
|
- let limit = paginationConfig2.limit
|
|
|
|
|
|
+ let curPage = paginationConfig.currentPage
|
|
|
|
+ let limit = paginationConfig.limit
|
|
let begin = curPage * limit - limit
|
|
let begin = curPage * limit - limit
|
|
//这里不减一是因为,slice方法裁切是左闭右开数组
|
|
//这里不减一是因为,slice方法裁切是左闭右开数组
|
|
let end = curPage * limit
|
|
let end = curPage * limit
|
|
@@ -122,103 +122,102 @@ const dateFieldsList = computed(() => {
|
|
|
|
|
|
// 计算行号
|
|
// 计算行号
|
|
const computedRowIndex = (index: number) => {
|
|
const computedRowIndex = (index: number) => {
|
|
- return (paginationConfig2.currentPage - 1) * paginationConfig2.limit + index + 1
|
|
|
|
|
|
+ return (paginationConfig.currentPage - 1) * paginationConfig.limit + index + 1
|
|
}
|
|
}
|
|
|
|
|
|
// 改变页码
|
|
// 改变页码
|
|
const handleCurrentChange = (val: number) => {
|
|
const handleCurrentChange = (val: number) => {
|
|
- paginationConfig2.currentPage = val
|
|
|
|
|
|
+ paginationConfig.currentPage = val
|
|
}
|
|
}
|
|
|
|
|
|
// 改变每页大小
|
|
// 改变每页大小
|
|
const handleSizeChange = (val: number) => {
|
|
const handleSizeChange = (val: number) => {
|
|
- paginationConfig2.limit = val
|
|
|
|
|
|
+ paginationConfig.limit = val
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * @description: 获取数据,如果没有直接传入数据,则去请求数据,有则直接用
|
|
|
|
|
|
+ * @description: 加载表格数据
|
|
* @return {*}
|
|
* @return {*}
|
|
*/
|
|
*/
|
|
-const getData = () => {
|
|
|
|
- console.trace()
|
|
|
|
- return new Promise(async (resolve, reject) => {
|
|
|
|
- try {
|
|
|
|
- const loadTableData = async () => {
|
|
|
|
- return new Promise((resolve, reject) => {
|
|
|
|
- if (props.dataList) {
|
|
|
|
- tableData.splice(0, tableData.length, ...props.dataList)
|
|
|
|
|
|
+const loadTableData = async () => {
|
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
|
+ if (props.dataList) {
|
|
|
|
+ tableData.splice(0, tableData.length, ...props.dataList)
|
|
|
|
+
|
|
|
|
+ paginationConfig.total = props.paginationConfig.total
|
|
|
|
+ loading.value = false
|
|
|
|
+ // emits('loadSuccess', tableData)
|
|
|
|
+
|
|
|
|
+ resolve(true)
|
|
|
|
+ } else {
|
|
|
|
+ loading.value = true
|
|
|
|
+ if (props.requestConfig) {
|
|
|
|
+ if (props.openPageQuery) {
|
|
|
|
+ // 如果开启了分页查询,那么要计算出需要展示的页码位置所对应的偏移量
|
|
|
|
+ // 同时要将查询的条数改为对应的用户选择的展示条数
|
|
|
|
+ reqconfig.otherOptions.offset =
|
|
|
|
+ (paginationConfig.currentPage - 1) * paginationConfig.limit
|
|
|
|
+ reqconfig.otherOptions.limit = paginationConfig.limit
|
|
|
|
+ }
|
|
|
|
|
|
- paginationConfig2.total = props.paginationConfig.total
|
|
|
|
- loading.value = false
|
|
|
|
|
|
+ // 查询时要根据是否开启分页查询传入对应参数
|
|
|
|
+ getTableData(reqconfig.url, reqconfig.otherOptions, props.openPageQuery)
|
|
|
|
+ .then(() => {
|
|
// emits('loadSuccess', tableData)
|
|
// emits('loadSuccess', tableData)
|
|
|
|
+ backupTableData.splice(0, backupTableData.length, ...tableData)
|
|
|
|
|
|
resolve(true)
|
|
resolve(true)
|
|
- } else {
|
|
|
|
- loading.value = true
|
|
|
|
- if (props.requestConfig) {
|
|
|
|
- if (props.openPageQuery) {
|
|
|
|
- // 如果开启了分页查询,那么要计算出需要展示的页码位置所对应的偏移量
|
|
|
|
- // 同时要将查询的条数改为对应的用户选择的展示条数
|
|
|
|
- reqconfig.otherOptions.offset =
|
|
|
|
- (paginationConfig2.currentPage - 1) * paginationConfig2.limit
|
|
|
|
- reqconfig.otherOptions.limit = paginationConfig2.limit
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- // 查询时要根据是否开启分页查询传入对应参数
|
|
|
|
- getTableData(reqconfig.url, reqconfig.otherOptions, props.openPageQuery)
|
|
|
|
- .then(() => {
|
|
|
|
- // emits('loadSuccess', tableData)
|
|
|
|
- backupTableData.splice(0, backupTableData.length, ...tableData)
|
|
|
|
-
|
|
|
|
- resolve(true)
|
|
|
|
- })
|
|
|
|
- .catch((err) => {
|
|
|
|
- console.log(err)
|
|
|
|
-
|
|
|
|
- reject(err)
|
|
|
|
- })
|
|
|
|
- .finally(() => {
|
|
|
|
- loading.value = false
|
|
|
|
- })
|
|
|
|
- } else {
|
|
|
|
- loading.value = false
|
|
|
|
-
|
|
|
|
- throw new Error('no match requestConfig')
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- })
|
|
|
|
|
|
+ })
|
|
|
|
+ .catch((err) => {
|
|
|
|
+ console.log(err)
|
|
|
|
+
|
|
|
|
+ reject(err)
|
|
|
|
+ })
|
|
|
|
+ .finally(() => {
|
|
|
|
+ loading.value = false
|
|
|
|
+ })
|
|
|
|
+ } else {
|
|
|
|
+ loading.value = false
|
|
|
|
+
|
|
|
|
+ throw new Error('no match requestConfig')
|
|
}
|
|
}
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+}
|
|
|
|
+import type { TableFieldInfo } from '@/types/table'
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * @description: 获取数据,如果没有直接传入数据,则去请求数据,有则直接用
|
|
|
|
+ * @return {*}
|
|
|
|
+ */
|
|
|
|
+const getData = () => {
|
|
|
|
+ return new Promise(async (resolve, reject) => {
|
|
|
|
+ try {
|
|
// 等待数据加载完成
|
|
// 等待数据加载完成
|
|
await loadTableData()
|
|
await loadTableData()
|
|
- .then(async () => {
|
|
|
|
- if (props.needAverage) {
|
|
|
|
- let rowData: any = {}
|
|
|
|
- let oldList: Array<any> = JSON.parse(JSON.stringify(tableData))
|
|
|
|
- Object.values(props.tableFieldsInfo).map((item, index) => {
|
|
|
|
- let sum = oldList
|
|
|
|
- .map((item) => item.count)
|
|
|
|
- .reduce((accumulator, currentValue) => accumulator + currentValue, 0)
|
|
|
|
- let averageList = oldList
|
|
|
|
- .map((val) => val[item.name])
|
|
|
|
- .filter((item) => item !== undefined)
|
|
|
|
- if (index === 0) rowData[item.name] = '均值'
|
|
|
|
- else if (item.name === 'count') rowData[item.name] = sum
|
|
|
|
- else {
|
|
|
|
- let num =
|
|
|
|
- averageList.reduce((accumulator, currentValue) => accumulator + currentValue, 0) /
|
|
|
|
- averageList.length
|
|
|
|
-
|
|
|
|
- rowData[item.name] = isNaN(num) ? 0 : num.toFixed(2)
|
|
|
|
- }
|
|
|
|
- })
|
|
|
|
- insertRow(0, rowData)
|
|
|
|
|
|
+ if (props.needAverage) {
|
|
|
|
+ let rowData: any = {}
|
|
|
|
+ let oldList: Array<any> = JSON.parse(JSON.stringify(tableData))
|
|
|
|
+ Object.values(props.tableFieldsInfo).map((item: TableFieldInfo, index: number) => {
|
|
|
|
+ let sum = oldList
|
|
|
|
+ .map((item) => item.count)
|
|
|
|
+ .reduce((accumulator, currentValue) => accumulator + currentValue, 0)
|
|
|
|
+ let averageList = oldList
|
|
|
|
+ .map((val) => val[item.name])
|
|
|
|
+ .filter((item) => item !== undefined)
|
|
|
|
+ if (index === 0) rowData[item.name] = '均值'
|
|
|
|
+ else if (item.name === 'count') rowData[item.name] = sum
|
|
|
|
+ else {
|
|
|
|
+ let num =
|
|
|
|
+ averageList.reduce((accumulator, currentValue) => accumulator + currentValue, 0) /
|
|
|
|
+ averageList.length
|
|
|
|
+
|
|
|
|
+ rowData[item.name] = isNaN(num) ? 0 : num.toFixed(2)
|
|
}
|
|
}
|
|
- resolve(true)
|
|
|
|
- })
|
|
|
|
- .catch((err) => {
|
|
|
|
- console.log(err)
|
|
|
|
- reject(err)
|
|
|
|
})
|
|
})
|
|
|
|
+ insertRow(0, rowData)
|
|
|
|
+ }
|
|
|
|
+ resolve(true)
|
|
} catch (err) {
|
|
} catch (err) {
|
|
console.log(err)
|
|
console.log(err)
|
|
reject(err)
|
|
reject(err)
|
|
@@ -246,6 +245,7 @@ const queryTableData = () => {
|
|
reqconfig.otherOptions = { ...props.requestConfig.otherOptions, ...queryFormData }
|
|
reqconfig.otherOptions = { ...props.requestConfig.otherOptions, ...queryFormData }
|
|
getData()
|
|
getData()
|
|
} else {
|
|
} else {
|
|
|
|
+ console.log('执行')
|
|
let filteredTable = []
|
|
let filteredTable = []
|
|
// 过滤出来所有符合formData数据的条件
|
|
// 过滤出来所有符合formData数据的条件
|
|
filteredTable = backupTableData.filter((item) => {
|
|
filteredTable = backupTableData.filter((item) => {
|
|
@@ -344,21 +344,17 @@ const tableCellStyle = (info: any) => {
|
|
* @return {*}
|
|
* @return {*}
|
|
*/
|
|
*/
|
|
const changePageLimit = watch(
|
|
const changePageLimit = watch(
|
|
- () => [paginationConfig2.limit, paginationConfig2.currentPage],
|
|
|
|
|
|
+ () => [paginationConfig.limit, paginationConfig.currentPage],
|
|
([newLimit, newCurPage], [oldLimit, oldCruPage]) => {
|
|
([newLimit, newCurPage], [oldLimit, oldCruPage]) => {
|
|
if (newLimit != oldLimit) {
|
|
if (newLimit != oldLimit) {
|
|
// 需要给分页按钮加上:current-page.sync="current_page" 配置,不然不生效
|
|
// 需要给分页按钮加上:current-page.sync="current_page" 配置,不然不生效
|
|
// 当改变每页大小时把之前的缓存全部清除,重新开始
|
|
// 当改变每页大小时把之前的缓存全部清除,重新开始
|
|
- paginationConfig2.currentPage = 1
|
|
|
|
- // resetTableData()
|
|
|
|
|
|
+ paginationConfig.currentPage = 1
|
|
}
|
|
}
|
|
|
|
|
|
- if (newCurPage != oldCruPage) paginationConfig2.currentPage = newCurPage
|
|
|
|
-
|
|
|
|
- // if (newGid != oldGid) reqconfig.otherOptions.gid = newGid
|
|
|
|
- // || newGid != oldGid
|
|
|
|
|
|
+ if (newCurPage != oldCruPage) paginationConfig.currentPage = newCurPage
|
|
|
|
|
|
- if (newLimit != oldLimit || !tableData[paginationConfig2.currentPage]) {
|
|
|
|
|
|
+ if (newLimit != oldLimit || !tableData[paginationConfig.currentPage]) {
|
|
getData()
|
|
getData()
|
|
}
|
|
}
|
|
},
|
|
},
|
|
@@ -444,7 +440,7 @@ if (!props.openPageQuery) {
|
|
* @return {*}
|
|
* @return {*}
|
|
*/
|
|
*/
|
|
const initpageConfig = () => {
|
|
const initpageConfig = () => {
|
|
- Object.assign(paginationConfig2, props.paginationConfig)
|
|
|
|
|
|
+ Object.assign(paginationConfig, props.paginationConfig)
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -670,7 +666,7 @@ onMounted(() => {
|
|
<div class="tableBox">
|
|
<div class="tableBox">
|
|
<!-- 没有分页的时候需要重新计算一下data -->
|
|
<!-- 没有分页的时候需要重新计算一下data -->
|
|
<el-table
|
|
<el-table
|
|
- :data="openPageQuery ? tableData[paginationConfig2.currentPage] : tableDataNoPaging"
|
|
|
|
|
|
+ :data="openPageQuery ? tableData[paginationConfig.currentPage] : tableDataNoPaging"
|
|
style="width: 100%"
|
|
style="width: 100%"
|
|
class="tableBody"
|
|
class="tableBody"
|
|
:cell-style="tableCellStyle"
|
|
:cell-style="tableCellStyle"
|
|
@@ -832,12 +828,12 @@ onMounted(() => {
|
|
<el-pagination
|
|
<el-pagination
|
|
class="userTablePagination"
|
|
class="userTablePagination"
|
|
background
|
|
background
|
|
- :page-size="paginationConfig2.limit"
|
|
|
|
- :page-sizes="paginationConfig2.pagesizeList"
|
|
|
|
|
|
+ :page-size="paginationConfig.limit"
|
|
|
|
+ :page-sizes="paginationConfig.pagesizeList"
|
|
table-layout="fixed"
|
|
table-layout="fixed"
|
|
layout="prev, pager, next ,jumper ,sizes,total,"
|
|
layout="prev, pager, next ,jumper ,sizes,total,"
|
|
- :total="paginationConfig2.total"
|
|
|
|
- :current-page.sync="paginationConfig2.currentPage"
|
|
|
|
|
|
+ :total="paginationConfig.total"
|
|
|
|
+ :current-page.sync="paginationConfig.currentPage"
|
|
@current-change="handleCurrentChange"
|
|
@current-change="handleCurrentChange"
|
|
@size-change="handleSizeChange"
|
|
@size-change="handleSizeChange"
|
|
/>
|
|
/>
|