diff --git a/src/pages/index/index.jsx b/src/pages/index/index.jsx
index e32f124..b356acf 100644
--- a/src/pages/index/index.jsx
+++ b/src/pages/index/index.jsx
@@ -1,5 +1,5 @@
import { Component } from "react";
-import Taro from "@tarojs/taro";
+import Taro ,{useRouter}from "@tarojs/taro";
import { View, Text, Image, Button } from "@tarojs/components";
import "./index.scss";
import { AtTabBar } from "taro-ui";
@@ -101,6 +101,8 @@ const Index = () => {
const [headers, setHeaders] = useState([]); // 存储所有
的内容
const contentRef = useRef(null); // 用于获取渲染后的 DOM
+ const router = useRouter(); // Taro 3+ 获取路由参数
+
marked.setOptions({
breaks: true, // 是否回车换行
gfm: true, //使用经批准的 GitHub Flavored Markdown (GFM) 规范
@@ -430,7 +432,7 @@ const Index = () => {
} catch (error) {
console.error('清空存储失败:', error);
Taro.showToast({
- title: '清空失败',
+ title: '清空存储失败',
icon: 'none',
});
}
@@ -441,8 +443,11 @@ const Index = () => {
useEffect(() => {
// 判断是否在微信
isWeChatFun()
- // 测试用=>清除缓存
- // clearAllStorage()
+ // 方法1:Taro 3+ 推荐方式(支持小程序 + H5)
+ if (router && router.params && router.params.type === 'clean') {
+ clearAllStorage();
+ return
+ }
const init = async () => {
getOrCreateUserId(); // 确保 userId 存在
@@ -560,17 +565,17 @@ const Index = () => {
});
};
-// 生成或获取 userId(修改为无下划线)
-const getOrCreateUserId = () => {
- let userId = Taro.getStorageSync("userId");
- if (!userId) {
- // 修改这里:去掉下划线
- userId = `user${Date.now()}`; // 示例:user1766043770158
- Taro.setStorageSync("userId", userId);
- console.log('新生成 userId:', userId);
- }
- return userId;
-};
+ // 生成或获取 userId(修改为无下划线)
+ const getOrCreateUserId = () => {
+ let userId = Taro.getStorageSync("userId");
+ if (!userId) {
+ // 修改这里:去掉下划线
+ userId = `user${Date.now()}`; // 示例:user1766043770158
+ Taro.setStorageSync("userId", userId);
+ console.log('新生成 userId:', userId);
+ }
+ return userId;
+ };
const payh5 = (type, total_fee = 1000) => {
const userId = getOrCreateUserId(); // ← 新增:获取 userId