Files
mini-programs/src/app.ts
2025-11-18 08:00:38 +08:00

68 lines
1.7 KiB
TypeScript

import { Component, ReactNode } from "react";
import Taro from "@tarojs/taro";
import "./nutui-theme.scss";
import "./app.scss";
import "./scss/qweather-icons/qweather-icons.css";
import { useGlobalStore } from "./store/global";
import { removeStorage } from "./store/storage";
import { sceneRedirectLogic } from './utils/helper';
interface AppProps {
children: ReactNode;
}
function clearSpecStorage() {
removeStorage('list_reload_page_number')
removeStorage('backFlag')
}
class App extends Component<AppProps> {
onLaunch(options) {
console.log("小程序启动,初始化逻辑写这里");
clearSpecStorage()
Taro.onNeedPrivacyAuthorization((resolve) => {
// 这里可以自定义弹窗(或直接默认同意)
resolve({ event: 'agree' }); // 同意隐私协议
});
// 微信授权逻辑已转移到 main_pages/index.tsx 中
// 不再在 app.ts 中执行静默登录
}
componentDidMount() {
// 使用 requestAnimationFrame 延迟执行,避免阻塞首屏渲染
requestAnimationFrame(() => {
this.getNavBarHeight();
});
// this.getLocation()
}
componentDidShow(options) {
sceneRedirectLogic(options.query, options.path);
// 微信授权逻辑已转移到 main_pages/index.tsx 中
}
componentDidHide() { }
// 获取导航高度
getNavBarHeight = () => {
const { getNavbarHeightInfo } = useGlobalStore.getState();
getNavbarHeightInfo();
};
// 获取位置信息
// getLocation = () => {
// const { getCurrentLocationInfo } = useGlobalStore.getState()
// getCurrentLocationInfo()
// }
render() {
// this.props.children 是将要会渲染的页面
return this.props.children;
}
}
export default App;