import React, { useState } from "react";
import {
Form,
Input,
Button,
Space,
Table,
Checkbox,
InputNumber,
Image,
} from "antd";
import Modal from "../../components/Modal";
import VideoUploader from "../../components/VideoUploader";
import ImageUploader from "../../components/ImageUploader";
import baseRequest from "../../utils/baseRequest";
//tab内容
const StreamerInformationContent = () => {
const { TextArea } = Input;
//展示的表头
const [showColumns, setShowColumns] = useState([
"baseInfo",
"displayInfo",
"displayPoster",
"displayVideo",
"displayGallery",
]);
//动态的表头
const dynamicColumns = showColumns.map((item) => {
switch (item) {
case "baseInfo":
return {
title: "基础信息",
dataIndex: "baseInfo",
key: "baseInfo",
render: (data) => (
ID:{data.id}
昵称:{data.name}
入驻时间:{data.joinTime}
),
};
case "displayInfo":
return {
title: "个人展示信息",
dataIndex: "displayInfo",
key: "displayInfo",
render: (data) => (
性别:
{data.gender === 1 ? "女" : "男"}
全网粉丝:{data.fans}万
微信添加方式:
{data.wechat_lock_type === 1 ? "主动添加" : "直接展示"}
微信:
{data.wechat ? data.wechat : "空"}
微信价格:
¥{data.wechat_price / 10}
个性签名:{data.signature}
私信自动回复:
{data.auto_response_message}
年龄:{data.age}
身高:{data.height}
体重:{data.weight}
星座:{data.constellation}
居住地:{data.location}
),
};
case "displayPoster":
return {
title: "封面图片",
dataIndex: "displayPoster",
key: "displayPoster",
render: (data) => ,
};
case "displayVideo":
return {
title: "封面视频",
dataIndex: "displayVideo",
key: "displayVideo",
render: (data) => (
),
};
case "displayGallery":
return {
title: "相册",
dataIndex: "displayGallery",
key: "displayGallery",
render: (data) => (
{data.map((item) => (
))}
),
};
default:
return {};
}
});
dynamicColumns.push({
title: "操作",
dataIndex: "opeartion",
key: "opeartion",
render: (_, record) => (
),
});
//modal中select选项
const constellations = [
{ label: "白羊座", value: "白羊座" },
{ label: "金牛座", value: "金牛座" },
{ label: "双子座", value: "双子座" },
{ label: "巨蟹座", value: "巨蟹座" },
{ label: "狮子座", value: "狮子座" },
{ label: "处女座", value: "处女座" },
{ label: "天秤座", value: "天秤座" },
{ label: "天蝎座", value: "天蝎座" },
{ label: "射手座", value: "射手座" },
{ label: "摩羯座", value: "摩羯座" },
{ label: "水瓶座", value: "水瓶座" },
{ label: "双鱼座", value: "双鱼座" },
];
const provinces = [
{ label: "北京市", value: "北京市" },
{ label: "天津市", value: "天津市" },
{ label: "河北省", value: "河北省" },
{ label: "山西省", value: "山西省" },
{ label: "内蒙古自治区", value: "内蒙古自治区" },
{ label: "辽宁省", value: "辽宁省" },
{ label: "吉林省", value: "吉林省" },
{ label: "黑龙江省", value: "黑龙江省" },
{ label: "上海市", value: "上海市" },
{ label: "江苏省", value: "江苏省" },
{ label: "浙江省", value: "浙江省" },
{ label: "安徽省", value: "安徽省" },
{ label: "福建省", value: "福建省" },
{ label: "江西省", value: "江西省" },
{ label: "山东省", value: "山东省" },
{ label: "河南省", value: "河南省" },
{ label: "湖北省", value: "湖北省" },
{ label: "湖南省", value: "湖南省" },
{ label: "广东省", value: "广东省" },
{ label: "广西壮族自治区", value: "广西壮族自治区" },
{ label: "海南省", value: "海南省" },
{ label: "重庆市", value: "重庆市" },
{ label: "四川省", value: "四川省" },
{ label: "贵州省", value: "贵州省" },
{ label: "云南省", value: "云南省" },
{ label: "西藏自治区", value: "西藏自治区" },
{ label: "陕西省", value: "陕西省" },
{ label: "甘肃省", value: "甘肃省" },
{ label: "青海省", value: "青海省" },
{ label: "宁夏回族自治区", value: "宁夏回族自治区" },
{ label: "新疆维吾尔自治区", value: "新疆维吾尔自治区" },
{ label: "台湾省", value: "台湾省" },
{ label: "香港特别行政区", value: "香港特别行政区" },
{ label: "澳门特别行政区", value: "澳门特别行政区" },
];
//modal中平台checkbox名称
const platformList = ["抖音", "微博", "哔哩哔哩", "快手", "秘live"];
//表头可见性表单的checkbox选项
const showColumnsOptions = [
{
label: "基础信息",
value: "baseInfo",
},
{
label: "个人展示信息",
value: "displayInfo",
},
{
label: "封面图片",
value: "displayPoster",
},
{
label: "封面视频",
value: "displayVideo",
},
{
label: "相册",
value: "displayGallery",
},
];
//展示的数据
const [showData, setShowData] = useState([]);
//搜索名人
const search = async (value) => {
try {
const base = baseRequest();
const detailResponse = await fetch(`/op/streamer/list_ext_by_user_id`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
user_id: parseInt(value.id, 10),
...base,
}),
});
const detailData = await detailResponse.json();
if (detailData.ret === -1) {
alert(detailData.msg);
return;
}
setShowData([
{
key: detailData.data.streamer_ext.mid,
baseInfo: {
id: detailData.data.streamer_ext.user_id,
name: detailData.data.streamer_ext.name,
avatar: detailData.data.streamer_ext.avatar.images[0].urls[0],
joinTime: new Date(
detailData.data.streamer_ext.ct * 1000
).toLocaleString(),
},
displayInfo: {
gender: detailData.data.streamer_ext.gender,
fans: detailData.data.streamer_ext.fans,
wechat_lock_type: detailData.data.streamer_ext.wechat_lock_type,
wechat: detailData.data.streamer_ext.wechat_contact,
wechat_price: detailData.data.streamer_ext.wechat_coin_price,
signature: detailData.data.streamer_ext.bio,
age: detailData.data.streamer_ext.age,
height: detailData.data.streamer_ext.height,
weight: detailData.data.streamer_ext.weight,
constellation: detailData.data.streamer_ext.constellation,
location: detailData.data.streamer_ext.city,
auto_response_message:
detailData.data.streamer_ext.auto_response_message,
},
displayPoster: detailData.data.streamer_ext.cover.images,
displayVideo: detailData.data.streamer_ext.shorts.videos,
displayGallery: detailData.data.streamer_ext.album.images,
},
]);
} catch (error) {
console.error(error);
}
};
//表单提交失败
const onFinishFailed = (errorInfo) => {
console.log("Failed:", errorInfo);
};
//modal是否展示
const [isModalOpen, setIsModalOpen] = useState(false);
//点击modal取消按钮
const handleCancel = () => {
setShowData([]);
setDefaultValues({});
setDefaultMedia({});
setDisplayVideoId([]);
setDisplayPosterId([]);
setDisplayGalleryId([]);
setIsModalOpen(false);
};
//modal打开时的默认值
const [defaultValues, setDefaultValues] = useState({});
const [defaultMedia, setDefaultMedia] = useState({});
//点击修改按钮
const handleModal = (record) => {
setDefaultValues(record);
setDefaultMedia({
displayPoster: record.displayPoster,
displayVideo: record.displayVideo,
displayGallery: record.displayGallery,
});
setIsModalOpen(true);
};
//表单提交成功
const onModalFormFinish = async (value) => {
//上传表单操作...
const oldPosterId = defaultMedia.displayPoster.map((item) => item.id);
const oldVideoId = defaultMedia.displayVideo.map((item) => item.id);
const oldGalleryId = defaultMedia.displayGallery.map((item) => item.id);
const newPosterId = [...oldPosterId, ...displayPosterId];
const newVideoId = [...oldVideoId, ...displayVideoId];
const newGalleryId = [...oldGalleryId, ...displayGalleryId];
if (
newPosterId.length === 0 ||
newVideoId.length === 0 ||
newGalleryId.length < 2
) {
alert("请确保封面、视频不为空,且相册大于2");
return;
}
if (
newPosterId.length > 1 ||
newVideoId.length > 1 ||
newGalleryId.length > 9
) {
alert("请确保封面、视频、相册数量未超过上限");
return;
}
if (
!defaultValues.key ||
!value.signature ||
!value.age ||
!value.height ||
!value.weight ||
!value.constellation ||
!value.location ||
!value.fans ||
!value.wechat_price ||
!value.auto_response_message
) {
alert("请完善信息后提交");
return;
}
if (value.wechat_lock_type === 0 && !value.wechat) {
alert("请填写微信后提交");
return;
}
try {
const base = baseRequest();
const detailResponse = await fetch(`/op/streamer/update`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
mid: defaultValues.key,
gender: parseInt(value.gender, 10),
wechat_contact: value.wechat,
bio: value.signature,
cover: { image_ids: newPosterId },
shorts: { video_ids: newVideoId },
album: { image_ids: newGalleryId },
age: parseInt(value.age, 10),
height: parseInt(value.height, 10),
weight: parseInt(value.weight, 10),
constellation: value.constellation,
city: value.location,
wechat_lock_type: parseInt(value.wechat_lock_type, 10),
fans: parseInt(value.fans, 10),
wechat_coin_price: parseInt(value.wechat_price, 10) * 10,
auto_response_message: value.auto_response_message,
...base,
}),
});
const detailData = await detailResponse.json();
if (detailData.ret === -1) {
alert(detailData.msg);
return;
}
} catch (error) {
console.error(error);
}
//关闭模态
setShowData([]);
setDefaultValues({});
setDefaultMedia({});
setDisplayVideoId([]);
setDisplayPosterId([]);
setDisplayGalleryId([]);
setIsModalOpen(false);
};
//表单提交失败
const onModalFormFinishFailed = (errorInfo) => {
console.log("Failed:", errorInfo);
};
//保存上传的封面id
const [displayVideoId, setDisplayVideoId] = useState([]);
const [displayPosterId, setDisplayPosterId] = useState([]);
const [displayGalleryId, setDisplayGalleryId] = useState([]);
//删除默认的媒体
const handleDeleteMedia = (type, id) => {
if (type === "displayPoster") {
setDefaultMedia({
...defaultMedia,
displayPoster: [],
});
return;
}
if (type === "displayVideo") {
setDefaultMedia({
...defaultMedia,
displayVideo: [],
});
return;
}
if (type === "displayGallery") {
setDefaultMedia({
...defaultMedia,
displayGallery: defaultMedia.displayGallery.filter(
(item) => item.id !== id
),
});
return;
}
};
return (
数据可见性:
setShowColumns(value)}
/>
{/* 模态框是否显示 */}
{isModalOpen && (
}
/>
)}
);
};
export default function StreamerInformation() {
return ;
}