about.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <script lang="ts" setup>
  2. import { isApp, isAppAndroid, isAppHarmony, isAppIOS, isAppPlus, isH5, isMpWeixin, isWeb } from '@uni-helper/uni-env'
  3. import { LOGIN_PAGE } from '@/router/config'
  4. import { useTokenStore } from '@/store'
  5. import RequestOpenApiComp from './components/request-openapi.vue'
  6. import RequestComp from './components/request.vue'
  7. import UploadComp from './components/Upload.vue'
  8. import VBindCss from './components/VBindCss.vue'
  9. definePage({
  10. style: {
  11. navigationBarTitleText: '关于',
  12. },
  13. // 登录授权(可选):跟以前的 needLogin 类似功能,但是同时支持黑白名单,详情请见 arc/router 文件夹
  14. excludeLoginPath: false,
  15. })
  16. const tokenStore = useTokenStore()
  17. // 浏览器打印 isH5为true, isWeb为false,大家尽量用 isH5
  18. console.log({ isApp, isAppAndroid, isAppHarmony, isAppIOS, isAppPlus, isH5, isMpWeixin, isWeb })
  19. function gotoLogin() {
  20. if (tokenStore.hasLogin) {
  21. uni.showToast({
  22. title: '已登录,不能去登录页',
  23. icon: 'none',
  24. })
  25. return
  26. }
  27. uni.navigateTo({
  28. url: `${LOGIN_PAGE}?redirect=${encodeURIComponent('/pages-sub/about/about?a=1&b=2')}`,
  29. })
  30. }
  31. function logout() {
  32. // 清空用户信息
  33. tokenStore.logout()
  34. // 执行退出登录逻辑
  35. uni.showToast({
  36. title: '退出登录成功',
  37. icon: 'success',
  38. })
  39. }
  40. function gotoScroll() {
  41. uni.navigateTo({
  42. url: '/pages-sub/demo/scroll',
  43. })
  44. }
  45. function gotoAlova() {
  46. uni.navigateTo({
  47. url: '/pages-sub/about/alova',
  48. })
  49. }
  50. function gotoSubPage() {
  51. uni.navigateTo({
  52. url: '/pages-sub/demo/index',
  53. })
  54. }
  55. // uniLayout里面的变量通过 expose 暴露出来后可以在 onReady 钩子获取到(onLoad 钩子不行)
  56. const uniLayout = ref()
  57. onLoad(() => {
  58. console.log('onLoad:', uniLayout.value) // onLoad: undefined
  59. })
  60. onReady(() => {
  61. console.log('onReady:', uniLayout.value) // onReady: Proxy(Object)
  62. console.log('onReady:', uniLayout.value.testUniLayoutExposedData) // onReady: testUniLayoutExposedData
  63. })
  64. // 结论:第一次通过onShow获取不到,但是可以通过 onReady获取到,后面就可以通过onShow获取到了
  65. onShow(() => {
  66. console.log('onShow:', uniLayout.value) // onReady: Proxy(Object)
  67. console.log('onShow:', uniLayout.value?.testUniLayoutExposedData) // onReady: testUniLayoutExposedData
  68. })
  69. const uniKuRoot = ref()
  70. // 结论:(同上)第一次通过onShow获取不到,但是可以通过 onReady获取到,后面就可以通过onShow获取到了
  71. onReady(() => {
  72. console.log('onReady uniKuRoot exposeRef', uniKuRoot.value?.exposeRef)
  73. })
  74. onShow(() => {
  75. console.log('onShow uniKuRoot exposeRef', uniKuRoot.value?.exposeRef)
  76. })
  77. </script>
  78. <template root="uniKuRoot">
  79. <!-- page-meta 使用范例 -->
  80. <page-meta page-style="overflow: auto" />
  81. <view>
  82. <view class="mt-8 text-center text-xl text-gray-400">
  83. 请求调用、unocss、static图片
  84. </view>
  85. <view class="my-2 text-center">
  86. <image src="/static/images/avatar.jpg" class="h-100px w-100px" />
  87. </view>
  88. <view class="my-2 text-center">
  89. 当前是否登录:{{ tokenStore.hasLogin }}
  90. </view>
  91. <view class="m-auto max-w-600px flex items-center">
  92. <button class="mt-4 w-40 text-center" @click="gotoLogin">
  93. 点击去登录页
  94. </button>
  95. <button class="mt-4 w-40 text-center" @click="logout">
  96. 点击退出登录
  97. </button>
  98. </view>
  99. <RequestOpenApiComp />
  100. <RequestComp />
  101. <UploadComp />
  102. <VBindCss />
  103. <view class="mb-6 h-1px bg-#eee" />
  104. <view class="mb-2 text-center">
  105. <button type="primary" size="mini" class="w-240px" @click="gotoScroll">
  106. 下拉刷新和下拉加载更多
  107. </button>
  108. <view>简单hooks(非z-paging组件)</view>
  109. </view>
  110. <view class="text-center">
  111. <button type="primary" size="mini" class="w-160px" @click="gotoAlova">
  112. 前往 alova 示例页面
  113. </button>
  114. </view>
  115. <view class="text-center">
  116. <button type="primary" size="mini" class="w-160px" @click="gotoSubPage">
  117. 前往分包页面
  118. </button>
  119. </view>
  120. <view class="mt-6 text-center text-sm">
  121. <view class="inline-block w-80% text-gray-400">
  122. 为了方便脚手架动态生成不同UI模板,本页的按钮统一使用UI库无关的原生button
  123. </view>
  124. </view>
  125. <view class="h-6" />
  126. </view>
  127. </template>