App.vue 2.42 KB
<!--
 * @Author: hookehuyr hookehuyr@gmail.com
 * @Date: 2022-05-26 23:52:36
 * @LastEditors: hookehuyr hookehuyr@gmail.com
 * @LastEditTime: 2022-08-29 14:00:58
 * @FilePath: /data-table/src/App.vue
 * @Description:
-->
<template>
  <!-- 页面缓存 -->
  <!-- <router-view v-slot="{ Component, route }">
    <keep-alive :include="keepPages" :max="10">
      <component :is="Component" :key="route.name" />
    </keep-alive>
  </router-view> -->
  <router-view></router-view>
</template>

<script setup>
import { mainStore, useTitle } from '@/utils/generatePackage'
import { computed, watchEffect, onMounted } from 'vue';
import { useRoute, useRouter } from 'vue-router'
import { Toast } from 'vant';
// 会根据配置判断是否显示调试控件
// eslint-disable-next-line no-unused-vars
import vConsole from '@/utils/vconsole'
// 初始化WX环境
// import wx from 'weixin-js-sdk'
// import { wxJsAPI } from '@/api/wx/config'
// import { apiList } from '@/api/wx/jsApiList.js'
import { wxInfo } from '@/utils/tools'

// 使用 include + pinia 状态管理动态缓存页面
const store = mainStore()
const keepPages = computed(() => store.getKeepPages)

// // TAG: 全局设置页面标题
// const $route = useRoute();
// watchEffect(
//   () => useTitle($route.meta.title)
// )
// 监听路由变化
// 切换路由页面返回顶部
const $router = useRouter();
watch(() => $router.currentRoute.value, (newValue, oldValue) => {
  nextTick(() => {
    // document.getElementById('app')?.scrollIntoView();
  })
  // console.warn(wxInfo().isMobile);
}, { immediate: true })

// TAG: 全局配置Toast
Toast.setDefaultOptions({
  duration: 2000,
  className: 'zIndex'
});

onMounted(async () => {
  // web端访问跳转
  // const url = import.meta.env.VITE_MOBILE_URL;
  // if (!wxInfo().isMobile && !wxInfo().isWeiXin) {
  //   location.href = url + location.hash;
  // }
  // const { data } = await wxJsAPI();
  // data.jsApiList = apiList;
  // wx.config(data);
  // wx.ready(() => {
  //   wx.showAllNonBaseMenuItem();
  // });
  // wx.error((err) => {
  //   console.warn(err);
  // });
})
</script>

<style lang="less">
@prefix: ~'@{namespace}-x';

html,
body {
  width: 100%;
  height: 100%;
  color: @base-font-color;
}

body {
  position: relative;
  p {
    margin: 0;
    padding: 0;
  }
}

.@{prefix} {
  color: red;
}

.global-center {
  position: relative;
  top: 50%;
  transform: translateY(-50%);
}

.zIndex {
  z-index: 4500 !important;
}
</style>