| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- <script setup>
- import { onLaunch, onShow, onHide, onUnload } from "@dcloudio/uni-app";
- import { store } from "@/store/index.js";
- import { useGlobalEventRemove, useInit, updateActivePageOnShow } from "@/utils/useBarcodeModule.js";
- import { useRouteMonitor } from "@/utils/useRouteMonitor.js";
- import { playClickSound } from "@/config/audioUtil.js";
- // 存储移动端触摸事件处理函数的引用
- let touchHandler;
- onLaunch(() => {
- // 尝试去获取本地的 token 和用户信息,填充到 store 中
- let token = uni.getStorageSync("token");
- if (token) {
- let userInfo = uni.getStorageSync("userInfo");
- if (userInfo) {
- if (userInfo.userId) {
- store.setUserInfo(userInfo);
- }
- }
- }
- // 移动端触摸事件处理函数
- touchHandler = (e) => {
- playClickSound();
- };
- // 添加移动端触摸事件监听 - 使用条件编译区分不同平台
- // #ifdef H5
- document.addEventListener("touchstart", touchHandler);
- // #endif
- // #ifdef APP-PLUS
- // 在APP环境中使用uni的API监听触摸事件
- var globalEvent = uni.requireNativePlugin("globalEvent");
- globalEvent.addEventListener("touchstart", touchHandler);
- // 初始化扫码模块
- useInit();
- // #endif
- });
- onShow(() => {});
- // 在应用销毁时移除点击事件监听
- onUnload(() => {
- // 移除移动端触摸事件监听 - 使用条件编译区分不同平台
- // #ifdef H5
- if (touchHandler) {
- document.removeEventListener("touchstart", touchHandler);
- touchHandler = null;
- }
- // #endif
- // #ifdef APP-PLUS
- if (touchHandler) {
- var globalEvent = uni.requireNativePlugin("globalEvent");
- globalEvent.removeEventListener("click", touchHandler);
- touchHandler = null;
- }
- // #endif
- });
- </script>
- <style lang="scss">
- @import "@/uni_modules/uview-plus/index.scss";
- @import "@/static/css/mystyle.css";
- @import "@/static/css/common.scss";
- /*每个页面公共css */
- page {
- background: #f5f6fa;
- height: 100%;
- }
- </style>
|