index.vue 18 KB

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