This commit is contained in:
chashaobao
2025-10-15 20:44:20 +08:00
parent 7ba04b27ff
commit 3d2b121b92
23 changed files with 724 additions and 65 deletions

View File

@ -1,5 +1,7 @@
import Taro from '@tarojs/taro';
import { API } from '@/http/api';
export const isDev = () => process.env.NODE_ENV === 'development';
// export const isDev = () => true;
@ -13,7 +15,6 @@ export const isDesktop = (() => {
return info.platform === 'windows' || info.platform === 'mac';
})();
export const logWithPrefix = isDev()
? (prefix: string) =>
(...args: BL.Anything[]) =>
@ -87,3 +88,9 @@ export const isValidIdCard = (idCard: string) =>
export const isValidPhone = (phone: string) => /^1[3-9]\d{9}$/.test(phone);
export const getScrollItemId = (id?: string) => (id ? `sid-${id}` : id);
export function buildUrl(url: API, params: Record<string, string | number>): API {
return Object.entries(params).reduce((result, [key, value]) => {
return result.replace(new RegExp(`\\{${key}\\}`, 'g'), String(value));
}, url) as API;
}

View File

@ -6,9 +6,9 @@ import { CITY_CODE_TO_NAME_MAP, COUNTY_CODE_TO_NAME_MAP, PROVINCE_CODE_TO_NAME_M
import http from '@/http';
import { API } from '@/http/api';
import store from '@/store';
import { setLocationInfo } from '@/store/actions';
import { setLocationInfo, setServiceUrls } from '@/store/actions';
import { selectLocation } from '@/store/selector';
import { GetCityCodeRequest, LocationInfo } from '@/types/location';
import { CityOperatorListItem, GetCityCodeRequest, LocationInfo } from '@/types/location';
import { authorize, getWxSetting } from './wx';
@ -134,3 +134,16 @@ export async function requestLocation(force: boolean = false) {
store.dispatch(setLocationInfo(location));
return location;
}
export async function requestServiceUrls() {
const list = await http.post<CityOperatorListItem[]>(API.GET_ALL_CITY_OPERATOR);
store.dispatch(
setServiceUrls(
(list || []).map(it => ({
title: `${it.cityName}`,
cityCode: Number(it.cityCode),
serviceUrl: it.groupLink,
}))
)
);
}

View File

@ -7,16 +7,22 @@ import store from '@/store';
import { setInviteCode } from '@/store/actions/partner';
import { IPaginationRequest } from '@/types/common';
import {
AuthedGroupInfo,
DecryptOpenGidBody,
GetProfitRequest,
GroupAuthCode,
InviteUserInfo,
PartnerInviteCode,
PartnerPagination,
PartnerProfitItem,
PartnerProfitsState,
StaffInfo,
UserProfitListItem,
WithdrawRecord,
WithdrawResponse,
} from '@/types/partner';
import { requestUserInfo } from '@/utils/user';
import { buildUrl } from '@/utils/common';
export const getInviteCodeFromQuery = (query: Record<string, string>): string | undefined => {
if (query) {
@ -82,7 +88,7 @@ export const formatMoney = (cents: number) => {
const yuan = cents / 100;
return yuan.toFixed(2);
};
export function formatTimestamp(timestamp: string): string {
export function formatTimestamp(timestamp: string, dateOnly?: boolean): string {
// 创建 Date 对象
const date = new Date(/^\d+$/.test(timestamp) ? Number(timestamp) : timestamp);
@ -94,7 +100,7 @@ export function formatTimestamp(timestamp: string): string {
const mm = String(date.getMinutes()).padStart(2, '0');
// 拼接成所需的格式
return `${YYYY}.${MM}.${DD} ${HH}:${mm}`;
return dateOnly ? `${YYYY}.${MM}.${DD}` : `${YYYY}.${MM}.${DD} ${HH}:${mm}`;
}
export function formatUserId(input: string): string {
@ -127,3 +133,24 @@ export async function getWithdrawList(data: IPaginationRequest) {
contentType: 'application/x-www-form-urlencoded',
});
}
export async function getLastProfitList() {
const result = await http.get<UserProfitListItem[]>(API.GET_PROFIT_LIST);
return Array.isArray(result) ? result : [];
}
export async function generateGroupAuthCode() {
return await http.get<GroupAuthCode>(API.GENERATE_GROUP_AUTH_CODE);
}
export async function getAuthedGroupList() {
return await http.get<AuthedGroupInfo[]>(API.GET_AUTHED_GROUP_LIST);
}
export async function decryptOpenGid(data: DecryptOpenGidBody) {
return await http.post(API.DECRYPT_OPEN_GID, {
data,
});
}
export async function getStaffInfo(cityCode: string) {
const result = await http.post<StaffInfo[]>(buildUrl(API.GET_STAFF_CODE, { cityCode }));
return Array.isArray(result) && result.length ? result[0] : null;
}