|
@@ -7,16 +7,14 @@ import style from "./index.module.less";
|
|
import { useEffect, useState } from "react";
|
|
import { useEffect, useState } from "react";
|
|
import ContactCard from "./components/contact-card/index";
|
|
import ContactCard from "./components/contact-card/index";
|
|
import { getContactList, setContactToTop } from "@/service/contact";
|
|
import { getContactList, setContactToTop } from "@/service/contact";
|
|
-import {
|
|
|
|
- useLoadMoreInfinite,
|
|
|
|
- type TResponseData,
|
|
|
|
-} from "@/utils/loadMoreInfinite";
|
|
|
|
|
|
+import { useLoadMoreInfinite } from "@/utils/loadMoreInfinite";
|
|
import PageCustom from "@/components/page-custom/index";
|
|
import PageCustom from "@/components/page-custom/index";
|
|
import { TContactItem } from "@/types/contact";
|
|
import { TContactItem } from "@/types/contact";
|
|
import { isSuccess } from "@/utils";
|
|
import { isSuccess } from "@/utils";
|
|
import { delContact } from "@/service/contact";
|
|
import { delContact } from "@/service/contact";
|
|
import TabPageCheckLogin from "@/components/TabPageCheckLogin";
|
|
import TabPageCheckLogin from "@/components/TabPageCheckLogin";
|
|
import BlurContainer from "@/components/BlurContainer";
|
|
import BlurContainer from "@/components/BlurContainer";
|
|
|
|
+import SliderAction from "@/components/SliderAction";
|
|
|
|
|
|
export default function Index() {
|
|
export default function Index() {
|
|
const [searchValue, setSearchValue] = useState("");
|
|
const [searchValue, setSearchValue] = useState("");
|
|
@@ -65,38 +63,6 @@ export default function Index() {
|
|
setSize((prevSize) => prevSize + 1);
|
|
setSize((prevSize) => prevSize + 1);
|
|
};
|
|
};
|
|
|
|
|
|
- const handleAction = async (e: any) => {
|
|
|
|
- const detail = e.detail as { type: string; id: string };
|
|
|
|
- console.log(detail);
|
|
|
|
- // 置顶与取消置顶
|
|
|
|
- if (detail.type === "pin" || detail.type === "unpin") {
|
|
|
|
- const reseponse = await setContactToTop({
|
|
|
|
- isTop: detail.type === "pin",
|
|
|
|
- contactId: detail.id,
|
|
|
|
- });
|
|
|
|
- if (isSuccess(reseponse.status)) {
|
|
|
|
- mutate();
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- if (detail.type === "delete") {
|
|
|
|
- handleDelete(detail.id);
|
|
|
|
- }
|
|
|
|
- };
|
|
|
|
-
|
|
|
|
- useDidShow(() => {
|
|
|
|
- mutate();
|
|
|
|
- });
|
|
|
|
- const onLoginEnd = () => {
|
|
|
|
- mutate();
|
|
|
|
- };
|
|
|
|
-
|
|
|
|
- useEffect(() => {
|
|
|
|
- if (data && pageIndex === 1) {
|
|
|
|
- setTotalCount(data?.[0].totalCount || 0);
|
|
|
|
- }
|
|
|
|
- }, [data, pageIndex]);
|
|
|
|
-
|
|
|
|
const handleDelete = (contactId: string | number) => {
|
|
const handleDelete = (contactId: string | number) => {
|
|
Taro.showModal({
|
|
Taro.showModal({
|
|
content: "😭 确认删除该联系人吗?",
|
|
content: "😭 确认删除该联系人吗?",
|
|
@@ -115,27 +81,70 @@ export default function Index() {
|
|
});
|
|
});
|
|
};
|
|
};
|
|
|
|
|
|
|
|
+ const handlePin = async (isTop: boolean, contactId: string | number) => {
|
|
|
|
+ const reseponse = await setContactToTop({
|
|
|
|
+ isTop: !isTop,
|
|
|
|
+ contactId: contactId,
|
|
|
|
+ });
|
|
|
|
+ if (isSuccess(reseponse.status)) {
|
|
|
|
+ mutate();
|
|
|
|
+ }
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ useDidShow(() => {
|
|
|
|
+ mutate();
|
|
|
|
+ });
|
|
|
|
+ const onLoginEnd = () => {
|
|
|
|
+ mutate();
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ useEffect(() => {
|
|
|
|
+ if (data && pageIndex === 1) {
|
|
|
|
+ setTotalCount(data?.[0].totalCount || 0);
|
|
|
|
+ }
|
|
|
|
+ }, [data, pageIndex]);
|
|
|
|
+
|
|
|
|
+ const createSliderButtons = (item: TContactItem) => {
|
|
|
|
+ const onTopText = item.isTop ? (
|
|
|
|
+ <View>
|
|
|
|
+ <View>取消</View>
|
|
|
|
+ <View>置顶</View>
|
|
|
|
+ </View>
|
|
|
|
+ ) : (
|
|
|
|
+ "置顶"
|
|
|
|
+ );
|
|
|
|
+ return [
|
|
|
|
+ {
|
|
|
|
+ text: "删除",
|
|
|
|
+ color: "#FF8200",
|
|
|
|
+ onClick: () => {
|
|
|
|
+ handleDelete(item.contactId);
|
|
|
|
+ },
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ text: onTopText,
|
|
|
|
+ color: `${item.isTop ? "#FF4747" : "#327BF9"}`,
|
|
|
|
+ onClick: () => {
|
|
|
|
+ handlePin(item.isTop, item.contactId);
|
|
|
|
+ },
|
|
|
|
+ },
|
|
|
|
+ ];
|
|
|
|
+ };
|
|
|
|
|
|
const renderContent = () => {
|
|
const renderContent = () => {
|
|
if (list?.length) {
|
|
if (list?.length) {
|
|
return list.map((item) => (
|
|
return list.map((item) => (
|
|
<View className={`rounded-12 overflow-hidden truncate`}>
|
|
<View className={`rounded-12 overflow-hidden truncate`}>
|
|
- <slide-contact
|
|
|
|
- pid={item.contactId}
|
|
|
|
- pinned={item.isTop}
|
|
|
|
- onAction={handleAction}
|
|
|
|
- >
|
|
|
|
- <View className={``}>
|
|
|
|
- <ContactCard
|
|
|
|
- refresh={mutate}
|
|
|
|
- deleteable={true}
|
|
|
|
- key={item.contactId}
|
|
|
|
- data={item}
|
|
|
|
- fromContact
|
|
|
|
- className={`${item.isTop ? "bg-[#EDF1FF]" : "bg-white"}`}
|
|
|
|
- ></ContactCard>
|
|
|
|
- </View>
|
|
|
|
- </slide-contact>
|
|
|
|
|
|
+ <SliderAction actions={createSliderButtons(item)}>
|
|
|
|
+ <ContactCard
|
|
|
|
+ refresh={mutate}
|
|
|
|
+ deleteable={true}
|
|
|
|
+ key={item.contactId}
|
|
|
|
+ data={item}
|
|
|
|
+ fromContact
|
|
|
|
+ className={`${item.isTop ? "bg-[#EDF1FF]" : "bg-white"}`}
|
|
|
|
+ ></ContactCard>
|
|
|
|
+ </SliderAction>
|
|
</View>
|
|
</View>
|
|
));
|
|
));
|
|
}
|
|
}
|