Skip to content

Let's use AI to Earn!

feat(数据统计): 1. 找不到空间的账号更改为默认账号的ID。 2. 完善swiper。 3. 添加过滤后的账号

gaoSire56faac2ec24
diff --git a/src/app/[lng]/dataStatistics/DataStatisticsCore.tsx b/src/app/[lng]/dataStatistics/DataStatisticsCore.tsx
index a0d767d5..8d44ee32 100644
--- a/src/app/[lng]/dataStatistics/DataStatisticsCore.tsx
+++ b/src/app/[lng]/dataStatistics/DataStatisticsCore.tsx
@@ -8,14 +8,18 @@ import { useEffect } from "react";
import { useAccountStore } from "@/store/account";
export const DataStatisticsCore = () => {
- const { setChoosedGroupIds } = useDataStatisticsStore(
- useShallow((state) => ({
- setChoosedGroupIds: state.setChoosedGroupIds,
- })),
- );
- const { accountGroupList } = useAccountStore(
+ const { setChoosedGroupIds, setFilteredAccountList, choosedGroupIds } =
+ useDataStatisticsStore(
+ useShallow((state) => ({
+ setChoosedGroupIds: state.setChoosedGroupIds,
+ setFilteredAccountList: state.setFilteredAccountList,
+ choosedGroupIds: state.choosedGroupIds,
+ })),
+ );
+ const { accountGroupList, accountList } = useAccountStore(
useShallow((state) => ({
accountGroupList: state.accountGroupList,
+ accountList: state.accountList,
})),
);
@@ -25,6 +29,15 @@ export const DataStatisticsCore = () => {
}
}, [setChoosedGroupIds, accountGroupList]);
+ // 过滤账户
+ useEffect(() => {
+ setFilteredAccountList(
+ accountList.filter((v) => {
+ return choosedGroupIds.includes(v.groupId);
+ }),
+ );
+ }, [choosedGroupIds, accountList]);
+
return (
<div className={styles.dataStatistics}>
<DataStatisticsHeader />
diff --git a/src/app/[lng]/dataStatistics/components/DataStatisticsHeader/dataStatisticsHeader.module.scss b/src/app/[lng]/dataStatistics/components/DataStatisticsHeader/dataStatisticsHeader.module.scss
index a4769f10..7385bf81 100644
--- a/src/app/[lng]/dataStatistics/components/DataStatisticsHeader/dataStatisticsHeader.module.scss
+++ b/src/app/[lng]/dataStatistics/components/DataStatisticsHeader/dataStatisticsHeader.module.scss
@@ -17,11 +17,73 @@
}
.dataStatisticsHeader-accounts {
+ display: flex;
+ margin-top: 15px;
+ height: 145px;
- }
+ .dataStatisticsHeader-accountCount {
+ background: rgb(247, 250, 250);
+ width: 200px;
+ box-sizing: border-box;
+ padding: 10px 20px;
+ border-radius: 8px;
+ flex-shrink: 0;
- .dataStatisticsHeader-accountCount {
+ &-title {
+ display: flex;
+ align-items: center;
+ svg {
+ margin-right: 5px;
+ }
+ }
+ &-number {
+ font-size: 26px;
+ font-weight: bold;
+ margin: 5px 0;
+ }
+
+ .ant-tag {
+ background: rgb(236, 240, 240);
+ &:nth-of-type(1) {
+ margin-bottom: 10px;
+ svg {
+ color: var(--success-color);
+ }
+ }
+ &:nth-of-type(2) {
+ svg {
+ color: var(--warning-color);
+ }
+ }
+ b {
+ margin-left: 5px;
+ display: inline-block;
+ }
+ }
+ }
+ &-swiper {
+ display: flex;
+ align-items: center;
+ background: rgb(247, 250, 250);
+ width: 100%;
+ min-width: 0;
+ height: 100%;
+ border-radius: 8px;
+ margin-left: 20px;
+
+ button {
+ width: 25px;
+ height: 40px;
+ }
+
+ .swiper {
+ width: 100%;
+ height: 100%;
+ padding: 15px;
+ box-sizing: border-box;
+ }
+ }
}
}
}
\ No newline at end of file
diff --git a/src/app/[lng]/dataStatistics/components/DataStatisticsHeader/index.tsx b/src/app/[lng]/dataStatistics/components/DataStatisticsHeader/index.tsx
index 91ddea1c..82ddf4a6 100644
--- a/src/app/[lng]/dataStatistics/components/DataStatisticsHeader/index.tsx
+++ b/src/app/[lng]/dataStatistics/components/DataStatisticsHeader/index.tsx
@@ -4,8 +4,17 @@ import AccountCount from "../../svgs/accountCount.svg";
import { Swiper, SwiperSlide } from "swiper/react";
import { useAccountStore } from "@/store/account";
import { useShallow } from "zustand/react/shallow";
-import { Input, Select } from "antd";
+import { Button, Input, Select, Tag } from "antd";
import { useDataStatisticsStore } from "@/app/[lng]/dataStatistics/useDataStatistics";
+import {
+ CheckCircleOutlined,
+ LeftOutlined,
+ RightOutlined,
+ WarningOutlined,
+} from "@ant-design/icons";
+import { Navigation } from "swiper/modules";
+import "swiper/css";
+import "swiper/css/navigation";
export interface IDataStatisticsHeaderRef {}
@@ -17,18 +26,19 @@ const DataStatisticsHeader = memo(
{}: IDataStatisticsHeaderProps,
ref: ForwardedRef<IDataStatisticsHeaderRef>,
) => {
- const { accountList, accountGroupList } = useAccountStore(
+ const { accountGroupList } = useAccountStore(
useShallow((state) => ({
- accountList: state.accountList,
accountGroupList: state.accountGroupList,
})),
);
- const { choosedGroupIds, setChoosedGroupIds } = useDataStatisticsStore(
- useShallow((state) => ({
- setChoosedGroupIds: state.setChoosedGroupIds,
- choosedGroupIds: state.choosedGroupIds,
- })),
- );
+ const { choosedGroupIds, setChoosedGroupIds, filteredAccountList } =
+ useDataStatisticsStore(
+ useShallow((state) => ({
+ setChoosedGroupIds: state.setChoosedGroupIds,
+ choosedGroupIds: state.choosedGroupIds,
+ filteredAccountList: state.filteredAccountList,
+ })),
+ );
return (
<div className={styles.dataStatisticsHeader}>
@@ -47,7 +57,10 @@ const DataStatisticsHeader = memo(
setChoosedGroupIds(value);
}}
/>
- <Input.Search style={{ width: '300px' }} placeholder="请输入账号名称" />
+ <Input.Search
+ style={{ width: "300px" }}
+ placeholder="请输入账号名称"
+ />
</div>
</div>
@@ -58,11 +71,36 @@ const DataStatisticsHeader = memo(
累计账号数
</div>
<div className="dataStatisticsHeader-accountCount-number">4</div>
+ <Tag bordered={false} icon={<CheckCircleOutlined />}>
+ 在线 <b>1</b>
+ </Tag>
+ <br />
+ <Tag bordered={false} icon={<WarningOutlined />}>
+ 离线 <b>3</b>
+ </Tag>
</div>
- <Swiper>
- <SwiperSlide></SwiperSlide>
- </Swiper>
+ <div className="dataStatisticsHeader-accounts-swiper">
+ <Button className="swiper-prev" icon={<LeftOutlined />} />
+ <Swiper
+ modules={[Navigation]}
+ slidesPerView={4}
+ slidesPerGroup={4}
+ navigation={{
+ prevEl: ".swiper-prev",
+ nextEl: ".swiper-next",
+ }}
+ >
+ {filteredAccountList.map((account) => {
+ return (
+ <SwiperSlide key={account.id}>
+ {account.nickname}
+ </SwiperSlide>
+ );
+ })}
+ </Swiper>
+ <Button className="swiper-next" icon={<RightOutlined />} />
+ </div>
</div>
</div>
);
diff --git a/src/app/[lng]/dataStatistics/useDataStatistics.ts b/src/app/[lng]/dataStatistics/useDataStatistics.ts
index c981d1d3..fd6e0556 100644
--- a/src/app/[lng]/dataStatistics/useDataStatistics.ts
+++ b/src/app/[lng]/dataStatistics/useDataStatistics.ts
@@ -1,13 +1,17 @@
import { create } from "zustand/index";
import { combine } from "zustand/middleware";
+import { SocialAccount } from "@/api/types/account.type";
export interface IDataStatisticsStore {
// 当前选择的账户组IDs
choosedGroupIds: string[];
+ // 过滤之后的账户
+ filteredAccountList: SocialAccount[];
}
const state: IDataStatisticsStore = {
choosedGroupIds: [],
+ filteredAccountList: [],
};
export const useDataStatisticsStore = create(
@@ -23,6 +27,12 @@ export const useDataStatisticsStore = create(
choosedGroupIds,
});
},
+ // 设置过滤之后的账户
+ setFilteredAccountList(filteredAccountList: SocialAccount[]) {
+ set({
+ filteredAccountList,
+ });
+ },
};
return methods;
diff --git a/src/app/var.css b/src/app/var.css
index 3a1404c1..1d0e3378 100644
--- a/src/app/var.css
+++ b/src/app/var.css
@@ -73,6 +73,8 @@
--border-color: #e5e7eb;
--background-color: #fff;
--card-background: #fff;
+ /* 警告颜色 */
+ --warning-color: #f59e0b;
/* 错误颜色 */
--error-color: #ef4444;
/* 成功色 */
diff --git a/src/store/account.ts b/src/store/account.ts
index c8af2462..4a5ba402 100644
--- a/src/store/account.ts
+++ b/src/store/account.ts
@@ -3,7 +3,6 @@ import { combine } from "zustand/middleware";
import lodash from "lodash";
import { AccountGroupItem, SocialAccount } from "@/api/types/account.type";
import { getAccountGroupApi, getAccountListApi } from "@/api/account";
-import { PlatType } from "@/app/config/platConfig";
import { directTrans } from "@/app/i18n/client";
export interface AccountGroup extends AccountGroupItem {
@@ -75,12 +74,6 @@ export const useAccountStore = create(
const accountList: SocialAccount[] = [];
for (const item of result.data) {
- if (
- item.type === PlatType.Xhs ||
- item.type === PlatType.Douyin ||
- item.type === PlatType.WxSph
- )
- continue;
accountMap.set(item.id, item);
accountAccountMap.set(item.account, item);
accountList.push(item);
@@ -101,7 +94,7 @@ export const useAccountStore = create(
if (!groupList) return;
if (groupList.length === 0) return;
- groupList.map((v:any) => {
+ groupList.map((v: any) => {
v.name = v.isDefault
? directTrans("account", "defaultSpace")
: v.name;
@@ -111,9 +104,9 @@ export const useAccountStore = create(
// key=组ID,val=账户ID
const accountGroupMap = new Map<string, AccountGroup>();
- const defaultGroup = groupList.find((v:any) => v.isDefault)!;
+ const defaultGroup = groupList.find((v: any) => v.isDefault)!;
- groupList.map((v:any) => {
+ groupList.map((v: any) => {
const accountGroupItem = {
...v,
children: [],
@@ -122,10 +115,12 @@ export const useAccountStore = create(
accountGroupMap.set(v.id, accountGroupItem);
});
get().accountList.map((v) => {
- (
- accountGroupMap.get(v.groupId!) ||
- accountGroupMap.get(defaultGroup.id)!
- ).children?.push(v);
+ if (accountGroupMap.get(v.groupId!)) {
+ accountGroupMap.get(v.groupId!)!.children?.push(v);
+ } else {
+ accountGroupMap.get(defaultGroup.id)!.children?.push(v);
+ v.groupId = defaultGroup.id;
+ }
});
accountGroupList.sort((a, b) => {