Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

merge #215

Merged
merged 3 commits into from
Dec 22, 2024
Merged

merge #215

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
16 changes: 11 additions & 5 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,22 @@ const interceptor: Taro.interceptor = function (chain: Taro.Chain) {
return chain.proceed(requestParams).then((res) => {
console.log(Taro.getStorageSync('shortToken'));

if (res.statusCode === 401 && Taro.getStorageSync('visitor') !== false) {
void Taro.reLaunch({ url: '/pages/login/index' });
Taro.showToast({
title: '登录过期,请重新登录',
icon: 'none',
if (res.statusCode === 401 && Taro.getStorageSync('visitor') !== true) {
console.log(res, Taro.getStorageSync('visitor'));

void Taro.reLaunch({ url: '/pages/login/index' }).then(() => {
Taro.showToast({
title: '登录过期,请重新登录',
icon: 'none',
});
});
}
return res;
}) as Taro.Chain;
};
Taro.onAppShow(() => {
Taro.setStorageSync('visitor', false);
});
Taro.addInterceptor(interceptor);
class App extends Component<PropsWithChildren> {
//TODO 写成加interceptor 但是我还没写明白 别急
Expand Down
5 changes: 3 additions & 2 deletions src/common/components/AnswerToStudent/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ interface Question {
content: string;
preview_answers: Array<Answerv1Answer>;
}

const AnswerToStudent: React.FC<Question> = (props) => {
const { content, preview_answers } = props;
return (
<View className="m-auto flex h-[4vh] w-[80vw] items-center justify-center gap-2">
<Image src={Ask as string} className="h-6 w-6" />
<View className="text-base font-medium text-gray-800">{content}</View>
<View className="w-[50vw] overflow-hidden text-ellipsis whitespace-nowrap text-base font-medium text-gray-800">
{content}
</View>
<View className="ml-auto text-sm text-gray-500">
{preview_answers?.length ?? 0} 个回答
</View>
Expand Down
4 changes: 2 additions & 2 deletions src/common/components/Comment/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
.then((res) => {
setPublisherInfo(res);
});
}, [props.course_id, props.publisher_id]);

Check warning on line 51 in src/common/components/Comment/index.tsx

View workflow job for this annotation

GitHub Actions / lint-and-format

React Hook useEffect has missing dependencies: 'course_id' and 'publisher_id'. Either include them or remove the dependency array
const navigateToPage = async () => {
await Taro.navigateTo({
url: `/pages/classInfo/index?course_id=${course_id}`, // 传递 course_id 参数
Expand All @@ -56,14 +56,14 @@
};

const handleClickToClass = () => {
void navigateToPage().then((r) => console.log(r));

Check warning on line 59 in src/common/components/Comment/index.tsx

View workflow job for this annotation

GitHub Actions / lint-and-format

Unexpected console statement
};

return (
<>
{!course_info ? (
<>
<View className="classTitle">pending</View>
<View className="italic text-gray-400">加载中 ...</View>
</>
) : (
<>
Expand All @@ -75,7 +75,7 @@
<View className="comment">
{!publisher_info ? (
<>
<View>pending</View>
<View className="italic text-gray-400">加载中 ...</View>
</>
) : (
<>
Expand Down Expand Up @@ -125,7 +125,7 @@
const father_record = getComment(id ?? 0);
const handleClick = useCallback(() => {
onClick && onClick(props);
}, [onClick]);

Check warning on line 128 in src/common/components/Comment/index.tsx

View workflow job for this annotation

GitHub Actions / lint-and-format

React Hook useCallback has a missing dependency: 'props'. Either include it or remove the dependency array

const handlEndorse = async () => {
setShouldSupport(!shouldSupport);
Expand Down
14 changes: 8 additions & 6 deletions src/common/utils/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ const header = {
const getToken = async () => {
const res = await Taro.getStorage({ key: 'shortToken' });
if (res.data) return res.data;
void Taro.navigateTo({ url: '/pages/login/index' });
void Taro.reLaunch({ url: '/pages/login/index' });
throw new Error(`没token: ${res.errMsg as unknown as string}`);
};

const refreshToken = async () => {
try {
const longToken = await Taro.getStorage({ key: 'longToken' });
if (!longToken.data) {
void Taro.navigateTo({ url: '/pages/login/index' });
void Taro.reLaunch({ url: '/pages/login/index' });
throw new Error('没longToken');
}

Expand All @@ -42,11 +42,13 @@ const refreshToken = async () => {
}
throw new Error('刷新token失败');
} catch (error) {
void Taro.showToast({
title: '登录过期 请刷新小程序重新登录',
icon: 'error',
if (Taro.getStorageSync('visitor') === true) return;
void Taro.reLaunch({ url: '/pages/login/index' }).then(() => {
void Taro.showToast({
title: '登录过期 请刷新小程序重新登录',
icon: 'none',
});
});
void Taro.navigateTo({ url: '/pages/login/index' });
throw error;
}
};
Expand Down
21 changes: 18 additions & 3 deletions src/modules/notification/components/Notification.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,14 @@ const Notification: React.FC = memo(() => {
const [supportMessage, setSupportMessage] = useState<MessageType[]>([]);
const [loading, setLoading] = useState<boolean>(false);
const currentMessage = useMemo(() => {
return tab === '提问' ? commentMessage : tab === '点赞' ? supportMessage : [];
const msg = tab === '提问' ? commentMessage : tab === '点赞' ? supportMessage : [];
if (!msg || !msg.length) {
void Taro.showToast({
title: '暂时没有消息',
icon: 'none',
});
}
return msg;
}, [tab, commentMessage, supportMessage]);
const [ctime, setCtime] = useState<number>(0);
const [end, setEnd] = useState(false);
Expand All @@ -43,8 +50,9 @@ const Notification: React.FC = memo(() => {
if (itemType === 'Comment') {
detailRes = await get(`/comments/${item.Ext.commentId}/detail`);
parentRes = await get(
`/comments/${detailRes.data.parent_comment_id}/detail`
`/comments/${detailRes.data?.parent_comment_id ?? 0}/detail`
);
console.log('tag');
user = await getUserInfo(item.Ext.commentator);
} else if (itemType === 'Support') {
detailRes =
Expand Down Expand Up @@ -164,7 +172,14 @@ const Notification: React.FC = memo(() => {
</View>
) : (
<View className="flex h-screen w-full flex-col items-center gap-4 overflow-y-scroll pb-[13vh]">
<TabBar tab={tab} setTab={setTab} />
<TabBar
tab={tab}
//eslint-disable-next-line @typescript-eslint/no-shadow
setTab={(tab) => {
setTab(tab);
setCtime(0);
}}
/>
<VirtualList
height="70%"
width="100%"
Expand Down
107 changes: 61 additions & 46 deletions src/pages/classInfo/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
/* eslint-disable import/first */
import { Image, Text, View } from '@tarojs/components';
import Taro from '@tarojs/taro';

import Taro, { useDidShow } from '@tarojs/taro';
import { useCallback, useEffect, useMemo, useState } from 'react';
import { AtIcon } from 'taro-ui';

Expand Down Expand Up @@ -96,7 +97,7 @@ export default function Index() {
getParams();
}, []);
//获取问题个数
useEffect(() => {
const initData = () => {
// eslint-disable-next-line @typescript-eslint/require-await
const getCourseData = async () => {
try {
Expand Down Expand Up @@ -127,52 +128,66 @@ export default function Index() {
};

if (courseId) void getCommentData();
};
const fetchAnswer = () => {
try {
void get(
`/questions/list?biz=Course&biz_id=${courseId}&cur_question_id=${0}&limit=${3}`
).then((res) => {
console.log(res);

console.log('questionlist1', res.data);
// eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-return
const questionsWithAnswers = res.data.map((item) => ({
...item,
preview_answers: item.preview_answers || [],
}));
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
setQuestionlist(res.data);
Taro.hideLoading();
});
} catch (e) {
console.error('Failed to fetch course data:', e);
}
};
const fetchGrades = async () => {
try {
await get(`/grades/courses/${courseId}`).then((res) => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
setGrade(res.data); // 设置 grade 数据
!res.data && bailout();
Taro.hideLoading();
});
} catch (err) {
console.error('Failed to fetch grades data', err);
}
};
const getNumData = () => {
try {
void get(`/questions/count?biz=Course&biz_id=${courseId}`).then((res) => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
setQuestionNum(res.data);
Taro.hideLoading();
});
} catch (e) {
console.error(e);
}
};
useEffect(() => {
initData();
}, [courseId]);
useDidShow(() => {
initData();
if (courseId) {
void Taro.showLoading({
title: '加载中',
});
void fetchGrades();
void getNumData();
void fetchAnswer();
}
});
useEffect(() => {
const fetchGrades = async () => {
try {
await get(`/grades/courses/${courseId}`).then((res) => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
setGrade(res.data); // 设置 grade 数据
!res.data && bailout();
Taro.hideLoading();
});
} catch (err) {
console.error('Failed to fetch grades data', err);
}
};
const getNumData = () => {
try {
void get(`/questions/count?biz=Course&biz_id=${courseId}`).then((res) => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
setQuestionNum(res.data);
Taro.hideLoading();
});
} catch (e) {
console.error(e);
}
};
const fetchAnswer = () => {
try {
void get(
`/questions/list?biz=Course&biz_id=${courseId}&cur_question_id=${0}&limit=${3}`
).then((res) => {
console.log(res);

console.log('questionlist1', res.data);
// eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-return
const questionsWithAnswers = res.data.map((item) => ({
...item,
preview_answers: item.preview_answers || [],
}));
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
setQuestionlist(res.data);
Taro.hideLoading();
});
} catch (e) {
console.error('Failed to fetch course data:', e);
}
};
if (courseId) {
void Taro.showLoading({
title: '加载中',
Expand Down
25 changes: 23 additions & 2 deletions src/pages/evaluate/evaluate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ export default function evaluate() {
});
return;
}
void Taro.showLoading({
title: '提交中',
});
const evaluationobj = {
star_rating: selectedStarIndex,
content: comment,
Expand All @@ -145,16 +148,34 @@ export default function evaluate() {
is_anonymous: isAnonymous,
};
console.log(evaluationobj);
if (!comment) {
void Taro.showToast({
title: '内容不能为空',
icon: 'none',
});
return;
}
post(`/evaluations/save`, evaluationobj)
.then((res) => {
if (res.code === 0) {
void Taro.switchTab({
url: '/pages/main/index', // 页面路径
void Taro.navigateBack().then(() => {
void Taro.showToast({
title: '课评发布成功',
icon: 'none',
});
});
} else {
void Taro.showToast({
title: res.msg,
icon: 'none',
});
}
})
.catch((error) => {
console.error('发布课评请求失败:', error);
})
.finally(() => {
void Taro.hideLoading();
});
};
const [selectedStarIndex, setSelectedStarIndex] = useState(-1);
Expand Down
21 changes: 17 additions & 4 deletions src/pages/main/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/* eslint-disable react-hooks/exhaustive-deps */
/* eslint-disable import/first */
import { Image, ScrollView, Text, View } from '@tarojs/components';
import Taro from '@tarojs/taro';

import Taro, { useDidShow } from '@tarojs/taro';
import { useCallback, useEffect, useMemo, useState } from 'react';

import './index.scss';
Expand All @@ -16,9 +17,9 @@ import { useCourseStore } from './store/store';
import { COURSE_TYPE } from './store/types';

const COURSE_NAME_MAP = {
[COURSE_TYPE.ANY]: '全部',
[COURSE_TYPE.MAJOR]: '专业',
[COURSE_TYPE.GENERAL_ELECT]: '通选',
[COURSE_TYPE.GENERAL_REQUIRED]: '通必',
[COURSE_TYPE.GENERAL_ELECT]: '个性',
[COURSE_TYPE.GENERAL_CORE]: '通核',
};

Expand Down Expand Up @@ -67,6 +68,19 @@ export default function Index() {
}
}, [classType]);

useDidShow(() => {
void Taro.showLoading({ title: '加载中' });
void dispatch
.refershComments()
.then(() => {
Taro.hideLoading();
})
.catch(() => {
Taro.hideLoading();
void Taro.showToast({ title: '加载失败', icon: 'none' });
});
});

const handleSearch = (searchText: string) => {
console.log('搜索文本:', searchText);
};
Expand All @@ -77,7 +91,6 @@ export default function Index() {
const res = (await postBool('/checkStatus', {
name: 'kestack',
})) as StatusResponse;

setTest(res.data.status);
} catch (error) {
console.error('Error fetching status:', error);
Expand Down
4 changes: 2 additions & 2 deletions src/pages/main/store/commentInfoSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ export const CreateCommentInfo: StateCreator<
comments: {
CoursePropertyGeneralCore: [],
CoursePropertyGeneralElective: [],
CoursePropertyGeneralRequired: [],
CoursePropertyAny: [],
CoursePropertyMajorCore: [],
},
currentId: 0,
pageSize: 10,
loading: true,
classType: COURSE_TYPE.GENERAL_CORE,
classType: COURSE_TYPE.ANY,
async refershComments() {
return await get().updateComments(0);
},
Expand Down
Loading
Loading