mirror of
https://github.com/yangjian102621/geekai.git
synced 2025-11-05 00:33:47 +08:00
后台管理功能已完成
This commit is contained in:
@@ -109,4 +109,9 @@ export function renderInputText(text) {
|
||||
const replaceRegex = /(\n\r|\r\n|\r|\n)/g;
|
||||
text = text || '';
|
||||
return text.replace(replaceRegex, "<br/>");
|
||||
}
|
||||
|
||||
// 拷贝对象
|
||||
export function copyObj(origin) {
|
||||
return JSON.parse(JSON.stringify(origin));
|
||||
}
|
||||
@@ -43,6 +43,10 @@
|
||||
<span v-if="showSidebar">{{ nav.title }}</span>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<el-row class="tool-box">
|
||||
<el-button type="primary" plain @click="logout" v-show="isLogin">退出登录</el-button>
|
||||
</el-row>
|
||||
</el-aside>
|
||||
|
||||
<el-main>
|
||||
@@ -86,7 +90,7 @@
|
||||
<el-form :model="user" label-width="80px">
|
||||
<el-form-item label="用户名:">
|
||||
<el-input
|
||||
v-model="user.username"
|
||||
v-model.trim="user.username"
|
||||
autocomplete="off"
|
||||
placeholder="请输入用户名"
|
||||
/>
|
||||
@@ -94,10 +98,11 @@
|
||||
|
||||
<el-form-item label="密码:">
|
||||
<el-input
|
||||
v-model="user.password"
|
||||
v-model.trim="user.password"
|
||||
autocomplete="off"
|
||||
type="password"
|
||||
placeholder="请输入密码"
|
||||
@keyup="loginInputKeyup"
|
||||
/>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
@@ -105,7 +110,7 @@
|
||||
<template #footer>
|
||||
<span class="dialog-footer">
|
||||
<el-button @click="showDialog = false">取消</el-button>
|
||||
<el-button type="primary" @click="saveHost">提交</el-button>
|
||||
<el-button type="primary" @click="login">提交</el-button>
|
||||
</span>
|
||||
</template>
|
||||
</el-dialog>
|
||||
@@ -122,6 +127,9 @@ import SysConfig from "@/views/admin/SysConfig.vue";
|
||||
import {arrayContains, removeArrayItem} from "@/utils/libs";
|
||||
import UserList from "@/views/admin/UserList.vue";
|
||||
import RoleList from "@/views/admin/RoleList.vue";
|
||||
import {httpGet, httpPost} from "@/utils/http";
|
||||
import {ElMessage} from "element-plus";
|
||||
import {setLoginUser} from "@/utils/storage";
|
||||
|
||||
|
||||
export default defineComponent({
|
||||
@@ -156,6 +164,7 @@ export default defineComponent({
|
||||
curNav: null,
|
||||
curTab: 'welcome',
|
||||
tabs: [],
|
||||
isLogin: false,
|
||||
|
||||
showDialog: false,
|
||||
|
||||
@@ -180,14 +189,54 @@ export default defineComponent({
|
||||
},
|
||||
|
||||
mounted: function () {
|
||||
|
||||
// bind window resize event
|
||||
window.addEventListener("resize", function () {
|
||||
this.winHeight = window.innerHeight
|
||||
})
|
||||
this.checkSession()
|
||||
},
|
||||
|
||||
methods: {
|
||||
checkSession: function () {
|
||||
httpGet("/api/session/get").then(() => {
|
||||
this.isLogin = true
|
||||
}).catch(() => {
|
||||
this.showDialog = true
|
||||
})
|
||||
},
|
||||
|
||||
// 登录输入框输入事件处理
|
||||
loginInputKeyup: function (e) {
|
||||
if (e.keyCode === 13) {
|
||||
this.login();
|
||||
}
|
||||
},
|
||||
|
||||
// 登录
|
||||
login: function () {
|
||||
if (!this.user.username || !this.user.password) {
|
||||
ElMessage.error('请输入用户名和密码')
|
||||
return
|
||||
}
|
||||
httpPost('/api/admin/login', this.user).then((res) => {
|
||||
setLoginUser(res.data)
|
||||
this.showDialog = false
|
||||
this.isLogin = true
|
||||
this.user = {}
|
||||
}).catch((e) => {
|
||||
ElMessage.error('登录失败,' + e.message)
|
||||
})
|
||||
},
|
||||
|
||||
logout: function () {
|
||||
httpPost("/api/logout", {opt: "logout"}).then(() => {
|
||||
this.checkSession();
|
||||
this.isLogin = false
|
||||
}).catch(() => {
|
||||
ElMessage.error("注销失败");
|
||||
})
|
||||
},
|
||||
|
||||
arrayContains(array, value, compare) {
|
||||
return arrayContains(array, value, compare);
|
||||
},
|
||||
@@ -315,6 +364,12 @@ $borderColor = #4676d0;
|
||||
background-color: #363535
|
||||
}
|
||||
}
|
||||
|
||||
.tool-box {
|
||||
display flex
|
||||
justify-content center
|
||||
padding 10px 20px;
|
||||
}
|
||||
}
|
||||
|
||||
.el-main {
|
||||
|
||||
@@ -222,6 +222,7 @@ export default defineComponent({
|
||||
allChatRoles: [], // 所有角色集合
|
||||
role: 'gpt',
|
||||
inputValue: '', // 聊天内容
|
||||
sendHelloMsg: {}, // 是否发送过打招呼信息
|
||||
|
||||
showConfigDialog: false, // 显示配置对话框
|
||||
userInfo: {},
|
||||
@@ -299,7 +300,7 @@ export default defineComponent({
|
||||
socket.addEventListener('open', () => {
|
||||
// 获取聊天角色
|
||||
if (this.chatRoles.length === 0) {
|
||||
httpGet("/api/config/chat-roles/get").then((res) => {
|
||||
httpGet("/api/chat-roles/list").then((res) => {
|
||||
// ElMessage.success('创建会话成功!');
|
||||
this.chatRoles = res.data;
|
||||
this.allChatRoles = res.data;
|
||||
@@ -326,6 +327,10 @@ export default defineComponent({
|
||||
reader.readAsText(event.data, "UTF-8");
|
||||
reader.onload = () => {
|
||||
const data = JSON.parse(String(reader.result));
|
||||
if (data['is_hello_msg'] && this.sendHelloMsg[this.role]) { // 一定发送过打招呼信息的
|
||||
return
|
||||
}
|
||||
|
||||
if (data.type === 'start') {
|
||||
this.chatData.push({
|
||||
type: "reply",
|
||||
@@ -340,6 +345,8 @@ export default defineComponent({
|
||||
this.sending = false;
|
||||
if (data['is_hello_msg'] !== true) {
|
||||
this.showReGenerate = true;
|
||||
} else {
|
||||
this.sendHelloMsg[this.role] = true
|
||||
}
|
||||
this.showStopGenerate = false;
|
||||
this.lineBuffer = ''; // 清空缓冲
|
||||
|
||||
@@ -37,7 +37,7 @@
|
||||
<el-table-column label="打招呼信息" prop="hello_msg"/>
|
||||
<el-table-column label="操作" width="80" align="right">
|
||||
<template #default="scope">
|
||||
<el-button size="small" type="primary" @click="rowEdit(scope.row)">编辑</el-button>
|
||||
<el-button size="small" type="primary" @click="rowEdit(scope.$index, scope.row)">编辑</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
@@ -47,8 +47,6 @@
|
||||
v-model="showDialog"
|
||||
title="编辑用户"
|
||||
width="50%"
|
||||
:destroy-on-close="true"
|
||||
|
||||
>
|
||||
<el-form :model="form1" label-width="120px" ref="formRef" :rules="rules">
|
||||
<el-form-item label="角色名称:" prop="name">
|
||||
@@ -140,6 +138,7 @@ import {Plus, RemoveFilled} from "@element-plus/icons-vue";
|
||||
import {reactive, ref} from "vue";
|
||||
import {httpPost} from "@/utils/http";
|
||||
import {ElMessage} from "element-plus";
|
||||
import {copyObj} from "@/utils/libs";
|
||||
|
||||
const showDialog = ref(false)
|
||||
const parentBorder = ref(false)
|
||||
@@ -164,8 +163,10 @@ httpPost('/api/admin/chat-roles/list').then((res) => {
|
||||
})
|
||||
|
||||
// 编辑
|
||||
const rowEdit = function (row) {
|
||||
form1.value = row
|
||||
const curIndex = ref(0)
|
||||
const rowEdit = function (index, row) {
|
||||
curIndex.value = index
|
||||
form1.value = copyObj(row)
|
||||
showDialog.value = true
|
||||
}
|
||||
|
||||
@@ -175,6 +176,8 @@ const doUpdate = function () {
|
||||
showDialog.value = false
|
||||
httpPost('/api/admin/chat-roles/set', form1.value).then(() => {
|
||||
ElMessage.success('更新角色成功')
|
||||
// 更新当前数据行
|
||||
tableData.value[curIndex.value] = form1.value
|
||||
}).catch((e) => {
|
||||
ElMessage.error('更新角色失败,' + e.message)
|
||||
})
|
||||
|
||||
@@ -11,6 +11,14 @@
|
||||
<el-input v-model="form['proxy_url']" placeholder="多个地址之间用逗号隔开"/>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="微信群聊二维码">
|
||||
<el-input v-model="form['img_url']['wechat_group']" placeholder="群聊二维码地址"/>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="个人微信名片">
|
||||
<el-input v-model="form['img_url']['wechat_card']" placeholder="名片二维码地址"/>
|
||||
</el-form-item>
|
||||
|
||||
<el-divider content-position="center">聊天设置</el-divider>
|
||||
<el-row>
|
||||
<el-col :span="12">
|
||||
@@ -124,14 +132,14 @@ export default defineComponent({
|
||||
data() {
|
||||
return {
|
||||
apiKey: '',
|
||||
form: {},
|
||||
form: {img_url: {}},
|
||||
apiKeys: [],
|
||||
loading: true
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
// 获取系统配置
|
||||
httpGet('/api/admin/config/get').then((res) => {
|
||||
httpGet('/api/config/get').then((res) => {
|
||||
this.form = res.data;
|
||||
}).catch(() => {
|
||||
ElMessage.error('获取系统配置失败')
|
||||
|
||||
@@ -190,8 +190,6 @@
|
||||
v-model="showUserEditDialog"
|
||||
title="编辑用户"
|
||||
width="50%"
|
||||
:destroy-on-close="true"
|
||||
|
||||
>
|
||||
<el-form :model="form2" label-width="100px" ref="userEditFormRef" :rules="rules">
|
||||
<el-form-item label="用户名:" prop="name">
|
||||
|
||||
Reference in New Issue
Block a user