app.js 1.1 KB
/*
 * @Date: 2025-06-28 10:33:00
 * @LastEditors: hookehuyr hookehuyr@gmail.com
 * @LastEditTime: 2025-06-28 11:04:17
 * @FilePath: /myApp/src/app.js
 * @Description: 文件描述
 */
import { createApp } from 'vue'
import { createPinia } from 'pinia'
import './app.less'
import { saveCurrentPagePath, needAuth, silentAuth, navigateToAuth } from '@/utils/authRedirect'

const App = createApp({
    // 对应 onLaunch
  async onLaunch(options) {
    const path = options?.path || ''
    const query = options?.query || {}

    const query_string = Object.keys(query)
      .map((key) => `${key}=${encodeURIComponent(query[key])}`)
      .join('&')
    const full_path = query_string ? `${path}?${query_string}` : path

    if (full_path) {
      saveCurrentPagePath(full_path)
    }

    if (!needAuth()) return

    if (path === 'pages/auth/index') return

    try {
      await silentAuth()
    } catch (error) {
      navigateToAuth(full_path || undefined)
    }
  },
  onShow() {
  },
  // 入口组件不需要实现 render 方法,即使实现了也会被 taro 所覆盖
});

App.use(createPinia())

export default App