This commit is contained in:
Tivibra
2025-09-27 16:28:38 +08:00
parent 86cfcc5af1
commit 4b8498203d
21 changed files with 3997 additions and 343 deletions

View File

@@ -57,6 +57,7 @@
"vue-i18n": "^9.1.9"
},
"devDependencies": {
"@babel/plugin-transform-private-property-in-object": "^7.23.4",
"@dcloudio/types": "^3.4.8",
"@dcloudio/uni-automator": "3.0.0-4060420250429001",
"@dcloudio/uni-cli-shared": "3.0.0-4060420250429001",

28
project.config.json Normal file
View File

@@ -0,0 +1,28 @@
{
"appid": "wxff56c34ef9aceb62",
"compileType": "miniprogram",
"libVersion": "3.8.10",
"packOptions": {
"ignore": [],
"include": []
},
"setting": {
"coverView": true,
"es6": true,
"postcss": true,
"minified": true,
"enhance": true,
"showShadowRootInWxmlPanel": true,
"packNpmRelationList": [],
"babelSetting": {
"ignore": [],
"disablePlugins": [],
"outputPath": ""
}
},
"condition": {},
"editorSetting": {
"tabIndent": "insertSpaces",
"tabSize": 4
}
}

View File

@@ -0,0 +1,7 @@
{
"description": "项目私有配置文件。此文件中的内容将覆盖 project.config.json 中的相同字段。项目的改动优先同步到此文件中。详见文档https://developers.weixin.qq.com/miniprogram/dev/devtools/projectconfig.html",
"projectname": "webUI",
"setting": {
"compileHotReLoad": true
}
}

View File

@@ -3,21 +3,11 @@ export default {
onLaunch: function () {
console.log('App Launch');
// 检查本地存储中是否有同意协议的记录
try {
const hasAgreed = uni.getStorageSync('hasAgreedToTerms');
// 如果没有同意过,显示协议页面
if (hasAgreed !== 'true') {
// 使用setTimeout避免可能的导航冲突
setTimeout(() => {
uni.navigateTo({
url: '/pages/agreement/agreement'
});
}, 500);
}
} catch (e) {
console.error('Check agreement status error:', e);
}
// 应用启动时的全局初始化逻辑
// 启动页会自动处理倒计时和页面跳转
// 可以在这里添加其他全局初始化逻辑
// 例如:设置全局变量、注册事件监听器等
},
onShow: function () {

View File

@@ -4,7 +4,9 @@
<view class="agreement-header">
<text class="agreement-title">用户须知</text>
</view>
<scroll-view class="agreement-body" scroll-y show-scrollbar="true">
<!-- 用普通view替代scroll-view -->
<view class="agreement-body">
<view class="agreement-inner">
<view class="agreement-section">
<view class="section-title">1 年龄与身份</view>
@@ -29,17 +31,32 @@
<text class="section-item">3.3 若不同意本须知请立即退出并停止使用本平台及相关产品</text>
</view>
</view>
</scroll-view>
</view>
<view class="agreement-footer">
<button class="btn-disagree" @click="handleDisagree">暂不进入</button>
<button class="btn-agree" @click="handleAgree">确定</button>
<view
class="btn-disagree"
:class="{ 'btn-disabled': isProcessing }"
@click.stop.prevent="handleDisagree"
@tap.stop.prevent="handleDisagree"
>
{{ isProcessing ? '处理中...' : '暂不进入' }}
</view>
<view
class="btn-agree"
:class="{ 'btn-disabled': isProcessing }"
@click.stop.prevent="handleAgree"
@tap.stop.prevent="handleAgree"
>
{{ isProcessing ? '处理中...' : '确定' }}
</view>
</view>
</view>
</view>
</template>
<script setup>
import { ref, defineEmits } from 'vue';
import { ref, onMounted, nextTick } from 'vue';
const props = defineProps({
visible: {
@@ -50,15 +67,80 @@ const props = defineProps({
const emit = defineEmits(['agree', 'disagree']);
// 处理同意事件
const handleAgree = () => {
emit('agree');
// 防止重复点击的状态
const isProcessing = ref(false);
// 组件挂载时的调试信息
onMounted(() => {
console.log('UserAgreement component mounted, visible:', props.visible);
});
// 防抖处理函数
const debounce = (func, wait) => {
let timeout;
return function executedFunction(...args) {
const later = () => {
clearTimeout(timeout);
func(...args);
};
clearTimeout(timeout);
timeout = setTimeout(later, wait);
};
};
// 处理同意事件
const handleAgree = debounce(async () => {
if (isProcessing.value) {
console.log('UserAgreement: handleAgree already processing, skipping');
return;
}
isProcessing.value = true;
console.log('UserAgreement: handleAgree clicked');
try {
console.log('About to emit agree event');
emit('agree');
console.log('Agree event emitted');
// 确保DOM更新完成
await nextTick();
} catch (error) {
console.error('Error in handleAgree:', error);
} finally {
// 延迟重置状态,避免快速连续点击
setTimeout(() => {
isProcessing.value = false;
}, 300);
}
}, 300);
// 处理不同意事件
const handleDisagree = () => {
emit('disagree');
};
const handleDisagree = debounce(async () => {
if (isProcessing.value) {
console.log('UserAgreement: handleDisagree already processing, skipping');
return;
}
isProcessing.value = true;
console.log('UserAgreement: handleDisagree clicked');
try {
console.log('About to emit disagree event');
emit('disagree');
console.log('Disagree event emitted');
// 确保DOM更新完成
await nextTick();
} catch (error) {
console.error('Error in handleDisagree:', error);
} finally {
// 延迟重置状态,避免快速连续点击
setTimeout(() => {
isProcessing.value = false;
}, 300);
}
}, 300);
</script>
<style scoped>
@@ -72,7 +154,8 @@ const handleDisagree = () => {
display: flex;
align-items: center;
justify-content: center;
z-index: 9999;
z-index: 99999;
pointer-events: auto;
}
.agreement-content {
@@ -84,6 +167,7 @@ const handleDisagree = () => {
display: flex;
flex-direction: column;
max-height: 88vh;
pointer-events: auto;
}
.agreement-header {
@@ -100,6 +184,7 @@ const handleDisagree = () => {
.agreement-body {
max-height: 70vh;
overflow-y: auto;
box-sizing: border-box;
}
@@ -153,6 +238,12 @@ const handleDisagree = () => {
font-size: 30rpx;
margin: 0;
border-radius: 0;
border: none;
outline: none;
cursor: pointer;
pointer-events: auto;
user-select: none;
transition: all 0.2s ease;
}
.btn-disagree {
@@ -161,8 +252,30 @@ const handleDisagree = () => {
border-right: 1rpx solid #EEEEEE;
}
.btn-disagree:hover {
background: #f5f5f5;
}
.btn-disagree:active {
background: #eeeeee;
}
.btn-agree {
background: #FF9800;
color: #FFFFFF;
}
.btn-agree:hover {
background: #e68900;
}
.btn-agree:active {
background: #cc7700;
}
.btn-disabled {
background: #cccccc;
color: #999999;
cursor: not-allowed;
}
</style>

View File

@@ -12,7 +12,7 @@
"compilerVersion" : 3,
"splashscreen" : {
"alwaysShowBeforeRender" : true,
"waiting" : true,
"waiting" : false,
"autoclose" : true,
"delay" : 0
},
@@ -50,11 +50,20 @@
"quickapp" : {},
/* */
"mp-weixin" : {
"appid" : "",
"appid" : "wxff56c34ef9aceb62",
"setting" : {
"urlCheck" : false
"urlCheck" : false,
"es6": true,
"postcss": true,
"minified": true
},
"usingComponents" : true
"usingComponents" : true,
"permission": {
"scope.userLocation": {
"desc": "您的位置信息将用于小程序位置接口的效果展示"
}
},
"requiredPrivateInfos": []
},
"mp-alipay" : {
"usingComponents" : true

View File

@@ -1,5 +1,16 @@
{
"lazyCodeLoading": "requiredComponents",
"pages": [
{
"path": "pages/splash/splash",
"style": {
"navigationStyle": "custom",
"disableScroll": true,
"app-plus": {
"popGesture": "none"
}
}
},
{
"path": "pages/index/index",
"style": {
@@ -39,6 +50,12 @@
"popGesture": "none"
}
}
},
{
"path": "pages/chat/chat",
"style": {
"navigationStyle": "custom"
}
}
],
"globalStyle": {
@@ -55,14 +72,11 @@
"list": [
{
"pagePath": "pages/index/index",
"iconPath": "static/tabbar/home.png",
"selectedIconPath": "static/tabbar/home_selected.png",
"text": "首页"
},
{
"pagePath": "pages/mine/mine",
"iconPath": "static/tabbar/mine.png",
"selectedIconPath": "static/tabbar/mine_selected.png",
"text": "我的"
}
]

View File

@@ -17,19 +17,15 @@ const handleAgree = () => {
// 保存到本地存储
uni.setStorageSync('hasAgreedToTerms', 'true');
// 返回上一页或首页
uni.navigateBack({
fail: () => {
uni.switchTab({
url: '/pages/index/index'
});
}
// 跳转到"我的"页面
uni.switchTab({
url: '/pages/mine/mine'
});
} catch (e) {
console.error('Save agreement status error:', e);
// 发生错误时也返回首页
// 发生错误时也跳转到"我的"页面
uni.switchTab({
url: '/pages/index/index'
url: '/pages/mine/mine'
});
}
};

1056
src/pages/chat/chat.vue Normal file

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -51,8 +51,12 @@
</view>
<!-- 退出登录按钮仅登录后显示 -->
<view class="logout-section" v-if="isLoggedIn">
<view class="logout-section">
<button class="logout-btn" @click="handleLogout">退出登录</button>
<button class="logout-btn" style="margin-top: 20rpx; background-color: #ff9800; color: white;" @click="testDirectApiCall">直接测试API</button>
<text style="display: block; margin-top: 20rpx; text-align: center; color: #999;">
登录状态: {{ isLoggedIn ? '已登录' : '未登录' }}
</text>
</view>
<!-- 用户须知弹窗 -->
@@ -81,15 +85,7 @@ const avatarUrl = ref('/static/default-avatar.png');
// 登录按钮文本
const loginButtonText = computed(() => {
// #ifdef MP-WEIXIN
return '微信一键登录';
// #endif
// #ifdef H5
return '立即登录';
// #endif
return '一键登录';
});
// 初始化函数
@@ -104,9 +100,22 @@ const initUserInfo = () => {
avatarUrl.value = parsedInfo.avatarUrl || '/static/default-avatar.png';
openid.value = parsedInfo.openid || '';
isLoggedIn.value = !!parsedInfo.token;
// 调试信息
uni.showToast({
title: `登录状态: ${isLoggedIn.value ? '已登录' : '未登录'}`,
icon: 'none',
duration: 2000
});
} catch (e) {
console.error('Parse user info error:', e);
}
} else {
uni.showToast({
title: '没有找到用户信息',
icon: 'none',
duration: 2000
});
}
} catch (e) {
console.error('Load user info error:', e);
@@ -115,102 +124,133 @@ const initUserInfo = () => {
// 页面加载时初始化
onMounted(() => {
// 初始化用户信息
// 初始化用户store
userStore.init();
// 初始化本地状态
initUserInfo();
});
// 登录处理
const handleLogin = () => {
// H5环境
// #ifdef H5
nickName.value = 'H5测试用户';
avatarUrl.value = '/static/default-avatar.png';
openid.value = 'h5-mock-openid';
isLoggedIn.value = true;
// 保存到本地
const userInfo = {
token: 'h5-mock-token',
nickName: nickName.value,
avatarUrl: avatarUrl.value,
openid: openid.value
};
const handleLogin = async () => {
try {
uni.setStorageSync('userInfo', JSON.stringify(userInfo));
} catch (e) {
console.error('Save user info error:', e);
}
uni.showToast({
title: '登录成功',
icon: 'success'
});
return;
// #endif
// 微信环境
// #ifdef MP-WEIXIN
uni.getUserProfile({
desc: '用于完善用户资料',
success: (res) => {
const userInfo = res.userInfo;
nickName.value = userInfo.nickName;
avatarUrl.value = userInfo.avatarUrl;
openid.value = 'wx-' + Date.now();
isLoggedIn.value = true;
// 保存到本地
const storeInfo = {
token: 'wx-mock-token',
nickName: nickName.value,
avatarUrl: avatarUrl.value,
openid: openid.value
};
try {
uni.setStorageSync('userInfo', JSON.stringify(storeInfo));
} catch (e) {
console.error('Save user info error:', e);
}
uni.showToast({
title: '登录成功',
icon: 'success'
});
},
fail: (err) => {
console.error('Login failed:', err);
uni.showToast({
title: '登录失败',
icon: 'none'
});
// 先清理假登录数据
console.log('开始登录,先清理假登录数据...');
userStore.clearFakeLoginData();
uni.showLoading({
title: '登录中...'
});
// 使用store中的真实登录方法
await userStore.login();
// 登录成功后更新本地状态
initUserInfo();
uni.hideLoading();
uni.showToast({
title: '登录成功',
icon: 'success'
});
} catch (error) {
uni.hideLoading();
console.error('Login failed:', error);
let errorMessage = '登录失败';
if (error.message) {
errorMessage = error.message;
} else if (typeof error === 'string') {
errorMessage = error;
}
});
// #endif
// 显示详细的错误信息
uni.showModal({
title: '登录失败',
content: `错误信息:${errorMessage}\n\n请检查\n1. 网络连接是否正常\n2. 后端服务是否运行\n3. 微信小程序配置是否正确`,
showCancel: false
});
}
};
// 退出登录
const handleLogout = () => {
const handleLogout = async () => {
// 用弹窗显示调试信息,确保用户能看到
uni.showToast({
title: '点击了退出登录',
icon: 'none',
duration: 2000
});
uni.showModal({
title: '提示',
content: '确定要退出登录吗?',
success: (res) => {
success: async (res) => {
if (res.confirm) {
try {
uni.removeStorageSync('userInfo');
} catch (e) {
console.error('Remove user info error:', e);
}
nickName.value = '';
avatarUrl.value = '/static/default-avatar.png';
openid.value = '';
isLoggedIn.value = false;
uni.showToast({
title: '已退出登录',
icon: 'success'
title: '确认退出',
icon: 'none',
duration: 1000
});
try {
uni.showLoading({
title: '退出中...'
});
// 显示token信息
uni.showToast({
title: `Token: ${userStore.token ? '有' : '无'}`,
icon: 'none',
duration: 2000
});
console.log('mine.vue: 开始调用userStore.logout()');
console.log('mine.vue: 当前store中的token:', userStore.token);
// 使用store中的真实登出方法
await userStore.logout();
uni.showToast({
title: 'logout执行完成',
icon: 'none',
duration: 1000
});
// 清空本地状态
nickName.value = '';
avatarUrl.value = '/static/default-avatar.png';
openid.value = '';
isLoggedIn.value = false;
uni.hideLoading();
uni.showToast({
title: '已退出登录',
icon: 'success'
});
} catch (error) {
uni.hideLoading();
uni.showToast({
title: '登出异常: ' + error.message,
icon: 'none',
duration: 3000
});
// 即使后台退出失败,也要清空本地状态
nickName.value = '';
avatarUrl.value = '/static/default-avatar.png';
openid.value = '';
isLoggedIn.value = false;
uni.showToast({
title: '已退出登录',
icon: 'success'
});
}
} else {
uni.showToast({
title: '取消退出',
icon: 'none',
duration: 1000
});
}
}
@@ -219,25 +259,169 @@ const handleLogout = () => {
// 显示用户须知
const showAgreement = () => {
console.log('showAgreement clicked, current showAgreementModal:', showAgreementModal.value);
showAgreementModal.value = true;
console.log('showAgreementModal set to:', showAgreementModal.value);
};
// 处理同意用户须知
const handleAgreeTerms = () => {
showAgreementModal.value = false;
const handleAgreeTerms = async () => {
console.log('mine.vue: handleAgreeTerms called');
try {
// 先关闭弹窗
showAgreementModal.value = false;
// 等待DOM更新
await uni.$nextTick?.() || Promise.resolve();
// 设置本地存储
uni.setStorageSync('hasAgreedToTerms', 'true');
uni.setStorageSync('hasVisitedMinePage', 'true');
// 显示成功提示
uni.showToast({
title: '已确认用户须知',
icon: 'success',
duration: 2000
});
} catch (e) {
console.error('Save agreement status error:', e);
uni.showToast({
title: '操作失败,请重试',
icon: 'none',
duration: 2000
});
// 如果失败,重新显示弹窗
showAgreementModal.value = true;
}
};
// 处理不同意用户须知
const handleDisagreeTerms = () => {
showAgreementModal.value = false;
const handleDisagreeTerms = async () => {
console.log('mine.vue: handleDisagreeTerms called');
try {
// 先关闭弹窗
showAgreementModal.value = false;
// 等待DOM更新
await uni.$nextTick?.() || Promise.resolve();
// 显示提示
uni.showToast({
title: '您可随时查看用户须知',
icon: 'none',
duration: 2000
});
} catch (e) {
console.error('Handle disagree error:', e);
showAgreementModal.value = false;
}
};
// 直接测试API
const testDirectApiCall = () => {
// 从store获取token
const currentToken = userStore.token;
uni.showModal({
title: '选择测试方法',
content: '请选择要测试的API调用方式',
cancelText: '普通方法',
confirmText: '请求体方法',
success: (res1) => {
if (res1.confirm) {
// 尝试在请求体中发送token
uni.showModal({
title: '请求体方法',
content: '在请求体中发送token',
showCancel: false,
success: () => {
uni.request({
url: 'http://8.145.52.111:8084/app/logout',
method: 'POST',
header: {
'Content-Type': 'application/json'
},
data: {
token: currentToken || ''
},
complete: (res) => {
uni.showModal({
title: '调用结果(请求体)',
content: JSON.stringify(res),
showCancel: false
});
}
});
}
});
} else {
// 普通方法: 选择URL方式
uni.showModal({
title: '普通方法',
content: '选择URL方式',
cancelText: '带参数URL',
confirmText: 'Header方式',
success: (res2) => {
if (res2.confirm) {
// Header方式
uni.showModal({
title: '调用信息',
content: `
在Header中发送token
Token: ${currentToken || '无'}
`,
showCancel: false,
success: () => {
uni.request({
url: 'http://8.145.52.111:8084/app/logout',
method: 'POST',
header: {
'Content-Type': 'application/json',
'Authorization': currentToken || ''
},
complete: (res) => {
uni.showModal({
title: '调用结果(Header)',
content: JSON.stringify(res),
showCancel: false
});
}
});
}
});
} else {
// 带参数URL方式
uni.showModal({
title: '调用信息',
content: `尝试带token参数的URL`,
showCancel: false,
success: () => {
const url = `http://8.145.52.111:8084/app/logout?token=${currentToken || ''}`;
uni.request({
url: url,
method: 'POST',
header: {
'Content-Type': 'application/json'
},
complete: (res) => {
uni.showModal({
title: '调用结果(URL参数)',
content: JSON.stringify(res),
showCancel: false
});
}
});
}
});
}
}
});
}
}
});
};
</script>

783
src/pages/splash/splash.vue Normal file
View File

@@ -0,0 +1,783 @@
<template>
<view class="splash-container">
<!-- 背景装饰层 -->
<view class="background-layer">
<!-- 渐变背景 -->
<view class="gradient-bg"></view>
<!-- 右上角树枝装饰 -->
<view class="branch-decoration">
<view class="branch-stem"></view>
<view class="branch-leaf leaf-1"></view>
<view class="branch-leaf leaf-2"></view>
<view class="branch-leaf leaf-3"></view>
<view class="small-flower">
<view class="petal"></view>
<view class="petal"></view>
<view class="petal"></view>
<view class="petal"></view>
<view class="center"></view>
</view>
</view>
<!-- 左上角优雅光环 -->
<view class="elegant-halo">
<view class="halo-ring ring-1"></view>
<view class="halo-ring ring-2"></view>
<view class="halo-ring ring-3"></view>
<view class="glow-orb"></view>
<view class="sparkle sparkle-1"></view>
<view class="sparkle sparkle-2"></view>
<view class="sparkle sparkle-3"></view>
</view>
<!-- 左下角现代线条艺术 -->
<view class="modern-lines">
<view class="flow-line line-1"></view>
<view class="flow-line line-2"></view>
<view class="flow-line line-3"></view>
<view class="glow-node node-1"></view>
<view class="glow-node node-2"></view>
<view class="floating-orb"></view>
</view>
<!-- 飘落的花瓣动画 -->
<view class="falling-petals">
<view class="falling-petal petal-1"></view>
<view class="falling-petal petal-2"></view>
<view class="falling-petal petal-3"></view>
<view class="falling-petal petal-4"></view>
<view class="falling-petal petal-5"></view>
</view>
</view>
<!-- 主内容区 -->
<view class="content-area">
<!-- 标题区域 -->
<view class="title-section">
<!-- 主标题 -->
<view class="main-title-wrapper">
<text class="main-title">因为AI 所以爱</text>
</view>
<!-- 装饰小花朵 -->
<view class="title-flower">
<view class="tiny-petal"></view>
<view class="tiny-petal"></view>
<view class="tiny-petal"></view>
<view class="tiny-petal"></view>
<view class="tiny-center"></view>
</view>
<!-- 副标题 -->
<view class="sub-title-wrapper">
<text class="sub-title">让创意绽放</text>
</view>
</view>
<!-- 装饰分隔线 -->
<view class="divider-line">
<view class="line-segment"></view>
<view class="center-flower">
<view class="mini-petal"></view>
<view class="mini-petal"></view>
<view class="mini-petal"></view>
<view class="mini-petal"></view>
</view>
<view class="line-segment"></view>
</view>
<!-- 倒计时和跳过按钮 -->
<view class="bottom-section">
<view class="countdown-container" @click="skipToHome">
<text class="countdown-text">{{ countdown }}s</text>
<text class="skip-text">跳过</text>
</view>
</view>
</view>
</view>
</template>
<script setup>
import { ref, onMounted, onUnmounted } from 'vue';
// 倒计时
const countdown = ref(5);
let timer = null;
// 跳转到主页
const skipToHome = () => {
if (timer) {
clearInterval(timer);
}
// 尝试使用reLaunch跳转
uni.reLaunch({
url: '/pages/index/index',
fail: () => {
// 如果reLaunch失败尝试switchTab
uni.switchTab({
url: '/pages/index/index',
fail: () => {
// 如果switchTab也失败使用redirectTo
uni.redirectTo({
url: '/pages/index/index'
});
}
});
}
});
};
// 生命周期
onMounted(() => {
// 启动倒计时
timer = setInterval(() => {
countdown.value--;
if (countdown.value <= 0) {
skipToHome();
}
}, 1000);
});
onUnmounted(() => {
if (timer) {
clearInterval(timer);
}
});
</script>
<style scoped>
/* 容器样式 */
.splash-container {
position: fixed;
top: 0;
left: 0;
width: 100vw;
height: 100vh;
background: #f8f6f0;
overflow: hidden;
}
/* 背景装饰层 */
.background-layer {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 1;
}
/* 渐变背景 */
.gradient-bg {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: radial-gradient(ellipse at center top, rgba(255, 123, 123, 0.05) 0%, transparent 50%),
radial-gradient(ellipse at bottom left, rgba(74, 155, 74, 0.05) 0%, transparent 50%),
radial-gradient(ellipse at bottom right, rgba(255, 235, 153, 0.05) 0%, transparent 50%);
}
/* 右上角树枝装饰 */
.branch-decoration {
position: absolute;
top: 60rpx;
right: 40rpx;
width: 120rpx;
height: 160rpx;
animation: gentle-sway 4s ease-in-out infinite;
}
.branch-stem {
position: absolute;
top: 20rpx;
left: 50%;
width: 3rpx;
height: 100rpx;
background: #4a9b4a;
transform: translateX(-50%) rotate(15deg);
border-radius: 2rpx;
}
.branch-leaf {
position: absolute;
width: 30rpx;
height: 45rpx;
background: #4a9b4a;
border-radius: 0 100% 0 100%;
opacity: 0.9;
}
.leaf-1 {
top: 35rpx;
left: 35rpx;
transform: rotate(-30deg);
}
.leaf-2 {
top: 60rpx;
right: 25rpx;
transform: rotate(45deg);
}
.leaf-3 {
top: 85rpx;
left: 40rpx;
transform: rotate(-15deg);
opacity: 0.8;
}
.small-flower {
position: absolute;
top: 15rpx;
right: 20rpx;
width: 40rpx;
height: 40rpx;
}
.small-flower .petal {
position: absolute;
width: 10rpx;
height: 18rpx;
background: #ff7b7b;
border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%;
transform-origin: 50% 100%;
opacity: 0.9;
}
.small-flower .petal:nth-child(1) { transform: rotate(0deg) translateY(-8rpx); }
.small-flower .petal:nth-child(2) { transform: rotate(90deg) translateY(-8rpx); }
.small-flower .petal:nth-child(3) { transform: rotate(180deg) translateY(-8rpx); }
.small-flower .petal:nth-child(4) { transform: rotate(270deg) translateY(-8rpx); }
.small-flower .center {
position: absolute;
top: 50%;
left: 50%;
width: 8rpx;
height: 8rpx;
background: #ffeb99;
border-radius: 50%;
transform: translate(-50%, -50%);
}
/* 左上角优雅光环 */
.elegant-halo {
position: absolute;
top: 80rpx;
left: 60rpx;
width: 100rpx;
height: 100rpx;
}
.halo-ring {
position: absolute;
top: 50%;
left: 50%;
border: 2rpx solid transparent;
border-radius: 50%;
transform: translate(-50%, -50%);
}
.ring-1 {
width: 60rpx;
height: 60rpx;
border-color: rgba(255, 123, 123, 0.3);
animation: rotate-slow 8s linear infinite;
}
.ring-2 {
width: 80rpx;
height: 80rpx;
border-color: rgba(255, 235, 153, 0.3);
animation: rotate-reverse 10s linear infinite;
}
.ring-3 {
width: 100rpx;
height: 100rpx;
border-color: rgba(74, 155, 74, 0.2);
animation: rotate-slow 12s linear infinite;
}
.glow-orb {
position: absolute;
top: 50%;
left: 50%;
width: 20rpx;
height: 20rpx;
background: radial-gradient(circle, rgba(255, 123, 123, 0.6) 0%, transparent 70%);
border-radius: 50%;
transform: translate(-50%, -50%);
animation: pulse-glow 2s ease-in-out infinite;
}
.sparkle {
position: absolute;
width: 4rpx;
height: 4rpx;
background: #ff7b7b;
border-radius: 50%;
animation: sparkle-twinkle 3s ease-in-out infinite;
}
.sparkle-1 {
top: 10rpx;
left: 30rpx;
animation-delay: 0s;
}
.sparkle-2 {
top: 40rpx;
right: 15rpx;
animation-delay: 1s;
}
.sparkle-3 {
bottom: 20rpx;
left: 15rpx;
animation-delay: 2s;
}
/* 左下角现代线条艺术 */
.modern-lines {
position: absolute;
bottom: 100rpx;
left: 40rpx;
width: 150rpx;
height: 120rpx;
}
.flow-line {
position: absolute;
height: 2rpx;
background: linear-gradient(90deg, transparent 0%, rgba(255, 123, 123, 0.6) 50%, transparent 100%);
border-radius: 1rpx;
transform-origin: left center;
}
.line-1 {
top: 20rpx;
left: 0;
width: 100rpx;
transform: rotate(-15deg);
animation: flow-pulse 3s ease-in-out infinite;
}
.line-2 {
top: 50rpx;
left: 10rpx;
width: 120rpx;
transform: rotate(10deg);
animation: flow-pulse 3s ease-in-out infinite 0.5s;
}
.line-3 {
top: 80rpx;
left: 5rpx;
width: 90rpx;
transform: rotate(-25deg);
animation: flow-pulse 3s ease-in-out infinite 1s;
}
.glow-node {
position: absolute;
width: 8rpx;
height: 8rpx;
background: radial-gradient(circle, #ff7b7b 0%, transparent 70%);
border-radius: 50%;
animation: node-pulse 2s ease-in-out infinite;
}
.node-1 {
top: 45rpx;
left: 80rpx;
}
.node-2 {
top: 70rpx;
left: 40rpx;
animation-delay: 1s;
}
.floating-orb {
position: absolute;
top: 40rpx;
right: 10rpx;
width: 15rpx;
height: 15rpx;
background: radial-gradient(circle, rgba(255, 235, 153, 0.8) 0%, transparent 60%);
border-radius: 50%;
animation: float-around 6s ease-in-out infinite;
}
/* 飘落花瓣 */
.falling-petals {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
pointer-events: none;
}
.falling-petal {
position: absolute;
width: 20rpx;
height: 25rpx;
background: rgba(255, 123, 123, 0.6);
border-radius: 0 100% 0 100%;
animation: petal-fall 8s linear infinite;
}
.petal-1 {
left: 10%;
animation-delay: 0s;
animation-duration: 7s;
}
.petal-2 {
left: 30%;
animation-delay: 2s;
animation-duration: 9s;
}
.petal-3 {
left: 50%;
animation-delay: 1s;
animation-duration: 8s;
}
.petal-4 {
left: 70%;
animation-delay: 3s;
animation-duration: 10s;
}
.petal-5 {
left: 90%;
animation-delay: 4s;
animation-duration: 7s;
}
/* 主内容区 */
.content-area {
position: relative;
z-index: 10;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100vh;
padding: 0 60rpx;
}
/* 标题区域 */
.title-section {
display: flex;
flex-direction: column;
align-items: center;
margin-bottom: 80rpx;
animation: fade-in-up 1s ease-out;
}
/* 主标题 */
.main-title-wrapper {
margin-bottom: 30rpx;
animation: fade-in-up 1s ease-out 0.2s both;
}
.main-title {
font-size: 60rpx;
font-weight: 900;
color: #333;
letter-spacing: 8rpx;
text-shadow: 3rpx 3rpx 8rpx rgba(0, 0, 0, 0.1);
display: block;
text-align: center;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
}
/* 装饰小花朵 */
.title-flower {
position: relative;
width: 40rpx;
height: 40rpx;
margin: 30rpx 0;
animation: fade-in-scale 1s ease-out 0.3s both;
}
.tiny-petal {
position: absolute;
width: 12rpx;
height: 20rpx;
background: rgba(255, 123, 123, 0.8);
border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%;
transform-origin: 50% 100%;
}
.tiny-petal:nth-child(1) {
transform: rotate(0deg) translateY(-10rpx);
}
.tiny-petal:nth-child(2) {
transform: rotate(90deg) translateY(-10rpx);
}
.tiny-petal:nth-child(3) {
transform: rotate(180deg) translateY(-10rpx);
}
.tiny-petal:nth-child(4) {
transform: rotate(270deg) translateY(-10rpx);
}
.tiny-center {
position: absolute;
top: 50%;
left: 50%;
width: 10rpx;
height: 10rpx;
background: #ffeb99;
border-radius: 50%;
transform: translate(-50%, -50%);
}
/* 副标题 */
.sub-title-wrapper {
position: relative;
animation: fade-in-up 1s ease-out 0.4s both;
}
.sub-title {
font-size: 32rpx;
color: #ff7b7b;
letter-spacing: 6rpx;
display: block;
text-align: center;
font-weight: 500;
position: relative;
}
/* 添加装饰星点 */
.sub-title-wrapper::before,
.sub-title-wrapper::after {
content: '✦';
position: absolute;
font-size: 20rpx;
color: rgba(255, 123, 123, 0.5);
animation: sparkle-twinkle 3s ease-in-out infinite;
}
.sub-title-wrapper::before {
left: -40rpx;
top: 50%;
transform: translateY(-50%);
}
.sub-title-wrapper::after {
right: -40rpx;
top: 50%;
transform: translateY(-50%);
animation-delay: 1.5s;
}
/* 装饰分隔线 */
.divider-line {
display: flex;
align-items: center;
justify-content: center;
margin-bottom: 80rpx;
animation: fade-in 1s ease-out 0.6s both;
}
.line-segment {
width: 60rpx;
height: 1rpx;
background: linear-gradient(90deg, transparent 0%, rgba(255, 123, 123, 0.5) 50%, transparent 100%);
}
.center-flower {
position: relative;
width: 30rpx;
height: 30rpx;
margin: 0 20rpx;
}
.mini-petal {
position: absolute;
width: 8rpx;
height: 12rpx;
background: rgba(255, 123, 123, 0.6);
border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%;
transform-origin: 50% 100%;
}
.mini-petal:nth-child(1) { transform: rotate(0deg) translateY(-6rpx); }
.mini-petal:nth-child(2) { transform: rotate(90deg) translateY(-6rpx); }
.mini-petal:nth-child(3) { transform: rotate(180deg) translateY(-6rpx); }
.mini-petal:nth-child(4) { transform: rotate(270deg) translateY(-6rpx); }
/* 底部区域 */
.bottom-section {
position: absolute;
bottom: 80rpx;
right: 60rpx;
animation: fade-in 1s ease-out 0.9s both;
}
.countdown-container {
display: flex;
align-items: center;
padding: 15rpx 30rpx;
background: rgba(255, 255, 255, 0.9);
border: 2rpx solid rgba(255, 123, 123, 0.3);
border-radius: 50rpx;
backdrop-filter: blur(10rpx);
transition: all 0.3s ease;
}
.countdown-container:active {
transform: scale(0.95);
background: rgba(255, 123, 123, 0.1);
}
.countdown-text {
font-size: 24rpx;
color: #ff7b7b;
font-weight: bold;
margin-right: 10rpx;
}
.skip-text {
font-size: 24rpx;
color: #666;
}
/* 动画定义 */
@keyframes gentle-sway {
0%, 100% { transform: rotate(-5deg); }
50% { transform: rotate(5deg); }
}
@keyframes rotate-slow {
from { transform: translate(-50%, -50%) rotate(0deg); }
to { transform: translate(-50%, -50%) rotate(360deg); }
}
@keyframes rotate-reverse {
from { transform: translate(-50%, -50%) rotate(360deg); }
to { transform: translate(-50%, -50%) rotate(0deg); }
}
@keyframes pulse-glow {
0%, 100% {
transform: translate(-50%, -50%) scale(1);
opacity: 0.8;
}
50% {
transform: translate(-50%, -50%) scale(1.2);
opacity: 0.4;
}
}
@keyframes sparkle-twinkle {
0%, 100% {
opacity: 0;
transform: scale(0);
}
50% {
opacity: 1;
transform: scale(1);
}
}
@keyframes flow-pulse {
0%, 100% {
opacity: 0.3;
transform: scaleX(0.8) rotate(var(--rotation, 0deg));
}
50% {
opacity: 0.8;
transform: scaleX(1) rotate(var(--rotation, 0deg));
}
}
@keyframes node-pulse {
0%, 100% {
transform: scale(1);
opacity: 0.6;
}
50% {
transform: scale(1.5);
opacity: 1;
}
}
@keyframes float-around {
0% {
transform: translate(0, 0) scale(1);
opacity: 0.8;
}
25% {
transform: translate(-20rpx, -10rpx) scale(1.1);
opacity: 0.6;
}
50% {
transform: translate(-10rpx, -20rpx) scale(0.9);
opacity: 0.8;
}
75% {
transform: translate(10rpx, -10rpx) scale(1.1);
opacity: 0.6;
}
100% {
transform: translate(0, 0) scale(1);
opacity: 0.8;
}
}
@keyframes petal-fall {
0% {
transform: translateY(-100rpx) translateX(0) rotate(0deg);
opacity: 0;
}
10% {
opacity: 0.6;
}
90% {
opacity: 0.6;
}
100% {
transform: translateY(calc(100vh + 100rpx)) translateX(100rpx) rotate(360deg);
opacity: 0;
}
}
@keyframes fade-in-up {
from {
opacity: 0;
transform: translateY(30rpx);
}
to {
opacity: 1;
transform: translateY(0);
}
}
@keyframes fade-in {
from { opacity: 0; }
to { opacity: 1; }
}
@keyframes fade-in-scale {
from {
opacity: 0;
transform: scale(0.5) rotate(180deg);
}
to {
opacity: 1;
transform: scale(1) rotate(360deg);
}
}
</style>

BIN
src/static/bailing.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 77 KiB

BIN
src/static/haomen.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 77 KiB

BIN
src/static/tunvlang.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 104 KiB

BIN
src/static/waimai.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 82 KiB

View File

@@ -48,10 +48,10 @@ export const useUserStore = defineStore('user', () => {
// 4. 保存用户信息
setUserInfo({
token: loginData.token,
token: loginData.data.token,
nickName: userProfileRes.userInfo.nickName,
avatarUrl: userProfileRes.userInfo.avatarUrl,
openid: loginData.openid
openid: loginData.data.openid
});
return Promise.resolve(loginData);
@@ -63,20 +63,6 @@ export const useUserStore = defineStore('user', () => {
// 获取用户信息
function getUserProfile() {
// H5环境下模拟用户信息
// #ifdef H5
return new Promise((resolve) => {
resolve({
userInfo: {
nickName: 'H5测试用户',
avatarUrl: '/static/default-avatar.png'
}
});
});
// #endif
// 非H5环境下获取真实用户信息
// #ifndef H5
return new Promise((resolve, reject) => {
uni.getUserProfile({
desc: '用于完善用户资料',
@@ -84,77 +70,61 @@ export const useUserStore = defineStore('user', () => {
resolve(res);
},
fail: (err) => {
console.error('获取用户信息失败:', err);
reject(err);
}
});
});
// #endif
}
// 获取微信登录凭证
function getWxLogin() {
// H5环境下模拟登录凭证
// #ifdef H5
return new Promise((resolve) => {
resolve({ code: 'mock-code-for-h5' });
});
// #endif
// 非H5环境下获取真实登录凭证
// #ifndef H5
return new Promise((resolve, reject) => {
uni.login({
provider: 'weixin',
success: (res) => {
resolve(res);
if (res.code) {
resolve(res);
} else {
reject(new Error('获取登录凭证失败'));
}
},
fail: (err) => {
console.error('微信登录失败:', err);
reject(err);
}
});
});
// #endif
}
// 调用后端登录接口
function wxLogin(code, userInfo) {
// H5环境下模拟登录避免API超时
// #ifdef H5
return new Promise((resolve) => {
setTimeout(() => {
resolve({
token: 'mock-token-for-h5',
openid: 'mock-openid-for-h5'
});
}, 300);
});
// #endif
// 非H5环境下调用实际接口
// #ifndef H5
return new Promise((resolve, reject) => {
uni.request({
url: 'https://your-api.com/api/login/wechat',
url: 'http://8.145.52.111:8091/app/login',
method: 'POST',
data: {
code,
userInfo
code
},
header: {
'Content-Type': 'application/json'
},
success: (res) => {
if (res.statusCode === 200 && res.data.token) {
resolve(res.data);
console.log('登录响应:', res);
const resData = res.data;
if (resData.code === 200 && resData.data && resData.data.token) {
resolve(resData);
} else {
reject(new Error('Login failed: ' + JSON.stringify(res.data)));
reject(new Error('登录失败: ' + (resData.message || JSON.stringify(resData))));
}
},
fail: (err) => {
console.error('登录请求失败:', err);
reject(err);
},
// 设置超时时间
timeout: 5000
timeout: 10000 // 增加超时时间到10秒
});
});
// #endif
}
// 保存用户信息
@@ -171,6 +141,53 @@ export const useUserStore = defineStore('user', () => {
// 退出登录
function logout() {
return new Promise((resolve, reject) => {
try {
// 获取token
const currentToken = token.value;
// 尝试调用登出接口
uni.request({
url: 'http://8.145.52.111:8091/app/logout',
method: 'POST',
header: {
'Content-Type': 'application/json',
'Authorization': currentToken || ''
},
data: {
token: currentToken || ''
},
success: (res) => {
console.log('登出成功:', res);
uni.showToast({
title: '登出成功',
icon: 'success'
});
},
fail: (err) => {
console.error('登出失败:', err);
uni.showToast({
title: '登出接口调用失败',
icon: 'none'
});
},
complete: () => {
// 无论成功失败,都清除本地数据
clearUserData();
resolve();
}
});
} catch (error) {
console.error('登出过程发生异常:', error);
// 发生异常时也要清除本地数据
clearUserData();
resolve(); // 用resolve而不是reject确保登出操作总是成功
}
});
}
// 清除用户数据的辅助函数
function clearUserData() {
token.value = '';
nickName.value = '';
avatarUrl.value = '';
@@ -179,6 +196,43 @@ export const useUserStore = defineStore('user', () => {
// 清除本地存储
uni.removeStorageSync('userInfo');
uni.removeStorageSync('custom_token');
uni.removeStorageSync('user_token');
}
// 清理假登录数据
function clearFakeLoginData() {
console.log('清理假登录数据...');
// 检查是否有无效的登录数据
const userInfo = uni.getStorageSync('userInfo');
if (userInfo) {
try {
const parsedInfo = JSON.parse(userInfo);
// 如果没有token或token为空清除数据
if (!parsedInfo.token || parsedInfo.token.trim() === '') {
console.log('发现无效的userInfo清除中...');
uni.removeStorageSync('userInfo');
}
} catch (e) {
console.log('userInfo格式错误清除中...');
uni.removeStorageSync('userInfo');
}
}
// 清除其他可能的假token
const customToken = uni.getStorageSync('custom_token');
if (customToken && customToken.trim() === '') {
uni.removeStorageSync('custom_token');
}
const userToken = uni.getStorageSync('user_token');
if (userToken && userToken.trim() === '') {
uni.removeStorageSync('user_token');
}
// 重新初始化状态
init();
}
// 新增:设置用户同意须知状态
@@ -209,6 +263,7 @@ export const useUserStore = defineStore('user', () => {
setUserInfo,
logout,
setAgreedToTerms,
setVisitedMinePage
setVisitedMinePage,
clearFakeLoginData
};
});

192
src/utils/aiCharacters.js Normal file
View File

@@ -0,0 +1,192 @@
// AI角色配置文件
export const aiCharacters = [
{
id: 5,
name: '萌妹小甜',
avatar: '/static/logo.png',
personality: '可爱活泼,喜欢撒娇',
greeting: '你好呀~我是小甜,今天想聊什么呢?',
voiceStyle: '甜美可爱',
responseStyle: '活泼俏皮,喜欢用表情符号',
interests: ['美食', '宠物', '音乐', '旅行'],
sampleResponses: [
'哇~听起来好有趣呢!✨',
'真的吗?我也好想试试看!😊',
'你真是太棒了!继续加油哦~💪',
'哈哈,你说话真有意思!😄',
'我也有同样的想法呢!🤔'
]
},
{
id: 6,
name: '御姐温柔',
avatar: '/static/logo.png',
personality: '知性优雅,温柔体贴',
greeting: '你好,我是温柔,有什么心事可以和我分享。',
voiceStyle: '温柔知性',
responseStyle: '成熟稳重,善解人意',
interests: ['阅读', '艺术', '哲学', '心理学'],
sampleResponses: [
'我理解你的感受,这确实不容易。',
'从另一个角度来看,也许会有不同的收获。',
'你的想法很有深度,我很欣赏。',
'人生就是这样,有起有落,重要的是保持内心的平静。',
'我相信你有能力处理好这件事。'
]
},
{
id: 7,
name: '童真小天使',
avatar: '/static/logo.png',
personality: '纯真可爱,充满好奇心',
greeting: '嗨!我是小天使,我们一起探索有趣的世界吧!',
voiceStyle: '天真烂漫',
responseStyle: '充满好奇,喜欢提问',
interests: ['游戏', '动画', '童话', '科学'],
sampleResponses: [
'哇!这是真的吗?好神奇呀!🌟',
'为什么为什么?能告诉我更多吗?🤔',
'我觉得这个世界真是太有趣了!',
'我们一起玩个游戏吧!🎮',
'你是我见过最有趣的人!'
]
},
{
id: 8,
name: '贴心男友',
avatar: '/static/logo.png',
personality: '温暖体贴,善解人意',
greeting: '宝贝,今天过得怎么样?有什么想聊的吗?',
voiceStyle: '温暖磁性',
responseStyle: '关怀备至,充满爱意',
interests: ['运动', '电影', '音乐', '美食'],
sampleResponses: [
'宝贝,你辛苦了,要注意休息哦。',
'无论发生什么,我都会陪在你身边。',
'你笑起来真好看,要多笑笑。',
'今天想吃什么?我给你做。',
'我爱你,永远都是。'
]
},
{
id: 13,
name: '搞笑达人',
avatar: '/static/logo.png',
personality: '幽默风趣,善于调节气氛',
greeting: '哈哈,我是搞笑达人!准备好笑到肚子疼了吗?',
voiceStyle: '幽默风趣',
responseStyle: '妙语连珠,逗人开心',
interests: ['喜剧', '段子', '脱口秀', '相声'],
sampleResponses: [
'哈哈,这个笑话我听过,但你的版本更好笑!😂',
'你知道吗?我刚才差点笑到从椅子上掉下来!',
'我觉得你可以去说相声了,太有天赋了!',
'生活就像一盒巧克力,有时候是苦的,但我们可以加点糖!',
'别担心笑一笑十年少你看起来永远18岁'
]
},
{
id: 14,
name: '博学智者',
avatar: '/static/logo.png',
personality: '知识渊博,思维深刻',
greeting: '你好,我是博学智者,让我们进行一场深度对话吧。',
voiceStyle: '沉稳睿智',
responseStyle: '引经据典,富有哲理',
interests: ['历史', '文学', '科学', '哲学'],
sampleResponses: [
'正如古人所说,学而时习之,不亦说乎。',
'这个问题让我想起了苏格拉底的一句话...',
'从历史的角度来看,这种现象有其必然性。',
'知识就像海洋,我们永远只能取一瓢饮。',
'思考是人类最宝贵的财富,你问得很好。'
]
},
{
id: 15,
name: '活力健将',
avatar: '/static/logo.png',
personality: '充满活力,积极向上',
greeting: '嘿!我是活力健将,让我们一起充满正能量!',
voiceStyle: '充满活力',
responseStyle: '积极向上,充满正能量',
interests: ['运动', '健身', '户外', '挑战'],
sampleResponses: [
'太棒了!这就是我想要听到的!💪',
'让我们一起挑战不可能!',
'运动是最好的良药,要不要一起锻炼?',
'每一天都是新的开始,加油!',
'你的能量感染了我,让我们继续前进!'
]
},
{
id: 16,
name: '文艺青年',
avatar: '/static/logo.png',
personality: '文艺浪漫,富有想象力',
greeting: '你好,我是文艺青年,让我们一起感受生活的美好。',
voiceStyle: '文艺浪漫',
responseStyle: '诗意盎然,富有想象力',
interests: ['诗歌', '音乐', '绘画', '摄影'],
sampleResponses: [
'生活就像一首诗,需要用心去品味。',
'你的话让我想起了那首美丽的诗...',
'艺术是心灵的窗户,让我们透过它看世界。',
'每一个瞬间都值得被记录,被珍藏。',
'你的想法很有诗意,我喜欢这样的交流。'
]
}
];
// 根据角色ID获取角色信息
export const getCharacterById = (id) => {
return aiCharacters.find(character => character.id == id);
};
// 根据角色性格生成回复
export const generateResponse = (character, userMessage) => {
const responses = character.sampleResponses;
const randomIndex = Math.floor(Math.random() * responses.length);
return responses[randomIndex];
};
// 根据用户消息内容智能选择回复
export const getSmartResponse = (character, userMessage) => {
const message = userMessage.toLowerCase();
// 根据关键词匹配不同的回复风格
if (message.includes('你好') || message.includes('hi') || message.includes('hello')) {
return character.greeting;
}
if (message.includes('谢谢') || message.includes('感谢')) {
const thanksResponses = {
5: '不用谢啦~能帮到你我很开心!😊',
6: '不用客气,这是我应该做的。',
7: '嘿嘿,不用谢!我们是好朋友嘛!',
8: '宝贝,为你做什么我都愿意。',
13: '哈哈,不用谢!能让你开心就是我的荣幸!',
14: '助人为乐,何须言谢。',
15: '不用谢!让我们一起变得更好!',
16: '帮助他人是人生最美的诗篇。'
};
return thanksResponses[character.id] || '不用谢!';
}
if (message.includes('再见') || message.includes('拜拜')) {
const goodbyeResponses = {
5: '拜拜~记得想我哦!😘',
6: '再见,期待下次的深度交流。',
7: '再见!下次我们一起玩更多有趣的游戏!',
8: '宝贝,我会想你的,早点回来。',
13: '哈哈,再见!记得保持笑容哦!',
14: '再见,愿智慧与你同行。',
15: '再见!保持活力,我们下次见!',
16: '再见,愿美好与你相伴。'
};
return goodbyeResponses[character.id] || '再见!';
}
// 默认返回随机回复
return generateResponse(character, userMessage);
};

554
src/utils/api.js Normal file
View File

@@ -0,0 +1,554 @@
// API服务文件
import { useUserStore } from '@/stores/user.js';
// 基础配置
const BASE_URL = 'http://8.145.52.111:8091'; // 根据后端地址调整
// 检查用户登录状态
const checkLoginStatus = () => {
const userStore = useUserStore();
const customToken = uni.getStorageSync('custom_token');
const userToken = uni.getStorageSync('user_token');
const userInfo = uni.getStorageSync('userInfo');
// 解析userInfo检查是否有有效的token
let userInfoToken = '';
if (userInfo) {
try {
const parsedUserInfo = JSON.parse(userInfo);
userInfoToken = parsedUserInfo.token || '';
} catch (e) {
console.warn('解析userInfo失败:', e);
}
}
// 只有存在有效token才认为已登录
const hasValidToken = !!(userStore.token || customToken || userToken || userInfoToken);
return {
isLoggedIn: hasValidToken,
token: userStore.token || customToken || userToken || userInfoToken
};
};
// 请求拦截器
const request = (options) => {
return new Promise((resolve, reject) => {
const userStore = useUserStore();
const loginStatus = checkLoginStatus();
// 默认配置
const defaultOptions = {
url: BASE_URL + options.url,
method: options.method || 'GET',
header: {
'Content-Type': 'application/json',
'Authorization': loginStatus.token || '',
...options.header
},
data: options.data || {},
timeout: options.timeout || 30000
};
// 发送请求
uni.request({
...defaultOptions,
success: (res) => {
console.log('API请求成功:', res);
console.log('响应状态码:', res.statusCode);
console.log('响应数据:', res.data);
// 处理响应
if (res.statusCode === 200) {
resolve(res.data);
} else {
reject({
code: res.statusCode,
message: res.data?.message || '请求失败',
data: res.data
});
}
},
fail: (err) => {
console.error('API请求失败:', err);
reject({
code: -1,
message: '网络请求失败',
error: err
});
}
});
});
};
// AI聊天API
export const chatAPI = {
// 同步聊天接口
syncChat: async (params) => {
const loginStatus = checkLoginStatus();
// 如果用户未登录,直接返回失败,让前端使用本地模拟
if (!loginStatus.isLoggedIn) {
console.log('用户未登录跳过API调用使用本地模拟');
return {
success: false,
error: { message: '用户未登录,使用本地模拟回复' },
isAnonymous: true
};
}
try {
const response = await request({
url: '/api/chat/sync',
method: 'POST',
data: {
message: params.message,
useFunctionCall: false,
modelId: null, // 使用默认模型
templateId: params.characterId // 使用角色模板ID
}
});
console.log('API原始响应:', response);
// 处理不同的响应格式 - 参考chat.vue的实现
let processedResponse = null;
// 如果响应是字符串,直接返回
if (typeof response === 'string') {
processedResponse = response;
}
// 如果响应是对象尝试提取AI回复
else if (typeof response === 'object' && response !== null) {
// 优先处理嵌套结构res.data.data.response
if (response.data && response.data.data && response.data.data.response) {
processedResponse = response.data.data.response;
console.log('从嵌套结构 data.data.response 提取回复:', processedResponse);
}
// 备用:直接使用 data.response
else if (response.data && response.data.response) {
processedResponse = response.data.response;
console.log('从字段 data.response 提取回复:', processedResponse);
}
// 检查是否为状态消息
else if (response.data && response.data.message) {
if (response.data.message === '对话成功') {
// 后端返回成功消息,使用默认回复
processedResponse = '我收到了你的消息,很高兴和你聊天!';
console.log('检测到对话成功状态,使用默认回复');
} else {
// 如果后端返回了错误信息,抛出错误
throw new Error(response.data.message);
}
}
// 尝试其他可能的字段名
else {
const possibleFields = ['message', 'response', 'content', 'reply', 'answer', 'text'];
for (const field of possibleFields) {
if (response[field] && typeof response[field] === 'string') {
processedResponse = response[field];
console.log(`从字段 ${field} 提取回复:`, processedResponse);
break;
}
}
// 如果还是没找到尝试在data中查找
if (!processedResponse && response.data) {
for (const field of possibleFields) {
if (response.data[field] && typeof response.data[field] === 'string') {
processedResponse = response.data[field];
console.log(`从字段 data.${field} 提取回复:`, processedResponse);
break;
}
}
}
}
}
// 如果仍然没有找到有效回复,使用默认回复
if (!processedResponse) {
processedResponse = '我收到了你的消息,很高兴和你聊天!';
console.log('未找到有效回复,使用默认回复');
}
return {
success: true,
data: processedResponse,
originalResponse: response
};
} catch (error) {
console.error('AI聊天API调用失败:', error);
return {
success: false,
error: error
};
}
},
// 异步聊天接口(如果需要)
asyncChat: async (params) => {
try {
const response = await request({
url: '/api/chat/async',
method: 'POST',
data: {
message: params.message,
characterId: params.characterId,
conversationId: params.conversationId || null,
...params
}
});
return {
success: true,
data: response
};
} catch (error) {
console.error('AI异步聊天API调用失败:', error);
return {
success: false,
error: error
};
}
},
// 获取聊天历史
getChatHistory: async (conversationId) => {
try {
const response = await request({
url: `/api/chat/history/${conversationId}`,
method: 'GET'
});
return {
success: true,
data: response
};
} catch (error) {
console.error('获取聊天历史失败:', error);
return {
success: false,
error: error
};
}
},
// 创建新对话
createConversation: async (characterId) => {
try {
const response = await request({
url: '/api/chat/conversation',
method: 'POST',
data: {
characterId: characterId
}
});
return {
success: true,
data: response
};
} catch (error) {
console.error('创建对话失败:', error);
return {
success: false,
error: error
};
}
}
};
// 语音相关API
export const voiceAPI = {
// 1. 文本转语音 - TTS功能
textToSpeech: async (text, options = {}) => {
try {
const loginStatus = checkLoginStatus();
if (!loginStatus.isLoggedIn) {
return {
success: false,
error: { message: '用户未登录' }
};
}
console.log('开始文本转语音:', text);
const response = await request({
url: '/api/chat/tts',
method: 'POST',
data: {
text: text,
voiceStyle: options.voiceStyle || 'default',
modelId: options.modelId || null,
templateId: options.templateId || null
}
});
console.log('文本转语音响应:', response);
// 处理响应数据
let audioUrl = null;
if (response.data && response.data.audioUrl) {
audioUrl = response.data.audioUrl;
} else if (response.audioUrl) {
audioUrl = response.audioUrl;
} else if (response.data && response.data.url) {
audioUrl = response.data.url;
} else if (response.url) {
audioUrl = response.url;
}
return {
success: true,
data: {
audioUrl: audioUrl,
originalResponse: response
}
};
} catch (error) {
console.error('文本转语音失败:', error);
return {
success: false,
error: error
};
}
},
// 2. 对话+语音合成 - 对话后转语音
chatWithTTS: async (message, options = {}) => {
try {
const loginStatus = checkLoginStatus();
if (!loginStatus.isLoggedIn) {
return {
success: false,
error: { message: '用户未登录' }
};
}
console.log('开始对话+语音合成:', message);
const response = await request({
url: '/api/chat/answer-tts',
method: 'POST',
data: {
message: message,
modelId: options.modelId || null,
templateId: options.templateId || null,
voiceStyle: options.voiceStyle || 'default'
}
});
console.log('对话+语音合成响应:', response);
// 处理响应数据
let aiResponse = null;
let audioUrl = null;
if (response.data) {
aiResponse = response.data.response || response.data.text || response.data.message;
audioUrl = response.data.audioUrl || response.data.url;
}
return {
success: true,
data: {
aiResponse: aiResponse,
audioUrl: audioUrl,
originalResponse: response
}
};
} catch (error) {
console.error('对话+语音合成失败:', error);
return {
success: false,
error: error
};
}
},
// 3. 语音对话 - 完整语音交互流程
voiceChat: async (filePath, options = {}) => {
try {
const loginStatus = checkLoginStatus();
// 如果用户未登录,直接返回失败,让前端使用降级处理
if (!loginStatus.isLoggedIn) {
console.log('用户未登录语音对话跳过API调用');
return {
success: false,
error: { message: '用户未登录,使用降级处理' }
};
}
console.log('开始语音对话,文件路径:', filePath);
// 构建认证头
let authHeader = '';
if (loginStatus.token) {
authHeader = loginStatus.token.startsWith('Bearer ') ? loginStatus.token : 'Bearer ' + loginStatus.token;
}
return new Promise((resolve) => {
uni.uploadFile({
url: BASE_URL + '/api/chat/voice-chat',
filePath: filePath,
name: 'audio',
header: authHeader ? {
'Authorization': authHeader
} : {},
formData: {
modelId: options.modelId || null,
templateId: options.templateId || null,
voiceStyle: options.voiceStyle || 'default'
},
success: (res) => {
console.log('语音对话上传成功:', res);
try {
const data = JSON.parse(res.data);
console.log('语音对话响应数据:', data);
if (data.code === 200 && data.data) {
resolve({
success: true,
data: {
userText: data.data.userText || data.data.text,
aiResponse: data.data.aiResponse || data.data.response,
audioUrl: data.data.audioUrl || data.data.url
}
});
} else {
resolve({
success: false,
error: { message: data.message || '语音对话失败' }
});
}
} catch (parseError) {
console.error('解析语音对话响应失败:', parseError);
resolve({
success: false,
error: { message: '解析响应失败' }
});
}
},
fail: (err) => {
console.error('语音对话上传失败:', err);
resolve({
success: false,
error: err
});
}
});
});
} catch (error) {
console.error('语音对话失败:', error);
return {
success: false,
error: error
};
}
},
// 4. 音频文件上传语音对话
uploadVoiceChat: async (filePath, options = {}) => {
try {
const loginStatus = checkLoginStatus();
// 如果用户未登录,直接返回失败,让前端使用降级处理
if (!loginStatus.isLoggedIn) {
console.log('用户未登录上传音频文件语音对话跳过API调用');
return {
success: false,
error: { message: '用户未登录,使用降级处理' }
};
}
console.log('开始上传音频文件语音对话,文件路径:', filePath);
// 构建认证头
let authHeader = '';
if (loginStatus.token) {
authHeader = loginStatus.token.startsWith('Bearer ') ? loginStatus.token : 'Bearer ' + loginStatus.token;
}
return new Promise((resolve) => {
uni.uploadFile({
url: BASE_URL + '/api/chat/upload-voice-chat',
filePath: filePath,
name: 'audio',
header: authHeader ? {
'Authorization': authHeader
} : {},
formData: {
modelId: options.modelId || null,
templateId: options.templateId || null,
voiceStyle: options.voiceStyle || 'default'
},
success: (res) => {
console.log('上传音频文件语音对话成功:', res);
try {
const data = JSON.parse(res.data);
console.log('上传音频文件语音对话响应数据:', data);
if (data.code === 200 && data.data) {
resolve({
success: true,
data: {
userText: data.data.userText || data.data.text,
aiResponse: data.data.aiResponse || data.data.response,
audioUrl: data.data.audioUrl || data.data.url
}
});
} else {
resolve({
success: false,
error: { message: data.message || '上传音频文件语音对话失败' }
});
}
} catch (parseError) {
console.error('解析上传音频文件语音对话响应失败:', parseError);
resolve({
success: false,
error: { message: '解析响应失败' }
});
}
},
fail: (err) => {
console.error('上传音频文件语音对话失败:', err);
resolve({
success: false,
error: err
});
}
});
});
} catch (error) {
console.error('上传音频文件语音对话失败:', error);
return {
success: false,
error: error
};
}
},
// 兼容性方法:语音识别(降级处理)
speechToText: async (filePath) => {
console.warn('speechToText 方法已废弃,请使用 voiceChat 或 uploadVoiceChat');
// 降级处理:使用语音对话接口
const result = await voiceAPI.voiceChat(filePath);
if (result.success) {
return {
success: true,
data: result.data.userText
};
}
return result;
}
};
// 导出默认请求方法
export default request;

119
src/utils/debug.js Normal file
View File

@@ -0,0 +1,119 @@
// 调试工具
export const debugAPI = {
// 打印API请求详情
logRequest: (url, method, data) => {
console.log('=== API请求详情 ===');
console.log('URL:', url);
console.log('方法:', method);
console.log('请求数据:', data);
console.log('时间:', new Date().toLocaleString());
console.log('==================');
},
// 打印API响应详情
logResponse: (response) => {
console.log('=== API响应详情 ===');
console.log('完整响应:', response);
console.log('响应类型:', typeof response);
console.log('是否为对象:', typeof response === 'object');
if (typeof response === 'object' && response !== null) {
console.log('响应键:', Object.keys(response));
console.log('响应值:', Object.values(response));
}
console.log('时间:', new Date().toLocaleString());
console.log('==================');
},
// 分析响应数据结构
analyzeResponse: (response) => {
console.log('=== 响应数据分析 ===');
if (typeof response === 'string') {
console.log('响应是字符串:', response);
return { type: 'string', value: response };
}
if (typeof response === 'object' && response !== null) {
console.log('响应是对象');
console.log('对象结构:', JSON.stringify(response, null, 2));
// 查找可能的AI回复字段
const possibleFields = ['response', 'message', 'content', 'reply', 'answer', 'text', 'data'];
const foundFields = {};
possibleFields.forEach(field => {
if (response.hasOwnProperty(field)) {
foundFields[field] = response[field];
console.log(`找到字段 ${field}:`, response[field]);
}
});
return { type: 'object', fields: foundFields, full: response };
}
console.log('未知响应类型:', typeof response);
return { type: 'unknown', value: response };
},
// 测试API响应处理
testResponseHandling: (response) => {
console.log('=== 测试响应处理 ===');
const analysis = debugAPI.analyzeResponse(response);
// 尝试提取AI回复
let aiResponse = null;
if (analysis.type === 'string') {
aiResponse = analysis.value;
console.log('从字符串提取回复:', aiResponse);
} else if (analysis.type === 'object') {
// 尝试多种字段
const fields = ['response', 'message', 'content', 'reply', 'answer', 'text'];
for (const field of fields) {
if (response[field] && typeof response[field] === 'string') {
aiResponse = response[field];
console.log(`从字段 ${field} 提取回复:`, aiResponse);
break;
}
}
// 如果没找到,尝试嵌套对象
if (!aiResponse && response.data) {
for (const field of fields) {
if (response.data[field] && typeof response.data[field] === 'string') {
aiResponse = response.data[field];
console.log(`从 data.${field} 提取回复:`, aiResponse);
break;
}
}
}
}
console.log('最终提取的回复:', aiResponse);
console.log('回复是否有效:', aiResponse && typeof aiResponse === 'string' && aiResponse.trim());
// 检测是否为状态信息而非实际AI回复
if (aiResponse && typeof aiResponse === 'string') {
const statusKeywords = ['对话成功', 'success', '请求成功', '成功', 'ok', '完成'];
const isStatusMessage = statusKeywords.some(keyword =>
aiResponse.toLowerCase().includes(keyword.toLowerCase())
);
if (isStatusMessage) {
console.warn('⚠️ 检测到状态信息而非AI回复:', aiResponse);
console.log('建议使用本地模拟回复');
}
}
console.log('==================');
return aiResponse;
}
};
// 导出默认调试工具
export default debugAPI;

0
test.md Normal file
View File