index.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503
  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">
  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. <dict-tag :options="sys_yes_no" :value="scope.row.isDefault" />
  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. <!-- <el-tooltip content="删除" placement="top">
  125. <el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)" v-hasPermi="['system:gameEvent:remove']"></el-button>
  126. </el-tooltip> -->
  127. <el-tooltip :content="getDeleteTooltip(scope.row)" placement="top">
  128. <el-button
  129. link
  130. type="primary"
  131. icon="Delete"
  132. :disabled="!canDelete(scope.row)"
  133. @click="handleDelete(scope.row)"
  134. v-hasPermi="['system:event:remove']"
  135. >
  136. </el-button>
  137. </el-tooltip>
  138. <el-tooltip content="导入报名信息" placement="top">
  139. <el-button
  140. link
  141. type="primary"
  142. icon="FolderOpened"
  143. @click="handleImportRegistration(scope.row)"
  144. v-hasPermi="['system:gameEvent:import']"
  145. ></el-button>
  146. </el-tooltip>
  147. <el-tooltip content="添加参赛者" placement="top">
  148. <el-button
  149. link
  150. type="primary"
  151. icon="User"
  152. @click="handleAddParticipant(scope.row)"
  153. v-hasPermi="['system:gameEvent:addParticipant']"
  154. ></el-button>
  155. </el-tooltip>
  156. <el-tooltip content="添加裁判" placement="top">
  157. <el-button
  158. link
  159. type="primary"
  160. icon="Avatar"
  161. @click="handleAddReferee(scope.row)"
  162. v-hasPermi="['system:gameEvent:addReferee']"
  163. ></el-button>
  164. </el-tooltip>
  165. <!-- 新增预览按钮 -->
  166. <el-tooltip content="预览" placement="top">
  167. <el-button link type="primary" icon="View" @click="handlePreview(scope.row)" v-hasPermi="['system:gameEvent:view']"></el-button>
  168. </el-tooltip>
  169. <!-- 新增比赛数据按钮 -->
  170. <el-tooltip content="比赛数据" placement="top">
  171. <el-button
  172. link
  173. type="primary"
  174. icon="DataAnalysis"
  175. @click="handleGameData(scope.row)"
  176. v-hasPermi="['system:gameEvent:gameData']"
  177. ></el-button>
  178. </el-tooltip>
  179. </template>
  180. </el-table-column>
  181. </el-table>
  182. <pagination v-show="total > 0" :total="total" v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize" @pagination="getList" />
  183. </el-card>
  184. <!-- 注册 RefereeForm 组件 -->
  185. <RefereeForm ref="refereeFormRef" />
  186. <!-- 排行榜对话框 -->
  187. <el-dialog :title="`赛事 ${currentEventId} 排行榜`" v-model="rankingBoardVisible" width="800px" append-to-body>
  188. <RankingBoard :eventId="currentEventId" v-if="rankingBoardVisible" />
  189. </el-dialog>
  190. </div>
  191. </template>
  192. <script setup name="GameEvent" lang="ts">
  193. import { listGameEvent, getGameEvent, delGameEvent, addGameEvent, updateGameEvent } from '@/api/system/gameEvent';
  194. import { GameEventVO, GameEventQuery, GameEventForm } from '@/api/system/gameEvent/types';
  195. import { useRouter } from 'vue-router';
  196. import { ref } from 'vue';
  197. import RefereeForm from '@/views/system/gameEvent/RefereeForm.vue';
  198. import RankingBoard from './RankingBoard.vue';
  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. },
  254. rules: {
  255. eventCode: [{ required: true, message: '赛事编号不能为空', trigger: 'blur' }],
  256. eventName: [{ required: true, message: '赛事名称不能为空', trigger: 'blur' }],
  257. eventType: [{ required: true, message: '赛事类型不能为空', trigger: 'change' }]
  258. // purpose: [
  259. // { required: true, message: "用途不能为空", trigger: "change" }
  260. // ],
  261. // startTime: [
  262. // { required: true, message: "开始时间不能为空", trigger: "blur" }
  263. // ],
  264. // endTime: [
  265. // { required: true, message: "结束时间不能为空", trigger: "blur" }
  266. // ],
  267. // eventUrl: [
  268. // { required: true, message: "赛事链接不能为空", trigger: "blur" }
  269. // ],
  270. // refereeUrl: [
  271. // { required: true, message: "裁判码不能为空", trigger: "blur" }
  272. // ],
  273. // isDefault: [
  274. // { required: true, message: "是否默认赛事不能为空", trigger: "change" }
  275. // ],
  276. // status: [
  277. // { required: true, message: "状态不能为空", trigger: "change" }
  278. // ],
  279. }
  280. });
  281. const { queryParams, form, rules } = toRefs(data);
  282. /** 查询赛事基本信息列表 */
  283. const getList = async () => {
  284. loading.value = true;
  285. const res = await listGameEvent(queryParams.value);
  286. gameEventList.value = res.rows;
  287. total.value = res.total;
  288. loading.value = false;
  289. };
  290. /** 取消按钮 */
  291. const cancel = () => {
  292. reset();
  293. dialog.visible = false;
  294. };
  295. /** 表单重置 */
  296. const reset = () => {
  297. form.value = { ...initFormData };
  298. gameEventFormRef.value?.resetFields();
  299. };
  300. /** 搜索按钮操作 */
  301. const handleQuery = () => {
  302. queryParams.value.pageNum = 1;
  303. getList();
  304. };
  305. /** 重置按钮操作 */
  306. const resetQuery = () => {
  307. queryFormRef.value?.resetFields();
  308. handleQuery();
  309. };
  310. /** 多选框选中数据 */
  311. const handleSelectionChange = (selection: GameEventVO[]) => {
  312. ids.value = selection.map((item) => item.eventId);
  313. single.value = selection.length != 1;
  314. multiple.value = !selection.length;
  315. };
  316. /** 新增按钮操作 */
  317. const handleAdd = () => {
  318. router.push('/system/gameEvent/add');
  319. };
  320. /** 修改按钮操作 */
  321. const handleUpdate = async (row?: GameEventVO) => {
  322. const _eventId = row?.eventId || ids.value[0];
  323. router.push(`/system/gameEvent/edit/${_eventId}`);
  324. };
  325. /** 提交按钮 */
  326. const submitForm = () => {
  327. gameEventFormRef.value?.validate(async (valid: boolean) => {
  328. if (valid) {
  329. buttonLoading.value = true;
  330. if (form.value.eventId) {
  331. await updateGameEvent(form.value).finally(() => (buttonLoading.value = false));
  332. } else {
  333. await addGameEvent(form.value).finally(() => (buttonLoading.value = false));
  334. }
  335. proxy?.$modal.msgSuccess('操作成功');
  336. dialog.visible = false;
  337. await getList();
  338. }
  339. });
  340. };
  341. /** 删除按钮操作 */
  342. const handleDelete = async (row?: GameEventVO) => {
  343. const _ids = row?.eventId || ids.value;
  344. if (!_ids || (Array.isArray(_ids) && _ids.length === 0)) {
  345. proxy?.$modal.msgError('请选择要删除的赛事');
  346. return;
  347. }
  348. // 如果是单个删除,需要检查时间限制
  349. if (row) {
  350. const endTime = new Date(row.endTime);
  351. const currentTime = new Date();
  352. const daysDiff = Math.floor((currentTime.getTime() - endTime.getTime()) / (1000 * 60 * 60 * 24));
  353. if (daysDiff < 100) {
  354. proxy?.$modal.msgError(`该赛事结束时间不足100天,无法删除。距离可删除时间还有 ${100 - daysDiff} 天。`);
  355. return;
  356. }
  357. await proxy?.$modal.confirm('是否确认删除赛事编号为"' + row.eventCode + '"的数据项?').finally(() => (loading.value = false));
  358. await delGameEvent(row.eventId);
  359. proxy?.$modal.msgSuccess('删除成功');
  360. } else {
  361. // 批量删除
  362. const selectedEvents = gameEventList.value.filter((event) => ids.value.includes(event.eventId));
  363. const invalidEvents = selectedEvents.filter((event) => {
  364. const endTime = new Date(event.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. if (invalidEvents.length > 0) {
  370. const eventNames = invalidEvents.map((event) => event.eventName).join('、');
  371. proxy?.$modal.msgError(`以下赛事结束时间不足100天,无法删除:${eventNames}`);
  372. return;
  373. }
  374. const eventCodes = selectedEvents.map((event) => event.eventCode).join('、');
  375. await proxy?.$modal.confirm(`是否确认删除以下赛事:${eventCodes}?`).finally(() => (loading.value = false));
  376. await delGameEvent(ids.value);
  377. proxy?.$modal.msgSuccess(`成功删除 ${selectedEvents.length} 个赛事`);
  378. }
  379. await getList();
  380. };
  381. /** 判断是否可以删除赛事 */
  382. const canDelete = (row: GameEventVO): boolean => {
  383. const endTime = new Date(row.endTime);
  384. const currentTime = new Date();
  385. const daysDiff = Math.floor((currentTime.getTime() - endTime.getTime()) / (1000 * 60 * 60 * 24));
  386. return daysDiff >= 100;
  387. };
  388. /** 获取删除按钮的提示信息 */
  389. const getDeleteTooltip = (row: GameEventVO): string => {
  390. if (canDelete(row)) {
  391. return '删除';
  392. } else {
  393. const endTime = new Date(row.endTime);
  394. const currentTime = new Date();
  395. const daysDiff = Math.floor((currentTime.getTime() - endTime.getTime()) / (1000 * 60 * 60 * 24));
  396. return `赛事结束时间不足100天,无法删除。距离可删除时间还有 ${100 - daysDiff} 天。`;
  397. }
  398. };
  399. /** 导出按钮操作 */
  400. const handleExport = () => {
  401. proxy?.download(
  402. 'system/gameEvent/export',
  403. {
  404. ...queryParams.value
  405. },
  406. `gameEvent_${new Date().getTime()}.xlsx`
  407. );
  408. };
  409. // 导入报名表逻辑
  410. const handleImportRegistration = (row: GameEventVO) => {
  411. // 处理导入报名信息逻辑
  412. console.log('导入报名信息', row);
  413. };
  414. // 添加参赛者操作
  415. const handleAddParticipant = (row: GameEventVO) => {
  416. // 跳转到新增或编辑参赛者信息页面,并传递 eventName 参数
  417. router.push({
  418. name: 'GameEventAthlete',
  419. params: { eventId: row.eventId, eventName: row.eventName }
  420. });
  421. };
  422. // 添加裁判按钮操作
  423. const handleAddReferee = async (row: GameEventVO) => {
  424. // 打开裁判表单对话框并传递 eventId
  425. refereeFormRef.value?.openDialog(String(row.eventId));
  426. };
  427. // 预览按钮点击事件
  428. const handlePreview = (row: GameEventVO) => {
  429. // 跳转到赛事详情页面
  430. router.push({
  431. name: 'GameEventDetail',
  432. params: { eventId: row.eventId }
  433. });
  434. };
  435. // 比赛成绩按钮点击事件
  436. const handleGameData = (row: GameEventVO) => {
  437. router.push({
  438. name: 'RankingBoardPage',
  439. params: { eventId: row.eventId }
  440. });
  441. };
  442. const rankingBoardVisible = ref(false);
  443. const currentEventId = ref<string | undefined>();
  444. // 打开排行榜组件并传递赛事ID
  445. const openRankingBoard = (eventId: string) => {
  446. currentEventId.value = eventId;
  447. rankingBoardVisible.value = true;
  448. };
  449. onMounted(() => {
  450. getList();
  451. });
  452. // 监听路由变化,当从编辑页返回时检查是否需要刷新列表
  453. onActivated(() => {
  454. // 检查是否有需要刷新的标识
  455. const needRefresh = sessionStorage.getItem('needRefreshGameEventList');
  456. if (needRefresh === 'true') {
  457. // 清除标识
  458. sessionStorage.removeItem('needRefreshGameEventList');
  459. // 刷新列表数据
  460. getList();
  461. }
  462. });
  463. </script>