forked from gxwebsoft/mp-10550
refactor(api): 更新 API调用以使用 request-legacy- 将多个 API 文件中的 request 引用更新为 request-legacy
- 修改了部分 API调用的错误处理方式 - 更新了部分函数参数名称
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
export const ENV_CONFIG = {
|
||||
// 开发环境
|
||||
development: {
|
||||
API_BASE_URL: 'https://cms-api.websoft.top/api',
|
||||
API_BASE_URL: 'http://127.0.0.1:9200/api',
|
||||
APP_NAME: '开发环境',
|
||||
DEBUG: 'true',
|
||||
},
|
||||
|
||||
@@ -314,7 +314,7 @@ const AddShopArticle = () => {
|
||||
</CellGroup>
|
||||
|
||||
{/* 提交按钮 */}
|
||||
<FixedButton text={isEditMode ? '更新文章' : '发布文章'} onClick={submitSucceed} icon={<Edit />} />
|
||||
<FixedButton text={isEditMode ? '更新文章' : '发布文章'} onClick={() => submitSucceed} icon={<Edit />} />
|
||||
</Form>
|
||||
</>
|
||||
);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import request from '@/utils/request';
|
||||
import request from '@/utils/request-legacy';
|
||||
import type { ApiResult, PageResult } from '@/api/index';
|
||||
import type { BszxClass, BszxClassParam } from './model';
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import request from '@/utils/request';
|
||||
import request from '@/utils/request-legacy';
|
||||
import type { ApiResult, PageResult } from '@/api/index';
|
||||
import type { BszxEra, BszxEraParam } from './model';
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import request from '@/utils/request';
|
||||
import request from '@/utils/request-legacy';
|
||||
import type { ApiResult, PageResult } from '@/api/index';
|
||||
import type { BszxGrade, BszxGradeParam } from './model';
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import request from '@/utils/request';
|
||||
import type { ApiResult, PageResult } from '@/api/index';
|
||||
import request from '@/utils/request-legacy';
|
||||
import type { ApiResult, PageResult } from '@/api';
|
||||
import type {BszxPay, BszxPayParam} from "@/api/bszx/bszxPay/model";
|
||||
import type {BszxBm,BszxBmParam} from "@/api/bszx/bszxBm/model";
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import request from '@/utils/request';
|
||||
import request from '@/utils/request-legacy';
|
||||
import type { ApiResult, PageResult } from '@/api/index';
|
||||
import type { CmsArticleCategory, CmsArticleCategoryParam } from './model';
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import request from '@/utils/request';
|
||||
import request from '@/utils/request-legacy';
|
||||
import type { ApiResult, PageResult } from '@/api/index';
|
||||
import type { CmsArticleComment, CmsArticleCommentParam } from './model';
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import request from '@/utils/request';
|
||||
import request from '@/utils/request-legacy';
|
||||
import type { ApiResult, PageResult } from '@/api/index';
|
||||
import type { CmsArticleContent, CmsArticleContentParam } from './model';
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import request from '@/utils/request';
|
||||
import request from '@/utils/request-legacy';
|
||||
import type { ApiResult, PageResult } from '@/api/index';
|
||||
import type { CmsArticleCount, CmsArticleCountParam } from './model';
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import request from '@/utils/request';
|
||||
import request from '@/utils/request-legacy';
|
||||
import type { ApiResult, PageResult } from '@/api/index';
|
||||
import type { CmsArticleLike, CmsArticleLikeParam } from './model';
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import request from '@/utils/request';
|
||||
import request from '@/utils/request-legacy';
|
||||
import type { ApiResult, PageResult } from '@/api/index';
|
||||
import type { CmsComponents, CmsComponentsParam } from './model';
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import request from '@/utils/request';
|
||||
import request from '@/utils/request-legacy';
|
||||
import type { ApiResult, PageResult } from '@/api/index';
|
||||
import type { CmsDesign, CmsDesignParam } from './model';
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import request from '@/utils/request';
|
||||
import request from '@/utils/request-legacy';
|
||||
import type { ApiResult, PageResult } from '@/api/index';
|
||||
import type { CmsDesignRecord, CmsDesignRecordParam } from './model';
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import request from '@/utils/request';
|
||||
import request from '@/utils/request-legacy';
|
||||
import type { ApiResult, PageResult } from '@/api/index';
|
||||
import type { CmsDocs, CmsDocsParam } from './model';
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import request from '@/utils/request';
|
||||
import request from '@/utils/request-legacy';
|
||||
import type { ApiResult, PageResult } from '@/api/index';
|
||||
import type { CmsDocsContent, CmsDocsContentParam } from './model';
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import request from '@/utils/request';
|
||||
import request from '@/utils/request-legacy';
|
||||
import type { ApiResult, PageResult } from '@/api/index';
|
||||
import type { CmsDomain, CmsDomainParam } from './model';
|
||||
import {SERVER_API_URL} from "@/utils/server";
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import request from '@/utils/request';
|
||||
import request from '@/utils/request-legacy';
|
||||
import type { ApiResult, PageResult } from '@/api/index';
|
||||
import type { CmsForm, CmsFormParam } from './model';
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import request from '@/utils/request';
|
||||
import request from '@/utils/request-legacy';
|
||||
import type { ApiResult, PageResult } from '@/api/index';
|
||||
import type { CmsFormRecord, CmsFormRecordParam } from './model';
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import request from '@/utils/request';
|
||||
import request from '@/utils/request-legacy';
|
||||
import type { ApiResult, PageResult } from '@/api/index';
|
||||
import type { CmsLang, CmsLangParam } from './model';
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import request from '@/utils/request';
|
||||
import request from '@/utils/request-legacy';
|
||||
import type { ApiResult, PageResult } from '@/api/index';
|
||||
import type { CmsLangLog, CmsLangLogParam } from './model';
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import request from '@/utils/request';
|
||||
import request from '@/utils/request-legacy';
|
||||
import type { ApiResult, PageResult } from '@/api/index';
|
||||
import type { CmsLink, CmsLinkParam } from './model';
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import request from '@/utils/request';
|
||||
import request from '@/utils/request-legacy';
|
||||
import type { ApiResult, PageResult } from '@/api/index';
|
||||
import type { CmsMp, CmsMpParam } from './model';
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import request from '@/utils/request';
|
||||
import request from '@/utils/request-legacy';
|
||||
import type { ApiResult, PageResult } from '@/api/index';
|
||||
import type { CmsMpField, CmsMpFieldParam } from './model';
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import request from '@/utils/request';
|
||||
import request from '@/utils/request-legacy';
|
||||
import type { ApiResult, PageResult } from '@/api/index';
|
||||
import type { CmsMpMenu, CmsMpMenuParam } from './model';
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import request from '@/utils/request';
|
||||
import request from '@/utils/request-legacy';
|
||||
import type { ApiResult, PageResult } from '@/api/index';
|
||||
import type { CmsMpPages, CmsMpPagesParam } from './model';
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import request from '@/utils/request';
|
||||
import request from '@/utils/request-legacy';
|
||||
import type { ApiResult, PageResult } from '@/api/index';
|
||||
import type { CmsWebsite, CmsWebsiteParam } from './model';
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import request from '@/utils/request';
|
||||
import request from '@/utils/request-legacy';
|
||||
import type { ApiResult, PageResult } from '@/api/index';
|
||||
import type {CmsWebsiteField, CmsWebsiteFieldParam, Config} from './model';
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import request from '@/utils/request';
|
||||
import request from '@/utils/request-legacy';
|
||||
import type { ApiResult, PageResult } from '@/api/index';
|
||||
import type { Link, LinkParam } from './model';
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import request from '@/utils/request';
|
||||
import request from '@/utils/request-legacy';
|
||||
import type { ApiResult, PageResult } from '@/api/index';
|
||||
import type { MpOfficialMenu, MpOfficialMenuParam } from './model';
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import request from '@/utils/request';
|
||||
import request from '@/utils/request-legacy';
|
||||
import type { ApiResult, PageResult } from '@/api/index';
|
||||
import type { ShopCommissionRole, ShopCommissionRoleParam } from './model';
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import request from '@/utils/request';
|
||||
import request from '@/utils/request-legacy';
|
||||
import type { ApiResult, PageResult } from '@/api/index';
|
||||
import type { ShopCoupon, ShopCouponParam } from './model';
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import request from '@/utils/request-legacy';
|
||||
import type { ApiResult, PageResult } from '@/api/index';
|
||||
import request from '@/utils/request';
|
||||
import type { ApiResult, PageResult } from '@/api';
|
||||
import type { ShopDealerApply, ShopDealerApplyParam } from './model';
|
||||
|
||||
/**
|
||||
@@ -34,28 +34,82 @@ export async function listShopDealerApply(params?: ShopDealerApplyParam) {
|
||||
* 添加分销商申请记录表
|
||||
*/
|
||||
export async function addShopDealerApply(data: ShopDealerApply) {
|
||||
try {
|
||||
const res = await request.post<ApiResult<unknown>>(
|
||||
'/shop/shop-dealer-apply',
|
||||
data
|
||||
);
|
||||
if (res.code === 0) {
|
||||
return res.message;
|
||||
return res.message || '提交成功';
|
||||
}
|
||||
// 直接抛出包含服务器错误信息的错误
|
||||
const error = new Error(res.message || '提交失败');
|
||||
(error as any).code = res.code;
|
||||
(error as any).data = res.data;
|
||||
throw error;
|
||||
} catch (error: any) {
|
||||
// 如果已经是我们处理过的错误,直接抛出
|
||||
if (error.message && error.code !== undefined) {
|
||||
throw error;
|
||||
}
|
||||
|
||||
// 处理网络错误或其他异常
|
||||
console.error('添加分销商申请失败:', error);
|
||||
|
||||
// 尝试从响应中提取错误信息
|
||||
if (error.response?.data) {
|
||||
const responseData = error.response.data;
|
||||
if (responseData.message) {
|
||||
const newError = new Error(responseData.message);
|
||||
(newError as any).code = responseData.code;
|
||||
throw newError;
|
||||
}
|
||||
}
|
||||
|
||||
// 默认错误处理
|
||||
throw new Error(error.message || '网络错误,请重试');
|
||||
}
|
||||
return Promise.reject(new Error(res.message));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改分销商申请记录表
|
||||
*/
|
||||
export async function updateShopDealerApply(data: ShopDealerApply) {
|
||||
try {
|
||||
const res = await request.put<ApiResult<unknown>>(
|
||||
'/shop/shop-dealer-apply',
|
||||
data
|
||||
);
|
||||
if (res.code === 0) {
|
||||
return res.message;
|
||||
return res.message || '修改成功';
|
||||
}
|
||||
// 直接抛出包含服务器错误信息的错误
|
||||
const error = new Error(res.message || '修改失败');
|
||||
(error as any).code = res.code;
|
||||
(error as any).data = res.data;
|
||||
throw error;
|
||||
} catch (error: any) {
|
||||
// 如果已经是我们处理过的错误,直接抛出
|
||||
if (error.message && error.code !== undefined) {
|
||||
throw error;
|
||||
}
|
||||
|
||||
// 处理网络错误或其他异常
|
||||
console.error('修改分销商申请失败:', error);
|
||||
|
||||
// 尝试从响应中提取错误信息
|
||||
if (error.response?.data) {
|
||||
const responseData = error.response.data;
|
||||
if (responseData.message) {
|
||||
const newError = new Error(responseData.message);
|
||||
(newError as any).code = responseData.code;
|
||||
throw newError;
|
||||
}
|
||||
}
|
||||
|
||||
// 默认错误处理
|
||||
throw new Error(error.message || '网络错误,请重试');
|
||||
}
|
||||
return Promise.reject(new Error(res.message));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import request from '@/utils/request';
|
||||
import request from '@/utils/request-legacy';
|
||||
import type { ApiResult, PageResult } from '@/api/index';
|
||||
import type { ShopDealerCapital, ShopDealerCapitalParam } from './model';
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import request from '@/utils/request';
|
||||
import request from '@/utils/request-legacy';
|
||||
import type { ApiResult, PageResult } from '@/api/index';
|
||||
import type { ShopDealerReferee, ShopDealerRefereeParam } from './model';
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import request from '@/utils/request';
|
||||
import request from '@/utils/request-legacy';
|
||||
import type { ApiResult, PageResult } from '@/api/index';
|
||||
import type { ShopDealerSetting, ShopDealerSettingParam } from './model';
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import request from '@/utils/request';
|
||||
import request from '@/utils/request-legacy';
|
||||
import type { ApiResult, PageResult } from '@/api/index';
|
||||
import type { ShopDealerUser, ShopDealerUserParam } from './model';
|
||||
|
||||
@@ -88,11 +88,11 @@ export async function removeBatchShopDealerUser(data: (number | undefined)[]) {
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据id查询分销商用户记录表
|
||||
* 根据userId查询分销商用户记录表
|
||||
*/
|
||||
export async function getShopDealerUser(id: number) {
|
||||
export async function getShopDealerUser(userId: number) {
|
||||
const res = await request.get<ApiResult<ShopDealerUser>>(
|
||||
'/shop/shop-dealer-user/' + id
|
||||
'/shop/shop-dealer-user/' + userId
|
||||
);
|
||||
if (res.code === 0 && res.data) {
|
||||
return res.data;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import request from '@/utils/request';
|
||||
import request from '@/utils/request-legacy';
|
||||
import type { ApiResult, PageResult } from '@/api/index';
|
||||
import type { ShopDealerWithdraw, ShopDealerWithdrawParam } from './model';
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import request from '@/utils/request';
|
||||
import request from '@/utils/request-legacy';
|
||||
import type { ApiResult, PageResult } from '@/api/index';
|
||||
import type { ShopExpress, ShopExpressParam } from './model';
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import request from '@/utils/request';
|
||||
import request from '@/utils/request-legacy';
|
||||
import type { ApiResult, PageResult } from '@/api/index';
|
||||
import type { ShopExpressTemplate, ShopExpressTemplateParam } from './model';
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import request from '@/utils/request';
|
||||
import request from '@/utils/request-legacy';
|
||||
import type { ApiResult, PageResult } from '@/api/index';
|
||||
import type { ShopExpressTemplateDetail, ShopExpressTemplateDetailParam } from './model';
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import request from '@/utils/request';
|
||||
import request from '@/utils/request-legacy';
|
||||
import type { ApiResult, PageResult } from '@/api/index';
|
||||
import { ShopGoodsRoleCommission, ShopGoodsRoleCommissionParam } from '@/api/shop/shopGoodsRoleCommission/model';
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import request from '@/utils/request';
|
||||
import request from '@/utils/request-legacy';
|
||||
import type { ApiResult, PageResult } from '@/api/index';
|
||||
import type { ShopMerchantAccount, ShopMerchantAccountParam } from './model';
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import request from '@/utils/request';
|
||||
import request from '@/utils/request-legacy';
|
||||
import type { ApiResult, PageResult } from '@/api/index';
|
||||
import type { ShopMerchantApply, ShopMerchantApplyParam } from './model';
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import request from '@/utils/request';
|
||||
import request from '@/utils/request-legacy';
|
||||
import type { ApiResult, PageResult } from '@/api/index';
|
||||
import type { ShopMerchantCount, ShopMerchantCountParam } from './model';
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import request from '@/utils/request';
|
||||
import request from '@/utils/request-legacy';
|
||||
import type { ApiResult, PageResult } from '@/api/index';
|
||||
import type { ShopMerchantType, ShopMerchantTypeParam } from './model';
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import request from '@/utils/request';
|
||||
import request from '@/utils/request-legacy';
|
||||
import type { ApiResult, PageResult } from '@/api/index';
|
||||
import type { ShopOrderGoods, ShopOrderGoodsParam } from './model';
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import request from '@/utils/request';
|
||||
import request from '@/utils/request-legacy';
|
||||
import type { ApiResult } from '@/api/index';
|
||||
import type { AccessKey, AccessKeyParam } from './model';
|
||||
import { PageResult } from '@/api/index';
|
||||
|
||||
2
src/api/system/cache/index.ts
vendored
2
src/api/system/cache/index.ts
vendored
@@ -1,4 +1,4 @@
|
||||
import request from '@/utils/request';
|
||||
import request from '@/utils/request-legacy';
|
||||
import type { ApiResult } from '@/api/index';
|
||||
import type { Cache, CacheParam } from './model';
|
||||
import {SERVER_API_URL} from "@/utils/server";
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import request from '@/utils/request';
|
||||
import request from '@/utils/request-legacy';
|
||||
import type { ApiResult, PageResult } from '@/api/index';
|
||||
import type {
|
||||
ChatConversation,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import request from '@/utils/request';
|
||||
import request from '@/utils/request-legacy';
|
||||
import type { ApiResult, PageResult } from '@/api/index';
|
||||
import type { ChatConversation, ChatConversationParam } from './model';
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import request from '@/utils/request';
|
||||
import request from '@/utils/request-legacy';
|
||||
import type { ApiResult, PageResult } from '@/api/index';
|
||||
import type { ChatMessage, ChatMessageParam } from './model';
|
||||
import {SERVER_API_URL} from "@/utils/server";
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import request from '@/utils/request';
|
||||
import request from '@/utils/request-legacy';
|
||||
import type {ApiResult, PageResult} from '@/api';
|
||||
import type {CompanyComment, CompanyCommentParam} from './model';
|
||||
import {SERVER_API_URL} from "@/utils/server";
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import request from '@/utils/request';
|
||||
import request from '@/utils/request-legacy';
|
||||
import type { ApiResult, PageResult } from '@/api/index';
|
||||
import type { CompanyUrl, CompanyUrlParam } from './model';
|
||||
import {SERVER_API_URL} from '@/config/index';
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import request from '@/utils/request';
|
||||
import request from '@/utils/request-legacy';
|
||||
import type { ApiResult, PageResult } from '@/api/index';
|
||||
import type { Order, OrderParam } from './model';
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import request from '@/utils/request';
|
||||
import request from '@/utils/request-legacy';
|
||||
import type { ApiResult, PageResult } from '@/api/index';
|
||||
import type { OrderGoods, OrderGoodsParam } from './model';
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import request from '@/utils/request';
|
||||
import request from '@/utils/request-legacy';
|
||||
import type { ApiResult, PageResult } from '@/api/index';
|
||||
import type { Setting, SettingParam } from './model';
|
||||
import {SERVER_API_URL} from "@/utils/server";
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import request from '@/utils/request';
|
||||
import request from '@/utils/request-legacy';
|
||||
import type { ApiResult, PageResult } from '@/api/index';
|
||||
import type { UserCollection, UserCollectionParam } from './model';
|
||||
import {SERVER_API_URL} from "@/utils/server";
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import request from '@/utils/request';
|
||||
import request from '@/utils/request-legacy';
|
||||
import type { ApiResult } from '@/api/index';
|
||||
import type { UserRole, UserRoleParam } from './model';
|
||||
import {SERVER_API_URL} from "@/utils/server";
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import request from '@/utils/request';
|
||||
import request from '@/utils/request-legacy';
|
||||
import type { ApiResult, PageResult } from '@/api/index';
|
||||
import type { Version, VersionParam } from './model';
|
||||
import type { Menu } from '../menu/model';
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import request from '@/utils/request';
|
||||
import request from '@/utils/request-legacy';
|
||||
import type { ApiResult, PageResult } from '@/api/index';
|
||||
import type { UserBalanceLog, UserBalanceLogParam } from './model';
|
||||
import {SERVER_API_URL} from "@/utils/server";
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import request from '@/utils/request';
|
||||
import request from '@/utils/request-legacy';
|
||||
import type { ApiResult, PageResult } from '@/api/index';
|
||||
import type { UserPointsLog, UserPointsLogParam, UserPointsStats } from './model';
|
||||
import {SERVER_API_URL} from "@/utils/server";
|
||||
|
||||
@@ -54,7 +54,8 @@ export default defineAppConfig({
|
||||
"withdraw/index",
|
||||
"orders/index",
|
||||
"team/index",
|
||||
"qrcode/index"
|
||||
"qrcode/index",
|
||||
"info"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
export default definePageConfig({
|
||||
navigationBarTitleText: '注册成为经销商',
|
||||
navigationBarTitleText: '注册成为VIP',
|
||||
navigationBarTextStyle: 'black'
|
||||
})
|
||||
|
||||
@@ -36,7 +36,7 @@ const AddUserAddress = () => {
|
||||
|
||||
const reload = async () => {
|
||||
// 判断用户是否登录
|
||||
if(!user?.userId){
|
||||
if (!user?.userId) {
|
||||
return false;
|
||||
}
|
||||
// 查询当前用户ID是否已有申请记录
|
||||
@@ -161,10 +161,10 @@ const AddUserAddress = () => {
|
||||
}
|
||||
/>
|
||||
{FormData.applyStatus === 20 && (
|
||||
<Cell title={'审核时间'} extra={FormData.auditTime || '无'} />
|
||||
<Cell title={'审核时间'} extra={FormData.auditTime || '无'}/>
|
||||
)}
|
||||
{FormData.applyStatus === 30 && (
|
||||
<Cell title={'驳回原因'} extra={FormData.rejectReason || '无'} />
|
||||
<Cell title={'驳回原因'} extra={FormData.rejectReason || '无'}/>
|
||||
)}
|
||||
</CellGroup>
|
||||
)}
|
||||
@@ -173,7 +173,7 @@ const AddUserAddress = () => {
|
||||
{/* 底部浮动按钮 */}
|
||||
{(!isEditMode || FormData.applyStatus === 10 || FormData.applyStatus === 30) && (
|
||||
<FixedButton
|
||||
icon={<Edit />}
|
||||
icon={<Edit/>}
|
||||
text={isEditMode ? '保存修改' : '提交申请'}
|
||||
disabled={FormData.applyStatus === 10}
|
||||
onClick={handleFixedButtonClick}
|
||||
|
||||
157
src/dealer/info.tsx
Normal file
157
src/dealer/info.tsx
Normal file
@@ -0,0 +1,157 @@
|
||||
import React from 'react'
|
||||
import { View, Text } from '@tarojs/components'
|
||||
import { Button, Cell, CellGroup, Tag } from '@nutui/nutui-react-taro'
|
||||
import { useDealerUser } from '@/hooks/useDealerUser'
|
||||
import Taro from '@tarojs/taro'
|
||||
|
||||
const DealerInfo: React.FC = () => {
|
||||
const {
|
||||
dealerUser,
|
||||
loading,
|
||||
error,
|
||||
refresh,
|
||||
} = useDealerUser()
|
||||
|
||||
// 跳转到申请页面
|
||||
const navigateToApply = () => {
|
||||
Taro.navigateTo({
|
||||
url: '/pages/dealer/apply/add'
|
||||
})
|
||||
}
|
||||
|
||||
if (error) {
|
||||
return (
|
||||
<View className="p-4">
|
||||
<View className="bg-red-50 border border-red-200 rounded-lg p-4 mb-4">
|
||||
<Text className="text-red-600">{error}</Text>
|
||||
</View>
|
||||
<Button type="primary" onClick={refresh}>
|
||||
重试
|
||||
</Button>
|
||||
</View>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<View className="bg-gray-50 min-h-screen">
|
||||
{/* 页面标题 */}
|
||||
<View className="bg-white px-4 py-3 border-b border-gray-100">
|
||||
<Text className="text-lg font-bold text-center">
|
||||
经销商信息
|
||||
</Text>
|
||||
</View>
|
||||
|
||||
{!dealerUser ? (
|
||||
// 非经销商状态
|
||||
<View className="bg-white mx-4 mt-4 rounded-lg p-6">
|
||||
<View className="text-center py-8">
|
||||
<Text className="text-gray-500 mb-4">您还不是经销商</Text>
|
||||
<Text className="text-sm text-gray-400 mb-6">
|
||||
成为经销商后可享受专属价格和佣金收益
|
||||
</Text>
|
||||
<Button
|
||||
type="primary"
|
||||
size="large"
|
||||
onClick={navigateToApply}
|
||||
>
|
||||
申请成为经销商
|
||||
</Button>
|
||||
</View>
|
||||
</View>
|
||||
) : (
|
||||
// 经销商信息展示
|
||||
<View>
|
||||
{/* 状态卡片 */}
|
||||
<View className="bg-white mx-4 mt-4 rounded-lg p-4">
|
||||
<View className="flex items-center justify-between mb-4">
|
||||
<Text className="text-lg font-semibold">经销商状态</Text>
|
||||
<Tag>
|
||||
{dealerUser.realName}
|
||||
</Tag>
|
||||
</View>
|
||||
|
||||
{/* 基本信息 */}
|
||||
<CellGroup>
|
||||
<Cell
|
||||
title="经销商ID"
|
||||
extra={dealerUser.userId || '-'}
|
||||
/>
|
||||
<Cell
|
||||
title="refereeId"
|
||||
extra={dealerUser.refereeId || '-'}
|
||||
/>
|
||||
<Cell
|
||||
title="成为经销商时间"
|
||||
extra={
|
||||
dealerUser.money
|
||||
}
|
||||
/>
|
||||
|
||||
</CellGroup>
|
||||
|
||||
{/* 操作按钮 */}
|
||||
<View className="mt-6 space-y-3">
|
||||
<Button
|
||||
type="primary"
|
||||
size="large"
|
||||
loading={loading}
|
||||
>
|
||||
检查状态
|
||||
</Button>
|
||||
</View>
|
||||
</View>
|
||||
|
||||
{/* 经销商权益 */}
|
||||
<View className="bg-white mx-4 mt-4 rounded-lg p-4">
|
||||
<Text className="font-semibold mb-3">经销商权益</Text>
|
||||
<View className="space-y-2">
|
||||
<Text className="text-sm text-gray-600">
|
||||
• 享受经销商专属价格
|
||||
</Text>
|
||||
<Text className="text-sm text-gray-600">
|
||||
• 获得推广佣金收益
|
||||
</Text>
|
||||
<Text className="text-sm text-gray-600">
|
||||
• 优先获得新品信息
|
||||
</Text>
|
||||
<Text className="text-sm text-gray-600">
|
||||
• 专属客服支持
|
||||
</Text>
|
||||
</View>
|
||||
</View>
|
||||
|
||||
{/* 佣金统计 */}
|
||||
<View className="bg-white mx-4 mt-4 rounded-lg p-4">
|
||||
<Text className="font-semibold mb-3">佣金统计</Text>
|
||||
<View className="grid grid-cols-3 gap-4">
|
||||
<View className="text-center">
|
||||
<Text className="text-lg font-bold text-blue-600">0</Text>
|
||||
<Text className="text-sm text-gray-500">今日佣金</Text>
|
||||
</View>
|
||||
<View className="text-center">
|
||||
<Text className="text-lg font-bold text-green-600">0</Text>
|
||||
<Text className="text-sm text-gray-500">本月佣金</Text>
|
||||
</View>
|
||||
<View className="text-center">
|
||||
<Text className="text-lg font-bold text-orange-600">0</Text>
|
||||
<Text className="text-sm text-gray-500">累计佣金</Text>
|
||||
</View>
|
||||
</View>
|
||||
</View>
|
||||
</View>
|
||||
)}
|
||||
|
||||
{/* 刷新按钮 */}
|
||||
<View className="text-center py-4">
|
||||
<Text
|
||||
className="text-blue-500 text-sm"
|
||||
onClick={refresh}
|
||||
>
|
||||
点击刷新数据
|
||||
</Text>
|
||||
</View>
|
||||
</View>
|
||||
)
|
||||
}
|
||||
|
||||
export default DealerInfo
|
||||
81
src/hooks/useDealerApply.ts
Normal file
81
src/hooks/useDealerApply.ts
Normal file
@@ -0,0 +1,81 @@
|
||||
import {useState, useEffect, useCallback} from 'react'
|
||||
import Taro from '@tarojs/taro'
|
||||
import {getShopDealerApply} from '@/api/shop/shopDealerApply'
|
||||
import type {ShopDealerApply} from '@/api/shop/shopDealerApply/model'
|
||||
|
||||
// Hook 返回值接口
|
||||
export interface UseDealerApplyReturn {
|
||||
// 经销商用户信息
|
||||
dealerApply: ShopDealerApply | null
|
||||
// 加载状态
|
||||
loading: boolean
|
||||
// 错误信息
|
||||
error: string | null
|
||||
// 刷新数据
|
||||
refresh: () => Promise<void>
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 经销商用户 Hook - 简化版本
|
||||
* 只查询经销商用户信息和判断是否存在
|
||||
*/
|
||||
export const useDealerApply = (): UseDealerApplyReturn => {
|
||||
const [dealerApply, setDealerApply] = useState<ShopDealerApply | null>(null)
|
||||
const [loading, setLoading] = useState(false)
|
||||
const [error, setError] = useState<string | null>(null)
|
||||
|
||||
const userId = Taro.getStorageSync('UserId');
|
||||
|
||||
// 获取经销商用户数据
|
||||
const fetchDealerData = useCallback(async () => {
|
||||
|
||||
if (!userId) {
|
||||
console.log('🔍 用户未登录,提前返回')
|
||||
setDealerApply(null)
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
setLoading(true)
|
||||
setError(null)
|
||||
|
||||
// 查询当前用户的经销商信息
|
||||
const dealer = await getShopDealerApply(userId)
|
||||
|
||||
if (dealer) {
|
||||
setDealerApply(dealer)
|
||||
} else {
|
||||
setDealerApply(null)
|
||||
}
|
||||
} catch (err) {
|
||||
const errorMessage = err instanceof Error ? err.message : '获取经销商信息失败'
|
||||
setError(errorMessage)
|
||||
setDealerApply(null)
|
||||
} finally {
|
||||
setLoading(false)
|
||||
}
|
||||
}, [userId])
|
||||
|
||||
// 刷新数据
|
||||
const refresh = useCallback(async () => {
|
||||
await fetchDealerData()
|
||||
}, [fetchDealerData])
|
||||
|
||||
// 初始化加载数据
|
||||
useEffect(() => {
|
||||
if (userId) {
|
||||
console.log('🔍 调用 fetchDealerData')
|
||||
fetchDealerData()
|
||||
} else {
|
||||
console.log('🔍 用户ID不存在,不调用 fetchDealerData')
|
||||
}
|
||||
}, [fetchDealerData, userId])
|
||||
|
||||
return {
|
||||
dealerApply,
|
||||
loading,
|
||||
error,
|
||||
refresh
|
||||
}
|
||||
}
|
||||
81
src/hooks/useDealerUser.ts
Normal file
81
src/hooks/useDealerUser.ts
Normal file
@@ -0,0 +1,81 @@
|
||||
import {useState, useEffect, useCallback} from 'react'
|
||||
import Taro from '@tarojs/taro'
|
||||
import {getShopDealerUser} from '@/api/shop/shopDealerUser'
|
||||
import type {ShopDealerUser} from '@/api/shop/shopDealerUser/model'
|
||||
|
||||
// Hook 返回值接口
|
||||
export interface UseDealerUserReturn {
|
||||
// 经销商用户信息
|
||||
dealerUser: ShopDealerUser | null
|
||||
// 加载状态
|
||||
loading: boolean
|
||||
// 错误信息
|
||||
error: string | null
|
||||
// 刷新数据
|
||||
refresh: () => Promise<void>
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 经销商用户 Hook - 简化版本
|
||||
* 只查询经销商用户信息和判断是否存在
|
||||
*/
|
||||
export const useDealerUser = (): UseDealerUserReturn => {
|
||||
const [dealerUser, setDealerUser] = useState<ShopDealerUser | null>(null)
|
||||
const [loading, setLoading] = useState(false)
|
||||
const [error, setError] = useState<string | null>(null)
|
||||
|
||||
const userId = Taro.getStorageSync('UserId');
|
||||
|
||||
// 获取经销商用户数据
|
||||
const fetchDealerData = useCallback(async () => {
|
||||
|
||||
if (!userId) {
|
||||
console.log('🔍 用户未登录,提前返回')
|
||||
setDealerUser(null)
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
setLoading(true)
|
||||
setError(null)
|
||||
|
||||
// 查询当前用户的经销商信息
|
||||
const dealer = await getShopDealerUser(userId)
|
||||
|
||||
if (dealer) {
|
||||
setDealerUser(dealer)
|
||||
} else {
|
||||
setDealerUser(null)
|
||||
}
|
||||
} catch (err) {
|
||||
const errorMessage = err instanceof Error ? err.message : '获取经销商信息失败'
|
||||
setError(errorMessage)
|
||||
setDealerUser(null)
|
||||
} finally {
|
||||
setLoading(false)
|
||||
}
|
||||
}, [userId])
|
||||
|
||||
// 刷新数据
|
||||
const refresh = useCallback(async () => {
|
||||
await fetchDealerData()
|
||||
}, [fetchDealerData])
|
||||
|
||||
// 初始化加载数据
|
||||
useEffect(() => {
|
||||
if (userId) {
|
||||
console.log('🔍 调用 fetchDealerData')
|
||||
fetchDealerData()
|
||||
} else {
|
||||
console.log('🔍 用户ID不存在,不调用 fetchDealerData')
|
||||
}
|
||||
}, [fetchDealerData, userId])
|
||||
|
||||
return {
|
||||
dealerUser,
|
||||
loading,
|
||||
error,
|
||||
refresh
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,8 @@ import { useState, useEffect, useCallback } from 'react'
|
||||
import {pageShopUserCoupon} from "@/api/shop/shopUserCoupon";
|
||||
import {pageShopGift} from "@/api/shop/shopGift";
|
||||
import {useUser} from "@/hooks/useUser";
|
||||
import Taro from '@tarojs/taro'
|
||||
import {getUserInfo} from "@/api/layout";
|
||||
|
||||
interface UserData {
|
||||
balance: number
|
||||
@@ -22,12 +24,11 @@ interface UseUserDataReturn {
|
||||
loading: boolean
|
||||
error: string | null
|
||||
refresh: () => Promise<void>
|
||||
updateBalance: (newBalance: string) => void
|
||||
updateBalance: (newBalance: number) => void
|
||||
updatePoints: (newPoints: number) => void
|
||||
}
|
||||
|
||||
export const useUserData = (): UseUserDataReturn => {
|
||||
const {user} = useUser()
|
||||
const [data, setData] = useState<UserData | null>(null)
|
||||
const [loading, setLoading] = useState(true)
|
||||
const [error, setError] = useState<string | null>(null)
|
||||
@@ -39,14 +40,15 @@ export const useUserData = (): UseUserDataReturn => {
|
||||
setError(null)
|
||||
|
||||
// 并发请求所有数据
|
||||
const [couponsRes, giftCardsRes] = await Promise.all([
|
||||
pageShopUserCoupon({ page: 1, limit: 1, userId: user?.userId}),
|
||||
pageShopGift({ page: 1, limit: 1, userId: user?.userId, status: 0})
|
||||
const [userDataRes, couponsRes, giftCardsRes] = await Promise.all([
|
||||
getUserInfo(),
|
||||
pageShopUserCoupon({ page: 1, limit: 1, userId: Taro.getStorageSync('UserId'), status: 0}),
|
||||
pageShopGift({ page: 1, limit: 1, userId: Taro.getStorageSync('UserId'), status: 0})
|
||||
])
|
||||
|
||||
const newData: UserData = {
|
||||
balance: user?.balance || 0.00,
|
||||
points: user?.points || 0,
|
||||
balance: userDataRes?.balance || 0.00,
|
||||
points: userDataRes?.points || 0,
|
||||
coupons: couponsRes?.count || 0,
|
||||
giftCards: giftCardsRes?.count || 0,
|
||||
orders: {
|
||||
@@ -71,6 +73,16 @@ export const useUserData = (): UseUserDataReturn => {
|
||||
await fetchUserData()
|
||||
}, [fetchUserData])
|
||||
|
||||
// 更新余额(本地更新,避免频繁请求)
|
||||
const updateBalance = useCallback((newBalance: number) => {
|
||||
setData(prev => prev ? { ...prev, balance: newBalance } : null)
|
||||
}, [])
|
||||
|
||||
// 更新积分
|
||||
const updatePoints = useCallback((newPoints: number) => {
|
||||
setData(prev => prev ? { ...prev, points: newPoints } : null)
|
||||
}, [])
|
||||
|
||||
// 初始化加载
|
||||
useEffect(() => {
|
||||
fetchUserData().then()
|
||||
@@ -80,7 +92,9 @@ export const useUserData = (): UseUserDataReturn => {
|
||||
data,
|
||||
loading,
|
||||
error,
|
||||
refresh: fetchUserData
|
||||
refresh,
|
||||
updateBalance,
|
||||
updatePoints
|
||||
}
|
||||
}
|
||||
|
||||
@@ -104,7 +118,7 @@ export const useUserBasicData = () => {
|
||||
}, [])
|
||||
|
||||
useEffect(() => {
|
||||
fetchBasicData()
|
||||
fetchBasicData().then()
|
||||
}, [fetchBasicData])
|
||||
|
||||
return {
|
||||
|
||||
@@ -1,45 +1,17 @@
|
||||
import {Cell} from '@nutui/nutui-react-taro'
|
||||
import navTo from "@/utils/common";
|
||||
import Taro from '@tarojs/taro'
|
||||
import {View, Text} from '@tarojs/components'
|
||||
import {ArrowRight, Reward, Setting} from '@nutui/icons-react-taro'
|
||||
import {useUser} from '@/hooks/useUser'
|
||||
import {useEffect, useState} from "react";
|
||||
import {pageShopDealerUser} from "@/api/shop/shopDealerUser";
|
||||
import {useEffect} from "react";
|
||||
import {useDealerUser} from "@/hooks/useDealerUser";
|
||||
|
||||
const UserCell = () => {
|
||||
const {isSuperAdmin} = useUser();
|
||||
const [isDealer, setIsDealer] = useState<boolean>(false)
|
||||
|
||||
const reload = async () => {
|
||||
const userId = Taro.getStorageSync('UserId')
|
||||
|
||||
console.log('当前用户ID:', userId)
|
||||
|
||||
const params = {
|
||||
userId: Number(userId),
|
||||
page: 1,
|
||||
limit: 1
|
||||
}
|
||||
|
||||
console.log('查询分销商参数:', params)
|
||||
|
||||
try {
|
||||
const res = await pageShopDealerUser(params)
|
||||
console.log('分销商查询结果:', res)
|
||||
if (res?.count && res?.count > 0) {
|
||||
setIsDealer(true)
|
||||
} else {
|
||||
setIsDealer(false)
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('查询分销商信息失败:', error)
|
||||
setIsDealer(false)
|
||||
}
|
||||
}
|
||||
const {dealerUser} = useDealerUser()
|
||||
|
||||
useEffect(() => {
|
||||
reload().then()
|
||||
|
||||
}, [])
|
||||
|
||||
/**
|
||||
@@ -70,7 +42,7 @@ const UserCell = () => {
|
||||
/**
|
||||
* 分销中心
|
||||
*/
|
||||
if (isDealer) {
|
||||
if (dealerUser) {
|
||||
return (
|
||||
<>
|
||||
<View className={'px-4'}>
|
||||
@@ -82,8 +54,9 @@ const UserCell = () => {
|
||||
title={
|
||||
<View style={{display: 'inline-flex', alignItems: 'center'}} onClick={() => navTo('/dealer/index', true)}>
|
||||
<Reward className={'text-orange-100 '} size={16}/>
|
||||
<Text style={{fontSize: '16px'}} className={'pl-3 text-orange-100 font-medium'}>分销中心</Text>
|
||||
<Text className={'text-white opacity-80 pl-3'}>门店核销</Text>
|
||||
<Text style={{fontSize: '16px'}}
|
||||
className={'pl-3 text-orange-100 font-medium'}>分销中心</Text>
|
||||
{/*<Text className={'text-white opacity-80 pl-3'}>门店核销</Text>*/}
|
||||
</View>
|
||||
}
|
||||
extra={<ArrowRight color="#cccccc" size={18}/>}
|
||||
@@ -94,7 +67,7 @@ const UserCell = () => {
|
||||
}
|
||||
|
||||
/**
|
||||
* 分销中心
|
||||
* 普通用户
|
||||
*/
|
||||
return (
|
||||
<>
|
||||
|
||||
@@ -365,7 +365,7 @@ const AddUserAddress = () => {
|
||||
/>
|
||||
|
||||
{/* 底部浮动按钮 */}
|
||||
<FixedButton text={isEditMode ? '更新地址' : '保存并使用'} onClick={submitSucceed} />
|
||||
<FixedButton text={isEditMode ? '更新地址' : '保存并使用'} onClick={() => submitSucceed} />
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -314,7 +314,7 @@ const AddShopArticle = () => {
|
||||
</CellGroup>
|
||||
|
||||
{/* 提交按钮 */}
|
||||
<FixedButton text={isEditMode ? '更新文章' : '发布文章'} onClick={submitSucceed} icon={<Edit />} />
|
||||
<FixedButton text={isEditMode ? '更新文章' : '发布文章'} onClick={() => submitSucceed} icon={<Edit />} />
|
||||
</Form>
|
||||
</>
|
||||
);
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "es2017",
|
||||
"module": "commonjs",
|
||||
"target": "es2018",
|
||||
"module": "esnext",
|
||||
"lib": ["es2018", "dom", "dom.iterable"],
|
||||
"removeComments": false,
|
||||
"preserveConstEnums": true,
|
||||
"moduleResolution": "node",
|
||||
@@ -9,6 +10,7 @@
|
||||
"strict": true,
|
||||
"noImplicitAny": true,
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"esModuleInterop": true,
|
||||
"outDir": "lib",
|
||||
"noUnusedLocals": true,
|
||||
"noUnusedParameters": true,
|
||||
|
||||
Reference in New Issue
Block a user