component.uvue 12.3 KB
Newer Older
1 2
<template>
  <!-- #ifdef APP -->
3
  <scroll-view style="flex: 1; background-color: #f8f8f8" enable-back-to-top="true">
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
  <!-- #endif -->
    <view class="uni-container">
      <view class="uni-header-logo">
        <image class="uni-header-image" src="/static/componentIndex.png"></image>
      </view>
      <view class="uni-text-box">
        <text class="hello-text">uni-app内置组件,展示样式仅供参考,文档详见:</text>
        <u-link :href="'https://uniapp.dcloud.io/uni-app-x/component/'"
          :text="'https://uniapp.dcloud.io/uni-app-x/component/'" :inWhiteList="true"></u-link>
      </view>
      <uni-collapse>
        <template v-for="item in list" :key="item.id">
          <uni-collapse-item :title="item.name" class="item">
            <view class="uni-navigate-item" :hover-class="page.enable == false ? '' : 'is--active'"
              v-for="(page, key) in item.pages" :key="key" @click="goDetailPage(page)">
              <text class="uni-navigate-text"
                :class="page.enable == false ? 'text-disabled' : ''">{{ page.name }}</text>
              <image :src="arrowRightIcon" class="uni-icon-size"></image>
            </view>
          </uni-collapse-item>
        </template>
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
      </uni-collapse>

      <text>---------------</text>
      <uni-collapse>
        <template v-for="menuItem in menu" :key="menuItem.id">
          <uni-collapse-item :title="menuItem.name" class="item">
            <view v-for="page in menuItem.pages" :key="page.path" class="uni-navigate-item" hover-class="is--active"
              @click="goPage(`/${page.path}`)">
              <text class="uni-navigate-text">{{
                page.style["navigationBarTitleText"]
              }}</text>
              <image :src="arrowRightIcon" class="uni-icon-size"></image>
            </view>
            <uni-collapse style="width: 100%" v-for="childMenu in menuItem.children" :key="childMenu.id">
              <uni-collapse-item :title="childMenu.name" class="item" style="margin-bottom: 0">
                <view class="uni-navigate-item" hover-class="is--active" v-for="childPage in childMenu.pages"
                  :key="childPage.path" @click="goPage(`/${childPage.path}`)">
                  <text class="uni-navigate-text">{{
                    childPage.style["navigationBarTitleText"]
                  }}</text>
                  <image :src="arrowRightIcon" class="uni-icon-size"></image>
                </view>
              </uni-collapse-item>
            </uni-collapse>
          </uni-collapse-item>
        </template>
51 52
      </uni-collapse>

53
      <!-- #ifdef UNI-APP-X && APP -->
54 55 56 57 58 59 60 61 62
      <uni-upgrade-center-app ref="upgradePopup" @show="upgradePopupShow" @close="upgradePopupClose" />
      <!-- #endif -->
    </view>
  <!-- #ifdef APP -->
  </scroll-view>
  <!-- #endif -->
</template>

<script lang="uts">
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
  import { pages } from '@/target-pages.json'

  type PagesJsonPageGroup = {
    id : string,
    name : string
  }

  type PagesJsonPage = {
    path : string,
    style : UTSJSONObject,
    group ?: PagesJsonPageGroup[] | null
  }

  type MenuItem = {
    id : string,
    name : string,
    children : MenuItem[],
    pages : PagesJsonPage[]
  }
  const menu : MenuItem[] = []
  const menuKeyMap = new Map<string, number>()
  // #ifdef APP-ANDROID
  const componentPages = JSON.parse<PagesJsonPage[]>(JSON.stringify(pages))!.filter((page : PagesJsonPage) : boolean => page.path.startsWith('pages/component') && page.group !== null)
  // #endif
  // #ifdef WEB || APP-IOS
  const componentPages = (pages as unknown as PagesJsonPage[]).filter(page => page.path.startsWith('pages/component') && page.group)
  // #endif
  componentPages.forEach(page => {
    let currentArr : MenuItem[] = menu
    let currentMenu : MenuItem | null = null
    if (page.group !== null) {
      page.group!.forEach((item, index) => {
        const { id, name } = item
        const ids = id.split('.')
        const _id = ids[ids.length - 1]
        if (!menuKeyMap.has(id)) {
          menuKeyMap.set(id, currentArr.length)
          currentArr.push({
            id: _id,
            name,
            children: [] as MenuItem[],
            pages: [] as PagesJsonPage[]
          } as MenuItem)
        }
        currentMenu = currentArr[menuKeyMap.get(id)!]
        if (index < page.group!.length - 1) {
          currentArr = currentArr[menuKeyMap.get(id)!].children as MenuItem[]
        }
      })
    }
    if (currentMenu !== null) {
      (currentMenu as MenuItem).pages.push(page)
    }
  })
  console.log('menu', menu)
118
  // #ifdef UNI-APP-X && APP
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
  import checkUpdate from '@/uni_modules/uni-upgrade-center-app/utils/check-update'
  // #endif

  type Page = {
    name : string
    enable ?: boolean
    url ?: string.PageURIString
  }
  type ListItem = {
    id : string
    name : string
    pages : Page[]
    url ?: string
    enable ?: boolean
  }
  export default {
    data() {
      return {
137
        menu: menu as MenuItem[],
138 139 140 141 142 143 144 145 146 147 148 149 150
        list: [
          {
            id: 'view',
            name: '视图容器',
            pages: [
              {
                name: 'view',
              },
              {
                name: 'scroll-view',
              },
              {
                name: 'swiper',
151 152 153 154 155 156 157 158
              },
              // #ifdef WEB
              {
                name: 'movable-view'
              },
              {
                name: 'cover-view'
              },
Anne_LXM's avatar
Anne_LXM 已提交
159
              // #endif
160 161 162 163 164 165 166 167
              {
                name: 'list-view',
              },
              {
                name: 'sticky-header',
              },
              {
                name: 'sticky-section',
168
              },
169
              // #ifdef APP
170 171 172 173 174
              {
                name: 'nested-scroll-header',
              },
              {
                name: 'nested-scroll-body',
175
              },
176
              // #endif
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209
            ] as Page[],
          },
          {
            id: 'content',
            name: '基础内容',
            pages: [
              {
                name: 'text',
              },
              {
                name: 'rich-text',
                enable: true,
              },
              {
                name: 'progress',
              },
            ] as Page[],
          },
          {
            id: 'form',
            name: '表单组件',
            pages: [
              {
                name: 'button',
              },
              {
                name: 'checkbox',
              },
              {
                name: 'form',
              },
              {
                name: 'input',
210 211 212 213 214 215 216 217 218 219 220
              },
              // #ifdef WEB
              {
                name: 'editor',
              },
              {
                name: 'label',
              },
              {
                name: 'picker',
              },
Anne_LXM's avatar
Anne_LXM 已提交
221
              // #endif
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266
              {
                name: 'picker-view',
              },
              {
                name: 'radio',
              },
              {
                name: 'slider',
              },
              {
                name: 'slider-100',
              },
              {
                name: 'switch',
              },
              {
                name: 'textarea',
              },
            ] as Page[],
          },
          {
            id: 'nav',
            name: '导航',
            pages: [{
              name: 'navigator',
              enable: true
            }] as Page[],
          },
          {
            id: 'media',
            name: '媒体组件',
            pages: [
              {
                name: 'image',
                enable: true,
              },
              {
                name: 'video',
                enable: true,
              },
              /* {
                name: 'animation-view',
                enable: false,
              }, */
            ] as Page[],
267 268
          },
          // #ifdef WEB
Anne_LXM's avatar
Anne_LXM 已提交
269 270 271 272 273 274 275 276
          {
            id: 'map',
            name: '地图',
            pages: [
              {
                name: 'map',
              }
            ] as Page[]
277
          },
278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293
          // #endif
          // #ifdef APP || WEB
          {
            id: 'canvas',
            name: '画布',
            pages: [
              {
                name: 'canvas',
                url: '/pages/component/canvas/canvas',
              },
              {
                name: 'ball',
                url: '/pages/component/canvas/ball',
              }
            ] as Page[]
          },
Anne_LXM's avatar
Anne_LXM 已提交
294
          // #endif
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341
          {
            id: 'web-view',
            name: '网页',
            pages: [
              {
                name: '网络网页',
                enable: true,
                url: '/pages/component/web-view/web-view',
              },
              {
                name: '本地网页',
                enable: true,
                url: '/pages/component/web-view-local/web-view-local',
              },
            ] as Page[],
          },
          {
            id: 'unicloud-db',
            name: 'unicloud-db',
            pages: [
              {
                name: '联系人',
                enable: true,
                url: '/pages/component/unicloud-db-contacts/list'
              },
              {
                name: 'mixinDatacom',
                enable: true,
                url: '/pages/component/mixin-datacom/mixin-datacom'
              }
            ] as Page[],
          },
          /*
            {
              id: 'ad',
              url: 'ad',
              name: 'AD组件',
              enable: false,
              pages: [] as Page[]
            }
            */
          {
            id: 'general-attr-event',
            name: '通用属性和事件',
            pages: [
              {
                name: '通用属性',
342
                url: '/pages/component/public-properties/public-properties',
343 344 345 346
                enable: true,
              },
              {
                name: '通用事件',
347
                url: '/pages/component/public-events/public-events',
348 349 350 351
                enable: true,
              },
              {
                name: 'touch事件',
352
                url: '/pages/component/public-events/touch-events',
353 354 355 356
                enable: true,
              },
              {
                name: 'Transition事件',
357
                url: '/pages/component/public-events/transition-events',
358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382
                enable: true,
              },
            ] as Page[],
          }
        ] as ListItem[],
        arrowUpIcon: '/static/icons/arrow-up.png' as string.ImageURIString,
        arrowDownIcon: '/static/icons/arrow-down.png' as string.ImageURIString,
        arrowRightIcon: '/static/icons/arrow-right.png' as string.ImageURIString,
        pageHiden: false
      }
    },
    methods: {
      goDetailPage(e : Page) {
        if (e.enable == false) {
          uni.showToast({
            title: '暂不支持',
            icon: 'none'
          })
          return
        }
        const url =
          e.url != null ? e.url! : `/pages/component/${e.name}/${e.name}`
        uni.navigateTo({
          url,
        })
383 384 385 386
      },
      goPage(url : string) {
        uni.navigateTo({ url })
      },
387
      // #ifdef UNI-APP-X && APP
388
      upgradePopupShow() {
389 390 391 392 393 394 395 396 397 398 399 400
        console.log('upgradePopup show');
        if (!this.pageHiden) {
          uni.hideTabBar()?.catch(_ => { })
        }
      }
      , upgradePopupClose() {
        console.log('upgradePopup close');
        uni.showTabBar()?.catch(_ => { })
      }
      // #endif
    },
    onReady() {
401
      // #ifdef UNI-APP-X && APP
402 403
      checkUpdate(this.$refs['upgradePopup'] as UniUpgradeCenterAppComponentPublicInstance)
      // #endif
404 405 406
    },
    onLoad() {
      // console.log("component page onLoad")
407 408
    },
    onShow() {
409
      // console.log("component page onShow")
410 411 412
      this.pageHiden = false
    },
    onHide() {
413
      // console.log("component page onHide")
414 415 416 417 418 419 420 421 422 423 424 425
      this.pageHiden = true
    },
    beforeUnmount() {
      uni.showTabBar()?.catch(_ => { })
    }
  }
</script>

<style>
  .item {
    margin-bottom: 12px;
  }
426
</style>