修复客服bug
This commit is contained in:
parent
f69cd8d12b
commit
539be2b06a
|
@ -92,7 +92,7 @@ body{
|
|||
.tabPinkLine::after {
|
||||
content: "";
|
||||
position: absolute;
|
||||
background-image: url(http://localhost:3000/icons/tabindicator.png);
|
||||
background-image: url("/icons/tabindicator.png");
|
||||
height: 34px;
|
||||
background-position: -2px -18px;
|
||||
background-size: cover;
|
||||
|
@ -105,7 +105,7 @@ body{
|
|||
.titlePinkLine::after {
|
||||
content: "";
|
||||
position: absolute;
|
||||
background-image: url(http://localhost:3000/icons/pinkline.png);
|
||||
background-image: url("/icons/pinkline.png");
|
||||
height: 12px;
|
||||
width: inherit;
|
||||
min-width: 42px;
|
||||
|
|
|
@ -1,11 +1,21 @@
|
|||
|
||||
.customTabs {
|
||||
border: none;
|
||||
--active-line-color: #ff8383;
|
||||
--active-title-color: #fff;
|
||||
--title-color: #a0a0a0;
|
||||
--inactive-title-color: #FFFFFF80;
|
||||
--tab-border-color: #ff8383;
|
||||
}
|
||||
|
||||
.customTabs>div>div:last-child>div:first-child {
|
||||
z-index: 1;
|
||||
background: none;
|
||||
|
||||
}
|
||||
.customTabs>div>div:last-child>div:first-child ::after{
|
||||
content: '';
|
||||
background-image: url(http://localhost:3000/icons/tabindicator.png);
|
||||
.customTabs>div>div:last-child>div:first-child::after{
|
||||
content: "";
|
||||
background-image: url("/icons/tabindicator.png");
|
||||
height: 44px;
|
||||
background-size: cover;
|
||||
background-repeat: no-repeat;
|
||||
|
@ -14,14 +24,6 @@
|
|||
top: -48px;
|
||||
left: calc(50% - 25px);
|
||||
}
|
||||
.customTabs {
|
||||
border: none;
|
||||
--active-line-color: #ff8383;
|
||||
--active-title-color: #fff;
|
||||
--title-color: #a0a0a0;
|
||||
--inactive-title-color: #5c5c5c;
|
||||
--tab-border-color: #ff8383;
|
||||
}
|
||||
/* .loginBox .adm-tabs .adm-tabs-tab {
|
||||
color: #a0a0a0;
|
||||
} */
|
|
@ -12,7 +12,7 @@ import {
|
|||
Image,
|
||||
} from "antd-mobile";
|
||||
import { useRouter } from "next/navigation";
|
||||
import styles from "./index.module.css";
|
||||
import styles from "./index.module.scss";
|
||||
import { JSEncrypt } from "jsencrypt";
|
||||
import { handleLogin } from "@/store/actions";
|
||||
import { saveUserInfo, removeUserInfo } from "@/utils/storeInfo";
|
||||
|
@ -197,13 +197,13 @@ function Login({ handleLogin }) {
|
|||
}
|
||||
};
|
||||
return (
|
||||
<div className={`${styles.loginBox} flex flex-col justify-center items-center`}>
|
||||
<div className={`${styles.loginBox}`}>
|
||||
<Image
|
||||
src={process.env.NEXT_PUBLIC_CDN_URL + "/public/images/slogan.png"}
|
||||
alt=""
|
||||
className="mt-24 w-[90vw]"
|
||||
/>
|
||||
<div className="mt-6 flex justify-between items-center px-2 text-gray-400 sticky top-0 z-10 bg-deepBg">
|
||||
<div className="mt-6 flex justify-between items-center px-2 text-[#ffffff80] sticky top-0 z-10 bg-deepBg">
|
||||
<Tabs
|
||||
activeKey={tabItems[activeIndex].key}
|
||||
onChange={(key) => {
|
||||
|
|
|
@ -42,7 +42,6 @@ export default function MessageDetail({}) {
|
|||
if (oldMessages[0]) {
|
||||
updateMessages(oldMessages[0]?.id, 0, oldMessages);
|
||||
// toScrollBottom.current = 1;
|
||||
|
||||
}
|
||||
}, 3000); // 间隔时间为3秒
|
||||
|
||||
|
@ -53,8 +52,7 @@ export default function MessageDetail({}) {
|
|||
}, [oldMessages]);
|
||||
useEffect(() => {
|
||||
if (toScrollBottom.current) {
|
||||
|
||||
scrollBox.current?.scrollTo(0, scrollBox.current.scrollHeight+50);
|
||||
scrollBox.current?.scrollTo(0, scrollBox.current.scrollHeight + 50);
|
||||
toScrollBottom.current = 0;
|
||||
}
|
||||
}, [messages]);
|
||||
|
@ -79,14 +77,17 @@ export default function MessageDetail({}) {
|
|||
}, [sessionId]);
|
||||
//查询session
|
||||
const getSession = async (mid) => {
|
||||
setLoading(true)
|
||||
setLoading(true);
|
||||
try {
|
||||
const data =
|
||||
await requireAPI("POST", "/api/contact_customer_service_session/list_by_mid", {
|
||||
const data = await requireAPI(
|
||||
"POST",
|
||||
"/api/contact_customer_service_session/list_by_mid",
|
||||
{
|
||||
body: {
|
||||
mid: Number(mid),
|
||||
},
|
||||
});
|
||||
}
|
||||
);
|
||||
if (data.ret === -1) {
|
||||
Toast.show({
|
||||
icon: "fail",
|
||||
|
@ -94,26 +95,32 @@ export default function MessageDetail({}) {
|
|||
position: "top",
|
||||
});
|
||||
}
|
||||
setLoading(false)
|
||||
setLoading(false);
|
||||
if (data.data.session) {
|
||||
setSessionId(data.data.session.id);
|
||||
return;
|
||||
} else {
|
||||
//如果是第一次发送,需要创建session
|
||||
createSession(mid);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
};
|
||||
//创建session
|
||||
const createSession = async () => {
|
||||
setLoading(true)
|
||||
const createSession = async (mid) => {
|
||||
setLoading(true);
|
||||
try {
|
||||
const data =
|
||||
await requireAPI("POST", "/api/contact_customer_service_session/create", {
|
||||
const data = await requireAPI(
|
||||
"POST",
|
||||
"/api/contact_customer_service_session/create",
|
||||
{
|
||||
body: {
|
||||
sub_mid: Number(mid),
|
||||
obj_mid: 0,
|
||||
},
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
if (data.ret === -1) {
|
||||
Toast.show({
|
||||
icon: "fail",
|
||||
|
@ -122,7 +129,7 @@ export default function MessageDetail({}) {
|
|||
});
|
||||
}
|
||||
setSessionId(data.data.session_id);
|
||||
setLoading(false)
|
||||
setLoading(false);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
|
@ -131,15 +138,18 @@ export default function MessageDetail({}) {
|
|||
const loadEarlierHistory = async () => {
|
||||
if (!more) return;
|
||||
try {
|
||||
setLoading(true)
|
||||
const data =
|
||||
await requireAPI("POST", "/api/contact_customer_service/list_by_session_id", {
|
||||
setLoading(true);
|
||||
const data = await requireAPI(
|
||||
"POST",
|
||||
"/api/contact_customer_service/list_by_session_id",
|
||||
{
|
||||
body: {
|
||||
session_id: sessionId,
|
||||
offset: offset,
|
||||
limit: 12,
|
||||
},
|
||||
});
|
||||
}
|
||||
);
|
||||
if (data.ret === -1) {
|
||||
Toast.show({
|
||||
icon: "fail",
|
||||
|
@ -150,9 +160,9 @@ export default function MessageDetail({}) {
|
|||
}
|
||||
setOffset(data.data.offset);
|
||||
setMore(data.data.more);
|
||||
let mathNewMessages = handleData([...oldMessages,...data.data.list]);
|
||||
let mathNewMessages = handleData([...oldMessages, ...data.data.list]);
|
||||
// setMessages((prev) => [...prev, ...temMessages]);
|
||||
setLoading(false)
|
||||
setLoading(false);
|
||||
return mathNewMessages;
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
|
@ -170,21 +180,21 @@ export default function MessageDetail({}) {
|
|||
return;
|
||||
}
|
||||
|
||||
//如果是第一次发送,需要创建session
|
||||
if (!sessionId) await createSession();
|
||||
|
||||
//查询历史记录的时候后移一位,防止记录重复
|
||||
setOffset((prev) => prev + 1);
|
||||
//请求接口发送私信
|
||||
try {
|
||||
const data =
|
||||
await requireAPI("POST", "/api/contact_customer_service/create", {
|
||||
const data = await requireAPI(
|
||||
"POST",
|
||||
"/api/contact_customer_service/create",
|
||||
{
|
||||
body: {
|
||||
session_id: sessionId,
|
||||
predicate: 0,
|
||||
message,
|
||||
},
|
||||
});
|
||||
}
|
||||
);
|
||||
if (data.ret === -1) {
|
||||
Toast.show({
|
||||
icon: "error",
|
||||
|
@ -195,7 +205,7 @@ export default function MessageDetail({}) {
|
|||
}
|
||||
// updateLatestHistory();
|
||||
// console.log("oldArr", oldArr);
|
||||
updateMessages(lastId, 0, oldArr).then(res=>{
|
||||
updateMessages(lastId, 0, oldArr).then((res) => {
|
||||
setNewMessage("");
|
||||
toScrollBottom.current = 1;
|
||||
});
|
||||
|
@ -310,14 +320,17 @@ export default function MessageDetail({}) {
|
|||
const updateMessages = async (lastId, currentOffset, oldArr) => {
|
||||
// console.log("lastId", lastId);
|
||||
try {
|
||||
const data =
|
||||
await requireAPI("POST", "/api/contact_customer_service/list_by_session_id", {
|
||||
const data = await requireAPI(
|
||||
"POST",
|
||||
"/api/contact_customer_service/list_by_session_id",
|
||||
{
|
||||
body: {
|
||||
session_id: sessionId,
|
||||
offset: currentOffset,
|
||||
limit: 12,
|
||||
},
|
||||
});
|
||||
}
|
||||
);
|
||||
if (data.ret === -1) {
|
||||
Toast.show({
|
||||
icon: "fail",
|
||||
|
@ -330,12 +343,12 @@ export default function MessageDetail({}) {
|
|||
return element.id > lastId;
|
||||
});
|
||||
// console.log("[...messages,...newData]", [...newData]);
|
||||
let mathNewMessages = handleData([...newData,...oldArr]);
|
||||
let mathNewMessages = handleData([...newData, ...oldArr]);
|
||||
setMessages((old) => {
|
||||
toScrollBottom.current = 1;
|
||||
return mathNewMessages;
|
||||
});
|
||||
return
|
||||
return;
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
|
@ -357,11 +370,14 @@ export default function MessageDetail({}) {
|
|||
<div>
|
||||
<div className="my-[57px]">
|
||||
<div className="flex justify-center py-2">
|
||||
<div
|
||||
className="px-3 py-2 rounded-full bg-[#FFFFFF1A]"
|
||||
|
||||
>
|
||||
{loading? <DotLoading /> : more ? <span onClick={loadMore}>查看更早</span>:<span>无更早消息</span>}
|
||||
<div className="px-3 py-2 rounded-full bg-[#FFFFFF1A]">
|
||||
{loading ? (
|
||||
<DotLoading />
|
||||
) : more ? (
|
||||
<span onClick={loadMore}>查看更早</span>
|
||||
) : (
|
||||
<span>无更早消息</span>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
<ul className="py-2">
|
||||
|
@ -429,7 +445,9 @@ export default function MessageDetail({}) {
|
|||
<Button
|
||||
size="middle"
|
||||
block
|
||||
onClick={() => onSend(newMessage, oldMessages[0].id, oldMessages)}
|
||||
onClick={() =>
|
||||
onSend(newMessage, oldMessages[0]?.id || -1, oldMessages)
|
||||
}
|
||||
style={{ "--background-color": "#FF669E", color: "#FFFFFF" }}
|
||||
>
|
||||
发送
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
"use client";
|
||||
|
||||
import React, { useState, useEffect, useRef } from "react";
|
||||
import { Button,Dialog } from "antd-mobile";
|
||||
import { Button,Dialog,Toast } from "antd-mobile";
|
||||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||
import {
|
||||
faAngleLeft,
|
||||
|
@ -37,6 +37,7 @@ export default function DeleteAccount() {
|
|||
const handleDeleteAccount = async () => {
|
||||
try {
|
||||
const _data = await requireAPI("POST", "/api/account/cancel");
|
||||
console.log("requireAPI",_data)
|
||||
if (_data.ret === -1) {
|
||||
Toast.show({
|
||||
icon: "fail",
|
||||
|
|
|
@ -8,9 +8,11 @@ export default function WithAuth(WrappedComponent) {
|
|||
const pathname = usePathname();
|
||||
useEffect(() => {
|
||||
|
||||
if(!pathname.includes("webView") && !pathname.includes("login") )
|
||||
checkLogin();
|
||||
console.log("isLogin",!pathname.includes("webView") && !pathname.includes("login"))
|
||||
if(!pathname.includes("webView") && !pathname.includes("login") ){
|
||||
checkLogin();
|
||||
}
|
||||
|
||||
// console.log("isLogin",!pathname.includes("webView") && !pathname.includes("login"))
|
||||
}, [pathname]);
|
||||
const checkLogin = async () => {
|
||||
const hasToken = await get("token");
|
||||
|
@ -27,14 +29,13 @@ export default function WithAuth(WrappedComponent) {
|
|||
position: "top",
|
||||
});
|
||||
router.push("/login");
|
||||
}else{
|
||||
if(pathname.includes("login")){
|
||||
router.replace("/")
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Toast.show({
|
||||
icon: "fail",
|
||||
content:"当前登录失效,请重新登录",
|
||||
position: "top",
|
||||
});
|
||||
router.push("/login");
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue