完成意见反馈功能

This commit is contained in:
yezian 2024-01-02 22:09:17 +08:00
parent 05b6f83567
commit fce15a60d7
1 changed files with 163 additions and 84 deletions

View File

@ -1,6 +1,13 @@
import React, { useState, useRef } from "react";
import React, { useState, useRef, useEffect } from "react";
import { Form, Input, Button, Space, Table, Menu, Image } from "antd";
import { Routes, Route, Navigate, useNavigate,useLocation } from "react-router-dom";
import {
Routes,
Route,
Navigate,
useNavigate,
useLocation,
} from "react-router-dom";
import baseRequest from "../../utils/baseRequest";
const FeedbackContent = (props) => {
const { TextArea } = Input;
@ -24,32 +31,24 @@ const FeedbackContent = (props) => {
},
{
title: "辅助材料",
dataIndex: "mediaInfo",
key: "mediaInfo",
render: (mediaInfo) => (
dataIndex: "credentials",
key: "credentials",
render: (data) => (
<div>
{mediaInfo
? mediaInfo.map((item) =>
item.type === "img" ? (
<Image
key={item.url}
src={item.url}
width={150}
style={{ marginBottom: 10 }}
/>
) : (
<video key={item.url} src={item.url} width={150} controls />
)
)
: "无"}
{data.images?.map((item, index) => (
<Image
key={index}
src={item.urls[0]}
width={150}
style={{ marginBottom: 10 }}
/>
))}
{data.videos?.map((item, index) => (
<video key={index} src={item.urls[0]} width={150} controls />
))}
</div>
),
},
{
title: "联系方式",
dataIndex: "contact",
key: "contact",
},
{
title: "提交时间",
dataIndex: "submitTime",
@ -115,95 +114,174 @@ const FeedbackContent = (props) => {
formRef.current.submit();
};
//
const handleSubmit = (value) => {
const handleSubmit = async (value) => {
//
let status;
if (formRef.current.btn === "invalid") {
status = "invalid";
status = 3;
} else if (formRef.current.btn === "iteration") {
status = "iteration";
status = 4;
} else {
switch (current) {
case "pending":
status = "inProgress";
status = 1;
break;
case "inProgress":
status = "done";
status = 2;
break;
case "done":
status = "inProgress";
status = 1;
break;
case "invalid":
status = "inProgress";
status = 1;
break;
case "iteration":
status = "done";
status = 2;
break;
default:
break;
}
}
const submitData = {
key: formRef.current.key,
remark: value[formRef.current.key],
id: formRef.current.key,
remarks: value[formRef.current.key],
status: status,
};
//
console.log(submitData);
//
setShowData(showData.filter((item) => item.key !== submitData.key));
try {
const base = baseRequest();
const response = await fetch("/op/feedback/update", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
...submitData,
...base,
}),
});
const updateData = await response.json();
if (updateData.ret === -1) {
alert(updateData.msg);
return;
}
//
setShowData(showData.filter((item) => item.key !== submitData.id));
} catch (error) {
console.error(error);
}
};
//
let data = [
{
key: "1",
id: "123456",
name: "马牛逼",
description:
"马牛逼反馈马牛逼反馈马牛逼反馈马牛逼反馈马牛逼反馈马牛逼反馈马牛逼反馈马牛逼反馈",
mediaInfo: [
{
type: "img",
url: "https://s2.loli.net/2023/07/25/fjouqVLAlTn2s58.png",
//
const [data, setData] = useState([]);
const [offset, setOffset] = useState(0);
const [more, setMore] = useState(1);
const getData = async () => {
if (!more) return;
let querryStatus;
switch (current) {
case "pending":
querryStatus = 0;
break;
case "inProgress":
querryStatus = 1;
break;
case "done":
querryStatus = 2;
break;
case "invalid":
querryStatus = 3;
break;
case "iteration":
querryStatus = 4;
break;
default:
break;
}
try {
const base = baseRequest();
const response = await fetch("/op/feedback/list", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
{
type: "video",
url: "http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4",
body: JSON.stringify({
status: querryStatus,
offset: offset,
limit: 200,
...base,
}),
});
const temData = await response.json();
if (temData.ret === -1) {
alert(temData.msg);
return;
}
const userMids = temData.data.list.map((item) => item.mid);
if (userMids.length === 0) {
setData([]);
return;
}
const userResponse = await fetch("/op/account/list_others_by_mids", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
],
contact: "qq:123456789;wx:987654321",
submitTime: "2023-7-21 21:00",
remark: "马牛逼的备注",
status: "pending",
},
{
key: "2",
id: "10086",
name: "迪迦",
description:
"迪迦反馈迪迦反馈迪迦反馈迪迦反馈迪迦反馈迪迦反馈迪迦反馈迪迦反馈迪迦反馈迪迦反馈",
mediaInfo: [
{
type: "img",
url: "https://s2.loli.net/2023/07/25/1daCqmZGQNUzoJ8.png",
},
{
type: "video",
url: "https://media.w3.org/2010/05/sintel/trailer.mp4",
},
],
contact: "qq:741741;wx:147147",
submitTime: "2023-7-22 20:59",
remark: "迪迦的备注",
status: "pending",
},
];
body: JSON.stringify({
mids: userMids,
...base,
}),
});
const userData = await userResponse.json();
if (userData.ret === -1) {
alert(userData.msg);
return;
}
//
const combinedArray = temData.data.list.map((item1) => {
const matchingItem = userData.data.list.find(
(item2) => item2.mid === item1.mid
);
return { ...item1, ...matchingItem };
});
const structedData = combinedArray.map((item) => {
return {
key: item.id,
id: item.user_id,
name: item.name,
description: item.discription,
credentials: item.credentials,
submitTime: new Date(item.ct * 1000).toLocaleString(),
remark: item.remarks,
status: item.status,
};
});
setData([...data, ...structedData]);
setOffset(temData.data.offset);
setMore(temData.data.more);
} catch (error) {
console.error(error);
}
};
useEffect(() => {
getData();
}, [current]);
//
const [showData, setShowData] = useState(data);
useEffect(() => {
setShowData(data);
}, [data]);
//
const search = (value) => {
value.name||value.id
? setShowData(data.filter((item) => item.name === value.name||item.id===value.id))
value.name || value.id
? setShowData(
data.filter(
(item) =>
item.name.toLowerCase().includes(value.name.toLowerCase()) &&
item.id.toString().includes(value.id)
)
)
: setShowData(data);
};
//
@ -221,7 +299,7 @@ const FeedbackContent = (props) => {
</p>
<Form name="search" onFinish={search} onFinishFailed={onFinishFailed}>
<Space style={{ marginBottom: 20 }}>
<Form.Item label="用户ID" name="id" style={{ margin: 0 }}>
<Form.Item label="用户ID" name="id" style={{ margin: 0 }}>
<Input />
</Form.Item>
<Form.Item label="用户昵称" name="name" style={{ margin: 0 }}>
@ -253,7 +331,7 @@ export default function Feedback() {
const navigate = useNavigate();
//tab
const location = useLocation();
const pathname = location.pathname.split("/")[2]||"pending";
const pathname = location.pathname.split("/")[2] || "pending";
const [current, setCurrent] = useState(pathname);
//tab
const items = [
@ -281,6 +359,7 @@ export default function Feedback() {
const onClick = (e) => {
setCurrent(e.key);
navigate(e.key);
window.location.reload();
};
return (