<template>
  <cc-root-view>
    <image src="/static/logo.png" />
    <up-button type="primary" text="确定" @click="handleClick" />
    <up-button type="primary" text="需要权限" @click="handleClickAccess" class="my-7" />
    <up-button type="primary" text="不需要权限" @click="handleClickNotNeedAccess" />
  </cc-root-view>
</template>

<script setup lang="ts">
import { useWeAppAuthStore } from '@/common'
import { goto } from '@/common/libraries/naviHelper'
import { onLoad } from '@dcloudio/uni-app'
import { getCurrentInstance } from 'vue'

const auth: any = useWeAppAuthStore()

function handleClick() {
  goto('/pages/detail?id=123')
}

// 需要权限，进行权限判断，真实逻辑在闭包里
function handleClickAccess() {
  auth.checkRight(() => {
    goto('/pages/mine')
  })
}

function handleClickNotNeedAccess() {
  goto('/pages/mine')
}

onLoad(async () => {
  console.log('index.vue onLoad 1')
  await getCurrentInstance()?.appContext.config.globalProperties.$onLaunched
  console.log('index.vue onLoad 2')
})
</script>
