|
@@ -80,7 +80,7 @@
|
|
|
<el-form-item label="赛事项目" prop="projectList2">
|
|
|
<!-- 赛事项目穿梭框 -->
|
|
|
<el-transfer
|
|
|
- v-model="form.projectList2"
|
|
|
+ v-model="projectList2Str"
|
|
|
:data="allProjects"
|
|
|
:titles="['可选项目', '已选项目']"
|
|
|
:button-texts="['移除', '添加']"
|
|
@@ -114,10 +114,9 @@
|
|
|
</template>
|
|
|
|
|
|
<script setup name="GameReferee" lang="ts">
|
|
|
-import { listGameReferee, getGameReferee, delGameReferee, addGameReferee, updateGameReferee } from '@/api/system/gameReferee';
|
|
|
+import { listGameReferee, getGameReferee, delGameReferee, addGameReferee, updateGameReferee, generateRefereeQRCode } 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;
|
|
|
|
|
@@ -133,7 +132,7 @@ const allProjects = ref<{key: string, label: string }[]>([]); // 添加项目数
|
|
|
|
|
|
// 列显隐数据
|
|
|
const columns = ref<FieldOption[]>([
|
|
|
- { key: 0, label: '裁判ID', visible: true },
|
|
|
+ { key: 0, label: '裁判ID', visible: false },
|
|
|
{ key: 1, label: '裁判姓名', visible: true },
|
|
|
{ key: 2, label: '账号', visible: true },
|
|
|
{ key: 3, label: '密码', visible: true },
|
|
@@ -176,7 +175,7 @@ const form = reactive({
|
|
|
account: undefined,
|
|
|
password: undefined,
|
|
|
// projectList: [] as string[], // 存储所负责的项目
|
|
|
- projectList2: [] as string[], // 存储所负责的项目
|
|
|
+ projectList2: [] as number[], // 存储所负责的项目
|
|
|
refereeCode: undefined,
|
|
|
createTime: undefined,
|
|
|
updateTime: undefined,
|
|
@@ -223,7 +222,7 @@ const getList = async () => {
|
|
|
|
|
|
// 从所有项目中筛选出在projectIds中存在的项目,并提取它们的label值(项目名称)
|
|
|
const projectNames = projectRes.rows
|
|
|
- .filter(project => projectIds.includes(String(project.projectId)))
|
|
|
+ .filter(project => projectIds.map(id => Number(id)).includes(Number(project.projectId)))
|
|
|
.map(project => project.projectName);
|
|
|
|
|
|
// 添加projectNameList属性到裁判对象中用于展示
|
|
@@ -260,6 +259,14 @@ const reset = () => {
|
|
|
gameRefereeFormRef.value?.resetFields();
|
|
|
}
|
|
|
|
|
|
+// 添加一个计算属性用于处理projectList2的类型转换
|
|
|
+const projectList2Str = computed({
|
|
|
+ get: () => form.projectList2.map(id => String(id)),
|
|
|
+ set: (value) => {
|
|
|
+ form.projectList2 = value.map(id => Number(id));
|
|
|
+ }
|
|
|
+});
|
|
|
+
|
|
|
/** 搜索按钮操作 */
|
|
|
const handleQuery = () => {
|
|
|
queryParams.pageNum = 1;
|
|
@@ -308,20 +315,18 @@ const handleUpdate = async (row?: GameRefereeVO) => {
|
|
|
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;
|
|
|
+ // 将数字数组转换为字符串数组,以匹配 allProjects 的 key 类型
|
|
|
+ form.projectList2 = res.data.projectList2.map(id => id);
|
|
|
} else {
|
|
|
form.projectList2 = [];
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
dialog.visible = true;
|
|
|
dialog.title = "修改裁判";
|
|
|
}
|
|
@@ -331,103 +336,23 @@ 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
|
|
|
- });
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ await addGameReferee(submitForm as GameRefereeForm);
|
|
|
}
|
|
|
|
|
|
proxy?.$modal.msgSuccess("操作成功");
|
|
|
dialog.visible = false;
|
|
|
await getList();
|
|
|
} catch (error) {
|
|
|
- console.error('操作失败:', error);
|
|
|
+ console.error("操作失败:", error);
|
|
|
proxy?.$modal.msgError("操作失败");
|
|
|
} finally {
|
|
|
buttonLoading.value = false;
|
|
@@ -447,11 +372,11 @@ const handleDelete = async (row?: GameRefereeVO) => {
|
|
|
if (row) {
|
|
|
const refereeId = row.refereeId;
|
|
|
if (row.projectList2) {
|
|
|
- const projectIds = row.projectList2.filter(id => id.trim());
|
|
|
+ const projectIds = row.projectList2.filter(id => id);
|
|
|
|
|
|
for (const projectId of projectIds) {
|
|
|
// 获取当前项目信息
|
|
|
- const getProject = await getGameEventProject(projectId.trim());
|
|
|
+ const getProject = await getGameEventProject(projectId);
|
|
|
const project = getProject.data;
|
|
|
if (project) {
|
|
|
|
|
@@ -459,7 +384,7 @@ const handleDelete = async (row?: GameRefereeVO) => {
|
|
|
|
|
|
// 从裁判组中移除该裁判ID
|
|
|
if (currentRefereeGroups) {
|
|
|
- const refereeIds = currentRefereeGroups.filter(id => id.trim() !== String(refereeId));
|
|
|
+ const refereeIds = currentRefereeGroups.filter(id => id !== refereeId);
|
|
|
// 更新项目表中的裁判组字段
|
|
|
await updateGameEventProject({
|
|
|
...project,
|
|
@@ -482,18 +407,12 @@ const handleDelete = async (row?: GameRefereeVO) => {
|
|
|
/** 生成裁判二维码 */
|
|
|
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 });
|
|
|
+ // 生成二维码数据
|
|
|
+ const res = await generateRefereeQRCode(row.refereeId);
|
|
|
+ qrCodeData.value = res.data;
|
|
|
+ console.log('二维码数据:', res);
|
|
|
qrCodeDialog.visible = true;
|
|
|
} catch (error) {
|
|
|
proxy?.$modal.msgError("生成二维码失败");
|
|
@@ -522,4 +441,4 @@ onMounted(() => {
|
|
|
getList();
|
|
|
});
|
|
|
|
|
|
-</script>
|
|
|
+</script>
|