- Spring Boot 后端服务 (hss-home-service) - delivery-miniapp 配送小程序 - website 官网 (Nuxt) - docs 架构设计文档 - Docker 容器化部署配置 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
27 lines
804 B
JavaScript
27 lines
804 B
JavaScript
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 };
|