<template>
|
<view class="min-h-screen bg-gray-100 flex flex-col">
|
<view class="fixed bottom-0 left-0 right-0 z-10 bg-white shadow p-4">
|
<view class="flex flex-wrap ">
|
<button v-for="cat in categories" :key="cat.category"
|
class="bg-blue-500 text-white text-sm px-4 py-2 rounded m-1" @click="selectCategory(cat)">
|
{{ cat.category }}
|
</button>
|
</view>
|
</view>
|
|
<view class="flex-1 px-4 pb-20 h-80" >
|
<view v-if="selectedCategory" class="question-list">
|
<view v-for="(q, index) in selectedCategory.questions" :key="index" class="question-item"
|
@click="selectQuestion(q)">
|
{{ q[0] }}
|
</view>
|
<view class="h-2"></view>
|
|
<view v-for="(msg, index) in chatList" :key="index" :class="['chat-message', msg.type]">
|
{{ msg.text }}
|
</view>
|
</view>
|
</view>
|
|
</view>
|
</template>
|
|
<script>
|
import {
|
QUESTIONS
|
} from './questions';
|
|
|
export default {
|
data() {
|
return {
|
categories: QUESTIONS,
|
selectedCategory: null,
|
chatList: [],
|
scrollTop :0
|
};
|
},
|
methods: {
|
selectCategory(cat) {
|
this.selectedCategory = cat;
|
this.chatList = [];
|
},
|
selectQuestion(q) {
|
this.chatList =[];
|
this.chatList.push({
|
type: "question",
|
text: q[0]
|
});
|
this.chatList.push({
|
type: "answer",
|
text: q[1]
|
});
|
}
|
}
|
};
|
</script>
|
|
<style>
|
/* 容器 */
|
.min-h-screen {
|
min-height: 100vh;
|
}
|
|
.bg-gray-100 {
|
background-color: #f7fafc;
|
}
|
|
.flex {
|
display: flex;
|
}
|
|
.flex-col {
|
flex-direction: column;
|
}
|
|
.flex-1 {
|
flex: 1 1 0%;
|
}
|
.h-10 {
|
height: 40px;
|
}
|
|
.flex-wrap {
|
flex-wrap: wrap;
|
}
|
|
.justify-around {
|
justify-content: space-around;
|
}
|
|
.justify-end {
|
justify-content: flex-end;
|
}
|
|
.justify-start {
|
justify-content: flex-start;
|
}
|
.h-2 {
|
height: 2.5rem;
|
}
|
.h-80 {
|
min-height: 80vh;
|
}
|
|
.items-center {
|
align-items: center;
|
}
|
|
/* 定位 */
|
.fixed {
|
position: fixed;
|
}
|
|
.top-0 {
|
top: 0;
|
}
|
|
.left-0 {
|
left: 0;
|
}
|
|
.right-0 {
|
right: 0;
|
}
|
|
.right-10 {
|
right: 10;
|
}
|
|
.bottom-0 {
|
bottom: 0;
|
}
|
|
.z-10 {
|
z-index: 10;
|
}
|
|
/* 背景与阴影 */
|
.bg-white {
|
background-color: #ffffff;
|
}
|
|
.shadow {
|
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1),
|
0 1px 2px rgba(0, 0, 0, 0.06);
|
}
|
|
.shadow-t {
|
box-shadow: 0 -1px 3px rgba(0, 0, 0, 0.1),
|
0 -1px 2px rgba(0, 0, 0, 0.06);
|
}
|
|
/* 间距 */
|
.p-4 {
|
padding: 1rem;
|
}
|
|
.p-3 {
|
padding: 0.75rem;
|
}
|
|
.px-4 {
|
padding-left: 1rem;
|
padding-right: 1rem;
|
}
|
|
.pb-20 {
|
padding-bottom: 5rem;
|
}
|
|
.pt-20 {
|
padding-top: 5rem;
|
}
|
|
.m-1 {
|
margin: 0.25rem;
|
}
|
|
.m-3 {
|
margin-right: 2rem;
|
}
|
|
.mb-4 {
|
margin-bottom: 1rem;
|
}
|
|
/* 按钮 & 输入框 */
|
.bg-blue-200 {
|
background-color: #00ff00;
|
}
|
|
.bg-gray-200 {
|
background-color: #808080;
|
}
|
|
.bg-blue-500 {
|
background-color: #3b82f6;
|
}
|
|
.text-white {
|
color: #ffffff;
|
}
|
|
.text-black {
|
color: #000000;
|
}
|
|
.text-sm {
|
font-size: 0.875rem;
|
}
|
|
.text-base {
|
font-size: 1rem;
|
}
|
|
.rounded {
|
border-radius: 0.25rem;
|
}
|
|
.rounded-lg {
|
border-radius: 0.5rem;
|
}
|
|
.rounded-r {
|
border-top-right-radius: 0.25rem;
|
border-bottom-right-radius: 0.25rem;
|
}
|
|
.border {
|
border-width: 1px;
|
border-style: solid;
|
}
|
|
.border-gray-300 {
|
border-color: #d1d5db;
|
}
|
|
.h-12 {
|
height: 3rem;
|
}
|
|
|
.max-w-3-4 {
|
max-width: 90%;
|
}
|
|
/* 注意转义 / */
|
|
/* 滚动区域 */
|
.scroll-y {
|
overflow-y: auto;
|
}
|
|
.scroll-with-animation {
|
scroll-behavior: smooth;
|
}
|
|
/* 问题清单 */
|
.question-list {
|
min-height: 80%;
|
background-color: #fff;
|
padding: 0.5rem;
|
border-radius: 0.5rem;
|
max-height: 150px;
|
overflow-y: visible;
|
}
|
|
.question-item {
|
padding: 0.5rem;
|
border-bottom: 1px solid #eee;
|
}
|
|
.question-item:last-child {
|
border-bottom: none;
|
}
|
|
/* 聊天消息 */
|
.chat-message {
|
max-width: 70%;
|
margin: 0.25rem 0;
|
padding: 0.5rem 0.75rem;
|
border-radius: 0.5rem;
|
word-break: break-word;
|
}
|
|
.chat-message.question {
|
background-color: #e0f7fa;
|
align-self: flex-start;
|
}
|
|
.chat-message.answer {
|
background-color: #ffecb3;
|
align-self: flex-end;
|
}
|
</style>
|