|
@@ -2,7 +2,7 @@
|
|
|
* @Author: fxs bjnsfxs@163.com
|
|
|
* @Date: 2024-09-02 17:57:15
|
|
|
* @LastEditors: fxs bjnsfxs@163.com
|
|
|
- * @LastEditTime: 2024-09-09 17:58:41
|
|
|
+ * @LastEditTime: 2024-09-12 15:05:20
|
|
|
* @FilePath: \Game-Backstage-Management-System\src\views\AppManage\EventManageView.vue
|
|
|
* @Description:
|
|
|
*
|
|
@@ -10,10 +10,33 @@
|
|
|
<script setup lang="ts">
|
|
|
import HeaderCard from '@/components/dataAnalysis/HeaderCard.vue'
|
|
|
import { shouldListenToEvent } from '@/utils/table/table'
|
|
|
-import { onMounted, ref } from 'vue'
|
|
|
+import { onMounted, ref, reactive, toRaw } from 'vue'
|
|
|
+import { ElMessage } from 'element-plus'
|
|
|
+import FileUpload from '@/components/form/FileUpload.vue'
|
|
|
+import axiosInstance from '@/utils/axios/axiosInstance'
|
|
|
+import { useRequest } from '@/hooks/useRequest'
|
|
|
+import { useCommonStore } from '@/stores/useCommon'
|
|
|
+import { downLoadData } from '@/utils/table/table'
|
|
|
+import { resetTimeToMidnight } from '@/utils/common'
|
|
|
|
|
|
+const { selectInfo } = useCommonStore()
|
|
|
+
|
|
|
+const { AllApi } = useRequest()
|
|
|
+
|
|
|
+// 头部ref
|
|
|
const headerCard = ref<typeof HeaderCard>()
|
|
|
|
|
|
+// 上传ref
|
|
|
+const uploadRef = ref<InstanceType<typeof FileUpload> | null>(null)
|
|
|
+
|
|
|
+// 上传的信息
|
|
|
+const uploadInfo = reactive({
|
|
|
+ dialogTitle: '上传事件信息'
|
|
|
+})
|
|
|
+
|
|
|
+// 现在所有的选项列表
|
|
|
+// const nowOptionList: Array<any> = []
|
|
|
+
|
|
|
/**
|
|
|
* @description: 进入详情页,触发headercard的添加事件,增加一个面包屑导航
|
|
|
* @param {*} info 传入的信息
|
|
@@ -24,6 +47,247 @@ const headerAddPath = (info: any) => {
|
|
|
headerCard.value?.addPath(name, pathName)
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ * @description: 提交所有新上传的事件及选项请求
|
|
|
+ * @param {*} reqList 请求列表
|
|
|
+ * @return {*}
|
|
|
+ */
|
|
|
+const submitUpload = async (reqList: Array<Promise<boolean>>) => {
|
|
|
+ await Promise.allSettled(reqList).then((res) => {
|
|
|
+ if (
|
|
|
+ res.every((item) => {
|
|
|
+ console.log(item)
|
|
|
+ return item.status === 'fulfilled' && item.value === true
|
|
|
+ })
|
|
|
+ ) {
|
|
|
+ ElMessage.success('上传成功')
|
|
|
+ } else {
|
|
|
+ ElMessage.error('部分上传失败,请检查参数')
|
|
|
+ }
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * @description: 请求表格数据,如果一次请求没有拿到所有的数据,则再请求一次
|
|
|
+ * @param {*} url 请求地址
|
|
|
+ * @param {*} otherInfo 请求参数
|
|
|
+ * @param {*} offset 偏移量
|
|
|
+ * @param {*} limit 请求数量
|
|
|
+ * @return {*}
|
|
|
+ */
|
|
|
+const getTableData = async (
|
|
|
+ url: string,
|
|
|
+ otherInfo: any,
|
|
|
+ offset = 0,
|
|
|
+ limit = 10000
|
|
|
+): Promise<Array<any>> => {
|
|
|
+ let total = limit + offset // 目前请求到的总数
|
|
|
+ let finalResult = []
|
|
|
+ finalResult = await axiosInstance
|
|
|
+ .post(url, {
|
|
|
+ offset,
|
|
|
+ limit,
|
|
|
+ ...otherInfo
|
|
|
+ })
|
|
|
+ .then(async (res) => {
|
|
|
+ let resData = JSON.parse(JSON.stringify(res))
|
|
|
+ let result = []
|
|
|
+ if (!resData.data) return []
|
|
|
+ // nowOptionList.push(...resData.data)
|
|
|
+ if (resData.count > total) {
|
|
|
+ result = await getTableData(url, otherInfo, total, limit)
|
|
|
+ }
|
|
|
+ return [...resData.data, ...result]
|
|
|
+ })
|
|
|
+ .catch((err) => {
|
|
|
+ console.log(err)
|
|
|
+ return []
|
|
|
+ })
|
|
|
+ return finalResult
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * @description: 批量请求
|
|
|
+ * @param {*} url 请求地址
|
|
|
+ * @param {*} reqParams 请求参数列表
|
|
|
+ * @return {*}
|
|
|
+ */
|
|
|
+const batReqOptionsData = async (
|
|
|
+ url: string,
|
|
|
+ reqParams: Array<any>,
|
|
|
+ eventTable: Array<any>
|
|
|
+): Promise<Object> => {
|
|
|
+ let reqList: Array<Promise<any>> = []
|
|
|
+ let finalResult: {
|
|
|
+ [key: string]: Array<any>
|
|
|
+ } = {}
|
|
|
+
|
|
|
+ reqParams.map((item) => {
|
|
|
+ reqList.push(
|
|
|
+ getTableData(url, item)
|
|
|
+ .then((res) => {
|
|
|
+ let actionId = eventTable.find((i) => i.id === item.actionId).actionId
|
|
|
+ finalResult[actionId] = res
|
|
|
+ })
|
|
|
+ .catch((err) => {
|
|
|
+ console.log(err)
|
|
|
+ })
|
|
|
+ )
|
|
|
+ })
|
|
|
+ await Promise.all(reqList)
|
|
|
+ return finalResult
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * @description: 拿到事件数据和选项数据
|
|
|
+ * @param {*} needTable 需要拿到哪些数据,默认是all,即所有数据。'event'表示只拿事件数据,'option'表示只拿选项数据
|
|
|
+ * @return {*} 返回事件数据和选项数据
|
|
|
+ */
|
|
|
+const getAllTable = async (): Promise<{ allEventTable: Array<any>; allOptionsInfo: any }> => {
|
|
|
+ let allEventTable = await getTableData(AllApi.gameActionList, { gid: selectInfo.gid })
|
|
|
+ let optionReqList = allEventTable.map((item) => {
|
|
|
+ return { actionId: parseInt(item.id) }
|
|
|
+ })
|
|
|
+ let allOptionsInfo = await batReqOptionsData(
|
|
|
+ AllApi.gameActionOptionList,
|
|
|
+ optionReqList,
|
|
|
+ allEventTable
|
|
|
+ )
|
|
|
+ return { allEventTable, allOptionsInfo }
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * @description: 开始上传
|
|
|
+ * @param{Array<any>} tableData 表格数据
|
|
|
+ * @return {*}
|
|
|
+ */
|
|
|
+const startUpload = async () => {
|
|
|
+ if (uploadRef.value) {
|
|
|
+ uploadRef.value.startUpload()
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * @description: 开始下载
|
|
|
+ * @return {*}
|
|
|
+ */
|
|
|
+const startDownload = async () => {
|
|
|
+ let { allEventTable, allOptionsInfo } = await getAllTable()
|
|
|
+ downLoadData(`allevents_${resetTimeToMidnight(new Date())}`, {
|
|
|
+ allEventTable,
|
|
|
+ allOptionsInfo
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+// 上传选项的时候,选项的键要设置为actionid
|
|
|
+// 需要先上传事件,然后上传完了,用上传的选项中的第一个(如果有)的actionid去找到对应的事件的ID(不是actionid),然后作为选项上传的id
|
|
|
+
|
|
|
+const uploadSuccess2 = async (data: any) => {
|
|
|
+ let uploadEventTable = data.allEventTable
|
|
|
+ let uploadOptionsInfo = data.allOptionsInfo
|
|
|
+
|
|
|
+ // 上传的事件列表有值,则开始上传
|
|
|
+ let { allEventTable, allOptionsInfo } = await getAllTable() // 获取所有事件列表和选项列表
|
|
|
+ // console.log(allEventTable, allOptionsInfo, uploadOptionsInfo)
|
|
|
+ let newEventKeys: Array<any> = [] // 拿到所有需要新上传的事件
|
|
|
+ Object.keys(uploadOptionsInfo).map((item) => {
|
|
|
+ if (allEventTable.every((i) => i.actionId !== item)) {
|
|
|
+ newEventKeys.push(item)
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+ // 1、新事件、新选项
|
|
|
+ // 2、旧事件、新选项 + 旧选项
|
|
|
+
|
|
|
+ let eventReqList: Array<Promise<boolean>> = []
|
|
|
+ let eventReqUrl = AllApi.setGameAction
|
|
|
+ if (Array.isArray(uploadEventTable) && uploadEventTable.length) {
|
|
|
+ uploadEventTable.map((item) => {
|
|
|
+ let { id, createdAt, updatedAt, ...otherInfo } = item
|
|
|
+ if (allEventTable.some((i) => i.actionId === item.actionId)) {
|
|
|
+ eventReqUrl = AllApi.updateGameAction
|
|
|
+ console.log('更新一个事件', item)
|
|
|
+ } else {
|
|
|
+ eventReqUrl = AllApi.setGameAction
|
|
|
+ console.log('新增一个事件', item)
|
|
|
+ }
|
|
|
+ let eventReq = axiosInstance
|
|
|
+ .post(eventReqUrl, otherInfo)
|
|
|
+ .then((res: any) => {
|
|
|
+ if (res.code === 0) return true
|
|
|
+ return false
|
|
|
+ })
|
|
|
+ .catch((err) => {
|
|
|
+ console.log(err)
|
|
|
+ return false
|
|
|
+ })
|
|
|
+ eventReqList.push(eventReq)
|
|
|
+ })
|
|
|
+ await submitUpload(eventReqList)
|
|
|
+ }
|
|
|
+ ;({ allEventTable, allOptionsInfo } = await getAllTable()) // 获取所有事件列表和选项列表
|
|
|
+ let optionsReqList: Array<Promise<boolean>> = []
|
|
|
+ // console.log(allEventTable)
|
|
|
+
|
|
|
+ allEventTable.map((item) => {
|
|
|
+ let uploadOptionItem = uploadOptionsInfo[item.actionId] as Array<any> // 找到所有在已有事件列表中的选项列表
|
|
|
+ let nowOptionItem = allOptionsInfo[item.actionId] as Array<any> // 找到所有在已有事件列表中的选项列表
|
|
|
+
|
|
|
+ if (uploadOptionItem) {
|
|
|
+ uploadOptionItem.map((i) => {
|
|
|
+ let optionReqUrl = AllApi.addGameActionOption // 选项上传的url
|
|
|
+ let { id, actionId, createdAt, updatedAt, ...otherInfo } = i // 上传参数拆分出来
|
|
|
+ let reqParams = {}
|
|
|
+ if (newEventKeys.find((k) => k === item.actionId)) {
|
|
|
+ // 是新增的事件的选项
|
|
|
+ console.log('全新增')
|
|
|
+ actionId = item.id
|
|
|
+ console.log(actionId)
|
|
|
+ optionReqUrl = AllApi.addGameActionOption
|
|
|
+ reqParams = { actionId, ...otherInfo }
|
|
|
+ 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)
|
|
|
+ } else {
|
|
|
+ // 是已有事件的选项
|
|
|
+ // 分出来哪些是新增加的选项,哪些是需要更新的选项
|
|
|
+ if (nowOptionItem.some((k) => k.id === i.id)) {
|
|
|
+ reqParams = { id, ...otherInfo }
|
|
|
+
|
|
|
+ optionReqUrl = AllApi.updateGameActionOption
|
|
|
+ console.log('更新一个选项', i)
|
|
|
+ } else {
|
|
|
+ actionId = item.id
|
|
|
+ reqParams = { actionId, ...otherInfo }
|
|
|
+ optionReqUrl = AllApi.addGameActionOption
|
|
|
+ console.log('新增一个选项', i)
|
|
|
+ }
|
|
|
+ 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)
|
|
|
+}
|
|
|
+
|
|
|
onMounted(() => {})
|
|
|
</script>
|
|
|
|
|
@@ -37,6 +301,12 @@ onMounted(() => {})
|
|
|
:need-pf-select="false"
|
|
|
></HeaderCard>
|
|
|
</div>
|
|
|
+ <div class="handleEvent">
|
|
|
+ <div class="fileGroup">
|
|
|
+ <el-button class="fileBtn" color="#626aef" @click="startUpload">上传</el-button>
|
|
|
+ <el-button class="fileBtn" @click="startDownload">下载</el-button>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
<div class="eventTableBox">
|
|
|
<!-- 监听表格的跳转事件 -->
|
|
|
<router-view v-slot="{ Component, route }">
|
|
@@ -53,6 +323,13 @@ onMounted(() => {})
|
|
|
<component v-if="route.name !== 'EventTable'" :is="Component" />
|
|
|
</router-view>
|
|
|
</div>
|
|
|
+ <div class="uploadFileBox">
|
|
|
+ <FileUpload
|
|
|
+ @upload-success="uploadSuccess2"
|
|
|
+ ref="uploadRef"
|
|
|
+ :title="uploadInfo.dialogTitle"
|
|
|
+ ></FileUpload>
|
|
|
+ </div>
|
|
|
</div>
|
|
|
</template>
|
|
|
|
|
@@ -79,4 +356,32 @@ onMounted(() => {})
|
|
|
box-sizing: border-box;
|
|
|
padding: 0px 24px;
|
|
|
}
|
|
|
+
|
|
|
+.handleEvent {
|
|
|
+ width: 100%;
|
|
|
+ background-color: white;
|
|
|
+ box-sizing: border-box;
|
|
|
+ height: 48px;
|
|
|
+ padding: 0 24px;
|
|
|
+ font-size: 16px;
|
|
|
+ font-weight: 600;
|
|
|
+ position: relative;
|
|
|
+ display: flex;
|
|
|
+ align-items: center;
|
|
|
+ /* justify-content: flex-end; */
|
|
|
+}
|
|
|
+
|
|
|
+.fileGroup {
|
|
|
+ position: absolute;
|
|
|
+ right: 5%;
|
|
|
+ width: 12%;
|
|
|
+ box-sizing: border-box;
|
|
|
+ display: flex;
|
|
|
+ justify-content: space-around;
|
|
|
+}
|
|
|
+
|
|
|
+.fileBtn {
|
|
|
+ /* color: white; */
|
|
|
+ /* margin-left: 50px; */
|
|
|
+}
|
|
|
</style>
|