feat: 支持本地/云托管双模式切换,添加测试用户2-19
This commit is contained in:
@@ -38,6 +38,14 @@ export default class Main {
|
||||
this.showLoading('正在加载...');
|
||||
console.log('[Main] 开始初始化...');
|
||||
|
||||
// 初始化云环境
|
||||
console.log('[Main] 初始化云环境...');
|
||||
wx.cloud.init({
|
||||
env: 'prod-4gc9i2da1c70fc52', // 云环境ID,需替换为实际值
|
||||
traceUser: true
|
||||
});
|
||||
console.log('[Main] 云环境初始化完成');
|
||||
|
||||
// 用户初始化(失败不阻塞)
|
||||
console.log('[Main] 初始化用户...');
|
||||
await this.userManager.init().catch(e => {
|
||||
|
||||
@@ -1,34 +1,90 @@
|
||||
/**
|
||||
* 网络请求工具
|
||||
* 网络请求工具 - 支持本地/云托管切换
|
||||
*/
|
||||
|
||||
// API基础地址(开发环境)
|
||||
const BASE_URL = 'https://express-fuvd-231535-4-1409819450.sh.run.tcloudbase.com/api';
|
||||
// ============================================
|
||||
// 环境配置(切换这里即可)
|
||||
// ============================================
|
||||
const ENV = 'cloud'; // 'local' = 本地后端, 'cloud' = 微信云托管
|
||||
|
||||
const CONFIG = {
|
||||
local: {
|
||||
baseUrl: 'http://localhost:8000/api'
|
||||
},
|
||||
cloud: {
|
||||
env: 'prod-6gjx1rd4c40f5884',
|
||||
serviceName: 'express-fuvd'
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 发送HTTP请求
|
||||
*/
|
||||
export function request(options) {
|
||||
if (ENV === 'local') {
|
||||
return requestLocal(options);
|
||||
} else {
|
||||
return requestCloud(options);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 本地后端请求(wx.request)
|
||||
*/
|
||||
function requestLocal(options) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const timeoutMs = options.timeout || 30000;
|
||||
|
||||
wx.request({
|
||||
url: BASE_URL + options.url,
|
||||
url: CONFIG.local.baseUrl + options.url,
|
||||
method: options.method || 'GET',
|
||||
data: options.data || {},
|
||||
timeout: timeoutMs,
|
||||
timeout: options.timeout || 30000,
|
||||
header: {
|
||||
'Content-Type': 'application/json',
|
||||
...options.header
|
||||
},
|
||||
success(res) {
|
||||
if (res.data.code === 0) {
|
||||
if (res.data && res.data.code === 0) {
|
||||
resolve(res.data.data);
|
||||
} else {
|
||||
reject(new Error(res.data.message || '请求失败'));
|
||||
reject(new Error(res.data?.message || '请求失败'));
|
||||
}
|
||||
},
|
||||
fail(err) {
|
||||
console.error('[HTTP-Local] 请求失败:', err);
|
||||
reject(err);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 云托管请求(wx.cloud.callContainer)
|
||||
*/
|
||||
function requestCloud(options) {
|
||||
return new Promise((resolve, reject) => {
|
||||
wx.cloud.callContainer({
|
||||
config: {
|
||||
env: CONFIG.cloud.env
|
||||
},
|
||||
path: '/api' + options.url,
|
||||
method: options.method || 'GET',
|
||||
data: options.data || {},
|
||||
header: {
|
||||
'X-WX-SERVICE': CONFIG.cloud.serviceName,
|
||||
'Content-Type': 'application/json',
|
||||
...options.header
|
||||
},
|
||||
success(res) {
|
||||
if (res.data && res.data.code === 0) {
|
||||
resolve(res.data.data);
|
||||
} else if (res.data) {
|
||||
reject(new Error(res.data.message || '请求失败'));
|
||||
} else {
|
||||
reject(new Error('响应数据异常'));
|
||||
}
|
||||
},
|
||||
fail(err) {
|
||||
console.error('[HTTP-Cloud] 请求失败:', err);
|
||||
reject(err);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -6,6 +6,42 @@ USE stardom_story;
|
||||
-- ============================================
|
||||
INSERT INTO `users` (`id`, `openid`, `nickname`, `avatar_url`, `gender`, `total_play_count`, `total_endings`) VALUES
|
||||
(1, 'test_user', '测试用户', '', 0, 0, 0);
|
||||
INSERT INTO `users` (`id`, `openid`, `nickname`, `avatar_url`, `gender`, `total_play_count`, `total_endings`) VALUES
|
||||
(2, 'test_user', '测试用户', '', 0, 0, 0);
|
||||
INSERT INTO `users` (`id`, `openid`, `nickname`, `avatar_url`, `gender`, `total_play_count`, `total_endings`) VALUES
|
||||
(3, 'test_user', '测试用户', '', 0, 0, 0);
|
||||
INSERT INTO `users` (`id`, `openid`, `nickname`, `avatar_url`, `gender`, `total_play_count`, `total_endings`) VALUES
|
||||
(4, 'test_user', '测试用户', '', 0, 0, 0);
|
||||
INSERT INTO `users` (`id`, `openid`, `nickname`, `avatar_url`, `gender`, `total_play_count`, `total_endings`) VALUES
|
||||
(5, 'test_user', '测试用户', '', 0, 0, 0);
|
||||
INSERT INTO `users` (`id`, `openid`, `nickname`, `avatar_url`, `gender`, `total_play_count`, `total_endings`) VALUES
|
||||
(6, 'test_user', '测试用户', '', 0, 0, 0);
|
||||
INSERT INTO `users` (`id`, `openid`, `nickname`, `avatar_url`, `gender`, `total_play_count`, `total_endings`) VALUES
|
||||
(7, 'test_user', '测试用户', '', 0, 0, 0);
|
||||
INSERT INTO `users` (`id`, `openid`, `nickname`, `avatar_url`, `gender`, `total_play_count`, `total_endings`) VALUES
|
||||
(8, 'test_user', '测试用户', '', 0, 0, 0);
|
||||
INSERT INTO `users` (`id`, `openid`, `nickname`, `avatar_url`, `gender`, `total_play_count`, `total_endings`) VALUES
|
||||
(9, 'test_user', '测试用户', '', 0, 0, 0);
|
||||
INSERT INTO `users` (`id`, `openid`, `nickname`, `avatar_url`, `gender`, `total_play_count`, `total_endings`) VALUES
|
||||
(10, 'test_user', '测试用户', '', 0, 0, 0);
|
||||
INSERT INTO `users` (`id`, `openid`, `nickname`, `avatar_url`, `gender`, `total_play_count`, `total_endings`) VALUES
|
||||
(11, 'test_user', '测试用户', '', 0, 0, 0);
|
||||
INSERT INTO `users` (`id`, `openid`, `nickname`, `avatar_url`, `gender`, `total_play_count`, `total_endings`) VALUES
|
||||
(12, 'test_user', '测试用户', '', 0, 0, 0);
|
||||
INSERT INTO `users` (`id`, `openid`, `nickname`, `avatar_url`, `gender`, `total_play_count`, `total_endings`) VALUES
|
||||
(13, 'test_user', '测试用户', '', 0, 0, 0);
|
||||
INSERT INTO `users` (`id`, `openid`, `nickname`, `avatar_url`, `gender`, `total_play_count`, `total_endings`) VALUES
|
||||
(14, 'test_user', '测试用户', '', 0, 0, 0);
|
||||
INSERT INTO `users` (`id`, `openid`, `nickname`, `avatar_url`, `gender`, `total_play_count`, `total_endings`) VALUES
|
||||
(15, 'test_user', '测试用户', '', 0, 0, 0);
|
||||
INSERT INTO `users` (`id`, `openid`, `nickname`, `avatar_url`, `gender`, `total_play_count`, `total_endings`) VALUES
|
||||
(16, 'test_user', '测试用户', '', 0, 0, 0);
|
||||
INSERT INTO `users` (`id`, `openid`, `nickname`, `avatar_url`, `gender`, `total_play_count`, `total_endings`) VALUES
|
||||
(17, 'test_user', '测试用户', '', 0, 0, 0);
|
||||
INSERT INTO `users` (`id`, `openid`, `nickname`, `avatar_url`, `gender`, `total_play_count`, `total_endings`) VALUES
|
||||
(18, 'test_user', '测试用户', '', 0, 0, 0);
|
||||
INSERT INTO `users` (`id`, `openid`, `nickname`, `avatar_url`, `gender`, `total_play_count`, `total_endings`) VALUES
|
||||
(19, 'test_user', '测试用户', '', 0, 0, 0);
|
||||
|
||||
-- ============================================
|
||||
-- 1. 都市言情:《总裁的替身新娘》
|
||||
|
||||
Reference in New Issue
Block a user