diff --git a/package.json b/package.json
index 727e25d..50ccd4d 100644
--- a/package.json
+++ b/package.json
@@ -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",
diff --git a/project.config.json b/project.config.json
new file mode 100644
index 0000000..12aa3a6
--- /dev/null
+++ b/project.config.json
@@ -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
+ }
+}
\ No newline at end of file
diff --git a/project.private.config.json b/project.private.config.json
new file mode 100644
index 0000000..76ecff9
--- /dev/null
+++ b/project.private.config.json
@@ -0,0 +1,7 @@
+{
+ "description": "项目私有配置文件。此文件中的内容将覆盖 project.config.json 中的相同字段。项目的改动优先同步到此文件中。详见文档:https://developers.weixin.qq.com/miniprogram/dev/devtools/projectconfig.html",
+ "projectname": "webUI",
+ "setting": {
+ "compileHotReLoad": true
+ }
+}
\ No newline at end of file
diff --git a/src/App.vue b/src/App.vue
index 3279daf..8b90be5 100644
--- a/src/App.vue
+++ b/src/App.vue
@@ -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 () {
diff --git a/src/components/UserAgreement.vue b/src/components/UserAgreement.vue
index bc34659..3d9136a 100644
--- a/src/components/UserAgreement.vue
+++ b/src/components/UserAgreement.vue
@@ -4,7 +4,9 @@
-
+
+
+
1 年龄与身份
@@ -29,17 +31,32 @@
3.3 若不同意本须知,请立即退出并停止使用本平台及相关产品。
-
+
+
\ No newline at end of file
diff --git a/src/manifest.json b/src/manifest.json
index 309b9ec..983bc05 100644
--- a/src/manifest.json
+++ b/src/manifest.json
@@ -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
diff --git a/src/pages.json b/src/pages.json
index dbb8896..99ebd05 100644
--- a/src/pages.json
+++ b/src/pages.json
@@ -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": "我的"
}
]
diff --git a/src/pages/agreement/agreement.vue b/src/pages/agreement/agreement.vue
index a156205..4f4fcac 100644
--- a/src/pages/agreement/agreement.vue
+++ b/src/pages/agreement/agreement.vue
@@ -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'
});
}
};
diff --git a/src/pages/chat/chat.vue b/src/pages/chat/chat.vue
new file mode 100644
index 0000000..704bf16
--- /dev/null
+++ b/src/pages/chat/chat.vue
@@ -0,0 +1,1056 @@
+
+
+
+
+
+ ←
+
+
+
+ {{ currentCharacter.name }}
+
+
+
+ 未登录
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ {{ message.content }}
+
+
+ 🔊
+
+
+ {{ message.time }}
+
+
+
+
+
+
+
+
+ {{ message.content }}
+ {{ message.time }}
+
+
+
+
+
+
+
+
+
+
+ {{ message.content }}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ {{ isRecording ? '🎤' : '🎙️' }}
+
+
+
+ 📤
+
+
+
+
+
+
+ 🎤 正在录音,松开结束
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/pages/index/index.vue b/src/pages/index/index.vue
index ff15b65..8e285a3 100644
--- a/src/pages/index/index.vue
+++ b/src/pages/index/index.vue
@@ -1,54 +1,114 @@
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
- TEST玩具
+ 因为AI 所以爱
-
- +
+
+ 🌸
创建
+ 开启创意之旅
-
- 🌐
- 连接设备
- SN: xxxxxxxx
+
+ {{ deviceConnected ? '🌟' : '⭕' }}
+ {{ deviceConnected ? '设备已连接' : '设备未连接' }}
+ SN: {{ deviceSN }}
+ ID: {{ deviceId }}
+
- 剧情
- 聊天
+
+ 🎭
+ 剧情
+
+
+ 💬
+ 聊天
+
-
-
-
-
-
- {{ item.tag }}
-
- {{ item.title }}
-
-
-
+
+
+
+
+
+
+
+ {{ item.tag }}
+
+ {{ item.title }}
+
+
+
+
+
-
+
-
-
+
+
+
+
+
+ {{ item.tag }}
+
+ {{ item.title }}
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
- 提示
- 请先登录后再操作
-
-
-
+
+
+ 💝 温馨提示
+ 请先登录后再开始您的创意之旅
+
+
+
@@ -63,20 +123,31 @@ import { useUserStore } from '@/stores/user.js';
const userStore = useUserStore();
const tabActive = ref('drama');
const showLoginModal = ref(false);
+const deviceConnected = ref(false);
+const deviceSN = ref('未连接');
+const deviceId = ref('30:ed:a0:12:99:60'); // 固定设备ID
// 数据
const dramaList = ref([
- { id: 1, cover: '/static/drama1.jpg', tag: '台词腔', title: '白领女友的温柔早安' },
- { id: 2, cover: '/static/drama2.jpg', tag: '人妻', title: '豪门女主的秘密生活' },
- { id: 3, cover: '/static/drama3.jpg', tag: '外卖媛', title: '外卖小姐姐的贴心问候' },
- { id: 4, cover: '/static/drama4.jpg', tag: '病娇', title: '因爱执仗的少女' },
+ { id: 1, cover: '/static/bailing.jpg', tag: '浪漫', title: '白领女友的温柔早安' },
+ { id: 2, cover: '/static/haomen.jpg', tag: '优雅', title: '豪门女主的秘密生活' },
+ { id: 3, cover: '/static/waimai.jpg', tag: '活泼', title: '外卖小姐姐的贴心问候' },
+ { id: 4, cover: '/static/tunvlang.jpg', tag: '深情', title: '因爱执著的少女' },
+ { id: 9, cover: '/static/logo.png', tag: '温暖', title: '邻家女孩的暖心故事' },
+ { id: 10, cover: '/static/logo.png', tag: '梦幻', title: '公主的浪漫邂逅' },
+ { id: 11, cover: '/static/logo.png', tag: '治愈', title: '咖啡店的午后时光' },
+ { id: 12, cover: '/static/logo.png', tag: '青春', title: '校园里的美好回忆' },
]);
const chatList = ref([
- { id: 5, cover: '/static/chat1.jpg', tag: '萌妹', title: '可爱萌妹陪你聊' },
- { id: 6, cover: '/static/chat2.jpg', tag: '御姐', title: '知性御姐的温柔夜话' },
- { id: 7, cover: '/static/chat3.jpg', tag: '萝莉', title: '萝莉的童真世界' },
- { id: 8, cover: '/static/chat4.jpg', tag: '男友', title: '贴心男友的陪伴' },
+ { id: 5, cover: '/static/logo.png', tag: '可爱', title: '萌妹陪你聊天' },
+ { id: 6, cover: '/static/logo.png', tag: '知性', title: '御姐的温柔夜话' },
+ { id: 7, cover: '/static/logo.png', tag: '纯真', title: '童真世界探索' },
+ { id: 8, cover: '/static/logo.png', tag: '贴心', title: '温暖男友陪伴' },
+ { id: 13, cover: '/static/logo.png', tag: '幽默', title: '搞笑达人的日常' },
+ { id: 14, cover: '/static/logo.png', tag: '智慧', title: '博学者的深度对话' },
+ { id: 15, cover: '/static/logo.png', tag: '活力', title: '运动健将的正能量' },
+ { id: 16, cover: '/static/logo.png', tag: '艺术', title: '文艺青年的灵感分享' },
]);
// 计算属性
@@ -84,19 +155,127 @@ const currentList = computed(() => {
return tabActive.value === 'drama' ? dramaList.value : chatList.value;
});
+// 左列数据(偶数索引:0, 2, 4...)
+const leftColumnItems = computed(() => {
+ return currentList.value.filter((item, index) => index % 2 === 0);
+});
+
+// 右列数据(奇数索引:1, 3, 5...)
+const rightColumnItems = computed(() => {
+ return currentList.value.filter((item, index) => index % 2 === 1);
+});
+
// 生命周期
onMounted(() => {
userStore.init();
+ // 获取设备连接状态
+ checkDeviceStatus();
});
+// 检查设备状态
+const checkDeviceStatus = () => {
+ // 如果用户已登录,则获取设备状态
+ if (userStore.isLoggedIn) {
+ uni.showLoading({
+ title: '获取设备状态...'
+ });
+
+ uni.request({
+ url: 'http://8.145.52.111:8084/api/device/status',
+ method: 'GET',
+ header: {
+ 'Authorization': userStore.token || ''
+ },
+ success: (res) => {
+ console.log('设备状态响应:', res);
+ if (res.statusCode === 200 && res.data.data) {
+ const data = res.data.data;
+ deviceConnected.value = data.connected || false;
+ deviceSN.value = data.sn || '未知SN';
+ // 不再从响应中获取设备ID,使用固定值
+ }
+ },
+ fail: (err) => {
+ console.error('获取设备状态失败:', err);
+ },
+ complete: () => {
+ uni.hideLoading();
+ }
+ });
+ }
+};
+
// 方法
const handleUse = (item) => {
console.log('使用角色:', item);
- uni.showToast({
- title: `正在加载: ${item.title}`,
- icon: 'none'
+
+ // 显示加载提示
+ uni.showLoading({
+ title: `正在设置角色...`
+ });
+
+ // 获取token
+ const token = userStore.token;
+
+ // 根据角色id映射到roleId参数
+ let roleId = 0;
+ if (tabActive.value === 'drama') {
+ // 剧情角色映射
+ switch (item.id) {
+ case 1: roleId = 1; break; // 白领女友
+ case 2: roleId = 2; break; // 豪门女主
+ case 3: roleId = 3; break; // 外卖小姐姐
+ case 4: roleId = 4; break; // 病娇少女
+ default: roleId = 0;
+ }
+ } else {
+ // 聊天角色跳转到聊天页面
+ uni.hideLoading();
+ uni.navigateTo({
+ url: `/pages/chat/chat?characterId=${item.id}`
+ });
+ return;
+ }
+
+ // 不再检查设备ID是否存在,直接使用固定值
+
+ // 调用设备更新API - 使用form data格式
+ uni.request({
+ url: 'http://8.145.52.111:8084/api/device/update',
+ method: 'POST',
+ header: {
+ 'Content-Type': 'application/x-www-form-urlencoded',
+ 'Authorization': token || ''
+ },
+ data: {
+ roleId: roleId,
+ deviceId: deviceId.value // 使用固定的设备ID
+ },
+ success: (res) => {
+ console.log('设备更新成功:', res);
+ if (res.statusCode === 200) {
+ uni.showToast({
+ title: `角色设置成功`,
+ icon: 'success'
+ });
+ } else {
+ uni.showToast({
+ title: res.data?.message || '设备更新失败',
+ icon: 'none'
+ });
+ }
+ },
+ fail: (err) => {
+ console.error('设备更新失败:', err);
+ uni.showToast({
+ title: '设备更新失败',
+ icon: 'none'
+ });
+ },
+ complete: () => {
+ uni.hideLoading();
+ }
});
- // 这里添加跳转到详情页或使用页面的逻辑
};
const showLoginTip = () => {
@@ -115,9 +294,184 @@ const goToCreate = () => {
url: '/pages/create/create'
});
};
+
+const connectDevice = () => {
+ // 显示加载提示
+ uni.showLoading({
+ title: deviceConnected.value ? '断开连接中...' : '连接设备中...'
+ });
+
+ // 获取token
+ const token = userStore.token;
+
+ // 准备请求数据 - 始终使用固定设备ID
+ const requestData = {
+ deviceId: deviceId.value // 固定设备ID
+ };
+
+ // 调用设备连接/断开API
+ uni.request({
+ url: `http://8.145.52.111:8084/api/device/${deviceConnected.value ? 'disconnect' : 'connect'}`,
+ method: 'POST',
+ header: {
+ 'Content-Type': 'application/json',
+ 'Authorization': token || ''
+ },
+ data: requestData,
+ success: (res) => {
+ console.log('设备操作成功:', res);
+ if (res.statusCode === 200) {
+ // 更新设备状态
+ deviceConnected.value = !deviceConnected.value;
+
+ if (deviceConnected.value) {
+ // 如果是连接成功,更新设备SN
+ if (res.data.data) {
+ deviceSN.value = res.data.data.sn || '未知SN';
+ // 不更新设备ID,保持固定值
+ }
+ } else {
+ // 如果是断开连接,重置设备SN
+ deviceSN.value = '未连接';
+ // 设备ID保持不变
+ }
+
+ uni.showToast({
+ title: deviceConnected.value ? '设备已连接' : '设备已断开',
+ icon: 'success'
+ });
+ } else {
+ uni.showToast({
+ title: res.data?.message || '操作失败',
+ icon: 'none'
+ });
+ }
+ },
+ fail: (err) => {
+ console.error('设备操作失败:', err);
+ uni.showToast({
+ title: '设备操作失败',
+ icon: 'none'
+ });
+ },
+ complete: () => {
+ uni.hideLoading();
+ }
+ });
+};
diff --git a/src/pages/mine/mine.vue b/src/pages/mine/mine.vue
index 3547502..5579a3e 100644
--- a/src/pages/mine/mine.vue
+++ b/src/pages/mine/mine.vue
@@ -51,8 +51,12 @@
-
+
+
+
+ 登录状态: {{ isLoggedIn ? '已登录' : '未登录' }}
+
@@ -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
+ });
+ }
+ });
+ }
+ });
+ }
+ }
+ });
+ }
+ }
+ });
};
diff --git a/src/pages/splash/splash.vue b/src/pages/splash/splash.vue
new file mode 100644
index 0000000..b132716
--- /dev/null
+++ b/src/pages/splash/splash.vue
@@ -0,0 +1,783 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 因为AI 所以爱
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 让创意绽放
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ {{ countdown }}s
+ 跳过
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/static/bailing.jpg b/src/static/bailing.jpg
new file mode 100644
index 0000000..f2bf39b
Binary files /dev/null and b/src/static/bailing.jpg differ
diff --git a/src/static/haomen.jpg b/src/static/haomen.jpg
new file mode 100644
index 0000000..c7fff1d
Binary files /dev/null and b/src/static/haomen.jpg differ
diff --git a/src/static/tunvlang.jpg b/src/static/tunvlang.jpg
new file mode 100644
index 0000000..abcee22
Binary files /dev/null and b/src/static/tunvlang.jpg differ
diff --git a/src/static/waimai.jpg b/src/static/waimai.jpg
new file mode 100644
index 0000000..bb3f5d3
Binary files /dev/null and b/src/static/waimai.jpg differ
diff --git a/src/stores/user.js b/src/stores/user.js
index a7cb4c9..977379c 100644
--- a/src/stores/user.js
+++ b/src/stores/user.js
@@ -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
};
});
\ No newline at end of file
diff --git a/src/utils/aiCharacters.js b/src/utils/aiCharacters.js
new file mode 100644
index 0000000..fda6c20
--- /dev/null
+++ b/src/utils/aiCharacters.js
@@ -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);
+};
diff --git a/src/utils/api.js b/src/utils/api.js
new file mode 100644
index 0000000..83c1b9b
--- /dev/null
+++ b/src/utils/api.js
@@ -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;
diff --git a/src/utils/debug.js b/src/utils/debug.js
new file mode 100644
index 0000000..0c4377f
--- /dev/null
+++ b/src/utils/debug.js
@@ -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;
diff --git a/test.md b/test.md
new file mode 100644
index 0000000..e69de29