index.vue 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397
  1. <template>
  2. <div class="collectioncon">
  3. <div class="collections">
  4. <div class="slebar">
  5. <div class="sleft">
  6. <ui-select
  7. :options="museumList"
  8. :placeholder="'请选择'"
  9. v-model="currentMuseum"
  10. >
  11. <template v-slot:option="{ raw }">
  12. <div>{{ raw.label }}</div>
  13. </template>
  14. </ui-select>
  15. <ui-select :options="ages" :placeholder="'年代'" v-model="currentAge">
  16. <template v-slot:option="{ raw }">
  17. <div>{{ raw.label }}</div>
  18. </template>
  19. </ui-select>
  20. <ui-select
  21. :options="types"
  22. :placeholder="'藏品种类'"
  23. v-model="currentType"
  24. >
  25. <template v-slot:option="{ raw }">
  26. <div>{{ raw.label }}</div>
  27. </template>
  28. </ui-select>
  29. <ui-search
  30. v-model="searchKey"
  31. :placeholder="'请输入展览名称'"
  32. ></ui-search>
  33. </div>
  34. <div class="sright">
  35. <div>分类:</div>
  36. <ul>
  37. <li
  38. @click="menuActive = item.id"
  39. :class="{ active: menuActive == item.id }"
  40. v-for="(item, i) in menu"
  41. :key="i"
  42. >
  43. {{ item.name }}
  44. </li>
  45. </ul>
  46. </div>
  47. </div>
  48. <div
  49. v-if="list && list.length > 0"
  50. class="masonry"
  51. v-infinite-scroll="getData"
  52. infinite-scroll-disabled="busy"
  53. :infinite-scroll-immediate-check="true"
  54. infinite-scroll-distance="30"
  55. v-masonry="containerId"
  56. fit-width="true"
  57. gutter="40"
  58. initLayout="true"
  59. transition-duration="0.3s"
  60. item-selector=".item"
  61. >
  62. <div
  63. @click="onClickCollection(item)"
  64. v-masonry-tile
  65. class="item"
  66. :class="{ odd: index % 2 != 0 }"
  67. v-for="(item, index) in list"
  68. :key="index"
  69. >
  70. <div class="itemimg">
  71. <div :style="`background-image:url(${item.thumb})`"></div>
  72. </div>
  73. <p class="goodBotInfo">{{ item.name }}</p>
  74. </div>
  75. </div>
  76. <div class="searchNone" style="padding-top: 200px" v-else>
  77. <img src="@/assets/images/resource/searchNone.svg" alt="" />
  78. <p>暂时没有数据</p>
  79. </div>
  80. </div>
  81. <transition name="fade">
  82. <teleport to="body">
  83. <showCollection v-if="activeCollection" :item="activeCollection" />
  84. </teleport>
  85. </transition>
  86. </div>
  87. </template>
  88. <script>
  89. import { defineProps, onMounted, watch, nextTick, ref } from "vue";
  90. import {
  91. getCollectionList,
  92. getMuseumList,
  93. getAge,
  94. getType,
  95. } from "@/config/api";
  96. import showCollection from "@/components/showCollection/index.vue";
  97. import emitter from "@/mitt/index";
  98. export default {
  99. setup(props) {
  100. const containerId = ref("vuemasonry");
  101. const currentMuseum = ref("");
  102. const museumList = ref([]);
  103. // const props = defineProps({
  104. // currentMuseumItem: {
  105. // type: Object,
  106. // default: () => {
  107. // return {}
  108. // },
  109. // },
  110. // });
  111. const searchKey = ref("");
  112. const currentAge = ref("");
  113. const currentType = ref("");
  114. const busy = ref(false);
  115. const ages = ref([]);
  116. const types = ref([]);
  117. const menu = ref([
  118. {
  119. id: "",
  120. name: "全部",
  121. },
  122. {
  123. id: "model",
  124. name: "三维模型",
  125. },
  126. {
  127. id: "img",
  128. name: "图片",
  129. },
  130. {
  131. id: "video",
  132. name: "视频",
  133. },
  134. {
  135. id: "audio",
  136. name: "音频",
  137. },
  138. ]);
  139. const menuActive = ref("");
  140. onMounted(() => {
  141. getAge((data) => {
  142. ages.value = data.data.data.map((item) => {
  143. return {
  144. ...item,
  145. label: item.name,
  146. value: item.id,
  147. };
  148. });
  149. });
  150. getType((data) => {
  151. types.value = data.data.data.map((item) => {
  152. return {
  153. ...item,
  154. label: item.name,
  155. value: item.id,
  156. };
  157. });
  158. });
  159. getMuseumList(
  160. {
  161. cityId: "",
  162. pageNum: 1,
  163. pageSize: 1000,
  164. },
  165. (data) => {
  166. museumList.value = data.data.records.map((item) => {
  167. return {
  168. ...item,
  169. label: item.name,
  170. value: item.id,
  171. };
  172. });
  173. if (!props.currentMuseumItem) {
  174. currentMuseum.value = museumList.value[0].value;
  175. } else {
  176. currentMuseum.value = props.currentMuseumItem.id;
  177. }
  178. }
  179. );
  180. });
  181. return {
  182. ages,
  183. types,
  184. currentMuseum,
  185. menu,
  186. currentAge,
  187. menuActive,
  188. currentType,
  189. searchKey,
  190. busy,
  191. museumList,
  192. };
  193. },
  194. components: { showCollection },
  195. data() {
  196. return {
  197. activeCollection: "",
  198. list: [],
  199. paging: {
  200. pageSize: 10,
  201. pageNum: 1,
  202. showSize: 4,
  203. current: 1,
  204. },
  205. };
  206. },
  207. watch: {
  208. searchKey() {
  209. this.getData(true);
  210. },
  211. currentAge() {
  212. this.getData(true);
  213. },
  214. currentType() {
  215. this.getData(true);
  216. },
  217. currentMuseum() {
  218. this.getData(true);
  219. this.$emit(
  220. "updateMuseum",
  221. this.museumList.find((item) => item.id == this.currentMuseum)
  222. );
  223. },
  224. menuActive() {
  225. this.getData(true);
  226. },
  227. },
  228. methods: {
  229. getData(reset) {
  230. if (reset) {
  231. this.list = [];
  232. this.busy = false;
  233. }
  234. getCollectionList(
  235. {
  236. ageId: this.currentAge,
  237. museumId: this.currentMuseum,
  238. type: this.menuActive,
  239. pageNum: this.paging.pageNum,
  240. pageSize: this.paging.pageSize,
  241. searchKey: this.searchKey,
  242. textureId: this.currentType,
  243. },
  244. (data) => {
  245. if (data.data.total <= this.list.length) {
  246. this.busy = true;
  247. return;
  248. }
  249. this.list = this.list.concat(data.data.records);
  250. this.paging.pageNum += 1;
  251. this.$nextTick(() => {
  252. this.$redrawVueMasonry(this.containerId);
  253. });
  254. }
  255. );
  256. // console.log(this);
  257. // this.list = this.list.concat([]);
  258. // // list.value = list.value.concat(list.value);
  259. // this.$nextTick(() => {
  260. // this.$redrawVueMasonry(this.containerId);
  261. // });
  262. },
  263. onClickCollection(data) {
  264. this.activeCollection = data;
  265. console.log(this.activeCollection);
  266. },
  267. },
  268. mounted() {
  269. emitter.on("closeCollection", () => {
  270. this.activeCollection = "";
  271. });
  272. },
  273. };
  274. </script>
  275. <style lang="scss" scoped>
  276. .collectioncon {
  277. background: #e8e3d1;
  278. overflow-y: auto;
  279. overflow-x: hidden;
  280. .collections {
  281. width: 1400px;
  282. margin: 62px auto;
  283. .slebar {
  284. display: flex;
  285. justify-content: space-between;
  286. .sleft {
  287. display: flex;
  288. width: 65%;
  289. &:deep(.text) {
  290. margin-right: 20px;
  291. }
  292. }
  293. .sright {
  294. display: flex;
  295. align-items: center;
  296. color: #333;
  297. > ul {
  298. display: flex;
  299. align-items: center;
  300. > li {
  301. text-align: center;
  302. margin: 0 10px;
  303. cursor: pointer;
  304. &.active {
  305. width: 90px;
  306. height: 34px;
  307. color: var(--main-color);
  308. line-height: 34px;
  309. border-radius: 60px;
  310. border: 1px solid var(--main-color);
  311. }
  312. }
  313. }
  314. }
  315. }
  316. .masonry {
  317. margin-top: 36px;
  318. .item {
  319. width: 320px;
  320. height: 270px;
  321. border-radius: 10px;
  322. margin-bottom: 40px;
  323. overflow: hidden;
  324. cursor: pointer;
  325. .itemimg {
  326. background: linear-gradient(180deg, #d9d9d9 0%, #b9b9b9 100%);
  327. font-size: 0;
  328. height: calc(100% - 60px);
  329. width: 100%;
  330. > div {
  331. height: 100%;
  332. width: 100%;
  333. background-repeat: no-repeat;
  334. background-size: cover;
  335. background-position: center;
  336. }
  337. }
  338. p {
  339. background: #fffef6;
  340. color: #999;
  341. height: 60px;
  342. line-height: 60px;
  343. padding: 0 10px;
  344. &.active {
  345. color: var(--main-color);
  346. }
  347. }
  348. }
  349. .odd {
  350. height: 410px;
  351. }
  352. }
  353. }
  354. }
  355. </style>