Browse Source

feat(事件管理): 新增复制功能、新增导入默认配置功能(未完成)

fxs 1 day ago
parent
commit
20d8b525a7
2 changed files with 144 additions and 1 deletions
  1. 2 0
      src/hooks/useRequest.ts
  2. 142 1
      src/views/AppManage/EventManageView.vue

+ 2 - 0
src/hooks/useRequest.ts

@@ -52,6 +52,7 @@ export function useRequest() {
     gameActionDetail: `/user/gameActionDetail`, // 事件详情
     updateGameAction: `/user/updateGameAction`, // 更新游戏事件
     setGameAction: `/user/setGameAction`, // 新增事件
+    copyActionConfig: `/user/copyGameAction`, // 复制事件
 
     // 事件参数
     gameActionOptionList: `/user/gameActionOptionList`, // 获取事件参数列表
@@ -81,6 +82,7 @@ export function useRequest() {
     fileUploadToTencent: `/file/localFileToService`, // 上传到腾讯云
     fileManageDeleteFile: `/file/fileDelete`, // 删除文件
     makeDir: `/file/createDir`, // 新建文件夹
+    downloadFolder: `/file/dirDownload`, // 下载文件夹
 
     // 成员管理
     memberList: `/admin/adminList`, // 成员列表

+ 142 - 1
src/views/AppManage/EventManageView.vue

@@ -8,7 +8,11 @@
  * 
 -->
 <script setup lang="ts">
+import CustomDialog from '@/components/common/CustomDialog.vue'
+import type { DialogConfig } from '@/types/dialog.ts'
+import { FormFieldType } from '@/types/form.ts'
 import type { ResponseInfo } from '@/types/res'
+import type { FormRules } from 'element-plus'
 
 import { computed, reactive, ref } from 'vue'
 import { useRequest } from '@/hooks/useRequest'
@@ -21,6 +25,8 @@ import router from '@/router'
 import FileUpload from '@/components/form/FileUpload.vue'
 import axiosInstance from '@/utils/axios/axiosInstance'
 
+type CustomDialogType = InstanceType<typeof CustomDialog>
+
 interface uploadEvent {
   id?: number // 更新需要传入id
   gid: string
@@ -72,7 +78,7 @@ type GetTableReturn<T> = T extends 'all'
       ? { allOptionsInfo: { [key: string]: Array<DownLoadOption> } }
       : never
 
-const { selectInfo } = useCommonStore()
+const { selectInfo, allGameInfo } = useCommonStore()
 
 const { AllApi } = useRequest()
 
@@ -93,6 +99,78 @@ const uploadInfo = reactive({
 // 现在的路由路径名称
 const nowRouteName = computed(() => router.currentRoute.value.name)
 
+// 对话框表单规则字段
+const dialogRuleForm = reactive({
+  gid: '',
+  newGid: ''
+})
+
+/**
+ * 验证新旧游戏不能相同
+ * @param _rule 规则
+ * @param value 值
+ * @param callback 回调
+ */
+const checkNewGid = (_rule: any, value: any, callback: any) => {
+  if (value === '') {
+    callback(new Error('目标游戏必选'))
+  } else if (value === copyConfigDialogRef.value?.getFormData().gid) {
+    callback(new Error('目标游戏不能与原游戏相同'))
+  } else {
+    callback()
+  }
+}
+
+// 对话表单规则
+const dialogRules = reactive<FormRules<typeof dialogRuleForm>>({
+  gid: [{ required: true, message: '原游戏必选', trigger: 'blur' }],
+  newGid: [
+    { required: true, message: '目标游戏必选', trigger: 'blur' },
+    { validator: checkNewGid, trigger: 'blur' }
+  ]
+})
+
+const copyConfigDialogRef = ref<CustomDialogType>()
+
+const gameOptions = allGameInfo.map((item) => {
+  return {
+    name: item.gid,
+    value: item.gid,
+    label: item.gameName
+  }
+})
+
+const configCopyInfo = ref<DialogConfig>({
+  title: '复制事件',
+  rules: dialogRules,
+  reqConfig: {
+    url: AllApi.copyActionConfig,
+    otherOptions: {}
+  },
+  fieldsInfo: [
+    {
+      name: 'gid',
+      cnName: '原游戏',
+      type: FormFieldType.SELECT,
+      defaultValue: selectInfo.gid,
+      otherOptions: {
+        options: gameOptions,
+        searchSelected: true
+      }
+    },
+    {
+      name: 'newGid',
+      cnName: '目标游戏',
+      type: FormFieldType.SELECT,
+
+      otherOptions: {
+        options: gameOptions,
+        searchSelected: true
+      }
+    }
+  ]
+})
+
 /**
  * 进入详情页,触发headerCard的添加事件,增加一个面包屑导航
  * @param {*} info 传入的信息
@@ -441,6 +519,28 @@ const uploadSuccess = async (data: {
   uploadRef.value?.uploadCallback()
   eventTableRef.value?.updateData()
 }
+
+const handleCopyConfig = () => {
+  copyConfigDialogRef.value?.addForm()
+}
+
+const defaultEventDialogVisible = ref(false)
+
+const events = [
+  { id: '1', name: '登录事件', enabled: true },
+  { id: '2', name: '注册事件', enabled: false }
+]
+
+const submitEventInfo = () => {
+  console.log(events.filter((item) => item.enabled))
+  const hasEmpty = events
+    .filter((item) => item.enabled)
+    .some((item) => item.id === '' || item.name === '')
+  if (hasEmpty) {
+    ElMessage.warning('请为所有启用事件填写完整信息')
+    return
+  }
+}
 </script>
 
 <template>
@@ -456,6 +556,11 @@ const uploadSuccess = async (data: {
 
     <div class="handleEvent" v-if="nowRouteName === 'EventTable'">
       <div class="fileGroup">
+        <el-button class="fileBtn" @click="handleCopyConfig">复制</el-button>
+        <!--        TODO 完善-->
+        <el-button class="fileBtn" @click="defaultEventDialogVisible = true" v-if="false"
+          >导入默认配置
+        </el-button>
         <el-button class="fileBtn" color="#626aef" @click="startUpload">上传</el-button>
         <el-button class="fileBtn" @click="throttleStartDownload">下载</el-button>
       </div>
@@ -485,6 +590,42 @@ const uploadSuccess = async (data: {
         :title="uploadInfo.dialogTitle"
       ></FileUpload>
     </div>
+    <div>
+      <CustomDialog ref="copyConfigDialogRef" :config="configCopyInfo"></CustomDialog>
+    </div>
+    <div>
+      <el-dialog v-model="defaultEventDialogVisible" title="事件配置">
+        <el-table :data="events" style="width: 100%" table-layout="auto">
+          <!-- 是否启用列 -->
+          <el-table-column prop="enabled" label="是否启用" align="center">
+            <template #default="{ row }">
+              <el-checkbox v-model="row.enabled" />
+            </template>
+          </el-table-column>
+
+          <!-- 事件ID列 -->
+          <el-table-column align="center" prop="id" label="事件ID">
+            <template #default="{ row }">
+              <el-input v-model="row.id" />
+            </template>
+          </el-table-column>
+
+          <!-- 事件名称列 -->
+          <el-table-column align="center" prop="name" label="事件名称">
+            <template #default="{ row }">
+              <el-input v-model="row.name" placeholder="事件名称" />
+            </template>
+          </el-table-column>
+        </el-table>
+
+        <template #footer>
+          <el-button type="primary" @click="submitEventInfo" style="margin-right: 10px"
+            >保存
+          </el-button>
+          <el-button @click="defaultEventDialogVisible = false">取消</el-button>
+        </template>
+      </el-dialog>
+    </div>
   </div>
 </template>