123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502 |
- <template>
- <div class="p-2">
- <transition :enter-active-class="proxy?.animate.searchAnimate.enter" :leave-active-class="proxy?.animate.searchAnimate.leave">
- <div v-show="showSearch" class="mb-[10px]">
- <el-card shadow="hover">
- <el-form ref="queryFormRef" :model="queryParams" :inline="true" label-width="100px">
- <el-form-item label="赛事编号" prop="eventCode">
- <el-input v-model="queryParams.eventCode" placeholder="请输入赛事编号" clearable @keyup.enter="handleQuery" />
- </el-form-item>
- <el-form-item label="赛事名称" prop="eventName">
- <el-input v-model="queryParams.eventName" placeholder="请输入赛事名称" clearable @keyup.enter="handleQuery" />
- </el-form-item>
- <el-form-item label="赛事类型" prop="eventType">
- <el-select v-model="queryParams.eventType" placeholder="请选择赛事类型" clearable>
- <el-option v-for="dict in game_event_type" :key="dict.value" :label="dict.label" :value="dict.value" />
- </el-select>
- </el-form-item>
- <el-form-item label="开始时间" prop="startTime">
- <el-date-picker clearable v-model="queryParams.startTime" type="date" value-format="YYYY-MM-DD" placeholder="请选择开始时间" />
- </el-form-item>
- <el-form-item label="是否默认赛事" prop="isDefault">
- <el-select v-model="queryParams.isDefault" placeholder="请选择是否默认赛事" clearable>
- <el-option v-for="dict in sys_yes_no" :key="dict.value" :label="dict.label" :value="dict.value" />
- </el-select>
- </el-form-item>
- <el-form-item label="状态" prop="status">
- <el-select v-model="queryParams.status" placeholder="请选择状态" clearable>
- <el-option v-for="dict in game_event_status" :key="dict.value" :label="dict.label" :value="dict.value" />
- </el-select>
- </el-form-item>
- <el-form-item>
- <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
- <el-button icon="Refresh" @click="resetQuery">重置</el-button>
- </el-form-item>
- </el-form>
- </el-card>
- </div>
- </transition>
- <el-card shadow="never">
- <template #header>
- <el-row :gutter="10" class="mb8">
- <el-col :span="1.5">
- <el-button type="primary" plain icon="Plus" @click="handleAdd" v-hasPermi="['system:gameEvent:add']">新增 </el-button>
- </el-col>
- <el-col :span="1.5">
- <el-button type="success" plain icon="Edit" :disabled="single" @click="handleUpdate()" v-hasPermi="['system:gameEvent:edit']"
- >修改
- </el-button>
- </el-col>
- <el-col :span="1.5">
- <el-button type="danger" plain icon="Delete" :disabled="multiple" @click="handleDelete()" v-hasPermi="['system:gameEvent:remove']"
- >删除
- </el-button>
- </el-col>
- <el-col :span="1.5">
- <el-button type="warning" plain icon="Download" @click="handleExport" v-hasPermi="['system:gameEvent:export']">导出 </el-button>
- </el-col>
- <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
- </el-row>
- </template>
- <el-table v-loading="loading" border :data="gameEventList" @selection-change="handleSelectionChange">
- <el-table-column type="selection" width="55" align="center" />
- <el-table-column label="主键" align="center" prop="eventId" v-if="false" />
- <el-table-column label="赛事编号" align="center" prop="eventCode" />
- <el-table-column label="赛事名称" align="center" prop="eventName" />
- <el-table-column label="赛事类型" align="center" prop="eventType">
- <template #default="scope">
- <dict-tag :options="game_event_type" :value="scope.row.eventType" />
- </template>
- </el-table-column>
- <el-table-column label="举办地点" align="center" prop="location" />
- <el-table-column label="用途" align="center" prop="purpose">
- <template #default="scope">
- <dict-tag :options="game_event_purpose" :value="scope.row.purpose" />
- </template>
- </el-table-column>
- <el-table-column label="开始时间" align="center" prop="startTime" width="180">
- <template #default="scope">
- <span>{{ parseTime(scope.row.startTime, '{y}-{m}-{d}') }}</span>
- </template>
- </el-table-column>
- <el-table-column label="结束时间" align="center" prop="endTime" width="180">
- <template #default="scope">
- <span>{{ parseTime(scope.row.endTime, '{y}-{m}-{d}') }}</span>
- </template>
- </el-table-column>
- <el-table-column label="赛事链接" align="center" prop="eventUrlUrl" width="100">
- <template #default="scope">
- <image-preview :src="scope.row.eventUrlUrl" :width="50" :height="50" />
- </template>
- </el-table-column>
- <el-table-column label="裁判码" align="center" prop="refereeUrlUrl" width="100">
- <template #default="scope">
- <image-preview :src="scope.row.refereeUrlUrl" :width="50" :height="50" />
- </template>
- </el-table-column>
- <el-table-column label="举办单位" align="center" prop="unit" />
- <el-table-column label="是否默认赛事" align="center" prop="isDefault">
- <template #default="scope">
- <el-switch v-model="scope.row.isDefault" active-value="0" inactive-value="1" @change="handleStatusChange(scope.row)"></el-switch>
- </template>
- </el-table-column>
- <el-table-column label="创建时间" align="center" prop="createTime" width="180">
- <template #default="scope">
- <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
- </template>
- </el-table-column>
- <el-table-column label="更新时间" align="center" prop="updateTime" width="180">
- <template #default="scope">
- <span>{{ parseTime(scope.row.updateTime, '{y}-{m}-{d}') }}</span>
- </template>
- </el-table-column>
- <el-table-column label="状态" align="center" prop="status">
- <template #default="scope">
- <dict-tag :options="game_event_status" :value="scope.row.status" />
- </template>
- </el-table-column>
- <el-table-column label="备注" align="center" prop="remark" />
- <el-table-column label="操作" align="center" class-name="small-padding fixed-width" fixed="right">
- <template #default="scope">
- <el-tooltip content="修改" placement="top">
- <el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)" v-hasPermi="['system:gameEvent:edit']"></el-button>
- </el-tooltip>
- <!-- 删除操作 -->
- <el-tooltip :content="getDeleteTooltip(scope.row)" placement="top">
- <el-button
- link
- type="primary"
- icon="Delete"
- :disabled="!canDelete(scope.row)"
- @click="handleDelete(scope.row)"
- v-hasPermi="['system:event:remove']"
- >
- </el-button>
- </el-tooltip>
- <el-tooltip content="导入报名信息" placement="top">
- <el-button
- link
- type="primary"
- icon="FolderOpened"
- @click="handleImportRegistration(scope.row)"
- v-hasPermi="['system:gameEvent:import']"
- ></el-button>
- </el-tooltip>
- <el-tooltip content="添加参赛者" placement="top">
- <el-button
- link
- type="primary"
- icon="User"
- @click="handleAddParticipant(scope.row)"
- v-hasPermi="['system:gameEvent:addParticipant']"
- ></el-button>
- </el-tooltip>
- <el-tooltip content="添加裁判" placement="top">
- <el-button
- link
- type="primary"
- icon="Avatar"
- @click="handleAddReferee(scope.row)"
- v-hasPermi="['system:gameEvent:addReferee']"
- ></el-button>
- </el-tooltip>
- <!-- 新增预览按钮 -->
- <el-tooltip content="预览" placement="top">
- <el-button link type="primary" icon="View" @click="handlePreview(scope.row)" v-hasPermi="['system:gameEvent:view']"></el-button>
- </el-tooltip>
- <!-- 新增比赛数据按钮 -->
- <el-tooltip content="比赛数据" placement="top">
- <el-button
- link
- type="primary"
- icon="DataAnalysis"
- @click="handleGameData(scope.row)"
- v-hasPermi="['system:gameEvent:gameData']"
- ></el-button>
- </el-tooltip>
- </template>
- </el-table-column>
- </el-table>
- <pagination v-show="total > 0" :total="total" v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize" @pagination="getList" />
- </el-card>
- <!-- 注册 RefereeForm 组件 -->
- <RefereeForm ref="refereeFormRef" />
- <!-- 排行榜对话框 -->
- <el-dialog :title="`赛事 ${currentEventId} 排行榜`" v-model="rankingBoardVisible" width="800px" append-to-body>
- <RankingBoard :eventId="currentEventId" v-if="rankingBoardVisible" />
- </el-dialog>
- </div>
- </template>
- <script setup name="GameEvent" lang="ts">
- import { listGameEvent, changeEventDefault, delGameEvent, addGameEvent, updateGameEvent } from '@/api/system/gameEvent';
- import { GameEventVO, GameEventQuery, GameEventForm } from '@/api/system/gameEvent/types';
- import { useRouter } from 'vue-router';
- import { ref } from 'vue';
- import RefereeForm from '@/views/system/gameEvent/RefereeForm.vue';
- import RankingBoard from './RankingBoard.vue';
- import { useTagsViewStore } from '@/store/modules/tagsView';
- import { useTagsViewStore } from '@/store/modules/tagsView';
- const router = useRouter();
- const { proxy } = getCurrentInstance() as ComponentInternalInstance;
- 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')
- );
- // 定义 RefereeForm 组件的类型
- interface RefereeFormInstance {
- openDialog: (eventId: string) => void;
- }
- const refereeFormRef = ref<(InstanceType<typeof RefereeForm> & RefereeFormInstance) | null>(null);
- const gameEventList = ref<GameEventVO[]>([]);
- const buttonLoading = ref(false);
- const loading = ref(true);
- const showSearch = ref(true);
- const ids = ref<Array<string | number>>([]);
- const single = ref(true);
- const multiple = ref(true);
- const total = ref(0);
- const queryFormRef = ref<ElFormInstance>();
- const gameEventFormRef = ref<ElFormInstance>();
- const dialog = reactive<DialogOption>({
- visible: false,
- title: ''
- });
- const initFormData: GameEventForm = {
- eventId: undefined,
- eventCode: undefined,
- eventName: undefined,
- eventType: undefined,
- location: undefined,
- purpose: undefined,
- startTime: undefined,
- endTime: undefined,
- eventUrl: undefined,
- refereeUrl: undefined,
- registerUrl: undefined,
- unit: undefined,
- isDefault: undefined,
- status: undefined,
- remark: undefined
- };
- const data = reactive<PageData<GameEventForm, GameEventQuery>>({
- form: { ...initFormData },
- queryParams: {
- pageNum: 1,
- pageSize: 10,
- eventCode: undefined,
- eventName: undefined,
- eventType: undefined,
- purpose: undefined,
- startTime: undefined,
- isDefault: undefined,
- status: undefined,
- params: {},
- orderByColumn: '',
- isAsc: ''
- },
- rules: {
- eventCode: [{ required: true, message: '赛事编号不能为空', trigger: 'blur' }],
- eventName: [{ required: true, message: '赛事名称不能为空', trigger: 'blur' }],
- eventType: [{ required: true, message: '赛事类型不能为空', trigger: 'change' }]
- }
- });
- const { queryParams, form, rules } = toRefs(data);
- /** 查询赛事基本信息列表 */
- const getList = async () => {
- loading.value = true;
- const res = await listGameEvent(queryParams.value);
- gameEventList.value = res.rows;
- total.value = res.total;
- loading.value = false;
- };
- /** 取消按钮 */
- const cancel = () => {
- reset();
- dialog.visible = false;
- };
- /** 表单重置 */
- const reset = () => {
- form.value = { ...initFormData };
- gameEventFormRef.value?.resetFields();
- };
- /** 搜索按钮操作 */
- const handleQuery = () => {
- queryParams.value.pageNum = 1;
- getList();
- };
- /** 重置按钮操作 */
- const resetQuery = () => {
- queryFormRef.value?.resetFields();
- handleQuery();
- };
- /** 多选框选中数据 */
- const handleSelectionChange = (selection: GameEventVO[]) => {
- ids.value = selection.map((item) => item.eventId);
- single.value = selection.length != 1;
- multiple.value = !selection.length;
- };
- /** 新增按钮操作 */
- const handleAdd = () => {
- router.push('/system/gameEvent/add');
- };
- /** 修改按钮操作 */
- const handleUpdate = async (row?: GameEventVO) => {
- const _eventId = row?.eventId || ids.value[0];
- router.push(`/system/gameEvent/edit/${_eventId}`);
- };
- /** 提交按钮 */
- const submitForm = () => {
- gameEventFormRef.value?.validate(async (valid: boolean) => {
- if (valid) {
- buttonLoading.value = true;
- if (form.value.eventId) {
- await updateGameEvent(form.value).finally(() => (buttonLoading.value = false));
- } else {
- await addGameEvent(form.value).finally(() => (buttonLoading.value = false));
- }
- proxy?.$modal.msgSuccess('操作成功');
- dialog.visible = false;
- await getList();
- }
- });
- };
- /** 删除按钮操作 */
- const handleDelete = async (row?: GameEventVO) => {
- const _ids = row?.eventId || ids.value;
- if (!_ids || (Array.isArray(_ids) && _ids.length === 0)) {
- proxy?.$modal.msgError('请选择要删除的赛事');
- return;
- }
- // 如果是单个删除,需要检查时间限制
- if (row) {
- const endTime = new Date(row.endTime);
- const currentTime = new Date();
- const daysDiff = Math.floor((currentTime.getTime() - endTime.getTime()) / (1000 * 60 * 60 * 24));
- if (daysDiff < 100) {
- proxy?.$modal.msgError(`该赛事结束时间不足100天,无法删除。距离可删除时间还有 ${100 - daysDiff} 天。`);
- return;
- }
- await proxy?.$modal.confirm('是否确认删除赛事编号为"' + row.eventCode + '"的数据项?').finally(() => (loading.value = false));
- await delGameEvent(row.eventId);
- proxy?.$modal.msgSuccess('删除成功');
- } else {
- // 批量删除
- const selectedEvents = gameEventList.value.filter((event) => ids.value.includes(event.eventId));
- const invalidEvents = selectedEvents.filter((event) => {
- const endTime = new Date(event.endTime);
- const currentTime = new Date();
- const daysDiff = Math.floor((currentTime.getTime() - endTime.getTime()) / (1000 * 60 * 60 * 24));
- return daysDiff < 100;
- });
- if (invalidEvents.length > 0) {
- const eventNames = invalidEvents.map((event) => event.eventName).join('、');
- proxy?.$modal.msgError(`以下赛事结束时间不足100天,无法删除:${eventNames}`);
- return;
- }
- const eventCodes = selectedEvents.map((event) => event.eventCode).join('、');
- await proxy?.$modal.confirm(`是否确认删除以下赛事:${eventCodes}?`).finally(() => (loading.value = false));
- await delGameEvent(ids.value);
- proxy?.$modal.msgSuccess(`成功删除 ${selectedEvents.length} 个赛事`);
- }
- await getList();
- };
- /** 判断是否可以删除赛事 */
- const canDelete = (row: GameEventVO): boolean => {
- const endTime = new Date(row.endTime);
- const currentTime = new Date();
- const daysDiff = Math.floor((currentTime.getTime() - endTime.getTime()) / (1000 * 60 * 60 * 24));
- return daysDiff >= 100;
- };
- /** 获取删除按钮的提示信息 */
- const getDeleteTooltip = (row: GameEventVO): string => {
- if (canDelete(row)) {
- return '删除';
- } else {
- const endTime = new Date(row.endTime);
- const currentTime = new Date();
- const daysDiff = Math.floor((currentTime.getTime() - endTime.getTime()) / (1000 * 60 * 60 * 24));
- return `赛事结束时间不足100天,无法删除。距离可删除时间还有 ${100 - daysDiff} 天。`;
- }
- };
- /** 导出按钮操作 */
- const handleExport = () => {
- proxy?.download(
- 'system/gameEvent/export',
- {
- ...queryParams.value
- },
- `gameEvent_${new Date().getTime()}.xlsx`
- );
- };
- // 导入报名表逻辑
- const handleImportRegistration = (row: GameEventVO) => {
- // 处理导入报名信息逻辑
- console.log('导入报名信息', row);
- };
- // 添加参赛者操作
- const handleAddParticipant = (row: GameEventVO) => {
- // 跳转到新增或编辑参赛者信息页面,并传递 eventName 参数
- router.push({
- name: 'GameEventAthlete',
- params: { eventId: row.eventId, eventName: row.eventName }
- });
- };
- // 添加裁判按钮操作 1
- const handleAddReferee = async (row: GameEventVO) => {
- // 打开裁判表单对话框并传递 eventId
- refereeFormRef.value?.openDialog(String(row.eventId));
- };
- // 预览按钮点击事件
- const handlePreview = (row: GameEventVO) => {
- // 跳转到赛事详情页面
- router.push({
- name: 'GameEventDetail',
- params: { eventId: row.eventId }
- });
- };
- // 比赛成绩按钮点击事件
- const handleGameData = (row: GameEventVO) => {
- router.push({
- name: 'RankingBoardPage',
- params: { eventId: row.eventId }
- });
- };
- const rankingBoardVisible = ref(false);
- const currentEventId = ref<string | undefined>();
- // 打开排行榜组件并传递赛事ID
- const openRankingBoard = (eventId: string) => {
- currentEventId.value = eventId;
- rankingBoardVisible.value = true;
- };
- /** 状态修改 */
- const handleStatusChange = async (row: GameEventVO) => {
- const text = row.isDefault === '0' ? '启用' : '停用';
- try {
- await proxy?.$modal.confirm('确认要"' + text + '""' + row.eventName + '"为默认赛事吗?');
- await changeEventDefault(row.eventId, row.isDefault);
- await getList();
- // localStorage.setItem('defaultEventId', row.eventId);
- proxy?.$modal.msgSuccess(text + '成功');
- // 刷新当前标签页
- await useTagsViewStore().delOthersViews(router.currentRoute.value)
- } catch {
- return;
- } finally {
- row.isDefault = row.isDefault === '0' ? '1' : '0';
- }
- };
- onMounted(() => {
- getList();
- });
- // 监听路由变化,当从编辑页返回时检查是否需要刷新列表
- onActivated(() => {
- // 检查是否有需要刷新的标识
- const needRefresh = sessionStorage.getItem('needRefreshGameEventList');
- if (needRefresh === 'true') {
- // 清除标识
- sessionStorage.removeItem('needRefreshGameEventList');
- // 刷新列表数据
- getList();
- }
- });
- </script>
|