CSS.uvue 14.9 KB
Newer Older
M
mehaotian 已提交
1
<template>
W
wanganxp 已提交
2
  <!-- #ifdef APP -->
3
  <scroll-view style="flex: 1; background-color: #f8f8f8" enable-back-to-top="true">
4
  <!-- #endif -->
W
wanganxp 已提交
5 6 7 8
    <view class="uni-container">
      <view class="uni-header-logo">
        <image class="uni-header-image" src="/static/cssIndex.png"></image>
      </view>
Y
yurj26 已提交
9
      <view class="uni-text-box">
W
wanganxp 已提交
10
        <text class="hello-text">uni-app x目前已支持的CSS属性,展示样式仅供参考,文档详见:</text>
W
wanganxp 已提交
11
        <u-link :href="'https://uniapp.dcloud.io/uni-app-x/css/'" :text="'https://uniapp.dcloud.io/uni-app-x/css/'"
W
wanganxp 已提交
12 13 14 15 16
          :inWhiteList="true"></u-link>
      </view>
      <uni-collapse>
        <template v-for="item in list" :key="item.id">
          <uni-collapse-item :title="item.name" class="item">
17
            <view class="uni-navigate-item" :hover-class="page.enable == false ? '' : 'is--active'"
W
wanganxp 已提交
18 19 20
              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>
21
              <image :src="arrowRightIcon" class="uni-icon-size"></image>
W
wanganxp 已提交
22 23 24 25
            </view>
          </uni-collapse-item>
        </template>
      </uni-collapse>
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 51

      <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>
      </uni-collapse>
W
wanganxp 已提交
52
    </view>
53
  <!-- #ifdef APP -->
W
wanganxp 已提交
54 55
  </scroll-view>
  <!-- #endif -->
M
mehaotian 已提交
56 57
</template>

Y
yurj26 已提交
58
<script lang="uts">
59 60 61 62 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
  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 cssPages = JSON.parse<PagesJsonPage[]>(JSON.stringify(pages))!.filter((page : PagesJsonPage) : boolean => page.path.startsWith('pages/CSS') && page.group !== null)
  // #endif
  // #ifdef WEB || APP-IOS
  const cssPages = (pages as unknown as PagesJsonPage[]).filter(page => page.path.startsWith('pages/CSS') && page.group)
  // #endif
  cssPages.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)
    }
  })
W
wanganxp 已提交
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
  type Page = {
    name : string
    enable ?: boolean
    url ?: string
  }
  type ListItem = {
    id : string
    name : string
    pages : Page[]
    url ?: string
    enable ?: boolean
  }
  export default {
    data() {
      return {
128
        menu: menu as MenuItem[],
W
wanganxp 已提交
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
        list: [
          {
            id: 'background',
            name: 'background',
            pages: [
              {
                name: 'background-color',
                url: '/pages/CSS/background/background-color',
              },
              {
                name: 'background-image',
                url: '/pages/CSS/background/background-image',
              },
            ] as Page[],
          },
          {
            id: 'border',
            name: 'border',
            pages: [
              {
                name: 'border',
                url: '/pages/CSS/border/border',
              },
              {
                name: 'border-width',
                url: '/pages/CSS/border/border-width',
              },
              {
                name: 'border-style',
                url: '/pages/CSS/border/border-style',
              },
              {
                name: 'border-color',
                url: '/pages/CSS/border/border-color',
              },
              {
                name: 'border-radius',
                url: '/pages/CSS/border/border-radius',
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182
              },
              {
                name: 'border-top',
                url: '/pages/CSS/border/border-top',
              },
              {
                name: 'border-bottom',
                url: '/pages/CSS/border/border-bottom',
              },
              {
                name: 'border-left',
                url: '/pages/CSS/border/border-left',
              },
              {
                name: 'border-right',
                url: '/pages/CSS/border/border-right',
W
wanganxp 已提交
183 184 185 186
              },
              {
                name: 'border属性复合示例',
                url: '/pages/CSS/border/complex-border/complex-border',
187 188 189 190
              },
              {
                name: 'border动态修改样式',
                url: '/pages/CSS/border/dynamic-border'
W
wanganxp 已提交
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 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 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290
              },
            ] as Page[],
          },
          {
            id: 'box-shadow',
            name: 'box-shadow',
            pages: [
              {
                name: 'box-shadow',
                url: '/pages/CSS/box-shadow/box-shadow',
              },
            ] as Page[],
          },
          {
            id: 'display',
            name: 'display',
            pages: [
              {
                name: 'flex',
                url: '/pages/CSS/display/flex',
              },
              {
                name: 'none',
                url: '/pages/CSS/display/none',
              }
            ] as Page[],
          },
          {
            id: 'flex',
            name: 'flex',
            pages: [
              {
                name: 'align-content',
                url: '/pages/CSS/flex/align-content',
              },
              {
                name: 'align-items',
                url: '/pages/CSS/flex/align-items',
              },
              {
                name: 'flex-basis',
                url: '/pages/CSS/flex/flex-basis',
              },
              {
                name: 'flex-direction',
                url: '/pages/CSS/flex/flex-direction',
              },
              {
                name: 'flex-flow',
                url: '/pages/CSS/flex/flex-flow',
              },
              {
                name: 'flex-grow',
                url: '/pages/CSS/flex/flex-grow',
              },
              {
                name: 'flex-shrink',
                url: '/pages/CSS/flex/flex-shrink',
              },
              {
                name: 'flex',
                url: '/pages/CSS/flex/flex',
              },
              {
                name: 'justify-content',
                url: '/pages/CSS/flex/justify-content',
              },
            ] as Page[],
          },
          {
            id: 'layout',
            name: 'layout',
            pages: [
              {
                name: 'height',
                url: '/pages/CSS/layout/height',
              },
              {
                name: 'max-height',
                url: '/pages/CSS/layout/max-height',
              },
              {
                name: 'max-width',
                url: '/pages/CSS/layout/max-width',
              },
              {
                name: 'min-height',
                url: '/pages/CSS/layout/min-height',
              },
              {
                name: 'min-width',
                url: '/pages/CSS/layout/min-width',
              },
              {
                name: 'position',
                url: '/pages/CSS/layout/position',
              },
              {
                name: 'width',
                url: '/pages/CSS/layout/width',
291 292 293 294
              },
              {
                name: 'z-index',
                url: '/pages/CSS/layout/z-index',
W
wanganxp 已提交
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 342 343 344 345 346 347 348 349 350 351 352
              },
              {
                name: 'visibility',
                url: '/pages/CSS/layout/visibility',
              },
            ] as Page[],
          },
          {
            id: 'margin',
            name: 'margin',
            pages: [
              {
                name: 'margin-bottom',
                url: '/pages/CSS/margin/margin-bottom',
              },
              {
                name: 'margin-left',
                url: '/pages/CSS/margin/margin-left',
              },
              {
                name: 'margin-right',
                url: '/pages/CSS/margin/margin-right',
              },
              {
                name: 'margin-top',
                url: '/pages/CSS/margin/margin-top',
              },
              {
                name: 'margin',
                url: '/pages/CSS/margin/margin',
              },
            ] as Page[],
          },
          {
            id: 'padding',
            name: 'padding',
            pages: [
              {
                name: 'padding-bottom',
                url: '/pages/CSS/padding/padding-bottom',
              },
              {
                name: 'padding-left',
                url: '/pages/CSS/padding/padding-left',
              },
              {
                name: 'padding-right',
                url: '/pages/CSS/padding/padding-right',
              },
              {
                name: 'padding-top',
                url: '/pages/CSS/padding/padding-top',
              },
              {
                name: 'padding',
                url: '/pages/CSS/padding/padding',
              },
            ] as Page[],
353 354 355 356 357 358 359 360
          },
          {
            id: 'overflow',
            name: 'overflow',
            pages: [
              {
                name: 'overflow',
                url: '/pages/CSS/overflow/overflow',
361 362 363 364
              },
              {
                name: 'overflow-visible-event',
                url: '/pages/CSS/overflow/overflow-visible-event'
365
              }
366
            ] as Page[],
W
wanganxp 已提交
367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440
          },
          {
            id: 'text',
            name: 'text',
            pages: [
              {
                name: 'color',
                url: '/pages/CSS/text/color',
              },
              {
                name: 'font-family',
                url: '/pages/CSS/text/font-family',
              },
              {
                name: 'font-size',
                url: '/pages/CSS/text/font-size',
              },
              {
                name: 'font-style',
                url: '/pages/CSS/text/font-style',
              },
              {
                name: 'font-weight',
                url: '/pages/CSS/text/font-weight',
              },
              {
                name: 'letter-spacing',
                url: '/pages/CSS/text/letter-spacing',
              },
              {
                name: 'line-height',
                url: '/pages/CSS/text/line-height',
              },
              {
                name: 'text-align',
                url: '/pages/CSS/text/text-align',
              },
              {
                name: 'text-overflow',
                url: '/pages/CSS/text/text-overflow',
              },
              {
                name: 'text-decoration-line',
                url: '/pages/CSS/text/text-decoration-line',
              },
            ] as Page[],
          },
          {
            id: 'transform',
            name: 'transform',
            pages: [
              {
                name: 'translate',
                url: '/pages/CSS/transform/translate',
              },
              {
                name: 'scale',
                url: '/pages/CSS/transform/scale',
              },
              {
                name: 'rotate',
                url: '/pages/CSS/transform/rotate',
              },
            ] as Page[],
          },
          {
            id: 'transition',
            name: 'transition',
            pages: [
              {
                name: 'transition',
                url: '/pages/CSS/transition/transition',
              },
            ] as Page[],
441 442 443 444 445 446 447 448 449 450
          },
          {
            id: 'pointer-events',
            name: 'pointer-events',
            pages: [
              {
                name: 'pointer-events',
                url: '/pages/CSS/pointer-events/pointer-events',
              },
            ] as Page[],
451 452 453 454 455 456 457 458 459 460
          },
          {
            id: 'variable',
            name: 'variable',
            pages: [
              {
                name: 'variable',
                url: '/pages/CSS/variable/variable',
              },
            ] as Page[],
W
wanganxp 已提交
461
          }
W
wanganxp 已提交
462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481
        ] as ListItem[],
        arrowUpIcon: '/static/icons/arrow-up.png',
        arrowDownIcon: '/static/icons/arrow-down.png',
        arrowRightIcon: '/static/icons/arrow-right.png',
      }
    },
    methods: {
      goDetailPage(e : Page) {
        if (e.enable == false) {
          uni.showToast({
            icon: 'none',
            title: '暂不支持',
          })
          return
        }
        const url = e.url != null ? e.url! : `/pages/CSS/${e.name}/${e.name}`
        uni.navigateTo({
          url,
        })
      },
482 483 484
      goPage(url : string) {
        uni.navigateTo({ url })
      },
W
wanganxp 已提交
485 486
    },
  }
M
mehaotian 已提交
487 488 489
</script>

<style>
W
wanganxp 已提交
490 491 492
  .item {
    margin-bottom: 12px;
  }
Y
yurj26 已提交
493
</style>