PaintingDetail.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <script setup>
  2. import { onMounted, inject, computed } from 'vue'
  3. import { useRoute, useRouter } from 'vue-router'
  4. import PaintingDetailBox from '@/components/PaintingDetailBox.vue'
  5. import paintingInfoBox from '@/components/PaintingInfoBox.vue'
  6. const route = useRoute()
  7. const router = useRouter()
  8. // 可当普通组件传入或者当作路由界面使用
  9. const usageState = computed(() =>{
  10. if (route.query.idx) {
  11. return 'newPage'
  12. }
  13. return 'component'
  14. })
  15. // 当组件使用时需要传入的参数
  16. const props = defineProps({
  17. // 画作id(和路由参数一样)
  18. idx: {
  19. type: String,
  20. default: '0',
  21. },
  22. // 状态
  23. state: {
  24. type: String,
  25. default: '1',
  26. },
  27. })
  28. // 返回按钮触发的行为
  29. const emit = defineEmits(['close'])
  30. const $env = inject("$env")
  31. const getPaintingSize = (raw) => {
  32. const temp = raw.split('\n')
  33. let height = temp[0]
  34. let width = temp[1]
  35. height = Number(height.substring(1, height.length - 2))
  36. width = Number(width.substring(1, width.length - 2))
  37. return {
  38. width,
  39. height,
  40. }
  41. }
  42. const realState = computed(() => {
  43. if (props.state === '2' || route.query.state === '2') {
  44. return 2
  45. }
  46. return 1
  47. })
  48. // idx 传入下标index
  49. const paintingInfo = route.query.idx == 'home' || props.idx == 'home' ? configExcel['首页画作'][0] : configExcel['画作'][usageState.value == 'newPage' ? route.query.idx : props.idx]
  50. // const paintingInfo = route.query.idx == 'home' ? configExcel['首页画作'][0] : configExcel['画作'][route.query.idx]
  51. onMounted(() => {
  52. // if (usageState.value == 'newPage') {
  53. // paintingInfo = route.query.idx == 'home' ? configExcel['首页画作'][0] : configExcel['画作'][route.query.idx]
  54. // } else if (usageState.value == 'component') {
  55. // paintingInfo = props.idx == 'home' ? configExcel['首页画作'][0] : configExcel['画作'][props.idx]
  56. // }
  57. console.log('看看检索', props.state == '2', realState.value, paintingInfo['作者简介'])
  58. })
  59. </script>
  60. <template>
  61. <div class="home">
  62. <img
  63. class="img-bg"
  64. src="@/assets/images/painting-detail-bg.jpg"
  65. alt=""
  66. >
  67. <!-- 左侧图片交互区 -->
  68. <PaintingDetailBox
  69. :idx="route.query.idx ? route.query.idx : props.idx"
  70. :direction="paintingInfo['方向'] ? '横':'竖'"
  71. :big-url="`${$env.BASE_URL}configMultiMedia/paintings/${paintingInfo['标题']=='修篁树石图' ? 'home-painting2':paintingInfo['标题']}.jpg`"
  72. :url="`${$env.BASE_URL}configMultiMedia/paintings/${paintingInfo['标题']}.jpg`"
  73. />
  74. <!-- 右侧信息展示区 -->
  75. <paintingInfoBox
  76. :title="paintingInfo['标题(展示)']"
  77. :author="paintingInfo['注音']?paintingInfo['注音']:paintingInfo['作者']"
  78. :age="paintingInfo['朝代']"
  79. :subtitle="paintingInfo['装裱\/材质\/笔类型']"
  80. :location="paintingInfo['馆藏']"
  81. :painting-desc="paintingInfo['简介']"
  82. :author-info="paintingInfo['作者信息']"
  83. :author-desc="paintingInfo['作者简介']"
  84. :size="paintingInfo['尺寸'] ? getPaintingSize(paintingInfo['尺寸']) : ''"
  85. :state="realState"
  86. />
  87. <BtnBack @click="() => usageState ==='component' ? emit('close'):router.back()" />
  88. </div>
  89. </template>
  90. <style lang='less' scoped>
  91. .home{
  92. width: 100%;
  93. height: 100%;
  94. // background: linear-gradient( 180deg, #AFCEA5 0%, #34492E 100%);
  95. // background: url(@/assets/images/painting-detail-bg.jpg);
  96. // background-size: 100% 100%;
  97. display:flex;
  98. .img-bg{
  99. width: 100%;
  100. height: 100%;
  101. object-fit: cover;
  102. position: absolute;
  103. top: 0;
  104. left: 0
  105. }
  106. }
  107. </style>