MediaComponent.vue 2.48 KB
<template>
  <view class="layout">
    <view class="bg">
      <image :src="mediaBg" />
    </view>
    <view
      class="content"
      :style="{background:background}"
    >
      <view
        class="title"
        v-if="title"
      >{{title}}</view>
      <template v-if="views.length && views.length > 1">
        <tabs
          :list="views"
          @tabclick="changeView"
          ref="tabs"
        />
      </template>
      <view
        class="canvas-box"
        :style="canvasStyle"
      >
        <template v-for="(i,index) in views">
          <view
            :key="index"
            v-show="viewIndex == index"
            :class="['canvas-view', `${viewIndex == 0 ? 'left' : 'right'}`]"
          >
            <wnCanvas
              :drawImage="i.detailUrl"
              :drawStatus="penSwitch"
              :canvasId="`c-${madiaId}-${index}`"
            ></wnCanvas>
          </view>
        </template>
      </view>
    </view>
  </view>
</template>

<script type='text/ecmascript-6'>
import Tabs from './Tabs.vue'
export default {
  components: { Tabs },
  props: {
    views: Array,
    penSwitch: Boolean,
    title: String,
    madiaId: Number,
    mediaBg: String,
    background: String,
    defaultIndex: {
      type: Number,
      default: 0
    },
    canvasStyle: String
  },
  name: 'MediaComponent',
  data () {
    return {
      viewIndex: 0
    }
  },
  watch: {
    watchStatus: {
      immediate: true,
      handler (newval) {
        this.$refs?.tabs?.tabClick(this.defaultIndex)
      }
    },
  },
  computed: {
    watchStatus () {
      return this.$store.state.user.historyStatus
    },
  },
  mounted () {
    this.$refs?.tabs?.tabClick(this.defaultIndex)
  },
  methods: {
    changeView (index) {
      this.viewIndex = index
    },
  }
}
</script>

<style scoped lang='scss'>
.layout {
  padding-top: 192rpx;
  position: relative;
  .bg {
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    height: 240rpx;
    image {
      width: 100%;
      height: 100%;
    }
  }
  .content {
    border-radius: 40rpx 40rpx 0 0;
    background: linear-gradient(180deg, #f7f9fc 0%, #f7f9fc 100%);
    overflow: hidden;
    position: relative;
    z-index: 1;
    .title {
      font-size: 40rpx;
      line-height: 48rpx;
      color: #1a1a1a;
      padding: 32rpx 0;
      text-align: center;
    }
  }
  .canvas-box {
    padding-top: 6rpx;
    .left {
      animation: show-view-left 0.3s;
    }
    .right {
      animation: show-view-right 0.3s;
    }
  }
}
</style>