feat: add class share drafts
This commit is contained in:
@@ -9,7 +9,7 @@ import MessageList, { type DisplayMessage } from "./components/MessageList.vue";
|
||||
import SessionDrawer from "./components/SessionDrawer.vue";
|
||||
import SessionQuota from "./components/SessionQuota.vue";
|
||||
import { ApiError, api, clearToken, getToken, streamChat } from "./services/api";
|
||||
import type { ChatMessage as ApiMessage, ChatSession, GrowthProfileResult, TeacherHelpCard, UserProfile } from "./types/api";
|
||||
import type { ChatMessage as ApiMessage, ChatSession, GrowthProfileResult, ShareDraft, TeacherHelpCard, UserProfile } from "./types/api";
|
||||
|
||||
const user = ref<UserProfile | null>(null);
|
||||
const sessions = ref<ChatSession[]>([]);
|
||||
@@ -24,12 +24,16 @@ const sessionOperationPending = ref(false);
|
||||
const logoutDialogOpen = ref(false);
|
||||
const profileDialogOpen = ref(false);
|
||||
const helpCardDialogOpen = ref(false);
|
||||
const shareDraftDialogOpen = ref(false);
|
||||
const growthProfile = ref<GrowthProfileResult | null>(null);
|
||||
const helpCard = ref<TeacherHelpCard | null>(null);
|
||||
const helpCardContent = ref("");
|
||||
const shareDraft = ref<ShareDraft | null>(null);
|
||||
const shareDraftContent = ref("");
|
||||
const profileLoading = ref(false);
|
||||
const finishingTopic = ref(false);
|
||||
const generatingHelpCard = ref(false);
|
||||
const generatingShareDraft = ref(false);
|
||||
const statusText = ref("连接后端中");
|
||||
const toastText = ref("");
|
||||
const followingOutput = ref(true);
|
||||
@@ -251,6 +255,39 @@ async function copyHelpCard() {
|
||||
}
|
||||
}
|
||||
|
||||
async function generateShareDraft() {
|
||||
if (!activeSessionId.value || sending.value || generatingShareDraft.value) return;
|
||||
generatingShareDraft.value = true;
|
||||
try {
|
||||
const result = await api.generateShareDraft(activeSessionId.value);
|
||||
shareDraft.value = result;
|
||||
shareDraftContent.value = result.content;
|
||||
shareDraftDialogOpen.value = true;
|
||||
showToast("分享稿已生成,可编辑后复制");
|
||||
await refreshProfile();
|
||||
} catch (error) {
|
||||
handleError(error, "分享稿生成失败");
|
||||
} finally {
|
||||
generatingShareDraft.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function copyShareDraft() {
|
||||
if (!shareDraftContent.value.trim()) {
|
||||
showToast("分享稿内容为空");
|
||||
return;
|
||||
}
|
||||
try {
|
||||
await copyText(shareDraftContent.value);
|
||||
if (shareDraft.value) {
|
||||
shareDraft.value = await api.markShareDraftCopied(shareDraft.value.id);
|
||||
}
|
||||
showToast("已复制,可粘贴到班级群");
|
||||
} catch (error) {
|
||||
handleError(error, "复制失败,请手动选择文本复制");
|
||||
}
|
||||
}
|
||||
|
||||
async function openGrowthProfile() {
|
||||
profileDialogOpen.value = true;
|
||||
profileLoading.value = true;
|
||||
@@ -394,9 +431,11 @@ async function copyText(text: string) {
|
||||
:entitlement="user.entitlement"
|
||||
:finishing="finishingTopic"
|
||||
:generating-help-card="generatingHelpCard"
|
||||
:generating-share-draft="generatingShareDraft"
|
||||
@finish-topic="finishCurrentTopic"
|
||||
@open-profile="openGrowthProfile"
|
||||
@generate-help-card="generateHelpCard"
|
||||
@generate-share-draft="generateShareDraft"
|
||||
/>
|
||||
<MessageList
|
||||
ref="messageList"
|
||||
@@ -459,6 +498,19 @@ async function copyText(text: string) {
|
||||
</template>
|
||||
</AppDialog>
|
||||
|
||||
<AppDialog v-if="shareDraftDialogOpen" title="班级分享稿" labelled-by="share-draft-title" @close="shareDraftDialogOpen = false">
|
||||
<section class="help-card-dialog">
|
||||
<p>这只是分享草稿,系统不会自动发送到任何群。请删掉不想公开的隐私内容,并按自己的真实状态修改后再复制。</p>
|
||||
<textarea v-model="shareDraftContent" aria-label="班级分享稿内容" />
|
||||
</section>
|
||||
<template #footer>
|
||||
<div class="dialog-actions">
|
||||
<button type="button" class="dialog-secondary" @click="shareDraftDialogOpen = false">关闭</button>
|
||||
<button type="button" class="dialog-primary" @click="copyShareDraft">复制分享稿</button>
|
||||
</div>
|
||||
</template>
|
||||
</AppDialog>
|
||||
|
||||
<AppDialog v-if="logoutDialogOpen" title="退出登录" labelled-by="logout-dialog-title" @close="logoutDialogOpen = false">
|
||||
<p class="confirm-copy">确定退出当前账号吗?</p>
|
||||
<template #footer>
|
||||
|
||||
Reference in New Issue
Block a user