添加搜索

上级 96eef36b
<template>
<div>
<el-container>
<el-header style="text-align: right; font-size: 12px">
<i class="el-icon-refresh header-button-item" @click="refreshPage"></i>
<el-dropdown>
<i class="el-icon-setting header-button-item"></i>
<el-dropdown-menu slot="dropdown">
<el-dropdown-item>新增</el-dropdown-item>
</el-dropdown-menu>
</el-dropdown>
<a href="http://qinyingjie.top/" target="_blank" class="header-button-item">kwan</a>
</el-header>
<div>
<el-container>
<el-header style="text-align: right; font-size: 12px">
<i class="el-icon-refresh header-button-item" @click="refreshPage"></i>
<el-dropdown>
<i class="el-icon-setting header-button-item"></i>
<el-dropdown-menu slot="dropdown">
<el-dropdown-item>新增</el-dropdown-item>
</el-dropdown-menu>
</el-dropdown>
<a
href="http://qinyingjie.top/"
target="_blank"
class="header-button-item"
>kwan</a
>
</el-header>
<el-main>
<el-table border :data="userlist" v-loading="loading">
<el-table-column prop="id" label="序号" width="50" sortable></el-table-column>
<el-table-column prop="question" label="问题" width="240" show-overflow-tooltip></el-table-column>
<el-table-column prop="response" label="答案" show-overflow-tooltip></el-table-column>
<el-table-column label="创建时间" width="170">
<template slot-scope="props">
{{ props.row.createTime | dateFormat }}
</template>
</el-table-column>
<el-table-column prop="详情" label="详情" width="100">
<template slot-scope="props">
<a href="#" @click.prevent="gotoDetail(props.row.id)">详情</a>
</template>
</el-table-column>
</el-table>
<el-pagination
class="pagination"
background
:key="elementui_page_component_key"
:current-page.sync="currentPage"
:page-size="pageSize"
:total="total"
@current-change="handleCurrentChange"
></el-pagination>
</el-main>
<el-backtop class="backtop"></el-backtop>
</el-container>
</div>
<el-main>
<el-form :inline="true" :model="formInline" class="demo-form-inline">
<el-form-item label="问题">
<el-input
clearable
v-model="formInline.question"
placeholder="请输入问题"
@keydown.enter.native="initCartList"
></el-input>
</el-form-item>
<el-form-item>
<el-button type="primary" @click="initCartList">查询</el-button>
</el-form-item>
</el-form>
<el-table border :data="userlist" v-loading="loading">
<el-table-column
prop="id"
label="序号"
width="50"
sortable
></el-table-column>
<el-table-column
prop="question"
label="问题"
width="240"
show-overflow-tooltip
></el-table-column>
<el-table-column
prop="response"
label="答案"
show-overflow-tooltip
></el-table-column>
<el-table-column label="创建时间" width="170">
<template slot-scope="props">
{{ props.row.createTime | dateFormat }}
</template>
</el-table-column>
<el-table-column prop="详情" label="详情" width="180">
<template slot-scope="props">
<el-button type="info">
<a href="#" @click.prevent="gotoDetail(props.row.id)">详情</a>
</el-button>
<el-button type="primary" @click="onDelete(props.row.id)"
>删除</el-button
>
</template>
</el-table-column>
</el-table>
<el-pagination
class="pagination"
background
:key="elementui_page_component_key"
:current-page.sync="currentPage"
:page-size="pageSize"
:total="total"
@current-change="handleCurrentChange"
></el-pagination>
</el-main>
<el-backtop class="backtop"></el-backtop>
</el-container>
</div>
</template>
<script>
import axios from 'axios';
import axios from "axios";
export default {
name: 'MyChat',
name: "MyChat",
data() {
return {
// 用户列表数据
userlist: [],
loading: false,
elementui_page_component_key: 0,
currentPage: Number(localStorage.getItem('lastPage')) || 1,
pageSize: 14,
total: 0,
};
},
created() {
// 调用请求数据的方法
data() {
return {
// 用户列表数据
userlist: [],
loading: false,
elementui_page_component_key: 0,
currentPage: Number(localStorage.getItem("lastPage")) || 1,
pageSize: 14,
total: 0,
formInline: {
question: "",
},
};
},
watch: {
"formInline.question"(newVal) {
if (newVal === "") {
this.currentPage = 1;
localStorage.setItem("lastPage", this.currentPage);
this.initCartList();
}
},
},
created() {
this.$nextTick(() => {
const foo = this.$route.query.back;
if (foo === "back") {
this.currentPage = Number(localStorage.getItem("lastPage")) || 1;
this.formInline.question = localStorage.getItem("lastQuestion") || "";
} else {
localStorage.setItem("lastPage", 1);
localStorage.setItem("lastQuestion", "");
this.currentPage = 1;
this.formInline.question = "";
}
// 调用请求数据的方法
this.initCartList();
});
},
mounted() {
this.currentPage = Number(localStorage.getItem("lastPage")) || 1;
this.formInline.question = localStorage.getItem("lastQuestion");
this.elementui_page_component_key++;
this.initCartList();
},
methods: {
async onDelete(id) {
this.loading = true;
const { data: res } = await axios.get(
"http://120.79.36.53:8888/chatbot/delete",
{
params: {
id: id,
},
}
);
this.initCartList();
this.loading = false;
},
mounted() {
this.currentPage = Number(localStorage.getItem('lastPage')) || 1;
this.elementui_page_component_key++;
refreshPage() {
location.reload();
},
gotoDetail(id) {
this.$router.push("/home/chatinfo/" + id);
},
methods: {
refreshPage() {
location.reload();
},
gotoDetail(id) {
this.$router.push('/home/chatinfo/' + id);
},
async initCartList() {
this.loading = true;
const { data: res } = await axios.get('http://120.79.36.53:8888/chatbot/page', {
params: {
page: this.currentPage,
pageSize: this.pageSize,
},
});
if (res.code === 200) {
this.userlist = res.result.records;
this.total = res.result.total;
localStorage.setItem('lastPage', this.currentPage);
}
this.loading = false;
},
async initCartList() {
this.loading = true;
const { data: res } = await axios.get(
"http://120.79.36.53:8888/chatbot/page",
{
params: {
page: this.currentPage,
pageSize: this.pageSize,
question: this.formInline.question,
},
}
);
if (res.code === 200) {
this.userlist = res.result.records;
this.total = res.result.total;
localStorage.setItem("lastPage", this.currentPage);
localStorage.setItem("lastQuestion", this.formInline.question);
}
this.loading = false;
},
handleCurrentChange(currentPage) {
this.currentPage = currentPage;
this.initCartList();
},
handleCurrentChange(currentPage) {
this.currentPage = currentPage;
this.initCartList();
},
},
};
</script>
<style lang="less" scoped>
.el-header {
background-color: #b3c0d1;
color: #333;
line-height: 60px;
background-color: #b3c0d1;
color: #333;
line-height: 60px;
}
.el-aside {
color: #333;
color: #333;
}
.pagination {
margin-top: 16px;
text-align: right;
margin-top: 16px;
text-align: right;
}
.header-button-item {
margin-right: 15px;
font-size: 20px;
margin-right: 15px;
font-size: 20px;
}
.backtop {
position: fixed;
bottom: 50px;
right: 50px;
height: 40px;
width: 40px;
line-height: 40px;
text-align: center;
border-radius: 20px;
background-color: #007aff;
color: #fff;
cursor: pointer;
z-index: 999;
position: fixed;
bottom: 50px;
right: 50px;
height: 40px;
width: 40px;
line-height: 40px;
text-align: center;
border-radius: 20px;
background-color: #007aff;
color: #fff;
cursor: pointer;
z-index: 999;
}
.backtop:hover {
background-color: #0050a0;
background-color: #0050a0;
}
</style>
\ No newline at end of file
</style>
<template>
<div>
<el-button @click="$router.back()">后退</el-button>
<h4 class="text-center">ChatGpt问答详情 --- {{ id }}</h4>
<el-container>
<el-main>
<el-table border :data="list">
<el-table-column label="序号" width="50">
<template slot-scope="scope">
<span>{{ scope.row.id }}</span>
</template>
</el-table-column>
<el-table-column label="问题" width="240">
<template slot-scope="scope">
<span>{{ scope.row.question }}</span>
</template>
</el-table-column>
<el-table-column label="回答">
<template slot-scope="scope">
<span id="td-response">{{ scope.row.response }}</span>
</template>
</el-table-column>
<el-table-column label="创建时间" width="170">
<template slot-scope="scope">
<span>{{ scope.row.createTime | dateFormat }}</span>
</template>
</el-table-column>
</el-table>
</el-main>
</el-container>
<div class="button-container">
<el-button @click="copyCode">复制回答</el-button>
</div>
</div>
<div>
<!-- <el-button @click="$router.back()">后退</el-button> -->
<el-button @click="goBack()">后退</el-button>
<h4 class="text-center">ChatGpt问答详情 --- {{ id }}</h4>
<el-container>
<el-main>
<el-table border :data="list">
<el-table-column label="序号" width="50">
<template slot-scope="scope">
<span>{{ scope.row.id }}</span>
</template>
</el-table-column>
<el-table-column label="问题" width="240">
<template slot-scope="scope">
<span>{{ scope.row.question }}</span>
</template>
</el-table-column>
<el-table-column label="回答">
<template slot-scope="scope">
<span id="td-response">{{ scope.row.response }}</span>
</template>
</el-table-column>
<el-table-column label="创建时间" width="170">
<template slot-scope="scope">
<span>{{ scope.row.createTime | dateFormat }}</span>
</template>
</el-table-column>
</el-table>
</el-main>
</el-container>
<div class="button-container">
<el-button @click="copyCode">复制回答</el-button>
</div>
</div>
</template>
<script>
// 导入 axios 请求库
import axios from 'axios';
import axios from "axios";
export default {
name: 'MyChatDetail',
props: ['id'],
data() {
return {
list: [],
};
name: "MyChatDetail",
props: ["id"],
data() {
return {
list: [],
};
},
created() {
// 调用请求数据的方法
this.initChatList();
},
methods: {
goBack() {
// 传递参数到前一个页面
const params = {
// 参数名: 参数值
back: "back",
// baz: "qux",
};
// 使用 $router.push() 导航到前一个页面
this.$router.push({
path: "/home/chat", // 前一个页面的路径
query: params, // 参数对象
});
},
created() {
// 调用请求数据的方法
this.initChatList();
// 封装请求列表数据的方法
async initChatList() {
// 调用 axios 的 get 方法,请求列表数据
const { data: res } = await axios.get(
"http://120.79.36.53:8888/chatbot/" + this.id
);
// 只要请求回来的数据,在页面渲染期间要用到,则必须转存到 data 中
if (res.code === 200) {
this.list = [
{
id: res.result.id,
question: res.result.question,
response: res.result.response,
createTime: res.result.createTime,
},
];
}
},
methods: {
// // 封装请求列表数据的方法
async initChatList() {
// 调用 axios 的 get 方法,请求列表数据
const { data: res } = await axios.get('http://120.79.36.53:8888/chatbot/' + this.id);
// 只要请求回来的数据,在页面渲染期间要用到,则必须转存到 data 中
if (res.code === 200) {
this.list = [
{
id: res.result.id,
question: res.result.question,
response: res.result.response,
createTime: res.result.createTime,
},
];
}
},
copyCode() {
const codeBlock = document.getElementById('td-response');
const range = document.createRange();
range.selectNode(codeBlock);
const selection = window.getSelection();
selection.removeAllRanges();
selection.addRange(range);
document.execCommand('copy');
selection.removeAllRanges();
this.$message.success('代码已复制到剪贴板');
},
copyCode() {
const codeBlock = document.getElementById("td-response");
const range = document.createRange();
range.selectNode(codeBlock);
const selection = window.getSelection();
selection.removeAllRanges();
selection.addRange(range);
document.execCommand("copy");
selection.removeAllRanges();
this.$message.success("代码已复制到剪贴板");
},
},
};
</script>
<style lang="less" scoped>
.button-container {
position: fixed;
bottom: 0;
right: 0;
margin: 16px;
position: fixed;
bottom: 0;
right: 0;
margin: 16px;
}
</style>
\ No newline at end of file
</style>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册