tab4-2.vue 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. <template>
  2. <div class="tab4-2">
  3. <div class="search" @keyup.enter="mySearch">
  4. <el-input
  5. placeholder="请输入关键词..."
  6. suffix-icon="el-icon-search"
  7. v-model="formData.searchKey"
  8. >
  9. </el-input>
  10. <span class="btn" @click="mySearch"></span>
  11. </div>
  12. <!-- 内容 -->
  13. <div class="conten" v-if="myArr.length !== 0">
  14. <div class="row" v-for="(item, index) in myArr" :key="item.id">
  15. <el-image
  16. @click="lookBigImg(item, index)"
  17. style="width: 351px; height: 200px"
  18. :src="baseURL + item.thumb"
  19. :preview-src-list="srcList"
  20. >
  21. </el-image>
  22. <!-- <img src="../../assets/img/demo2.png" alt="" /> -->
  23. <p :title="item.name">{{ item.name }}</p>
  24. </div>
  25. </div>
  26. <div class="tab4-2 conNull" v-else>暂 无 数 据</div>
  27. <!-- 分页 -->
  28. <div class="paging">
  29. <el-pagination
  30. layout="prev,pager,next,jumper"
  31. :total="total"
  32. :current-page="formData.pageNum"
  33. @current-change="currentChange"
  34. @size-change="sizeChange"
  35. >
  36. </el-pagination>
  37. </div>
  38. <!-- 大图预览里面的文字显示 -->
  39. <div class="imgBigShow" v-if="imgBigShow">{{ imgBigTxt }}</div>
  40. </div>
  41. </template>
  42. <script>
  43. import axios from "@/utils/request";
  44. import { imgList, webVisit } from "@/utils/api";
  45. export default {
  46. name: "tab4-2",
  47. components: {},
  48. data() {
  49. // 这里存放数据
  50. return {
  51. tempNum: 0,
  52. imgBigTxt: "",
  53. imgBigShow: false,
  54. myArr: [],
  55. total: 0,
  56. formData: {
  57. pageNum: 1,
  58. pageSize: 8,
  59. searchKey: "",
  60. },
  61. baseURL: "",
  62. srcList: [""],
  63. };
  64. },
  65. // 监听属性 类似于data概念
  66. computed: {},
  67. // 监控data中的数据变化
  68. watch: {},
  69. // 方法集合
  70. methods: {
  71. //点击图片,查看大图
  72. async lookBigImg(item, index) {
  73. this.imgBigTxt = item.name;
  74. this.tempNum = index;
  75. this.$nextTick(() => {
  76. setTimeout(() => {
  77. this.imgBigShow = true;
  78. //因为污染自己写滚轮缩放
  79. document
  80. .querySelector(".el-image-viewer__wrapper")
  81. .addEventListener("mousewheel", (event) => {
  82. let delta = 0;
  83. if (!event) event = window.event;
  84. if (event.wheelDelta) {
  85. delta = event.wheelDelta / 120;
  86. if (window.opera) delta = -delta;
  87. } else if (event.detail) {
  88. delta = -event.detail / 3;
  89. }
  90. let img = document.querySelector(".el-image-viewer__img");
  91. if (delta > 0) {
  92. let width = img.width;
  93. img.width = width * 1.1;
  94. } else if (delta < 0) {
  95. let width = img.width;
  96. if (width > 100) {
  97. img.width = width * 0.9;
  98. }
  99. }
  100. });
  101. const myTemp = document.querySelector(".el-image-viewer__mask");
  102. myTemp.addEventListener("click", () => {
  103. this.imgBigShow = false;
  104. });
  105. const temp = document.querySelector(".el-image-viewer__close");
  106. temp.addEventListener("click", () => {
  107. this.imgBigShow = false;
  108. // console.log('我点了里面的关闭')
  109. });
  110. // 左按钮
  111. const tempLeft = document.querySelector(".el-image-viewer__prev");
  112. tempLeft.addEventListener("click", () => {
  113. this.tempNum--;
  114. if (this.tempNum < 0) this.tempNum = this.myArr.length - 1;
  115. this.imgBigTxt = this.myArr[this.tempNum].name;
  116. });
  117. // 右按钮
  118. const tempRight = document.querySelector(".el-image-viewer__next");
  119. tempRight.addEventListener("click", () => {
  120. this.tempNum++;
  121. if (this.tempNum === this.myArr.length) this.tempNum = 0;
  122. this.imgBigTxt = this.myArr[this.tempNum].name;
  123. });
  124. }, 100);
  125. });
  126. // 记录访问量
  127. await webVisit("img", item.id);
  128. },
  129. // 分页器方法
  130. currentChange(val) {
  131. // console.log('当前页改变了', val)
  132. this.formData.pageNum = val;
  133. this.imgList(this.formData);
  134. },
  135. sizeChange(val) {
  136. // console.log('条数改变了', val)
  137. this.formData.pageNum = 1;
  138. this.formData.pageSize = val;
  139. this.imgList(this.formData);
  140. },
  141. mySearch() {
  142. // console.log("点击了搜索");
  143. this.formData.pageNum = 1;
  144. this.imgList(this.formData);
  145. },
  146. // 封装获取列表函数
  147. async imgList(data) {
  148. const res = await imgList(data);
  149. this.total = res.data.total;
  150. this.myArr = res.data.records;
  151. let temp = [];
  152. res.data.records.forEach((v) => {
  153. temp.push(this.baseURL + v.thumb);
  154. });
  155. this.srcList = temp;
  156. },
  157. },
  158. // 生命周期 - 创建完成(可以访问当前this实例)
  159. created() {
  160. // 获取服务器前缀地址
  161. this.baseURL = axios.defaults.baseURL;
  162. this.imgList(this.formData);
  163. },
  164. // 生命周期 - 挂载完成(可以访问DOM元素)
  165. mounted() {},
  166. beforeCreate() {}, // 生命周期 - 创建之前
  167. beforeMount() {}, // 生命周期 - 挂载之前
  168. beforeUpdate() {}, // 生命周期 - 更新之前
  169. updated() {}, // 生命周期 - 更新之后
  170. beforeDestroy() {}, // 生命周期 - 销毁之前
  171. destroyed() {}, // 生命周期 - 销毁完成
  172. activated() {}, // 如果页面有keep-alive缓存功能,这个函数会触发
  173. };
  174. </script>
  175. <style lang='less' scoped>
  176. .conNull {
  177. display: flex;
  178. font-size: 30px;
  179. align-items: center;
  180. justify-content: center;
  181. color: #b9412e !important;
  182. }
  183. .tab4-2 {
  184. position: relative;
  185. /*修改提示文字的颜色*/
  186. /deep/input::-webkit-input-placeholder {
  187. /* WebKit browsers */
  188. color: #b9412e;
  189. }
  190. /deep/input:-moz-placeholder {
  191. /* Mozilla Firefox 4 to 18 */
  192. color: #b9412e;
  193. }
  194. /deep/input::-moz-placeholder {
  195. /* Mozilla Firefox 19+ */
  196. color: #b9412e;
  197. }
  198. /deep/input:-ms-input-placeholder {
  199. /* Internet Explorer 10+ */
  200. color: #b9412e;
  201. }
  202. // position: relative;
  203. padding: 30px 200px;
  204. display: flex;
  205. width: 100%;
  206. height: 620px;
  207. color: black;
  208. .search {
  209. z-index: 10;
  210. /*修改提示文字的颜色*/
  211. /deep/input::-webkit-input-placeholder {
  212. /* WebKit browsers */
  213. color: #be1220;
  214. }
  215. /deep/input:-moz-placeholder {
  216. /* Mozilla Firefox 4 to 18 */
  217. color: #be1220;
  218. }
  219. /deep/input::-moz-placeholder {
  220. /* Mozilla Firefox 19+ */
  221. color: #be1220;
  222. }
  223. /deep/input:-ms-input-placeholder {
  224. /* Internet Explorer 10+ */
  225. color: #be1220;
  226. }
  227. width: 700px;
  228. height: 50px;
  229. position: absolute;
  230. top: -25px;
  231. left: 50%;
  232. transform: translateX(-50%);
  233. /deep/.el-input__suffix {
  234. width: 50px;
  235. height: 50px;
  236. font-size: 20px;
  237. right: 0;
  238. }
  239. /deep/.el-input__inner {
  240. border-radius: 50px;
  241. height: 50px;
  242. border: 1px solid #be1220;
  243. }
  244. .btn {
  245. cursor: pointer;
  246. position: absolute;
  247. right: 0;
  248. top: 0;
  249. height: 50px;
  250. width: 50px;
  251. border-radius: 50%;
  252. background-color: transparent;
  253. }
  254. }
  255. .conten {
  256. height: 530px;
  257. display: flex;
  258. flex-wrap: wrap;
  259. .row {
  260. color: #626260;
  261. background-color: #fff;
  262. box-shadow: 1px 1px 2px 2px #ccc;
  263. cursor: pointer;
  264. margin: 20px 30px 10px 0;
  265. width: 351px;
  266. height: 235px;
  267. /deep/.el-image__preview {
  268. object-fit: cover;
  269. }
  270. & > img {
  271. width: 351px;
  272. height: 200px;
  273. }
  274. & > p {
  275. padding: 0 5px;
  276. overflow: hidden;
  277. text-overflow: ellipsis;
  278. white-space: nowrap;
  279. font-size: 18px;
  280. margin-top: 3px;
  281. text-align: center;
  282. }
  283. &:hover {
  284. background-color: #be1220;
  285. color: #fff;
  286. }
  287. }
  288. .row:nth-of-type(4n) {
  289. margin-right: 0;
  290. }
  291. }
  292. .paging {
  293. position: absolute;
  294. left: 50%;
  295. bottom: 10px;
  296. transform: translateX(-50%);
  297. /deep/.el-input__inner {
  298. width: 30px;
  299. height: 30px !important;
  300. background-color: transparent;
  301. border-radius: 50%;
  302. }
  303. }
  304. .imgBigShow {
  305. padding: 3px 5px;
  306. background-color: rgba(0, 0, 0, 0.7);
  307. font-size: 18px;
  308. z-index: 9999;
  309. position: fixed;
  310. left: 50%;
  311. transform: translateX(-50%);
  312. bottom: 100px;
  313. color: #fff;
  314. }
  315. }
  316. </style>