| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163 |
- <template lang="pug">
- .carousel-wrapper#carousel
- b-carousel(
- v-model="curIndex"
- :arrow="false"
- :pause-hover="false"
- :indicator="list.length > 1"
- indicator-style="is-lines"
- @change="onChange"
- )
- b-carousel-item(
- v-for="(item, idx) in list"
- :key="idx"
- )
- .pic(
- :class="{clickable: item.jump_target && !item.button_text}"
- :style="{backgroundImage: `url('${item.image_url}')`, backgroundColor: item.theme_color || 'transparent'}"
- @click="onClick(item, false)"
- )
- .container.is-content(v-if="item.title || item.desc" :style="{textAlign: item.cont_position || 'left'}")
- .text-content
- .title {{item.title}}
- .desc {{item.desc}}
- .button.is-primary.is-inverted.is-outlined(
- v-if="item.button_text"
- @click.stop.prevent="onClick(item, true)"
- ) {{item.button_text}}
- </template>
- <script lang="ts">
- import Vue from 'vue'
- const insertOrUpdateStyleTag = (item) => {
- const id = `carousel-style`
- const css = `.kaifain-view .carousel {background: ${item && item.theme_color || '#eee'}} .kaifain-view .carousel .carousel-item .text-content .button.is-primary:hover{color:${item && item.theme_color || '#20242d'}}`
- let dom = document.getElementById(id)
- if (!dom) {
- const wrapper = document.querySelector('#carousel')
- if (wrapper) {
- dom = document.createElement('style')
- dom.id = id
- dom.innerHTML = css
- wrapper.appendChild(dom)
- }
- } else {
- dom.innerHTML = css
- }
- }
- let lastClickedAt = 0
- export default Vue.extend({
- name: 'Carousel',
- components: {
- },
- props: {
- list: Array
- },
- data() {
- return {
- curIndex: 1
- }
- },
- methods: {
- onClick(item: any, isButton: boolean) {
- if (!isButton && item.button_text || !item.jump_target || Date.now() - lastClickedAt < 300) {
- return false
- }
- const win = window.open(item.jump_target, '_blank')
- if (win) {
- lastClickedAt = Date.now()
- }
- },
- onChange(idx: number) {
- const item = this.list[idx]
- item && insertOrUpdateStyleTag(item)
- }
- }
- })
- </script>
- <style lang="scss">
- .kaifain-view .carousel {
- width: 100%;
- height: 400px;
- background: #eee;
- .carousel-indicator {
- margin-bottom: 16px;
- .indicator-item {
- .indicator-style.is-lines {
- width: 48px;
- height: 4px;
- opacity: 0.2;
- }
- &.is-active .indicator-style {
- opacity: 0.8;
- }
- }
- }
- .carousel-item {
- width: 100%;
- height: 400px;
- .pic {
- background-position: center center;
- background-repeat: no-repeat;
- background-size: auto 100%;
- position: absolute;
- top: 0;
- left: 0;
- width: 100%;
- height: 100%;
- &.clickable {
- cursor: pointer;
- }
- }
- .text-content {
- position: relative;
- z-index: 1;
- margin-top: 140px;
- > * {
- color: #fff;
- }
- .desc {
- opacity: 0.76;
- }
- .button {
- margin-top: 44px;
- min-width: 128px;
- height: 2.572em;
- &.is-primary {
- font-size: 0.875rem;
- &:hover {
- color: #2487ff;
- }
- }
- }
- }
- }
- }
- </style>
|