添加内容过滤功能
This commit is contained in:
@@ -13,7 +13,7 @@ import {
|
||||
} from "../../config/formSchema/publishBallFormSchema";
|
||||
import { PublishBallFormData } from "../../../types/publishBall";
|
||||
import PublishService from "@/services/publishService";
|
||||
import { getNextHourTime, getEndTime, delay } from "@/utils";
|
||||
import { getNextHourTime, getEndTime, delay, getBackendErrorMsg } from "@/utils";
|
||||
import { useGlobalState } from "@/store/global";
|
||||
import GeneralNavbar from "@/components/GeneralNavbar";
|
||||
import images from "@/config/images";
|
||||
@@ -364,104 +364,27 @@ const PublishBall: React.FC = () => {
|
||||
};
|
||||
// 提交表单
|
||||
const handleSubmit = async () => {
|
||||
// 基础验证
|
||||
const params = getParams();
|
||||
const { republish } = params || {};
|
||||
if (activityType === "individual") {
|
||||
const isValid = validateFormData(formData[0]);
|
||||
if (!isValid || publishLoading) {
|
||||
return;
|
||||
}
|
||||
if (!isValid || publishLoading) return;
|
||||
setPublishLoading(true);
|
||||
const {
|
||||
activityInfo,
|
||||
descriptionInfo,
|
||||
is_substitute_supported,
|
||||
timeRange,
|
||||
players,
|
||||
skill_level,
|
||||
image_list,
|
||||
wechat,
|
||||
id,
|
||||
...rest
|
||||
} = formData[0];
|
||||
const { min, max, organizer_joined } = players;
|
||||
const options = {
|
||||
...rest,
|
||||
...activityInfo,
|
||||
...descriptionInfo,
|
||||
...timeRange,
|
||||
max_players: max,
|
||||
min_players: min,
|
||||
organizer_joined: organizer_joined === true ? 1 : 0,
|
||||
skill_level_min: skill_level[0],
|
||||
skill_level_max: skill_level[1],
|
||||
image_list: image_list.map((item) => item.url),
|
||||
is_wechat_contact: wechat.is_wechat_contact ? 1 : 0,
|
||||
wechat_contact: wechat.wechat_contact || wechat.default_wechat_contact,
|
||||
is_substitute_supported: is_substitute_supported ? "1" : "0",
|
||||
...(republish === "0" ? { id } : {}),
|
||||
};
|
||||
const res =
|
||||
republish === "0"
|
||||
? await PublishService.gamesUpdate(options)
|
||||
: await PublishService.createPersonal(options);
|
||||
const successText = republish === "0" ? "更新成功" : "发布成功";
|
||||
if (res.code === 0 && res.data) {
|
||||
Taro.showToast({
|
||||
title: successText,
|
||||
icon: "success",
|
||||
});
|
||||
delay(1000);
|
||||
// 如果是个人球局,则跳转到详情页,并自动分享
|
||||
// 如果是畅打,则跳转第一个球局详情页,并自动分享 @刘杰
|
||||
const id = (res as any).data?.id;
|
||||
// 如果是编辑,就返回,否则就是新发布
|
||||
if (republish === "0") {
|
||||
Taro.navigateBack();
|
||||
} else {
|
||||
// 使用 redirectTo 替换当前页面,避免返回时回到发布页面
|
||||
Taro.redirectTo({
|
||||
// @ts-expect-error: id
|
||||
url: `/game_pages/detail/index?id=${
|
||||
id || 1
|
||||
}&from=publish&autoShare=1`,
|
||||
});
|
||||
}
|
||||
} else {
|
||||
Taro.showToast({
|
||||
title: res.message,
|
||||
icon: "none",
|
||||
});
|
||||
setPublishLoading(false);
|
||||
}
|
||||
}
|
||||
if (activityType === "group") {
|
||||
const isValid = formData.every((item) => validateFormData(item));
|
||||
if (!isValid || publishLoading) {
|
||||
return;
|
||||
}
|
||||
setPublishLoading(true);
|
||||
if (checkAdjacentDataSame(formData)) {
|
||||
Taro.showToast({
|
||||
title: "信息不可与前序场完全一致",
|
||||
icon: "none",
|
||||
});
|
||||
return;
|
||||
}
|
||||
const options = formData.map((item) => {
|
||||
try {
|
||||
const {
|
||||
activityInfo,
|
||||
descriptionInfo,
|
||||
is_substitute_supported,
|
||||
timeRange,
|
||||
players,
|
||||
skill_level,
|
||||
is_substitute_supported,
|
||||
image_list,
|
||||
wechat,
|
||||
id,
|
||||
...rest
|
||||
} = item;
|
||||
} = formData[0];
|
||||
const { min, max, organizer_joined } = players;
|
||||
return {
|
||||
const options = {
|
||||
...rest,
|
||||
...activityInfo,
|
||||
...descriptionInfo,
|
||||
@@ -471,38 +394,108 @@ const PublishBall: React.FC = () => {
|
||||
organizer_joined: organizer_joined === true ? 1 : 0,
|
||||
skill_level_min: skill_level[0],
|
||||
skill_level_max: skill_level[1],
|
||||
image_list: image_list.map((item) => item.url),
|
||||
is_wechat_contact: wechat.is_wechat_contact ? 1 : 0,
|
||||
wechat_contact: wechat.wechat_contact || wechat.default_wechat_contact,
|
||||
is_substitute_supported: is_substitute_supported ? "1" : "0",
|
||||
image_list: item.image_list.map((img) => img.url),
|
||||
...(republish === "0" ? { id } : {}),
|
||||
};
|
||||
});
|
||||
const successText = republish === "0" ? "更新成功" : "发布成功";
|
||||
const res =
|
||||
republish === "0"
|
||||
? await PublishService.gamesUpdate(options[0])
|
||||
: await PublishService.create_play_pmoothlys({ rows: options });
|
||||
if (res.code === 0 && res.data) {
|
||||
Taro.showToast({
|
||||
title: successText,
|
||||
icon: "success",
|
||||
});
|
||||
delay(1000);
|
||||
// 如果是个人球局,则跳转到详情页,并自动分享
|
||||
// 如果是畅打,则跳转第一个球局详情页,并自动分享 @刘杰
|
||||
const id =
|
||||
const res =
|
||||
republish === "0"
|
||||
? (res as any).data?.id
|
||||
: (res as any).data?.[0]?.id;
|
||||
// 使用 redirectTo 替换当前页面,避免返回时回到发布页面
|
||||
Taro.redirectTo({
|
||||
// @ts-expect-error: id
|
||||
url: `/game_pages/detail/index?id=${
|
||||
id || 1
|
||||
}&from=publish&autoShare=1`,
|
||||
});
|
||||
} else {
|
||||
? await PublishService.gamesUpdate(options)
|
||||
: await PublishService.createPersonal(options);
|
||||
const successText = republish === "0" ? "更新成功" : "发布成功";
|
||||
if (res.code === 0 && res.data) {
|
||||
Taro.showToast({ title: successText, icon: "success" });
|
||||
delay(1000);
|
||||
const id = (res as any).data?.id;
|
||||
if (republish === "0") {
|
||||
Taro.navigateBack();
|
||||
} else {
|
||||
Taro.redirectTo({
|
||||
url: `/game_pages/detail/index?id=${id || 1}&from=publish&autoShare=1`,
|
||||
});
|
||||
}
|
||||
} else {
|
||||
Taro.showToast({
|
||||
title: getBackendErrorMsg(res, "发布失败"),
|
||||
icon: "none",
|
||||
});
|
||||
setPublishLoading(false);
|
||||
}
|
||||
} catch (error) {
|
||||
Taro.showToast({
|
||||
title: res.message,
|
||||
title: getBackendErrorMsg(error, "发布失败"),
|
||||
icon: "none",
|
||||
});
|
||||
setPublishLoading(false);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (activityType === "group") {
|
||||
const isValid = formData.every((item) => validateFormData(item));
|
||||
if (!isValid || publishLoading) return;
|
||||
if (checkAdjacentDataSame(formData)) {
|
||||
Taro.showToast({
|
||||
title: "信息不可与前序场完全一致",
|
||||
icon: "none",
|
||||
});
|
||||
return;
|
||||
}
|
||||
setPublishLoading(true);
|
||||
try {
|
||||
const options = formData.map((item) => {
|
||||
const {
|
||||
activityInfo,
|
||||
descriptionInfo,
|
||||
timeRange,
|
||||
players,
|
||||
skill_level,
|
||||
is_substitute_supported,
|
||||
id,
|
||||
...rest
|
||||
} = item;
|
||||
const { min, max, organizer_joined } = players;
|
||||
return {
|
||||
...rest,
|
||||
...activityInfo,
|
||||
...descriptionInfo,
|
||||
...timeRange,
|
||||
max_players: max,
|
||||
min_players: min,
|
||||
organizer_joined: organizer_joined === true ? 1 : 0,
|
||||
skill_level_min: skill_level[0],
|
||||
skill_level_max: skill_level[1],
|
||||
is_substitute_supported: is_substitute_supported ? "1" : "0",
|
||||
image_list: item.image_list.map((img) => img.url),
|
||||
...(republish === "0" ? { id } : {}),
|
||||
};
|
||||
});
|
||||
const successText = republish === "0" ? "更新成功" : "发布成功";
|
||||
const res =
|
||||
republish === "0"
|
||||
? await PublishService.gamesUpdate(options[0])
|
||||
: await PublishService.create_play_pmoothlys({ rows: options });
|
||||
if (res.code === 0 && res.data) {
|
||||
Taro.showToast({ title: successText, icon: "success" });
|
||||
delay(1000);
|
||||
const id =
|
||||
republish === "0"
|
||||
? (res as any).data?.id
|
||||
: (res as any).data?.[0]?.id;
|
||||
Taro.redirectTo({
|
||||
url: `/game_pages/detail/index?id=${id || 1}&from=publish&autoShare=1`,
|
||||
});
|
||||
} else {
|
||||
Taro.showToast({
|
||||
title: getBackendErrorMsg(res, "发布失败"),
|
||||
icon: "none",
|
||||
});
|
||||
setPublishLoading(false);
|
||||
}
|
||||
} catch (error) {
|
||||
Taro.showToast({
|
||||
title: getBackendErrorMsg(error, "发布失败"),
|
||||
icon: "none",
|
||||
});
|
||||
setPublishLoading(false);
|
||||
|
||||
Reference in New Issue
Block a user