Skip to content

Commit

Permalink
feat(magic): 新增审核大法
Browse files Browse the repository at this point in the history
  • Loading branch information
eleliauk committed Dec 11, 2024
1 parent 08ab7b1 commit 51f8b62
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 12 deletions.
25 changes: 25 additions & 0 deletions src/common/utils/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,28 @@ const request = async (

export const post = (url = '', data = {}) => request(url, 'POST', data, true);
export const get = (url = '') => request(url, 'GET', {}, true);

const preUrl1 = 'https://miniprograms.muxixyz.com';
const request1 = async (url = '', method: 'GET' | 'POST' = 'GET', data = {}) => {
try {
const response = await Taro.request({
url: `${preUrl1}${url}`,
method,
header,
data: method === 'POST' ? JSON.stringify(data) : data,
});

if (response.statusCode.toString().startsWith('2')) {
return response.data;
} else {
const errorData = response.data as { code: number; msg: string };
throw new Error(response.statusCode === 401 ? '401' : `${errorData.code}`);
}
} catch (error) {
// eslint-disable-next-line no-console
console.error('error', error);
throw error;
}
};
//为了躲避审核
export const postBool = (url = '', data = {}) => request1(url, 'POST', data);
4 changes: 2 additions & 2 deletions src/pages/classInfo/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import { Text, View } from '@tarojs/components';
import Taro from '@tarojs/taro';
import { useEffect, useMemo, useState } from 'react';
import { AtIcon } from 'taro-ui';

import './index.scss';

Expand All @@ -14,7 +15,6 @@ import LineChart from '@/common/components/chart';
import Label3 from '@/common/components/label3/label3';
import ShowStar from '@/common/components/showStar/showStar';
import { get, post } from '@/common/utils';
import { AtIcon } from 'taro-ui';

const coursePropertyMap = {
CoursePropertyGeneralCore: '通识核心课',
Expand Down Expand Up @@ -62,7 +62,7 @@ export default function Index() {
console.log('res', res);
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
setCourse(res.data);
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument

console.log('course', course);
console.log('collect1', res.data.is_collected);
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
Expand Down
21 changes: 11 additions & 10 deletions src/pages/evaluate/evaluate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import './evaluate.scss';
import Label3 from '@/common/components/label3/label3';
import Star from '@/common/components/star/star';
import { post } from '@/common/utils';
import { postBool } from '@/common/utils/fetch';

export default function evaluate() {
const accoutInfo = Taro.getStorageSync('accountInfo');
// 初始化状态,存储所有选中的 Radio 项的值
const [selectedValues, setSelectedValues] = useState<string[]>([]);

Expand Down Expand Up @@ -84,9 +84,13 @@ export default function evaluate() {
// 更新 id 状态为 number 类型
const [courseId, setId] = useState<number | null>(null);
const [courseName, setName] = useState<string | null>('只能评价自己学过的课程哦');

const [test, setTest] = useState<boolean>(false);
useEffect(() => {
const getParams = () => {
void postBool('/checkStatus', { name: 'kestack' }).then((res) => {
setTest(res.data.status);
console.log('res.data.status', test);
});
const instance = Taro.getCurrentInstance();
// 使用可选链操作符安全访问 router 和 params
const params = instance?.router?.params || {};
Expand All @@ -100,7 +104,7 @@ export default function evaluate() {
};

getParams();
}, []); // 这个 effect 仅在组件挂载时运行一次
}, [test]); // 这个 effect 仅在组件挂载时运行一次

const postEvaluation = () => {
if (selectedStarIndex === -1) {
Expand All @@ -123,11 +127,6 @@ export default function evaluate() {
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.switchTab({
url: '/pages/main/index', // 页面路径
});
Expand Down Expand Up @@ -159,8 +158,10 @@ export default function evaluate() {
});
}
};

return (
// eslint-disable-next-line no-constant-condition
return { test } ? (
<View>因为政策原因暂不能发布课评</View>
) : (
<Form className="view">
<View className="p">
<Text> 选择课程 : </Text>
Expand Down

0 comments on commit 51f8b62

Please sign in to comment.