index.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434
  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"></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="eventId" /> -->
  39. <el-table-column label="裁判ID" align="center" prop="refereeId" v-if="true" />
  40. <el-table-column label="裁判姓名" align="center" prop="name" />
  41. <el-table-column label="账号" align="center" prop="account" />
  42. <el-table-column label="密码" align="center" prop="password" />
  43. <!-- <el-table-column label="组别" align="center" prop="groupList" /> -->
  44. <el-table-column label="项目" align="center">
  45. <template #default="scope">
  46. <span>{{ scope.row.projectNameList || '无' }}</span>
  47. </template>
  48. </el-table-column>
  49. <!-- <el-table-column label="裁判码" align="center" prop="refereeCode" /> -->
  50. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  51. <template #default="scope">
  52. <el-tooltip content="修改" placement="top">
  53. <el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)" v-hasPermi="['system:gameReferee:edit']"></el-button>
  54. </el-tooltip>
  55. <el-tooltip content="删除" placement="top">
  56. <el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)" v-hasPermi="['system:gameReferee:remove']"></el-button>
  57. </el-tooltip>
  58. <el-tooltip content="生成二维码" placement="top">
  59. <el-button link type="primary" icon="FullScreen" @click="handleGenerateQRCode(scope.row)" v-hasPermi="['system:gameReferee:edit']">
  60. 裁判码
  61. </el-button>
  62. </el-tooltip>
  63. </template>
  64. </el-table-column>
  65. </el-table>
  66. <pagination v-show="total > 0" :total="total" v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize" @pagination="getList" />
  67. </el-card>
  68. <!-- 添加或修改裁判对话框 -->
  69. <el-dialog :title="dialog.title" v-model="dialog.visible" width="800px" append-to-body>
  70. <el-form ref="gameRefereeFormRef" :model="form" :rules="rules" label-width="80px">
  71. <el-form-item label="裁判姓名" prop="name">
  72. <el-input v-model="form.name" placeholder="请输入裁判姓名" />
  73. </el-form-item>
  74. <el-form-item label="账号" prop="account">
  75. <el-input v-model="form.account" placeholder="请输入账号" />
  76. </el-form-item>
  77. <el-form-item label="密码" prop="password">
  78. <el-input v-model="form.password" placeholder="请输入密码" />
  79. </el-form-item>
  80. <el-form-item label="赛事项目" prop="projectList">
  81. <!-- 赛事项目穿梭框 -->
  82. <el-transfer
  83. v-model="form.projectList"
  84. :data="allProjects"
  85. :titles="['可选项目', '已选项目']"
  86. :button-texts="['移除', '添加']"
  87. style="width: 100%"
  88. />
  89. </el-form-item>
  90. </el-form>
  91. <template #footer>
  92. <div class="dialog-footer">
  93. <el-button type="primary" @click="submitForm">确 定</el-button>
  94. <el-button @click="cancel">取 消</el-button>
  95. </div>
  96. </template>
  97. </el-dialog>
  98. <!-- 二维码对话框 -->
  99. <el-dialog :title="qrCodeDialog.title" v-model="qrCodeDialog.visible" width="400px" append-to-body>
  100. <div class="qr-code-container" style="text-align: center; padding: 20px;">
  101. <img :src="qrCodeData" alt="QR Code" v-if="qrCodeData" style="width: 200px; height: 200px;" />
  102. <p style="margin-top: 15px;">裁判: {{ currentReferee.name }}</p>
  103. <p>账号: {{ currentReferee.account }}</p>
  104. </div>
  105. <template #footer>
  106. <div class="dialog-footer">
  107. <el-button type="primary" @click="handleDownloadQRCode">下载二维码</el-button>
  108. <el-button @click="qrCodeDialog.visible = false">关闭</el-button>
  109. </div>
  110. </template>
  111. </el-dialog>
  112. </div>
  113. </template>
  114. <script setup name="GameReferee" lang="ts">
  115. import { listGameReferee, getGameReferee, delGameReferee, addGameReferee, updateGameReferee } from '@/api/system/gameReferee';
  116. import { listGameEventProject } from '@/api/system/gameEventProject';
  117. import { GameRefereeVO, GameRefereeQuery, GameRefereeForm } from '@/api/system/gameReferee/types';
  118. import { toDataURL } from 'qrcode';
  119. import { getDefaultEvent } from '@/api/system/gameEvent';
  120. import { GameEventVO } from '@/api/system/gameEvent/types';
  121. const { proxy } = getCurrentInstance() as ComponentInternalInstance;
  122. const defaultEvent = ref<GameEventVO | null>(null); // 默认赛事信息
  123. const gameRefereeList = ref<GameRefereeVOExt[]>([]);
  124. const buttonLoading = ref(false);
  125. const loading = ref(true);
  126. const showSearch = ref(true);
  127. const ids = ref<Array<string | number>>([]);
  128. const single = ref(true);
  129. const multiple = ref(true);
  130. const total = ref(0);
  131. const allProjects = ref<{key: string, label: string }[]>([]); // 添加项目数据
  132. const queryFormRef = ref<ElFormInstance>();
  133. const gameRefereeFormRef = ref<ElFormInstance>();
  134. const showList = reactive({
  135. projectNameList: [],
  136. groupList: []
  137. });
  138. // 二维码对话框数据
  139. const qrCodeDialog = reactive({
  140. visible: false,
  141. title: '裁判二维码'
  142. });
  143. const currentReferee = ref<GameRefereeVO>({} as GameRefereeVO);
  144. const qrCodeData = ref('');
  145. // 扩展GameRefereeVO类型,添加用于展示的projectNameList属性
  146. interface GameRefereeVOExt extends GameRefereeVO {
  147. projectNameList?: string;
  148. }
  149. const dialog = reactive<DialogOption>({
  150. visible: false,
  151. title: ''
  152. });
  153. // 定义表单数据结构,参考athlete.vue的实现方式
  154. const form = reactive({
  155. refereeId: undefined as string | number | undefined,
  156. eventId: undefined as string | number | undefined,
  157. name: '',
  158. groupName: '',
  159. account: '',
  160. password: '',
  161. projectList: [] as string[], // 存储所负责的项目
  162. refereeCode: '',
  163. createTime: '',
  164. updateTime: ''
  165. });
  166. const queryParams = reactive<GameRefereeQuery>({
  167. pageNum: 1,
  168. pageSize: 10,
  169. eventId: undefined,
  170. name: undefined,
  171. params: {}
  172. });
  173. const rules = {
  174. account: [
  175. { required: true, message: "账号不能为空", trigger: "blur" }
  176. ],
  177. password: [
  178. { required: true, message: "密码不能为空", trigger: "blur" }
  179. ],
  180. }
  181. // 添加额外的ref用于处理默认事件ID
  182. const defaultEventId = computed(() => defaultEvent.value?.eventId);
  183. // 监听默认事件变化
  184. watchEffect(() => {
  185. if (defaultEventId.value) {
  186. form.eventId = defaultEventId.value;
  187. queryParams.eventId = defaultEventId.value;
  188. }
  189. });
  190. /** 获取默认赛事 */
  191. const getDefaultEventInfo = async () => {
  192. try {
  193. const res = await getDefaultEvent();
  194. defaultEvent.value = res.data;
  195. } catch (error) {
  196. proxy?.$modal.msgError('获取默认赛事信息失败');
  197. }
  198. };
  199. /** 查询裁判列表 */
  200. const getList = async () => {
  201. if (!queryParams.eventId) {
  202. proxy?.$modal.msgWarning('未获取到默认赛事信息');
  203. loading.value = false;
  204. return;
  205. }
  206. loading.value = true;
  207. const res = await listGameReferee(queryParams);
  208. // 为每个裁判添加项目名称列表用于展示
  209. for (const referee of res.rows) {
  210. if (referee.projectList) {
  211. // 加载该项目对应的赛事的所有项目信息
  212. const projectRes = await listGameEventProject({
  213. eventId: referee.eventId,
  214. pageNum: 1,
  215. pageSize: 1000
  216. });
  217. // 获取项目ID数组
  218. const projectIds = referee.projectList.split(',').filter(id => id);
  219. // 从所有项目中筛选出在projectIds中存在的项目,并提取它们的label值(项目名称)
  220. const projectNames = projectRes.rows
  221. .filter(project => projectIds.includes(String(project.projectId)))
  222. .map(project => project.projectName);
  223. // 添加projectNameList属性到裁判对象中用于展示
  224. (referee as any).projectNameList = projectNames.join(', ');
  225. }
  226. }
  227. gameRefereeList.value = res.rows as GameRefereeVOExt[];
  228. total.value = res.total;
  229. loading.value = false;
  230. }
  231. /** 取消按钮 */
  232. const cancel = () => {
  233. reset();
  234. dialog.visible = false;
  235. }
  236. /** 表单重置 */
  237. const reset = () => {
  238. Object.assign(form, {
  239. refereeId: undefined,
  240. eventId: undefined,
  241. name: '',
  242. groupName: '',
  243. account: '',
  244. password: '',
  245. projectList: [],
  246. refereeCode: '',
  247. createTime: '',
  248. updateTime: ''
  249. });
  250. gameRefereeFormRef.value?.resetFields();
  251. }
  252. /** 搜索按钮操作 */
  253. const handleQuery = () => {
  254. queryParams.pageNum = 1;
  255. getList();
  256. }
  257. /** 重置按钮操作 */
  258. const resetQuery = () => {
  259. queryFormRef.value?.resetFields();
  260. // 保留默认赛事ID
  261. queryParams.eventId = defaultEvent.value?.eventId;
  262. handleQuery();
  263. }
  264. /** 多选框选中数据 */
  265. const handleSelectionChange = (selection: GameRefereeVO[]) => {
  266. ids.value = selection.map(item => item.refereeId);
  267. single.value = selection.length != 1;
  268. multiple.value = !selection.length;
  269. }
  270. /** 获取赛事项目列表 */
  271. const loadProjects = async (eventId: string | number) => {
  272. // if (!eventId) {
  273. // allProjects.value = [];
  274. // return;
  275. // }
  276. const res = await listGameEventProject({
  277. eventId: eventId,
  278. pageNum: 1,
  279. pageSize: 1000
  280. });
  281. // 赛事项目穿梭框可选数据拼接
  282. allProjects.value = res.rows.map(item => ({
  283. key: String(item.projectId),
  284. label: `${item.projectName}-${item.groupType}` // 根据规范,只显示项目名称,不拼接组别
  285. }));
  286. };
  287. /** 新增按钮操作 */
  288. const handleAdd = async () => {
  289. reset();
  290. // 监听赛事ID变化,加载对应项目
  291. watch(() => form.eventId, async (newVal) => {
  292. await loadProjects(newVal);
  293. }, { once: true });
  294. dialog.visible = true;
  295. dialog.title = "添加裁判";
  296. }
  297. /** 修改按钮操作 */
  298. const handleUpdate = async (row?: GameRefereeVO) => {
  299. reset();
  300. const _refereeId = row?.refereeId || ids.value[0]
  301. const res = await getGameReferee(_refereeId);
  302. Object.assign(form, res.data);
  303. // 如果是修改操作,先加载项目列表
  304. await loadProjects(form.eventId);
  305. // 处理项目列表数据格式,参考athlete.vue的实现方式
  306. if (res.data.projectList && typeof res.data.projectList === 'string') {
  307. form.projectList = res.data.projectList.split(',').filter(id => id);
  308. } else if (Array.isArray(res.data.projectList)) {
  309. form.projectList = res.data.projectList;
  310. } else {
  311. form.projectList = [];
  312. }
  313. dialog.visible = true;
  314. dialog.title = "修改裁判";
  315. }
  316. /** 提交按钮 */
  317. const submitForm = async () => {
  318. const valid = await gameRefereeFormRef.value?.validate();
  319. if (valid) {
  320. buttonLoading.value = true;
  321. // 提交前处理项目列表数据格式,参考athlete.vue的实现方式
  322. const submitForm: any = { ...form };
  323. if (Array.isArray(form.projectList)) {
  324. submitForm.projectList = form.projectList.join(',');
  325. }
  326. try {
  327. if (form.refereeId) {
  328. await updateGameReferee(submitForm as GameRefereeForm);
  329. } else {
  330. await addGameReferee(submitForm as GameRefereeForm);
  331. }
  332. proxy?.$modal.msgSuccess("操作成功");
  333. dialog.visible = false;
  334. await getList();
  335. } finally {
  336. buttonLoading.value = false;
  337. }
  338. }
  339. }
  340. /** 删除按钮操作 */
  341. const handleDelete = async (row?: GameRefereeVO) => {
  342. const _refereeIds = row?.refereeId || ids.value;
  343. await proxy?.$modal.confirm('是否确认删除裁判编号为"' + _refereeIds + '"的数据项?').finally(() => loading.value = false);
  344. await delGameReferee(_refereeIds);
  345. proxy?.$modal.msgSuccess("删除成功");
  346. await getList();
  347. }
  348. /** 生成裁判二维码 */
  349. const handleGenerateQRCode = async (row: GameRefereeVO) => {
  350. currentReferee.value = row;
  351. // 生成二维码数据,可以包含裁判的基本信息
  352. const qrData = {
  353. eventId: row.eventId,
  354. refereeId: row.refereeId,
  355. name: row.name,
  356. account: row.account,
  357. password: row.password,
  358. projectList: row.projectList,
  359. };
  360. try {
  361. qrCodeData.value = await toDataURL(JSON.stringify(qrData), { width: 200 });
  362. qrCodeDialog.visible = true;
  363. } catch (error) {
  364. proxy?.$modal.msgError("生成二维码失败");
  365. }
  366. };
  367. /** 下载二维码 */
  368. const handleDownloadQRCode = () => {
  369. if (!qrCodeData.value) return;
  370. const link = document.createElement('a');
  371. link.href = qrCodeData.value;
  372. link.download = `裁判二维码_${currentReferee.value.name}.png`;
  373. link.click();
  374. proxy?.$modal.msgSuccess("二维码下载成功");
  375. };
  376. /** 导出按钮操作 */
  377. const handleExport = () => {
  378. proxy?.download('system/gameReferee/export', {
  379. ...queryParams
  380. }, `gameReferee_${new Date().getTime()}.xlsx`)
  381. }
  382. onMounted(() => {
  383. getDefaultEventInfo().then(() => {
  384. getList();
  385. });
  386. });
  387. </script>