opt: refactor the web page's router and layout

This commit is contained in:
RockYang 2023-09-08 22:14:58 +08:00
parent c3f016eae8
commit 4b46d847f0
5 changed files with 60 additions and 52 deletions

View File

@ -134,6 +134,7 @@ func (h *ChatHandler) ChatHandle(c *gin.Context) {
err = h.sendMessage(ctx, session, chatRole, message, client) err = h.sendMessage(ctx, session, chatRole, message, client)
if err != nil { if err != nil {
logger.Error(err) logger.Error(err)
utils.ReplyChunkMessage(client, types.WsMessage{Type: types.WsEnd})
} else { } else {
utils.ReplyChunkMessage(client, types.WsMessage{Type: types.WsEnd}) utils.ReplyChunkMessage(client, types.WsMessage{Type: types.WsEnd})
logger.Info("回答完毕: " + string(message)) logger.Info("回答完毕: " + string(message))
@ -272,7 +273,11 @@ func (h *ChatHandler) sendMessage(ctx context.Context, session *types.ChatSessio
case types.ChatGLM: case types.ChatGLM:
return h.sendChatGLMMessage(chatCtx, req, userVo, ctx, session, role, prompt, ws) return h.sendChatGLMMessage(chatCtx, req, userVo, ctx, session, role, prompt, ws)
} }
return fmt.Errorf("not supported platform: %s", session.Model.Platform) utils.ReplyChunkMessage(ws, types.WsMessage{
Type: types.WsMiddle,
Content: fmt.Sprintf("Not supported platform: %s", session.Model.Platform),
})
return nil
} }
// Tokens 统计 token 数量 // Tokens 统计 token 数量

View File

@ -19,7 +19,7 @@ $borderColor = #4676d0;
font-size: 20px; font-size: 20px;
.logo { .logo {
background-color: #ffffff //background-color: #ffffff
border-radius: 8px; border-radius: 8px;
width: 35px; width: 35px;
height: 35px; height: 35px;
@ -41,6 +41,7 @@ $borderColor = #4676d0;
.search-box { .search-box {
flex-wrap: wrap flex-wrap: wrap
padding: 10px 15px; padding: 10px 15px;
//background-color #343540
.el-input__wrapper { .el-input__wrapper {
background-color: #363535; background-color: #363535;

View File

@ -4,22 +4,10 @@ const routes = [
{ {
name: 'home', name: 'home',
path: '/', path: '/',
redirect: '/chat',
meta: {title: '首页'}, meta: {title: '首页'},
component: () => import('@/views/Home.vue'), component: () => import('@/views/Home.vue'),
}, children: [
{
name: 'login',
path: '/login',
meta: {title: '用户登录'},
component: () => import('@/views/Login.vue'),
},
{
name: 'register',
path: '/register',
meta: {title: '用户注册'},
component: () => import('@/views/Register.vue'),
},
{ {
name: 'chat', name: 'chat',
path: '/chat', path: '/chat',
@ -39,6 +27,21 @@ const routes = [
meta: {title: '导出会话记录'}, meta: {title: '导出会话记录'},
component: () => import('@/views/ChatExport.vue'), component: () => import('@/views/ChatExport.vue'),
}, },
]
},
{
name: 'login',
path: '/login',
meta: {title: '用户登录'},
component: () => import('@/views/Login.vue'),
},
{
name: 'register',
path: '/register',
meta: {title: '用户注册'},
component: () => import('@/views/Register.vue'),
},
{ {
path: '/admin/login', path: '/admin/login',
name: 'admin-login', name: 'admin-login',

View File

@ -1,7 +1,7 @@
<template> <template>
<div class="common-layout theme-white"> <div class="common-layout theme-white">
<el-container> <el-container>
<el-aside width="320px"> <el-aside>
<div class="title-box"> <div class="title-box">
<el-image :src="logo" class="logo"/> <el-image :src="logo" class="logo"/>
<span>{{ title }}</span> <span>{{ title }}</span>
@ -47,7 +47,7 @@
<el-icon><ArrowDown/></el-icon> <el-icon><ArrowDown/></el-icon>
</span> </span>
<template #dropdown> <template #dropdown>
<el-dropdown-menu style="width: 315px;"> <el-dropdown-menu style="width: 296px;">
<el-dropdown-item @click="showConfig"> <el-dropdown-item @click="showConfig">
<el-icon> <el-icon>
<Tools/> <Tools/>

View File

@ -1,50 +1,49 @@
<template> <template>
<div class="home"> <div class="home">
<div class="inner"> <div class="navigator"></div>
<h1>HI <br/> ChatGPT-PLUS</h1> <div class="content">
<router-view v-slot="{ Component }">
<transition name="move" mode="out-in">
<component :is="Component"></component>
</transition>
</router-view>
</div> </div>
</div> </div>
</template> </template>
<script setup> <script setup>
import {useRouter} from "vue-router";
import {checkSession} from "@/action/session";
import {isMobile} from "@/utils/libs";
const router = useRouter(); // const router = useRouter();
checkSession().then(() => { // checkSession().then(() => {
if (isMobile()) { // if (isMobile()) {
router.push("/mobile") // router.push("/mobile")
} else { // } else {
router.push("/chat") // router.push("/chat")
} // }
}).catch(() => { // }).catch(() => {
router.push("/login") // router.push("/login")
}) // })
</script> </script>
<style lang="stylus" scoped> <style lang="stylus" scoped>
.home { .home {
display: flex; display: flex;
justify-content: center; background-color: #343540;
background-color: #282c34;
height 100vh height 100vh
width 100%
.inner { .navigator {
text-align center
display flex display flex
justify-content center width 30px
max-width 400px padding 10px 6px
align-items center
h1 {
color: #202020;
font-size: 55px;
line-height 1.5
font-weight: bold;
text-shadow: -1px -1px 1px #111111, 2px 2px 1px #363636;
} }
.content {
width: 100%;
height: 100vh;
overflow-y: scroll;
box-sizing: border-box;
} }
} }