Mon Jul 10 16:00:00 UTC 2023 inscode

上级 cf056da1
<template> <template>
<router-view/> <router-view/>
<div class="container ivu-p"> <div class="container ivu-p">
<span style="color:chartreuse;">用户:</span>
<Button type="large" class="ivu-ml" icon="md-log-out" :disabled="loading" @click="username">当前用户</Button>
<div class="dialog"> <div class="dialog">
<template v-for="(item, index) in dialogs" :key="index"> <template v-for="(item, index) in dialogs" :key="index">
<div class="dialog-item" :class="{ 'dialog-item-me': item.role === 'me', 'dialog-item-ai': item.role === 'ai' }"> <div class="dialog-item" :class="{ 'dialog-item-me': item.role === 'me', 'dialog-item-ai': item.role === 'ai' }">
...@@ -21,6 +23,10 @@ ...@@ -21,6 +23,10 @@
<Col> <Col>
<Button size="large" class="ivu-ml" icon="md-arrow-up" :disabled="loading" @click="handleExportChat">导出</Button> <Button size="large" class="ivu-ml" icon="md-arrow-up" :disabled="loading" @click="handleExportChat">导出</Button>
</Col> </Col>
<Col>
<Button type="large" class="ivu-ml" icon="md-log-out" :disabled="loading" @click="logout">退出</Button>
</Col>
</Row> </Row>
</div> </div>
</div> </div>
...@@ -28,6 +34,7 @@ ...@@ -28,6 +34,7 @@
<script> <script>
import { fetchEventSource } from '@microsoft/fetch-event-source'; import { fetchEventSource } from '@microsoft/fetch-event-source';
import { apiKey, apiUrl } from './api'; import { apiKey, apiUrl } from './api';
import axios from 'axios'
export default { export default {
data() { data() {
...@@ -117,6 +124,27 @@ export default { ...@@ -117,6 +124,27 @@ export default {
return; return;
} }
alert(JSON.stringify(this.dialogs)); alert(JSON.stringify(this.dialogs));
},
logout(){
axios({
method: "get",
url: "https://flask-wujiaping.inscode.cc/logout",
}).then((res) => {
console.log(res.data)
if(200==res.data['code']){
this.$router.push("/login");
}else{
alert(res.data['msg']);
}
});
},
username(){
axios({
method: "get",
url: "https://flask-wujiaping.inscode.cc/username",
}).then((res) => {
console.log(res.data)
});
} }
} }
......
...@@ -3,7 +3,8 @@ import axios from 'axios' ...@@ -3,7 +3,8 @@ import axios from 'axios'
//使用axios下面的create([config])方法创建axios实例,其中config参数为axios最基本的配置信息。 //使用axios下面的create([config])方法创建axios实例,其中config参数为axios最基本的配置信息。
const API = axios.create({ const API = axios.create({
baseUrl:'https://flask-wujiaping.inscode.cc/' //请求后端数据的基本地址,自定义 baseUrl:'https://flask-wujiaping.inscode.cc/', //请求后端数据的基本地址,自定义
changeOrigin:true
}) })
//导出我们建立的axios实例模块,ES6 export用法 //导出我们建立的axios实例模块,ES6 export用法
......
import { createRouter, createWebHistory } from 'vue-router' import { createRouter, createWebHistory } from 'vue-router'
import App from '../App.vue'
const routes = [ const routes = [
{ {
path: '/login', path: '/login',
......
...@@ -11,7 +11,8 @@ ...@@ -11,7 +11,8 @@
<label for="password">&nbsp&nbsp&nbsp&nbsp码:</label> <label for="password">&nbsp&nbsp&nbsp&nbsp码:</label>
<input type="password" id="password" v-model="loginForm.password" /> <input type="password" id="password" v-model="loginForm.password" />
</div> </div>
<button type="button" @click="login" style="background-color: aqua;width: 60px;">登录</button> <button type="button" @click="login" style="background-color: aqua;width: 60px;">登录</button>&nbsp&nbsp&nbsp&nbsp
<button type="button" @click="regist" style="background-color: aqua;width: 60px;">注册</button>
</form> </form>
</div> </div>
</div> </div>
...@@ -35,17 +36,21 @@ ...@@ -35,17 +36,21 @@
} else { } else {
axios({ axios({
method: "post", method: "post",
url: "/login", url: "https://flask-wujiaping.inscode.cc/login",
data: this.loginForm, data: this.loginForm,
}).then((res) => { }).then((res) => {
alert(res.data); console.log(res.data)
if(200==res.data['code']){
this.$router.push("/"); this.$router.push("/");
// alert("登陆成功"); }else{
}).catch((error) => { alert(res.data['msg']);
alert("账号或密码错误"); }
}); });
} }
}, },
regist() {
this.$router.push("/register");
},
}, },
}; };
</script> </script>
......
...@@ -4,11 +4,11 @@ ...@@ -4,11 +4,11 @@
<h2 style="color:greenyellow;">&nbsp&nbsp&nbsp&nbsp册</h2> <h2 style="color:greenyellow;">&nbsp&nbsp&nbsp&nbsp册</h2>
<form> <form>
<div class="input-group"> <div class="input-group">
<label for="new_username">用户名:</label> <label for="username">用户名:</label>
<input type="text" id="username" v-model="registerForm.username" /> <input type="text" id="username" v-model="registerForm.username" />
</div> </div>
<div class="input-group"> <div class="input-group">
<label for="new_password">&nbsp&nbsp&nbsp&nbsp码:</label> <label for="password">&nbsp&nbsp&nbsp&nbsp码:</label>
<input type="password" id="password" v-model="registerForm.password" /> <input type="password" id="password" v-model="registerForm.password" />
</div> </div>
<button type="button" @click="register" style="background-color: aqua;width: 60px;">注册</button> <button type="button" @click="register" style="background-color: aqua;width: 60px;">注册</button>
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
</div> </div>
</template> </template>
<script> <script>
// import { axios } from 'axios' import axios from 'axios'
export default { export default {
data() { data() {
return { return {
...@@ -30,22 +30,22 @@ ...@@ -30,22 +30,22 @@
methods: { methods: {
register() { register() {
//判读账号密码是否输入,没有则alert 出来 //判读账号密码是否输入,没有则alert 出来
// if (this.loginForm.username === "" || this.loginForm.password === "") { if (this.registerForm.username === "" || this.registerForm.password === "") {
// alert("账号或密码不能为空"); alert("注册账号或密码不能为空");
// } else { } else {
// axios({ axios({
// method: "post", method: "post",
// url: "https://flask-wujiaping.inscode.cc/register", url: "https://flask-wujiaping.inscode.cc/register",
// data: this.loginForm, data: this.registerForm,
// }).then((res) => { }).then((res) => {
// console.log(res.data); if(200==res.data['code']){
// this.$router.push("/home"); this.$router.push("/login");
// alert("登陆成功"); alert("请使用刚注册的账号进行登录")
// }).catch((error) => { }else{
// alert("账号或密码错误"); alert(res.data['msg'])
// console.log(error); }
// }); });
// } }
}, },
}, },
}; };
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册