Просмотр исходного кода

🎨 按要求增加发贴图话题和预发布文章,控制ai功能

快乐的梦鱼 1 месяц назад
Родитель
Сommit
6596a76d63

+ 3 - 0
src/pages/home/chat/dependent/post/components/tbutton.vue

@@ -33,6 +33,7 @@ const props = defineProps<{
     url: string;
     localUrl: string;
   }|string)[];
+  disabled?: boolean;
 }>();
 
 const emit = defineEmits([ 'showAi' ]);
@@ -64,6 +65,8 @@ function hideTip() {
   bubbleBoxRef.value?.hide();
 }
 function showTip(message: string) {
+  if (props.disabled)
+    return;
   tipDismissed = false;
   currentTipContent.value = message;
   bubbleBoxRef.value?.show();

+ 40 - 0
src/pages/home/chat/dependent/post/composables/file.ts

@@ -0,0 +1,40 @@
+export async function processImages(originalImages: { url: string; localUrl: string }[]) {
+  const processedImages: { url: string; localUrl: string }[] = [];
+  for (const image of originalImages) {
+    if (image.url && isNetworkUrl(image.url) && !image.localUrl) {
+      try {
+        const tempFilePath = await downloadImage(image.url);
+        processedImages.push({
+          url: image.url,
+          localUrl: tempFilePath,
+        });
+      } catch (err) {
+        console.error('图片下载失败:', err);
+        processedImages.push(image);
+      }
+    } else {
+      processedImages.push(image);
+    }
+  }
+  return processedImages;
+}
+export function isNetworkUrl(url: string): boolean {
+  return url.startsWith('http://') || url.startsWith('https://');
+}
+export function downloadImage(url: string): Promise<string> {
+  return new Promise((resolve, reject) => {
+    uni.downloadFile({
+      url: url,
+      success: (res) => {
+        if (res.statusCode === 200) {
+          resolve(res.tempFilePath);
+        } else {
+          reject(new Error('图片下载失败,状态码: ' + res.statusCode));
+        }
+      },
+      fail: (err) => {
+        reject(err);
+      },
+    });
+  });
+}

+ 39 - 9
src/pages/home/chat/dependent/post/publish.vue

@@ -17,6 +17,9 @@
           width="95%"
           :padding="[40, 30]"
         >
+          <FlexCol :padding="[0, 20]">
+            <Text :text="`#${currentTag}`" fontConfig="contentText" />
+          </FlexCol>
           <Field v-model="title" type="text" placeholder="输入标题(可选)" :maxLength="30" />
           <Field 
             v-model="content" 
@@ -26,7 +29,7 @@
             :maxLength="1000" 
             rows="20" 
             :inputStyle="{
-              height: '700rpx',
+              height: '600rpx',
             }"
             showWordLimit 
           />
@@ -38,12 +41,13 @@
             @updateList="onUpdateList"
             @allUploaded="onAllUploaded"
           />
-          <FlexRow justify="flex-end" align="center" gap="gap.md">
+          <FlexRow v-if="!querys.disableAi" justify="flex-end" align="center" gap="gap.md">
             <Button text="AI看图写作" @click="openImageWriting" />
             <Tbutton 
               :title="title"
               :content="content"
               :images="images"
+              :disabled="querys.disableAiPops"
               @showAi="showAgentPopup = true" 
             />
           </FlexRow>
@@ -58,6 +62,7 @@
         </FlexRow>
       </ProvideVar>
       <Agent 
+        v-if="!querys.disableAi" 
         ref="agentRef"
         v-model:showAgentPopup="showAgentPopup"
         v-model:title="title"
@@ -75,14 +80,15 @@
 <script setup lang="ts">
 import { computed, onMounted, ref, watch } from 'vue';
 import { useLoadQuerys } from '@/components/composeabe/LoadQuerys';
-import { Debounce, formatError } from '@imengyu/imengyu-utils';
-import { confirm, toast } from '@/components/dialog/CommonRoot';
+import { useRecharge } from './composables/recharge';
+import { useOfficialAccount } from '@/pages/home/composeabe/OfficialAccount';
 import { useAuthStore } from '@/store/auth';
 import { useSimpleDataLoader } from '@/components/composeabe/loader/SimpleDataLoader';
 import { envVersion, isDevEnv } from '@/common/config/AppCofig';
 import { back, backAndCallOnPageBack } from '@/components/utils/PageAction';
 import { confirm as uniConfirm } from '@/components/utils/DialogAction';
-import { useRecharge } from './composables/recharge';
+import { Debounce, formatError } from '@imengyu/imengyu-utils';
+import { confirm, toast } from '@/components/dialog/CommonRoot';
 import type { UploaderAction, UploaderItem } from '@/components/form/Uploader';
 import BackgroundBox from '@/components/display/block/BackgroundBox.vue';
 import Field from '@/components/form/Field.vue';
@@ -96,14 +102,17 @@ import PrimaryButton from '@/common/components/PrimaryButton.vue';
 import Tbutton from './components/tbutton.vue';
 import Height from '@/components/layout/space/Height.vue';
 import Button from '@/components/basic/Button.vue';
-import OfficialApi, { PostMessage } from '@/api/light/OfficialApi';
 import LightVillageApi from '@/api/light/LightVillageApi';
 import CommonContent from '@/api/CommonContent';
-import { useOfficialAccount } from '@/pages/home/composeabe/OfficialAccount';
+import Text from '@/components/basic/Text.vue';
+import { processImages } from './composables/file';
 
 const { querys } = useLoadQuerys({
   tag: '',
   villageId: 0,
+  entranceContent: '',
+  disableAiPops: false,
+  disableAi: false,
 }, () => {
 
   const info = uni.getSystemInfoSync();
@@ -138,7 +147,6 @@ const { onPublishSuccess, makeOfficialPublishLinkPathAndParams, prePublish } = u
   images: images.value.map((image) => image.localUrl),
 }));
 
-
 const title = ref('');
 const content = ref('');
 const images = ref<{
@@ -166,6 +174,25 @@ const villageInfoForAI = useSimpleDataLoader(async () => {
   return null;
 }, false);
 
+const currentTag = computed(() => querys.value.tag || '亮乡源');
+
+async function loadEntranceContent() {
+  const entranceContent = uni.getStorageSync(querys.value.entranceContent);
+  if (entranceContent) {
+    content.value = entranceContent.content || '';
+    title.value = entranceContent.title || '';
+    const originalImages = entranceContent.images || [];
+    const processedImages = await processImages(originalImages);
+    images.value = processedImages;
+    uploader.value?.setList(processedImages.map((image) => ({
+      url: image.url,
+      type: 'image',
+      filePath: image.localUrl,
+      state: image.url ? 'success' : 'notstart',
+    })));
+  }
+}
+
 const extraInfoFoAi = computed(() => {
   const result = [] as string[];
   result.push('用户正在编写话题:' + 
@@ -297,7 +324,10 @@ defineExpose({
 
 onMounted(() => {
   setTimeout(() => {
-    loadDraft();
+    if (querys.value.entranceContent)
+      loadEntranceContent();
+    else
+      loadDraft();
     if (envVersion === 'develop') {
       //showAgentPopup.value = true;
     }

+ 1 - 0
src/pages/home/village/task/index.vue

@@ -136,6 +136,7 @@ function handleDoTask(item: GrowthTaskItem) {
           });
           navTo('/pages/home/chat/dependent/post/publish', {
             entranceContent: 'ShareAppTempEntranceContent',
+            disableAiPops: true,
           });
           break;
       }