feat: 初始化居家上门服务系统完整项目代码
- Spring Boot 后端服务 (hss-home-service) - delivery-miniapp 配送小程序 - website 官网 (Nuxt) - docs 架构设计文档 - Docker 容器化部署配置 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
26
hss-home-service/delivery-miniapp/common/api.js
Normal file
26
hss-home-service/delivery-miniapp/common/api.js
Normal file
@@ -0,0 +1,26 @@
|
||||
const BASE_URL = 'http://localhost:18080/api/hss';
|
||||
|
||||
function getHeaders() {
|
||||
const token = uni.getStorageSync('token');
|
||||
return {
|
||||
'Authorization': token ? 'Bearer ' + token : '',
|
||||
'X-User-Role': 'STAFF',
|
||||
'Content-Type': 'application/json'
|
||||
};
|
||||
}
|
||||
|
||||
function generateIdempotencyKey() {
|
||||
return 'idem-' + Date.now() + '-' + Math.random().toString(36).substr(2, 9);
|
||||
}
|
||||
|
||||
function apiGet(path, params = {}) {
|
||||
return uni.request({ url: BASE_URL + path, method: 'GET', data: params, header: getHeaders() });
|
||||
}
|
||||
|
||||
function apiPost(path, data = {}) {
|
||||
const headers = getHeaders();
|
||||
headers['Idempotency-Key'] = generateIdempotencyKey();
|
||||
return uni.request({ url: BASE_URL + path, method: 'POST', data, header: headers });
|
||||
}
|
||||
|
||||
module.exports = { BASE_URL, apiGet, apiPost, generateIdempotencyKey };
|
||||
Reference in New Issue
Block a user