123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525 |
- <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">
- <el-form-item label="裁判姓名" prop="name">
- <el-input v-model="queryParams.name" placeholder="请输入裁判姓名" clearable @keyup.enter="handleQuery" />
- </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:gameReferee:add']">新增</el-button>
- </el-col>
- <el-col :span="1.5">
- <el-button type="success" plain icon="Edit" :disabled="single" @click="handleUpdate()" v-hasPermi="['system:gameReferee:edit']">修改</el-button>
- </el-col>
- <el-col :span="1.5">
- <el-button type="danger" plain icon="Delete" :disabled="multiple" @click="handleDelete()" v-hasPermi="['system:gameReferee:remove']">删除</el-button>
- </el-col>
- <el-col :span="1.5">
- <el-button type="warning" plain icon="Download" @click="handleExport" v-hasPermi="['system:gameReferee:export']">导出</el-button>
- </el-col>
- <right-toolbar v-model:showSearch="showSearch" @queryTable="getList" :columns="columns"></right-toolbar>
- </el-row>
- </template>
- <el-table v-loading="loading" border :data="gameRefereeList" @selection-change="handleSelectionChange">
- <el-table-column type="selection" width="55" align="center" />
- <el-table-column label="裁判ID" align="center" prop="refereeId" v-if="columns[0].visible" />
- <el-table-column label="裁判姓名" align="center" prop="name" v-if="columns[1].visible" />
- <el-table-column label="账号" align="center" prop="account" v-if="columns[2].visible" />
- <el-table-column label="密码" align="center" prop="password" v-if="columns[3].visible" />
- <el-table-column label="项目" align="center" v-if="columns[4].visible">
- <template #default="scope">
- <span>{{ scope.row.projectNameList || '无' }}</span>
- </template>
- </el-table-column>
- <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
- <template #default="scope">
- <el-tooltip content="修改" placement="top">
- <el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)" v-hasPermi="['system:gameReferee:edit']"></el-button>
- </el-tooltip>
- <el-tooltip content="删除" placement="top">
- <el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)" v-hasPermi="['system:gameReferee:remove']"></el-button>
- </el-tooltip>
- <el-tooltip content="生成二维码" placement="top">
- <el-button link type="primary" icon="FullScreen" @click="handleGenerateQRCode(scope.row)" v-hasPermi="['system:gameReferee:edit']">
- 裁判码
- </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>
- <!-- 添加或修改裁判对话框 -->
- <el-dialog :title="dialog.title" v-model="dialog.visible" width="800px" append-to-body>
- <el-form ref="gameRefereeFormRef" :model="form" :rules="rules" label-width="80px">
- <el-form-item label="裁判姓名" prop="name">
- <el-input v-model="form.name" placeholder="请输入裁判姓名" />
- </el-form-item>
- <el-form-item label="账号" prop="account">
- <el-input v-model="form.account" placeholder="请输入账号" />
- </el-form-item>
- <el-form-item label="密码" prop="password">
- <el-input v-model="form.password" placeholder="请输入密码" />
- </el-form-item>
- <el-form-item label="赛事项目" prop="projectList2">
- <!-- 赛事项目穿梭框 -->
- <el-transfer
- v-model="form.projectList2"
- :data="allProjects"
- :titles="['可选项目', '已选项目']"
- :button-texts="['移除', '添加']"
- style="width: 100%"
- />
- </el-form-item>
- </el-form>
- <template #footer>
- <div class="dialog-footer">
- <el-button type="primary" @click="submitForm">确 定</el-button>
- <el-button @click="cancel">取 消</el-button>
- </div>
- </template>
- </el-dialog>
-
- <!-- 二维码对话框 -->
- <el-dialog :title="qrCodeDialog.title" v-model="qrCodeDialog.visible" width="400px" append-to-body>
- <div class="qr-code-container" style="text-align: center; padding: 20px;">
- <img :src="qrCodeData" alt="QR Code" v-if="qrCodeData" style="width: 200px; height: 200px;" />
- <p style="margin-top: 15px;">裁判: {{ currentReferee.name }}</p>
- <p>账号: {{ currentReferee.account }}</p>
- </div>
- <template #footer>
- <div class="dialog-footer">
- <el-button type="primary" @click="handleDownloadQRCode">下载二维码</el-button>
- <el-button @click="qrCodeDialog.visible = false">关闭</el-button>
- </div>
- </template>
- </el-dialog>
- </div>
- </template>
- <script setup name="GameReferee" lang="ts">
- import { listGameReferee, getGameReferee, delGameReferee, addGameReferee, updateGameReferee } from '@/api/system/gameReferee';
- import { getGameEventProject, listGameEventProject, updateGameEventProject } from '@/api/system/gameEventProject';
- import { GameRefereeVO, GameRefereeQuery, GameRefereeForm } from '@/api/system/gameReferee/types';
- import { toDataURL } from 'qrcode';
- const { proxy } = getCurrentInstance() as ComponentInternalInstance;
- const gameRefereeList = ref<GameRefereeVOExt[]>([]);
- 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 allProjects = ref<{key: string, label: string }[]>([]); // 添加项目数据
- // 列显隐数据
- const columns = ref<FieldOption[]>([
- { key: 0, label: '裁判ID', visible: true },
- { key: 1, label: '裁判姓名', visible: true },
- { key: 2, label: '账号', visible: true },
- { key: 3, label: '密码', visible: true },
- { key: 4, label: '项目', visible: true }
- ]);
- const queryFormRef = ref<ElFormInstance>();
- const gameRefereeFormRef = ref<ElFormInstance>();
- const showList = reactive({
- projectNameList: [],
- groupList: []
- });
- // 二维码对话框数据
- const qrCodeDialog = reactive({
- visible: false,
- title: '裁判二维码'
- });
- const currentReferee = ref<GameRefereeVO>({} as GameRefereeVO);
- const qrCodeData = ref('');
- // 扩展GameRefereeVO类型,添加用于展示的projectNameList属性
- interface GameRefereeVOExt extends GameRefereeVO {
- projectNameList?: string;
- }
- const dialog = reactive<DialogOption>({
- visible: false,
- title: ''
- });
- // 定义表单数据结构
- const form = reactive({
- refereeId: undefined as string | number | undefined,
- eventId: undefined as string | number | undefined,
- name: undefined,
- groupName: undefined,
- account: undefined,
- password: undefined,
- // projectList: [] as string[], // 存储所负责的项目
- projectList2: [] as string[], // 存储所负责的项目
- refereeCode: undefined,
- createTime: undefined,
- updateTime: undefined,
- });
- const queryParams = reactive<GameRefereeQuery>({
- pageNum: 1,
- pageSize: 10,
- name: undefined,
- params: {},
- orderByColumn: undefined,
- isAsc: undefined,
- });
- const rules = {
- account: [
- { required: true, message: "账号不能为空", trigger: "blur" }
- ],
- password: [
- { required: true, message: "密码不能为空", trigger: "blur" }
- ],
- }
- /** 查询裁判列表 */
- const getList = async () => {
- loading.value = true;
-
- // 查询裁判列表
- const res = await listGameReferee(queryParams);
- // 加载所有项目信息
- const projectRes = await listGameEventProject({
- pageNum: 1,
- pageSize: 10,
- orderByColumn: undefined,
- isAsc: undefined,
- });
-
- // 为每个裁判添加项目名称列表用于展示
- for (const referee of res.rows) {
- if (referee.projectList2) {
- // 获取项目ID数组
- // const projectIds = referee.projectList.split(',').filter(id => id);
- const projectIds = referee.projectList2.filter(id => id);
-
- // 从所有项目中筛选出在projectIds中存在的项目,并提取它们的label值(项目名称)
- const projectNames = projectRes.rows
- .filter(project => projectIds.includes(String(project.projectId)))
- .map(project => project.projectName);
-
- // 添加projectNameList属性到裁判对象中用于展示
- (referee as any).projectNameList = projectNames.join(', ');
- }
- }
-
- gameRefereeList.value = res.rows as GameRefereeVOExt[];
- total.value = res.total;
- loading.value = false;
- }
- /** 取消按钮 */
- const cancel = () => {
- reset();
- dialog.visible = false;
- }
- /** 表单重置 */
- const reset = () => {
- Object.assign(form, {
- refereeId: undefined,
- eventId: undefined,
- name: undefined,
- groupName: undefined,
- account: undefined,
- password: undefined,
- // projectList: [],
- projectList2: [],
- refereeCode: undefined,
- createTime: undefined,
- updateTime: undefined,
- });
- gameRefereeFormRef.value?.resetFields();
- }
- /** 搜索按钮操作 */
- const handleQuery = () => {
- queryParams.pageNum = 1;
- getList();
- }
- /** 重置按钮操作 */
- const resetQuery = () => {
- queryFormRef.value?.resetFields();
- handleQuery();
- }
- /** 多选框选中数据 */
- const handleSelectionChange = (selection: GameRefereeVO[]) => {
- ids.value = selection.map(item => item.refereeId);
- single.value = selection.length != 1;
- multiple.value = !selection.length;
- }
- /** 获取赛事项目列表 */
- const loadProjects = async () => {
- const res = await listGameEventProject({
- pageNum: 1,
- pageSize: 1000,
- orderByColumn: '',
- isAsc: ''
- });
- // 赛事项目穿梭框可选数据拼接
- allProjects.value = res.rows.map(item => ({
- key: String(item.projectId),
- label: `${item.projectName}`
- }));
- };
- /** 新增按钮操作 */
- const handleAdd = async () => {
- reset();
- await loadProjects();
- dialog.visible = true;
- dialog.title = "添加裁判";
- }
- /** 修改按钮操作 */
- const handleUpdate = async (row?: GameRefereeVO) => {
- reset();
- const _refereeId = row?.refereeId || ids.value[0]
- const res = await getGameReferee(_refereeId);
- Object.assign(form, res.data);
-
- // 如果是修改操作,先加载项目列表
- await loadProjects();
-
- // 处理项目列表数据格式
- // if (res.data.projectList && typeof res.data.projectList === 'string') {
- // form.projectList = res.data.projectList.split(',').filter(id => id);
- // } else
- if (Array.isArray(res.data.projectList2)) {
- form.projectList2 = res.data.projectList2;
- } else {
- form.projectList2 = [];
- }
-
- dialog.visible = true;
- dialog.title = "修改裁判";
- }
- /** 提交按钮 */
- const submitForm = async () => {
- const valid = await gameRefereeFormRef.value?.validate();
- if (valid) {
- buttonLoading.value = true;
- // 提交前处理项目列表数据格式
- const submitForm: any = { ...form };
- // if (Array.isArray(form.projectList)) {
- // submitForm.projectList = form.projectList.join(',');
- // }
- if (form.projectList2) {
- submitForm.projectList2 = form.projectList2;
- }
- try {
- if (form.refereeId) {
- // 如果是更新操作,需要先获取原裁判信息,然后更新项目表中的裁判组
- const originalReferee = await getGameReferee(form.refereeId);
- const originalProjectList = originalReferee.data.projectList2 || [];
- const newProjectList = submitForm.projectList2 || [];
-
- // 获取当前项目列表中的项目ID集合
- // const currentProjectIds = new Set<string>(newProjectList.filter(id => id.trim()));
-
- // 获取原项目列表中的项目ID集合
- // const originalProjectIds = new Set<string>(originalProjectList.filter(id => id.trim()));
-
- // 筛选出在原项目列表中但不在当前项目列表中的项目(即被删除的项目)
- // const removedProjectIds = Array.from(currentProjectIds).filter(id => !originalProjectIds.has(id));
- const removedProjectIds = newProjectList.filter(id => !originalProjectList.includes(id));
-
- // 从被删除的项目中移除该裁判
- for (const projectId of removedProjectIds) {
- const projectRes = await getGameEventProject(projectId);
-
- if (projectRes) {
- const project = projectRes.data;
- let currentRefereeGroups = project.refereeGroups || [];
-
- // 从裁判组中移除该裁判ID
- if (currentRefereeGroups) {
- const refereeIds = currentRefereeGroups.filter(id => id.trim() !== String(form.refereeId));
- // 更新项目表中的裁判组字段
- await updateGameEventProject({
- ...project,
- refereeGroups: refereeIds
- });
- }
- }
- }
-
- // 向新项目中添加该裁判
- // const newProjectIds = Array.from<string>(currentProjectIds).filter(id => !originalProjectIds.has(
- const newProjectIds = newProjectList.filter(id => !originalProjectList.includes(id));
- for (const projectId of newProjectIds) {
- const projectRes = await getGameEventProject(projectId);
-
- if (projectRes) {
- const project = projectRes.data;
- let currentRefereeGroups = project.refereeGroups || [];
- // 如果该项目的裁判组中没有该裁判,则添加
- if(!project.refereeGroups.includes(String(form.refereeId))){
- currentRefereeGroups.push(String(form.refereeId)) ;
- await updateGameEventProject({
- ...project,
- refereeGroups: currentRefereeGroups
- });
- }
- }
- }
-
- await updateGameReferee(submitForm as GameRefereeForm);
- } else {
- // 新增裁判
- const refereeResult = await addGameReferee(submitForm as GameRefereeForm);
-
- // 获取新添加的裁判ID
- const newRefereeId = refereeResult.data?.refereeId || refereeResult.data;
-
- // 更新所选项目的裁判组字段
- if (newRefereeId && form.projectList2.length > 0) {
- for (const projectId of form.projectList2) {
- const projectRes = await getGameEventProject(projectId);
-
- if (projectRes) {
- const project = projectRes.data;
- let currentRefereeGroups = project.refereeGroups || [];
- currentRefereeGroups.push(String(newRefereeId));
- await updateGameEventProject({
- ...project,
- refereeGroups: currentRefereeGroups
- });
- }
- }
- }
- }
-
- proxy?.$modal.msgSuccess("操作成功");
- dialog.visible = false;
- await getList();
- } catch (error) {
- console.error('操作失败:', error);
- proxy?.$modal.msgError("操作失败");
- } finally {
- buttonLoading.value = false;
- }
- }
- }
- /** 删除按钮操作 */
- const handleDelete = async (row?: GameRefereeVO) => {
- const _refereeId = row?.refereeId || ids.value;
- await proxy?.$modal.confirm('是否确认删除裁判编号为"' + _refereeId + '"的数据项?').finally(() => loading.value = false);
-
- try {
- await delGameReferee(_refereeId);
-
- // 如果是单个删除,需要从项目表中移除该裁判
- if (row) {
- const refereeId = row.refereeId;
- if (row.projectList2) {
- const projectIds = row.projectList2.filter(id => id.trim());
-
- for (const projectId of projectIds) {
- // 获取当前项目信息
- const getProject = await getGameEventProject(projectId.trim());
- const project = getProject.data;
- if (project) {
-
- let currentRefereeGroups = project.refereeGroups || [];
-
- // 从裁判组中移除该裁判ID
- if (currentRefereeGroups) {
- const refereeIds = currentRefereeGroups.filter(id => id.trim() !== String(refereeId));
- // 更新项目表中的裁判组字段
- await updateGameEventProject({
- ...project,
- refereeGroups: refereeIds
- });
- }
- }
- }
- }
- }
-
- proxy?.$modal.msgSuccess("删除成功");
- await getList();
- } catch (error) {
- console.error('删除裁判失败:', error);
- proxy?.$modal.msgError("删除失败");
- }
- }
- /** 生成裁判二维码 */
- const handleGenerateQRCode = async (row: GameRefereeVO) => {
- currentReferee.value = row;
- // 生成二维码数据,可以包含裁判的基本信息
- const qrData = {
- eventId: row.eventId,
- refereeId: row.refereeId,
- name: row.name,
- account: row.account,
- password: row.password,
- projectList: row.projectList2,
- };
-
- try {
- qrCodeData.value = await toDataURL(JSON.stringify(qrData), { width: 200 });
- qrCodeDialog.visible = true;
- } catch (error) {
- proxy?.$modal.msgError("生成二维码失败");
- }
- };
- /** 下载二维码 */
- const handleDownloadQRCode = () => {
- if (!qrCodeData.value) return;
-
- const link = document.createElement('a');
- link.href = qrCodeData.value;
- link.download = `裁判二维码_${currentReferee.value.name}.png`;
- link.click();
- proxy?.$modal.msgSuccess("二维码下载成功");
- };
- /** 导出按钮操作 */
- const handleExport = () => {
- proxy?.download('system/gameReferee/export', {
- ...queryParams
- }, `gameReferee_${new Date().getTime()}.xlsx`)
- }
- onMounted(() => {
- getList();
- });
- </script>
|