|
@@ -2,7 +2,7 @@
|
|
|
* @Author: fxs bjnsfxs@163.com
|
|
|
* @Date: 2024-09-02 17:57:15
|
|
|
* @LastEditors: fxs bjnsfxs@163.com
|
|
|
- * @LastEditTime: 2024-10-10 15:40:15
|
|
|
+ * @LastEditTime: 2024-10-11 17:56:04
|
|
|
* @FilePath: \Game-Backstage-Management-System\src\views\AppManage\EventManageView.vue
|
|
|
* @Description:
|
|
|
*
|
|
@@ -61,30 +61,46 @@ const headerAddPath = (info: any) => {
|
|
|
* @param {*} msg 提示信息,用于展示上传之后返回的消息
|
|
|
* @return {*}
|
|
|
*/
|
|
|
-const submitUpload = async (reqList: Array<Promise<boolean>>, msg?: string) => {
|
|
|
- await Promise.allSettled(reqList).then((res) => {
|
|
|
- if (
|
|
|
- res.every((item) => {
|
|
|
- return item.status === 'fulfilled' && item.value === true
|
|
|
- })
|
|
|
- ) {
|
|
|
+const submitUpload = async (reqList: Array<Promise<boolean>>, msg?: string): Promise<boolean> => {
|
|
|
+ const result = await Promise.allSettled(reqList).then((res) => {
|
|
|
+ const failedList = res.filter((item: any) => item.value === false)
|
|
|
+ const failedCount = failedList.length
|
|
|
+ const totalCount = res.length
|
|
|
+ let state = true
|
|
|
+
|
|
|
+ if (failedCount === 0) {
|
|
|
+ // 全部成功
|
|
|
ElNotification({
|
|
|
type: 'success',
|
|
|
title: '上传完成',
|
|
|
- message: `${msg}上传成功`,
|
|
|
- position: 'top-left'
|
|
|
+ message: `${msg}全部上传成功`,
|
|
|
+ position: 'top-left',
|
|
|
+ duration: 3000
|
|
|
})
|
|
|
- } else {
|
|
|
+ } else if (failedCount === totalCount) {
|
|
|
+ // 全部失败
|
|
|
ElNotification({
|
|
|
type: 'error',
|
|
|
title: '上传完成',
|
|
|
- message: `${msg}部分上传失败,请检查参数`,
|
|
|
- duration: 3000,
|
|
|
+ message: `${msg}全部上传失败,请检查参数`,
|
|
|
+ duration: 5000,
|
|
|
position: 'top-left'
|
|
|
})
|
|
|
- // ElMessage.error()
|
|
|
+ state = false
|
|
|
+ } else {
|
|
|
+ // 部分失败
|
|
|
+ ElNotification({
|
|
|
+ type: 'warning',
|
|
|
+ title: '上传完成',
|
|
|
+ message: `${msg}部分上传成功`,
|
|
|
+ position: 'top-left',
|
|
|
+ duration: 5000
|
|
|
+ })
|
|
|
}
|
|
|
+ return state
|
|
|
})
|
|
|
+
|
|
|
+ return result
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -110,14 +126,21 @@ const getTableData = async (
|
|
|
...otherInfo
|
|
|
})
|
|
|
.then(async (res) => {
|
|
|
+ let resultData: any = []
|
|
|
let resData = JSON.parse(JSON.stringify(res))
|
|
|
let result = []
|
|
|
- if (!resData.data) return []
|
|
|
- // nowOptionList.push(...resData.data)
|
|
|
- if (resData.count > total) {
|
|
|
+ // if (!resData.data) return []
|
|
|
+ // // nowOptionList.push(...resData.data)
|
|
|
+ // if (resData.count > total) {
|
|
|
+ // result = await getTableData(url, otherInfo, total, limit)
|
|
|
+ // }
|
|
|
+ if (resData.data && resData.count > total) {
|
|
|
result = await getTableData(url, otherInfo, total, limit)
|
|
|
+ resultData = [...resData.data, ...result]
|
|
|
}
|
|
|
- return [...resData.data, ...result]
|
|
|
+
|
|
|
+ return resultData
|
|
|
+ // return [...resData.data, ...result]
|
|
|
})
|
|
|
.catch((err) => {
|
|
|
console.log(err)
|
|
@@ -176,11 +199,13 @@ const getAllTable = async <T extends 'all' | 'event' | 'option' = 'all'>(
|
|
|
): Promise<GetTableReturn<T>> => {
|
|
|
let allEventTable: Array<any> = [],
|
|
|
allOptionsInfo: any = null
|
|
|
+ allEventTable = await getTableData(AllApi.gameActionList, { gid: selectInfo.gid })
|
|
|
+ // 只需要事件列表在这里就返回
|
|
|
if (table === 'event') {
|
|
|
- allEventTable = await getTableData(AllApi.gameActionList, { gid: selectInfo.gid })
|
|
|
return { allEventTable } as GetTableReturn<T>
|
|
|
}
|
|
|
|
|
|
+ // 只需要选项在这里就只返回选项
|
|
|
if (table === 'option') {
|
|
|
let optionReqList = allEventTable.map((item) => {
|
|
|
return { actionId: parseInt(item.id) }
|
|
@@ -240,6 +265,8 @@ const uploadSuccess = async (data: any) => {
|
|
|
// 开始上传事件
|
|
|
let eventReqList: Array<Promise<boolean>> = []
|
|
|
let eventReqUrl = AllApi.setGameAction
|
|
|
+ let eventUploadResult = false
|
|
|
+
|
|
|
if (Array.isArray(uploadEventTable) && uploadEventTable.length) {
|
|
|
// 将新事件和旧事件区分,对于新事件走新增,对于旧事件走更新
|
|
|
uploadEventTable.map((item) => {
|
|
@@ -252,8 +279,7 @@ const uploadSuccess = async (data: any) => {
|
|
|
let eventReq = axiosInstance
|
|
|
.post(eventReqUrl, otherInfo)
|
|
|
.then((res: any) => {
|
|
|
- if (res.code === 0) return true
|
|
|
- return false
|
|
|
+ return res.code === 0
|
|
|
})
|
|
|
.catch((err) => {
|
|
|
console.log(err)
|
|
@@ -261,51 +287,74 @@ const uploadSuccess = async (data: any) => {
|
|
|
})
|
|
|
eventReqList.push(eventReq) // 统一放入请求列表中
|
|
|
})
|
|
|
- await submitUpload(eventReqList, '事件') // 等待所有的事件请求完成
|
|
|
- }
|
|
|
- ;({ allEventTable, allOptionsInfo } = await getAllTable()) // 重新获取所有事件列表和选项列表
|
|
|
- let optionsReqList: Array<Promise<boolean>> = []
|
|
|
-
|
|
|
- allEventTable.map((item) => {
|
|
|
- // 在上传的事件列表中,找到有对应的事件的actionid的那一组数据
|
|
|
- let uploadOptionItem = uploadOptionsInfo[item.actionId] as Array<any>
|
|
|
- // 在现有的事件列表中,找到对应事件的actionid的那一组数据
|
|
|
- let nowOptionItem = allOptionsInfo[item.actionId] as Array<any> // 找到所有在已有事件列表中的选项列表
|
|
|
-
|
|
|
- // 如果有已存在的事件,并且上传的选项列表中也有对应的actionid,则开始上传
|
|
|
- if (uploadOptionItem) {
|
|
|
- // 对找到的那一组数据进行循环,区分出来哪些是已有的,哪些是新上传的
|
|
|
- // 新上传的需要给他加上actionid,然后上传,这个actionid其实是事件列表的id字段
|
|
|
- uploadOptionItem.map((i) => {
|
|
|
- let optionReqUrl = AllApi.addGameActionOption // 选项上传的url
|
|
|
- let { id, actionId, createdAt, updatedAt, ...otherInfo } = i // 上传参数拆分出来
|
|
|
- let reqParams = {}
|
|
|
- // 分出来哪些是新增加的选项,哪些是需要更新的选项
|
|
|
- // 新增的选项需要加入的是事件列表的主键,而更新中需要加入的是option的id
|
|
|
- if (nowOptionItem.some((k) => k.id === i.id)) {
|
|
|
- reqParams = { id, ...otherInfo }
|
|
|
-
|
|
|
- optionReqUrl = AllApi.updateGameActionOption
|
|
|
- } else {
|
|
|
- actionId = item.id
|
|
|
- reqParams = { actionId, ...otherInfo }
|
|
|
- optionReqUrl = AllApi.addGameActionOption
|
|
|
- }
|
|
|
- let optionReq = axiosInstance
|
|
|
- .post(optionReqUrl, reqParams)
|
|
|
- .then((res: any) => {
|
|
|
- if (res.code === 0) return true
|
|
|
- return false
|
|
|
- })
|
|
|
- .catch((err) => {
|
|
|
- console.log(err)
|
|
|
- return false
|
|
|
- })
|
|
|
- optionsReqList.push(optionReq)
|
|
|
- })
|
|
|
+
|
|
|
+ eventUploadResult = await submitUpload(eventReqList, '事件') // 等待所有的事件请求完成
|
|
|
+ // 如果事件上传全部失败,那么就不要再上传选项了
|
|
|
+ if (eventUploadResult) {
|
|
|
+ ;({ allEventTable, allOptionsInfo } = await getAllTable()) // 重新获取所有事件列表和选项列表
|
|
|
+ let optionsReqList: Array<Promise<boolean>> = []
|
|
|
+ if (uploadOptionsInfo) {
|
|
|
+ // 开始上传选项
|
|
|
+ allEventTable.map((item) => {
|
|
|
+ // 在上传的事件列表中,找到有对应的事件的actionid的那一组数据
|
|
|
+ let uploadOptionItem = uploadOptionsInfo[item.actionId] as Array<any>
|
|
|
+ // 在现有的事件列表中,找到对应事件的actionid的那一组数据
|
|
|
+ let nowOptionItem = allOptionsInfo[item.actionId] as Array<any> // 找到所有在已有事件列表中的选项列表
|
|
|
+
|
|
|
+ // 如果有已存在的事件,并且上传的选项列表中也有对应的actionid,则开始上传
|
|
|
+ if (uploadOptionItem) {
|
|
|
+ // 对找到的那一组数据进行循环,区分出来哪些是已有的,哪些是新上传的
|
|
|
+ // 新上传的需要给他加上actionid,然后上传,这个actionid其实是事件列表的id字段
|
|
|
+ uploadOptionItem.map((i) => {
|
|
|
+ let optionReqUrl = AllApi.addGameActionOption // 选项上传的url
|
|
|
+ let { id, actionId, createdAt, updatedAt, ...otherInfo } = i // 上传参数拆分出来
|
|
|
+ let reqParams = {}
|
|
|
+ // 分出来哪些是新增加的选项,哪些是需要更新的选项
|
|
|
+ // 新增的选项需要加入的是事件列表的主键,而更新中需要加入的是option的id
|
|
|
+ if (nowOptionItem.some((k) => k.id === i.id)) {
|
|
|
+ reqParams = { id, ...otherInfo }
|
|
|
+
|
|
|
+ optionReqUrl = AllApi.updateGameActionOption
|
|
|
+ } else {
|
|
|
+ actionId = item.id
|
|
|
+ reqParams = { actionId, ...otherInfo }
|
|
|
+ optionReqUrl = AllApi.addGameActionOption
|
|
|
+ }
|
|
|
+ let optionReq = axiosInstance
|
|
|
+ .post(optionReqUrl, reqParams)
|
|
|
+ .then((res: any) => {
|
|
|
+ if (res.code === 0) return true
|
|
|
+ return false
|
|
|
+ })
|
|
|
+ .catch((err) => {
|
|
|
+ console.log(err)
|
|
|
+ return false
|
|
|
+ })
|
|
|
+ optionsReqList.push(optionReq)
|
|
|
+ })
|
|
|
+ }
|
|
|
+ })
|
|
|
+ await submitUpload(optionsReqList, '选项') // 等待所有选项上传完成
|
|
|
+ } else {
|
|
|
+ ElNotification({
|
|
|
+ type: 'warning',
|
|
|
+ title: '没有选项参数',
|
|
|
+ message: `上传选项为空`,
|
|
|
+ position: 'top-left',
|
|
|
+ duration: 5000
|
|
|
+ })
|
|
|
+ }
|
|
|
}
|
|
|
- })
|
|
|
- await submitUpload(optionsReqList, '选项') // 等待所有选项上传完成
|
|
|
+ } else {
|
|
|
+ ElNotification({
|
|
|
+ type: 'error',
|
|
|
+ title: '上传参数有误',
|
|
|
+ message: `上传参数为空,请检查参数`,
|
|
|
+ position: 'top-left',
|
|
|
+ duration: 5000
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
uploadRef.value?.uploadCallback()
|
|
|
eventTableRef.value?.updateData()
|
|
|
}
|