Skip to content

Commit

Permalink
🐞 fix: 修复eslint问题
Browse files Browse the repository at this point in the history
  • Loading branch information
MaggieMii committed Aug 25, 2024
1 parent 5df02b9 commit 733b003
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 21 deletions.
18 changes: 11 additions & 7 deletions src/common/components/star/star.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,24 @@ import { useState } from 'react';

import './star.scss';

export default function Star(props) {
interface Props {
onStarClick: (index: number) => void;
// ...其他属性...
}

const Star: React.FC<Props> = ({ onStarClick }) => {
const star0 = 'https://s2.loli.net/2023/08/29/NRLD54kzG9nEOHW.png';
const star1 = 'https://s2.loli.net/2023/08/29/rENVFz7xU9n2bd6.png';

const [stars, setStars] = useState([star0, star0, star0, star0, star0]);

const starClick = (index) => {
const starClick = (index: number) => {
const newStars = [star0, star0, star0, star0, star0];
for (let i = 0; i <= index; i++) {
newStars[i] = star1;
}
setStars(newStars);
// 使用 props.onStarClick 调用父组件的函数,并传递 index 参数
if (props.onStarClick) {
props.onStarClick(index);
}
onStarClick(index); // 安全调用
};

return (
Expand All @@ -38,4 +40,6 @@ export default function Star(props) {
})}
</View>
);
}
};

export default Star;
35 changes: 23 additions & 12 deletions src/pages/evaluate/evaluate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
/* eslint-disable react-hooks/rules-of-hooks */
/* eslint-disable import/first */
import { Button, Form, Radio, Text, Textarea, View } from '@tarojs/components';
import Taro from '@tarojs/taro';
import { useEffect, useState } from 'react';

import './evaluate.scss';

import Label3 from '@/common/components/label3/label3';
import Star from '@/common/components/star/star';
import { post } from '@/common/utils/fetch';
import Taro from '@tarojs/taro';

export default function evaluate() {
// function generateUniqueID() {
Expand Down Expand Up @@ -137,17 +138,27 @@ export default function evaluate() {
status: 'Public',
};
console.log(evaluationobj);
post(`/evaluations/save`, evaluationobj).then((res) => {
if (res.code == 0) {
console.log('发布课评成功');
// 使用 redirectTo 跳转
Taro.redirectTo({
url: '/pages/main/index', // 页面路径
});
}

// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
});
post(`/evaluations/save`, evaluationobj)
.then((res) => {
if (res.code === 0) {
// 打印成功信息,但最好使用其他日志记录方式,而不是 console.log
// 例如:this.setState({ message: '发布课评成功' });
// 或者使用 Taro 的日志记录方式:Taro.showToast({ title: '发布课评成功', icon: 'success' });
// console.log('发布课评成功');
// 使用 redirectTo 跳转
void Taro.redirectTo({
url: '/pages/main/index', // 页面路径
});
} else {
// 处理其他响应代码,可能需要给用户一些反馈
// 例如:Taro.showToast({ title: '发布课评失败', icon: 'none' });
}
})
.catch((error) => {
// 处理可能出现的错误情况
// 例如:Taro.showToast({ title: '发布失败,请稍后重试', icon: 'none' });
console.error('发布课评请求失败:', error);
});
};

//星级部分的代码
Expand Down
4 changes: 2 additions & 2 deletions src/pages/myclass/myclass.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ export default function Myclass() {
void fetchClasses();
}, [year, sem]);

const handleClassClick = (id, name) => {
const handleClassClick = (id: number, name: string) => {
// 拼接查询字符串参数
const query = `?id=${encodeURIComponent(id)}&name=${encodeURIComponent(name)}`;
// 使用 navigateTo 跳转到 evaluate 页面,并传递参数
Taro.navigateTo({
void Taro.navigateTo({
url: `/pages/evaluate/evaluate${query}`,
});
};
Expand Down

0 comments on commit 733b003

Please sign in to comment.