1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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
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
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
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
| <template>
| <el-card
| class="my-card"
| shadow="never"
| :style="`height:${outHeight};width:${outWidth};max-height:160px;min-height:135px`"
| :body-style="`height:${height};width:${width};`"
| >
| <el-carousel
| ref="carousel"
| :autoplay="false"
| indicator-position="none"
| :arrow="data.list.length > 1 ? 'always' : 'never'"
| @change="changeHandle"
| >
| <el-carousel-item v-for="(item, index) in data.list" :key="index">
| <card-item
| :data="item"
| :showType="showType"
| @detailsClick="detailsClick"
| @addToBase="toAdd"
| ></card-item>
| </el-carousel-item>
| </el-carousel>
| </el-card>
| </template>
|
| <script>
| import CardItem from "./CardItem";
| export default {
| components: {
| CardItem
| },
| props: {
| data: {
| type: Object,
| default: null
| },
| showType: {
| type: String,
| default: ""
| },
| height: {
| type: String,
| default: "100%"
| },
| width: {
| type: String,
| default: "100%"
| },
| outHeight: {
| type: String,
| default: "100%"
| },
| outWidth: {
| type: String,
| default: "100%"
| }
| },
| watch: {
|
| },
| data() {
| return {
| items: [],
| filled: false
| }
| },
| watch: {
| data(newVal) {
| this.len = this.data.list.length;
| if (this.len > 3) {
| this.data.list = this.data.list.slice(0, 3)
| }
| }
| },
| methods: {
| detailsClick(ev) {
| this.$emit("detailsClick", ev);
| },
| toAdd(item) {
| this.$emit("addToBase", item);
| },
| changeHandle(e) {
| // 点击切换时, 会触发该事件, 此时重新填充全部数据, 组件会重新渲染, DOM更新后根据点击的按钮,手动切换
| // filled 控制只在第一次点击时触发.然后不再干预跑马灯切换
| if (this.len > 3 && !this.filled) {
| this.items = this.data.list
| this.filled = true
|
| this.$nextTick(() => {
| if (e == 1) { // 点击了下一张
| this.$refs.carousel.next()
| }
| if (e == 2) { // 点击了上一张
| this.$refs.carousel.prev()
| }
| })
| }
| }
| }
| };
| </script>
| <style lang="scss">
| .my-active-card {
| border: 2px solid #ff7733 !important;
| // background: rgba(145,197,255, 0.6) !important;
| }
| .my-card {
| box-sizing: border-box;
| padding: 12px 10px;
| cursor: default;
| .el-carousel__arrow {
| top: 90%;
| }
| .el-carousel__arrow {
| height: 20px;
| width: 20px;
| }
| .el-carousel__arrow:hover {
| background-color: rgba(102, 102, 102);
| }
| .el-card__body {
| padding: 0px !important;
| }
| .el-card:hover {
| box-sizing: border-box;
| }
| // .el-carousel__arrow {
| // top: inherit;
| // bottom: 0px;
| // }
| .el-carousel {
| height: 100% !important;
| width: 100%;
| .el-carousel__container {
| height: 100% !important;
| width: 100%;
| }
| }
| }
| .my-card:hover {
| -webkit-box-shadow: 0px 0px 5px 1px rgba(0, 0, 0, 0.3);
| box-shadow: 0px 0px 5px 1px rgba(0, 0, 0, 0.3);
| }
| </style>
| <style lang = "scss" scoped>
| .el-carousel__container {
| height: 100% !important;
| .el-carousel__arrow {
| top: 70% !important;
| }
| .el-carousel__arrow {
| height: 20px;
| width: 20px;
| }
| .el-carousel__arrow--right {
| right: 10px !important;
| }
| .el-carousel__arrow--left {
| left: 10px !important;
| }
| }
| </style>
|
|