Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@
"@tarojs/components-advanced": "^4.1.2",
"@tarojs/helper": "4.1.2",
"@tarojs/plugin-framework-react": "4.1.2",
"@tarojs/plugin-html": "^4.0.6",
"@tarojs/plugin-html": "^4.1.2",
"@tarojs/plugin-platform-alipay": "4.1.2",
"@tarojs/plugin-platform-h5": "4.1.2",
"@tarojs/plugin-platform-jd": "4.1.2",
"@tarojs/plugin-platform-qq": "4.1.2",
"@tarojs/plugin-platform-swan": "4.1.2",
"@tarojs/plugin-platform-tt": "4.1.2",
"@tarojs/plugin-platform-weapp": "4.0.6",
"@tarojs/plugin-platform-weapp": "4.1.2",
"@tarojs/react": "4.1.2",
"@tarojs/runtime": "4.1.2",
"@tarojs/shared": "4.1.2",
Expand Down
1 change: 1 addition & 0 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ Taro.onAppShow(() => {
Taro.setStorageSync('visitor', false);
});
Taro.addInterceptor(interceptor);

class App extends Component<PropsWithChildren> {
state = {
isLoading: true,
Expand Down
44 changes: 44 additions & 0 deletions src/common/utils/generateSemesterOptions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { get } from '../api/get';

export interface semesterOptionsType {
yearOptions: string[];
// semesterOptions: string[];
currentSemester: { year: string; sem: string };
}

export const generateSemesterOptions = async (): Promise<semesterOptionsType> => {
const response = await get('/users/profile');
const { studentId } = response.data;

const currentYear = new Date().getFullYear();
const currentMonth = new Date().getMonth() + 1;
const firstOfUserYear = Number(studentId.slice(0, 4));

const yearOptions: string[] = [];
// const semesterOptions: string[] = [];
let currentSemester: { year: string; sem: string } = {} as {
year: string;
sem: string;
};
const currentSemesterNumber = currentMonth >= 3 ? 1 : currentMonth >= 6 ? 2 : 3;

for (let year = firstOfUserYear; year <= currentYear; year++) {
if (year === currentYear) {
if (currentMonth >= 6) yearOptions.push(`${year}-${year + 1}学年`);
} else {
yearOptions.push(`${year}-${year + 1}学年`);
}
}

if (currentSemesterNumber === 1) currentSemester.sem = '第一学期';
else if (currentSemesterNumber === 2) currentSemester.sem = '第二学期';
else if (currentSemesterNumber === 3) currentSemester.sem = '第三学期';

currentSemester.year = yearOptions[yearOptions.length - 1];

return {
yearOptions,
// semesterOptions,
currentSemester,
};
};
19 changes: 11 additions & 8 deletions src/pages/myclass/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { useEffect, useState } from 'react';
import './style.scss';

import { getUserCourses } from '@/common/api/getUserCourses';
import { generateSemesterOptions } from '@/common/utils/generateSemesterOptions';
import { NavigationBar } from '@/modules/navigation';

interface CouresProps {
Expand All @@ -22,15 +23,10 @@ interface CouresProps {

const Page: React.FC = () => {
//待优化点 别写死了
const [yearSelector] = useState<string[]>([
'2022-2023学年',
'2023-2024学年',
'2024-2025学年',
'2025-2026学年',
]);
const [yearSelector, setYearSelector] = useState<string[]>([]);
const [semSelector] = useState(['第一学期', '第二学期', '第三学期', '全部学期']);
const [year, setYear] = useState('2024-2025学年');
const [sem, setSem] = useState('第二学期');
const [year, setYear] = useState<string>('');
const [sem, setSem] = useState<string>('');

const [myclasses, setMyclasses] = useState<CouresProps[]>([]);

Expand All @@ -39,6 +35,7 @@ const Page: React.FC = () => {
setYear(yearSelector[yearIndex]);
setSem(semSelector[semIndex]);
};

async function fetchClasses() {
try {
const yearValue = year.split('-')[0];
Expand Down Expand Up @@ -78,6 +75,12 @@ const Page: React.FC = () => {
}, [year, sem]);
useDidShow(() => {
fetchCourses();
generateSemesterOptions().then(({ yearOptions, currentSemester }) => {
console.log(yearOptions, currentSemester);
setYearSelector(yearOptions);
setYear(currentSemester.year);
setSem(currentSemester.sem);
});
});

const handleClassClick = (item: CouresProps) => {
Expand Down
Loading
Loading