Skip to content

Let's use AI to Earn!

feat: AI榜单筛选开发完成

gaoSirc40bfd7fb643
diff --git a/src/index.scss b/src/index.scss
index 4ae39dde..07530d5a 100644
--- a/src/index.scss
+++ b/src/index.scss
@@ -5,6 +5,9 @@
body {
background: #fff;
color: #222;
+ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial,
+ 'Noto Sans', sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol',
+ 'Noto Color Emoji';
}
.ant-tabs-dropdown {
diff --git a/src/views/aiTool/children/aiRanking/index.tsx b/src/views/aiTool/children/aiRanking/index.tsx
index ce604043..1c398967 100644
--- a/src/views/aiTool/children/aiRanking/index.tsx
+++ b/src/views/aiTool/children/aiRanking/index.tsx
@@ -1,6 +1,6 @@
import styles from './aiRanking.module.scss';
import RankingTags from '../../components/RankingTags';
-import Cycleselects from '../../components/CycleSelects';
+import Cycleselects, { CycleTypeEnum } from '../../components/CycleSelects';
const options = [
{
@@ -24,12 +24,23 @@ export default function Page() {
<div className="aiRanking-head">
<div className="aiRanking-head-item">
<div className="aiRanking-head-title">类型</div>
- <RankingTags options={options} defaultValue={options[0].value} />
+ <RankingTags
+ options={options}
+ defaultValue={options[0].value}
+ onChange={(val) => {
+ console.log(val);
+ }}
+ />
</div>
<div className="aiRanking-head-item">
<div className="aiRanking-head-title">周期</div>
<div className="aiRanking-head-cycleselects">
- <Cycleselects />
+ <Cycleselects
+ defaultType={CycleTypeEnum.Week}
+ onChange={(v) => {
+ console.log(v);
+ }}
+ />
</div>
</div>
</div>
diff --git a/src/views/aiTool/components/CycleSelects/cycleSelects.module.scss b/src/views/aiTool/components/CycleSelects/cycleSelects.module.scss
index baf2f8c9..f76f73fc 100644
--- a/src/views/aiTool/components/CycleSelects/cycleSelects.module.scss
+++ b/src/views/aiTool/components/CycleSelects/cycleSelects.module.scss
@@ -1,3 +1,24 @@
.cycleSelects {
-
+ display: flex;
+ :global {
+ .cycleSelects-item {
+ display: flex;
+ align-items: center;
+ height: 32px;
+ margin-right: 30px;
+ &-label {
+ height: 100%;
+ display: flex;
+ align-items: center;
+ padding: 0 10px;
+ border-radius: 8px 0 0 8px;
+ background: var(--colorPrimary3);
+ color: var(--colorPrimary8);
+ }
+ .ant-select-selector {
+ border-bottom-left-radius: 0;
+ border-top-left-radius: 0;
+ }
+ }
+ }
}
\ No newline at end of file
diff --git a/src/views/aiTool/components/CycleSelects/index.tsx b/src/views/aiTool/components/CycleSelects/index.tsx
index d33e1e51..11f34f71 100644
--- a/src/views/aiTool/components/CycleSelects/index.tsx
+++ b/src/views/aiTool/components/CycleSelects/index.tsx
@@ -1,22 +1,199 @@
-import { ForwardedRef, forwardRef, memo } from 'react';
+import { ForwardedRef, forwardRef, memo, useEffect, useState } from 'react';
import styles from './cycleSelects.module.scss';
+import { Button, Select } from 'antd';
+import dayjs from 'dayjs';
+import isoWeek from 'dayjs/plugin/isoWeek';
+
+dayjs.extend(isoWeek);
+
+export enum CycleTypeEnum {
+ Week = 1,
+ Month = 2,
+}
+
+type CycleItemType = {
+ value: string;
+ label: string;
+};
export interface ICycleselectsRef {}
-export interface ICycleselectsProps {}
+export interface ICycleselectsProps {
+ onChange: (params: { type: CycleTypeEnum; value: string }) => void;
+ defaultType: CycleTypeEnum;
+}
-const CycleseCore = () => {
- return <></>;
+const CycleseCore = ({
+ title,
+ options,
+ onChange,
+ onActiveClick,
+ isActive,
+ value,
+}: {
+ onChange: (value: string) => void;
+ title: string;
+ options: CycleItemType[];
+ onActiveClick: () => void;
+ isActive: boolean;
+ value: string;
+}) => {
+ return (
+ <div className="cycleSelects-item">
+ {isActive}
+ {isActive ? (
+ <>
+ <div className="cycleSelects-item-label">{title}</div>
+ <Select options={options} value={value} onChange={onChange}></Select>
+ </>
+ ) : (
+ <Button onClick={onActiveClick}>{title}</Button>
+ )}
+ </div>
+ );
};
+/**
+ * 获取指定数量的月份
+ * @param {number} skipMonths 跳过的月份数(当前月不算)
+ * @param {number} numberOfMonths 获取的月份数
+ */
+function getMonths(skipMonths: number, numberOfMonths: number) {
+ const currentMonth = dayjs().startOf('month'); // 当前月的开始时间
+ const months: string[] = [];
+
+ for (let i = 0; i < numberOfMonths; i++) {
+ const month = currentMonth.subtract(skipMonths + i + 1, 'month');
+ months.push(month.format('YYYY年MM月'));
+ }
+
+ return months;
+}
+
+/**
+ * 获取指定周范围的周
+ * @param {number} skipWeeks 跳过的周数(当前周不算)
+ * @param {number} numberOfWeeks 获取的周数
+ */
+function getWeekRanges(skipWeeks: number, numberOfWeeks: number) {
+ const currentWeekStart = dayjs().startOf('isoWeek'); // 当前周的开始时间(周一)
+ const ranges: {
+ start: string;
+ end: string;
+ }[] = [];
+
+ for (let i = 0; i < numberOfWeeks; i++) {
+ const startOfWeek = currentWeekStart
+ .subtract(skipWeeks + i + 1, 'week')
+ .startOf('isoWeek');
+ const endOfWeek = startOfWeek.endOf('isoWeek');
+ ranges.push({
+ start: startOfWeek.format('MM月DD日'),
+ end: endOfWeek.format('MM月DD日'),
+ });
+ }
+
+ return ranges;
+}
+
+/**
+ * 获取指定数量的日期
+ * @param {number} skipDays 跳过的天数(当前日不算)
+ * @param {number} numberOfDays 获取的天数
+ */
+function getDays(skipDays: number, numberOfDays: number) {
+ const currentDay = dayjs().startOf('day'); // 当前天的起始时间
+ const days: string[] = [];
+
+ for (let i = 0; i < numberOfDays; i++) {
+ const day = currentDay.subtract(skipDays + i + 1, 'day');
+ days.push(day.format('YYYY年MM月DD日'));
+ }
+
+ return days;
+}
+
const Cycleselects = memo(
- forwardRef(({}: ICycleselectsProps, ref: ForwardedRef<ICycleselectsRef>) => {
- return (
- <div className={styles.cycleSelects}>
- <CycleseCore />
- </div>
- );
- }),
+ forwardRef(
+ (
+ { onChange, defaultType }: ICycleselectsProps,
+ ref: ForwardedRef<ICycleselectsRef>,
+ ) => {
+ // 1周榜 2=月榜
+ const [active, setActive] = useState<CycleTypeEnum>(defaultType);
+ const [value, setValue] = useState('');
+ const [weekOptions, setWeekOptions] = useState<CycleItemType[]>([]);
+ const [monthsOptions, setMonthsOptions] = useState<CycleItemType[]>([]);
+
+ useEffect(() => {
+ const weekOptions = getWeekRanges(1, 3).map((v) => {
+ const value = `${v.start}-${v.start}`;
+ return {
+ label: value,
+ value,
+ };
+ });
+ setWeekOptions(weekOptions);
+
+ const monthsOptions = getMonths(0, 3).map((v) => {
+ return {
+ label: v,
+ value: v,
+ };
+ });
+ setMonthsOptions(monthsOptions);
+
+ if (defaultType === CycleTypeEnum.Week) {
+ setValue(weekOptions[0].value);
+ }
+ }, []);
+
+ useEffect(() => {
+ if (!value) return;
+ onChange({
+ type: active,
+ value,
+ });
+ }, [value]);
+
+ useEffect(() => {
+ if (active === CycleTypeEnum.Week) {
+ if (weekOptions[0]?.value) setValue(weekOptions[0]?.value);
+ return;
+ }
+ if (active === CycleTypeEnum.Month) {
+ if (monthsOptions[0]?.value) setValue(monthsOptions[0]?.value);
+ return;
+ }
+ }, [active]);
+
+ return (
+ <div className={styles.cycleSelects}>
+ <CycleseCore
+ value={value}
+ isActive={active === CycleTypeEnum.Week}
+ onActiveClick={() => {
+ setActive(CycleTypeEnum.Week);
+ }}
+ onChange={setValue}
+ title="周榜"
+ options={weekOptions}
+ />
+
+ <CycleseCore
+ value={value}
+ isActive={active === CycleTypeEnum.Month}
+ onActiveClick={() => {
+ setActive(CycleTypeEnum.Month);
+ }}
+ onChange={setValue}
+ title="月榜"
+ options={monthsOptions}
+ />
+ </div>
+ );
+ },
+ ),
);
Cycleselects.displayName = 'Cycleselects';
diff --git a/src/views/aiTool/components/RankingTags/index.tsx b/src/views/aiTool/components/RankingTags/index.tsx
index f44b9928..d481d6a0 100644
--- a/src/views/aiTool/components/RankingTags/index.tsx
+++ b/src/views/aiTool/components/RankingTags/index.tsx
@@ -10,12 +10,13 @@ export interface IRankingtagsProps {
}[];
defaultValue: string;
disable?: boolean;
+ onChange: (value: string) => void;
}
const Rankingtags = memo(
forwardRef(
(
- { options, defaultValue, disable }: IRankingtagsProps,
+ { options, defaultValue, disable, onChange }: IRankingtagsProps,
ref: ForwardedRef<IRankingtagsRef>,
) => {
const [activeValue, setActiveValue] = useState(defaultValue);
@@ -32,6 +33,7 @@ const Rankingtags = memo(
key={v.value}
onClick={() => {
if (disable) return;
+ onChange(v.value);
setActiveValue(v.value);
}}
>