Skip to content

Commit

Permalink
Merge pull request MuxiKeStack#217 from MuxiKeStack/feat-cache
Browse files Browse the repository at this point in the history
Feat cache
  • Loading branch information
eleliauk authored Dec 24, 2024
2 parents c3bc59a + a24e1b8 commit a9ea530
Show file tree
Hide file tree
Showing 21 changed files with 89 additions and 26 deletions.
10 changes: 7 additions & 3 deletions src/common/components/chart/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,10 @@ const LineChart: React.FC<LineChartProps> = (props) => {
// 高亮
ctx.lineWidth = 1;
const highlightPos = heightLightPercent ?? DEFAULT_HEIGHTLIGHT_POS;
const centerX = ((width - 2 * padding) / 7) * highlightPos + (1 / 2) * barWidth;
const centerX = ((width - 2 * padding) / 7) * Math.ceil(highlightPos);
drawGradientRectangle(
ctx,
centerX + barWidth / 2,
centerX + padding,
padding - 6,
barWidth,
height - 2 * padding + 6,
Expand All @@ -148,7 +148,11 @@ const LineChart: React.FC<LineChartProps> = (props) => {
ctx.beginPath();
ctx.fillStyle = DEFAULT_TEXT_COLOR;
ctx.font = '15px sans-serif';
ctx.fillText(title ?? DEFAULT_TITLE, centerX, padding / 2);
ctx.fillText(
title ?? DEFAULT_TITLE,
centerX + (1 / 2) * (title ?? DEFAULT_TITLE)?.length,
padding / 2
);
void ctx.draw();
};

Expand Down
2 changes: 1 addition & 1 deletion src/modules/login/components/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { TopBackground } from '@/common/assets/img/login';
import AuthForm from './AuthForm';

const Login: React.FC = memo(() => (
<View className="h-screen w-full">
<View className="h-screen w-full overflow-auto">
<Image src={TopBackground as string} className="w-full"></Image>
<AuthForm />
</View>
Expand Down
13 changes: 11 additions & 2 deletions src/modules/notification/components/Notification.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,19 @@ const Notification: React.FC = memo(() => {
}, [test]);
const handleScroll = useCallback(
(event) => {
if (end) return;
if (end) {
void Taro.showToast({
title: '没有更多啦',
icon: 'none',
});
return;
}
void Taro.showLoading({ title: '加载中 ...' });
if (!loading) {
console.log('fetching', event);
void fetchData();
void fetchData().then(() => {
void Taro.hideLoading();
});
}
},
[loading, currentMessage.length, end]
Expand Down
1 change: 1 addition & 0 deletions src/pages/classInfo/index.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export default definePageConfig({
navigationBarTitleText: '课程主页',
navigationBarBackgroundColor: '#F9F9F2',
disableScroll: true,
});
1 change: 1 addition & 0 deletions src/pages/editUser/index.config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export default definePageConfig({
navigationBarTitleText: '修改个人信息',
disableScroll: true,
});
1 change: 1 addition & 0 deletions src/pages/evaluate/evaluate.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export default definePageConfig({
navigationBarTitleText: '评课',
navigationBarBackgroundColor: '#F9F9F2',
disableScroll: true,
});
1 change: 1 addition & 0 deletions src/pages/evaluateInfo/index.config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export default definePageConfig({
navigationBarTitleText: '首页',
disableScroll: true,
});
1 change: 1 addition & 0 deletions src/pages/feedback/index.config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export default definePageConfig({
navigationBarTitleText: '意见反馈',
disableScroll: true,
});
1 change: 1 addition & 0 deletions src/pages/guide/index.config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export default definePageConfig({
navigationBarTitleText: '选课手册',
disableScroll: true,
});
1 change: 1 addition & 0 deletions src/pages/index/index.config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export default definePageConfig({
navigationBarTitleText: '首页',
disableScroll: true,
});
1 change: 1 addition & 0 deletions src/pages/main/index.config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export default definePageConfig({
navigationBarTitleText: '首页',
disableScroll: true,
});
64 changes: 46 additions & 18 deletions src/pages/main/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/* eslint-disable import/first */
import { Image, ScrollView, Text, View } from '@tarojs/components';
import Taro from '@tarojs/taro';
import { useCallback, useEffect, useMemo, useState } from 'react';
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';

import './index.scss';

Expand All @@ -24,7 +24,6 @@ const COURSE_NAME_MAP = {

export default function Index() {
const handleSearchToggle = () => {
// console.log(isSearchActive);
void Taro.navigateTo({
url: '/pages/research/research',
});
Expand All @@ -42,6 +41,36 @@ export default function Index() {
changeType,
})
);
const touchStartX = useRef(0); // 记录触摸起始点
const touchEndX = useRef(0); // 记录触摸结束点

const handleTouchStart = (e) => {
//eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
touchStartX.current = e?.touches[0].pageX as number; // 记录起始触摸点
};
const handleTouchMove = (e) => {
//eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
touchEndX.current = e?.touches[0].pageX as number; // 实时记录滑动点
};

const handleTouchEnd = () => {
const deltaX = touchEndX.current - touchStartX.current; // 计算滑动距离
const tabs = Object.entries(COURSE_NAME_MAP);
const currentTab = tabs.findIndex(([name, value]) => name === classType);
if (Math.abs(deltaX) > 50) {
// 判断滑动距离是否足够切换 Tab
if (deltaX > 0 && currentTab > 0) {
// 向右滑动且不是第一个 Tab
handleChangeType(tabs[currentTab - 1][0]);
} else if (deltaX < 0 && currentTab < tabs.length - 1) {
// 向左滑动且不是最后一个 Tab
handleChangeType(tabs[currentTab + 1][0]);
}
}
// 重置滑动记录
touchStartX.current = 0;
touchEndX.current = 0;
};

useEffect(() => {
void dispatch.loadMoreComments();
Expand All @@ -67,19 +96,6 @@ 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 @@ -90,13 +106,11 @@ 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);
}
};

void getParams();
}, []);
useEffect(() => {
Expand All @@ -105,6 +119,8 @@ export default function Index() {
const geneHandler = () => {
let timeNow = Date.now();
return (e) => {
console.log(e);

if (
!useCourseStore.getState().loading &&
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
Expand All @@ -113,7 +129,16 @@ export default function Index() {
e.detail.deltaY < 0 &&
Date.now() - timeNow > 1000
) {
void dispatch.loadMoreComments();
void Taro.showLoading({ title: '加载中...' });
void dispatch
.loadMoreComments()
.then(() => {
Taro.hideLoading();
})
.catch(() => {
Taro.hideLoading();
void Taro.showToast({ title: '加载失败', icon: 'error' });
});
timeNow = Date.now();
}
};
Expand Down Expand Up @@ -165,6 +190,9 @@ export default function Index() {
})}
</View>
<ScrollView
onTouchStart={handleTouchStart}
onTouchMove={handleTouchMove}
onTouchEnd={handleTouchEnd}
refresherEnabled
style={{ height: '70vh' }}
refresherTriggered={refresherTriggered}
Expand Down
1 change: 1 addition & 0 deletions src/pages/myclass/myclass.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export default definePageConfig({
navigationBarTitleText: '我的课程',
navigationBarBackgroundColor: '#F9F9F2',
disableScroll: true,
});
2 changes: 1 addition & 1 deletion src/pages/myclass/myclass.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export default function Myclass() {
};

return (
<View>
<View className="h-full w-full overflow-auto">
<View className="select">
<Picker
mode="multiSelector"
Expand Down
8 changes: 8 additions & 0 deletions src/pages/myclass/store/store.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { StateCreator } from 'zustand';

const CreateCourseInfoStore: StateCreator<
CourseInfoStore,
[['zustand/immer', never]],
[['zustand/immer', never]],
CourseInfoStore
> = (...args) => ({});
1 change: 1 addition & 0 deletions src/pages/notification/index.config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export default definePageConfig({
navigationBarTitleText: '消息提醒',
disableScroll: true,
});
1 change: 1 addition & 0 deletions src/pages/profile/index.config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export default definePageConfig({
navigationBarTitleText: '个人主页',
disableScroll: true,
});
1 change: 1 addition & 0 deletions src/pages/publishQuestion/index.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export default definePageConfig({
navigationBarTitleText: '问问同学',
navigationBarBackgroundColor: '#F9F9F2',
disableScroll: true,
});
1 change: 1 addition & 0 deletions src/pages/questionInfo/index.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export default definePageConfig({
navigationBarTitleText: '问问同学',
navigationBarBackgroundColor: '#F9F9F2',
disableScroll: true,
});
1 change: 1 addition & 0 deletions src/pages/research/research.config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export default definePageConfig({
navigationBarTitleText: '搜索',
disableScroll: true,
});
2 changes: 1 addition & 1 deletion src/pages/research/research.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ const Research: React.FC = () => {

return (
<View
className="index"
className="index h-[100vh] w-[100vw]"
onClick={() => {
handleClick();
}}
Expand Down

0 comments on commit a9ea530

Please sign in to comment.