feat: 星域故事汇小游戏初始版本

This commit is contained in:
2026-03-03 16:57:49 +08:00
commit cc0e39cccc
34 changed files with 6556 additions and 0 deletions

55
client/js/utils/http.js Normal file
View File

@@ -0,0 +1,55 @@
/**
* 网络请求工具
*/
// API基础地址开发环境
const BASE_URL = 'http://localhost:3000/api';
/**
* 发送HTTP请求
*/
export function request(options) {
return new Promise((resolve, reject) => {
const timeout = setTimeout(() => {
reject(new Error('请求超时'));
}, 5000);
wx.request({
url: BASE_URL + options.url,
method: options.method || 'GET',
data: options.data || {},
header: {
'Content-Type': 'application/json',
...options.header
},
success(res) {
clearTimeout(timeout);
if (res.data.code === 0) {
resolve(res.data.data);
} else {
reject(new Error(res.data.message || '请求失败'));
}
},
fail(err) {
clearTimeout(timeout);
reject(err);
}
});
});
}
/**
* GET请求
*/
export function get(url, data) {
return request({ url, method: 'GET', data });
}
/**
* POST请求
*/
export function post(url, data) {
return request({ url, method: 'POST', data });
}
export default { request, get, post };