projectImage.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <template>
  2. <view>
  3. <scroll-view
  4. :scroll-with-animation="true"
  5. class="scroll-view"
  6. scroll-y
  7. @scrolltolower="loadMore"
  8. >
  9. <uni-grid :column="2" :highlight="true" :show-border="false" :square="true">
  10. <uni-grid-item v-for="(item, index) in imageList" :key="index"
  11. class="custom-grid-item"
  12. >
  13. <image
  14. :src="item.url"
  15. class="project-image"
  16. mode="aspectFill"
  17. @click="previewImage(index)"
  18. />
  19. </uni-grid-item>
  20. </uni-grid>
  21. <!-- <image-->
  22. <!-- v-for="(item, index) in imageList"-->
  23. <!-- :key="index"-->
  24. <!-- :src="item.url"-->
  25. <!-- class="project-image"-->
  26. <!-- mode="aspectFill"-->
  27. <!-- @click="previewImage(index)"-->
  28. <!-- />-->
  29. </scroll-view>
  30. </view>
  31. </template>
  32. <script setup>
  33. import {onLoad} from '@dcloudio/uni-app'
  34. import {ref, reactive} from 'vue'
  35. import {getOaProjectIndexImg} from "@/api/oa/project";
  36. import config from "@/config";
  37. const imageList = ref([])
  38. const loading = ref(false)
  39. const noMore = ref(false)
  40. const projectData = reactive({
  41. projectId: '',
  42. name: '',
  43. pageNum: 1,
  44. pageSize: 10,
  45. })
  46. onLoad((options) => {
  47. console.log('接收到的参数:', options)
  48. // projectId: "1893214899153747969", projectName: "南通奥特莱斯", timestamp: "1752287330777"
  49. projectData.projectId = options.projectId || ''
  50. projectData.name = decodeURIComponent(options.projectName || '')
  51. // 设置导航栏标题
  52. uni.setNavigationBarTitle({
  53. title: projectData.name
  54. })
  55. // 获取项目图片
  56. getProjectImage()
  57. })
  58. async function getProjectImage() {
  59. if (loading.value || noMore.value) return
  60. loading.value = true
  61. try {
  62. const res = await getOaProjectIndexImg(projectData)
  63. if (res?.accessories) {
  64. const newImages = res.accessories.split(',').filter(url => url.trim())
  65. .map(url => {
  66. let imageUrl = url.trim();
  67. if (!imageUrl.startsWith('http')) {
  68. imageUrl = `${config.baseUrl}${config.apiPrefix}${imageUrl}`;
  69. }
  70. // #ifdef MP-WEIXIN
  71. imageUrl = imageUrl.replace(/^http:/, 'https:');
  72. // #endif
  73. return {url: imageUrl};
  74. })
  75. if (newImages.length === 0) {
  76. noMore.value = true
  77. } else {
  78. imageList.value = [...imageList.value, ...newImages]
  79. projectData.pageNum++
  80. }
  81. }
  82. } catch (error) {
  83. console.error('获取图片失败:', error)
  84. uni.showToast({
  85. title: '加载图片失败',
  86. icon: 'none'
  87. })
  88. } finally {
  89. loading.value = false
  90. }
  91. }
  92. // 加载更多
  93. function loadMore() {
  94. if (!loading.value && !noMore.value) {
  95. getProjectImage()
  96. }
  97. }
  98. // 图片预览
  99. function previewImage(current) {
  100. uni.previewImage({
  101. current,
  102. urls: imageList.value.map(item => item.url),
  103. // #ifdef MP-WEIXIN
  104. // 微信小程序专属配置
  105. indicator: 'number'
  106. // #endif
  107. })
  108. }
  109. </script>
  110. <style scoped>
  111. .scroll-view {
  112. height: 100vh;
  113. padding-bottom: 100rpx;
  114. }
  115. /* 修改网格项的内边距 */
  116. :deep(.custom-grid-item .uni-grid-item__box) {
  117. padding: 20rpx !important;
  118. }
  119. /* 调整图片大小 */
  120. .project-image {
  121. width: 100%;
  122. height: 100%;
  123. border-radius: 10rpx;
  124. }
  125. .loading-more {
  126. display: flex;
  127. justify-content: center;
  128. padding: 20rpx 0;
  129. }
  130. </style>