From 1d48783518b8eccdfb4f311e7ec675916b9211cd Mon Sep 17 00:00:00 2001 From: MaggieMii <1350383261@qq.com> Date: Sat, 31 Aug 2024 22:54:34 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E2=9C=A8=20feat:=20=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E6=8F=90=E9=97=AE=E9=A1=B5=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app.config.ts | 26 +-- src/common/assets/img/publishQuestion/ask.png | Bin 0 -> 447 bytes src/common/assets/types.ts | 15 ++ src/common/components/comment/comment.scss | 1 + src/pages/classInfo/index.tsx | 17 +- src/pages/main/index.scss | 6 +- src/pages/publishQuestion/index.config.ts | 4 + src/pages/publishQuestion/index.scss | 77 +++++++++ src/pages/publishQuestion/index.tsx | 159 ++++++++++++++++++ src/pages/questionInfo/index.config.ts | 4 + src/pages/questionInfo/index.scss | 0 src/pages/questionInfo/index.tsx | 9 + 12 files changed, 288 insertions(+), 30 deletions(-) create mode 100644 src/common/assets/img/publishQuestion/ask.png create mode 100644 src/pages/publishQuestion/index.config.ts create mode 100644 src/pages/publishQuestion/index.scss create mode 100644 src/pages/publishQuestion/index.tsx create mode 100644 src/pages/questionInfo/index.config.ts create mode 100644 src/pages/questionInfo/index.scss create mode 100644 src/pages/questionInfo/index.tsx diff --git a/src/app.config.ts b/src/app.config.ts index d60cef4..c5da642 100644 --- a/src/app.config.ts +++ b/src/app.config.ts @@ -41,6 +41,8 @@ import { useGlobalIconFont } from './common/components/iconfont/helper'; export default defineAppConfig({ pages: [ + // 'pages/questionInfo/index', + 'pages/publishQuestion/index', 'pages/login/index', 'pages/main/index', 'pages/classInfo/index', @@ -58,18 +60,18 @@ export default defineAppConfig({ ], /* eslint-disable */ usingComponents: Object.assign(useGlobalIconFont()), - tabBar: { - /* tab页面必须放在主包里 */ - custom: true, - list: [ - { - pagePath: 'pages/main/index', - text: 'Home', - }, - { pagePath: 'pages/notification/index', text: 'Massage' }, - { pagePath: 'pages/personalPage/index', text: 'Profile' }, - ], - }, + // tabBar: { + // /* tab页面必须放在主包里 */ + // custom: true, + // list: [ + // { + // pagePath: 'pages/main/index', + // text: 'Home', + // }, + // { pagePath: 'pages/notification/index', text: 'Massage' }, + // { pagePath: 'pages/personalPage/index', text: 'Profile' }, + // ], + // }, window: { backgroundTextStyle: 'light', navigationBarBackgroundColor: '#fff', diff --git a/src/common/assets/img/publishQuestion/ask.png b/src/common/assets/img/publishQuestion/ask.png new file mode 100644 index 0000000000000000000000000000000000000000..9a0d457fd66b624b987c281d8942d3fb357bad37 GIT binary patch literal 447 zcmV;w0YLtVP)P000^Y1^@s6LVfqm00001b5ch_0Itp) z=>Px$c}YY;R7gwhmd#PZKp2LfFY$*13MF6%(1BLqSb>~mJULVVRG^+DC!hk;fw2SZ z06R$3gToBF&PL-1W|=4(Pwp{+?|Hw!cO!a4{b^25LtCJZqoZN!E4q8zyP*_9+fuL3kA0wFL3E;ke~$c31o0w?<&!emH@a12a5#n=W^ z9!-lNJ0z=Tr9zy{nTh7s^YS6pZ601;X)2Gq91*#YRI&MkhR|1BFNBc@4Of)F z31m>~(9i2tnUD!EvjBSL`No-;0A```AX&D~AaOv1ejoQOk8bshsdLEJ9%b46Lrlq+ zM)*$}k7kTmN4W1~go~J?FSPW6y7P_K@MxA)U{>qUe!k(*ImEcK37%z|1gUwR7BWb! ziA2&3PwQ; // 使用 Record 类型来表示对象,具体类型根据实际结构定义 + features: Record; + is_collected: boolean; + is_subscribed: boolean; +} diff --git a/src/common/components/comment/comment.scss b/src/common/components/comment/comment.scss index a512c31..d9686ae 100644 --- a/src/common/components/comment/comment.scss +++ b/src/common/components/comment/comment.scss @@ -46,6 +46,7 @@ $content-line-height: 30; } .bigcomment { + margin: 60rpx 0; .commentplus { position: relative; margin-left: 45rpx; diff --git a/src/pages/classInfo/index.tsx b/src/pages/classInfo/index.tsx index d00a9ef..9b6518e 100644 --- a/src/pages/classInfo/index.tsx +++ b/src/pages/classInfo/index.tsx @@ -16,25 +16,12 @@ import Label3 from '@/common/components/label3/label3'; import ShowStar from '@/common/components/showStar/showStar'; import { get } from '@/common/utils/fetch'; -import { CommentInfoType } from '../../common/assets/types'; +import { CommentInfoType,Course } from '../../common/assets/types'; // import { useRef } from 'react'; // import Echarts, { EChartOption, EchartsHandle } from 'taro-react-echarts'; // 定义接口 -interface Course { - id: number; - name: string; - teacher: string; - school: string; - type: string; - credit: number; - composite_score: number; - rater_count: number; - assessments: Record; // 使用 Record 类型来表示对象,具体类型根据实际结构定义 - features: Record; - is_collected: boolean; - is_subscribed: boolean; -} + // 创建一个对象来存储英文描述和对应的中文描述 const coursePropertyMap = { diff --git a/src/pages/main/index.scss b/src/pages/main/index.scss index b4c8f99..affa71c 100644 --- a/src/pages/main/index.scss +++ b/src/pages/main/index.scss @@ -28,6 +28,6 @@ margin-bottom: 70rpx; } -.main .bigcomment { - margin: 60rpx 0; -} +// .main .bigcomment { +// margin: 60rpx 0; +// } diff --git a/src/pages/publishQuestion/index.config.ts b/src/pages/publishQuestion/index.config.ts new file mode 100644 index 0000000..2acd01b --- /dev/null +++ b/src/pages/publishQuestion/index.config.ts @@ -0,0 +1,4 @@ +export default definePageConfig({ + navigationBarTitleText: '问问同学', + navigationBarBackgroundColor: '#F9F9F2' +}); diff --git a/src/pages/publishQuestion/index.scss b/src/pages/publishQuestion/index.scss new file mode 100644 index 0000000..e3a7684 --- /dev/null +++ b/src/pages/publishQuestion/index.scss @@ -0,0 +1,77 @@ +.theClassnme { + font-size: 43rpx; + font-weight: bold; + color: #565552; + text-align: center; + margin-top: 22rpx; +} + +.teacherName { + font-size: 33rpx; + font-weight: 400; + color: #9f9f9c; + text-align: center; + margin-top: 15rpx; + margin-bottom: 27rpx; +} + +.publishView{ + background-color: #F9F9F2; + padding: 45rpx; + width: 659.42rpx; + position: relative; + left: 50%; + transform:translateX(-50%); +} + +.avatar { + width: 90.58rpx; + height: 90.58rpx; + border-radius: 100%; + margin-right: 10px; + border: #d2d5d8 solid 5rpx; + margin-right: 27rpx; +} + +.nickname { + font-weight: bold; + font-size: 22rpx; + color: #565552; +} + +.currentDate{ + font-weight: 400; + font-size: 14rpx; + color: #9F9F9C; + margin-top: 20rpx; +} + +.publish-header{ + display: flex; + align-items: center; +} + +.askicon{ + width: 44.44rpx; + height: 47.05rpx; + margin: 28rpx 0; +} + +.quesionContent{ + width: 568.84rpx; + height: 719.2rpx; + background-color: white; + padding: 40rpx; + font-size: 25rpx; + box-sizing: border-box; +} + +.publishBtn{ + margin-top: 60rpx; + width: 230.07rpx; + height: 70.65rpx; + border-radius: 50rpx; + background-color: #FFD777; + color: white; + line-height: 70.65rpx; +} \ No newline at end of file diff --git a/src/pages/publishQuestion/index.tsx b/src/pages/publishQuestion/index.tsx new file mode 100644 index 0000000..0df2ddd --- /dev/null +++ b/src/pages/publishQuestion/index.tsx @@ -0,0 +1,159 @@ +import { View,Image,Text,Textarea,Button } from '@tarojs/components'; +import { useEffect,useState } from 'react'; +import { get,post } from '@/common/utils/fetch'; +import { Course } from '../../common/assets/types'; +import askicon from '@/common/assets/img/publishQuestion/ask.png' +import Taro from '@tarojs/taro'; + +import './index.scss' + +export interface UserInfo { + avatarUrl: string; // 用户头像的URL + nickName: string; // 用户昵称 +} + +export interface ResponseUser { + code?: number; + data: WebUserProfileVo; + msg?: string; +} + +export interface WebUserProfileVo { + avatar: string; + ctime: number; + grade_sharing_is_signed?: boolean; + id: number; + /** + * 是否为新用户,新用户尚未编辑过个人信息 + */ + new: boolean; + nickname: string; + studentId: string; + title_ownership: { [key: string]: boolean }; + using_title: string; + utime?: number; +} + +const getCurrentDate = () => { + // 创建一个新的Date对象,它将被初始化为当前日期和时间 + const now = new Date(); + + // 获取年、月、日 + const year = now.getFullYear(); + const month = now.getMonth() + 1; // getMonth() 返回的月份是从0开始的 + const day = now.getDate(); + + // 格式化为 YYYY-MM-DD + const formattedDate = `${year}年${month.toString().padStart(2, '0')}月${day.toString().padStart(2, '0')}日`; + + return formattedDate; +}; + +export default function Index() { + const [course, setCourse] = useState(null); + + const courseId = 2347; //先用概率统计A来调试吧! + + //用户个人身份信息 + const [avatarUrl, setAvatarUrl] = useState(''); + const [nickName, setNickName] = useState('昵称'); + + + useEffect(() => { + // eslint-disable-next-line @typescript-eslint/require-await + const getCourseData = async () => { + try { + void get(`/courses/${courseId}/detail`, true).then((res) => { + console.log(res); + // eslint-disable-next-line @typescript-eslint/no-unsafe-argument + setCourse(res.data); + }); + } catch (error) { + // 错误处理,例如弹出提示 + console.error('Failed to fetch course data:', error); + } + }; + + if (courseId) void getCourseData().then((r) => console.log(r)); + + }, [courseId]); // 在courseId变化时运行 + + useEffect(()=>{ + const fetchProfile = async () =>{ + try{ + const url = '/users/profile'; + const response: ResponseUser = await get(url); + setNickName(response.data.nickname); + setAvatarUrl(response.data.avatar); + }catch (error) { + console.error('Error fetching collection data:', error); + } + } + void fetchProfile(); + },[])//仅在挂载时运行一次 + + const [question,setQuestion] = useState('') + + const countContent = (e) => { + const { value } = e.detail; + setQuestion(value); // 更新状态为当前输入框的值 + // const length = value.length; + // setLength(length); + }; + + const postQuestion = () => { + + const questionobj = { + biz:'Course', + biz_id:courseId, + content:question + } + post(`/questions/publish`, questionobj) + .then((res) => { + if (res.code === 0) { + // 打印成功信息,但最好使用其他日志记录方式,而不是 console.log + // 例如:this.setState({ message: '发布课评成功' }); + 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); + }); + }; + return ( + + {course?.name} + + {course?.school} {course?.teacher} + + + + + + {nickName} + {getCurrentDate()} + + + + + + + + ); +} diff --git a/src/pages/questionInfo/index.config.ts b/src/pages/questionInfo/index.config.ts new file mode 100644 index 0000000..2acd01b --- /dev/null +++ b/src/pages/questionInfo/index.config.ts @@ -0,0 +1,4 @@ +export default definePageConfig({ + navigationBarTitleText: '问问同学', + navigationBarBackgroundColor: '#F9F9F2' +}); diff --git a/src/pages/questionInfo/index.scss b/src/pages/questionInfo/index.scss new file mode 100644 index 0000000..e69de29 diff --git a/src/pages/questionInfo/index.tsx b/src/pages/questionInfo/index.tsx new file mode 100644 index 0000000..f1c99e8 --- /dev/null +++ b/src/pages/questionInfo/index.tsx @@ -0,0 +1,9 @@ +import { Navigator, View } from '@tarojs/components'; + +export default function Index() { + return ( + + 我要跳转到搜索页面 + + ); +} From a932e7a0b8040c636bf24475f04f20799b65c10c Mon Sep 17 00:00:00 2001 From: MaggieMii <1350383261@qq.com> Date: Sat, 31 Aug 2024 23:01:01 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=F0=9F=8C=88=20style:=20fix=20prettier?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/common/assets/types.ts | 2 +- src/pages/classInfo/index.tsx | 3 +- src/pages/publishQuestion/index.config.ts | 2 +- src/pages/publishQuestion/index.scss | 114 +++++++++++----------- src/pages/publishQuestion/index.tsx | 57 ++++++----- src/pages/questionInfo/index.config.ts | 2 +- 6 files changed, 89 insertions(+), 91 deletions(-) diff --git a/src/common/assets/types.ts b/src/common/assets/types.ts index da8aeba..a996b44 100644 --- a/src/common/assets/types.ts +++ b/src/common/assets/types.ts @@ -76,4 +76,4 @@ export interface Course { features: Record; is_collected: boolean; is_subscribed: boolean; -} +} diff --git a/src/pages/classInfo/index.tsx b/src/pages/classInfo/index.tsx index 9b6518e..ef9a13b 100644 --- a/src/pages/classInfo/index.tsx +++ b/src/pages/classInfo/index.tsx @@ -16,13 +16,12 @@ import Label3 from '@/common/components/label3/label3'; import ShowStar from '@/common/components/showStar/showStar'; import { get } from '@/common/utils/fetch'; -import { CommentInfoType,Course } from '../../common/assets/types'; +import { CommentInfoType, Course } from '../../common/assets/types'; // import { useRef } from 'react'; // import Echarts, { EChartOption, EchartsHandle } from 'taro-react-echarts'; // 定义接口 - // 创建一个对象来存储英文描述和对应的中文描述 const coursePropertyMap = { CoursePropertyGeneralCore: '通识核心课', diff --git a/src/pages/publishQuestion/index.config.ts b/src/pages/publishQuestion/index.config.ts index 2acd01b..fd01a30 100644 --- a/src/pages/publishQuestion/index.config.ts +++ b/src/pages/publishQuestion/index.config.ts @@ -1,4 +1,4 @@ export default definePageConfig({ navigationBarTitleText: '问问同学', - navigationBarBackgroundColor: '#F9F9F2' + navigationBarBackgroundColor: '#F9F9F2', }); diff --git a/src/pages/publishQuestion/index.scss b/src/pages/publishQuestion/index.scss index e3a7684..4803a1b 100644 --- a/src/pages/publishQuestion/index.scss +++ b/src/pages/publishQuestion/index.scss @@ -1,77 +1,77 @@ .theClassnme { - font-size: 43rpx; - font-weight: bold; - color: #565552; - text-align: center; - margin-top: 22rpx; + font-size: 43rpx; + font-weight: bold; + color: #565552; + text-align: center; + margin-top: 22rpx; } - + .teacherName { - font-size: 33rpx; - font-weight: 400; - color: #9f9f9c; - text-align: center; - margin-top: 15rpx; - margin-bottom: 27rpx; + font-size: 33rpx; + font-weight: 400; + color: #9f9f9c; + text-align: center; + margin-top: 15rpx; + margin-bottom: 27rpx; } -.publishView{ - background-color: #F9F9F2; - padding: 45rpx; - width: 659.42rpx; - position: relative; - left: 50%; - transform:translateX(-50%); +.publishView { + background-color: #f9f9f2; + padding: 45rpx; + width: 659.42rpx; + position: relative; + left: 50%; + transform: translateX(-50%); } .avatar { - width: 90.58rpx; - height: 90.58rpx; - border-radius: 100%; - margin-right: 10px; - border: #d2d5d8 solid 5rpx; - margin-right: 27rpx; + width: 90.58rpx; + height: 90.58rpx; + border-radius: 100%; + margin-right: 10px; + border: #d2d5d8 solid 5rpx; + margin-right: 27rpx; } - + .nickname { - font-weight: bold; - font-size: 22rpx; - color: #565552; + font-weight: bold; + font-size: 22rpx; + color: #565552; } -.currentDate{ - font-weight: 400; - font-size: 14rpx; - color: #9F9F9C; - margin-top: 20rpx; +.currentDate { + font-weight: 400; + font-size: 14rpx; + color: #9f9f9c; + margin-top: 20rpx; } -.publish-header{ - display: flex; - align-items: center; +.publish-header { + display: flex; + align-items: center; } -.askicon{ - width: 44.44rpx; - height: 47.05rpx; - margin: 28rpx 0; +.askicon { + width: 44.44rpx; + height: 47.05rpx; + margin: 28rpx 0; } -.quesionContent{ - width: 568.84rpx; - height: 719.2rpx; - background-color: white; - padding: 40rpx; - font-size: 25rpx; - box-sizing: border-box; +.quesionContent { + width: 568.84rpx; + height: 719.2rpx; + background-color: white; + padding: 40rpx; + font-size: 25rpx; + box-sizing: border-box; } -.publishBtn{ - margin-top: 60rpx; - width: 230.07rpx; - height: 70.65rpx; - border-radius: 50rpx; - background-color: #FFD777; - color: white; - line-height: 70.65rpx; -} \ No newline at end of file +.publishBtn { + margin-top: 60rpx; + width: 230.07rpx; + height: 70.65rpx; + border-radius: 50rpx; + background-color: #ffd777; + color: white; + line-height: 70.65rpx; +} diff --git a/src/pages/publishQuestion/index.tsx b/src/pages/publishQuestion/index.tsx index 0df2ddd..e6fc52a 100644 --- a/src/pages/publishQuestion/index.tsx +++ b/src/pages/publishQuestion/index.tsx @@ -1,11 +1,11 @@ -import { View,Image,Text,Textarea,Button } from '@tarojs/components'; -import { useEffect,useState } from 'react'; -import { get,post } from '@/common/utils/fetch'; -import { Course } from '../../common/assets/types'; -import askicon from '@/common/assets/img/publishQuestion/ask.png' +import askicon from '@/common/assets/img/publishQuestion/ask.png'; +import { get, post } from '@/common/utils/fetch'; +import { Button, Image, Text, Textarea, View } from '@tarojs/components'; import Taro from '@tarojs/taro'; +import { useEffect, useState } from 'react'; +import { Course } from '../../common/assets/types'; -import './index.scss' +import './index.scss'; export interface UserInfo { avatarUrl: string; // 用户头像的URL @@ -58,7 +58,6 @@ export default function Index() { const [avatarUrl, setAvatarUrl] = useState(''); const [nickName, setNickName] = useState('昵称'); - useEffect(() => { // eslint-disable-next-line @typescript-eslint/require-await const getCourseData = async () => { @@ -75,24 +74,23 @@ export default function Index() { }; if (courseId) void getCourseData().then((r) => console.log(r)); - }, [courseId]); // 在courseId变化时运行 - useEffect(()=>{ - const fetchProfile = async () =>{ - try{ + useEffect(() => { + const fetchProfile = async () => { + try { const url = '/users/profile'; const response: ResponseUser = await get(url); setNickName(response.data.nickname); setAvatarUrl(response.data.avatar); - }catch (error) { + } catch (error) { console.error('Error fetching collection data:', error); } - } + }; void fetchProfile(); - },[])//仅在挂载时运行一次 + }, []); //仅在挂载时运行一次 - const [question,setQuestion] = useState('') + const [question, setQuestion] = useState(''); const countContent = (e) => { const { value } = e.detail; @@ -102,12 +100,11 @@ export default function Index() { }; const postQuestion = () => { - const questionobj = { - biz:'Course', - biz_id:courseId, - content:question - } + biz: 'Course', + biz_id: courseId, + content: question, + }; post(`/questions/publish`, questionobj) .then((res) => { if (res.code === 0) { @@ -136,24 +133,26 @@ export default function Index() { {course?.school} {course?.teacher} - + - - - {nickName} - {getCurrentDate()} - + + + {nickName} + {getCurrentDate()} + - + + > - + ); } diff --git a/src/pages/questionInfo/index.config.ts b/src/pages/questionInfo/index.config.ts index 2acd01b..fd01a30 100644 --- a/src/pages/questionInfo/index.config.ts +++ b/src/pages/questionInfo/index.config.ts @@ -1,4 +1,4 @@ export default definePageConfig({ navigationBarTitleText: '问问同学', - navigationBarBackgroundColor: '#F9F9F2' + navigationBarBackgroundColor: '#F9F9F2', }); From f59222bb67543f7f7cc0e8c77f32feea29f08d08 Mon Sep 17 00:00:00 2001 From: MaggieMii <1350383261@qq.com> Date: Sun, 1 Sep 2024 00:24:42 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=F0=9F=8C=88=20style:=20=E4=BF=AE=E5=A4=8De?= =?UTF-8?q?slint?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/publishQuestion/index.tsx | 52 ++++++++++++++++++++--------- 1 file changed, 36 insertions(+), 16 deletions(-) diff --git a/src/pages/publishQuestion/index.tsx b/src/pages/publishQuestion/index.tsx index e6fc52a..3da1378 100644 --- a/src/pages/publishQuestion/index.tsx +++ b/src/pages/publishQuestion/index.tsx @@ -1,9 +1,11 @@ -import askicon from '@/common/assets/img/publishQuestion/ask.png'; -import { get, post } from '@/common/utils/fetch'; import { Button, Image, Text, Textarea, View } from '@tarojs/components'; import Taro from '@tarojs/taro'; import { useEffect, useState } from 'react'; -import { Course } from '../../common/assets/types'; + +// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment +import askicon from '@/common/assets/img/publishQuestion/ask.png'; +import { Course } from '@/common/assets/types'; +import { get, post } from '@/common/utils/fetch'; import './index.scss'; @@ -55,8 +57,8 @@ export default function Index() { const courseId = 2347; //先用概率统计A来调试吧! //用户个人身份信息 - const [avatarUrl, setAvatarUrl] = useState(''); - const [nickName, setNickName] = useState('昵称'); + const [avatarUrl, setAvatarUrl] = useState(''); + const [nickName, setNickName] = useState('昵称'); useEffect(() => { // eslint-disable-next-line @typescript-eslint/require-await @@ -64,8 +66,9 @@ export default function Index() { try { void get(`/courses/${courseId}/detail`, true).then((res) => { console.log(res); - // eslint-disable-next-line @typescript-eslint/no-unsafe-argument - setCourse(res.data); + // 检查 res 是否有 data 属性,并且断言其类型 + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access + setCourse(res?.data as Course); }); } catch (error) { // 错误处理,例如弹出提示 @@ -80,9 +83,15 @@ export default function Index() { const fetchProfile = async () => { try { const url = '/users/profile'; + // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment const response: ResponseUser = await get(url); - setNickName(response.data.nickname); - setAvatarUrl(response.data.avatar); + if ( + typeof response?.data?.nickname == 'string' && + typeof response?.data?.avatar == 'string' + ) { + setNickName(response?.data?.nickname); + setAvatarUrl(response?.data?.avatar); + } } catch (error) { console.error('Error fetching collection data:', error); } @@ -93,8 +102,15 @@ export default function Index() { const [question, setQuestion] = useState(''); const countContent = (e) => { - const { value } = e.detail; - setQuestion(value); // 更新状态为当前输入框的值 + /* eslint-disable @typescript-eslint/no-unsafe-member-access */ + // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment + const { value } = e?.detail ?? {}; + if (typeof value === 'string') { + setQuestion(value); + } else { + console.error('Expected a string but received a different type'); + } + /* eslint-enable @typescript-eslint/no-unsafe-member-access */ // const length = value.length; // setLength(length); }; @@ -107,10 +123,11 @@ export default function Index() { }; post(`/questions/publish`, questionobj) .then((res) => { - if (res.code === 0) { + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access + if (res?.code === 0) { // 打印成功信息,但最好使用其他日志记录方式,而不是 console.log // 例如:this.setState({ message: '发布课评成功' }); - Taro.showToast({ title: '发布问题成功', icon: 'success' }); + void Taro.showToast({ title: '发布问题成功', icon: 'success' }); // console.log('发布课评成功'); // 使用 redirectTo 跳转 // void Taro.redirectTo({ @@ -118,12 +135,12 @@ export default function Index() { // }); } else { // 处理其他响应代码,可能需要给用户一些反馈 - Taro.showToast({ title: '发布课评失败', icon: 'none' }); + void Taro.showToast({ title: '发布课评失败', icon: 'none' }); } }) .catch((error) => { // 处理可能出现的错误情况 - Taro.showToast({ title: '发布失败,请稍后重试', icon: 'none' }); + void Taro.showToast({ title: '发布失败,请稍后重试', icon: 'none' }); console.error('发布问题请求失败:', error); }); }; @@ -141,7 +158,10 @@ export default function Index() { {getCurrentDate()} - + { + // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment + + }