slide.vue 5.5 KB
Newer Older
M
init  
miaodian 已提交
1
<template>
2
  <cube-page type="slide-view" title="Slide" class="option-demo">
M
init  
miaodian 已提交
3 4
    <div slot="content">
      <div ref="slideWrapper" class="slide-container">
F
funanamy 已提交
5 6 7
        <cube-slide
          v-if="ifSlide"
          ref="slide"
D
dolymood 已提交
8
          :initial-index="initialIndex"
F
funanamy 已提交
9 10 11 12 13 14
          :loop="loop"
          :auto-play="autoPlay"
          :interval="interval"
          :threshold="threshold"
          :speed="speed"
          @change="changePage">
M
init  
miaodian 已提交
15 16 17 18 19
          <cube-slide-item v-for="(item, index) in items" :key="index" @click.native="clickHandler(item, index)">
            <a :href="item.url">
              <img :src="item.image">
            </a>
          </cube-slide-item>
D
dolymood 已提交
20 21 22
          <template v-if="dotsSlot" slot="dots" slot-scope="props">
            <span class="my-dot" :class="{active: props.current === index}" v-for="(item, index) in props.dots">{{index + 1}}</span>
          </template>
M
init  
miaodian 已提交
23 24
        </cube-slide>
      </div>
F
funanamy 已提交
25 26
      <div class="options">
        <div class="option-list">
D
dolymood 已提交
27 28 29 30
          <div class="group">
            <input-option class="item" name="InitialIndex" :value="initialIndex"
                           @update:value="updateInitialIndex"></input-option>
          </div>
F
funanamy 已提交
31 32 33 34
          <div class="group">
            <switch-option class="item" name="Loop" :value="loop"
                           @update:value="updateLoop"></switch-option>
          </div>
F
funanamy 已提交
35 36 37 38 39 40 41 42 43 44 45 46 47 48
          <div class="group">
            <switch-option class="item" name="Auto Play" :value="autoPlay"
                           @update:value="updateAutoPlay"></switch-option>
            <input-option v-if="autoPlay" class="item sub first last" name="interval" :value="interval"
                           @update:value="updateInterval"></input-option>
          </div>
          <div class="group">
            <input-option class="item" name="Threshold" :value="threshold"
                           @update:value="updateThreshold"></input-option>
          </div>
          <div class="group">
            <input-option class="item" name="Speed" :value="speed"
                           @update:value="updateSpeed"></input-option>
          </div>
D
dolymood 已提交
49 50 51 52 53 54 55 56
          <div class="group">
            <switch-option class="item" name="Add Slide Item3" :value="addItem3"
                           @update:value="updateItem3"></switch-option>
          </div>
          <div class="group">
            <switch-option class="item" name="Dots Slot" :value="dotsSlot"
                           @update:value="updateDotsSlot"></switch-option>
          </div>
F
funanamy 已提交
57 58
        </div>
      </div>
M
init  
miaodian 已提交
59 60 61
    </div>
  </cube-page>
</template>
62

M
init  
miaodian 已提交
63 64
<script type="text/ecmascript-6">
  import CubePage from '../components/cube-page.vue'
A
AmyFoxFN 已提交
65 66
  import SwitchOption from '../components/switch-option'
  import InputOption from '../components/input-option'
M
init  
miaodian 已提交
67

D
dolymood 已提交
68 69 70 71
  const item3 = {
    url: 'http://www.didichuxing.com/',
    image: '//webapp.didistatic.com/static/webapp/shield/cube-ui-examples-slide03.png'
  }
M
init  
miaodian 已提交
72 73 74 75 76 77 78 79 80 81 82
  export default{
    data() {
      return {
        items: [
          {
            url: 'http://www.didichuxing.com/',
            image: '//webapp.didistatic.com/static/webapp/shield/cube-ui-examples-slide01.png'
          }, {
            url: 'http://www.didichuxing.com/',
            image: '//webapp.didistatic.com/static/webapp/shield/cube-ui-examples-slide02.png'
          }
83
        ],
F
funanamy 已提交
84
        ifSlide: true,
85
        loop: true,
F
funanamy 已提交
86 87 88
        autoPlay: true,
        interval: 4000,
        threshold: 0.3,
D
dolymood 已提交
89 90 91 92
        speed: 400,
        initialIndex: 1,
        dotsSlot: false,
        addItem3: false
93 94 95 96 97
      }
    },
    watch: {
      loop() {
        this.rebuildSlide()
F
funanamy 已提交
98
      },
D
dolymood 已提交
99 100 101
      dotsSlot() {
        this.rebuildSlide()
      },
F
funanamy 已提交
102 103 104 105 106 107 108 109 110 111 112
      autoPlay() {
        this.rebuildSlide()
      },
      interval() {
        this.rebuildSlide()
      },
      threshold() {
        this.rebuildSlide()
      },
      speed() {
        this.rebuildSlide()
D
dolymood 已提交
113 114 115 116 117 118 119 120
      },
      addItem3(newV) {
        if (newV) {
          this.items.push(item3)
        } else {
          this.items.pop()
        }
        this.rebuildSlide()
M
init  
miaodian 已提交
121 122 123 124 125 126 127 128
      }
    },
    methods: {
      changePage(current) {
        console.log('当前轮播图序号为:' + current)
      },
      clickHandler(item, index) {
        console.log(item, index)
129 130
      },
      rebuildSlide() {
D
dolymood 已提交
131 132 133 134 135
        this.$refs.slide.refresh()
        // this.ifSlide = false
        // this.$nextTick(() => {
        //   this.ifSlide = true
        // })
136
      },
D
dolymood 已提交
137 138 139
      updateItem3(val) {
        this.addItem3 = val
      },
140 141
      updateLoop(val) {
        this.loop = val
F
funanamy 已提交
142
      },
D
dolymood 已提交
143 144 145
      updateDotsSlot(val) {
        this.dotsSlot = val
      },
F
funanamy 已提交
146 147 148 149
      updateAutoPlay(val) {
        this.autoPlay = val
      },
      updateInterval(val) {
D
dolymood 已提交
150 151 152 153
        val = +val
        if (val) {
          this.interval = val
        }
F
funanamy 已提交
154 155
      },
      updateThreshold(val) {
D
dolymood 已提交
156 157 158 159
        val = +val
        if (val) {
          this.threshold = val
        }
F
funanamy 已提交
160 161
      },
      updateSpeed(val) {
D
dolymood 已提交
162 163 164 165 166 167 168 169 170
        val = +val
        if (val) {
          this.speed = val
        }
      },
      updateInitialIndex(val) {
        if (val) {
          this.initialIndex = +val
        }
M
init  
miaodian 已提交
171 172 173
      }
    },
    components: {
174 175
      CubePage,
      SwitchOption,
F
funanamy 已提交
176
      InputOption
M
init  
miaodian 已提交
177 178 179
    }
  }
</script>
180 181 182

<style lang="stylus" rel="stylesheet/stylus">
  .slide-container
F
funanamy 已提交
183 184
    height: 64px
    margin-bottom: 15px
185 186 187 188
    transform: translateZ(0px)
    border-radius: 2px
    overflow: hidden
    box-shadow: 0 2px 9px #ddd
D
dolymood 已提交
189 190 191 192 193 194 195
    .cube-slide-dots
      .my-dot
        height: auto
        font-size: 12px
        background: none
        &.active
          color: #fc9153
196
</style>