forked from gxwebsoft/mp-10550
refactor(invite): 重构邀请二维码生成逻辑
- 优化了 generateMiniProgramCode 函数,直接返回完整的二维码 URL - 移除了未使用的 getInviteStats 函数调用 - 增加了二维码加载失败时的错误处理和重新生成逻辑 -调整了页面布局,隐藏了邀请统计数据部分
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
import request from '@/utils/request';
|
||||
import type { ApiResult, PageResult } from '@/api';
|
||||
import { SERVER_API_URL } from '@/utils/server';
|
||||
|
||||
/**
|
||||
* 小程序码生成参数
|
||||
@@ -96,14 +95,13 @@ export interface InviteRecordParam {
|
||||
* 生成小程序码
|
||||
*/
|
||||
export async function generateMiniProgramCode(data: MiniProgramCodeParam) {
|
||||
const res = await request.get<ApiResult<string>>(
|
||||
'/wx-login/getOrderQRCodeUnlimited/' + data.scene
|
||||
);
|
||||
console.log(res,'res....')
|
||||
if (res.code === 0) {
|
||||
return res.data;
|
||||
try {
|
||||
const url = '/wx-login/getOrderQRCodeUnlimited/' + data.scene;
|
||||
// 由于接口直接返回图片buffer,我们直接构建完整的URL
|
||||
return `${API_BASE_URL}${url}`;
|
||||
} catch (error: any) {
|
||||
throw new Error(error.message || '生成小程序码失败');
|
||||
}
|
||||
return Promise.reject(new Error(res.message));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -126,7 +124,7 @@ export async function generateInviteCode(inviterId: number) {
|
||||
*/
|
||||
export async function createInviteRelation(data: InviteRelationParam) {
|
||||
const res = await request.post<ApiResult<unknown>>(
|
||||
SERVER_API_URL + '/invite/create-relation',
|
||||
'/invite/create-relation',
|
||||
data
|
||||
);
|
||||
if (res.code === 0) {
|
||||
@@ -140,7 +138,7 @@ export async function createInviteRelation(data: InviteRelationParam) {
|
||||
*/
|
||||
export async function processInviteScene(scene: string, userId: number) {
|
||||
const res = await request.post<ApiResult<unknown>>(
|
||||
SERVER_API_URL + '/invite/process-scene',
|
||||
'/invite/process-scene',
|
||||
{ scene, userId }
|
||||
);
|
||||
if (res.code === 0) {
|
||||
@@ -154,7 +152,7 @@ export async function processInviteScene(scene: string, userId: number) {
|
||||
*/
|
||||
export async function getInviteStats(inviterId: number) {
|
||||
const res = await request.get<ApiResult<InviteStats>>(
|
||||
SERVER_API_URL + `/invite/stats/${inviterId}`
|
||||
`/invite/stats/${inviterId}`
|
||||
);
|
||||
if (res.code === 0) {
|
||||
return res.data;
|
||||
@@ -167,7 +165,7 @@ export async function getInviteStats(inviterId: number) {
|
||||
*/
|
||||
export async function pageInviteRecords(params: InviteRecordParam) {
|
||||
const res = await request.get<ApiResult<PageResult<InviteRecord>>>(
|
||||
SERVER_API_URL + '/invite/records/page',
|
||||
'/invite/records/page',
|
||||
params
|
||||
);
|
||||
if (res.code === 0) {
|
||||
@@ -181,7 +179,7 @@ export async function pageInviteRecords(params: InviteRecordParam) {
|
||||
*/
|
||||
export async function getMyInviteRecords(params: InviteRecordParam) {
|
||||
const res = await request.get<ApiResult<PageResult<InviteRecord>>>(
|
||||
SERVER_API_URL + '/invite/my-records',
|
||||
'/invite/my-records',
|
||||
params
|
||||
);
|
||||
if (res.code === 0) {
|
||||
@@ -195,7 +193,7 @@ export async function getMyInviteRecords(params: InviteRecordParam) {
|
||||
*/
|
||||
export async function validateInviteCode(scene: string) {
|
||||
const res = await request.post<ApiResult<{ valid: boolean; inviterId?: number; source?: string }>>(
|
||||
SERVER_API_URL + '/invite/validate-code',
|
||||
'/invite/validate-code',
|
||||
{ scene }
|
||||
);
|
||||
if (res.code === 0) {
|
||||
@@ -209,7 +207,7 @@ export async function validateInviteCode(scene: string) {
|
||||
*/
|
||||
export async function updateInviteStatus(inviteId: number, status: 'registered' | 'activated') {
|
||||
const res = await request.put<ApiResult<unknown>>(
|
||||
SERVER_API_URL + `/invite/update-status/${inviteId}`,
|
||||
`/invite/update-status/${inviteId}`,
|
||||
{ status }
|
||||
);
|
||||
if (res.code === 0) {
|
||||
@@ -229,7 +227,7 @@ export async function getInviteRanking(params?: { limit?: number; period?: 'day'
|
||||
successCount: number;
|
||||
conversionRate: number;
|
||||
}>>>(
|
||||
SERVER_API_URL + '/invite/ranking',
|
||||
'/invite/ranking',
|
||||
params
|
||||
);
|
||||
if (res.code === 0) {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import type { PageParam } from '@/api/index';
|
||||
import {OrderGoods} from "@/api/system/orderGoods/model";
|
||||
|
||||
/**
|
||||
* 订单
|
||||
@@ -144,6 +145,8 @@ export interface ShopOrder {
|
||||
selfTakeCode?: string;
|
||||
// 是否已收到赠品
|
||||
hasTakeGift?: string;
|
||||
// 订单商品项
|
||||
orderGoods?: OrderGoods[];
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user