index.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502
  1. <template>
  2. <div class="p-2">
  3. <transition :enter-active-class="proxy?.animate.searchAnimate.enter" :leave-active-class="proxy?.animate.searchAnimate.leave">
  4. <div v-show="showSearch" class="mb-[10px]">
  5. <el-card shadow="hover">
  6. <el-form ref="queryFormRef" :model="queryParams" :inline="true" label-width="100px">
  7. <el-form-item label="赛事编号" prop="eventCode">
  8. <el-input v-model="queryParams.eventCode" placeholder="请输入赛事编号" clearable @keyup.enter="handleQuery" />
  9. </el-form-item>
  10. <el-form-item label="赛事名称" prop="eventName">
  11. <el-input v-model="queryParams.eventName" placeholder="请输入赛事名称" clearable @keyup.enter="handleQuery" />
  12. </el-form-item>
  13. <el-form-item label="赛事类型" prop="eventType">
  14. <el-select v-model="queryParams.eventType" placeholder="请选择赛事类型" clearable>
  15. <el-option v-for="dict in game_event_type" :key="dict.value" :label="dict.label" :value="dict.value" />
  16. </el-select>
  17. </el-form-item>
  18. <el-form-item label="开始时间" prop="startTime">
  19. <el-date-picker clearable v-model="queryParams.startTime" type="date" value-format="YYYY-MM-DD" placeholder="请选择开始时间" />
  20. </el-form-item>
  21. <el-form-item label="是否默认赛事" prop="isDefault">
  22. <el-select v-model="queryParams.isDefault" placeholder="请选择是否默认赛事" clearable>
  23. <el-option v-for="dict in sys_yes_no" :key="dict.value" :label="dict.label" :value="dict.value" />
  24. </el-select>
  25. </el-form-item>
  26. <el-form-item label="状态" prop="status">
  27. <el-select v-model="queryParams.status" placeholder="请选择状态" clearable>
  28. <el-option v-for="dict in game_event_status" :key="dict.value" :label="dict.label" :value="dict.value" />
  29. </el-select>
  30. </el-form-item>
  31. <el-form-item>
  32. <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
  33. <el-button icon="Refresh" @click="resetQuery">重置</el-button>
  34. </el-form-item>
  35. </el-form>
  36. </el-card>
  37. </div>
  38. </transition>
  39. <el-card shadow="never">
  40. <template #header>
  41. <el-row :gutter="10" class="mb8">
  42. <el-col :span="1.5">
  43. <el-button type="primary" plain icon="Plus" @click="handleAdd" v-hasPermi="['system:gameEvent:add']">新增 </el-button>
  44. </el-col>
  45. <el-col :span="1.5">
  46. <el-button type="success" plain icon="Edit" :disabled="single" @click="handleUpdate()" v-hasPermi="['system:gameEvent:edit']"
  47. >修改
  48. </el-button>
  49. </el-col>
  50. <el-col :span="1.5">
  51. <el-button type="danger" plain icon="Delete" :disabled="multiple" @click="handleDelete()" v-hasPermi="['system:gameEvent:remove']"
  52. >删除
  53. </el-button>
  54. </el-col>
  55. <el-col :span="1.5">
  56. <el-button type="warning" plain icon="Download" @click="handleExport" v-hasPermi="['system:gameEvent:export']">导出 </el-button>
  57. </el-col>
  58. <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
  59. </el-row>
  60. </template>
  61. <el-table v-loading="loading" border :data="gameEventList" @selection-change="handleSelectionChange">
  62. <el-table-column type="selection" width="55" align="center" />
  63. <el-table-column label="主键" align="center" prop="eventId" v-if="false" />
  64. <el-table-column label="赛事编号" align="center" prop="eventCode" />
  65. <el-table-column label="赛事名称" align="center" prop="eventName" />
  66. <el-table-column label="赛事类型" align="center" prop="eventType">
  67. <template #default="scope">
  68. <dict-tag :options="game_event_type" :value="scope.row.eventType" />
  69. </template>
  70. </el-table-column>
  71. <el-table-column label="举办地点" align="center" prop="location" />
  72. <el-table-column label="用途" align="center" prop="purpose">
  73. <template #default="scope">
  74. <dict-tag :options="game_event_purpose" :value="scope.row.purpose" />
  75. </template>
  76. </el-table-column>
  77. <el-table-column label="开始时间" align="center" prop="startTime" width="180">
  78. <template #default="scope">
  79. <span>{{ parseTime(scope.row.startTime, '{y}-{m}-{d}') }}</span>
  80. </template>
  81. </el-table-column>
  82. <el-table-column label="结束时间" align="center" prop="endTime" width="180">
  83. <template #default="scope">
  84. <span>{{ parseTime(scope.row.endTime, '{y}-{m}-{d}') }}</span>
  85. </template>
  86. </el-table-column>
  87. <el-table-column label="赛事链接" align="center" prop="eventUrlUrl" width="100">
  88. <template #default="scope">
  89. <image-preview :src="scope.row.eventUrlUrl" :width="50" :height="50" />
  90. </template>
  91. </el-table-column>
  92. <el-table-column label="裁判码" align="center" prop="refereeUrlUrl" width="100">
  93. <template #default="scope">
  94. <image-preview :src="scope.row.refereeUrlUrl" :width="50" :height="50" />
  95. </template>
  96. </el-table-column>
  97. <el-table-column label="举办单位" align="center" prop="unit" />
  98. <el-table-column label="是否默认赛事" align="center" prop="isDefault">
  99. <template #default="scope">
  100. <el-switch v-model="scope.row.isDefault" active-value="0" inactive-value="1" @change="handleStatusChange(scope.row)"></el-switch>
  101. </template>
  102. </el-table-column>
  103. <el-table-column label="创建时间" align="center" prop="createTime" width="180">
  104. <template #default="scope">
  105. <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
  106. </template>
  107. </el-table-column>
  108. <el-table-column label="更新时间" align="center" prop="updateTime" width="180">
  109. <template #default="scope">
  110. <span>{{ parseTime(scope.row.updateTime, '{y}-{m}-{d}') }}</span>
  111. </template>
  112. </el-table-column>
  113. <el-table-column label="状态" align="center" prop="status">
  114. <template #default="scope">
  115. <dict-tag :options="game_event_status" :value="scope.row.status" />
  116. </template>
  117. </el-table-column>
  118. <el-table-column label="备注" align="center" prop="remark" />
  119. <el-table-column label="操作" align="center" class-name="small-padding fixed-width" fixed="right">
  120. <template #default="scope">
  121. <el-tooltip content="修改" placement="top">
  122. <el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)" v-hasPermi="['system:gameEvent:edit']"></el-button>
  123. </el-tooltip>
  124. <!-- 删除操作 -->
  125. <el-tooltip :content="getDeleteTooltip(scope.row)" placement="top">
  126. <el-button
  127. link
  128. type="primary"
  129. icon="Delete"
  130. :disabled="!canDelete(scope.row)"
  131. @click="handleDelete(scope.row)"
  132. v-hasPermi="['system:event:remove']"
  133. >
  134. </el-button>
  135. </el-tooltip>
  136. <el-tooltip content="导入报名信息" placement="top">
  137. <el-button
  138. link
  139. type="primary"
  140. icon="FolderOpened"
  141. @click="handleImportRegistration(scope.row)"
  142. v-hasPermi="['system:gameEvent:import']"
  143. ></el-button>
  144. </el-tooltip>
  145. <el-tooltip content="添加参赛者" placement="top">
  146. <el-button
  147. link
  148. type="primary"
  149. icon="User"
  150. @click="handleAddParticipant(scope.row)"
  151. v-hasPermi="['system:gameEvent:addParticipant']"
  152. ></el-button>
  153. </el-tooltip>
  154. <el-tooltip content="添加裁判" placement="top">
  155. <el-button
  156. link
  157. type="primary"
  158. icon="Avatar"
  159. @click="handleAddReferee(scope.row)"
  160. v-hasPermi="['system:gameEvent:addReferee']"
  161. ></el-button>
  162. </el-tooltip>
  163. <!-- 新增预览按钮 -->
  164. <el-tooltip content="预览" placement="top">
  165. <el-button link type="primary" icon="View" @click="handlePreview(scope.row)" v-hasPermi="['system:gameEvent:view']"></el-button>
  166. </el-tooltip>
  167. <!-- 新增比赛数据按钮 -->
  168. <el-tooltip content="比赛数据" placement="top">
  169. <el-button
  170. link
  171. type="primary"
  172. icon="DataAnalysis"
  173. @click="handleGameData(scope.row)"
  174. v-hasPermi="['system:gameEvent:gameData']"
  175. ></el-button>
  176. </el-tooltip>
  177. </template>
  178. </el-table-column>
  179. </el-table>
  180. <pagination v-show="total > 0" :total="total" v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize" @pagination="getList" />
  181. </el-card>
  182. <!-- 注册 RefereeForm 组件 -->
  183. <RefereeForm ref="refereeFormRef" />
  184. <!-- 排行榜对话框 -->
  185. <el-dialog :title="`赛事 ${currentEventId} 排行榜`" v-model="rankingBoardVisible" width="800px" append-to-body>
  186. <RankingBoard :eventId="currentEventId" v-if="rankingBoardVisible" />
  187. </el-dialog>
  188. </div>
  189. </template>
  190. <script setup name="GameEvent" lang="ts">
  191. import { listGameEvent, changeEventDefault, delGameEvent, addGameEvent, updateGameEvent } from '@/api/system/gameEvent';
  192. import { GameEventVO, GameEventQuery, GameEventForm } from '@/api/system/gameEvent/types';
  193. import { useRouter } from 'vue-router';
  194. import { ref } from 'vue';
  195. import RefereeForm from '@/views/system/gameEvent/RefereeForm.vue';
  196. import RankingBoard from './RankingBoard.vue';
  197. import { useTagsViewStore } from '@/store/modules/tagsView';
  198. import { useTagsViewStore } from '@/store/modules/tagsView';
  199. const router = useRouter();
  200. const { proxy } = getCurrentInstance() as ComponentInternalInstance;
  201. const { game_event_type, game_event_status, sys_yes_no, game_event_purpose } = toRefs<any>(
  202. proxy?.useDict('game_event_type', 'game_event_status', 'sys_yes_no', 'game_event_purpose')
  203. );
  204. // 定义 RefereeForm 组件的类型
  205. interface RefereeFormInstance {
  206. openDialog: (eventId: string) => void;
  207. }
  208. const refereeFormRef = ref<(InstanceType<typeof RefereeForm> & RefereeFormInstance) | null>(null);
  209. const gameEventList = ref<GameEventVO[]>([]);
  210. const buttonLoading = ref(false);
  211. const loading = ref(true);
  212. const showSearch = ref(true);
  213. const ids = ref<Array<string | number>>([]);
  214. const single = ref(true);
  215. const multiple = ref(true);
  216. const total = ref(0);
  217. const queryFormRef = ref<ElFormInstance>();
  218. const gameEventFormRef = ref<ElFormInstance>();
  219. const dialog = reactive<DialogOption>({
  220. visible: false,
  221. title: ''
  222. });
  223. const initFormData: GameEventForm = {
  224. eventId: undefined,
  225. eventCode: undefined,
  226. eventName: undefined,
  227. eventType: undefined,
  228. location: undefined,
  229. purpose: undefined,
  230. startTime: undefined,
  231. endTime: undefined,
  232. eventUrl: undefined,
  233. refereeUrl: undefined,
  234. registerUrl: undefined,
  235. unit: undefined,
  236. isDefault: undefined,
  237. status: undefined,
  238. remark: undefined
  239. };
  240. const data = reactive<PageData<GameEventForm, GameEventQuery>>({
  241. form: { ...initFormData },
  242. queryParams: {
  243. pageNum: 1,
  244. pageSize: 10,
  245. eventCode: undefined,
  246. eventName: undefined,
  247. eventType: undefined,
  248. purpose: undefined,
  249. startTime: undefined,
  250. isDefault: undefined,
  251. status: undefined,
  252. params: {},
  253. orderByColumn: '',
  254. isAsc: ''
  255. },
  256. rules: {
  257. eventCode: [{ required: true, message: '赛事编号不能为空', trigger: 'blur' }],
  258. eventName: [{ required: true, message: '赛事名称不能为空', trigger: 'blur' }],
  259. eventType: [{ required: true, message: '赛事类型不能为空', trigger: 'change' }]
  260. }
  261. });
  262. const { queryParams, form, rules } = toRefs(data);
  263. /** 查询赛事基本信息列表 */
  264. const getList = async () => {
  265. loading.value = true;
  266. const res = await listGameEvent(queryParams.value);
  267. gameEventList.value = res.rows;
  268. total.value = res.total;
  269. loading.value = false;
  270. };
  271. /** 取消按钮 */
  272. const cancel = () => {
  273. reset();
  274. dialog.visible = false;
  275. };
  276. /** 表单重置 */
  277. const reset = () => {
  278. form.value = { ...initFormData };
  279. gameEventFormRef.value?.resetFields();
  280. };
  281. /** 搜索按钮操作 */
  282. const handleQuery = () => {
  283. queryParams.value.pageNum = 1;
  284. getList();
  285. };
  286. /** 重置按钮操作 */
  287. const resetQuery = () => {
  288. queryFormRef.value?.resetFields();
  289. handleQuery();
  290. };
  291. /** 多选框选中数据 */
  292. const handleSelectionChange = (selection: GameEventVO[]) => {
  293. ids.value = selection.map((item) => item.eventId);
  294. single.value = selection.length != 1;
  295. multiple.value = !selection.length;
  296. };
  297. /** 新增按钮操作 */
  298. const handleAdd = () => {
  299. router.push('/system/gameEvent/add');
  300. };
  301. /** 修改按钮操作 */
  302. const handleUpdate = async (row?: GameEventVO) => {
  303. const _eventId = row?.eventId || ids.value[0];
  304. router.push(`/system/gameEvent/edit/${_eventId}`);
  305. };
  306. /** 提交按钮 */
  307. const submitForm = () => {
  308. gameEventFormRef.value?.validate(async (valid: boolean) => {
  309. if (valid) {
  310. buttonLoading.value = true;
  311. if (form.value.eventId) {
  312. await updateGameEvent(form.value).finally(() => (buttonLoading.value = false));
  313. } else {
  314. await addGameEvent(form.value).finally(() => (buttonLoading.value = false));
  315. }
  316. proxy?.$modal.msgSuccess('操作成功');
  317. dialog.visible = false;
  318. await getList();
  319. }
  320. });
  321. };
  322. /** 删除按钮操作 */
  323. const handleDelete = async (row?: GameEventVO) => {
  324. const _ids = row?.eventId || ids.value;
  325. if (!_ids || (Array.isArray(_ids) && _ids.length === 0)) {
  326. proxy?.$modal.msgError('请选择要删除的赛事');
  327. return;
  328. }
  329. // 如果是单个删除,需要检查时间限制
  330. if (row) {
  331. const endTime = new Date(row.endTime);
  332. const currentTime = new Date();
  333. const daysDiff = Math.floor((currentTime.getTime() - endTime.getTime()) / (1000 * 60 * 60 * 24));
  334. if (daysDiff < 100) {
  335. proxy?.$modal.msgError(`该赛事结束时间不足100天,无法删除。距离可删除时间还有 ${100 - daysDiff} 天。`);
  336. return;
  337. }
  338. await proxy?.$modal.confirm('是否确认删除赛事编号为"' + row.eventCode + '"的数据项?').finally(() => (loading.value = false));
  339. await delGameEvent(row.eventId);
  340. proxy?.$modal.msgSuccess('删除成功');
  341. } else {
  342. // 批量删除
  343. const selectedEvents = gameEventList.value.filter((event) => ids.value.includes(event.eventId));
  344. const invalidEvents = selectedEvents.filter((event) => {
  345. const endTime = new Date(event.endTime);
  346. const currentTime = new Date();
  347. const daysDiff = Math.floor((currentTime.getTime() - endTime.getTime()) / (1000 * 60 * 60 * 24));
  348. return daysDiff < 100;
  349. });
  350. if (invalidEvents.length > 0) {
  351. const eventNames = invalidEvents.map((event) => event.eventName).join('、');
  352. proxy?.$modal.msgError(`以下赛事结束时间不足100天,无法删除:${eventNames}`);
  353. return;
  354. }
  355. const eventCodes = selectedEvents.map((event) => event.eventCode).join('、');
  356. await proxy?.$modal.confirm(`是否确认删除以下赛事:${eventCodes}?`).finally(() => (loading.value = false));
  357. await delGameEvent(ids.value);
  358. proxy?.$modal.msgSuccess(`成功删除 ${selectedEvents.length} 个赛事`);
  359. }
  360. await getList();
  361. };
  362. /** 判断是否可以删除赛事 */
  363. const canDelete = (row: GameEventVO): boolean => {
  364. const endTime = new Date(row.endTime);
  365. const currentTime = new Date();
  366. const daysDiff = Math.floor((currentTime.getTime() - endTime.getTime()) / (1000 * 60 * 60 * 24));
  367. return daysDiff >= 100;
  368. };
  369. /** 获取删除按钮的提示信息 */
  370. const getDeleteTooltip = (row: GameEventVO): string => {
  371. if (canDelete(row)) {
  372. return '删除';
  373. } else {
  374. const endTime = new Date(row.endTime);
  375. const currentTime = new Date();
  376. const daysDiff = Math.floor((currentTime.getTime() - endTime.getTime()) / (1000 * 60 * 60 * 24));
  377. return `赛事结束时间不足100天,无法删除。距离可删除时间还有 ${100 - daysDiff} 天。`;
  378. }
  379. };
  380. /** 导出按钮操作 */
  381. const handleExport = () => {
  382. proxy?.download(
  383. 'system/gameEvent/export',
  384. {
  385. ...queryParams.value
  386. },
  387. `gameEvent_${new Date().getTime()}.xlsx`
  388. );
  389. };
  390. // 导入报名表逻辑
  391. const handleImportRegistration = (row: GameEventVO) => {
  392. // 处理导入报名信息逻辑
  393. console.log('导入报名信息', row);
  394. };
  395. // 添加参赛者操作
  396. const handleAddParticipant = (row: GameEventVO) => {
  397. // 跳转到新增或编辑参赛者信息页面,并传递 eventName 参数
  398. router.push({
  399. name: 'GameEventAthlete',
  400. params: { eventId: row.eventId, eventName: row.eventName }
  401. });
  402. };
  403. // 添加裁判按钮操作 1
  404. const handleAddReferee = async (row: GameEventVO) => {
  405. // 打开裁判表单对话框并传递 eventId
  406. refereeFormRef.value?.openDialog(String(row.eventId));
  407. };
  408. // 预览按钮点击事件
  409. const handlePreview = (row: GameEventVO) => {
  410. // 跳转到赛事详情页面
  411. router.push({
  412. name: 'GameEventDetail',
  413. params: { eventId: row.eventId }
  414. });
  415. };
  416. // 比赛成绩按钮点击事件
  417. const handleGameData = (row: GameEventVO) => {
  418. router.push({
  419. name: 'RankingBoardPage',
  420. params: { eventId: row.eventId }
  421. });
  422. };
  423. const rankingBoardVisible = ref(false);
  424. const currentEventId = ref<string | undefined>();
  425. // 打开排行榜组件并传递赛事ID
  426. const openRankingBoard = (eventId: string) => {
  427. currentEventId.value = eventId;
  428. rankingBoardVisible.value = true;
  429. };
  430. /** 状态修改 */
  431. const handleStatusChange = async (row: GameEventVO) => {
  432. const text = row.isDefault === '0' ? '启用' : '停用';
  433. try {
  434. await proxy?.$modal.confirm('确认要"' + text + '""' + row.eventName + '"为默认赛事吗?');
  435. await changeEventDefault(row.eventId, row.isDefault);
  436. await getList();
  437. // localStorage.setItem('defaultEventId', row.eventId);
  438. proxy?.$modal.msgSuccess(text + '成功');
  439. // 刷新当前标签页
  440. await useTagsViewStore().delOthersViews(router.currentRoute.value)
  441. } catch {
  442. return;
  443. } finally {
  444. row.isDefault = row.isDefault === '0' ? '1' : '0';
  445. }
  446. };
  447. onMounted(() => {
  448. getList();
  449. });
  450. // 监听路由变化,当从编辑页返回时检查是否需要刷新列表
  451. onActivated(() => {
  452. // 检查是否有需要刷新的标识
  453. const needRefresh = sessionStorage.getItem('needRefreshGameEventList');
  454. if (needRefresh === 'true') {
  455. // 清除标识
  456. sessionStorage.removeItem('needRefreshGameEventList');
  457. // 刷新列表数据
  458. getList();
  459. }
  460. });
  461. </script>