index.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514
  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="teamName">
  8. <el-input v-model="queryParams.teamName" placeholder="请输入队伍名称" clearable @keyup.enter="handleQuery" />
  9. </el-form-item>
  10. <el-form-item label="队伍编号" prop="teamCode">
  11. <el-input v-model="queryParams.teamCode" placeholder="请输入队伍编号" clearable @keyup.enter="handleQuery" />
  12. </el-form-item>
  13. <el-form-item>
  14. <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
  15. <el-button icon="Refresh" @click="resetQuery">重置</el-button>
  16. </el-form-item>
  17. </el-form>
  18. </el-card>
  19. </div>
  20. </transition>
  21. <el-card shadow="never">
  22. <template #header>
  23. <el-row :gutter="10" class="mb8">
  24. <el-col :span="1.5">
  25. <el-button type="primary" plain icon="Plus" @click="handleAdd" v-hasPermi="['system:gameTeam:add']">新增</el-button>
  26. </el-col>
  27. <el-col :span="1.5">
  28. <el-button type="success" plain icon="Edit" :disabled="single" @click="handleUpdate()" v-hasPermi="['system:gameTeam:edit']">修改</el-button>
  29. </el-col>
  30. <el-col :span="1.5">
  31. <el-button type="danger" plain icon="Delete" :disabled="multiple" @click="handleDelete()" v-hasPermi="['system:gameTeam:remove']">删除</el-button>
  32. </el-col>
  33. <el-col :span="1.5">
  34. <el-button type="info" plain icon="Upload" @click="handleImport" v-hasPermi="['system:gameTeam:import']">导入</el-button>
  35. </el-col>
  36. <el-col :span="1.5">
  37. <el-button type="warning" plain icon="Download" @click="handleExport" v-hasPermi="['system:gameTeam:export']">导出</el-button>
  38. </el-col>
  39. <el-col :span="6" >
  40. <el-select v-model="selectedRankGroupId" placeholder="选择分组" clearable style="width: 100px;">
  41. <el-option
  42. v-for="item in rankGroupOptions"
  43. :key="item.value"
  44. :label="item.label"
  45. :value="item.value"
  46. />
  47. </el-select>
  48. <el-button
  49. type="warning"
  50. icon="Switch"
  51. :disabled="!selectedRankGroupId"
  52. @click="handleMoveGroup"
  53. v-hasPermi="['system:gameTeam:edit']"
  54. >
  55. 移动分组
  56. </el-button>
  57. </el-col>
  58. <right-toolbar v-model:showSearch="showSearch" :columns="columns" @queryTable="getList"></right-toolbar>
  59. </el-row>
  60. </template>
  61. <el-table v-loading="loading" border :data="gameTeamList" @selection-change="handleSelectionChange">
  62. <el-table-column type="selection" width="55" align="center" />
  63. <el-table-column label="队伍id" align="center" prop="teamId" v-if="columns[0].visible" />
  64. <el-table-column label="队伍编号" align="center" prop="teamCode" v-if="columns[1].visible" />
  65. <el-table-column label="赛事名称" align="center" prop="eventName" v-if="columns[2].visible" />
  66. <el-table-column label="队伍名称" align="center" prop="teamName" v-if="columns[3].visible" />
  67. <el-table-column label="分组名" align="center" prop="rgId" v-if="columns[4].visible">
  68. <template #default="scope">
  69. <span v-if="scope.row.rgId">{{ rankGroupMap.get(scope.row.rgId) }}</span>
  70. <span v-else style="color: #999;">未分组</span>
  71. </template>
  72. </el-table-column>
  73. <el-table-column label="团队描述" align="center" prop="teamDescribe" v-if="columns[5].visible">
  74. <template #default="scope">
  75. <span v-if="scope.row.teamDescribe">{{ scope.row.teamDescribe }}</span>
  76. <span v-else>该团队暂无描述</span>
  77. </template>
  78. </el-table-column>
  79. <el-table-column label="领队" align="center" prop="leader" v-if="columns[6].visible" />
  80. <el-table-column label="人数" align="center" prop="athleteNum" v-if="columns[7].visible" />
  81. <el-table-column label="号码段" align="center" prop="numberRange" v-if="columns[8].visible" />
  82. <el-table-column label="状态" align="center" prop="status" v-if="columns[9].visible">
  83. <template #default="scope">
  84. <dict-tag :options="sys_normal_disable" :value="scope.row.status" />
  85. </template>
  86. </el-table-column>
  87. <el-table-column label="备注" align="center" prop="remark" v-if="columns[10].visible" />
  88. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  89. <template #default="scope">
  90. <el-tooltip content="修改" placement="top">
  91. <el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)" v-hasPermi="['system:gameTeam:edit']"></el-button>
  92. </el-tooltip>
  93. <el-tooltip content="删除" placement="top">
  94. <el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)" v-hasPermi="['system:gameTeam:remove']"></el-button>
  95. </el-tooltip>
  96. </template>
  97. </el-table-column>
  98. </el-table>
  99. <pagination v-show="total > 0" :total="total" v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize" @pagination="getList" />
  100. </el-card>
  101. <!-- 添加或修改参赛队伍对话框 -->
  102. <el-dialog :title="dialog.title" v-model="dialog.visible" width="500px" append-to-body>
  103. <el-form ref="gameTeamFormRef" :model="form" :rules="rules" label-width="80px">
  104. <!-- <el-form-item label="赛事" prop="eventId">
  105. <el-select v-model="form.eventId" placeholder="请选择赛事" clearable filterable style="width: 100%">
  106. <el-option v-for="option in eventOptions" :key="option.value" :label="option.label" :value="option.value" />
  107. </el-select>
  108. </el-form-item> -->
  109. <el-form-item label="队伍名称" prop="teamName">
  110. <el-input v-model="form.teamName" placeholder="请输入队伍名称" />
  111. </el-form-item>
  112. <el-form-item label="队伍编号" prop="teamCode">
  113. <el-input v-model="form.teamCode" placeholder="请输入队伍编号" />
  114. </el-form-item>
  115. <el-form-item label="团队描述" prop="teamDescribe">
  116. <el-input v-model="form.teamDescribe" placeholder="请输入团队描述" />
  117. </el-form-item>
  118. </el-form>
  119. <template #footer>
  120. <div class="dialog-footer">
  121. <el-button :loading="buttonLoading" type="primary" @click="submitForm">确 定</el-button>
  122. <el-button @click="cancel">取 消</el-button>
  123. </div>
  124. </template>
  125. </el-dialog>
  126. <!-- 用户导入对话框 -->
  127. <el-dialog v-model="upload.open" :title="upload.title" width="400px" append-to-body>
  128. <el-upload
  129. ref="uploadRef"
  130. :limit="1"
  131. accept=".xlsx, .xls"
  132. :headers="upload.headers"
  133. :action="upload.url + '?updateSupport=' + upload.updateSupport"
  134. :disabled="upload.isUploading"
  135. :on-progress="handleFileUploadProgress"
  136. :on-success="handleFileSuccess"
  137. :auto-upload="false"
  138. drag
  139. >
  140. <el-icon class="el-icon--upload">
  141. <i-ep-upload-filled />
  142. </el-icon>
  143. <div class="el-upload__text">将文件拖到此处,或<em>点击上传</em></div>
  144. <template #tip>
  145. <div class="text-center el-upload__tip">
  146. <!-- <div class="el-upload__tip">-->
  147. <!-- <el-checkbox v-model="upload.updateSupport" />-->
  148. <!-- 是否更新已经存在的用户数据-->
  149. <!-- </div>-->
  150. <span>仅允许导入xls、xlsx格式文件。</span>
  151. <el-link type="primary" :underline="false" style="font-size: 12px; vertical-align: baseline" @click="importTemplate">下载模板 </el-link>
  152. </div>
  153. </template>
  154. </el-upload>
  155. <template #footer>
  156. <div class="dialog-footer">
  157. <el-button type="primary" @click="submitFileForm">确 定</el-button>
  158. <el-button @click="upload.open = false">取 消</el-button>
  159. </div>
  160. </template>
  161. </el-dialog>
  162. </div>
  163. </template>
  164. <script setup name="GameTeam" lang="ts">
  165. import { listGameTeam, getGameTeam, delGameTeam, addGameTeam, updateGameTeam, moveGroup } from '@/api/system/gameTeam';
  166. import { listRankGroup } from '@/api/system/rankGroup';
  167. import { GameTeamVO, GameTeamQuery, GameTeamForm } from '@/api/system/gameTeam/types';
  168. import { RankGroupVO } from '@/api/system/rankGroup/types';
  169. import { globalHeaders } from '@/utils/request';
  170. import { GameEventVO } from '@/api/system/gameEvent/types';
  171. import { orderBy } from 'element-plus/es/components/table/src/util';
  172. const { proxy } = getCurrentInstance() as ComponentInternalInstance;
  173. const { sys_normal_disable } = toRefs<any>(proxy?.useDict('sys_normal_disable'));
  174. const defaultEvent = ref<GameEventVO | null>(null); // 默认赛事信息
  175. const gameTeamList = ref<GameTeamVO[]>([]);
  176. const buttonLoading = ref(false);
  177. const loading = ref(true);
  178. const showSearch = ref(true);
  179. const ids = ref<Array<string | number>>([]);
  180. const single = ref(true);
  181. const multiple = ref(true);
  182. const total = ref(0);
  183. const eventOptions = ref<Array<{ label: string; value: string | number }>>([]);
  184. // 新增:排名分组相关
  185. const rankGroupOptions = ref<Array<{ label: string; value: string | number }>>([]);
  186. const selectedRankGroupId = ref<number | null>(null);
  187. // 列显隐数据
  188. const columns = ref<FieldOption[]>([
  189. { key: 0, label: '队伍id', visible: false },
  190. { key: 1, label: '队伍编号', visible: false },
  191. { key: 2, label: '赛事名称', visible: false },
  192. { key: 3, label: '队伍名称', visible: true },
  193. { key: 4, label: '排名分组名', visible: true }, // 新增
  194. { key: 5, label: '团队描述', visible: true },
  195. { key: 6, label: '领队', visible: true },
  196. { key: 7, label: '人数', visible: true },
  197. { key: 8, label: '号码段', visible: true },
  198. { key: 9, label: '状态', visible: false },
  199. { key: 10, label: '备注', visible: false }
  200. ]);
  201. const queryFormRef = ref<ElFormInstance>();
  202. const gameTeamFormRef = ref<ElFormInstance>();
  203. const uploadRef = ref<ElUploadInstance>();
  204. const dialog = reactive<DialogOption>({
  205. visible: false,
  206. title: ''
  207. });
  208. /*** 用户导入参数 */
  209. const upload = reactive<ImportOption>({
  210. // 是否显示弹出层(用户导入)
  211. open: false,
  212. // 弹出层标题(用户导入)
  213. title: '',
  214. // 是否禁用上传
  215. isUploading: false,
  216. // 是否更新已经存在的用户数据
  217. updateSupport: 0,
  218. // 设置上传的请求头部
  219. headers: globalHeaders(),
  220. // 上传的地址
  221. url: import.meta.env.VITE_APP_BASE_API + '/system/gameTeam/import'
  222. });
  223. const initFormData: GameTeamForm = {
  224. eventId: undefined,
  225. rgId:undefined,
  226. teamName: undefined,
  227. teamCode: undefined,
  228. leader: undefined,
  229. athleteValue: undefined,
  230. projectValue: undefined,
  231. athleteNum: undefined,
  232. numberRange: undefined,
  233. teamDescribe: undefined,
  234. status: undefined,
  235. remark: undefined,
  236. athleteList: []
  237. };
  238. const data = reactive<PageData<GameTeamForm, GameTeamQuery>>({
  239. form: { ...initFormData },
  240. queryParams: {
  241. pageNum: 1,
  242. pageSize: 10,
  243. eventId: undefined,
  244. orderByColumn: undefined,
  245. isAsc: undefined
  246. // teamName: undefined,
  247. // teamCode: undefined,
  248. // leader: undefined,
  249. // athleteValue: undefined,
  250. // projectValue: undefined,
  251. // athleteNum: undefined,
  252. // numberRange: undefined,
  253. // teamDescribe: undefined,
  254. // status: undefined,
  255. // params: {
  256. // }
  257. },
  258. rules: {
  259. teamName: [{ required: true, message: '队伍名称不能为空', trigger: 'blur' }],
  260. teamCode: [{ required: true, message: '队伍编号不能为空', trigger: 'blur' }],
  261. teamDescribe: [{ required: true, message: '团队描述不能为空', trigger: 'blur' }]
  262. }
  263. });
  264. const { queryParams, form, rules } = toRefs(data);
  265. // // 添加额外的ref用于处理默认事件ID
  266. // const defaultEventId = computed(() => defaultEvent.value?.eventId);
  267. // // 监听默认事件变化
  268. // watchEffect(() => {
  269. // if (defaultEventId.value) {
  270. // form.value.eventId = defaultEventId.value;
  271. // queryParams.value.eventId = defaultEventId.value;
  272. // }
  273. // });
  274. /** 获取默认赛事 */
  275. // const getDefaultEventInfo = async () => {
  276. // try {
  277. // const res = await getDefaultEvent();
  278. // defaultEvent.value = res.data;
  279. // } catch (error) {
  280. // proxy?.$modal.msgError('获取默认赛事信息失败');
  281. // }
  282. // };
  283. const rankGroupMap = computed(() => {
  284. const map = new Map();
  285. rankGroupOptions.value.forEach(option => {
  286. map.set(option.value, option.label);
  287. });
  288. return map;
  289. });
  290. /** 查询参赛队伍列表 */
  291. const getList = async () => {
  292. // if (!queryParams.value.eventId) {
  293. // proxy?.$modal.msgWarning('未获取到默认赛事信息');
  294. // loading.value = false;
  295. // return;
  296. // }
  297. loading.value = true;
  298. const res = await listGameTeam(queryParams.value);
  299. gameTeamList.value = res.rows;
  300. total.value = res.total;
  301. loading.value = false;
  302. };
  303. /** 获取赛事选项列表 */
  304. // const getEventOptions = async () => {
  305. // try {
  306. // const res = await getEventIdNameMap();
  307. // eventOptions.value = Object.entries(res.data).map(([key, value]) => ({
  308. // label: key as string,
  309. // value: value as string | number
  310. // }));
  311. // } catch (error) {
  312. // console.error('获取赛事列表失败:', error);
  313. // }
  314. // };
  315. /** 取消按钮 */
  316. const cancel = () => {
  317. reset();
  318. dialog.visible = false;
  319. };
  320. /** 表单重置 */
  321. const reset = () => {
  322. form.value = { ...initFormData };
  323. gameTeamFormRef.value?.resetFields();
  324. };
  325. /** 搜索按钮操作 */
  326. const handleQuery = () => {
  327. queryParams.value.pageNum = 1;
  328. getList();
  329. };
  330. /** 重置按钮操作 */
  331. const resetQuery = () => {
  332. queryFormRef.value?.resetFields();
  333. // 保留默认赛事ID
  334. // queryParams.value.eventId = defaultEvent.value?.eventId;
  335. handleQuery();
  336. };
  337. /** 多选框选中数据 */
  338. const handleSelectionChange = (selection: GameTeamVO[]) => {
  339. ids.value = selection.map((item) => item.teamId);
  340. single.value = selection.length != 1;
  341. multiple.value = !selection.length;
  342. // 如果没有选中队伍,清空选择的分组
  343. if (selection.length === 0) {
  344. selectedRankGroupId.value = null;
  345. }
  346. };
  347. /** 新增:获取排名分组选项列表 */
  348. const getRankGroupOptions = async () => {
  349. try {
  350. const res = await listRankGroup({
  351. pageNum: 1,
  352. pageSize: 1000, // 获取所有排名分组
  353. eventId: queryParams.value.eventId,
  354. orderByColumn: undefined,
  355. isAsc: undefined,
  356. });
  357. rankGroupOptions.value = res.rows.map(item => ({
  358. label: item.rgName,
  359. value: item.rgId
  360. }));
  361. } catch (error) {
  362. console.error('获取排名分组列表失败:', error);
  363. }
  364. };
  365. /** 新增:移动分组操作 */
  366. const handleMoveGroup = async () => {
  367. if (!selectedRankGroupId.value) {
  368. proxy?.$modal.msgWarning('请选择目标排名分组');
  369. return;
  370. }
  371. if (ids.value.length === 0) {
  372. proxy?.$modal.msgWarning('请选择要移动的队伍');
  373. return;
  374. }
  375. try {
  376. await proxy?.$modal.confirm(`确认将选中的 ${ids.value.length} 个队伍移动到选定的排名分组吗?`);
  377. loading.value = true;
  378. await moveGroup({
  379. teamIds: ids.value,
  380. rgId: selectedRankGroupId.value
  381. });
  382. proxy?.$modal.msgSuccess('移动分组成功');
  383. selectedRankGroupId.value = null;
  384. await getList();
  385. } catch (error) {
  386. console.error('移动分组失败:', error);
  387. } finally {
  388. loading.value = false;
  389. }
  390. };
  391. /** 新增按钮操作 */
  392. const handleAdd = () => {
  393. reset();
  394. dialog.visible = true;
  395. dialog.title = '添加参赛队伍';
  396. };
  397. /** 修改按钮操作 */
  398. const handleUpdate = async (row?: GameTeamVO) => {
  399. reset();
  400. const _teamId = row?.teamId || ids.value[0];
  401. const res = await getGameTeam(_teamId);
  402. Object.assign(form.value, res.data);
  403. dialog.visible = true;
  404. dialog.title = '修改参赛队伍';
  405. };
  406. /** 提交按钮 */
  407. const submitForm = () => {
  408. gameTeamFormRef.value?.validate(async (valid: boolean) => {
  409. if (valid) {
  410. buttonLoading.value = true;
  411. if (form.value.teamId) {
  412. await updateGameTeam(form.value).finally(() => (buttonLoading.value = false));
  413. } else {
  414. await addGameTeam(form.value).finally(() => (buttonLoading.value = false));
  415. }
  416. proxy?.$modal.msgSuccess('操作成功');
  417. dialog.visible = false;
  418. await getList();
  419. }
  420. });
  421. };
  422. /** 删除按钮操作 */
  423. const handleDelete = async (row?: GameTeamVO) => {
  424. const _teamIds = row?.teamId || ids.value;
  425. await proxy?.$modal.confirm('是否确认删除参赛队伍编号为"' + _teamIds + '"的数据项?').finally(() => (loading.value = false));
  426. await delGameTeam(_teamIds);
  427. proxy?.$modal.msgSuccess('删除成功');
  428. await getList();
  429. };
  430. /** 导出按钮操作 */
  431. const handleExport = () => {
  432. proxy?.download(
  433. 'system/gameTeam/export',
  434. {
  435. ...queryParams.value
  436. },
  437. `队伍详情_${new Date().getTime()}.xlsx`
  438. );
  439. };
  440. /** 导入按钮操作 */
  441. const handleImport = () => {
  442. upload.title = '参赛队伍导入';
  443. upload.open = true;
  444. };
  445. /**文件上传中处理 */
  446. const handleFileUploadProgress = () => {
  447. upload.isUploading = true;
  448. };
  449. /** 文件上传成功处理 */
  450. const handleFileSuccess = (response: any, file: UploadFile) => {
  451. upload.open = false;
  452. upload.isUploading = false;
  453. uploadRef.value?.handleRemove(file);
  454. ElMessageBox.alert("<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" + response.msg + '</div>', '导入结果', {
  455. dangerouslyUseHTMLString: true
  456. });
  457. getList();
  458. };
  459. /** 提交上传文件 */
  460. function submitFileForm() {
  461. uploadRef.value?.submit();
  462. }
  463. /** 下载模板操作 */
  464. const importTemplate = () => {
  465. proxy?.download('system/gameTeam/importTemplate', {}, `game_event_template_${new Date().getTime()}.xlsx`);
  466. };
  467. onMounted(() => {
  468. getList();
  469. getRankGroupOptions(); // 新增
  470. });
  471. </script>