index.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. <template>
  2. <CommonTopBanner title="村社相册">
  3. <FlexCol gap="gap.md" padding="padding.md">
  4. <SimplePageListLoader :loader="galleryLoader">
  5. <FlexRow
  6. v-if="galleryLoader.list.value && galleryLoader.list.value.length > 0"
  7. wrap
  8. gap="gap.md"
  9. >
  10. <FlexCol
  11. v-for="item in galleryLoader.list.value"
  12. :key="item.id"
  13. :width="galleryItemWidth"
  14. :height="galleryItemHeight"
  15. position="relative"
  16. radius="radius.md"
  17. overflow="hidden"
  18. >
  19. <Image
  20. :src="item.image"
  21. :width="galleryItemWidth"
  22. :height="galleryItemHeight"
  23. mode="aspectFill"
  24. touchable
  25. @click="previewImage(item.image)"
  26. />
  27. <IconButton
  28. v-if="item.userId === authStore.userId"
  29. icon="edit-filling"
  30. shape="round"
  31. :size="30"
  32. :buttonSize="50"
  33. color="white"
  34. backgroundColor="rgba(0,0,0,0.4)"
  35. :buttonStyle="{
  36. position: 'absolute',
  37. right: '20rpx',
  38. top: '20rpx',
  39. }"
  40. @click="editImage(item)"
  41. />
  42. <BackgroundBox
  43. position="absolute"
  44. :inset="{ l: 0, r: 0, b: 0 }"
  45. :padding="[20, 15]"
  46. color1="transparent"
  47. color2="rgba(0,0,0,0.5)"
  48. direction="column"
  49. >
  50. <Text :text="item.desc || '相片'" color="white" fontConfig="contentText" :lines="1" />
  51. <!-- <FlexRow justify="space-between" align="center">
  52. <Avatar :url="item.user.avatar" :size="40" />
  53. <Text :text="item.user.nickname" fontConfig="contentText" />
  54. </FlexRow> -->
  55. </BackgroundBox>
  56. </FlexCol>
  57. <VillageGalleryUpload
  58. :width="galleryItemWidth"
  59. :height="galleryItemHeight"
  60. @click="uploadImage"
  61. />
  62. </FlexRow>
  63. <template #empty>
  64. <Empty description="还没有任何村社照片,快来上传吧">
  65. <Height :height="20" />
  66. <Button type="primary" icon="add" @click="uploadImage">上传图片</Button>
  67. </Empty>
  68. </template>
  69. </SimplePageListLoader>
  70. </FlexCol>
  71. </CommonTopBanner>
  72. </template>
  73. <script setup lang="ts">
  74. import { computed } from 'vue';
  75. import { useSimplePageListLoader } from '@/components/composeabe/loader/SimplePageListLoader';
  76. import { useAuthStore } from '@/store/auth';
  77. import { backAndCallOnPageBack, callPrevOnPageBack, navTo } from '@/components/utils/PageAction';
  78. import { useLoadQuerys } from '@/components/composeabe/LoadQuerys';
  79. import { confirm } from '@/components/dialog/CommonRoot';
  80. import Text from '@/components/basic/Text.vue';
  81. import BackgroundBox from '@/components/display/block/BackgroundBox.vue';
  82. import IconButton from '@/components/basic/IconButton.vue';
  83. import FlexCol from '@/components/layout/FlexCol.vue';
  84. import FlexRow from '@/components/layout/FlexRow.vue';
  85. import SimplePageListLoader from '@/components/loader/SimplePageListLoader.vue';
  86. import CommonTopBanner from '@/common/components/CommonTopBanner.vue';
  87. import Image from '@/components/basic/Image.vue';
  88. import Button from '@/components/basic/Button.vue';
  89. import Empty from '@/components/feedback/Empty.vue';
  90. import Height from '@/components/layout/space/Height.vue';
  91. import GalleryApi, { type GalleryItem } from '@/api/light/GalleryApi';
  92. import VillageGalleryUpload from '../components/VillageGalleryUpload.vue';
  93. import Avatar from '@/components/display/Avatar.vue';
  94. const { querys } = useLoadQuerys({
  95. villageId: 0,
  96. maxCount: 3,
  97. });
  98. const authStore = useAuthStore();
  99. const galleryLoader = useSimplePageListLoader(30, async (page, pageSize) => {
  100. return await GalleryApi.getAlbumList({
  101. villageId: querys.value.villageId,
  102. userId: authStore.userId,
  103. page,
  104. pageSize,
  105. });
  106. });
  107. const galleryItemWidth = 350;
  108. const galleryItemHeight = 230;
  109. const isOverMaxCount = computed(() => galleryLoader.total.value >= querys.value.maxCount);
  110. function previewImage(url: string) {
  111. const urls = galleryLoader.list.value?.map(item => item.image) ?? [];
  112. uni.previewImage({
  113. current: url,
  114. urls,
  115. });
  116. }
  117. function editImage(item: GalleryItem) {
  118. navTo(`/pages/home/village/gallery/upload`, {
  119. id: item.id,
  120. villageId: querys.value.villageId,
  121. desc: item.desc,
  122. image: item.image,
  123. });
  124. }
  125. function uploadImage() {
  126. if (isOverMaxCount.value) {
  127. confirm({
  128. content: '您最多只能上传' + querys.value.maxCount + '张图片哦,升级村社等级可以获得更多照片上传权益',
  129. icon: 'prompt',
  130. confirmText: '去升级',
  131. }).then((res) => {
  132. if (res) {
  133. backAndCallOnPageBack('showVillageUpgrade', {});
  134. }
  135. });
  136. return;
  137. }
  138. navTo('./upload', {
  139. villageId: querys.value.villageId
  140. });
  141. }
  142. defineExpose({
  143. onPageBack: (name: string, data: Record<string, unknown>) => {
  144. if (data.needRefresh) {
  145. galleryLoader.reload();
  146. callPrevOnPageBack('refreshVillageGrallery', { needRefresh: true }, -1);
  147. }
  148. },
  149. });
  150. </script>