MyChat.vue 3.5 KB
Newer Older
1
<template>
2 3 4 5 6 7 8 9 10 11 12 13
	<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>
14

15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
			<el-main>
				<el-table :data="userlist" v-loading="loading">
					<el-table-column prop="id" label="序号" width="50"></el-table-column>
					<el-table-column prop="question" label="问题" width="240"></el-table-column>
					<el-table-column prop="response" label="答案"></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>
44 45 46
</template>

<script>
47
import axios from 'axios';
48
export default {
49
    name: 'MyChat',
50

51 52 53 54 55 56 57 58 59 60 61
    data() {
        return {
            // 用户列表数据
            userlist: [],
            loading: false,
            elementui_page_component_key: 0,
            currentPage: Number(localStorage.getItem('lastPage')) || 1,
            pageSize: 5,
            total: 0,
        };
    },
62

63 64 65
    created() {
        // 调用请求数据的方法
        this.initCartList();
66
    },
67 68 69
    mounted() {
        this.currentPage = Number(localStorage.getItem('lastPage')) || 1;
        this.elementui_page_component_key++;
70
    },
71 72 73 74 75 76 77
    methods: {
        refreshPage() {
            location.reload();
        },
        gotoDetail(id) {
            this.$router.push('/home/chatinfo/' + id);
        },
78

79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
        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;
        },
94

95 96 97 98
        handleCurrentChange(currentPage) {
            this.currentPage = currentPage;
            this.initCartList();
        },
99 100 101 102 103 104
    },
};
</script>

<style lang="less" scoped>
.el-header {
105 106 107
	background-color: #b3c0d1;
	color: #333;
	line-height: 60px;
108 109 110
}

.el-aside {
111
	color: #333;
112 113 114
}

.pagination {
115 116
	margin-top: 16px;
	text-align: right;
117 118
}
.header-button-item {
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
	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;
}

.backtop:hover {
	background-color: #0050a0;
140
}
141
</style>