diff --git a/src/apis.js b/src/apis.js index 9f7f8bc..7e8f0ed 100644 --- a/src/apis.js +++ b/src/apis.js @@ -26,8 +26,9 @@ try { } const ADDONS_BASE_URL = BASE_URL.replace(/\/api\/shoot$/, "/api/shoot"); +const API_ROOT_URL = BASE_URL.replace(/\/api\/shoot$/, ""); // 统一处理业务接口请求,包含登录态、业务错误和特定接口空响应兼容。 -function request(method, url, data = {}, baseUrl = BASE_URL) { +function request(method, url, data = {}, baseUrl = BASE_URL, successCodes = [0]) { const token = uni.getStorageSync( `${uni.getAccountInfoSync().miniProgram.envVersion}_token` ); @@ -51,7 +52,7 @@ function request(method, url, data = {}, baseUrl = BASE_URL) { } if (res.data) { const {code, data, message} = res.data; - if (code === 0) resolve(data); + if (successCodes.includes(code)) resolve(data); else if (message) { const error = {code, data, message}; if (message.indexOf("登录身份已失效") !== -1) { @@ -698,3 +699,56 @@ export const getMyTenRingRank = (seasonId) => { if (seasonId !== undefined && seasonId !== null) data.seasonId = seasonId; return request("GET", "/index/myTenRingRank", data); }; + +// 获取当前用户的金币统计,可按门店查询。 +export const getMyGoldAPI = (storeId) => { + const data = {}; + if (storeId !== undefined && storeId !== null) data.storeId = storeId; + return request("GET", "/index/gold/my", data); +}; + +// 分页获取当前用户的金币流水,type:1=获得,2=兑换。 +export const getGoldLogAPI = ({page = 1, pageSize = 20, type, storeId} = {}) => { + const data = {page, pageSize}; + if (type !== undefined && type !== null) data.type = type; + if (storeId !== undefined && storeId !== null) data.storeId = storeId; + return request("GET", "/index/gold/log", data); +}; + +// 前台礼品接口位于站点根路径,并使用 code=200 表示成功。 +export const getGiftListAPI = ({page = 1, pageSize = 20, sort = "coin_desc"} = {}) => { + return request( + "GET", + "/gin/api/v1/gift/list", + {page, page_size: pageSize, sort}, + API_ROOT_URL, + [0, 200] + ); +}; + +export const getGiftDetailAPI = (id) => { + return request( + "GET", + `/gin/api/v1/gift/${id}`, + {}, + API_ROOT_URL, + [0, 200] + ); +}; + +// 根据用户定位分页获取附近门店。 +export const getNearbyStoresAPI = ({ + longitude, + latitude, + radius = 65535, + page = 1, + pageSize = 20, +} = {}) => { + return request("GET", "/store/nearby", { + longitude, + latitude, + radius, + page, + pageSize, + }); +}; diff --git a/src/components/Container.vue b/src/components/Container.vue index 9df69a2..cf3c3dc 100644 --- a/src/components/Container.vue +++ b/src/components/Container.vue @@ -9,6 +9,7 @@ import DeviceChargingDialog from "@/components/DeviceChargingDialog.vue"; import {laserAimAPI, getBattleAPI, matchGameAPI} from "@/apis"; import { capsuleHeight, debounce } from "@/util"; import { returnToBattle } from "@/utils/matchReturn"; +const emit = defineEmits(["scrolltolower"]); const props = defineProps({ title: { type: String, @@ -131,8 +132,9 @@ const goCalibration = async () => {