Skip to content

Let's use AI to Earn!

feat: AI工具排行篇开发完成

gaoSircd28febcccf7
diff --git a/src/api/platform.ts b/src/api/platform.ts
index 74125ef2..59aa9547 100644
--- a/src/api/platform.ts
+++ b/src/api/platform.ts
@@ -3,6 +3,10 @@ import { HotTopic } from './types/hotTopic';
import { Topic } from './types/topic';
import { ViralTitle } from './types/viralTitles';
import { hotHttp } from './request';
+import {
+ GetAiToolsRankingApiParams,
+ GetAiToolsRankingApiRes,
+} from './types/platform.type';
export interface Platform {
id: string;
@@ -252,7 +256,8 @@ export const platformApi = {
},
// 获取平台下所有分类的前五条数据
- findTopByPlatformAndCategories(platformId: string,
+ findTopByPlatformAndCategories(
+ platformId: string,
timeType?: string, // 时间分类
) {
return hotHttp.get<
@@ -342,5 +347,12 @@ export const platformApi = {
});
},
+ // 获取AI工具榜数据
+ getAiToolsRankingApi(data: GetAiToolsRankingApiParams) {
+ return hotHttp.post<GetAiToolsRankingApiRes>(`/products/ranking/ai`, {
+ ...data,
+ pageSize: 100,
+ area: +data.area,
+ });
+ },
};
-
diff --git a/src/api/types/platform.type.ts b/src/api/types/platform.type.ts
new file mode 100644
index 00000000..fcfd5604
--- /dev/null
+++ b/src/api/types/platform.type.ts
@@ -0,0 +1,61 @@
+export type AiToolsRankingItemType = {
+ _id: string;
+ rankingId: string;
+ col_name: string;
+ status: number;
+ videoDuration: number;
+ anaAdd: null | string;
+ url: string;
+ category: string;
+ subCategory: string;
+ type: null | string;
+ shareCount: number;
+ collectCount: null | number;
+ cover: string;
+ description: string;
+ title: string;
+ createTime: string;
+ updateTime: string;
+ author: {
+ id: null | string;
+ name: null | string;
+ fansCount: null | number;
+ avatar: null | string;
+ };
+ stats: {
+ viewCount: string;
+ likeCount: number;
+ commentCount: number;
+ };
+ publishTime: string;
+ rankingPosition: number;
+ spider_time: null | string;
+ platformId: string;
+ originalId: string;
+ downCount: string;
+ referCount: number;
+ volumeCount: number;
+ exponentCount: number;
+ intro: string;
+ rankChange: number;
+ detail: {
+ 公众号: number;
+ 抖音: number;
+ 视频号: number;
+ 小红书: number;
+ 快手: number;
+ 哔哩哔哩: number;
+ };
+ area: number;
+ id: string;
+};
+
+export interface GetAiToolsRankingApiRes {
+ items: AiToolsRankingItemType[];
+}
+
+export interface GetAiToolsRankingApiParams {
+ dateType: string;
+ startDate: string;
+ area: string;
+}
diff --git a/src/index.scss b/src/index.scss
index 07530d5a..7425cec9 100644
--- a/src/index.scss
+++ b/src/index.scss
@@ -121,6 +121,10 @@ ul {
}
/* 全局自定义滚动条样式 */
+.ant-table-body {
+ scrollbar-width: auto;
+ scrollbar-color: auto;
+}
*::-webkit-scrollbar {
width: 10px;
height: 10px;
@@ -139,4 +143,4 @@ ul {
*::-webkit-scrollbar-thumb:hover {
background: #a2a2a2;
-}
\ No newline at end of file
+}
diff --git a/src/views/aiTool/children/aiRanking/aiRanking.module.scss b/src/views/aiTool/children/aiRanking/aiRanking.module.scss
index b1ee87e1..0b2fd730 100644
--- a/src/views/aiTool/children/aiRanking/aiRanking.module.scss
+++ b/src/views/aiTool/children/aiRanking/aiRanking.module.scss
@@ -1,15 +1,80 @@
.aiRanking {
padding: 15px;
width: 100%;
+ min-width: 0;
height: 100%;
box-sizing: border-box;
+ display: flex;
+ flex-direction: column;
+ min-height: 0;
font-size: 14px;
:global {
+ .aiRanking-rank, .aiRanking-topthree {
+ width: 30px;
+ height: 30px;
+ text-align: center;
+ line-height: 30px;
+ font-size: var(--fs-md);
+ }
+ .ant-table-tbody {
+ .ant-table-row {
+ &:nth-child(odd) {
+ background: #f2f5f6;
+ }
+ td {
+ .anticon {
+ margin-left: 5px;
+ cursor: pointer;
+ }
+ }
+ }
+ }
+ .aiRanking-topthree {
+ color: #fff;
+ background: url("../../images/bg-rank-index.png") no-repeat center / cover;
+ }
+ .ant-table-thead {
+ th {
+ color: #9a9a9a !important;
+ padding-top: 10px !important;
+ padding-bottom: 10px !important;
+ font-weight: 400 !important;
+ .anticon {
+ margin-left: 5px;
+ }
+ }
+ }
.aiRanking-title {
- margin-bottom: 30px;
+ margin-bottom: 20px;
font-weight: 900;
font-size: 24px;
}
+ .aiRanking-productName {
+ display: flex;
+ align-items: center;
+ overflow: hidden;
+ label {
+ font-size: var(--fs-md);
+ margin-bottom: 6px;
+ }
+ .ant-avatar {
+ white-space: nowrap;
+ flex-shrink: 0;
+ }
+ &-con {
+ overflow: hidden;
+ margin-left: 10px;
+ white-space: nowrap;
+ text-overflow: ellipsis;
+ &-des {
+ overflow: hidden;
+ text-overflow: ellipsis;
+ width: 100%;
+ color: var(--grayColor8);
+ font-size: var(--fs-xs);
+ }
+ }
+ }
.aiRanking-head {
width: 100%;
margin-bottom: 10px;
@@ -30,5 +95,11 @@
}
}
}
+
+ .aiRanking-content {
+ height: 100%;
+ min-width: 0;
+ display: flex;
+ }
}
-}
\ No newline at end of file
+}
diff --git a/src/views/aiTool/children/aiRanking/echarts-weekPie.ts b/src/views/aiTool/children/aiRanking/echarts-weekPie.ts
new file mode 100644
index 00000000..85ee2f92
--- /dev/null
+++ b/src/views/aiTool/children/aiRanking/echarts-weekPie.ts
@@ -0,0 +1,45 @@
+import * as echarts from 'echarts';
+import { CallbackDataParams } from 'echarts/types/src/util/types';
+
+type EChartsOption = echarts.EChartsOption;
+
+const initWeepPie = (
+ chartDom: HTMLDivElement,
+ data: {
+ value: number;
+ name: string;
+ }[],
+) => {
+ if (!chartDom) return;
+ const myChart = echarts.init(chartDom);
+
+ const option: EChartsOption = {
+ tooltip: {
+ trigger: 'item',
+ formatter: (params: echarts.TooltipComponentFormatterCallbackParams) => {
+ params = params as CallbackDataParams;
+ const total = data.reduce((sum, item) => sum + item.value, 0);
+ const percent = (((params.value as number) / total) * 100).toFixed(2); // 计算百分比并保留两位小数
+ return `${params.name}: ${params.value} (${percent}%)`; // 格式化显示文本
+ },
+ },
+ series: [
+ {
+ type: 'pie',
+ radius: '60%',
+ label: {
+ formatter: (params: any) => {
+ const total = data.reduce((sum, item) => sum + item.value, 0);
+ const percent = ((params.value / total) * 100).toFixed(0); // 百分比
+ return `${params.name} ${params.value}(${percent}%) `; // 自定义显示名称、数值和百分比
+ },
+ },
+ data,
+ },
+ ],
+ };
+
+ if (option) myChart.setOption(option);
+};
+
+export default initWeepPie;
diff --git a/src/views/aiTool/children/aiRanking/index.tsx b/src/views/aiTool/children/aiRanking/index.tsx
index 1c398967..e5660736 100644
--- a/src/views/aiTool/children/aiRanking/index.tsx
+++ b/src/views/aiTool/children/aiRanking/index.tsx
@@ -1,34 +1,284 @@
import styles from './aiRanking.module.scss';
import RankingTags from '../../components/RankingTags';
import Cycleselects, { CycleTypeEnum } from '../../components/CycleSelects';
+import { useEffect, useMemo, useRef, useState } from 'react';
+import { platformApi } from '../../../../api/platform';
+import {
+ AiToolsRankingItemType,
+ GetAiToolsRankingApiParams,
+} from '../../../../api/types/platform.type';
+import { Avatar, Popover, Table, TableProps, Tooltip } from 'antd';
+import { QuestionCircleOutlined, SearchOutlined } from '@ant-design/icons';
+import initWeepPie from './echarts-weekPie';
-const options = [
+const optionsTags = [
{
label: '总榜',
- value: 'all',
+ value: '1',
},
{
label: '国内榜',
- value: 'cn',
+ value: '2',
},
{
label: '国外榜',
- value: 'en',
+ value: '3',
},
];
+function parseChineseNumber(input: string): number {
+ if (!input) return 0;
+ const units: { [key: string]: number } = {
+ 千: 1000,
+ 万: 10000,
+ 亿: 100000000,
+ };
+
+ let result = 0;
+ let currentNumber = 0;
+ let decimalPart = 0;
+ let isDecimal = false;
+ let decimalScale = 0.1;
+
+ for (const char of input) {
+ if (char === '.') {
+ isDecimal = true; // 标记进入小数部分
+ continue;
+ }
+
+ if (char in units) {
+ if (isDecimal) {
+ result += (currentNumber + decimalPart) * units[char];
+ } else {
+ result += currentNumber * units[char];
+ }
+ currentNumber = 0;
+ decimalPart = 0;
+ isDecimal = false;
+ decimalScale = 0.1;
+ } else {
+ const num = parseInt(char, 10);
+ if (!isNaN(num)) {
+ if (isDecimal) {
+ decimalPart += num * decimalScale;
+ decimalScale *= 0.1;
+ } else {
+ currentNumber = currentNumber * 10 + num;
+ }
+ }
+ }
+ }
+
+ // 如果最后还有剩余的数字或小数部分,直接加到结果里
+ result += currentNumber + decimalPart;
+
+ return result;
+}
+
export default function Page() {
+ const [params, setParams] = useState<GetAiToolsRankingApiParams>({
+ dateType: '',
+ startDate: '',
+ area: '1',
+ });
+ const [loading, setLoading] = useState(false);
+ const [data, setData] = useState<AiToolsRankingItemType[]>([]);
+ const aiRankingContentRef = useRef<HTMLDivElement>(null);
+ const [tableHeight, setTableHeight] = useState(200);
+
+ useEffect(() => {
+ setTableHeight(aiRankingContentRef.current!.offsetHeight - 55);
+ }, []);
+
+ useEffect(() => {
+ if (params.dateType === '' || params.startDate === '') return;
+ if (loading) return;
+ setLoading(true);
+ platformApi.getAiToolsRankingApi(params).then((res) => {
+ setLoading(false);
+ setData(res.items);
+ document.querySelector('.ant-table-body')!.scrollTo(0, 0);
+ });
+ }, [params]);
+
+ const columns = useMemo(() => {
+ const columns: TableProps<AiToolsRankingItemType>['columns'] = [
+ {
+ title: () => <p style={{ textAlign: 'center' }}>#</p>,
+ render: (text, prm, ind) => {
+ if (ind <= 2) {
+ return <div className="aiRanking-topthree">{ind + 1}</div>;
+ }
+ return <div className="aiRanking-rank">{ind + 1}</div>;
+ },
+ width: 40,
+ key: '序号',
+ },
+ {
+ title: '产品名',
+ render: (text, prm) => {
+ return (
+ <div className="aiRanking-productName">
+ <Avatar src={prm.cover} size="large" />
+ <div className="aiRanking-productName-con">
+ <label>{prm.title}</label>
+ <div
+ className="aiRanking-productName-con-des"
+ title={prm.description}
+ >
+ {prm.description}
+ </div>
+ </div>
+ </div>
+ );
+ },
+ width: 250,
+ key: 'title',
+ },
+ {
+ title: '标签',
+ render: (text, prm) => {
+ return (
+ <div className="aiRanking-productName">
+ <div className="aiRanking-productName-con">{prm.intro}</div>
+ </div>
+ );
+ },
+ width: 200,
+ key: 'title',
+ },
+ {
+ title: '月访问量',
+ render: (text, prm) => {
+ return prm.stats.viewCount;
+ },
+ sorter: (a, b) =>
+ parseChineseNumber(b.stats.viewCount) -
+ parseChineseNumber(a.stats.viewCount),
+ width: 80,
+ key: 'title',
+ },
+ {
+ title: '月下载量',
+ render: (text, prm) => {
+ return prm.downCount;
+ },
+ sorter: (a, b) =>
+ parseChineseNumber(b.downCount) - parseChineseNumber(a.downCount),
+ width: 80,
+ key: '月下载量',
+ },
+ {
+ title: () => {
+ return (
+ <>
+ 周提及量
+ <Tooltip title="统计AI工具排行榜的周提及作品数">
+ <QuestionCircleOutlined />
+ </Tooltip>
+ </>
+ );
+ },
+ sorter: (a, b) => b.referCount - a.referCount,
+ render: (text, prm, ind) => {
+ return (
+ <>
+ {prm.referCount}
+ <Popover
+ content={() => {
+ return (
+ <>
+ <div
+ className={`weekChat${ind}`}
+ style={{ width: '350px', height: '200px' }}
+ />
+ </>
+ );
+ }}
+ onOpenChange={() => {
+ setTimeout(() => {
+ initWeepPie(
+ document.querySelector(`.weekChat${ind}`)!,
+ Object.keys(prm.detail).map((key) => {
+ return {
+ name: key,
+ value: prm.detail[key as '抖音'],
+ };
+ }),
+ );
+ }, 10);
+ }}
+ >
+ <SearchOutlined />
+ </Popover>
+ </>
+ );
+ },
+ width: 80,
+ key: 'referCount',
+ },
+ {
+ title: () => {
+ return (
+ <>
+ 声望值
+ <Tooltip title="统计AI工具排行榜的提及作品、传播范围等多维度数据分析做出的综合评分">
+ <QuestionCircleOutlined />
+ </Tooltip>
+ </>
+ );
+ },
+ sorter: (a, b) => b.volumeCount - a.volumeCount,
+ render: (text, prm) => {
+ return prm.volumeCount;
+ },
+ width: 80,
+ key: 'volumeCount',
+ },
+ {
+ title: () => {
+ return (
+ <>
+ 综合评分
+ <Tooltip title="统计AI工具排行榜的用户使用情况等多维度数据分析做出的综合评分">
+ <QuestionCircleOutlined />
+ </Tooltip>
+ </>
+ );
+ },
+ sorter: (a, b) => b.exponentCount - a.exponentCount,
+ render: (text, prm) => {
+ return (
+ <span style={{ color: 'var(--colorPrimary6)' }}>
+ {prm.exponentCount}
+ </span>
+ );
+ },
+ width: 80,
+ key: 'exponentCount',
+ },
+ ];
+ return columns;
+ }, []);
+
return (
<div className={styles.aiRanking}>
- <div className="aiRanking-title">AI产品 · 总榜 · 周榜</div>
+ <div className="aiRanking-title">
+ AI工具排行榜 · {optionsTags.find((v) => v.value === params.area)?.label}{' '}
+ ·{params.dateType === CycleTypeEnum.Week ? '周榜' : '月榜'}
+ </div>
<div className="aiRanking-head">
<div className="aiRanking-head-item">
<div className="aiRanking-head-title">类型</div>
<RankingTags
- options={options}
- defaultValue={options[0].value}
+ options={optionsTags}
+ defaultValue={optionsTags[0].value}
onChange={(val) => {
- console.log(val);
+ setParams((prevState) => {
+ const newState = { ...prevState };
+ newState.area = val;
+ return newState;
+ });
}}
/>
</div>
@@ -38,12 +288,30 @@ export default function Page() {
<Cycleselects
defaultType={CycleTypeEnum.Week}
onChange={(v) => {
- console.log(v);
+ setParams((prevState) => {
+ const newState = { ...prevState };
+ newState.dateType = v.type;
+ newState.startDate = v.value;
+ return newState;
+ });
}}
/>
</div>
</div>
</div>
+
+ <div className="aiRanking-content" ref={aiRankingContentRef}>
+ <Table<AiToolsRankingItemType>
+ columns={columns}
+ dataSource={data}
+ rowKey="id"
+ loading={loading}
+ pagination={false}
+ scroll={{
+ y: tableHeight,
+ }}
+ />
+ </div>
</div>
);
}
diff --git a/src/views/aiTool/components/CycleSelects/index.tsx b/src/views/aiTool/components/CycleSelects/index.tsx
index 11f34f71..10d8ab4e 100644
--- a/src/views/aiTool/components/CycleSelects/index.tsx
+++ b/src/views/aiTool/components/CycleSelects/index.tsx
@@ -7,8 +7,8 @@ import isoWeek from 'dayjs/plugin/isoWeek';
dayjs.extend(isoWeek);
export enum CycleTypeEnum {
- Week = 1,
- Month = 2,
+ Week = 'week',
+ Month = 'month',
}
type CycleItemType = {
@@ -21,6 +21,7 @@ export interface ICycleselectsRef {}
export interface ICycleselectsProps {
onChange: (params: { type: CycleTypeEnum; value: string }) => void;
defaultType: CycleTypeEnum;
+ disable?: boolean;
}
const CycleseCore = ({
@@ -60,11 +61,14 @@ const CycleseCore = ({
*/
function getMonths(skipMonths: number, numberOfMonths: number) {
const currentMonth = dayjs().startOf('month'); // 当前月的开始时间
- const months: string[] = [];
+ const months: CycleItemType[] = [];
for (let i = 0; i < numberOfMonths; i++) {
const month = currentMonth.subtract(skipMonths + i + 1, 'month');
- months.push(month.format('YYYY年MM月'));
+ months.push({
+ label: month.format('YYYY年MM月'),
+ value: month.format('YYYY-MM-DD'),
+ });
}
return months;
@@ -77,10 +81,7 @@ function getMonths(skipMonths: number, numberOfMonths: number) {
*/
function getWeekRanges(skipWeeks: number, numberOfWeeks: number) {
const currentWeekStart = dayjs().startOf('isoWeek'); // 当前周的开始时间(周一)
- const ranges: {
- start: string;
- end: string;
- }[] = [];
+ const ranges: CycleItemType[] = [];
for (let i = 0; i < numberOfWeeks; i++) {
const startOfWeek = currentWeekStart
@@ -88,8 +89,8 @@ function getWeekRanges(skipWeeks: number, numberOfWeeks: number) {
.startOf('isoWeek');
const endOfWeek = startOfWeek.endOf('isoWeek');
ranges.push({
- start: startOfWeek.format('MM月DD日'),
- end: endOfWeek.format('MM月DD日'),
+ label: `${startOfWeek.format('MM月DD日')} - ${endOfWeek.format('MM月DD日')}`,
+ value: startOfWeek.format('YYYY-MM-DD'),
});
}
@@ -103,11 +104,14 @@ function getWeekRanges(skipWeeks: number, numberOfWeeks: number) {
*/
function getDays(skipDays: number, numberOfDays: number) {
const currentDay = dayjs().startOf('day'); // 当前天的起始时间
- const days: string[] = [];
+ const days: CycleItemType[] = [];
for (let i = 0; i < numberOfDays; i++) {
const day = currentDay.subtract(skipDays + i + 1, 'day');
- days.push(day.format('YYYY年MM月DD日'));
+ days.push({
+ value: day.format('YYYY年MM月DD日'),
+ label: day.format('YYYY-MM-DD'),
+ });
}
return days;
@@ -116,7 +120,7 @@ function getDays(skipDays: number, numberOfDays: number) {
const Cycleselects = memo(
forwardRef(
(
- { onChange, defaultType }: ICycleselectsProps,
+ { onChange, defaultType, disable }: ICycleselectsProps,
ref: ForwardedRef<ICycleselectsRef>,
) => {
// 1周榜 2=月榜
@@ -126,21 +130,10 @@ const Cycleselects = memo(
const [monthsOptions, setMonthsOptions] = useState<CycleItemType[]>([]);
useEffect(() => {
- const weekOptions = getWeekRanges(1, 3).map((v) => {
- const value = `${v.start}-${v.start}`;
- return {
- label: value,
- value,
- };
- });
+ const weekOptions = getWeekRanges(1, 3);
setWeekOptions(weekOptions);
- const monthsOptions = getMonths(0, 3).map((v) => {
- return {
- label: v,
- value: v,
- };
- });
+ const monthsOptions = getMonths(0, 3);
setMonthsOptions(monthsOptions);
if (defaultType === CycleTypeEnum.Week) {
@@ -173,6 +166,7 @@ const Cycleselects = memo(
value={value}
isActive={active === CycleTypeEnum.Week}
onActiveClick={() => {
+ if (disable) return;
setActive(CycleTypeEnum.Week);
}}
onChange={setValue}
@@ -184,6 +178,7 @@ const Cycleselects = memo(
value={value}
isActive={active === CycleTypeEnum.Month}
onActiveClick={() => {
+ if (disable) return;
setActive(CycleTypeEnum.Month);
}}
onChange={setValue}
diff --git a/src/views/aiTool/images/bg-rank-index.png b/src/views/aiTool/images/bg-rank-index.png
new file mode 100644
index 00000000..ed4c7e69
Binary files /dev/null and b/src/views/aiTool/images/bg-rank-index.png differ