Skip to content

Commit

Permalink
fix: 扫码bug
Browse files Browse the repository at this point in the history
  • Loading branch information
icai committed Sep 19, 2024
1 parent 0d7cb09 commit cdd1814
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 16 deletions.
3 changes: 2 additions & 1 deletion project.alipay.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
}
},
"component2": true
}
},
"miniprogramRoot": "dist/"
}
7 changes: 0 additions & 7 deletions src/components/link/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { View } from '@tarojs/components';
import Taro from '@tarojs/taro';
import * as utils from '@/libs/utils';
import React from 'react';

Expand Down Expand Up @@ -53,11 +52,5 @@ const Link: React.FC<IProps> = ({ to, className, children }) => {
);
};

Link.defaultProps = {
to: {
url: '',
params: {},
},
};

export default Link;
6 changes: 1 addition & 5 deletions src/components/topics/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,9 @@ interface IProps {
topics: ITopic[];
}

const TopicsList: React.FC<IProps> = ({ topics }) => {
const TopicsList: React.FC<IProps> = ({ topics = [] }) => {
const renderTopics = topics.map((topic) => <Topic key={topic.id} topic={topic} />);
return <View className="topic-list">{renderTopics}</View>;
};

TopicsList.defaultProps = {
topics: [],
};

export { TopicsList };
9 changes: 6 additions & 3 deletions src/hooks/useRouterCodeUrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@ import { useRouter } from '@tarojs/taro';
const useRouterCodeUrl = (basePath = '') => {
const router = useRouter(true);
const [url, setUrl] = useState('');
const page = router.path.replace(basePath, '')
let page = router.path.replace(basePath, '')
if (page.includes('?')) {
page = page.split('?')[0];
}
const params = router.params;
const query = Object.keys(params).map(key => `${key}=${params[key]}`).join('&');
const fullUrl = query ? `${page}?${encodeURIComponent(query)}` : page;
const fullUrl = query ? `${page}${encodeURIComponent('?' + query)}` : page;
useEffect(() => {
const newUrl = `alipays://platformapi/startapp?appId=2021002183695117&page=${encodeURIComponent(fullUrl)}`;
const newUrl = `alipays://platformapi/startapp?appId=2021002183695117&page=${fullUrl}`;
setUrl(newUrl);
}, [router.path, router.params.id, basePath]);

Expand Down
12 changes: 12 additions & 0 deletions src/pages/topic/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ const Topic: React.FC = () => {
fetchTopic();
}, [dispatch]);


// watch route change
useEffect(() => {
fetchTopic();
}, [router.params.id]);

const addReply = (id: string) => {
setCurReplyId(id);
if (!userInfo.userId) {
Expand Down Expand Up @@ -90,6 +96,12 @@ const Topic: React.FC = () => {

const fetchTopic = () => {
const topicId = router?.params.id || '';
if (!topicId) {
// navigate to home page
return utils.redirectTo({
url: "/pages/index/index"
});
}
setTopicId(topicId);
getTopic({
topicId: topicId
Expand Down

0 comments on commit cdd1814

Please sign in to comment.