diff --git a/src/stores/userInfo.js b/src/stores/userInfo.js index f3253c5..14cb713 100644 --- a/src/stores/userInfo.js +++ b/src/stores/userInfo.js @@ -1,5 +1,7 @@ import { ref, computed } from "vue"; import { defineStore } from "pinia"; +import http from '@/io/request'; +import { localCache } from '@/io/cache'; export const useUserInfo = defineStore("userInfo", () => { const userData = ref({}); @@ -7,5 +9,12 @@ export const useUserInfo = defineStore("userInfo", () => { userData.value = data; } - return { userData, updateUserInfo }; + function getUserInfo() { + http.get('/api/user/profile').then(res => { + localCache.set('userInfo', res); + userData.value = res; + }) + }; + + return { userData, updateUserInfo,getUserInfo }; }); diff --git a/src/views/chat/index.vue b/src/views/chat/index.vue index 7f5c03b..c573100 100644 --- a/src/views/chat/index.vue +++ b/src/views/chat/index.vue @@ -22,6 +22,9 @@ name="stop" class="text-white text-26px cursor-pointer mr-28px" > +
+ 剩余字数:{{ surplus }} +
{ return !!userInfo.userData?.id ?? false }) +const surplus = computed(() => { + const { words_count=0 ,words_used = 0} = userInfo.userData?.equity ?? {} + return words_count - words_used +}) + const authModal = useAuthModal() const { proxy } = getCurrentInstance() @@ -133,6 +141,9 @@ const fileLoading = ref(false) const currentChart = computed(() => chatStore.getCurrentChat) + + + async function handleFileChange(file) { if (!isLogin.value) { authModal.setAuthModalType('login') @@ -371,6 +382,7 @@ async function onConversation(action = 'next', file, fileText) { }) } finally { loading.value = false + userInfo.getUserInfo() } }