index.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525
  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="name">
  8. <el-input v-model="queryParams.name" placeholder="请输入裁判姓名" clearable @keyup.enter="handleQuery" />
  9. </el-form-item>
  10. <el-form-item>
  11. <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
  12. <el-button icon="Refresh" @click="resetQuery">重置</el-button>
  13. </el-form-item>
  14. </el-form>
  15. </el-card>
  16. </div>
  17. </transition>
  18. <el-card shadow="never">
  19. <template #header>
  20. <el-row :gutter="10" class="mb8">
  21. <el-col :span="1.5">
  22. <el-button type="primary" plain icon="Plus" @click="handleAdd" v-hasPermi="['system:gameReferee:add']">新增</el-button>
  23. </el-col>
  24. <el-col :span="1.5">
  25. <el-button type="success" plain icon="Edit" :disabled="single" @click="handleUpdate()" v-hasPermi="['system:gameReferee:edit']">修改</el-button>
  26. </el-col>
  27. <el-col :span="1.5">
  28. <el-button type="danger" plain icon="Delete" :disabled="multiple" @click="handleDelete()" v-hasPermi="['system:gameReferee:remove']">删除</el-button>
  29. </el-col>
  30. <el-col :span="1.5">
  31. <el-button type="warning" plain icon="Download" @click="handleExport" v-hasPermi="['system:gameReferee:export']">导出</el-button>
  32. </el-col>
  33. <right-toolbar v-model:showSearch="showSearch" @queryTable="getList" :columns="columns"></right-toolbar>
  34. </el-row>
  35. </template>
  36. <el-table v-loading="loading" border :data="gameRefereeList" @selection-change="handleSelectionChange">
  37. <el-table-column type="selection" width="55" align="center" />
  38. <el-table-column label="裁判ID" align="center" prop="refereeId" v-if="columns[0].visible" />
  39. <el-table-column label="裁判姓名" align="center" prop="name" v-if="columns[1].visible" />
  40. <el-table-column label="账号" align="center" prop="account" v-if="columns[2].visible" />
  41. <el-table-column label="密码" align="center" prop="password" v-if="columns[3].visible" />
  42. <el-table-column label="项目" align="center" v-if="columns[4].visible">
  43. <template #default="scope">
  44. <span>{{ scope.row.projectNameList || '无' }}</span>
  45. </template>
  46. </el-table-column>
  47. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  48. <template #default="scope">
  49. <el-tooltip content="修改" placement="top">
  50. <el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)" v-hasPermi="['system:gameReferee:edit']"></el-button>
  51. </el-tooltip>
  52. <el-tooltip content="删除" placement="top">
  53. <el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)" v-hasPermi="['system:gameReferee:remove']"></el-button>
  54. </el-tooltip>
  55. <el-tooltip content="生成二维码" placement="top">
  56. <el-button link type="primary" icon="FullScreen" @click="handleGenerateQRCode(scope.row)" v-hasPermi="['system:gameReferee:edit']">
  57. 裁判码
  58. </el-button>
  59. </el-tooltip>
  60. </template>
  61. </el-table-column>
  62. </el-table>
  63. <pagination v-show="total > 0" :total="total" v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize" @pagination="getList" />
  64. </el-card>
  65. <!-- 添加或修改裁判对话框 -->
  66. <el-dialog :title="dialog.title" v-model="dialog.visible" width="800px" append-to-body>
  67. <el-form ref="gameRefereeFormRef" :model="form" :rules="rules" label-width="80px">
  68. <el-form-item label="裁判姓名" prop="name">
  69. <el-input v-model="form.name" placeholder="请输入裁判姓名" />
  70. </el-form-item>
  71. <el-form-item label="账号" prop="account">
  72. <el-input v-model="form.account" placeholder="请输入账号" />
  73. </el-form-item>
  74. <el-form-item label="密码" prop="password">
  75. <el-input v-model="form.password" placeholder="请输入密码" />
  76. </el-form-item>
  77. <el-form-item label="赛事项目" prop="projectList2">
  78. <!-- 赛事项目穿梭框 -->
  79. <el-transfer
  80. v-model="form.projectList2"
  81. :data="allProjects"
  82. :titles="['可选项目', '已选项目']"
  83. :button-texts="['移除', '添加']"
  84. style="width: 100%"
  85. />
  86. </el-form-item>
  87. </el-form>
  88. <template #footer>
  89. <div class="dialog-footer">
  90. <el-button type="primary" @click="submitForm">确 定</el-button>
  91. <el-button @click="cancel">取 消</el-button>
  92. </div>
  93. </template>
  94. </el-dialog>
  95. <!-- 二维码对话框 -->
  96. <el-dialog :title="qrCodeDialog.title" v-model="qrCodeDialog.visible" width="400px" append-to-body>
  97. <div class="qr-code-container" style="text-align: center; padding: 20px;">
  98. <img :src="qrCodeData" alt="QR Code" v-if="qrCodeData" style="width: 200px; height: 200px;" />
  99. <p style="margin-top: 15px;">裁判: {{ currentReferee.name }}</p>
  100. <p>账号: {{ currentReferee.account }}</p>
  101. </div>
  102. <template #footer>
  103. <div class="dialog-footer">
  104. <el-button type="primary" @click="handleDownloadQRCode">下载二维码</el-button>
  105. <el-button @click="qrCodeDialog.visible = false">关闭</el-button>
  106. </div>
  107. </template>
  108. </el-dialog>
  109. </div>
  110. </template>
  111. <script setup name="GameReferee" lang="ts">
  112. import { listGameReferee, getGameReferee, delGameReferee, addGameReferee, updateGameReferee } from '@/api/system/gameReferee';
  113. import { getGameEventProject, listGameEventProject, updateGameEventProject } from '@/api/system/gameEventProject';
  114. import { GameRefereeVO, GameRefereeQuery, GameRefereeForm } from '@/api/system/gameReferee/types';
  115. import { toDataURL } from 'qrcode';
  116. const { proxy } = getCurrentInstance() as ComponentInternalInstance;
  117. const gameRefereeList = ref<GameRefereeVOExt[]>([]);
  118. const buttonLoading = ref(false);
  119. const loading = ref(true);
  120. const showSearch = ref(true);
  121. const ids = ref<Array<string | number>>([]);
  122. const single = ref(true);
  123. const multiple = ref(true);
  124. const total = ref(0);
  125. const allProjects = ref<{key: string, label: string }[]>([]); // 添加项目数据
  126. // 列显隐数据
  127. const columns = ref<FieldOption[]>([
  128. { key: 0, label: '裁判ID', visible: true },
  129. { key: 1, label: '裁判姓名', visible: true },
  130. { key: 2, label: '账号', visible: true },
  131. { key: 3, label: '密码', visible: true },
  132. { key: 4, label: '项目', visible: true }
  133. ]);
  134. const queryFormRef = ref<ElFormInstance>();
  135. const gameRefereeFormRef = ref<ElFormInstance>();
  136. const showList = reactive({
  137. projectNameList: [],
  138. groupList: []
  139. });
  140. // 二维码对话框数据
  141. const qrCodeDialog = reactive({
  142. visible: false,
  143. title: '裁判二维码'
  144. });
  145. const currentReferee = ref<GameRefereeVO>({} as GameRefereeVO);
  146. const qrCodeData = ref('');
  147. // 扩展GameRefereeVO类型,添加用于展示的projectNameList属性
  148. interface GameRefereeVOExt extends GameRefereeVO {
  149. projectNameList?: string;
  150. }
  151. const dialog = reactive<DialogOption>({
  152. visible: false,
  153. title: ''
  154. });
  155. // 定义表单数据结构
  156. const form = reactive({
  157. refereeId: undefined as string | number | undefined,
  158. eventId: undefined as string | number | undefined,
  159. name: undefined,
  160. groupName: undefined,
  161. account: undefined,
  162. password: undefined,
  163. // projectList: [] as string[], // 存储所负责的项目
  164. projectList2: [] as string[], // 存储所负责的项目
  165. refereeCode: undefined,
  166. createTime: undefined,
  167. updateTime: undefined,
  168. });
  169. const queryParams = reactive<GameRefereeQuery>({
  170. pageNum: 1,
  171. pageSize: 10,
  172. name: undefined,
  173. params: {},
  174. orderByColumn: undefined,
  175. isAsc: undefined,
  176. });
  177. const rules = {
  178. account: [
  179. { required: true, message: "账号不能为空", trigger: "blur" }
  180. ],
  181. password: [
  182. { required: true, message: "密码不能为空", trigger: "blur" }
  183. ],
  184. }
  185. /** 查询裁判列表 */
  186. const getList = async () => {
  187. loading.value = true;
  188. // 查询裁判列表
  189. const res = await listGameReferee(queryParams);
  190. // 加载所有项目信息
  191. const projectRes = await listGameEventProject({
  192. pageNum: 1,
  193. pageSize: 10,
  194. orderByColumn: undefined,
  195. isAsc: undefined,
  196. });
  197. // 为每个裁判添加项目名称列表用于展示
  198. for (const referee of res.rows) {
  199. if (referee.projectList2) {
  200. // 获取项目ID数组
  201. // const projectIds = referee.projectList.split(',').filter(id => id);
  202. const projectIds = referee.projectList2.filter(id => id);
  203. // 从所有项目中筛选出在projectIds中存在的项目,并提取它们的label值(项目名称)
  204. const projectNames = projectRes.rows
  205. .filter(project => projectIds.includes(String(project.projectId)))
  206. .map(project => project.projectName);
  207. // 添加projectNameList属性到裁判对象中用于展示
  208. (referee as any).projectNameList = projectNames.join(', ');
  209. }
  210. }
  211. gameRefereeList.value = res.rows as GameRefereeVOExt[];
  212. total.value = res.total;
  213. loading.value = false;
  214. }
  215. /** 取消按钮 */
  216. const cancel = () => {
  217. reset();
  218. dialog.visible = false;
  219. }
  220. /** 表单重置 */
  221. const reset = () => {
  222. Object.assign(form, {
  223. refereeId: undefined,
  224. eventId: undefined,
  225. name: undefined,
  226. groupName: undefined,
  227. account: undefined,
  228. password: undefined,
  229. // projectList: [],
  230. projectList2: [],
  231. refereeCode: undefined,
  232. createTime: undefined,
  233. updateTime: undefined,
  234. });
  235. gameRefereeFormRef.value?.resetFields();
  236. }
  237. /** 搜索按钮操作 */
  238. const handleQuery = () => {
  239. queryParams.pageNum = 1;
  240. getList();
  241. }
  242. /** 重置按钮操作 */
  243. const resetQuery = () => {
  244. queryFormRef.value?.resetFields();
  245. handleQuery();
  246. }
  247. /** 多选框选中数据 */
  248. const handleSelectionChange = (selection: GameRefereeVO[]) => {
  249. ids.value = selection.map(item => item.refereeId);
  250. single.value = selection.length != 1;
  251. multiple.value = !selection.length;
  252. }
  253. /** 获取赛事项目列表 */
  254. const loadProjects = async () => {
  255. const res = await listGameEventProject({
  256. pageNum: 1,
  257. pageSize: 1000,
  258. orderByColumn: '',
  259. isAsc: ''
  260. });
  261. // 赛事项目穿梭框可选数据拼接
  262. allProjects.value = res.rows.map(item => ({
  263. key: String(item.projectId),
  264. label: `${item.projectName}-${item.groupType}`
  265. }));
  266. };
  267. /** 新增按钮操作 */
  268. const handleAdd = async () => {
  269. reset();
  270. await loadProjects();
  271. dialog.visible = true;
  272. dialog.title = "添加裁判";
  273. }
  274. /** 修改按钮操作 */
  275. const handleUpdate = async (row?: GameRefereeVO) => {
  276. reset();
  277. const _refereeId = row?.refereeId || ids.value[0]
  278. const res = await getGameReferee(_refereeId);
  279. Object.assign(form, res.data);
  280. // 如果是修改操作,先加载项目列表
  281. await loadProjects();
  282. // 处理项目列表数据格式
  283. // if (res.data.projectList && typeof res.data.projectList === 'string') {
  284. // form.projectList = res.data.projectList.split(',').filter(id => id);
  285. // } else
  286. if (Array.isArray(res.data.projectList2)) {
  287. form.projectList2 = res.data.projectList2;
  288. } else {
  289. form.projectList2 = [];
  290. }
  291. dialog.visible = true;
  292. dialog.title = "修改裁判";
  293. }
  294. /** 提交按钮 */
  295. const submitForm = async () => {
  296. const valid = await gameRefereeFormRef.value?.validate();
  297. if (valid) {
  298. buttonLoading.value = true;
  299. // 提交前处理项目列表数据格式
  300. const submitForm: any = { ...form };
  301. // if (Array.isArray(form.projectList)) {
  302. // submitForm.projectList = form.projectList.join(',');
  303. // }
  304. if (form.projectList2) {
  305. submitForm.projectList2 = form.projectList2;
  306. }
  307. try {
  308. if (form.refereeId) {
  309. // 如果是更新操作,需要先获取原裁判信息,然后更新项目表中的裁判组
  310. const originalReferee = await getGameReferee(form.refereeId);
  311. const originalProjectList = originalReferee.data.projectList2 || [];
  312. const newProjectList = submitForm.projectList2 || [];
  313. // 获取当前项目列表中的项目ID集合
  314. // const currentProjectIds = new Set<string>(newProjectList.filter(id => id.trim()));
  315. // 获取原项目列表中的项目ID集合
  316. // const originalProjectIds = new Set<string>(originalProjectList.filter(id => id.trim()));
  317. // 筛选出在原项目列表中但不在当前项目列表中的项目(即被删除的项目)
  318. // const removedProjectIds = Array.from(currentProjectIds).filter(id => !originalProjectIds.has(id));
  319. const removedProjectIds = newProjectList.filter(id => !originalProjectList.includes(id));
  320. // 从被删除的项目中移除该裁判
  321. for (const projectId of removedProjectIds) {
  322. const projectRes = await getGameEventProject(projectId);
  323. if (projectRes) {
  324. const project = projectRes.data;
  325. let currentRefereeGroups = project.refereeGroups || [];
  326. // 从裁判组中移除该裁判ID
  327. if (currentRefereeGroups) {
  328. const refereeIds = currentRefereeGroups.filter(id => id.trim() !== String(form.refereeId));
  329. // 更新项目表中的裁判组字段
  330. await updateGameEventProject({
  331. ...project,
  332. refereeGroups: refereeIds
  333. });
  334. }
  335. }
  336. }
  337. // 向新项目中添加该裁判
  338. // const newProjectIds = Array.from<string>(currentProjectIds).filter(id => !originalProjectIds.has(
  339. const newProjectIds = newProjectList.filter(id => !originalProjectList.includes(id));
  340. for (const projectId of newProjectIds) {
  341. const projectRes = await getGameEventProject(projectId);
  342. if (projectRes) {
  343. const project = projectRes.data;
  344. let currentRefereeGroups = project.refereeGroups || [];
  345. // 如果该项目的裁判组中没有该裁判,则添加
  346. if(!project.refereeGroups.includes(String(form.refereeId))){
  347. currentRefereeGroups.push(String(form.refereeId)) ;
  348. await updateGameEventProject({
  349. ...project,
  350. refereeGroups: currentRefereeGroups
  351. });
  352. }
  353. }
  354. }
  355. await updateGameReferee(submitForm as GameRefereeForm);
  356. } else {
  357. // 新增裁判
  358. const refereeResult = await addGameReferee(submitForm as GameRefereeForm);
  359. // 获取新添加的裁判ID
  360. const newRefereeId = refereeResult.data?.refereeId || refereeResult.data;
  361. // 更新所选项目的裁判组字段
  362. if (newRefereeId && form.projectList2.length > 0) {
  363. for (const projectId of form.projectList2) {
  364. const projectRes = await getGameEventProject(projectId);
  365. if (projectRes) {
  366. const project = projectRes.data;
  367. let currentRefereeGroups = project.refereeGroups || [];
  368. currentRefereeGroups.push(String(newRefereeId));
  369. await updateGameEventProject({
  370. ...project,
  371. refereeGroups: currentRefereeGroups
  372. });
  373. }
  374. }
  375. }
  376. }
  377. proxy?.$modal.msgSuccess("操作成功");
  378. dialog.visible = false;
  379. await getList();
  380. } catch (error) {
  381. console.error('操作失败:', error);
  382. proxy?.$modal.msgError("操作失败");
  383. } finally {
  384. buttonLoading.value = false;
  385. }
  386. }
  387. }
  388. /** 删除按钮操作 */
  389. const handleDelete = async (row?: GameRefereeVO) => {
  390. const _refereeId = row?.refereeId || ids.value;
  391. await proxy?.$modal.confirm('是否确认删除裁判编号为"' + _refereeId + '"的数据项?').finally(() => loading.value = false);
  392. try {
  393. await delGameReferee(_refereeId);
  394. // 如果是单个删除,需要从项目表中移除该裁判
  395. if (row) {
  396. const refereeId = row.refereeId;
  397. if (row.projectList2) {
  398. const projectIds = row.projectList2.filter(id => id.trim());
  399. for (const projectId of projectIds) {
  400. // 获取当前项目信息
  401. const getProject = await getGameEventProject(projectId.trim());
  402. const project = getProject.data;
  403. if (project) {
  404. let currentRefereeGroups = project.refereeGroups || [];
  405. // 从裁判组中移除该裁判ID
  406. if (currentRefereeGroups) {
  407. const refereeIds = currentRefereeGroups.filter(id => id.trim() !== String(refereeId));
  408. // 更新项目表中的裁判组字段
  409. await updateGameEventProject({
  410. ...project,
  411. refereeGroups: refereeIds
  412. });
  413. }
  414. }
  415. }
  416. }
  417. }
  418. proxy?.$modal.msgSuccess("删除成功");
  419. await getList();
  420. } catch (error) {
  421. console.error('删除裁判失败:', error);
  422. proxy?.$modal.msgError("删除失败");
  423. }
  424. }
  425. /** 生成裁判二维码 */
  426. const handleGenerateQRCode = async (row: GameRefereeVO) => {
  427. currentReferee.value = row;
  428. // 生成二维码数据,可以包含裁判的基本信息
  429. const qrData = {
  430. eventId: row.eventId,
  431. refereeId: row.refereeId,
  432. name: row.name,
  433. account: row.account,
  434. password: row.password,
  435. projectList: row.projectList2,
  436. };
  437. try {
  438. qrCodeData.value = await toDataURL(JSON.stringify(qrData), { width: 200 });
  439. qrCodeDialog.visible = true;
  440. } catch (error) {
  441. proxy?.$modal.msgError("生成二维码失败");
  442. }
  443. };
  444. /** 下载二维码 */
  445. const handleDownloadQRCode = () => {
  446. if (!qrCodeData.value) return;
  447. const link = document.createElement('a');
  448. link.href = qrCodeData.value;
  449. link.download = `裁判二维码_${currentReferee.value.name}.png`;
  450. link.click();
  451. proxy?.$modal.msgSuccess("二维码下载成功");
  452. };
  453. /** 导出按钮操作 */
  454. const handleExport = () => {
  455. proxy?.download('system/gameReferee/export', {
  456. ...queryParams
  457. }, `gameReferee_${new Date().getTime()}.xlsx`)
  458. }
  459. onMounted(() => {
  460. getList();
  461. });
  462. </script>