【门店端】 提交

This commit is contained in:
Ghost
2025-04-09 09:34:27 +08:00
parent 3d49092cf7
commit c78ded8a7c
31 changed files with 10541 additions and 1 deletions

View File

@@ -0,0 +1,854 @@
<template>
<view class="chat-container">
<!-- 顶部导航栏 -->
<view class="header">
<view class="title">美业AI助理</view>
<view class="header-right">
<text style="font-size: 16px;" @click='showMenu'>
<u-icon name="list" color="#333" size="28"></u-icon>
</text>
</view>
</view>
<!-- 引入侧边菜单组件 -->
<side-menu :show="menuVisible" @close="closeMenu"></side-menu>
<!-- 搜索栏 -->
<view class="search-container" v-if="false">
<view class="search-input-wrapper">
<text class="iconfont search-icon">
<u-icon name="search"></u-icon>
</text>
<input
type="text"
v-model="searchText"
placeholder="搜索消息"
class="search-input"
@focus="onSearchFocus"
/>
</view>
</view>
<!-- 消息区域 -->
<scroll-view
scroll-y
class="message-list"
:scroll-into-view="scrollIntoView"
:scroll-with-animation="true"
:scroll-top="scrollTop"
@scroll="onScroll"
scroll-anchoring
ref="messageList"
>
<view
v-for="(message, index) in messages"
:key="message.id"
:id="message.id"
:class="['message-item', message.type, showContent ? 'fade-in' : '', message.isImage ? 'image-message' : '']"
>
<view class="message-content">
<!-- 图片消息 -->
<image v-if="message.isImage" :src="message.imagePath" mode="widthFix" @tap="previewImage(message.imagePath)"></image>
<!-- 文本消息 -->
<view v-else class="text-content">
<text v-if="message.isThinking">{{ message.content.replace('...', '') }}</text>
<text v-else>{{ message.content }}</text>
<text v-if="message.isThinking" class="thinking-dots">...</text>
</view>
</view>
<view class="message-time">{{ message.time }}</view>
</view>
</scroll-view>
<!-- 底部操作区域 -->
<view class="bottom-area safe-area-inset-bottom" style="border-top: 1px solid #e5e5e5;">
<!-- 底部按钮区域 -->
<view class="footer">
<!-- 艺施内容库按钮 - 动态样式 -->
<u-button
:type="contentLibEnabled ? 'primary' : 'default'"
class="footer-btn"
:class="contentLibEnabled ? 'content-btn' : 'content-btn-off'"
:custom-style="{
height: '40px',
padding: '0 12px',
fontSize: '14px',
backgroundColor: contentLibEnabled ? '#0080FF' : '#fff',
color: contentLibEnabled ? '#fff' : '#333',
border: '1px solid #e5e5e5',
borderColor: contentLibEnabled ? '#0080FF' : '#e5e5e5'
}"
@click="toggleContentLib"
>
<view class="btn-content">
<text class="iconfont">
<u-icon name="file-text" size="24" color="{color: contentLibEnabled ? '#fff' : '#333'}"></u-icon>
</text>
<text style="margin-left: 5px;">艺施内容库</text>
</view>
</u-button>
<!-- 自动开发客户按钮 - 动态样式 -->
<u-button
:type="autoCustomerEnabled ? 'primary' : 'default'"
class="footer-btn"
:class="autoCustomerEnabled ? 'auto-btn-on' : 'auto-btn'"
:custom-style="{
height: '40px',
padding: '0 12px',
fontSize: '14px',
backgroundColor: autoCustomerEnabled ? '#0080FF' : '#fff',
color: autoCustomerEnabled ? '#fff' : '#333',
border: '1px solid #e5e5e5',
borderColor: autoCustomerEnabled ? '#0080FF' : '#e5e5e5'
}"
@click="toggleAutoCustomer"
>
<view class="btn-content">
<text class="iconfont" >
<u-icon name="account" size="24" :color="{color: autoCustomerEnabled ? '#fff' : '#333'}"></u-icon>
</text>
<text style="margin-left: 5px;">自动开发客户</text>
</view>
</u-button>
</view>
<!-- 输入框 -->
<view class="input-container">
<view class="input-wrapper" style="padding: 0;">
<!-- 输入框 -->
<u-input
style="padding: 0 15px;box-sizing: border-box;"
v-model="inputText"
type="text"
placeholder="发消息、输入@或/选择技能"
border="none"
:clearable="false"
@confirm="sendMessage"
height="44px"
>
</u-input>
<!-- 发送按钮 -->
<view class="right-btn" style="padding: 0;">
<u-button style="width: 80px;height: 100%;" v-if="inputText.trim()" @click="sendMessage" text="发送" type="primary" size="larg" shape="circle"></u-button>
</view>
</view>
</view>
</view>
</view>
</template>
<script>
import SideMenu from '@/components/SideMenu.vue';
import { hasValidToken, redirectToLogin } from '@/api/utils/auth';
import { request } from '@/api/config';
export default {
components: {
SideMenu
},
data() {
return {
searchText: '',
inputText: '',
scrollIntoView: '',
showContent: false,
contentLibEnabled: true,
autoCustomerEnabled: false,
scrollTop: 0,
menuVisible: false,
isRecording: false,
messages: [],
pageSize: 20,
currentPage: 1,
total: 0,
loading: false,
conversationId: '',
isLoadingMore: false,
hasMore: true,
lastScrollTime: 0,
scrollTimer: null
}
},
created() {
this.checkTokenStatus();
this.initMessages();
},
onShow() {
this.checkTokenStatus();
if (this.messages.length === 0) {
this.initMessages();
}
},
methods: {
checkTokenStatus() {
if (!hasValidToken()) {
console.log('Token无效重定向到登录页面');
redirectToLogin();
}
},
async initMessages() {
try {
const res = await request({
url: '/v1/cozeai/message/list',
method: 'GET',
data: {
conversation_id: this.conversationId,
page: 1,
page_size: this.pageSize
}
});
if (res.code === 200) {
this.messages = res.data.list || [];
this.total = res.data.total || 0;
this.conversationId = res.data.conversation_id;
this.hasMore = this.messages.length < this.total;
this.$nextTick(() => {
this.scrollToBottom();
});
} else {
uni.showToast({
title: res.msg || '获取消息失败',
icon: 'none'
});
}
} catch (err) {
console.error('获取消息列表失败:', err);
uni.showToast({
title: '网络异常,请稍后重试',
icon: 'none'
});
}
},
async loadMoreMessages() {
if (this.isLoadingMore || !this.hasMore) return;
this.isLoadingMore = true;
try {
const res = await request({
url: '/v1/cozeai/message/list',
method: 'GET',
data: {
conversation_id: this.conversationId,
page: this.currentPage + 1,
page_size: this.pageSize
}
});
if (res.code === 200) {
const newMessages = res.data.list || [];
this.messages = [...newMessages, ...this.messages];
this.currentPage += 1;
this.hasMore = this.messages.length < this.total;
this.$nextTick(() => {
const oldHeight = this.$refs.messageList.scrollHeight;
setTimeout(() => {
const newHeight = this.$refs.messageList.scrollHeight;
this.$refs.messageList.scrollTop = newHeight - oldHeight;
}, 0);
});
} else {
uni.showToast({
title: res.msg || '加载更多消息失败',
icon: 'none'
});
}
} catch (err) {
console.error('加载更多消息失败:', err);
uni.showToast({
title: '网络异常,请稍后重试',
icon: 'none'
});
} finally {
this.isLoadingMore = false;
}
},
onScroll(e) {
if (this.scrollTimer) {
clearTimeout(this.scrollTimer);
}
this.scrollTimer = setTimeout(() => {
const currentTime = Date.now();
if (currentTime - this.lastScrollTime < 100) return;
this.lastScrollTime = currentTime;
this.scrollTop = e.detail.scrollTop;
if (this.scrollTop <= 50 && !this.isLoadingMore && this.hasMore) {
this.loadMoreMessages();
}
}, 100);
},
async sendMessage() {
if (!this.inputText.trim()) return;
// 保存用户输入
const userInput = this.inputText;
// 添加用户消息到列表
const userMsg = {
id: 'msg' + (this.messages.length + 1),
type: 'user',
content: userInput,
time: this.formatTime(new Date())
};
this.messages.push(userMsg);
// 添加思考中的状态消息
const thinkingMsg = {
id: 'thinking_' + Date.now(),
type: 'assistant',
content: '正在思考中...',
time: this.formatTime(new Date()),
isThinking: true // 标记为思考状态
};
this.messages.push(thinkingMsg);
// 清空输入框
this.inputText = '';
// 立即滚动到底部
this.scrollToBottom();
try {
// 调用发送消息接口
const res = await request({
url: '/v1/cozeai/conversation/createChat',
method: 'POST',
data: {
conversation_id: this.conversationId,
question: userInput
}
});
if (res.code === 200) {
// 更新会话ID
if (res.data.conversation_id) {
this.conversationId = res.data.conversation_id;
}
// 开始轮询获取结果
if (res.data.status === 'in_progress') {
this.pollMessageResult(res.data.id, thinkingMsg.id);
}
} else {
// 显示错误提示
uni.showToast({
title: res.msg || '发送失败',
icon: 'none'
});
// 移除思考中的消息
this.removeThinkingMessage(thinkingMsg.id);
}
} catch (err) {
console.error('发送消息失败:', err);
uni.showToast({
title: '网络异常,请稍后重试',
icon: 'none'
});
// 移除思考中的消息
this.removeThinkingMessage(thinkingMsg.id);
}
},
// 移除思考中的消息
removeThinkingMessage(thinkingId) {
const index = this.messages.findIndex(msg => msg.id === thinkingId);
if (index !== -1) {
this.messages.splice(index, 1);
}
},
// 更新轮询方法
async pollMessageResult(messageId, thinkingId) {
let retryCount = 0;
const maxRetries = 30;
const interval = 1000;
const poll = async () => {
if (retryCount >= maxRetries) {
uni.showToast({
title: '响应超时,请重试',
icon: 'none'
});
this.removeThinkingMessage(thinkingId);
return;
}
try {
const statusRes = await request({
url: '/v1/cozeai/conversation/chatretRieve',
method: 'GET',
data: {
conversation_id: this.conversationId,
chat_id: messageId
}
});
if (statusRes.code === 200) {
if (statusRes.data.status === 'completed') {
const messageRes = await request({
url: '/v1/cozeai/conversation/chatMessage',
method: 'GET',
data: {
conversation_id: this.conversationId,
chat_id: messageId
}
});
if (messageRes.code === 200 && messageRes.data) {
// 移除思考中的消息
this.removeThinkingMessage(thinkingId);
// 添加AI回复
const aiMsg = {
id: 'msg' + (this.messages.length + 1),
type: 'assistant',
content: messageRes.data.content || '抱歉,我现在无法回答您的问题。',
time: messageRes.data.time || this.formatTime(new Date())
};
this.messages.push(aiMsg);
// 滚动到底部
this.scrollToBottom();
return;
} else {
uni.showToast({
title: messageRes.msg || '获取消息内容失败',
icon: 'none'
});
this.removeThinkingMessage(thinkingId);
}
} else if (statusRes.data.status === 'failed') {
uni.showToast({
title: '消息处理失败',
icon: 'none'
});
this.removeThinkingMessage(thinkingId);
return;
}
// 如果状态是处理中,继续轮询
retryCount++;
setTimeout(poll, interval);
} else {
uni.showToast({
title: statusRes.msg || '检查消息状态失败',
icon: 'none'
});
this.removeThinkingMessage(thinkingId);
}
} catch (err) {
console.error('轮询消息状态失败:', err);
retryCount++;
setTimeout(poll, interval);
}
};
poll();
},
scrollToBottom() {
if (this.messages.length > 0) {
this.scrollIntoView = this.messages[this.messages.length - 1].id;
}
this.$nextTick(() => {
setTimeout(() => {
this.scrollTop = 999999;
}, 50);
});
},
formatTime(date) {
const hours = date.getHours().toString().padStart(2, '0');
const minutes = date.getMinutes().toString().padStart(2, '0');
return hours + ':' + minutes;
},
goBack() {
uni.navigateBack();
},
onSearchFocus() {
uni.showToast({
title: '搜索功能开发中',
icon: 'none'
});
},
onSearch() {
if (!this.searchText.trim()) return;
uni.showToast({
title: '搜索"' + this.searchText + '"的结果开发中',
icon: 'none'
});
},
toggleContentLib() {
this.contentLibEnabled = !this.contentLibEnabled;
uni.showToast({
title: this.contentLibEnabled ? '艺施内容库已开启' : '艺施内容库已关闭',
icon: 'none'
});
},
toggleAutoCustomer() {
this.autoCustomerEnabled = !this.autoCustomerEnabled;
uni.showToast({
title: this.autoCustomerEnabled ? '自动开发客户已开启' : '自动开发客户已关闭',
icon: 'none'
});
},
showMenu() {
this.menuVisible = true;
},
closeMenu() {
this.menuVisible = false;
},
previewImage(url) {
uni.previewImage({
urls: [url],
current: url
});
},
beforeDestroy() {
if (this.scrollTimer) {
clearTimeout(this.scrollTimer);
}
}
}
}
</script>
<style lang="scss">
.chat-container {
display: flex;
flex-direction: column;
height: 100vh;
background-color: #fff;
box-sizing: border-box;
}
.header {
display: flex;
justify-content: space-between;
align-items: center;
padding: 15px 15px;
padding-top: calc(var(--status-bar-height) + 15px);
box-shadow: none;
background-color: #fff;
z-index: 1000;
border-bottom: 1px solid #f5f5f5;
.title {
font-size: 20px;
font-weight: 500;
}
.header-right {
display: flex;
align-items: center;
}
}
.search-container {
padding: 10px 15px 15px;
background-color: #fff;
}
.search-input-wrapper {
display: flex;
align-items: center;
background-color: #F5F5F5;
height: 36px;
border-radius: 18px;
padding: 0 12px;
}
.search-icon {
color: #999;
font-size: 16px;
margin-right: 6px;
}
.search-input {
flex: 1;
height: 100%;
font-size: 14px;
background-color: transparent;
border: none;
}
.message-list {
flex: 1;
padding: 10px;
overflow-y: auto;
background-color: #fff;
box-sizing: border-box;
}
.message-item {
margin-bottom: 20px;
&.assistant {
.message-content {
background-color: #F5F5F5;
border-radius: 10px;
padding: 12px 15px;
font-size: 15px;
line-height: 1.5;
color: #333;
max-width: 85%;
box-shadow: none;
word-break: break-word;
}
.message-time {
font-size: 12px;
color: #999;
margin-top: 5px;
padding-left: 5px;
}
}
&.user {
display: flex;
flex-direction: column;
align-items: flex-end;
.message-content {
background-color: #0080FF;
border-radius: 18px;
padding: 12px 15px;
font-size: 15px;
line-height: 1.5;
color: #fff;
max-width: 75%;
word-break: break-word;
}
.message-time {
font-size: 12px;
color: #999;
margin-top: 5px;
padding-right: 5px;
}
&.image-message {
.message-content {
padding: 0;
background-color: transparent;
overflow: hidden;
image {
width: 100%;
max-width: 200px;
border-radius: 10px;
}
}
}
}
}
.bottom-area {
background-color: #fff;
border-top: none;
}
.footer {
padding: 10px 15px;
display: flex;
justify-content: space-between;
.footer-btn {
flex: 1;
margin: 0 5px;
border-radius: 4px;
height: 40px;
line-height: 40px;
}
.content-btn {
background-color: #0080FF;
color: #fff;
border-color: #0080FF;
}
.content-btn-off {
background-color: #fff;
color: #333;
border-color: #e5e5e5;
}
.auto-btn-on {
background-color: #0080FF;
color: #fff;
border-color: #0080FF;
}
.auto-btn {
background-color: #fff;
color: #333;
border-color: #e5e5e5;
}
}
.input-container {
padding: 10px 15px 15px;
.input-wrapper {
border: 1px solid #e5e5e5;
border-radius: 40px;
padding: 0 5px;
background-color: #fff;
height: 44px;
display: flex;
align-items: center;
}
.right-btn {
padding: 0 8px;
height: 100%;
display: flex;
align-items: center;
}
:deep(.u-input) {
background-color: transparent;
flex: 1;
height: 42px;
}
:deep(.u-input__content__field-wrapper__field) {
font-size: 15px;
}
}
.fade-in {
animation: fadeIn 0.5s ease-in-out;
}
@keyframes fadeIn {
from {
opacity: 0;
transform: translateY(10px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
.btn-content {
display: flex;
align-items: center;
justify-content: center;
}
.iconfont {
font-family: "SF Pro Display";
font-size: 16px;
}
.icon-wrapper {
display: flex;
align-items: center;
justify-content: center;
margin-right: 5px;
}
.mic-icon {
color: #333;
font-size: 24px;
}
.send-icon {
color: #0080FF;
font-size: 24px;
cursor: pointer;
}
.recording {
color: #f00;
font-weight: bold;
}
.recording-tip {
position: fixed;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
width: 150px;
height: 150px;
background-color: rgba(0, 0, 0, 0.7);
border-radius: 10px;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
z-index: 999;
.recording-wave {
display: flex;
align-items: flex-end;
height: 50px;
margin-bottom: 10px;
.wave {
width: 5px;
background-color: #0080FF;
margin: 0 3px;
border-radius: 3px;
animation: waveAnimation 0.5s infinite alternate;
&:nth-child(1) {
height: 15px;
animation-delay: 0s;
}
&:nth-child(2) {
height: 25px;
animation-delay: 0.2s;
}
&:nth-child(3) {
height: 20px;
animation-delay: 0.4s;
}
}
}
.recording-text {
color: #fff;
font-size: 14px;
margin-bottom: 10px;
}
.recording-cancel {
color: #999;
font-size: 12px;
}
}
@keyframes waveAnimation {
from {
transform: scaleY(1);
}
to {
transform: scaleY(1.5);
}
}
.text-content {
display: flex;
align-items: center;
.thinking-dots {
display: inline-block;
animation: thinkingDots 2s infinite;
}
}
@keyframes thinkingDots {
0% { opacity: 0.2; }
20% { opacity: 1; }
100% { opacity: 0.2; }
}
</style>

View File

@@ -0,0 +1,557 @@
<template>
<view class="login-page">
<!-- 页面顶部导航 -->
<view class="page-header">
<view class="back-btn"></view>
<view class="page-title">登录/注册</view>
</view>
<!-- 内容区域 -->
<view class="content-area">
<!-- 登录方式选项卡 -->
<view class="tab-container" v-if="false">
<view
class="tab-item"
:class="{ active: loginType === 'code' }"
@tap="loginType = 'code'"
>
验证码登录
</view>
<view
class="tab-item"
:class="{ active: loginType === 'password' }"
@tap="loginType = 'password'"
>
密码登录
</view>
</view>
<!-- 地区提示 -->
<view class="tip-text u-line-1">
您所在地区仅支持 手机号 <!-- / 微信 / Apple 登录 -->
</view>
<!-- 验证码登录 -->
<block v-if="loginType === 'code'">
<view class="form-item">
<view class="input-item">
<view class="input-prefix">+86</view>
<u-input
type="number"
v-model="phone"
maxlength="11"
placeholder="手机号"
class="input-field"
border="0"
/>
</view>
</view>
<view class="form-item">
<view class="input-item code-input-box">
<u-input
type="number"
v-model="code"
maxlength="6"
placeholder="验证码"
class="input-field"
border="0"
/>
<view
class="send-code-btn"
:class="{ disabled: codeSending || !isPhoneValid }"
@tap="sendCode"
>
{{ codeText }}
</view>
</view>
</view>
</block>
<!-- 密码登录 -->
<block v-else>
<view class="form-item">
<view class="input-item">
<view class="input-prefix">+86</view>
<u-input
type="number"
v-model="phone"
maxlength="11"
placeholder="手机号"
class="input-field"
border="0"
/>
</view>
</view>
<view class="form-item">
<view class="input-item">
<u-input
:type="passwordVisible ? 'text' : 'password'"
v-model="password"
placeholder="密码"
class="input-field"
border="0"
/>
<view class="password-icon" @tap="passwordVisible = !passwordVisible">
<u-icon :name="passwordVisible ? 'eye' : 'eye-off'" size="20" color="#999"></u-icon>
</view>
</view>
</view>
</block>
<!-- 用户协议 -->
<view class="agreement-container">
<checkbox-group @change="checkboxChange">
<checkbox :value="agreement" :checked="agreement" class="agreement-checkbox" color="#4080ff" />
</checkbox-group>
<text class="agreement-text">已阅读并同意</text>
<text class="agreement-link" @tap="openAgreement('user')">用户协议</text>
<text class="agreement-text"></text>
<text class="agreement-link" @tap="openAgreement('privacy')">隐私政策</text>
</view>
<!-- 登录按钮 -->
<view
class="login-btn"
:class="{ active: canLogin }"
@tap="handleLogin"
>
登录
</view>
<!-- 分隔线 -->
<view class="divider" v-if="false">
<view class="divider-line"></view>
<text class="divider-text"></text>
<view class="divider-line"></view>
</view>
<!-- 第三方登录 -->
<view class="third-party-login" v-if="false">
<u-button
text="使用微信登录"
:custom-style="{backgroundColor: '#07c160', color: '#ffffff', marginBottom: '15px'}"
shape="circle"
@click="handleThirdLogin('wechat')"
:ripple="true"
>
<template slot="icon">
<u-icon name="weixin-fill" color="#ffffff" size="18" style="margin-right: 5px;"></u-icon>
</template>
</u-button>
<u-button
text="使用 Apple 登录"
:custom-style="{backgroundColor: '#000000', color: '#ffffff'}"
shape="circle"
@click="handleThirdLogin('apple')"
:ripple="true"
>
<template slot="icon">
<u-icon name="apple-fill" color="#ffffff" size="18" style="margin-right: 5px;"></u-icon>
</template>
</u-button>
</view>
<!-- 联系我们 -->
<view class="contact-us" @tap="contactUs">
联系我们
</view>
</view>
</view>
</template>
<script>
// 引入API
import { authApi } from '../../api/modules/auth';
import { hasValidToken, redirectToChat } from '../../api/utils/auth';
export default {
data() {
return {
loginType: 'password', // 默认密码登录
phone: '', // 手机号
code: '', // 验证码
password: '', // 密码
passwordVisible: false, // 密码是否可见
agreement: true, // 是否同意协议
codeSending: false, // 是否正在发送验证码
countdown: 60, // 倒计时
codeText: '发送验证码' // 验证码按钮文本
}
},
// 页面加载时检查token
onLoad() {
this.checkTokenStatus();
},
// 页面显示时检查token
onShow() {
this.checkTokenStatus();
},
computed: {
// 验证手机号是否有效
isPhoneValid() {
return this.phone && this.phone.length === 11;
},
// 验证是否可以登录
canLogin() {
if (!this.phone || !this.agreement) {
return false;
}
if (this.loginType === 'code') {
return this.isPhoneValid && this.code && this.code.length === 6;
} else {
return this.password && this.password.length >= 6;
}
}
},
methods: {
// 检查token状态
checkTokenStatus() {
// 如果token有效则跳转到聊天页面
if (hasValidToken()) {
redirectToChat();
}
},
// 返回上一页
goBack() {
uni.navigateBack();
},
// 切换登录类型
switchLoginType(type) {
this.loginType = type;
},
// 发送验证码
sendCode() {
if (this.codeSending || !this.isPhoneValid) return;
this.codeSending = true;
this.countdown = 60;
this.codeText = `${this.countdown}秒后重发`;
// 模拟发送验证码
uni.showToast({
title: '验证码已发送',
icon: 'success'
});
const timer = setInterval(() => {
this.countdown--;
this.codeText = `${this.countdown}秒后重发`;
if (this.countdown <= 0) {
clearInterval(timer);
this.codeSending = false;
this.codeText = '发送验证码';
}
}, 1000);
},
checkboxChange(){
this.agreement = !this.agreement
},
// 处理登录
async handleLogin() {
// 检查是否同意协议
console.log(this.agreement)
if (!this.agreement) {
uni.showToast({
title: '请阅读并同意用户协议和隐私政策',
icon: 'none',
duration: 2000
});
return;
}
if (!this.canLogin) {
// 显示错误原因
if (!this.isPhoneValid) {
uni.showToast({
title: '请输入正确的手机号',
icon: 'none'
});
} else if (this.loginType === 'code' && (!this.code || this.code.length !== 6)) {
uni.showToast({
title: '请输入6位验证码',
icon: 'none'
});
} else if (this.loginType === 'password' && (!this.password || this.password.length < 6)) {
uni.showToast({
title: '密码不能少于6位',
icon: 'none'
});
}
return;
}
uni.showLoading({
title: '登录中...',
mask: true
});
try {
// 调用登录API
const loginPassword = this.loginType === 'password' ? this.password : this.code;
const response = await authApi.login(this.phone, loginPassword);
console.log(response);
if (response.code === 200) { // 成功code是200
// 登录成功缓存token信息
const { token, member, token_expired } = response.data;
// 存储token信息
uni.setStorageSync('token', token);
uni.setStorageSync('member', JSON.stringify(member));
uni.setStorageSync('token_expired', token_expired);
uni.showToast({
title: '登录成功',
icon: 'success'
});
// 登录成功后跳转到对话页面
setTimeout(() => {
redirectToChat();
}, 1500);
} else {
// 登录失败,显示错误信息
uni.showToast({
title: response.msg || '登录失败,请重试',
icon: 'none'
});
}
} catch (err) {
console.error('登录失败:', err);
uni.showToast({
title: '网络异常,请稍后重试',
icon: 'none'
});
} finally {
uni.hideLoading();
}
},
// 第三方登录
handleThirdLogin(platform) {
uni.showToast({
title: `${platform === 'wechat' ? '微信' : 'Apple'}登录功能暂未实现`,
icon: 'none'
});
},
// 打开协议
openAgreement(type) {
uni.showToast({
title: `打开${type === 'user' ? '用户协议' : '隐私政策'}`,
icon: 'none'
});
},
// 联系我们
contactUs() {
uni.showToast({
title: '联系方式: support@example.com',
icon: 'none',
duration: 3000
});
}
}
}
</script>
<style lang="scss">
.login-page {
min-height: 100vh;
background-color: #fff;
display: flex;
flex-direction: column;
padding-top: 40px; /* 为状态栏预留空间 */
}
.page-header {
display: flex;
align-items: center;
position: relative;
padding: 10px 0;
margin-bottom: 10px;
}
.back-btn {
position: absolute;
left: 15px;
width: 30px;
height: 30px;
display: flex;
align-items: center;
z-index: 2;
}
.page-title {
text-align: center;
font-size: 18px;
font-weight: bold;
width: 100%;
}
.content-area {
flex: 1;
padding: 0 30px;
}
.tab-container {
display: flex;
justify-content: space-between;
margin-bottom: 20px;
position: relative;
}
.tab-item {
position: relative;
text-align: center;
padding: 10px 0;
font-size: 16px;
color: #666;
flex: 1;
}
.tab-item.active {
color: #4080ff;
font-weight: bold;
}
.tab-item.active::after {
content: '';
position: absolute;
bottom: -2px;
left: 25%;
width: 50%;
height: 3px;
background-color: #4080ff;
border-radius: 2px;
}
.tip-text {
font-size: 14px;
color: #666;
margin-bottom: 20px;
}
.input-item {
display: flex;
align-items: center;
border-bottom: 1px solid #eee;
padding: 12px 0;
height: 24px;
}
.input-prefix {
color: #333;
margin-right: 10px;
padding-right: 10px;
border-right: 1px solid #eee;
font-size: 14px;
}
.input-field {
flex: 1;
height: 24px;
font-size: 15px;
}
.code-input-box {
position: relative;
}
.send-code-btn {
position: absolute;
right: 0;
background-color: #4080ff;
color: #fff;
padding: 5px 10px;
border-radius: 4px;
font-size: 12px;
}
.send-code-btn.disabled {
background-color: #ccc;
}
.password-icon {
padding: 0 5px;
height: 100%;
display: flex;
align-items: center;
}
.agreement-container {
display: flex;
align-items: center;
margin: 15px 0;
}
.agreement-checkbox {
transform: scale(0.8);
margin-right: 5px;
}
.agreement-text {
font-size: 13px;
color: #666;
}
.agreement-link {
font-size: 13px;
color: #4080ff;
}
.login-btn {
height: 44px;
line-height: 44px;
text-align: center;
background-color: #dddddd;
color: #ffffff;
border-radius: 22px;
margin: 20px 0;
font-size: 16px;
transition: background-color 0.3s;
}
.login-btn.active {
background-color: #4080ff;
}
.divider {
display: flex;
align-items: center;
margin: 20px 0;
}
.divider-line {
flex: 1;
height: 1px;
background-color: #eee;
}
.divider-text {
color: #999;
padding: 0 15px;
font-size: 14px;
}
.third-party-login {
margin: 20px 0;
}
.contact-us {
text-align: center;
color: #999;
font-size: 14px;
margin-top: 40px;
}
</style>