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

View File

@@ -1,4 +1,6 @@
/* eslint-disable no-constant-condition */ /* eslint-disable no-constant-condition */
import {dateFormat} from "@/utils/libs";
/** /**
* storage handler * storage handler
*/ */
@@ -22,4 +24,15 @@ export function getLoginUser() {
export function setLoginUser(user) { export function setLoginUser(user) {
sessionStorage.setItem(SessionUserKey, JSON.stringify(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-icon>
</el-button> </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> <el-icon>
<Tools/> <Tools/>
</el-icon> </el-icon>
@@ -65,7 +65,7 @@
</div><!-- end container --> </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"> <div class="token-dialog">
<el-dialog <el-dialog
@@ -107,7 +107,7 @@ import {ElMessage, ElMessageBox} from 'element-plus'
import {Tools, Lock, Delete} from '@element-plus/icons-vue' import {Tools, Lock, Delete} from '@element-plus/icons-vue'
import ConfigDialog from '@/components/ConfigDialog.vue' import ConfigDialog from '@/components/ConfigDialog.vue'
import {httpPost, httpGet} from "@/utils/http"; 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 hl from 'highlight.js'
import 'highlight.js/styles/a11y-dark.css' import 'highlight.js/styles/a11y-dark.css'
@@ -123,8 +123,11 @@ export default defineComponent({
role: 'gpt', role: 'gpt',
inputValue: '', // 聊天内容 inputValue: '', // 聊天内容
chatBoxHeight: 0, // 聊天内容框高度 chatBoxHeight: 0, // 聊天内容框高度
showConnectDialog: false,
showConfigDialog: false,
userInfo: {},
showLoginDialog: false, showLoginDialog: false,
token: '', // 会话 token token: '', // 会话 token
replyIcon: 'images/avatar/gpt.png', // 回复信息的头像 replyIcon: 'images/avatar/gpt.png', // 回复信息的头像
@@ -159,6 +162,10 @@ export default defineComponent({
}, },
methods: { methods: {
configDialog: function () {
this.showConfigDialog = true;
this.userInfo = getUserInfo();
},
// 创建 socket 会话连接 // 创建 socket 会话连接
connect: function () { connect: function () {
// 初始化 WebSocket 对象 // 初始化 WebSocket 对象
@@ -240,26 +247,6 @@ export default defineComponent({
httpGet("/api/session/get").then(() => { httpGet("/api/session/get").then(() => {
// 自动重新连接 // 自动重新连接
this.connect(); 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) => { }).catch((res) => {
if (res.code === 400) { if (res.code === 400) {
this.showLoginDialog = true; this.showLoginDialog = true;

View File

@@ -19,7 +19,7 @@
</span> </span>
<template #dropdown> <template #dropdown>
<el-dropdown-menu> <el-dropdown-menu>
<el-dropdown-item @click="showConnectDialog = true"> <el-dropdown-item @click="configDialog()">
<el-icon> <el-icon>
<Tools/> <Tools/>
</el-icon> </el-icon>
@@ -135,7 +135,7 @@
</div> </div>
</el-row> </el-row>
<config-dialog v-model:show="showConnectDialog"></config-dialog> <config-dialog v-model:show="showConfigDialog" :user="userInfo"></config-dialog>
<div class="token-dialog"> <div class="token-dialog">
<el-dialog <el-dialog
@@ -189,7 +189,7 @@ import {
} from '@element-plus/icons-vue' } from '@element-plus/icons-vue'
import ConfigDialog from '@/components/ConfigDialog.vue' import ConfigDialog from '@/components/ConfigDialog.vue'
import {httpPost, httpGet} from "@/utils/http"; 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 hl from 'highlight.js'
import 'highlight.js/styles/a11y-dark.css' import 'highlight.js/styles/a11y-dark.css'
@@ -218,7 +218,10 @@ export default defineComponent({
allChatRoles: [], // 所有角色集合 allChatRoles: [], // 所有角色集合
role: 'gpt', role: 'gpt',
inputValue: '', // 聊天内容 inputValue: '', // 聊天内容
showConnectDialog: false,
showConfigDialog: false, // 显示配置对话框
userInfo: {},
showLoginDialog: false, showLoginDialog: false,
token: '', // 会话 token token: '', // 会话 token
replyIcon: 'images/avatar/gpt.png', // 回复信息的头像 replyIcon: 'images/avatar/gpt.png', // 回复信息的头像
@@ -258,6 +261,11 @@ export default defineComponent({
}, },
methods: { methods: {
configDialog() {
this.showConfigDialog = true
this.userInfo = getUserInfo();
},
resizeElement: function () { resizeElement: function () {
this.chatBoxHeight = window.innerHeight - 61 - 115 - 38; this.chatBoxHeight = window.innerHeight - 61 - 115 - 38;
this.mainWinHeight = window.innerHeight - 61; this.mainWinHeight = window.innerHeight - 61;