Tow.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. <!-- -->
  2. <template>
  3. <div class="Tow">
  4. <div class="main">
  5. <div
  6. class="row"
  7. @click="lookInfo(item)"
  8. v-for="(item) in handlData[acInd]"
  9. :key="item.bs"
  10. >
  11. <div v-if="item.imgNum>1">
  12. <img v-lazy="`goodsData/2D/${item.bs} (1).jpg`" alt="" />
  13. </div>
  14. <div v-else><img v-lazy="`goodsData/2D/${item.bs}.jpg`" alt="" /></div>
  15. <p>{{ item.name }}</p>
  16. </div>
  17. </div>
  18. <!-- 分页 -->
  19. <Pagination
  20. class="page"
  21. layout="prev, pager, next"
  22. :total="this.data.length"
  23. @current-change="currentChange"
  24. :current-page="acInd + 1"
  25. :page-size="20"
  26. >
  27. </Pagination>
  28. <!-- 点击图片出来的页面 -->
  29. <Img v-if="type === 'img'" @close="type = ''" :info="info" />
  30. </div>
  31. </template>
  32. <script>
  33. import { Pagination } from "element-ui";
  34. import _ from "lodash";
  35. import Img from "./Img";
  36. export default {
  37. name: "Tow",
  38. props: {
  39. data: {
  40. type: Array,
  41. default: () => [],
  42. },
  43. },
  44. //import引入的组件需要注入到对象中才能使用
  45. components: { Img, Pagination },
  46. data() {
  47. //这里存放数据
  48. return {
  49. type: "",
  50. info: {},
  51. handlData: [],
  52. acInd: 0,
  53. pageNum: 0,
  54. };
  55. },
  56. //监听属性 类似于data概念
  57. computed: {},
  58. //监控data中的数据变化
  59. watch: {
  60. data(val) {
  61. this.pageNum = 0;
  62. if (val.length > 20) this.pageNum = Math.ceil(val.length / 20);
  63. this.acInd = 0;
  64. this.handlData = _.chunk(val, 20);
  65. this.$nextTick(() => {
  66. let dom = document.querySelector(".main");
  67. dom.scrollTop = 0;
  68. });
  69. },
  70. acInd() {
  71. this.$nextTick(() => {
  72. let dom = document.querySelector(".main");
  73. dom.scrollTop = 0;
  74. });
  75. },
  76. },
  77. //方法集合
  78. methods: {
  79. // 分页器方法
  80. currentChange(val) {
  81. this.acInd = val - 1;
  82. // console.log('当前页改变了', val)
  83. },
  84. lookInfo(val) {
  85. this.info = val;
  86. this.type = "img";
  87. },
  88. },
  89. //生命周期 - 创建完成(可以访问当前this实例)
  90. created() {
  91. if (this.data.length > 20) this.pageNum = Math.ceil(this.data.length / 20);
  92. this.handlData = _.chunk(this.data, 20);
  93. },
  94. //生命周期 - 挂载完成(可以访问DOM元素)
  95. mounted() {},
  96. beforeCreate() {}, //生命周期 - 创建之前
  97. beforeMount() {}, //生命周期 - 挂载之前
  98. beforeUpdate() {}, //生命周期 - 更新之前
  99. updated() {}, //生命周期 - 更新之后
  100. beforeDestroy() {}, //生命周期 - 销毁之前
  101. destroyed() {}, //生命周期 - 销毁完成
  102. activated() {}, //如果页面有keep-alive缓存功能,这个函数会触发
  103. };
  104. </script>
  105. <style lang='less' scoped>
  106. .Tow {
  107. width: 100%;
  108. height: calc(100% - 140px);
  109. position: absolute;
  110. bottom: 0;
  111. left: 0;
  112. z-index: 10;
  113. padding: 0 80px 0 160px;
  114. .main::-webkit-scrollbar {
  115. /*滚动条整体样式*/
  116. width: 6px; /*高宽分别对应横竖滚动条的尺寸*/
  117. height: 0px;
  118. }
  119. .main::-webkit-scrollbar-thumb {
  120. /*滚动条里面小方块*/
  121. border-radius: 10px;
  122. box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2);
  123. background: #930909;
  124. }
  125. .main::-webkit-scrollbar-track {
  126. /*滚动条里面轨道*/
  127. box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2);
  128. border-radius: 10px;
  129. background: #d8b275;
  130. }
  131. .page {
  132. height: 6%;
  133. align-items: center;
  134. display: flex;
  135. justify-content: flex-end;
  136. padding-right: 64px;
  137. }
  138. .main {
  139. width: 100%;
  140. height: 92%;
  141. overflow-y: auto;
  142. padding-right: 60px;
  143. display: flex;
  144. flex-wrap: wrap;
  145. align-content: flex-start;
  146. .row {
  147. cursor: pointer;
  148. border-radius: 6px;
  149. overflow: hidden;
  150. width: 23%;
  151. height: 280px;
  152. margin: 0 40px 40px 0;
  153. background-color: #f0f1f3;
  154. & > div {
  155. width: 100%;
  156. height: 210px;
  157. padding: 20px;
  158. & > img {
  159. width: 100%;
  160. height: 100%;
  161. object-fit: contain;
  162. }
  163. }
  164. & > P {
  165. display: flex;
  166. align-items: center;
  167. height: 70px;
  168. padding: 3px 5px;
  169. font-size: 16px;
  170. color: #666666;
  171. line-height: 24px;
  172. background-color: #fff;
  173. }
  174. &:hover {
  175. & > P {
  176. color: #930909;
  177. }
  178. }
  179. &:nth-of-type(4n) {
  180. margin-right: 0;
  181. }
  182. }
  183. @media screen and (max-width: 1800px) {
  184. .row {
  185. width: 22%;
  186. }
  187. }
  188. }
  189. }
  190. </style>