toutiao.vue 5.8 KB
Newer Older
T
tank0317 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
<template>
  <cube-page type="scroll-view" title="Scroll" class="toutiao">
    <template slot="content">
      <header ref="topHeader"><img src="http://om0jxp12h.bkt.clouddn.com/toutiao_header2.png"></header>
      <div class="nav-scroll-list-wrap">
        <cube-scroll ref="navScroll" direction="horizontal">
          <ul class="nav-wrapper">
            <li v-for="(item, index) in navTxts" :key="index" class="nav-item">{{ item }}</li>
          </ul>
        </cube-scroll>
        <div class="more-wrapper">
          <span class="more"></span>
        </div>
      </div>
      <div class="content-scroll-wrapper">
        <div class="content-scroll-list-wrap" ref="scrollWrapper">
          <cube-scroll
            ref="contentScroll"
            :data="content"
T
tank0317 已提交
20
            :options="options"
T
tank0317 已提交
21 22 23 24
            @pulling-down="onPullingDown"
            @pulling-up="onPullingUp">
            <ul class="imgs-wrapper">
              <li v-for="(item, index) in content" :key="index" class="imgs-item">
25
                <img :src="item.url" @load="onImgLoad">
T
tank0317 已提交
26 27 28
              </li>
            </ul>
            <template slot="pulldown" slot-scope="props">
T
tank0317 已提交
29 30 31 32 33 34 35
              <div v-if="props.pullDownRefresh"
                class="cube-pulldown-wrapper"
                :style="props.pullDownStyle">
                <div v-if="props.beforePullDown"
                  class="before-trigger"
                  :style="{paddingTop: props.bubbleY + 'px'}">
                  <span :class="{rotate: props.bubbleY > 0}">↓</span>
T
tank0317 已提交
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
                </div>
                <div class="after-trigger" v-else>
                  <div v-show="props.isPullingDown" class="loading">
                    <cube-loading></cube-loading>
                  </div>
                  <transition name="success">
                    <div v-show="!props.isPullingDown" class="text-wrapper"><span class="refresh-text">今日头条推荐引擎有x条更新</span></div>
                  </transition>
                </div>
              </div>
            </template>
          </cube-scroll>
        </div>
      </div>
      <footer ref="footer"><img src="http://om0jxp12h.bkt.clouddn.com/toutiao_footer2.png"></footer>
    </template>
  </cube-page>
</template>

<script type="text/ecmascript-6">
import CubePage from '../../components/cube-page.vue'

const imgs = [
  {
    url: 'http://om0jxp12h.bkt.clouddn.com/toutiao_12.JPG'
  },
  {
    url: 'http://om0jxp12h.bkt.clouddn.com/toutiao_21.JPG'
  },
  {
    url: 'http://om0jxp12h.bkt.clouddn.com/toutiao_31.JPG'
  }
]

const txts = ['关注', '推荐', '新时代', '热点', '体育', '娱乐', '科技', '头条号', '问答', '国际', 'cube-ui666']

let cnt = 1
export default {
  data() {
    return {
      content: imgs.slice(),
T
tank0317 已提交
77
      options: {
T
tank0317 已提交
78 79
        pullDownRefresh: {
          threshold: 60,
80
          // stop: 44,
T
tank0317 已提交
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
          stopTime: 1000,
          txt: '更新成功'
        },
        pullUpLoad: true
      },
      navTxts: txts,
      secondStop: 26
    }
  },
  components: {
    CubePage
  },
  methods: {
    onPullingDown() {
      setTimeout(() => {
        this.content.unshift(imgs[cnt++ % 3])
        this.$refs.contentScroll.scrollTo(0, this.secondStop, 300)
      }, 1000)
    },
    onPullingUp() {
      setTimeout(() => {
        this.content = this.content.concat(imgs)
      }, 1000)
104 105
    },
    onImgLoad() {
F
fengweiyao 已提交
106 107
      const contentScroll = this.$refs.contentScroll
      contentScroll.scroll.beforePullDown && contentScroll.refresh()
T
tank0317 已提交
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 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 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183
    }
  },
  mounted() {
  }
}
</script>

<style lang="stylus" rel="stylesheet/stylus">
.toutiao
  .content
    margin: 0 !important
    height: 100%
    display: flex
    flex-flow: column
    >header
      line-height: 0
      img 
        width: 100%
    footer
      line-height: 0
      img
        width: 100%
  .nav-scroll-list-wrap
    transform: rotate(0deg) // fix 子元素超出边框圆角部分不隐藏的问题
    position: relative
    background-color: white
    border-bottom : 1px solid rgba(0, 0, 0, 0.1)
    padding-right: 30px
    .cube-scroll-content
      display: inline-block
      .nav-wrapper
        display: inline-block
        white-space: nowrap
        line-height: 36px
        padding: 0 5px
        .nav-item
          display: inline-block
          padding: 0 5px
          &:nth-child(2)
            color: #fa7b7a
    .more-wrapper
      position: absolute
      right: 0
      top: 0
      bottom: 0
      z-index: 1
      background-color: #fff
      opacity: 0.95
      .more
        display: inline-block
        height: 1px
        width: 20px
        padding: 5px 0
        border: 1px solid #000
        border-right: transparent
        border-left: transparent
        background-color: #000
        background-clip: content-box
        margin: 11px
  .content-scroll-wrapper
    flex: 1
    position: relative
    .content-scroll-list-wrap
      height: 100%
      transform: rotate(0deg) // fix 子元素超出边框圆角部分不隐藏的问题
      position: absolute
      top: 0
      bottom: 0
      overflow: hidden
      .imgs-wrapper
        .imgs-item
          >img 
            width: 100%
  .cube-pulldown-wrapper
    text-align: center
    .before-trigger
T
tank0317 已提交
184
      height: auto
T
tank0317 已提交
185 186
      font-size: 30px
      align-self: flex-end
187
      span
T
tank0317 已提交
188
        display: inline-block
T
tank0317 已提交
189
        line-height: 1
T
tank0317 已提交
190 191
        transition: all 0.3s
        color: #666
192
        padding: 15px 0
T
tank0317 已提交
193 194 195 196 197 198
        &.rotate 
          transform: rotate(180deg)
    .after-trigger
      flex: 1
      margin: 0
      .text-wrapper
199 200
        margin: 0 auto
        margin-top: 14px
T
tank0317 已提交
201 202 203 204 205 206 207 208 209 210 211 212
        padding: 5px 0
        color: #498ec2
        background-color: #d6eaf8
      .cube-loading-spinners
        margin: auto
  .success-enter-active, .success-leave-active
    transition: width .5s
  .success-enter, .success-leave-to
    width: 70%
  .success-enter-to, .success-leave
    width: 100%
</style>