collectDetail.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777
  1. <template>
  2. <div class="collect-detail-container">
  3. <!-- 顶部固定导航 -->
  4. <div class="top-navigation">
  5. <!-- 返回按钮 -->
  6. <div class="back-button" @click="goBack">
  7. <img src="@/assets/img/icon_back.png" alt="返回" />
  8. </div>
  9. <!-- 自定义标签页导航 -->
  10. <div class="custom-tabs">
  11. <div
  12. class="tab-item"
  13. :class="{ active: activeTab === 'model' }"
  14. @click="switchTab('model')"
  15. >
  16. 模型
  17. </div>
  18. <div
  19. class="tab-item"
  20. :class="{ active: activeTab === 'image' }"
  21. @click="switchTab('image')"
  22. >
  23. 图片
  24. </div>
  25. </div>
  26. </div>
  27. <!-- 内容展示区域 -->
  28. <div class="content-display" :class="{ zoomed: isZoomed }">
  29. <!-- 轮播展示区域 -->
  30. <div class="carousel-viewer">
  31. <!-- 模型展示容器 -->
  32. <div v-show="activeTab === 'model'" class="carousel-container">
  33. <!-- 模型直接展示,不使用轮播 -->
  34. <div class="model-container" v-if="artifactData && artifactData.modelFiles && artifactData.modelFiles.length > 0">
  35. <div class="model-item">
  36. <iframe
  37. id="ifr"
  38. :src="`https://sit-huyaobangjng.4dage.com/modelLoad/model.html?m=${modelList[0]?.src}`"
  39. frameborder="0"
  40. width="100%"
  41. height="100%"
  42. allowfullscreen
  43. ></iframe>
  44. <!-- <iframe
  45. id="ifr"
  46. :src="`${modelList[0]?.src}`"
  47. frameborder="0"
  48. width="100%"
  49. height="100%"
  50. allowfullscreen
  51. ></iframe> -->
  52. </div>
  53. </div>
  54. <div v-else class="empty-state">
  55. <div class="empty-content">
  56. <div class="empty-text">暂无3D模型数据</div>
  57. </div>
  58. </div>
  59. </div>
  60. <!-- 图片轮播容器 -->
  61. <div v-show="activeTab === 'image'" class="carousel-container">
  62. <div class="carousel-container-image" v-if="artifactData && artifactData.imageFiles && artifactData.imageFiles.length > 0">
  63. <el-carousel
  64. height="100%"
  65. arrow="always"
  66. ref="imageCarouselRef"
  67. @change="handleImageCarouselChange"
  68. :autoplay="autoplayEnabled"
  69. :interval="4000"
  70. :pause-on-hover="false"
  71. >
  72. <el-carousel-item
  73. v-for="(item, index) in imageList"
  74. :key="index"
  75. >
  76. <div class="image-item">
  77. <img :src="item.src" :alt="item.alt" class="carousel-image" />
  78. </div>
  79. </el-carousel-item>
  80. </el-carousel>
  81. </div>
  82. <div v-else class="empty-state">
  83. <div class="empty-content">
  84. <div class="empty-text">暂无图片数据</div>
  85. </div>
  86. </div>
  87. </div>
  88. <!-- 放大镜图标 -->
  89. <div v-if="activeTab === 'model' && artifactData && artifactData.modelFiles && artifactData.modelFiles.length > 0" class="zoom-icon" @click="toggleZoom">
  90. <el-icon style="color: #7C6444" :size="24">
  91. <ZoomIn v-if="!isZoomed" />
  92. <ZoomOut v-else />
  93. </el-icon>
  94. </div>
  95. </div>
  96. </div>
  97. <!-- 底部固定信息卡片 -->
  98. <div class="artifact-info-card" :class="{ hidden: isZoomed }">
  99. <div class="card-content">
  100. <div class="artifact-title">{{ getFieldValue(artifactData, 'title') }}</div>
  101. <!-- 信息表格 -->
  102. <div class="info-table">
  103. <div class="info-row">
  104. <div class="info-label-container" v-if="getFieldValue(artifactData, 'level')">
  105. <div class="info-label">
  106. <span class="info-label-text">级别</span>
  107. <span>{{ getFieldValue(artifactData, 'level') }}</span>
  108. </div>
  109. <div class="bottom-img"></div>
  110. </div>
  111. <div class="info-label-container" v-if="getFieldValue(artifactData, 'era')">
  112. <div class="info-label">
  113. <span class="info-label-text">年代</span>
  114. <span>{{ getFieldValue(artifactData, 'era') }}</span>
  115. </div>
  116. <div class="bottom-img"></div>
  117. </div>
  118. </div>
  119. <div class="info-row">
  120. <div class="info-label-container" v-if="getFieldValue(artifactData, 'category')">
  121. <div class="info-label">
  122. <span class="info-label-text">类别</span>
  123. <span>{{ getFieldValue(artifactData, 'category') }}</span>
  124. </div>
  125. <div class="bottom-img"></div>
  126. </div>
  127. <div class="info-label-container" v-if="getFieldValue(artifactData, 'texture')">
  128. <div class="info-label">
  129. <span class="info-label-text">材质</span>
  130. <span>{{ getFieldValue(artifactData, 'texture') }}</span>
  131. </div>
  132. <div class="bottom-img"></div>
  133. </div>
  134. </div>
  135. </div>
  136. <div class="artifact-size" v-if="getFieldValue(artifactData, 'size')">
  137. {{ getFieldValue(artifactData, 'size') }}
  138. </div>
  139. <div class="divider">
  140. <span class="divider-text">藏品描述</span>
  141. </div>
  142. <div class="artifact-description">
  143. {{ getFieldValue(artifactData, 'intro') }}
  144. </div>
  145. </div>
  146. </div>
  147. <!-- 加载状态 -->
  148. <div v-if="loading" class="loading-overlay">
  149. <div class="loading-text">加载中...</div>
  150. </div>
  151. </div>
  152. </template>
  153. <script setup>
  154. import { ref, onMounted, nextTick } from 'vue'
  155. import { useRouter, useRoute } from 'vue-router'
  156. import getBookCountApi from '@/api'
  157. import { ZoomIn, ZoomOut } from '@element-plus/icons-vue'
  158. const modelUrl = import.meta.env.VITE_MODEL_URL
  159. const router = useRouter()
  160. const route = useRoute()
  161. const activeTab = ref('model')
  162. const loading = ref(false)
  163. const artifactData = ref({})
  164. const isZoomed = ref(false)
  165. const isFrom = ref('')
  166. const autoplayEnabled = ref(true)
  167. const imageCarouselRef = ref(null)
  168. const currentImageIndex = ref(1)
  169. const modelList = ref([])
  170. const imageList = ref([])
  171. const imgUrl = import.meta.env.VITE_COS_BASE_URL
  172. // 获取字段值的通用方法,优先获取带B后缀的字段
  173. const getFieldValue = (item, fieldName) => {
  174. return item[fieldName]
  175. }
  176. // 初始化模型和图片列表
  177. const initializeLists = () => {
  178. if (!artifactData.value) {
  179. modelList.value = []
  180. imageList.value = []
  181. return
  182. }
  183. // 初始化模型列表
  184. const modelFiles = artifactData.value.modelFiles || []
  185. console.log('modelFiles', modelFiles)
  186. modelList.value = modelFiles.map((modelFile, index) => ({
  187. type: 'model',
  188. src: `${modelUrl}${modelFile}`,
  189. // src: `${modelFile}`,
  190. alt: `${artifactData.value.title || artifactData.value.name} 3D模型${index + 1}`
  191. }))
  192. // 初始化图片列表
  193. const imgFiles = artifactData.value.imageFiles || []
  194. imageList.value = imgFiles.map((imgFile, index) => ({
  195. type: 'image',
  196. src: `${imgUrl}${imgFile}`,
  197. alt: `${artifactData.value.title || artifactData.value.name} 图片${index + 1}`
  198. }))
  199. }
  200. // 返回上一页
  201. const goBack = () => {
  202. // 如果当前URL包含preview=1参数,则在返回时保持该参数
  203. router.replace('/collectpage')
  204. }
  205. const getModelList = (arr) => {
  206. // return ['https://4dscene.4dage.com/culturalrelics/HYBJNG/Model.html?m=hybjn006']
  207. if(arr){
  208. return arr.filter((item) => {return item.indexOf('.4dage') != -1})
  209. } else {
  210. return []
  211. }
  212. }
  213. // 获取文物详情数据
  214. const getArtifactDetail = async () => {
  215. let id
  216. // 从route.query获取id和type
  217. const routeParams = route.query
  218. id = routeParams.id
  219. isFrom.value = routeParams.isFrom
  220. loading.value = true
  221. try {
  222. const response = await getBookCountApi.getArtifactDetailApi(id)
  223. console.log('文物详情数据:', response)
  224. if (response) {
  225. // 处理返回的详情数据,与collectDetails.vue保持一致
  226. artifactData.value = {
  227. id: response.id,
  228. title: response.name || response.title,
  229. name: response.name || response.title,
  230. remark: response.description || response.desc || '暂无描述',
  231. era: response.era || response.agetype || '近现代',
  232. category: response.texturetype1 || '其他',
  233. level: response.level || response.grade || '未定级',
  234. texture: response.material || response.texture || '其他',
  235. size: response.size || response.dimensions,
  236. imageFiles: response.imgFiles || [],
  237. modelFile: response.modelFiles && response.modelFiles.length > 0 ? response.modelFiles[0] : null,
  238. modelFiles: getModelList(response.modelFiles) || [],
  239. hasImage: response.hasImage !== false,
  240. hasModel: response.hasModel !== false
  241. }
  242. // 初始化列表
  243. initializeLists()
  244. }
  245. } catch (error) {
  246. console.error('获取文物详情失败:', error)
  247. } finally {
  248. loading.value = false
  249. }
  250. }
  251. // 图片轮播切换事件
  252. const handleImageCarouselChange = (index) => {
  253. currentImageIndex.value = imageList.value.length > 0 ? index + 1 : 0
  254. }
  255. // 切换标签页
  256. const switchTab = (tab) => {
  257. activeTab.value = tab
  258. if (isZoomed.value) {
  259. toggleZoom()
  260. }
  261. // 重置图片轮播索引
  262. if (tab === 'image') {
  263. currentImageIndex.value = imageList.value.length > 0 ? 1 : 0
  264. }
  265. if (activeTab.value === 'image') {
  266. nextTick(() => {
  267. slideBanner()
  268. })
  269. }
  270. }
  271. // 切换放大缩小状态
  272. const toggleZoom = () => {
  273. isZoomed.value = !isZoomed.value
  274. if (activeTab.value === 'model') {
  275. const dom = document.querySelector('#ifr')
  276. if (dom && dom.contentWindow) {
  277. if (isZoomed.value) {
  278. dom.contentWindow.webview.zoomIn()
  279. } else {
  280. dom.contentWindow.webview.zoomOut()
  281. }
  282. }
  283. }
  284. }
  285. // 重新启动自动播放
  286. const restartAutoplay = () => {
  287. // 通过动态控制autoplay属性来重新启动自动播放
  288. autoplayEnabled.value = false
  289. nextTick(() => {
  290. autoplayEnabled.value = true
  291. })
  292. }
  293. // 滑动切换
  294. const slideBanner = () => {
  295. // 等待DOM更新后再添加事件监听
  296. nextTick(() => {
  297. const box = document.querySelector('.el-carousel__container')
  298. if (!box) return
  299. let startPoint = 0
  300. let stopPoint = 0
  301. let isDragging = false
  302. // 重置坐标
  303. const resetPoint = () => {
  304. startPoint = 0
  305. stopPoint = 0
  306. isDragging = false
  307. }
  308. // 处理滑动切换逻辑
  309. const handleSlideChange = () => {
  310. if (stopPoint === 0 || startPoint - stopPoint === 0) {
  311. resetPoint()
  312. return
  313. }
  314. // 只有图片才支持轮播切换
  315. if (activeTab.value === 'image') {
  316. const currentCarouselRef = imageCarouselRef.value
  317. if (currentCarouselRef) {
  318. if (startPoint - stopPoint > 0) {
  319. // 向左滑动,下一张
  320. currentCarouselRef.next()
  321. } else {
  322. // 向右滑动,上一张
  323. currentCarouselRef.prev()
  324. }
  325. }
  326. }
  327. resetPoint()
  328. }
  329. // 移除之前的事件监听器(避免重复绑定)
  330. box.removeEventListener('touchstart', handleTouchStart)
  331. box.removeEventListener('touchmove', handleTouchMove)
  332. box.removeEventListener('touchend', handleTouchEnd)
  333. box.removeEventListener('mousedown', handleMouseDown)
  334. box.removeEventListener('mousemove', handleMouseMove)
  335. box.removeEventListener('mouseup', handleMouseUp)
  336. box.removeEventListener('mouseleave', handleMouseLeave)
  337. // === 触摸事件处理 ===
  338. // 手指按下
  339. function handleTouchStart(e) {
  340. startPoint = e.changedTouches[0].pageX
  341. }
  342. // 手指滑动
  343. function handleTouchMove(e) {
  344. stopPoint = e.changedTouches[0].pageX
  345. }
  346. // 手指抬起
  347. function handleTouchEnd() {
  348. handleSlideChange()
  349. // 重新启动自动播放
  350. restartAutoplay()
  351. }
  352. // === 鼠标事件处理 ===
  353. // 鼠标按下
  354. function handleMouseDown(e) {
  355. isDragging = true
  356. startPoint = e.pageX
  357. box.style.cursor = 'grabbing'
  358. // 阻止默认的拖拽行为
  359. e.preventDefault()
  360. }
  361. // 鼠标移动
  362. function handleMouseMove(e) {
  363. if (!isDragging) return
  364. stopPoint = e.pageX
  365. // 阻止默认行为
  366. e.preventDefault()
  367. }
  368. // 鼠标抬起
  369. function handleMouseUp() {
  370. if (!isDragging) return
  371. box.style.cursor = 'grab'
  372. handleSlideChange()
  373. // 重新启动自动播放
  374. restartAutoplay()
  375. }
  376. // 鼠标离开容器
  377. function handleMouseLeave() {
  378. if (!isDragging) return
  379. box.style.cursor = 'grab'
  380. handleSlideChange()
  381. // 重新启动自动播放
  382. restartAutoplay()
  383. }
  384. // 添加触摸事件监听器
  385. box.addEventListener('touchstart', handleTouchStart)
  386. box.addEventListener('touchmove', handleTouchMove)
  387. box.addEventListener('touchend', handleTouchEnd)
  388. // 添加鼠标事件监听器
  389. box.addEventListener('mousedown', handleMouseDown)
  390. box.addEventListener('mousemove', handleMouseMove)
  391. box.addEventListener('mouseup', handleMouseUp)
  392. box.addEventListener('mouseleave', handleMouseLeave)
  393. // 设置初始鼠标样式
  394. box.style.cursor = 'grab'
  395. })
  396. }
  397. // 初始化
  398. onMounted(() => {
  399. getArtifactDetail()
  400. })
  401. </script>
  402. <style lang="scss" scoped>
  403. .collect-detail-container {
  404. position: relative;
  405. height: 100vh;
  406. background: #fff;
  407. background-size: cover;
  408. overflow: hidden;
  409. }
  410. .top-navigation {
  411. position: absolute;
  412. top: 0;
  413. left: 0;
  414. right: 0;
  415. display: flex;
  416. align-items: center;
  417. padding: 20px;
  418. z-index: 100;
  419. }
  420. .back-button {
  421. width: 30px;
  422. height: 30px;
  423. border-radius: 50%;
  424. cursor: pointer;
  425. margin-right: 20px;
  426. img {
  427. width: 30px;
  428. height: 30px;
  429. }
  430. }
  431. .custom-tabs {
  432. flex: 1;
  433. display: flex;
  434. justify-content: center;
  435. max-width: 200px;
  436. margin: 0 auto;
  437. .tab-item {
  438. width: 72px;
  439. text-align: center;
  440. color: #ffffff;
  441. font-size: 16px;
  442. cursor: pointer;
  443. transition: all 0.3s ease;
  444. position: relative;
  445. border-bottom: 2px solid transparent;
  446. &.active {
  447. color: #ffffff;
  448. font-weight: bold;
  449. border-bottom-color: #A99271;
  450. }
  451. &:hover:not(.active) {
  452. color: rgba(245, 245, 220, 1);
  453. }
  454. }
  455. }
  456. .content-display {
  457. height: 49%;
  458. background-color: #D1BB9E;
  459. transition: height 0.3s ease;
  460. &.zoomed {
  461. height: 100%;
  462. }
  463. }
  464. .content-area {
  465. margin: 20px 0;
  466. display: flex;
  467. justify-content: center;
  468. }
  469. .carousel-viewer {
  470. position: relative;
  471. width: 100%;
  472. height: 100%;
  473. .empty-state{
  474. width: 100%;
  475. height: 100%;
  476. display: flex;
  477. justify-content: center;
  478. align-items: center;
  479. .empty-content{
  480. text-align: center;
  481. color: #fff;
  482. }
  483. }
  484. }
  485. .carousel-container {
  486. height: 100%;
  487. position: relative;
  488. overflow: hidden;
  489. .carousel-container-model{
  490. height: 100%;
  491. }
  492. .carousel-container-image{
  493. height: 100%;
  494. }
  495. .el-carousel {
  496. height: 100%;
  497. .el-carousel__container {
  498. height: 100%;
  499. }
  500. .el-carousel__item {
  501. display: flex;
  502. justify-content: center;
  503. align-items: center;
  504. height: 100%;
  505. }
  506. /*指示器按钮*/
  507. :deep(.el-carousel__button) {
  508. width: 10px;
  509. height: 10px;
  510. border: none;
  511. border-radius: 50%;
  512. background-color: rgba(255, 255, 255, 0.5);
  513. }
  514. /*指示器激活按钮*/
  515. :deep(.is-active) {
  516. .el-carousel__button {
  517. background-color: #fff;
  518. }
  519. }
  520. }
  521. :deep(.el-carousel__indicators--horizontal){
  522. max-width: 300px;
  523. background: rgba(0,0,0,0.2);
  524. text-align: center;
  525. bottom: 16px;
  526. border-radius: 50px;
  527. padding: 0px 4px 0px 8px;
  528. .el-carousel__indicator--horizontal{
  529. padding: 4px 4px 0 0;
  530. }
  531. }
  532. .model-container {
  533. width: 100%;
  534. height: 100%;
  535. display: flex;
  536. align-items: center;
  537. justify-content: center;
  538. }
  539. .model-item, .image-item {
  540. width: 100%;
  541. height: 100%;
  542. display: flex;
  543. align-items: center;
  544. justify-content: center;
  545. iframe {
  546. width: 100%;
  547. height: 100%;
  548. }
  549. img {
  550. max-width: 100%;
  551. max-height: 100%;
  552. object-fit: contain;
  553. }
  554. }
  555. .carousel-image {
  556. max-width: 100%;
  557. max-height: 100%;
  558. object-fit: contain;
  559. }
  560. }
  561. .zoom-icon {
  562. position: absolute;
  563. bottom: 36px;
  564. right: 16px;
  565. cursor: pointer;
  566. transition: all 0.3s ease;
  567. }
  568. .artifact-info-card {
  569. position: absolute;
  570. top: 44%;
  571. width: 90%;
  572. height: 47%;
  573. background: #F4EFE9;
  574. border-radius: 15px 15px 0 0;
  575. padding: 20px;
  576. margin: 20px 0;
  577. overflow: auto;
  578. transition:
  579. opacity 0.3s ease,
  580. visibility 0.3s ease;
  581. &.hidden {
  582. opacity: 0;
  583. visibility: hidden;
  584. }
  585. .artifact-title {
  586. font-size: 20px;
  587. font-weight: bold;
  588. color: #7C6444;
  589. padding-bottom: 15px;
  590. margin-bottom: 24px;
  591. border-bottom: 1px solid #B49D7E;
  592. }
  593. .info-table {
  594. background: #F4EFE9;
  595. border-radius: 8px;
  596. margin-bottom: 15px;
  597. .info-row {
  598. display: flex;
  599. justify-content: space-between;
  600. margin-bottom: 15px;
  601. gap: 40px;
  602. .info-label-container {
  603. flex: 1;
  604. display: flex;
  605. flex-direction: column;
  606. .info-label {
  607. display: flex;
  608. justify-content: space-between;
  609. font-size: 16px;
  610. color: #464646;
  611. margin-bottom: 4px;
  612. .info-label-text{
  613. font-size: 16px;
  614. color: #D1BB9E;
  615. font-weight: bold;
  616. }
  617. }
  618. .bottom-img {
  619. width: 100%;
  620. height: 2px;
  621. background: url('@/assets/img/line.png') no-repeat center center;
  622. background-size: 100% 100%;
  623. }
  624. }
  625. &:last-child {
  626. margin-bottom: 0;
  627. }
  628. }
  629. }
  630. .artifact-size {
  631. font-size: 14px;
  632. color: #584735;
  633. margin-bottom: 15px;
  634. }
  635. .divider {
  636. width: 100%;
  637. margin: 24px 0;
  638. display: flex;
  639. align-items: center;
  640. .divider-text{
  641. font-size: 16px;
  642. color: #D1BB9E;
  643. font-weight: bold;
  644. }
  645. }
  646. .artifact-description {
  647. font-size: 13px;
  648. line-height: 1.6;
  649. color: #584735;
  650. text-align: justify;
  651. }
  652. }
  653. @media (max-width: 480px) {
  654. .tab-navigation {
  655. max-width: 280px;
  656. margin: 50px auto 15px;
  657. .tab-item {
  658. padding: 8px 15px;
  659. font-size: 13px;
  660. }
  661. }
  662. .artifact-info {
  663. padding: 15px;
  664. .artifact-title {
  665. font-size: 18px;
  666. }
  667. .artifact-description {
  668. font-size: 12px;
  669. }
  670. }
  671. }
  672. .no-video {
  673. height: 96%;
  674. display: flex;
  675. justify-content: center;
  676. align-items: center;
  677. .no-video-text {
  678. color: #fff;
  679. }
  680. }
  681. </style>