fix(plugin): 🐛 display of ai usage times
This commit is contained in:
@@ -431,6 +431,7 @@ pub enum ImUrl {
|
||||
ModelUpdate,
|
||||
ModelDelete,
|
||||
ModelGet,
|
||||
ModelRemainingUsage,
|
||||
ModelPage,
|
||||
ModelSimpleList,
|
||||
|
||||
@@ -709,6 +710,7 @@ impl ImUrl {
|
||||
ImUrl::ModelUpdate => (http::Method::PUT, "ai/model/update"),
|
||||
ImUrl::ModelDelete => (http::Method::DELETE, "ai/model/delete"),
|
||||
ImUrl::ModelGet => (http::Method::GET, "ai/model/get"),
|
||||
ImUrl::ModelRemainingUsage => (http::Method::GET, "ai/model/get-remaining-usage"),
|
||||
ImUrl::ModelPage => (http::Method::GET, "ai/model/page"),
|
||||
ImUrl::ModelSimpleList => (http::Method::GET, "ai/model/simple-list"),
|
||||
|
||||
@@ -1006,6 +1008,7 @@ impl ImUrl {
|
||||
"modelUpdate" => Ok(ImUrl::ModelUpdate),
|
||||
"modelDelete" => Ok(ImUrl::ModelDelete),
|
||||
"modelGet" => Ok(ImUrl::ModelGet),
|
||||
"modelRemainingUsage" => Ok(ImUrl::ModelRemainingUsage),
|
||||
"modelPage" => Ok(ImUrl::ModelPage),
|
||||
"modelSimpleList" => Ok(ImUrl::ModelSimpleList),
|
||||
|
||||
@@ -1033,6 +1036,7 @@ impl ImUrl {
|
||||
|
||||
// ================ 平台配置 ================
|
||||
"platformList" => Ok(ImUrl::PlatformList),
|
||||
"modelRemainingUsage" => Ok(ImUrl::ModelRemainingUsage),
|
||||
"platformAddModel" => Ok(ImUrl::PlatformAddModel),
|
||||
|
||||
// ================ AI 工具 ================
|
||||
|
||||
@@ -839,7 +839,11 @@ export enum ImUrlEnum {
|
||||
CONVERSATION_UPDATE_MY = 'conversationUpdateMy',
|
||||
/** 删除会话 */
|
||||
CONVERSATION_DELETE_MY = 'conversationDeleteMy',
|
||||
/** 模型页面 */
|
||||
/** 获得模型 */
|
||||
MODEL_GET = 'modelGet',
|
||||
/** 获得模型剩余使用次数 */
|
||||
MODEL_REMAINING_USAGE = 'modelRemainingUsage',
|
||||
/** 获得模型分页 */
|
||||
MODEL_PAGE = 'modelPage',
|
||||
/** 创建模型 */
|
||||
MODEL_CREATE = 'modelCreate',
|
||||
|
||||
@@ -51,6 +51,12 @@
|
||||
<n-tag v-if="selectedModel && selectedModel.type === 4" size="small" type="warning">视频</n-tag>
|
||||
<n-tag v-if="selectedModel && selectedModel.type === 7" size="small" type="warning">文生视频</n-tag>
|
||||
<n-tag v-if="selectedModel && selectedModel.type === 8" size="small" type="success">图生视频</n-tag>
|
||||
|
||||
<!-- 剩余次数显示 -->
|
||||
<n-tag v-if="remainingUsage !== null" size="small" :type="remainingUsageTagType" round>
|
||||
剩余次数: {{ remainingUsageDisplay }}
|
||||
</n-tag>
|
||||
|
||||
<n-tag
|
||||
v-else-if="!selectedModel"
|
||||
size="small"
|
||||
@@ -881,6 +887,7 @@ import { ThemeEnum, AiMsgContentTypeEnum } from '@/enums'
|
||||
import 'markstream-vue/index.css'
|
||||
import {
|
||||
modelPage,
|
||||
getModelRemainingUsage,
|
||||
conversationCreateMy,
|
||||
conversationUpdateMy,
|
||||
conversationDeleteMy,
|
||||
@@ -938,6 +945,25 @@ const currentChat = ref({
|
||||
createTime: 0
|
||||
})
|
||||
|
||||
/** 模型剩余使用次数 */
|
||||
const remainingUsage = ref<number | null>(null)
|
||||
const remainingUsageDisplay = computed(() => {
|
||||
if (remainingUsage.value === null) return ''
|
||||
if (remainingUsage.value === -1) return '无限'
|
||||
return String(remainingUsage.value)
|
||||
})
|
||||
const remainingUsageTagType = computed(() => {
|
||||
if (remainingUsage.value === -1) return 'success'
|
||||
if ((remainingUsage.value || 0) > 0) return 'info'
|
||||
return 'error'
|
||||
})
|
||||
|
||||
/** 加载模型剩余使用次数 */
|
||||
const loadRemainingUsage = async (modelId: string) => {
|
||||
if (!modelId) return
|
||||
remainingUsage.value = await getModelRemainingUsage(modelId)
|
||||
}
|
||||
|
||||
// 计算是否是暗色主题,处理空值和未初始化的情况
|
||||
const isDarkTheme = computed(() => {
|
||||
const content = themes.value.content
|
||||
@@ -1378,6 +1404,18 @@ const selectedModel = ref<any>(null)
|
||||
const reasoningEnabled = ref(false)
|
||||
const supportsReasoning = computed(() => Boolean(selectedModel.value?.supportsReasoning))
|
||||
|
||||
watch(
|
||||
selectedModel,
|
||||
(model) => {
|
||||
remainingUsage.value = null
|
||||
const m = model as any
|
||||
if (m && m.id) {
|
||||
void loadRemainingUsage(m.id)
|
||||
}
|
||||
},
|
||||
{ immediate: true }
|
||||
)
|
||||
|
||||
// 模型分页数据
|
||||
const modelPagination = ref({
|
||||
pageNo: 1,
|
||||
@@ -1809,6 +1847,12 @@ const sendAIMessage = async (content: string, model: any) => {
|
||||
}
|
||||
})
|
||||
.catch(() => {})
|
||||
|
||||
// 更新模型剩余使用次数
|
||||
if (model && model.id) {
|
||||
loadRemainingUsage(model.id)
|
||||
}
|
||||
|
||||
if (!messageList.value[aiMessageIndex].reasoningContent) {
|
||||
messageListByConversationId({ conversationId: currentChat.value.id, pageNo: 1, pageSize: 100 })
|
||||
.then((list: any[]) => {
|
||||
@@ -2465,6 +2509,10 @@ const selectModel = async (model: any) => {
|
||||
|
||||
// 可以通过mitt通知其他组件模型已选择
|
||||
useMitt.emit('model-selected', model)
|
||||
|
||||
if (model && model.id) {
|
||||
void loadRemainingUsage(model.id)
|
||||
}
|
||||
}
|
||||
|
||||
// 处理模型分页变化
|
||||
@@ -2788,6 +2836,8 @@ useMitt.on('chat-active', async (e) => {
|
||||
const model = modelList.value.find((m: any) => String(m.id) === String(modelId))
|
||||
if (model) {
|
||||
selectedModel.value = model
|
||||
// 加载剩余次数
|
||||
loadRemainingUsage(model.id)
|
||||
// 如果是音频模型,加载支持的声音列表
|
||||
if (model.type === 3) {
|
||||
await loadAudioVoices(model)
|
||||
@@ -2891,6 +2941,7 @@ const handleRefreshModelList = async () => {
|
||||
const oldType = selectedModel.value.type
|
||||
// 更新为新的模型对象
|
||||
selectedModel.value = { ...updatedModel }
|
||||
loadRemainingUsage(updatedModel.id)
|
||||
console.log('已更新 selectedModel:', selectedModel.value)
|
||||
|
||||
// 如果模型类型从 8 改为其他类型,清空参考图片
|
||||
|
||||
@@ -1028,6 +1028,14 @@ export async function modelDelete(params: { id: string }) {
|
||||
})
|
||||
}
|
||||
|
||||
// 获得模型剩余使用次数
|
||||
export async function getModelRemainingUsage(modelId: string) {
|
||||
return await imRequest({
|
||||
url: ImUrlEnum.MODEL_REMAINING_USAGE,
|
||||
params: { id: modelId }
|
||||
})
|
||||
}
|
||||
|
||||
// ==================== AI 图片生成 ====================
|
||||
|
||||
export async function imageMyPage(params?: { pageNo?: number; pageSize?: number; prompt?: string; status?: number }) {
|
||||
|
||||
Reference in New Issue
Block a user