about.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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 { tabbarStore } from '@/tabbar/store'
  5. import RequestComp from './components/request.vue'
  6. import VBindCss from './components/VBindCss.vue'
  7. definePage({
  8. style: {
  9. navigationBarTitleText: '关于',
  10. },
  11. // 登录授权(可选):跟以前的 needLogin 类似功能,但是同时支持黑白名单,详情请见 arc/router 文件夹
  12. excludeLoginPath: true,
  13. // 角色授权(可选):如果需要根据角色授权,就配置这个
  14. roleAuth: {
  15. field: 'role',
  16. value: 'admin',
  17. redirect: '/pages/auth/403',
  18. },
  19. })
  20. // 浏览器打印 isH5为true, isWeb为false,大家尽量用 isH5
  21. console.log({ isApp, isAppAndroid, isAppHarmony, isAppIOS, isAppPlus, isH5, isMpWeixin, isWeb })
  22. function toLogin() {
  23. uni.navigateTo({
  24. url: `${LOGIN_PAGE}?redirect=${encodeURIComponent('/pages/about/about?a=1&b=2')}`,
  25. })
  26. }
  27. function gotoAlova() {
  28. uni.navigateTo({
  29. url: '/pages/about/alova',
  30. })
  31. }
  32. function gotoVueQuery() {
  33. uni.navigateTo({
  34. url: '/pages/about/vue-query',
  35. })
  36. }
  37. function gotoSubPage() {
  38. uni.navigateTo({
  39. url: '/pages-sub/demo/index',
  40. })
  41. }
  42. // uniLayout里面的变量通过 expose 暴露出来后可以在 onReady 钩子获取到(onLoad 钩子不行)
  43. const uniLayout = ref()
  44. onLoad(() => {
  45. console.log('onLoad:', uniLayout.value) // onLoad: undefined
  46. })
  47. onReady(() => {
  48. console.log('onReady:', uniLayout.value) // onReady: Proxy(Object)
  49. console.log('onReady:', uniLayout.value.testUniLayoutExposedData) // onReady: testUniLayoutExposedData
  50. })
  51. // 结论:第一次通过onShow获取不到,但是可以通过 onReady获取到,后面就可以通过onShow获取到了
  52. onShow(() => {
  53. console.log('onShow:', uniLayout.value) // onReady: Proxy(Object)
  54. console.log('onShow:', uniLayout.value?.testUniLayoutExposedData) // onReady: testUniLayoutExposedData
  55. })
  56. function gotoTabbar() {
  57. uni.switchTab({
  58. url: '/pages/index/index',
  59. })
  60. }
  61. // #region setTabbarBadge
  62. function setTabbarBadge() {
  63. tabbarStore.setTabbarItemBadge(1, 100)
  64. }
  65. // #endregion
  66. const uniKuRoot = ref()
  67. // 结论:(同上)第一次通过onShow获取不到,但是可以通过 onReady获取到,后面就可以通过onShow获取到了
  68. onReady(() => {
  69. console.log('onReady uniKuRoot exposeRef', uniKuRoot.value?.exposeRef)
  70. })
  71. onShow(() => {
  72. console.log('onShow uniKuRoot exposeRef', uniKuRoot.value?.exposeRef)
  73. })
  74. </script>
  75. <template root="uniKuRoot">
  76. <view>
  77. <view class="mt-8 text-center text-xl text-gray-400">
  78. 请求调用、unocss、static图片
  79. </view>
  80. <view class="my-2 text-center">
  81. <image src="/static/images/avatar.jpg" class="h-100px w-100px" />
  82. </view>
  83. <button class="mt-4 w-40 text-center" @click="toLogin">
  84. 点击去登录页
  85. </button>
  86. <button class="mt-4 w-60 text-center" @click="setTabbarBadge">
  87. 设置tabbarBadge
  88. </button>
  89. <RequestComp />
  90. <VBindCss />
  91. <view class="mb-6 h-1px bg-#eee" />
  92. <view class="text-center">
  93. <button type="primary" size="mini" class="w-160px" @click="gotoAlova">
  94. 前往 alova 示例页面
  95. </button>
  96. </view>
  97. <view class="text-center">
  98. <button type="primary" size="mini" class="w-160px" @click="gotoTabbar">
  99. 切换tabbar
  100. </button>
  101. </view>
  102. <view class="text-center">
  103. <button type="primary" size="mini" class="w-160px" @click="gotoVueQuery">
  104. vue-query 示例页面
  105. </button>
  106. </view>
  107. <view class="text-center">
  108. <button type="primary" size="mini" class="w-160px" @click="gotoSubPage">
  109. 前往分包页面
  110. </button>
  111. </view>
  112. <view class="mt-6 text-center text-sm">
  113. <view class="inline-block w-80% text-gray-400">
  114. 为了方便脚手架动态生成不同UI模板,本页的按钮统一使用UI库无关的原生button
  115. </view>
  116. </view>
  117. <view class="h-6" />
  118. </view>
  119. </template>