API.uvue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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/apiIndex.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/api/'" :text="'https://uniapp.dcloud.io/uni-app-x/api/'"
  12. :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="pl" hover-class="is--active"
  19. :class="{'uni-navigate-item':childMenuItem.path !== 'set-tab-bar' || windowWidth <= 768}"
  20. @click="goPage(`/${childMenuItem.path}`)">
  21. <template v-if="childMenuItem.path !== 'set-tab-bar' || windowWidth <= 768">
  22. <text class="uni-navigate-text"
  23. :class="{'left-win-active': leftWinActive === childMenuItem.path && hasLeftWin}">{{ childMenuItem.style["navigationBarTitleText"] }}</text>
  24. <image :src="arrowRightIcon" class="uni-icon-size"></image>
  25. </template>
  26. </view>
  27. <uni-collapse v-else style="width: 100%;border-top: 1px solid #f0f0f0;">
  28. <uni-collapse-item :title="childMenuItem.name" class="uni-panel"
  29. style="margin-bottom: 0;">
  30. <view class="uni-navigate-item pl" hover-class="is--active"
  31. v-for="grandChildMenuItem in childMenuItem.items" :key="grandChildMenuItem.path"
  32. @click="goPage(`/${grandChildMenuItem.path}`)">
  33. <text class="uni-navigate-text" :class="{
  34. 'left-win-active':
  35. leftWinActive === grandChildMenuItem.path && hasLeftWin,
  36. }">{{ grandChildMenuItem.style["navigationBarTitleText"] }}</text>
  37. <image :src="arrowRightIcon" class="uni-icon-size"></image>
  38. </view>
  39. </uni-collapse-item>
  40. </uni-collapse>
  41. </template>
  42. </uni-collapse-item>
  43. </uni-collapse>
  44. <!-- #ifdef MP || WEB -->
  45. <view v-if="!hasLeftWin" ref="pop" @click="hidePop()" class="popup" @touchmove.prevent="stopPropagation">
  46. <!-- #endif -->
  47. <!-- #ifndef MP || WEB -->
  48. <view v-if="!hasLeftWin" ref="pop" @click="hidePop()" class="popup">
  49. <!-- #endif -->
  50. <view style="width: 90%; background-color: white" @click.stop="stopClickPop">
  51. <api-set-tabbar></api-set-tabbar>
  52. </view>
  53. </view>
  54. </view>
  55. <!-- #ifdef APP -->
  56. </scroll-view>
  57. <!-- #endif -->
  58. </template>
  59. <script lang="uts">
  60. import { generateMenu, MenuItem } from './generateMenu.uts'
  61. const menu = generateMenu('pages/API')
  62. import { state } from '@/store/index.uts'
  63. export default {
  64. data() {
  65. return {
  66. menu: menu as MenuItem[],
  67. arrowRightIcon: '/static/icons/arrow-right.png'
  68. }
  69. },
  70. computed: {
  71. hasLeftWin() : boolean {
  72. return !state.noMatchLeftWindow
  73. },
  74. leftWinActive() : string {
  75. return state.leftWinActive.slice(1)
  76. },
  77. windowWidth() : number {
  78. return uni.getWindowInfo().windowWidth
  79. },
  80. isDarkMode() : boolean {
  81. return state.isDarkMode
  82. },
  83. netless() : boolean {
  84. return state.netless
  85. }
  86. },
  87. // #ifdef APP-HARMONY
  88. watch: {
  89. 'netless': {
  90. immediate: true,
  91. handler(netless) {
  92. if (netless) {
  93. this.menu = this.menu.filter(item => {
  94. return !['unicloud'].includes(item.id)
  95. })
  96. }
  97. }
  98. }
  99. },
  100. // #endif
  101. methods: {
  102. goPage(url : string) {
  103. if (url == '/set-tab-bar') {
  104. this.showPop()
  105. }else {
  106. if (this.hasLeftWin) {
  107. uni.reLaunch({ url })
  108. } else {
  109. uni.navigateTo({ url })
  110. }
  111. }
  112. },
  113. showPop: function () {
  114. (this.$refs["pop"] as UniElement).style.setProperty("display", "flex")
  115. },
  116. hidePop: function () {
  117. (this.$refs["pop"] as UniElement).style.setProperty("display", "none")
  118. },
  119. stopClickPop: function (e : PointerEvent) {
  120. e.stopPropagation() //点击到pop的非灰色区域,拦截点击事件
  121. },
  122. stopPropagation() {
  123. }
  124. },
  125. // #ifdef WEB
  126. watch: {
  127. $route: {
  128. immediate: true,
  129. handler(newRoute) {
  130. if (newRoute.matched.length) {
  131. const activeCategoryIndex = this.menu.findIndex(menuItem => menuItem?.items.some(item => this.leftWinActive && this.leftWinActive === item?.path))
  132. if (activeCategoryIndex > -1) {
  133. this.$nextTick(() => {
  134. ((this.$refs.category as ComponentPublicInstance[])[activeCategoryIndex])?.$callMethod('openCollapse', true)
  135. })
  136. }
  137. }
  138. }
  139. }
  140. },
  141. // #endif
  142. }
  143. </script>
  144. <style>
  145. .pl{
  146. padding-left: 18px
  147. }
  148. .popup {
  149. position: fixed;
  150. top: 0;
  151. bottom: 0;
  152. left: 0;
  153. right: 0;
  154. align-items: center;
  155. justify-content: center;
  156. display: none;
  157. background-color: rgba(16, 16, 16, 0.5);
  158. }
  159. </style>