template.uvue 8.7 KB
Newer Older
DCloud_JSON's avatar
DCloud_JSON 已提交
1
<template>
DCloud-WZF's avatar
DCloud-WZF 已提交
2
  <!-- #ifdef APP -->
3
  <scroll-view style="flex: 1;" enable-back-to-top="true">
W
wanganxp 已提交
4
  <!-- #endif -->
DCloud-WZF's avatar
DCloud-WZF 已提交
5
    <view class="uni-container">
6
      <view v-if="!hasLeftWin" class="uni-header-logo">
DCloud-WZF's avatar
DCloud-WZF 已提交
7
        <image class="uni-header-image" src="/static/templateIndex.png"></image>
DCloud-WZF's avatar
DCloud-WZF 已提交
8
      </view>
9
      <view v-if="!hasLeftWin" class="uni-text-box">
DCloud-WZF's avatar
DCloud-WZF 已提交
10
        <text class="hello-text">以下是部分模板示例,更多模板见插件市场:</text>
W
wanganxp 已提交
11
        <u-link href="https://ext.dcloud.net.cn" :text="'https://ext.dcloud.net.cn'" :inWhiteList="true"></u-link>
DCloud-WZF's avatar
DCloud-WZF 已提交
12 13
      </view>
      <view class="uni-panel" v-for="(item, index) in list" :key="item.id">
14
        <view class="uni-panel-h" @click="triggerCollapse(index, item)">
DCloud-WZF's avatar
DCloud-WZF 已提交
15 16
          <text class="uni-panel-text"
            :class="item.enable == false || item.open == true ? 'text-disabled' : '',item.url == leftWinActive && item.pages.length == 0 ? 'left-win-active' : ''">{{ item.name }}</text>
W
wanganxp 已提交
17
          <image :src="
DCloud-WZF's avatar
DCloud-WZF 已提交
18 19 20 21 22
              item.pages.length > 0
                ? item.open
                  ? arrowUpIcon
                  : arrowDownIcon
                : arrowRightIcon
23
            " class="uni-icon-size">
DCloud-WZF's avatar
DCloud-WZF 已提交
24 25
          </image>
        </view>
A
Anne_LXM 已提交
26
        <view v-if="item.open">
DCloud-WZF's avatar
DCloud-WZF 已提交
27 28 29 30 31
          <view style="padding-left: 18px;" 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="{'left-win-active': leftWinActive === page.url  && hasLeftWin,'text-disabled' : page.enable == false}">{{ page.name }}</text>
32
            <image :src="arrowRightIcon" class="uni-icon-size"></image>
DCloud-WZF's avatar
DCloud-WZF 已提交
33
          </view>
DCloud-WZF's avatar
DCloud-WZF 已提交
34 35 36
        </view>
      </view>
    </view>
W
wanganxp 已提交
37
  <!-- #ifdef APP -->
DCloud-WZF's avatar
DCloud-WZF 已提交
38
  </scroll-view>
DCloud-WZF's avatar
DCloud-WZF 已提交
39
  <!-- #endif -->
DCloud_JSON's avatar
DCloud_JSON 已提交
40 41
</template>

Y
yurj26 已提交
42
<script lang="uts">
W
wanganxp 已提交
43 44 45 46 47
  type Page = {
    name : string
    enable ?: boolean
    url : string
  }
DCloud_JSON's avatar
DCloud_JSON 已提交
48

W
wanganxp 已提交
49 50 51 52 53 54 55
  type ListItem = {
    id : string
    name : string
    open : boolean
    pages : Page[]
    url ?: string
    enable ?: boolean
DCloud-WZF's avatar
DCloud-WZF 已提交
56
  }
57
  import { state } from '@/store/index.uts'
W
wanganxp 已提交
58 59 60
  export default {
    data() {
      return {
DCloud-WZF's avatar
DCloud-WZF 已提交
61 62 63 64 65 66 67
        list: [
          {
            id: 'slider-100',
            url: 'slider-100',
            name: 'slider-100',
            open: false,
            pages: [] as Page[],
W
wanganxp 已提交
68
          },
W
wanganxp 已提交
69 70 71 72 73 74 75 76
          {
            id: 'long-list',
            url: 'long-list',
            name: '左右滑动长列表',
            open: false,
            enable: true,
            pages: [
              {
77
                name: 'Android顶部搜索框随时下移长列表',
W
wanganxp 已提交
78
                url: 'long-list'
79
              },
80
              // #ifdef WEB
W
wanganxp 已提交
81
              {
82
                name: '顶部banner长列表(嵌套滚动)',
W
wanganxp 已提交
83
                url: 'long-list2'
84 85
              },
              // #endif
86
              // #ifdef APP-IOS || APP-ANDROID
87
              {
88
                name: '顶部banner长列表(嵌套滚动)',
89 90
                url: 'long-list-nested'
              },
DCloud_iOS_XHY's avatar
DCloud_iOS_XHY 已提交
91
              // #endif
W
wanganxp 已提交
92
            ] as Page[],
93
          },
W
wanganxp 已提交
94 95 96
          {
            id: 'list-news',
            url: 'list-news',
97
            name: '列表到详情(吸顶)',
W
wanganxp 已提交
98 99
            open: false,
            pages: [] as Page[],
雪洛's avatar
雪洛 已提交
100
          },
W
wanganxp 已提交
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
          {
            id: 'swiper-list',
            url: 'swiper-list',
            name: 'swiper-list',
            open: false,
            pages: [
              {
                name: '下划线样式',
                url: 'swiper-list'
              },
              {
                name: '字体放大样式',
                url: 'swiper-list2'
              },
            ] as Page[],
116
          },
117 118 119
          {
            id: 'custom-long-list',
            url: 'custom-long-list',
W
wanganxp 已提交
120
            name: '自定义虚拟长列表uni-recycle-view',
121 122
            open: false,
            pages: [] as Page[],
123 124 125 126 127 128 129
          },
          {
            id: 'scroll-fold-nav',
            url: 'scroll-fold-nav',
            name: '随滚动折叠的导航栏',
            open: false,
            pages: [] as Page[],
130 131
          },
          // #ifdef APP
W
wanganxp 已提交
132 133 134 135 136 137
          {
            id: 'custom-refresher',
            url: 'custom-refresher',
            name: '自定义下拉刷新',
            open: false,
            pages: [] as Page[],
138 139 140 141 142 143 144
          },
          {
            id: 'pull-zoom-image',
            url: 'pull-zoom-image',
            name: '下拉缩放顶部封面图',
            open: false,
            pages: [] as Page[],
145 146 147 148 149 150 151
          },
          {
            id: 'scroll-sticky',
            url: 'scroll-sticky',
            name: 'scroll-view自定义滚动吸顶',
            open: false,
            pages: [] as Page[],
152
          },
W
wanganxp 已提交
153
          // #endif
W
wanganxp 已提交
154 155 156 157 158 159
          {
            id: 'swiper-vertical-video',
            url: 'swiper-vertical-video',
            name: '竖滑视频',
            open: false,
            pages: [] as Page[],
160
          },
DCloud-yyl's avatar
DCloud-yyl 已提交
161 162 163 164 165 166 167
          {
            id: 'half-screen',
            url: 'half-screen',
            name: '半屏弹窗',
            open: false,
            pages: [] as Page[],
          },
W
wanganxp 已提交
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188
          {
            id: 'drop-card',
            url: 'drop-card',
            name: '划走式卡片',
            open: false,
            pages: [] as Page[],
          },
          {
            id: 'navbar-lite',
            url: 'navbar-lite',
            name: '自定义导航栏',
            open: false,
            pages: [] as Page[],
          },
          {
            id: 'custom-tab-bar',
            url: 'custom-tab-bar',
            name: '自定义TabBar',
            open: false,
            enable: true,
            pages: [] as Page[],
189
          },
W
wanganxp 已提交
190
          // #ifdef APP
W
wanganxp 已提交
191 192 193 194 195 196
          {
            id: 'calendar',
            url: 'calendar',
            name: '日历',
            open: false,
            pages: [] as Page[],
197
          },
198 199
          // #endif
          // #ifdef APP || WEB
200
          {
W
wanganxp 已提交
201 202 203 204 205
            id: 'schema',
            url: 'schema',
            name: '打开外部链接',
            open: false,
            pages: [] as Page[],
206 207
          },
          // #endif
208 209
          // #ifdef WEB
          {
210 211 212
            id: 'browser-element',
            url: 'browser-element',
            name: '如何使用浏览器 element',
213 214 215
            open: false,
            pages: [] as Page[],
          },
Anne_LXM's avatar
Anne_LXM 已提交
216 217 218 219 220 221 222 223 224
          // #endif
          // #ifdef MP
          {
            id: 'vant-button',
            url: 'vant-button',
            name: '微信自定义组件示例',
            open: false,
            pages: [] as Page[],
          },
W
wanganxp 已提交
225
          // #endif
W
wanganxp 已提交
226 227 228 229
        ] as ListItem[],
        arrowUpIcon: '/static/icons/arrow-up.png',
        arrowDownIcon: '/static/icons/arrow-down.png',
        arrowRightIcon: '/static/icons/arrow-right.png',
DCloud-WZF's avatar
DCloud-WZF 已提交
230
      }
DCloud-WZF's avatar
DCloud-WZF 已提交
231 232 233 234 235 236 237 238
    },
    computed: {
      hasLeftWin() : boolean {
        return !state.noMatchLeftWindow
      },
      leftWinActive() : string {
        return state.leftWinActive.split('/')[3]
      }
DCloud-WZF's avatar
DCloud-WZF 已提交
239
    },
W
wanganxp 已提交
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 267 268 269
    methods: {
      triggerCollapse(index : number, item : ListItem) {
        if (item.pages.length == 0) {
          const page : Page = {
            name: item.name,
            enable: item.enable,
            url: item.url!,
          }
          this.goDetailPage(page)
          return
        }
        for (var i = 0; i < this.list.length; ++i) {
          if (index == i) {
            this.list[i].open = !this.list[i].open
          } else {
            this.list[i].open = false
          }
        }
      },
      goDetailPage(e : Page) {
        if (e.enable == false) {
          uni.showToast({
            icon: 'none',
            title: '暂不支持',
          })
          return
        }
        const url =
          e.url.indexOf('platform') > -1
            ? e.url
DCloud-WZF's avatar
DCloud-WZF 已提交
270 271 272 273 274
            : `/pages/template/${e.url}/${e.url}`
        if (this.hasLeftWin) {
          uni.reLaunch({ url })
        } else {
          uni.navigateTo({ url })
275
        }
W
wanganxp 已提交
276
      },
DCloud-WZF's avatar
DCloud-WZF 已提交
277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297
    },
    // #ifdef WEB
    watch: {
      $route: {
        immediate: true,
        handler(newRoute) {
          if (newRoute.matched.length) {
            let path = newRoute.path.split('/')[3]
            for (const item of this.list) {
              if (Array.isArray(item.pages)) {
                for (const page of item.pages) {
                  if (page.url && page.url === path) {
                    item.open = true
                  }
                }
              }
            }
          }
        }
      }
    },
298
    // #endif
W
wanganxp 已提交
299
  }
300
</script>