component.uvue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <template>
  2. <!-- #ifdef APP -->
  3. <scroll-view style="flex: 1;" enable-back-to-top="true">
  4. <!-- #endif -->
  5. <view class="uni-container" :class="isDarkMode ? 'theme-dark' : 'theme-light'">
  6. <view v-if="!hasLeftWin" class="uni-header-logo">
  7. <image class="uni-header-image" src="/static/componentIndex.png"></image>
  8. </view>
  9. <view v-if="!hasLeftWin" class="uni-text-box">
  10. <text class="hello-text">uni-app x内置组件,展示样式仅供参考,文档详见:</text>
  11. <u-link :href="'https://uniapp.dcloud.io/uni-app-x/component/'"
  12. :text="'https://uniapp.dcloud.io/uni-app-x/component/'" :inWhiteList="true"></u-link>
  13. </view>
  14. <uni-collapse>
  15. <uni-collapse-item ref="category" v-for="menuItem in menu" :key="menuItem.id" :title="menuItem.name"
  16. class="uni-panel">
  17. <template v-for="childMenuItem in menuItem.items" :key="childMenuItem.id">
  18. <view v-if="childMenuItem.items.length==0" class="uni-navigate-item pl" hover-class="is--active"
  19. @click="goPage(`/${childMenuItem.path}`)">
  20. <text class="uni-navigate-text" :class="{
  21. 'left-win-active': leftWinActive === childMenuItem.path && hasLeftWin,
  22. }">{{ childMenuItem.style["navigationBarTitleText"] }}</text>
  23. <image :src="arrowRightIcon" class="uni-icon-size"></image>
  24. </view>
  25. <uni-collapse v-else style="width: 100%;border-top: 1px solid #f0f0f0;">
  26. <uni-collapse-item :title="childMenuItem.name" class="uni-panel" style="margin-bottom: 0;">
  27. <view class="uni-navigate-item pl" hover-class="is--active"
  28. v-for="grandChildMenuItem in childMenuItem.items" :key="grandChildMenuItem.path"
  29. @click="goPage(`/${grandChildMenuItem.path}`)">
  30. <text class="uni-navigate-text" :class="{
  31. 'left-win-active':
  32. leftWinActive === grandChildMenuItem.path && hasLeftWin,
  33. }">{{ grandChildMenuItem.style["navigationBarTitleText"] }}</text>
  34. <image :src="arrowRightIcon" class="uni-icon-size"></image>
  35. </view>
  36. </uni-collapse-item>
  37. </uni-collapse>
  38. </template>
  39. </uni-collapse-item>
  40. </uni-collapse>
  41. </view>
  42. <!-- #ifdef APP -->
  43. </scroll-view>
  44. <!-- #endif -->
  45. </template>
  46. <script lang="uts">
  47. import { generateMenu, MenuItem } from './generateMenu.uts'
  48. const menu = generateMenu('pages/component')
  49. // #ifdef APP
  50. import checkUpdate from '@/uni_modules/uni-upgrade-center-app/utils/check-update'
  51. // #endif
  52. import { state } from '@/store/index.uts'
  53. export default {
  54. data() {
  55. return {
  56. menu: menu as MenuItem[],
  57. arrowRightIcon: '/static/icons/arrow-right.png' as string.ImageURIString,
  58. pageHiden: false
  59. }
  60. },
  61. computed: {
  62. hasLeftWin() : boolean {
  63. return !state.noMatchLeftWindow
  64. },
  65. leftWinActive() : string {
  66. return state.leftWinActive.slice(1)
  67. },
  68. isDarkMode() : boolean {
  69. return state.isDarkMode
  70. },
  71. netless() : boolean {
  72. return state.netless
  73. }
  74. },
  75. // #ifdef APP-HARMONY
  76. watch: {
  77. 'netless': {
  78. immediate: true,
  79. handler(netless) {
  80. if (netless) {
  81. this.menu = this.menu.filter(item => {
  82. return !['unicloud'].includes(item.id)
  83. })
  84. }
  85. }
  86. }
  87. },
  88. // #endif
  89. methods: {
  90. goPage(url : string) {
  91. if (this.hasLeftWin) {
  92. uni.reLaunch({ url })
  93. } else {
  94. uni.navigateTo({ url })
  95. }
  96. }
  97. },
  98. // #ifdef WEB
  99. watch: {
  100. $route: {
  101. immediate: true,
  102. handler(newRoute) {
  103. if (newRoute.matched.length) {
  104. const activeCategoryIndex = this.menu.findIndex(menuItem => menuItem?.items.some(item => this.leftWinActive && this.leftWinActive === item?.path))
  105. if (activeCategoryIndex > -1) {
  106. this.$nextTick(() => {
  107. ((this.$refs.category as ComponentPublicInstance[])[activeCategoryIndex])?.$callMethod('openCollapse', true)
  108. })
  109. }
  110. }
  111. }
  112. }
  113. },
  114. // #endif
  115. onReady() {
  116. // #ifdef UNI-APP-X && APP
  117. uni.getPrivacySetting({
  118. success(res) {
  119. if (process.env.NODE_ENV !== 'development') {
  120. if (res.needAuthorization) {
  121. uni.onPrivacyAuthorizationChange((res) => {
  122. if (!res.needAuthorization) {
  123. checkUpdate()
  124. }
  125. })
  126. } else {
  127. checkUpdate()
  128. }
  129. }
  130. }
  131. })
  132. // #endif
  133. },
  134. onShow() {
  135. this.pageHiden = false
  136. },
  137. onHide() {
  138. this.pageHiden = true
  139. },
  140. beforeUnmount() {
  141. uni.showTabBar()?.catch(_ => { })
  142. }
  143. }
  144. </script>
  145. <style>
  146. .pl {
  147. padding-left: 18px
  148. }
  149. /* web端适配暗黑主题 */
  150. /* #ifdef WEB */
  151. .uni-container.theme-dark {
  152. min-height: calc(100vh - var(--uni-safe-area-inset-top));
  153. }
  154. /* #endif */
  155. </style>