|
|
@@ -2,13 +2,14 @@
|
|
|
* @Author: fxs bjnsfxs@163.com
|
|
|
* @Date: 2024-08-20 18:16:18
|
|
|
* @LastEditors: fxs bjnsfxs@163.com
|
|
|
- * @LastEditTime: 2024-08-30 17:50:03
|
|
|
+ * @LastEditTime: 2024-08-31 18:04:39
|
|
|
* @FilePath: \Game-Backstage-Management-System\src\components\Table.vue
|
|
|
* @Description:
|
|
|
*
|
|
|
-->
|
|
|
<script setup lang="ts">
|
|
|
-import type { PropsParams } from '@/types/table'
|
|
|
+import type { PropsParams, TablePaginationSetting } from '@/types/table'
|
|
|
+import type { ReqConfig } from '@/types/dataAnalysis'
|
|
|
import { FilterType, FieldSpecialEffectType } from '@/types/table'
|
|
|
|
|
|
import { computed, onMounted, reactive, ref, watch } from 'vue'
|
|
|
@@ -47,13 +48,28 @@ const tableData: Array<any> = reactive([])
|
|
|
// 查询表单的数据
|
|
|
const queryFormData = reactive<any>({})
|
|
|
|
|
|
+// 分页数据
|
|
|
+const paginationConfig2 = reactive<TablePaginationSetting>({
|
|
|
+ currentPage: 0,
|
|
|
+ limit: 0,
|
|
|
+ total: 0,
|
|
|
+ pagesizeList: [],
|
|
|
+ hasLodingData: 0
|
|
|
+})
|
|
|
+
|
|
|
+// 请求配置
|
|
|
+const reqconfig = reactive<ReqConfig>({
|
|
|
+ url: '',
|
|
|
+ otherOptions: {}
|
|
|
+})
|
|
|
+
|
|
|
// 一些公用方法
|
|
|
-const { getTableData } = useTable(tableData, props.paginationConfig)
|
|
|
+const { getTableData } = useTable(tableData, paginationConfig2)
|
|
|
|
|
|
// 没有开启分页查询的时候使用的数据
|
|
|
const tableDataNoPaging = computed(() => {
|
|
|
- let curPage = props.paginationConfig.currentPage
|
|
|
- let limit = props.paginationConfig.limit
|
|
|
+ let curPage = paginationConfig2.currentPage
|
|
|
+ let limit = paginationConfig2.limit
|
|
|
let begin = curPage * limit - limit
|
|
|
//这里不减一是因为,slice方法裁切是左闭右开数组
|
|
|
let end = curPage * limit
|
|
|
@@ -82,17 +98,17 @@ const dateFieldsList = computed(() => {
|
|
|
|
|
|
// 计算行号
|
|
|
const computedRowIndex = (index: number) => {
|
|
|
- return (props.paginationConfig.currentPage - 1) * props.paginationConfig.limit + index + 1
|
|
|
+ return (paginationConfig2.currentPage - 1) * paginationConfig2.limit + index + 1
|
|
|
}
|
|
|
|
|
|
// 改变页码
|
|
|
const handleCurrentChange = (val: number) => {
|
|
|
- props.paginationConfig.currentPage = val
|
|
|
+ paginationConfig2.currentPage = val
|
|
|
}
|
|
|
|
|
|
// 改变每页大小
|
|
|
const handleSizeChange = (val: number) => {
|
|
|
- props.paginationConfig.limit = val
|
|
|
+ paginationConfig2.limit = val
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -111,13 +127,13 @@ const getData = () => {
|
|
|
if (props.openPageQuery) {
|
|
|
// 如果开启了分页查询,那么要计算出需要展示的页码位置所对应的偏移量
|
|
|
// 同时要将查询的条数改为对应的用户选择的展示条数
|
|
|
- props.requestConfig.otherOptions.offset =
|
|
|
- (props.paginationConfig.currentPage - 1) * props.paginationConfig.limit
|
|
|
- props.requestConfig.otherOptions.limit = props.paginationConfig.limit
|
|
|
+ reqconfig.otherOptions.offset =
|
|
|
+ (paginationConfig2.currentPage - 1) * paginationConfig2.limit
|
|
|
+ reqconfig.otherOptions.limit = paginationConfig2.limit
|
|
|
}
|
|
|
|
|
|
// 查询时要根据是否开启分页查询传入对应参数
|
|
|
- getTableData(props.requestConfig.url, props.requestConfig.otherOptions, props.openPageQuery)
|
|
|
+ getTableData(reqconfig.url, reqconfig.otherOptions, props.openPageQuery)
|
|
|
.then(() => {
|
|
|
resolve(true)
|
|
|
})
|
|
|
@@ -169,7 +185,7 @@ const resetTableData = () => {
|
|
|
// 按条件查询
|
|
|
const queryTableData = () => {
|
|
|
if (props.requestConfig) {
|
|
|
- props.requestConfig.otherOptions = { ...props.requestConfig.otherOptions, ...queryFormData }
|
|
|
+ reqconfig.otherOptions = { ...reqconfig.otherOptions, ...queryFormData }
|
|
|
getData()
|
|
|
} else {
|
|
|
throw new Error('no match requestConfig')
|
|
|
@@ -233,17 +249,29 @@ const tableCellStyle = (info: any) => {
|
|
|
|
|
|
// 根据分页大小的切换来更新数据
|
|
|
// 这里将他赋值,用于根据传入的配置来选择是否开启该监听
|
|
|
+/**
|
|
|
+ * @description: 监听litmit,currentpage,gid的变化,改变后去重新请求数据
|
|
|
+ * 如果是limit的变化,则需要把当前页置为1
|
|
|
+ *
|
|
|
+ * 对于Gid需要去监听props的,而不是本地的,因为是外部的改变
|
|
|
+ * @return {*}
|
|
|
+ */
|
|
|
const changePageLimit = watch(
|
|
|
- () => [props.paginationConfig.limit, props.paginationConfig.currentPage],
|
|
|
- ([newLimit], [oldLimit]) => {
|
|
|
+ () => [
|
|
|
+ paginationConfig2.limit,
|
|
|
+ props.requestConfig?.otherOptions.gid,
|
|
|
+ paginationConfig2.currentPage
|
|
|
+ ],
|
|
|
+ ([newLimit, newGid], [oldLimit, oldGid]) => {
|
|
|
if (newLimit != oldLimit) {
|
|
|
// 需要给分页按钮加上:current-page.sync="current_page" 配置,不然不生效
|
|
|
// 当改变每页大小时把之前的缓存全部清除,重新开始
|
|
|
- props.paginationConfig.currentPage = 1
|
|
|
- resetTableData()
|
|
|
- getData()
|
|
|
- } else if (!tableData[props.paginationConfig.currentPage]) {
|
|
|
- // 当对应的数组下标位置没有这页的数据的时候再去请求
|
|
|
+ paginationConfig2.currentPage = 1
|
|
|
+ // resetTableData()
|
|
|
+ }
|
|
|
+ if (newGid != oldGid) reqconfig.otherOptions.gid = newGid
|
|
|
+ console.log('gidchange', newGid, oldGid)
|
|
|
+ if (newLimit != oldLimit || !tableData[paginationConfig2.currentPage] || newGid != oldGid) {
|
|
|
getData()
|
|
|
}
|
|
|
},
|
|
|
@@ -261,16 +289,13 @@ const changeDataList = watch(
|
|
|
}
|
|
|
)
|
|
|
|
|
|
-// 监听gid的变化
|
|
|
-const changeGid = watch(
|
|
|
- () => props.requestConfig?.otherOptions.gid,
|
|
|
- () => {
|
|
|
- getData()
|
|
|
- }
|
|
|
-)
|
|
|
-
|
|
|
-// 没有传入请求配置就关掉这个监听
|
|
|
-if (!props.requestConfig) changeGid()
|
|
|
+/**
|
|
|
+ * @description: 创建row-key优化表格性能
|
|
|
+ * @return {*}
|
|
|
+ */
|
|
|
+const createRowKey = () => {
|
|
|
+ return `${Date.now()}-${Math.random().toString(36).substr(2, 9)}`
|
|
|
+}
|
|
|
|
|
|
// 没传入datalist则取消该监听
|
|
|
if (!props.dataList) {
|
|
|
@@ -278,7 +303,17 @@ if (!props.dataList) {
|
|
|
}
|
|
|
|
|
|
// 没有开启分页查询就关闭掉这个监听
|
|
|
-if (!props.openPageQuery) changePageLimit()
|
|
|
+if (!props.openPageQuery) {
|
|
|
+ changePageLimit()
|
|
|
+}
|
|
|
+
|
|
|
+const initpageConfig = () => {
|
|
|
+ Object.assign(paginationConfig2, props.paginationConfig)
|
|
|
+}
|
|
|
+
|
|
|
+const initReqConfig = () => {
|
|
|
+ Object.assign(reqconfig, props.requestConfig)
|
|
|
+}
|
|
|
|
|
|
// 定义暴露出去的方法
|
|
|
defineExpose({
|
|
|
@@ -287,10 +322,14 @@ defineExpose({
|
|
|
})
|
|
|
|
|
|
onMounted(() => {
|
|
|
+ initpageConfig()
|
|
|
+ initReqConfig()
|
|
|
if (props.loadingState !== undefined) {
|
|
|
loading.value = props.loadingState
|
|
|
}
|
|
|
- getData()
|
|
|
+ if (!props.openPageQuery) {
|
|
|
+ getData()
|
|
|
+ }
|
|
|
})
|
|
|
</script>
|
|
|
|
|
|
@@ -375,11 +414,12 @@ onMounted(() => {
|
|
|
<div class="tableBox">
|
|
|
<!-- 没有分页的时候需要重新计算一下data -->
|
|
|
<el-table
|
|
|
- :data="openPageQuery ? tableData[paginationConfig.currentPage] : tableDataNoPaging"
|
|
|
+ :data="openPageQuery ? tableData[paginationConfig2.currentPage] : tableDataNoPaging"
|
|
|
style="width: 100%"
|
|
|
class="tableBody"
|
|
|
:cell-style="tableCellStyle"
|
|
|
v-loading="loading"
|
|
|
+ :row-key="createRowKey()"
|
|
|
>
|
|
|
<!-- 这里还有问题,需要计算一下 -->
|
|
|
<el-table-column
|
|
|
@@ -406,8 +446,8 @@ onMounted(() => {
|
|
|
>
|
|
|
{{
|
|
|
scope.row[item.name]
|
|
|
- ? item.specialEffect.othnerInfo[0]
|
|
|
- : item.specialEffect.othnerInfo[1]
|
|
|
+ ? item.specialEffect.othnerInfo.text[0]
|
|
|
+ : item.specialEffect.othnerInfo.text[1]
|
|
|
}}
|
|
|
</el-tag>
|
|
|
|
|
|
@@ -430,18 +470,23 @@ onMounted(() => {
|
|
|
<!-- 文字类 -->
|
|
|
<el-text
|
|
|
v-else-if="item.specialEffect?.type === FieldSpecialEffectType.TEXT"
|
|
|
- :type="scope.row[item.name] ? 'danger' : 'success'"
|
|
|
+ :type="
|
|
|
+ scope.row[item.name]
|
|
|
+ ? item.specialEffect.othnerInfo.color[0]
|
|
|
+ : item.specialEffect.othnerInfo.color[1]
|
|
|
+ "
|
|
|
>
|
|
|
{{ scope.row[item.name] }}
|
|
|
</el-text>
|
|
|
|
|
|
<!-- 翻译类 -->
|
|
|
<el-text v-else-if="item.specialEffect?.type === FieldSpecialEffectType.TRANSLATE">
|
|
|
- {{ item.specialEffect.othnerInfo[scope.row[item.name]] }}
|
|
|
+ {{ item.specialEffect.othnerInfo.translateText[scope.row[item.name]] }}
|
|
|
</el-text>
|
|
|
|
|
|
<el-text v-else>
|
|
|
<!-- 其他列按默认方式显示 -->
|
|
|
+
|
|
|
{{
|
|
|
props.needAverage &&
|
|
|
scope.row[item.name] !== undefined &&
|
|
|
@@ -461,12 +506,12 @@ onMounted(() => {
|
|
|
<el-pagination
|
|
|
class="userTablePagination"
|
|
|
background
|
|
|
- :page-size="paginationConfig.limit"
|
|
|
- :page-sizes="paginationConfig.pagesizeList"
|
|
|
+ :page-size="paginationConfig2.limit"
|
|
|
+ :page-sizes="paginationConfig2.pagesizeList"
|
|
|
table-layout="fixed"
|
|
|
layout="prev, pager, next ,jumper ,sizes,total,"
|
|
|
- :total="paginationConfig.total"
|
|
|
- :current-page.sync="paginationConfig.currentPage"
|
|
|
+ :total="paginationConfig2.total"
|
|
|
+ :current-page.sync="paginationConfig2.currentPage"
|
|
|
@current-change="handleCurrentChange"
|
|
|
@size-change="handleSizeChange"
|
|
|
/>
|