瀏覽代碼

📦 村社相册上传

快乐的梦鱼 1 月之前
父節點
當前提交
e883590223

+ 10 - 0
src/api/CommonContent.ts

@@ -489,6 +489,16 @@ export class CommonContentApi extends AppServerRequestModule<DataModel> {
         receiveTask(task);
     })
   }
+
+  /**
+   * 上传图片
+   * @param tempFilePath 临时文件路径
+   * @returns 
+   */
+  async uploadImages(tempFilePath: string) {
+    const res = await this.uploadFile(tempFilePath, 'image');
+    return res.fullurl;
+  }
 }
 
 export default new CommonContentApi(undefined, 0, '默认通用内容');

+ 5 - 0
src/api/inhert/VillageInfoApi.ts

@@ -312,6 +312,11 @@ export class VillageInfoApi extends AppServerRequestModule<DataModel> {
       res[subKey] = subId;
     return (await this.post(`/village/collect/save`, '通用更新信息详情', res));
   }
+  async getInfoByVillageId(id: number) {
+    return (await this.post(`/village/village/getInfo`, '获取村社信息', {
+      id,
+    }, undefined, VillageListItem)).data as VillageListItem
+  }
 }
 
 export default new VillageInfoApi();

+ 7 - 0
src/api/light/LightVillageApi.ts

@@ -241,6 +241,13 @@ export class LightVillageApi extends AppServerRequestModule<DataModel> {
   async publishMessage(params: PostMessage) {
     return await this.post<KeyValue>('/village/collect/wechatContentSave', '发布微信贴图', params.toServerSide());
   }
+
+  async updateVillageGallery(id: number, images: string[]) {
+    return await this.post<KeyValue>('/village/village/save', '更新村社相册', {
+      id: id,
+      images: images,
+    });
+  }
 }
 
 

+ 88 - 0
src/pages/home/village/components/VillageGallery.vue

@@ -0,0 +1,88 @@
+<template>
+  <FlexRow justify="space-between">
+    <Image 
+      v-for="index of 3" 
+      :key="index" 
+      :src="images[index - 1]" 
+      radius="radius.md"
+      :width="200"
+      :height="140"
+      mode="aspectFill"
+      defaultImage=""
+      touchable
+    >
+      <template #empty>
+        <Touchable
+          direction="column" 
+          position="absolute" 
+          inset="0" 
+          center
+          backgroundColor="background.primary"
+          @click="uploadImage(index)"
+        >
+          <Icon name="add" size="fontSize.md" />
+          <Text text="上传封面" fontConfig="secondText" />
+        </Touchable>
+      </template>
+      <!-- <FlexCol 
+        v-if="index === 3 && images.length >= 3" 
+        position="absolute" inset="0" 
+        center 
+        backgroundColor="mask.default"
+      >
+        <Text :text="`更多相册`" fontSize="fontSize.lg" color="white" />
+      </FlexCol> -->
+    </Image>
+  </FlexRow>
+
+</template>
+
+<script setup lang="ts">
+import FlexRow from '@/components/layout/FlexRow.vue';
+import Image from '@/components/basic/Image.vue';
+import Touchable from '@/components/feedback/Touchable.vue';
+import Icon from '@/components/basic/Icon.vue';
+import Text from '@/components/basic/Text.vue';
+import CommonContent from '@/api/CommonContent';
+import { showError } from '@/common/composeabe/ErrorDisplay';
+import { toast } from '@/components/utils/DialogAction';
+import LightVillageApi from '@/api/light/LightVillageApi';
+
+const props = withDefaults(defineProps<{
+  villageId: number;
+  images?: string[];
+}>(), {
+  images: () => [],
+});
+const emit = defineEmits<{
+  (e: 'update:images', images: string[]): void;
+}>();
+
+async function uploadImage(index: number) {
+  const tempFilePath = await new Promise<string>((resolve, reject) => {
+    uni.chooseImage({
+      count: 1,
+      sizeType: ['original', 'compressed'],
+      sourceType: ['album', 'camera'],
+      success: (res) => {
+        resolve(res.tempFilePaths[0]);
+      },
+    });
+  });
+
+  try {
+    const image = await CommonContent.uploadImages(tempFilePath);
+    if (image) {
+      if (props.images.length >= index)
+        props.images[index - 1] = image;
+      else
+        props.images.push(image);
+    }
+    toast('上传成功');
+    await LightVillageApi.updateVillageGallery(props.villageId, props.images);
+    emit('update:images', props.images);
+  } catch (error) {
+    showError(error);
+  }
+}
+</script>

+ 1 - 1
src/pages/home/village/dialogs/JoinDialog.vue

@@ -1,5 +1,5 @@
 <template>
-  <CommonDialog v-model:show="show" title="加入村社" :showDivider="false" :showCloseButton="false">
+  <CommonDialog v-model:show="show" title="加入村社" :showDivider="false">
     <FlexCol gap="gap.lg" padding="padding.md" width="600rpx">
       
       <template v-if="step === 'chooseType'">