PaintingDetail.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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)
  58. })
  59. </script>
  60. <template>
  61. <div class="home">
  62. <!-- 左侧图片交互区 -->
  63. <PaintingDetailBox
  64. :direction="paintingInfo['方向'] ? '横':'竖'"
  65. :url="`${$env.BASE_URL}configMultiMedia/paintings/${paintingInfo['标题']}.jpg`"
  66. />
  67. <!-- 右侧信息展示区 -->
  68. <paintingInfoBox
  69. :title="paintingInfo['标题(展示)']"
  70. :author="paintingInfo['注音']?paintingInfo['注音']:paintingInfo['作者']"
  71. :age="paintingInfo['朝代']"
  72. :subtitle="paintingInfo['装裱\/材质\/笔类型']"
  73. :location="paintingInfo['馆藏']"
  74. :painting-desc="paintingInfo['简介']"
  75. :author-desc="paintingInfo['作者简介']"
  76. :size="paintingInfo['尺寸'] ? getPaintingSize(paintingInfo['尺寸']) : ''"
  77. :state="realState"
  78. />
  79. <BtnBack @click="() => usageState ==='component' ? emit('close'):router.back()" />
  80. </div>
  81. </template>
  82. <style lang='less' scoped>
  83. .home{
  84. width: 100%;
  85. height: 100%;
  86. background: linear-gradient( 180deg, #AFCEA5 0%, #34492E 100%);
  87. display:flex;
  88. }
  89. </style>