mirror of
https://gh-proxy.org/https://github.com/klinsmaya/SQLBot.git
synced 2026-11-09 01:36:57 +08:00
perf: UI
This commit is contained in:
@@ -22,7 +22,6 @@ from apps.chat.models.chat_model import ChatQuestion, ChatRecord, Chat
|
||||
from apps.datasource.crud.datasource import get_table_schema
|
||||
from apps.datasource.models.datasource import CoreDatasource
|
||||
from apps.db.db import exec_sql
|
||||
from apps.system.crud.user import get_user_info
|
||||
from common.core.config import settings
|
||||
from common.core.deps import SessionDep, CurrentUser
|
||||
|
||||
@@ -70,8 +69,7 @@ class LLMService:
|
||||
if ds:
|
||||
chat_question.db_schema = get_table_schema(session=self.session, ds=ds)
|
||||
|
||||
db_user = get_user_info(session=self.session, user_id=current_user.id)
|
||||
chat_question.lang = db_user.language
|
||||
chat_question.lang = current_user.language
|
||||
|
||||
self.ds = CoreDatasource(**ds.model_dump()) if ds else None
|
||||
self.chat_question = chat_question
|
||||
|
||||
@@ -1,19 +1,18 @@
|
||||
from fastapi import APIRouter
|
||||
from apps.system.crud.user import get_db_user, get_user_info
|
||||
from apps.system.crud.user import get_db_user
|
||||
from apps.system.models.user import UserModel
|
||||
from apps.system.schemas.system_schema import PwdEditor, UserCreator, UserEditor, UserGrid, UserLanguage
|
||||
from common.core.deps import CurrentUser, SessionDep
|
||||
from common.core.pagination import Paginator
|
||||
from common.core.schemas import PaginatedResponse, PaginationParams
|
||||
from common.core.security import md5pwd, verify_md5pwd
|
||||
from common.utils.time import get_timestamp
|
||||
|
||||
router = APIRouter(tags=["user"], prefix="/user")
|
||||
|
||||
|
||||
@router.get("/info")
|
||||
async def user_info(session: SessionDep, current_user: CurrentUser):
|
||||
db_user = get_user_info(session=session, user_id=current_user.id)
|
||||
db_user = get_db_user(session=session, user_id=current_user.id)
|
||||
if not db_user:
|
||||
return {"message": "User not found"}
|
||||
db_user.password = None
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<script lang="ts" setup>
|
||||
import { ref } from 'vue'
|
||||
import { computed, ref } from 'vue'
|
||||
import Default_avatar from '@/assets/svg/icon-member-default.svg'
|
||||
import icon_admin_outlined from '@/assets/svg/icon_admin_outlined.svg'
|
||||
import icon_maybe_outlined from '@/assets/svg/icon-maybe_outlined.svg'
|
||||
@@ -12,16 +12,19 @@ import { useI18n } from 'vue-i18n'
|
||||
import PwdForm from './PwdForm.vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { useUserStore } from '@/stores/user'
|
||||
import { userApi } from '@/api/auth'
|
||||
const router = useRouter()
|
||||
const userStore = useUserStore()
|
||||
const pwdFormRef = ref()
|
||||
const { t } = useI18n()
|
||||
const { t, locale } = useI18n()
|
||||
defineProps({
|
||||
collapse: { type: [Boolean], required: true },
|
||||
})
|
||||
|
||||
const name = ref('飞小致')
|
||||
const currentLanguage = ref('zh-CN')
|
||||
const name = computed(() => userStore.getName)
|
||||
const account = computed(() => userStore.getAccount)
|
||||
const currentLanguage = computed(() => userStore.getLanguage)
|
||||
const isAdmin = computed(() => userStore.getUid === '1')
|
||||
const emit = defineEmits(['selectPerson'])
|
||||
const dialogVisible = ref(false)
|
||||
const languageList = [
|
||||
@@ -30,20 +33,25 @@ const languageList = [
|
||||
value: 'en',
|
||||
},
|
||||
{
|
||||
name: '简体中文',
|
||||
name: '中文',
|
||||
value: 'zh-CN',
|
||||
},
|
||||
} /* ,
|
||||
{
|
||||
name: '繁體中文',
|
||||
value: 'zh-CN',
|
||||
},
|
||||
}, */,
|
||||
]
|
||||
const handlePersonChange = () => {
|
||||
emit('selectPerson')
|
||||
}
|
||||
|
||||
const handleDefaultLanguageChange = (item: any) => {
|
||||
currentLanguage.value = item.value
|
||||
const changeLanguage = (lang: string) => {
|
||||
locale.value = lang
|
||||
userStore.setLanguage(lang)
|
||||
const param = {
|
||||
language: lang,
|
||||
}
|
||||
userApi.language(param)
|
||||
}
|
||||
|
||||
const openPwd = () => {
|
||||
@@ -78,9 +86,9 @@ const logout = () => {
|
||||
<Default_avatar></Default_avatar>
|
||||
</el-icon>
|
||||
<div class="top">{{ name }}</div>
|
||||
<div class="bottom">feixaozhi</div>
|
||||
<div class="bottom">{{ account }}</div>
|
||||
</div>
|
||||
<div class="popover-item" @click="handlePersonChange">
|
||||
<div v-if="isAdmin" class="popover-item" @click="handlePersonChange">
|
||||
<el-icon size="16">
|
||||
<icon_admin_outlined></icon_admin_outlined>
|
||||
</el-icon>
|
||||
@@ -110,7 +118,7 @@ const logout = () => {
|
||||
:key="ele.name"
|
||||
class="popover-item_language"
|
||||
:class="currentLanguage === ele.value && 'isActive'"
|
||||
@click="handleDefaultLanguageChange(ele)"
|
||||
@click="changeLanguage(ele.value)"
|
||||
>
|
||||
<div class="language-name">{{ ele.name }}</div>
|
||||
<el-icon size="16" class="done">
|
||||
@@ -256,6 +264,12 @@ const logout = () => {
|
||||
padding-right: 8px;
|
||||
position: relative;
|
||||
cursor: pointer;
|
||||
&:hover {
|
||||
background-color: #1f23291a;
|
||||
}
|
||||
&:active {
|
||||
background-color: #1f232926;
|
||||
}
|
||||
.datasource-name {
|
||||
margin-left: 8px;
|
||||
}
|
||||
|
||||
@@ -18,9 +18,12 @@ export const watchRouter = (router: any) => {
|
||||
next('/login')
|
||||
return
|
||||
}
|
||||
if (!wsCache.get('user.uid')) {
|
||||
if (!userStore.getUid) {
|
||||
await userStore.info()
|
||||
}
|
||||
/* if (!wsCache.get('user.uid')) {
|
||||
await userStore.info()
|
||||
} */
|
||||
if (to.path === '/') {
|
||||
next('/chat')
|
||||
return
|
||||
|
||||
@@ -10,6 +10,7 @@ const { wsCache } = useCache()
|
||||
interface UserState {
|
||||
token: string
|
||||
uid: string
|
||||
account: string
|
||||
name: string
|
||||
oid: string
|
||||
language: string
|
||||
@@ -23,6 +24,7 @@ export const UserStore = defineStore('user', {
|
||||
return {
|
||||
token: '',
|
||||
uid: '',
|
||||
account: '',
|
||||
name: '',
|
||||
oid: '',
|
||||
language: 'zh-CN',
|
||||
@@ -37,6 +39,9 @@ export const UserStore = defineStore('user', {
|
||||
getUid(): string {
|
||||
return this.uid
|
||||
},
|
||||
getAccount(): string {
|
||||
return this.account
|
||||
},
|
||||
getName(): string {
|
||||
return this.name
|
||||
},
|
||||
@@ -67,7 +72,7 @@ export const UserStore = defineStore('user', {
|
||||
const res: any = await AuthApi.info()
|
||||
const res_data = res || {}
|
||||
|
||||
const keys = ['uid', 'name', 'oid', 'language', 'exp', 'time'] as const
|
||||
const keys = ['uid', 'account', 'name', 'oid', 'language', 'exp', 'time'] as const
|
||||
|
||||
keys.forEach((key) => {
|
||||
const dkey = key === 'uid' ? 'id' : key
|
||||
@@ -98,6 +103,10 @@ export const UserStore = defineStore('user', {
|
||||
wsCache.set('user.uid', uid)
|
||||
this.uid = uid
|
||||
},
|
||||
setAccount(account: string) {
|
||||
wsCache.set('user.account', account)
|
||||
this.account = account
|
||||
},
|
||||
setName(name: string) {
|
||||
wsCache.set('user.name', name)
|
||||
this.name = name
|
||||
@@ -118,8 +127,9 @@ export const UserStore = defineStore('user', {
|
||||
// locale.setLang(language)
|
||||
},
|
||||
clear() {
|
||||
const keys: string[] = ['token', 'uid', 'name', 'oid', 'language', 'exp', 'time']
|
||||
const keys: string[] = ['token', 'uid', 'account', 'name', 'oid', 'language', 'exp', 'time']
|
||||
keys.forEach((key) => wsCache.delete('user.' + key))
|
||||
this.$reset()
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user