Skip to content

Commit

Permalink
Merge branch 'main' into mhr-dev
Browse files Browse the repository at this point in the history
  • Loading branch information
MaggieMii authored Aug 31, 2024
2 parents f59222b + 7e55066 commit 3506129
Show file tree
Hide file tree
Showing 45 changed files with 680 additions and 863 deletions.
2 changes: 1 addition & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ babel.config.js
ec-canvas

*.js
src/pages/notification/index.tsx
VirtualList.tsx
75 changes: 20 additions & 55 deletions src/app.config.ts
Original file line number Diff line number Diff line change
@@ -1,43 +1,4 @@
// // import { useGlobalIconFont } from './common/components/iconfont/helper';

// export default defineAppConfig({
// pages: [
// ],
// window: {
// backgroundTextStyle: 'light',
// navigationBarBackgroundColor: '#fff',
// navigationBarTitleText: 'WeChat',
// navigationBarTextStyle: 'black',
// },
// subpackages: [
// //分包
// {
// root: 'subpackages/123',
// pages: [
// 'pages/114514/index',
// ],
// },
// {
// root: 'subpackages/456',
// pages: [
// 'pages/1919810/index',
// ],
// },
// ],
// tabBar: {
// /* tab页面必须放在主包里 */
// custom: true,
// list: [
// {
// pagePath: 'pages/123/index',
// text: '123',
// },
// { pagePath: 'pages/456/index', text: '456' },
// ],
// },
// lazyCodeLoading: 'requiredComponents',
// });
import { useGlobalIconFont } from './common/components/iconfont/helper';
// import { useGlobalIconFont } from './common/components/iconfont/helper';

export default defineAppConfig({
pages: [
Expand All @@ -47,9 +8,8 @@ export default defineAppConfig({
'pages/main/index',
'pages/classInfo/index',
'pages/evaluateInfo/index',
'pages/personalPage/index',
'pages/profile/index',
'pages/myCollection/index',
'pages/evaluateCourseHistory/index',
'pages/notification/index',
'pages/feedback/index',
'pages/evaluate/evaluate',
Expand All @@ -58,20 +18,25 @@ export default defineAppConfig({
'pages/index/index',
'pages/editUser/index',
],
subpackages: [
{
root: 'subpackages/profile',
pages: ['pages/history/index'],
},
],
/* 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' },
// ],
// },
// usingComponents: Object.assign(useGlobalIconFont()),
tabBar: {
custom: true,
list: [
{
pagePath: 'pages/main/index',
text: 'Home',
},
{ pagePath: 'pages/notification/index', text: 'Massage' },
{ pagePath: 'pages/profile/index', text: 'Profile' },
],
},
window: {
backgroundTextStyle: 'light',
navigationBarBackgroundColor: '#fff',
Expand Down
44 changes: 13 additions & 31 deletions src/common/api/handleLogin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,16 @@ import Taro from '@tarojs/taro';

const preUrl = 'https://kstack.muxixyz.com';

interface LoginResponseHeaders {
type LoginResponseHeaders = {
'X-Jwt-Token'?: string;
'X-Refresh-Token'?: string;
}
};

const handleLogin = async (data: Record<string, unknown> = {}) => {
const header = {
'Content-Type': 'application/json;charset=utf-8',
};

await Taro.setStorage({
key: 'shortToken',
data: 'shortToken',
});

await Taro.setStorage({
key: 'longToken',
data: 'longToken',
});

try {
const response = await Taro.request({
method: 'POST',
Expand All @@ -35,46 +25,38 @@ const handleLogin = async (data: Record<string, unknown> = {}) => {
const longToken = headers['X-Refresh-Token'];

if (shortToken && longToken) {
await Taro.setStorage({
void Taro.setStorage({
key: 'shortToken',
data: shortToken.toString(),
success: () => {
console.log('shortToken 设置成功');
// 方便看情况 log 出 shortToken 后期上线之前删除掉这个
console.log(shortToken);
},
});

await Taro.setStorage({
void Taro.setStorage({
key: 'longToken',
data: longToken.toString(),
success: () => {
console.log('longToken 设置成功');
// 方便看情况 log 出 longToken 后期上线之前删除掉这个
console.log(longToken);
},
});

await Taro.switchTab({
void Taro.switchTab({
url: '/pages/main/index',
});
}

// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
if (response.data.code !== 0) {
console.log('登陆失败(code 不为 0)');
await Taro.showToast({
// 登陆失败(code 不为 0)
void Taro.showToast({
icon: 'error',
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-member-access
title: response.data.msg,
title: '登录失败,请重试',
});
}

if (!response.statusCode.toString().startsWith('2')) {
throw new Error(`${response.statusCode}`);
throw new Error(`请求失败,状态码:${response.statusCode}`);
}
} catch (error) {
console.log(error);
void Taro.showToast({
icon: 'error',
title: (error as Error).message || '登录过程中发生错误',
});
}
};

Expand Down
25 changes: 25 additions & 0 deletions src/common/components/TitleButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { Button } from '@tarojs/components';
import { memo } from 'react';

interface TitleButtonProps {
title: string;
isSelected?: boolean;
isDisabled?: boolean;
onClick?: () => void;
}

const TitleButton: React.FC<TitleButtonProps> = memo(
({ title, isSelected, isDisabled, onClick }) => {
return (
<Button
className={`whitespace-nowrap px-2 py-1 text-xs text-[#f19900] shadow-lg ${isSelected ? 'bg-[#f19900] text-white' : 'bg-gray-200 text-white'}`}
disabled={isDisabled}
onClick={onClick}
>
{title}
</Button>
);
}
);

export default TitleButton;
21 changes: 21 additions & 0 deletions src/common/components/VirtualList.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import type { VirtualListProps as TaroVirtualListProps } from '@tarojs/components-advanced/dist/components/virtual-list';
import TaroVirtualList from '@tarojs/components-advanced/dist/components/virtual-list';
import { memo } from 'react';

interface VirtualListProps extends TaroVirtualListProps {}

const VirtualList: React.FC<VirtualListProps> = memo(
({ height, width, item, itemData, itemCount, itemSize, onScroll }) => (
<TaroVirtualList
height={height}
width={width}
item={item}
itemData={itemData}
itemCount={itemCount}
itemSize={itemSize}
onScroll={onScroll}
/>
)
);

export default VirtualList;
2 changes: 2 additions & 0 deletions src/common/components/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
export { default as CollectionCourse } from './CollectionCourse/CollectionCourse';
export { default as FloatingWindow } from './FloatingWindow/FloatingWindow';
export { default as TitleButton } from './TitleButton';
export { default as VirtualList } from './VirtualList';
15 changes: 0 additions & 15 deletions src/common/components/titleButton/titleButton.scss

This file was deleted.

24 changes: 0 additions & 24 deletions src/common/components/titleButton/titleButton.tsx

This file was deleted.

45 changes: 0 additions & 45 deletions src/common/hooks/useTokenCheck.ts

This file was deleted.

Empty file removed src/common/types/testTypes.ts
Empty file.
38 changes: 38 additions & 0 deletions src/common/types/userTypes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
export type UserInfo = {
avatarUrl: string; // 用户头像的URL
nickName: string; // 用户昵称
};

export type ResponseLevel = {
code?: number;
data: WebPointInfoVo;
msg?: string;
};

export type WebPointInfoVo = {
level: number;
next_level_points: number;
points: number;
};

export type ResponseUser = {
code?: number;
data: WebUserProfileVo;
msg?: string;
};

export type 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;
};
10 changes: 4 additions & 6 deletions src/common/utils/checkToken.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import Taro from '@tarojs/taro';

function checkToken() {
const checkToken = () => {
const token: string = Taro.getStorageSync('shortToken');

if (token) {
// eslint-disable-next-line no-console
console.log('Token 有');
void Taro.switchTab({ url: '/pages/main/index' });
} else {
// eslint-disable-next-line no-console
console.log('无token先登陆');
void Taro.redirectTo({ url: '/pages/login/index' });
}
}
};

export default checkToken;
Loading

0 comments on commit 3506129

Please sign in to comment.