index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514
  1. <!-- -->
  2. <template>
  3. <div class="Goods" @click.once="music = true">
  4. <audio src="../../assets/media/bacMusic.mp3" loop id="bacMusic"></audio>
  5. <!-- 左侧搜索 -->
  6. <div class="leftTop">
  7. <div class="model">
  8. <div class="row1" @click="model = '3D'" :class="{ active: model === '3D' }">
  9. <div class="rowll"></div>
  10. <div class="rowrr">三维展示</div>
  11. </div>
  12. <div class="row1" @click="model = '2D'" :class="{ active: model === '2D' }">
  13. <div class="rowll"></div>
  14. <div class="rowrr">二维展示</div>
  15. </div>
  16. </div>
  17. <div class="type">
  18. <div class="typell">类型:</div>
  19. <div class="typerr">
  20. <div class="row" v-show="model === '2D' || item.type !== 'straw'" @click="genre = item.type"
  21. :class="{ active: item.type === genre }" v-for="(item) in genreList" :key="item.bs">
  22. {{ item.name }}
  23. </div>
  24. <div class="row" @click="genre = 'picture'" :class="{ active: 'picture' === genre }" v-if="model === '2D'">
  25. 照片
  26. </div>
  27. <div class="row" @click="genre = 'Italy'" :class="{ active: 'Italy' === genre }" v-if="model === '2D'">
  28. 字画
  29. </div>
  30. </div>
  31. </div>
  32. <div class="inputSearch" @keyup.enter="mySearch">
  33. <input class="searll" autofocus type="text" v-model="txt" placeholder="请输入文物名称" />
  34. <div class="searrr" @click="mySearch">
  35. <img src="../../assets/img/Goods/search.svg" alt="" />
  36. </div>
  37. </div>
  38. </div>
  39. <!-- 右侧图标 -->
  40. <div class="rightTop">
  41. <div class="row" @click="rightClisk(item.type)" v-for="item in rightList" :key="item.type" :class="{
  42. active2:
  43. (music && item.type === 2) ||
  44. (like && item.type === 3) ||
  45. (share && item.type === 4),
  46. }">
  47. <img :src="require(`@/assets/img/Goods/inco${item.type}Ac.png`)" alt="" v-if="music && item.type === 2" />
  48. <img :src="require(`@/assets/img/Goods/inco${item.type}Ac.png`)" alt="" v-else-if="like && item.type === 3" />
  49. <img :src="require(`@/assets/img/Goods/inco${item.type}Ac.png`)" alt="" v-else-if="share && item.type === 4" />
  50. <img :src="require(`@/assets/img/Goods/inco${item.type}.png`)" alt="" v-else />
  51. <transition name="likeAddAnimate">
  52. <div class="likeMove" v-show="like && item.type === 3">+ 1</div>
  53. </transition>
  54. <p>
  55. {{ item.name }}
  56. </p>
  57. </div>
  58. </div>
  59. <div class="nullSerach" v-if="data.length === 0">
  60. <div>
  61. <img src="../../assets/img/Goods/nullSearch.png" alt="" />
  62. <p>暂时没有数据</p>
  63. <p>请试一下其他关键字</p>
  64. </div>
  65. </div>
  66. <template v-else>
  67. <Three ref="ThreeRef" v-if="model === '3D'" :data="data" />
  68. <Tow v-else :data="data" />
  69. </template>
  70. <!-- 分享页面 -->
  71. <div class="shareBox" :class="{ shareBoxShow: share }">
  72. <div class="shareMain">
  73. <div class="close" @click="share = false"></div>
  74. <h3>分享</h3>
  75. <p>
  76. 请使用手机扫描二维码或
  77. <br />
  78. 复制分享链接
  79. </p>
  80. <img src="../../assets/img/Goods/Rcode.jpg" alt="" />
  81. <div class="btnn" @click="copyPcTxt">复制分享链接</div>
  82. </div>
  83. </div>
  84. </div>
  85. </template>
  86. <script>
  87. import { addNumAPI } from "@/utils/api";
  88. import { goodsData } from "./data";
  89. import Three from "./components/Three.vue";
  90. import Tow from "./components/Tow.vue";
  91. goodsData['2D'] = goodsData['2D'].map(v => ({
  92. ...v,
  93. imgNum: v.imgNum && v.imgNum > 3 ? 3 : v.imgNum
  94. }))
  95. export default {
  96. name: "Goods",
  97. //import引入的组件需要注入到对象中才能使用
  98. components: { Three, Tow },
  99. data() {
  100. //这里存放数据
  101. return {
  102. model: "3D",
  103. genre: "all",
  104. txt: "",
  105. genreList: [
  106. { name: "全部", type: "all" },
  107. { name: "手稿", type: "straw" },
  108. { name: "书刊", type: "book" },
  109. { name: "用具", type: "tool" },
  110. { name: "服装", type: "clothing" },
  111. ],
  112. rightList: [
  113. { name: "首页", type: 1 },
  114. { name: "声音", type: 2 },
  115. { name: "点赞", type: 3 },
  116. { name: "分享", type: 4 },
  117. ],
  118. music: false,
  119. like: false,
  120. share: false,
  121. data: [],
  122. };
  123. },
  124. //监听属性 类似于data概念
  125. computed: {},
  126. //监控data中的数据变化
  127. watch: {
  128. genre(val) {
  129. let temp = goodsData[this.model]
  130. if (val === "all") {
  131. this.data = temp.filter((v) => v.name.includes(this.txt));
  132. } else {
  133. let temp2 = temp.filter((v) => v.type === val);
  134. this.data = temp2.filter((v) => v.name.includes(this.txt));
  135. }
  136. },
  137. share(val) {
  138. this.$refs.ThreeRef.moveShareCut(val);
  139. },
  140. music(val) {
  141. let dom = document.querySelector("#bacMusic");
  142. if (val) dom.play();
  143. else dom.pause();
  144. },
  145. model(val) {
  146. this.data = goodsData[val];
  147. this.genre = "all";
  148. this.txt = "";
  149. },
  150. },
  151. //方法集合
  152. methods: {
  153. mySearch() {
  154. let val = this.genre;
  155. let temp = goodsData[this.model];
  156. if (val === "all") {
  157. this.data = temp.filter((v) => v.name.includes(this.txt));
  158. } else {
  159. let temp2 = temp.filter((v) => v.type === val);
  160. this.data = temp2.filter((v) => v.name.includes(this.txt));
  161. }
  162. },
  163. rightClisk(type) {
  164. if (type === 1) this.$router.replace("/Home");
  165. if (type === 2) this.music = !this.music;
  166. if (type === 3) {
  167. if (this.like) return;
  168. this.like = true;
  169. setTimeout(() => {
  170. this.like = false;
  171. }, 2000);
  172. addNumAPI("star");
  173. }
  174. if (type === 4) this.share = true;
  175. },
  176. //点击复制链接
  177. copyPcTxt() {
  178. // 存储传递过来的数据
  179. let OrderNumber = window.location.origin + "/YHT/index.html";
  180. // 创建一个input 元素
  181. // createElement() 方法通过指定名称创建一个元素
  182. let newInput = document.createElement("input");
  183. // 讲存储的数据赋值给input的value值
  184. newInput.value = OrderNumber;
  185. // appendChild() 方法向节点添加最后一个子节点。
  186. document.body.appendChild(newInput);
  187. // 选中input元素中的文本
  188. // select() 方法用于选择该元素中的文本。
  189. newInput.select();
  190. // 执行浏览器复制命令
  191. // execCommand方法是执行一个对当前文档,当前选择或者给出范围的命令
  192. document.execCommand("Copy");
  193. // 清空输入框
  194. newInput.remove();
  195. alert("复制成功");
  196. },
  197. },
  198. //生命周期 - 创建完成(可以访问当前this实例)
  199. created() { },
  200. //生命周期 - 挂载完成(可以访问DOM元素)
  201. mounted() {
  202. this.data = goodsData[this.model];
  203. },
  204. beforeCreate() { }, //生命周期 - 创建之前
  205. beforeMount() { }, //生命周期 - 挂载之前
  206. beforeUpdate() { }, //生命周期 - 更新之前
  207. updated() { }, //生命周期 - 更新之后
  208. beforeDestroy() { }, //生命周期 - 销毁之前
  209. destroyed() { }, //生命周期 - 销毁完成
  210. activated() { }, //如果页面有keep-alive缓存功能,这个函数会触发
  211. };
  212. </script>
  213. <style lang='less' scoped>
  214. .likeAddAnimate-enter-active,
  215. .likeAddAnimate-leave-active {
  216. transition: all 2s ease;
  217. }
  218. .likeAddAnimate-enter,
  219. .likeAddAnimate-leave {
  220. transform: translateY(0) scale(0);
  221. opacity: 0;
  222. }
  223. .likeAddAnimate-enter-to,
  224. .likeAddAnimate-leave-to {
  225. transform: translateY(-30px) scale(1.2);
  226. opacity: 1;
  227. }
  228. .Goods {
  229. padding-top: 140px;
  230. width: 100%;
  231. height: 100%;
  232. background-image: url("../../assets/img/Goods/GoodsBac.png");
  233. background-size: 100% 100%;
  234. position: relative;
  235. .leftTop {
  236. position: absolute;
  237. top: 42px;
  238. left: 160px;
  239. height: 40px;
  240. display: flex;
  241. .model {
  242. color: #fff;
  243. width: 260px;
  244. height: 40px;
  245. border-radius: 20px;
  246. background-color: #930909;
  247. display: flex;
  248. justify-content: space-between;
  249. padding: 0 22px;
  250. margin-right: 40px;
  251. .row1 {
  252. cursor: pointer;
  253. display: flex;
  254. justify-content: center;
  255. align-items: center;
  256. font-size: 16px;
  257. .rowll {
  258. margin-right: 6px;
  259. width: 24px;
  260. height: 24px;
  261. border-radius: 50%;
  262. border: 1px solid #d8b275;
  263. position: relative;
  264. }
  265. .rowrr {
  266. padding-bottom: 2px;
  267. }
  268. }
  269. .active {
  270. color: #d8b275;
  271. .rowll {
  272. &::after {
  273. content: "";
  274. position: absolute;
  275. top: 50%;
  276. left: 50%;
  277. transform: translate(-50%, -50%);
  278. border-radius: 50%;
  279. width: 14px;
  280. height: 14px;
  281. background-color: #d8b275;
  282. }
  283. }
  284. }
  285. }
  286. .type {
  287. display: flex;
  288. font-size: 16px;
  289. color: #fff;
  290. background-color: #930909;
  291. height: 40px;
  292. border-radius: 20px;
  293. padding: 0 20px;
  294. margin-right: 40px;
  295. .typell {
  296. width: 50px;
  297. line-height: 38px;
  298. }
  299. .typerr {
  300. display: flex;
  301. align-items: center;
  302. padding-bottom: 4px;
  303. .row {
  304. cursor: pointer;
  305. margin: 0 10px;
  306. }
  307. .active {
  308. color: #d8b275;
  309. position: relative;
  310. &::after {
  311. content: "";
  312. position: absolute;
  313. bottom: -4px;
  314. left: 0;
  315. width: 100%;
  316. height: 2px;
  317. background-color: #d8b275;
  318. }
  319. }
  320. }
  321. }
  322. .inputSearch {
  323. overflow: hidden;
  324. display: flex;
  325. font-size: 16px;
  326. color: #fff;
  327. width: 260px;
  328. height: 40px;
  329. border-radius: 20px;
  330. display: flex;
  331. .searll {
  332. width: 214px;
  333. height: 40px;
  334. border: none;
  335. background-color: #fff;
  336. padding: 0 10px 0 20px;
  337. &:focus {
  338. outline: none;
  339. }
  340. }
  341. .searrr {
  342. cursor: pointer;
  343. background-color: #930909;
  344. width: 46px;
  345. display: flex;
  346. justify-content: center;
  347. align-items: center;
  348. padding-right: 4px;
  349. img {
  350. width: 24px;
  351. height: 24px;
  352. }
  353. }
  354. }
  355. }
  356. .rightTop {
  357. position: absolute;
  358. top: 32px;
  359. right: 100px;
  360. height: 60px;
  361. display: flex;
  362. .row {
  363. position: relative;
  364. cursor: pointer;
  365. width: 50px;
  366. text-align: center;
  367. margin-left: 24px;
  368. &>img {
  369. width: 50px;
  370. }
  371. .likeMove {
  372. color: #930909;
  373. position: absolute;
  374. top: 10px;
  375. width: 100%;
  376. text-align: center;
  377. }
  378. }
  379. .active2 {
  380. color: #930909;
  381. }
  382. }
  383. .nullSerach {
  384. width: 100%;
  385. height: 90%;
  386. display: flex;
  387. justify-content: center;
  388. align-items: center;
  389. &>div {
  390. width: 240px;
  391. &>img {
  392. width: 100%;
  393. }
  394. &>p {
  395. text-align: center;
  396. color: #666666;
  397. font-size: 24px;
  398. margin: 10px 0;
  399. }
  400. }
  401. }
  402. .shareBox {
  403. z-index: 11;
  404. position: absolute;
  405. top: 0;
  406. left: 0;
  407. width: 100%;
  408. height: 100%;
  409. opacity: 0;
  410. pointer-events: none;
  411. backdrop-filter: blur(4px);
  412. transition: opacity 0.5s;
  413. .shareMain {
  414. padding: 40px 30px 0;
  415. position: absolute;
  416. top: 50%;
  417. left: 50%;
  418. transform: translate(-50%, -50%);
  419. width: 450px;
  420. height: 650px;
  421. background-image: url("../../assets/img/Goods/shareBac.png");
  422. background-size: 100% 100%;
  423. text-align: center;
  424. .close {
  425. width: 48px;
  426. height: 48px;
  427. cursor: pointer;
  428. position: absolute;
  429. right: -24px;
  430. top: -24px;
  431. background-image: url("../../assets/img/Goods/shareClose.png");
  432. background-size: 100% 100%;
  433. }
  434. h3 {
  435. text-align: left;
  436. color: #d8b275;
  437. font-size: 24px;
  438. margin-bottom: 50px;
  439. }
  440. p {
  441. font-size: 20px;
  442. color: #ffffff;
  443. margin-bottom: 40px;
  444. }
  445. img {
  446. width: 240px;
  447. margin-bottom: 50px;
  448. }
  449. .btnn {
  450. cursor: pointer;
  451. width: 280px;
  452. margin: 0 auto;
  453. height: 60px;
  454. border-radius: 30px;
  455. border: 2px solid #d8b275;
  456. line-height: 58px;
  457. font-size: 20px;
  458. color: #ffffff;
  459. }
  460. }
  461. }
  462. .shareBoxShow {
  463. opacity: 1;
  464. pointer-events: auto;
  465. }
  466. }
  467. </style>