|
@@ -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-09-13 18:07:38
|
|
|
|
|
|
+ * @LastEditTime: 2024-09-18 12:00:45
|
|
* @FilePath: \Game-Backstage-Management-System\src\components\Table.vue
|
|
* @FilePath: \Game-Backstage-Management-System\src\components\Table.vue
|
|
* @Description:
|
|
* @Description:
|
|
*
|
|
*
|
|
@@ -23,7 +23,6 @@ import { useRequest } from '@/hooks/useRequest'
|
|
|
|
|
|
import type { FormInstance } from 'element-plus'
|
|
import type { FormInstance } from 'element-plus'
|
|
import axiosInstance from '@/utils/axios/axiosInstance'
|
|
import axiosInstance from '@/utils/axios/axiosInstance'
|
|
-import { clearReactiveData } from '@/utils/common'
|
|
|
|
|
|
|
|
const { analysisResCode } = useRequest()
|
|
const { analysisResCode } = useRequest()
|
|
|
|
|
|
@@ -46,7 +45,8 @@ const props = withDefaults(defineProps<PropsParams>(), {
|
|
})
|
|
})
|
|
|
|
|
|
// 父组件触发的方法
|
|
// 父组件触发的方法
|
|
-const emits = defineEmits(['addNewItem', 'upload', 'downLoad', 'loadSuccess'])
|
|
|
|
|
|
+// 删除了一个事件触发,loadSuccess
|
|
|
|
+const emits = defineEmits(['addNewItem', 'upload', 'downLoad'])
|
|
|
|
|
|
// 加载动画
|
|
// 加载动画
|
|
const loading = ref(false)
|
|
const loading = ref(false)
|
|
@@ -60,6 +60,8 @@ const backupTableData: Array<any> = []
|
|
// 查询表单的数据
|
|
// 查询表单的数据
|
|
const queryFormData = reactive<{ [key: string]: any }>({})
|
|
const queryFormData = reactive<{ [key: string]: any }>({})
|
|
|
|
|
|
|
|
+const backupQueryFormData = reactive<{ [key: string]: any }>({})
|
|
|
|
+
|
|
// 分页数据
|
|
// 分页数据
|
|
const paginationConfig2 = reactive<TablePaginationSetting>({
|
|
const paginationConfig2 = reactive<TablePaginationSetting>({
|
|
currentPage: 0,
|
|
currentPage: 0,
|
|
@@ -132,79 +134,104 @@ const handleSizeChange = (val: number) => {
|
|
* @return {*}
|
|
* @return {*}
|
|
*/
|
|
*/
|
|
const getData = () => {
|
|
const getData = () => {
|
|
- return new Promise((resolve, reject) => {
|
|
|
|
- if (props.dataList) {
|
|
|
|
- tableData.splice(0, tableData.length, ...props.dataList)
|
|
|
|
- paginationConfig2.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 =
|
|
|
|
- (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(() => {
|
|
|
|
|
|
+ return new Promise(async (resolve, reject) => {
|
|
|
|
+ try {
|
|
|
|
+ Object.assign(queryFormData, JSON.parse(JSON.stringify(backupQueryFormData)))
|
|
|
|
+ const loadTableData = async () => {
|
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
|
+ if (props.dataList) {
|
|
|
|
+ tableData.splice(0, tableData.length, ...props.dataList)
|
|
|
|
+
|
|
|
|
+ paginationConfig2.total = props.paginationConfig.total
|
|
loading.value = false
|
|
loading.value = false
|
|
- })
|
|
|
|
- } else {
|
|
|
|
- loading.value = false
|
|
|
|
|
|
+ // emits('loadSuccess', tableData)
|
|
|
|
|
|
- throw new Error('no match requestConfig')
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (tableData.length) {
|
|
|
|
- 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)
|
|
|
|
|
|
+ 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')
|
|
|
|
+ }
|
|
}
|
|
}
|
|
})
|
|
})
|
|
- insertRow(0, rowData)
|
|
|
|
}
|
|
}
|
|
|
|
+ // 等待数据加载完成
|
|
|
|
+ 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)
|
|
|
|
+ }
|
|
|
|
+ resolve(true)
|
|
|
|
+ })
|
|
|
|
+ .catch((err) => {
|
|
|
|
+ console.log(err)
|
|
|
|
+ reject(err)
|
|
|
|
+ })
|
|
|
|
+ } catch (err) {
|
|
|
|
+ console.log(err)
|
|
|
|
+ reject(err)
|
|
}
|
|
}
|
|
})
|
|
})
|
|
}
|
|
}
|
|
|
|
|
|
-// 清空表格数据
|
|
|
|
|
|
+/**
|
|
|
|
+ * @description: 清空表格数据
|
|
|
|
+ * @return {*}
|
|
|
|
+ */
|
|
const resetTableData = () => {
|
|
const resetTableData = () => {
|
|
tableData.splice(0, tableData.length)
|
|
tableData.splice(0, tableData.length)
|
|
}
|
|
}
|
|
|
|
|
|
-// 按条件查询
|
|
|
|
|
|
+/**
|
|
|
|
+ * @description: 按条件查询,如果开启了分页查询,那么会直接重新查询数据,否则,会根据现有数据进行查询
|
|
|
|
+ * @return {*}
|
|
|
|
+ */
|
|
const queryTableData = () => {
|
|
const queryTableData = () => {
|
|
if (props.requestConfig) {
|
|
if (props.requestConfig) {
|
|
reqconfig.otherOptions = { ...props.requestConfig.otherOptions, ...queryFormData }
|
|
reqconfig.otherOptions = { ...props.requestConfig.otherOptions, ...queryFormData }
|
|
@@ -212,9 +239,11 @@ const queryTableData = () => {
|
|
if (props.openPageQuery) getData()
|
|
if (props.openPageQuery) getData()
|
|
else {
|
|
else {
|
|
let filteredTable = []
|
|
let filteredTable = []
|
|
|
|
+ // 过滤出来所有符合formData数据的条件
|
|
filteredTable = backupTableData.filter((item) => {
|
|
filteredTable = backupTableData.filter((item) => {
|
|
let state = true
|
|
let state = true
|
|
for (let [k, v] of Object.entries(queryFormData)) {
|
|
for (let [k, v] of Object.entries(queryFormData)) {
|
|
|
|
+ // 模糊查询,看值是否跟表格中的数据匹配
|
|
if (!fuzzySearch(v, item[k])) {
|
|
if (!fuzzySearch(v, item[k])) {
|
|
state = false
|
|
state = false
|
|
break
|
|
break
|
|
@@ -234,7 +263,9 @@ const queryTableData = () => {
|
|
*/
|
|
*/
|
|
const resetQueryForm = (formEl: FormInstance | undefined) => {
|
|
const resetQueryForm = (formEl: FormInstance | undefined) => {
|
|
if (!formEl) return
|
|
if (!formEl) return
|
|
- clearReactiveData(queryFormData)
|
|
|
|
|
|
+ // clearReactiveData(queryFormData)
|
|
|
|
+ // queryFormData
|
|
|
|
+ Object.assign(queryFormData, JSON.parse(JSON.stringify(backupQueryFormData)))
|
|
queryTableData()
|
|
queryTableData()
|
|
}
|
|
}
|
|
|
|
|
|
@@ -283,8 +314,6 @@ const tableCellStyle = (info: any) => {
|
|
} else return {}
|
|
} else return {}
|
|
}
|
|
}
|
|
|
|
|
|
-// 根据分页大小的切换来更新数据
|
|
|
|
-// 这里将他赋值,用于根据传入的配置来选择是否开启该监听
|
|
|
|
/**
|
|
/**
|
|
* @description: 监听litmit,currentpage的变化,改变后去重新请求数据
|
|
* @description: 监听litmit,currentpage的变化,改变后去重新请求数据
|
|
* 如果是limit的变化,则需要把当前页置为1
|
|
* 如果是limit的变化,则需要把当前页置为1
|
|
@@ -395,6 +424,8 @@ const initFormData = () => {
|
|
props.queryInfo?.map((item: any) => {
|
|
props.queryInfo?.map((item: any) => {
|
|
queryFormData[item.name] = item.default
|
|
queryFormData[item.name] = item.default
|
|
})
|
|
})
|
|
|
|
+ // backupQueryFormData = JSON.parse(JSON.stringify(queryFormData))
|
|
|
|
+ Object.assign(backupQueryFormData, JSON.parse(JSON.stringify(queryFormData)))
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -613,7 +644,8 @@ onMounted(() => {
|
|
: item.specialEffect.othnerInfo.text[1]
|
|
: item.specialEffect.othnerInfo.text[1]
|
|
}}
|
|
}}
|
|
</el-tag>
|
|
</el-tag>
|
|
-
|
|
|
|
|
|
+ <!-- :src="loadResource(scope.row[item.name])" -->
|
|
|
|
+ <!-- :src="scope.row[item.name]" -->
|
|
<!-- 头像类 -->
|
|
<!-- 头像类 -->
|
|
<el-image
|
|
<el-image
|
|
v-else-if="item.specialEffect?.type === FieldSpecialEffectType.IMG"
|
|
v-else-if="item.specialEffect?.type === FieldSpecialEffectType.IMG"
|