index.vue 15 KB

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