Optimize the UI of config dialoy

This commit is contained in:
RockYang 2023-04-12 09:02:39 +08:00
parent aef3414928
commit a88f55372c
4 changed files with 50 additions and 40 deletions

View File

@ -8,14 +8,14 @@
title="聊天配置"
>
<div class="user-info">
<el-input v-model="user['api_key']" placeholder="填写你 OpenAI 的 API KEY">
<el-input :value="user['api_key']" placeholder="填写你 OpenAI 的 API KEY">
<template #prepend>API KEY</template>
</el-input>
<el-descriptions
class="margin-top"
title="账户信息"
:column="2"
:column="col"
border
>
@ -125,8 +125,7 @@ import {
UserFilled,
Histogram
} from '@element-plus/icons-vue'
import {getLoginUser} from "@/utils/storage";
import {dateFormat} from "@/utils/libs";
import {isMobile} from "@/utils/libs";
export default defineComponent({
name: 'ConfigDialog',
@ -135,11 +134,16 @@ export default defineComponent({
show: {
type: Boolean,
default: true
},
user: {
type: Object,
default() {
return {}
},
}
},
data() {
return {
user: {},
wechatGroup: "https://img.r9it.com/chatgpt/wechat-group.jpeg",
wechatCard: "https://img.r9it.com/chatgpt/wechat-card.jpeg"
}
@ -151,16 +155,14 @@ export default defineComponent({
} else {
return '15vh';
}
},
col: function () {
return isMobile() ? 1 : 2;
}
},
mounted() {
//
const data = getLoginUser();
if (data !== null) {
this.user = data["user"];
this.user['active_time'] = dateFormat(this.user['active_time']);
this.user['expired_time'] = dateFormat(this.user['expired_time']);
}
},
methods: {
save: function () {

View File

@ -1,4 +1,6 @@
/* eslint-disable no-constant-condition */
import {dateFormat} from "@/utils/libs";
/**
* storage handler
*/
@ -22,4 +24,15 @@ export function getLoginUser() {
export function setLoginUser(user) {
sessionStorage.setItem(SessionUserKey, JSON.stringify(user))
}
export function getUserInfo() {
const data = getLoginUser();
if (data !== null) {
const user = data["user"];
user['active_time'] = dateFormat(user['active_time']);
user['expired_time'] = dateFormat(user['expired_time']);
return user;
}
return {}
}

View File

@ -21,7 +21,7 @@
</el-icon>
</el-button>
<el-button type="info" size="small" class="config" ref="send-btn" circle @click="showConnectDialog = true">
<el-button type="info" size="small" class="config" ref="send-btn" circle @click="configDialog">
<el-icon>
<Tools/>
</el-icon>
@ -65,7 +65,7 @@
</div><!-- end container -->
<config-dialog v-model:show="showConnectDialog"></config-dialog>
<config-dialog v-model:show="showConfigDialog" :user="userInfo"></config-dialog>
<div class="token-dialog">
<el-dialog
@ -107,7 +107,7 @@ import {ElMessage, ElMessageBox} from 'element-plus'
import {Tools, Lock, Delete} from '@element-plus/icons-vue'
import ConfigDialog from '@/components/ConfigDialog.vue'
import {httpPost, httpGet} from "@/utils/http";
import {getSessionId, setLoginUser} from "@/utils/storage";
import {getSessionId, getUserInfo, setLoginUser} from "@/utils/storage";
import hl from 'highlight.js'
import 'highlight.js/styles/a11y-dark.css'
@ -123,8 +123,11 @@ export default defineComponent({
role: 'gpt',
inputValue: '', //
chatBoxHeight: 0, //
showConnectDialog: false,
showConfigDialog: false,
userInfo: {},
showLoginDialog: false,
token: '', // token
replyIcon: 'images/avatar/gpt.png', //
@ -159,6 +162,10 @@ export default defineComponent({
},
methods: {
configDialog: function () {
this.showConfigDialog = true;
this.userInfo = getUserInfo();
},
// socket
connect: function () {
// WebSocket
@ -240,26 +247,6 @@ export default defineComponent({
httpGet("/api/session/get").then(() => {
//
this.connect();
// if (this.connectingMessageBox === null) {
// this.connectingMessageBox = ElMessageBox.confirm(
// '^_^ !',
// '',
// {
// confirmButtonText: '',
// cancelButtonText: '',
// type: 'warning',
// showClose: false,
// closeOnClickModal: false
// }
// ).then(() => {
// this.connect();
// }).catch(() => {
// ElMessage({
// type: 'info',
// message: '',
// })
// })
// }
}).catch((res) => {
if (res.code === 400) {
this.showLoginDialog = true;

View File

@ -19,7 +19,7 @@
</span>
<template #dropdown>
<el-dropdown-menu>
<el-dropdown-item @click="showConnectDialog = true">
<el-dropdown-item @click="configDialog()">
<el-icon>
<Tools/>
</el-icon>
@ -135,7 +135,7 @@
</div>
</el-row>
<config-dialog v-model:show="showConnectDialog"></config-dialog>
<config-dialog v-model:show="showConfigDialog" :user="userInfo"></config-dialog>
<div class="token-dialog">
<el-dialog
@ -189,7 +189,7 @@ import {
} from '@element-plus/icons-vue'
import ConfigDialog from '@/components/ConfigDialog.vue'
import {httpPost, httpGet} from "@/utils/http";
import {getSessionId, setLoginUser} from "@/utils/storage";
import {getSessionId, getUserInfo, setLoginUser} from "@/utils/storage";
import hl from 'highlight.js'
import 'highlight.js/styles/a11y-dark.css'
@ -218,7 +218,10 @@ export default defineComponent({
allChatRoles: [], //
role: 'gpt',
inputValue: '', //
showConnectDialog: false,
showConfigDialog: false, //
userInfo: {},
showLoginDialog: false,
token: '', // token
replyIcon: 'images/avatar/gpt.png', //
@ -258,6 +261,11 @@ export default defineComponent({
},
methods: {
configDialog() {
this.showConfigDialog = true
this.userInfo = getUserInfo();
},
resizeElement: function () {
this.chatBoxHeight = window.innerHeight - 61 - 115 - 38;
this.mainWinHeight = window.innerHeight - 61;