update aiChatQuestions.ts from api
This commit is contained in:
@@ -16,6 +16,19 @@
|
||||
<span v-text="question" />
|
||||
</t-button>
|
||||
</div>
|
||||
<t-button
|
||||
v-if="props.quickQuestionList.length"
|
||||
class="refresh-button"
|
||||
variant="text"
|
||||
size="small"
|
||||
:disabled="isRefreshingQuestions"
|
||||
@click="handleRefreshQuestions"
|
||||
>
|
||||
<template #icon>
|
||||
<t-icon name="refresh" class="refresh-icon" :class="{ refreshing: isRefreshingQuestions }" />
|
||||
</template>
|
||||
<span>换一批</span>
|
||||
</t-button>
|
||||
</div>
|
||||
|
||||
<article
|
||||
@@ -65,7 +78,7 @@
|
||||
</div>
|
||||
</template>
|
||||
<script setup lang="ts">
|
||||
import { MarkdownView } from "timi-web";
|
||||
import { MarkdownView, Toolkit } from "timi-web";
|
||||
import type { AiChatMessage } from "@/composables/useAiChat";
|
||||
import AiChatThinking from "@/pages/ai/components/AiChatThinking.vue";
|
||||
|
||||
@@ -82,9 +95,21 @@ interface Props {
|
||||
const props = defineProps<Props>();
|
||||
const emit = defineEmits<{
|
||||
selectQuestion: [question: string];
|
||||
refreshQuestions: [];
|
||||
}>();
|
||||
|
||||
const messageListRef = useTemplateRef<HTMLElement>("messageList");
|
||||
const isRefreshingQuestions = ref(false);
|
||||
|
||||
async function handleRefreshQuestions(): Promise<void> {
|
||||
if (isRefreshingQuestions.value) {
|
||||
return;
|
||||
}
|
||||
isRefreshingQuestions.value = true;
|
||||
emit("refreshQuestions");
|
||||
await Toolkit.sleep(300);
|
||||
isRefreshingQuestions.value = false;
|
||||
}
|
||||
|
||||
async function scrollToBottom(): Promise<void> {
|
||||
await nextTick();
|
||||
@@ -167,17 +192,35 @@ defineExpose({
|
||||
font-size: .8125rem;
|
||||
line-height: 1.5;
|
||||
}
|
||||
}
|
||||
|
||||
.quick-list {
|
||||
gap: .5rem;
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
justify-content: center;
|
||||
.quick-list {
|
||||
gap: .5rem;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
|
||||
.quick-question {
|
||||
max-width: 100%;
|
||||
white-space: normal;
|
||||
.quick-question {
|
||||
overflow: hidden;
|
||||
min-width: 0;
|
||||
max-width: 100%;
|
||||
|
||||
:deep(.t-button__content) {
|
||||
display: block;
|
||||
overflow: hidden;
|
||||
min-width: 0;
|
||||
max-width: 100%;
|
||||
white-space: nowrap;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.refresh-button {
|
||||
margin-top: .75rem;
|
||||
|
||||
.refresh-icon.refreshing {
|
||||
animation: refresh-once .3s var(--tui-bezier);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -347,4 +390,13 @@ defineExpose({
|
||||
transform: translateY(-.1875rem);
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes refresh-once {
|
||||
from {
|
||||
transform: rotate(0);
|
||||
}
|
||||
to {
|
||||
transform: rotate(360deg);
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -5,7 +5,8 @@
|
||||
:messages="messages"
|
||||
:is-generating="isGenerating"
|
||||
:quick-question-list="aiQuickQuestionList"
|
||||
@select-question="selectQuestion"
|
||||
@select-question="submitMessage"
|
||||
@refresh-questions="refreshQuickQuestions"
|
||||
/>
|
||||
<div class="bottom-area">
|
||||
<div v-if="activeToolStatus" class="tool-status">
|
||||
@@ -39,7 +40,7 @@ import type { GaoAiConversation } from "@/api/GaoAiAPI";
|
||||
import AiChatComposer from "@/pages/ai/components/AiChatComposer.vue";
|
||||
import AiConversationList from "@/pages/ai/components/AiConversationList.vue";
|
||||
import AiChatMessageList from "@/pages/ai/components/AiChatMessageList.vue";
|
||||
import { aiQuickQuestionList } from "@/pages/ai/aiChatQuestions";
|
||||
import { aiQuickQuestionList, loadAiQuickQuestions, refreshAiQuickQuestions } from "@/pages/ai/aiChatQuestions";
|
||||
import { useNavBarStore } from "@/store/navBarStore";
|
||||
import { getErrorMessage } from "@/utils/error";
|
||||
import { Message } from "@/utils/message";
|
||||
@@ -110,17 +111,18 @@ function handleConversationDelete(deletedConversationId: string): void {
|
||||
}
|
||||
}
|
||||
|
||||
function selectQuestion(question: string): void {
|
||||
draft.value = question;
|
||||
function refreshQuickQuestions(): void {
|
||||
refreshAiQuickQuestions();
|
||||
}
|
||||
|
||||
async function scrollToBottom(): Promise<void> {
|
||||
await messageListRef.value?.scrollToBottom();
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
onMounted(async () => {
|
||||
navBarStore.clearRight();
|
||||
navBarStore.setRightText("历史", "var(--td-brand-color)", openConversationList);
|
||||
await loadAiQuickQuestions();
|
||||
});
|
||||
|
||||
watch(isBusy, value => navBarStore.setRightDisabled(value));
|
||||
|
||||
@@ -36,7 +36,7 @@
|
||||
<span class="title" v-text="getConversationName(item)" />
|
||||
</template>
|
||||
<template #description>
|
||||
<span v-text="formatConversationTime(item)" />
|
||||
<pass-time-label :timestamp="formatConversationTime(item)" underline />
|
||||
</template>
|
||||
</t-cell>
|
||||
<template #right>
|
||||
@@ -78,6 +78,7 @@ import { DialogPlugin } from "tdesign-mobile-vue";
|
||||
import { deleteConversation as removeConversation, type GaoAiConversation, listConversations } from "@/api/GaoAiAPI";
|
||||
import { getErrorMessage } from "@/utils/error";
|
||||
import { Message } from "@/utils/message";
|
||||
import { PassTimeLabel } from "timi-web";
|
||||
|
||||
defineOptions({
|
||||
name: "AiConversationList"
|
||||
@@ -114,16 +115,6 @@ const deletingId = ref("");
|
||||
let requestToken = 0;
|
||||
let loadingPromise: Promise<void> | undefined;
|
||||
|
||||
const loadStateText = computed(() => {
|
||||
if (isLoading.value && conversationList.value.length) {
|
||||
return "正在加载更多";
|
||||
}
|
||||
if (isNoMore.value) {
|
||||
return conversationList.value.length ? "没有更多会话" : "";
|
||||
}
|
||||
return "上拉加载更多";
|
||||
});
|
||||
|
||||
async function loadMore(): Promise<void> {
|
||||
if (loadingPromise) {
|
||||
await loadingPromise;
|
||||
@@ -240,14 +231,13 @@ function getConversationName(conversation: GaoAiConversation): string {
|
||||
return conversation.name?.trim() || conversation.introduction?.trim() || "未命名会话";
|
||||
}
|
||||
|
||||
function formatConversationTime(conversation: GaoAiConversation): string {
|
||||
function formatConversationTime(conversation: GaoAiConversation): number {
|
||||
const value = conversation["updated_at"] || conversation["created_at"];
|
||||
const timestamp = typeof value === "number" ? value : Number(value);
|
||||
if (!Number.isFinite(timestamp) || timestamp <= 0) {
|
||||
return "时间未知";
|
||||
}
|
||||
const milliseconds = timestamp < 100000000000 ? timestamp * 1000 : timestamp;
|
||||
return new Date(milliseconds).toLocaleString("zh-CN", { hour12: false });
|
||||
return timestamp < 100000000000 ? timestamp * 1000 : timestamp;
|
||||
}
|
||||
|
||||
watch(() => props.visible, async visible => {
|
||||
|
||||
Reference in New Issue
Block a user