全局:清理多余的 request2.js

pull/38/head
YunaiV 2024-01-17 19:45:39 +08:00
parent ce389efdae
commit 492d84073d
36 changed files with 133 additions and 974 deletions

View File

@ -102,25 +102,10 @@
</template> </template>
<script setup> <script setup>
import { import { reactive } from 'vue';
computed,
reactive
} from 'vue';
import sheep from '@/sheep'; import sheep from '@/sheep';
import _ from 'lodash'; import { onLoad } from '@dcloudio/uni-app';
import { import BargainApi from '@/sheep/api/promotion/bargain'
onLoad,
onReachBottom
} from '@dcloudio/uni-app';
import {
useDurationTime
} from '@/sheep/hooks/useGoods';
import {
showShareModal
} from '@/sheep/hooks/useModal';
import {
isEmpty
} from 'lodash';
const state = reactive({ const state = reactive({
id: '', id: '',
@ -142,7 +127,7 @@
let { let {
data, data,
code code
} = await sheep.$api.activity.getBargainActivityDetail({ } = await BargainApi.getBargainActivityDetail({
id: state.id id: state.id
}) })
if (code == 0) { if (code == 0) {

View File

@ -82,7 +82,7 @@
import { import {
fen2yuan fen2yuan
} from '@/sheep/hooks/useGoods'; } from '@/sheep/hooks/useGoods';
import BargainApi from '@/sheep/api/activity' import BargainApi from '@/sheep/api/promotion/bargain'
const state = reactive({ const state = reactive({
navH: '', navH: '',
returnShow: true, returnShow: true,

View File

@ -38,7 +38,7 @@
<view class="order-card-footer ss-flex ss-row-right ss-p-x-20"> <view class="order-card-footer ss-flex ss-row-right ss-p-x-20">
<button <button
class="detail-btn ss-reset-button" class="detail-btn ss-reset-button"
@tap="sheep.$router.go('/pages/order/detail', { id: record.id })" @tap="sheep.$router.go('/pages/order/detail', { id: record.orderId })"
> >
订单详情 订单详情
</button> </button>

View File

@ -32,11 +32,12 @@
<script setup> <script setup>
import { reactive, watch } from 'vue'; import { reactive, watch } from 'vue';
import { onLoad } from '@dcloudio/uni-app';
import sheep from '@/sheep'; import sheep from '@/sheep';
import _ from 'lodash'; import _ from 'lodash';
import GoodsItem from './goods.vue'; import GoodsItem from './goods.vue';
import OrderItem from './order.vue'; import OrderItem from './order.vue';
import OrderApi from '@/sheep/api/trade/order';
import SpuHistoryApi from '@/sheep/api/product/history';
const emits = defineEmits(['select', 'close']); const emits = defineEmits(['select', 'close']);
const props = defineProps({ const props = defineProps({
@ -74,11 +75,11 @@
state.loadStatus = 'loading'; state.loadStatus = 'loading';
const res = const res =
props.mode == 'goods' props.mode == 'goods'
? await sheep.$api.user.view.list({ ? await SpuHistoryApi.getBrowseHistoryPage({
page, page,
list_rows, list_rows,
}) })
: await sheep.$api.order.list({ : await OrderApi.getOrderPage({
page, page,
list_rows, list_rows,
}); });

View File

@ -15,7 +15,7 @@
text="暂无优惠券" text="暂无优惠券"
/> />
<!-- 情况一领劵中心 --> <!-- 情况一领劵中心 -->
<template v-if="state.currentTab === '0'"> <template v-if="state.currentTab === 0">
<view v-for="item in state.pagination.list" :key="item.id"> <view v-for="item in state.pagination.list" :key="item.id">
<s-coupon-list <s-coupon-list
:data="item" :data="item"
@ -40,11 +40,7 @@
<s-coupon-list <s-coupon-list
:data="item" :data="item"
type="user" type="user"
@tap=" @tap="sheep.$router.go('/pages/coupon/detail', { couponId: item.id })"
sheep.$router.go('/pages/coupon/detail', {
data: JSON.stringify(item),
})
"
> >
<template #default> <template #default>
<button <button
@ -183,12 +179,12 @@
getData(); getData();
// //
} else { } else {
state.type = Option.type;
Option.type === 'geted' Option.type === 'geted'
? (state.currentTab = 1) ? (state.currentTab = 1)
: Option.type === 'used' : Option.type === 'used'
? (state.currentTab = 2) ? (state.currentTab = 2)
: (state.currentTab = 3); : (state.currentTab = 3);
state.type = state.currentTab;
getCoupon(); getCoupon();
} }
}); });

View File

@ -80,7 +80,7 @@
} }
state.id = options.id; state.id = options.id;
const { code, data } = await sheep.$api.order.detail(state.id); const { code, data } = await OrderApi.getOrder(state.id);
if (code !== 0) { if (code !== 0) {
sheep.$helper.toast('无待评价订单'); sheep.$helper.toast('无待评价订单');
return return

View File

@ -87,13 +87,11 @@
<script setup> <script setup>
import { reactive } from 'vue'; import { reactive } from 'vue';
import { import { onLoad, onReachBottom } from '@dcloudio/uni-app';
onLoad,
onReachBottom
} from '@dcloudio/uni-app';
import sheep from '@/sheep'; import sheep from '@/sheep';
import _ from 'lodash'; import _ from 'lodash';
import { resetPagination } from '@/sheep/util'; import { resetPagination } from '@/sheep/util';
import SpuApi from '@/sheep/api/product/spu';
const sys_navBar = sheep.$platform.navbar; const sys_navBar = sheep.$platform.navbar;
const emits = defineEmits(['close', 'change']); const emits = defineEmits(['close', 'change']);
@ -232,7 +230,7 @@
async function getList() { async function getList() {
state.loadStatus = 'loading'; state.loadStatus = 'loading';
const { code, data } = await sheep.$api.goods.list({ const { code, data } = await SpuApi.getSpuPage({
pageNo: state.pagination.pageNo, pageNo: state.pagination.pageNo,
pageSize: state.pagination.pageSize, pageSize: state.pagination.pageSize,
sortField: state.currentSort, sortField: state.currentSort,

View File

@ -102,7 +102,7 @@
// //
async function getOrderList() { async function getOrderList() {
state.loadStatus = 'loading'; state.loadStatus = 'loading';
let { data, code } = await sheep.$api.order.aftersale.list({ let { data, code } = await AfterSaleApi.getAfterSalePage({
// type: tabMaps[state.currentTab].value, // type: tabMaps[state.currentTab].value,
pageNo: state.pagination.pageNo, pageNo: state.pagination.pageNo,
pageSize: state.pagination.pageSize, pageSize: state.pagination.pageSize,

View File

@ -372,7 +372,8 @@
// //
let res; let res;
if (state.comeinType === 'wechat') { if (state.comeinType === 'wechat') {
res = await sheep.$api.order.detail(id, { // TODO
res = await OrderApi.getOrder(id, {
merchant_trade_no: state.merchantTradeNo, merchant_trade_no: state.merchantTradeNo,
}); });
} else { } else {

View File

@ -1,48 +0,0 @@
import request from '@/sheep/request';
export default {
myGroupon: (params) =>
request({
url: 'activity/groupon/myGroupons',
method: 'GET',
params,
}),
getGrouponList: (params) =>
request({
url: 'activity/groupon',
method: 'GET',
params,
}),
grouponDetail: (id) =>
request({
url: 'activity/groupon/' + id,
method: 'GET',
}),
activity: (id) =>
request({
url: 'activity/activity/' + id,
method: 'GET',
}),
getSummary: () =>
request({
url: '/app-api/member/sign-in/record/get-summary',
method: 'GET',
}),
getBargainRecordSummary: () =>
request({
url: '/app-api/promotion/bargain-record/get-summary',
method: 'GET',
}),
getBargainActivityPage: () =>
request({
url: '/app-api/promotion/bargain-activity/page',
method: 'GET',
}),
getBargainActivityDetail: (params) =>
request({
url: '/app-api/promotion/bargain-activity/get-detail',
method: 'GET',
params
}),
};

View File

@ -1,42 +0,0 @@
import request from '@/sheep/request';
import request2 from '@/sheep/request2';
export default {
list: (data) =>
request2({
url: 'trade/cart/list',
method: 'GET',
custom: {
showLoading: false,
auth: true,
},
}),
append: (data) =>
request({
url: 'cart',
method: 'POST',
custom: {
showSuccess: true,
successMsg: '已添加到购物车~',
},
data: {
...data,
type: 'inc',
},
}),
// 删除购物车
delete: (ids) =>
request2({
url: 'trade/cart/delete?ids=' + ids,
method: 'DELETE',
}),
update: (data) =>
request2({
url: 'trade/cart/update-count',
method: 'PUT',
data: {
...data,
type: 'cover',
},
}),
};

View File

@ -1,10 +0,0 @@
import request2 from '@/sheep/request2';
export default {
list: (params) =>
request2({
url: 'product/category/list',
method: 'GET',
params,
}),
};

View File

@ -1,29 +0,0 @@
import request from '@/sheep/request';
import request2 from '@/sheep/request2';
export default {
// 我的拼团
list: (params) =>
request({
url: 'coupon',
method: 'GET',
params,
custom: {
showLoading: false,
},
}),
detail: (id, user_coupon_id) =>
request({
url: 'coupon/' + id,
method: 'GET',
params: {
user_coupon_id,
},
}),
get: (id) =>
request({
url: 'coupon/get/' + id,
method: 'POST',
}),
};

View File

@ -1,58 +0,0 @@
import request from '@/sheep/request';
import request2 from '@/sheep/request2';
export default {
// 商品详情
detail: (id, params = {}) =>
request2({
url: 'product/spu/get-detail?id=' + id,
method: 'GET',
params,
custom: {
showLoading: false,
showError: false,
},
}),
// 商品列表
list: (params) =>
request2({
url: 'product/spu/page',
method: 'GET',
params,
custom: {
showLoading: false,
showError: false,
},
}),
// 商品查询
ids: (params = {}) =>
request({
url: 'goods/goods/ids',
method: 'GET',
params,
custom: {
showLoading: false,
showError: false,
},
}),
// 商品查询
activity: (params = {}) =>
request({
url: 'goods/goods/activity',
method: 'GET',
params,
custom: {
showLoading: false,
showError: false,
},
}),
activityList: (params = {}) =>
request({
url: 'goods/goods/activityList',
method: 'GET',
params,
}),
};

View File

@ -1,13 +0,0 @@
const files = import.meta.globEager('./*.js');
let api = {};
Object.keys(files).forEach((key) => {
api = {
...api,
[key.replace(/(.*\/)*([^.]+).*/gi, '$2')]: files[key].default,
};
});
// TODO 芋艿:直接在 useModal 引入 AuthUtil 会报错,所以采用这用这方式先
api.AuthUtil = import.meta.globEager('./member/auth.js')['./member/auth.js'].default;
export default api;

View File

@ -1,12 +1,7 @@
import request from '@/sheep/request'; import request from '@/sheep/request';
// TODO 芋艿:小程序直播还不支持
export default { export default {
// 自定义页面
page: (id) =>
request({
url: 'page/' + id,
method: 'GET',
}),
//小程序直播 //小程序直播
mplive: { mplive: {
getRoomList: (ids) => getRoomList: (ids) =>

View File

@ -1,5 +1,6 @@
import request from '@/sheep/request'; import request from '@/sheep/request';
// TODO 芋艿:暂不支持 socket 聊天
export default { export default {
// 获取聊天token // 获取聊天token
unifiedToken: () => unifiedToken: () =>

View File

@ -0,0 +1,10 @@
const files = import.meta.globEager('./*.js');
let api = {};
Object.keys(files).forEach((key) => {
api = {
...api,
[key.replace(/(.*\/)*([^.]+).*/gi, '$2')]: files[key].default,
};
});
export default api;

View File

@ -0,0 +1,44 @@
import request from '@/sheep/request';
import { baseUrl, apiPath } from '@/sheep/config';
export default {
// 微信相关
wechat: {
// 小程序订阅消息
subscribeTemplate: (params) =>
request({
url: 'third/wechat/subscribeTemplate',
method: 'GET',
params: {
platform: 'miniProgram',
},
custom: {
showError: false,
showLoading: false,
},
}),
// 获取微信小程序码
getWxacode: (path) =>
`${baseUrl}${apiPath}third/wechat/wxacode?platform=miniProgram&payload=${encodeURIComponent(
JSON.stringify({
path,
}),
)}`,
},
// 苹果相关
apple: {
// 第三方登录
login: (data) =>
request({
url: 'third/apple/login',
method: 'POST',
data,
custom: {
showSuccess: true,
loadingMsg: '登陆中',
},
}),
},
};

View File

@ -1,186 +0,0 @@
import request from '@/sheep/request';
import request2 from '@/sheep/request2';
export default {
// 订单详情
detail: (id, params) =>
request2({
url: 'trade/order/get-detail?id=' + id,
method: 'GET',
params,
}),
// detail: (id, params) =>
// request({
// url: 'order/order/' + id,
// method: 'GET',
// params,
// }),
// 获取支付结果
payResult: (id) =>
request({
url: 'order/order/' + id,
method: 'GET',
custom: {
showLoading: false,
},
}),
itemDetail: (id, itemId) =>
request({
url: 'order/order/itemDetail/' + id + '/' + itemId,
method: 'GET',
custom: {
showLoading: false,
},
}),
// 订单列表
list: (params) =>
request2({
url: 'trade/order/page',
method: 'GET',
params,
custom: {
showLoading: false,
},
}),
// list: (params) =>
// request({
// url: 'order/order',
// method: 'GET',
// params,
// custom: {
// showLoading: false,
// },
// }),
// 计算订单信息
calc: (data) => {
const data2 = {
...data,
}
// 解决 SpringMVC 接受 List<Item> 参数的问题
delete data2.items
for (let i = 0; i < data.items.length; i++) {
// data2['items[' + i + '' + '].skuId'] = data.items[i].skuId + '';
// data2['items[' + i + '' + '].count'] = data.items[i].count + '';
// data2['items[' + i + '' + '].cartId'] = data.items[i].cartId + '';
data2['items' + `%5B${i}%5D` + '.skuId'] = data.items[i].skuId + '';
data2['items' + `%5B${i}%5D` + '.count'] = data.items[i].count + '';
data2['items' + `%5B${i}%5D` + '.cartId'] = data.items[i].cartId + '';
}
console.log(data2, '对比数据')
return request2({
url: 'trade/order/settlement',
method: 'GET',
// data,
params: data2
})
},
// calc: (data) =>
// request({
// url: 'order/order/calc',
// method: 'POST',
// data,
// }),
// 创建订单
create: (data) =>
request({
url: 'order/order/create',
method: 'POST',
data,
}),
//订单可用优惠券
coupons: (data) =>
request({
url: 'order/order/coupons',
method: 'POST',
data,
}),
// 确认收货
confirm: (id) =>
request({
url: 'order/order/confirm/' + id,
method: 'PUT',
}),
// 评价订单
comment: (data) =>
request2({
url: 'trade/order/item/create-comment',
method: 'POST',
data,
}),
// comment: (id, data) =>
// request({
// url: 'order/order/comment/' + id,
// method: 'POST',
// data,
// }),
// 申请退款
applyRefund: (id) =>
request({
url: 'order/order/applyRefund/' + id,
method: 'PUT',
}),
// 取消订单
cancel: (id) =>
request({
url: 'order/order/cancel/' + id,
method: 'PUT',
}),
// 删除订单
delete: (id) =>
request({
url: 'order/order/' + id,
method: 'DELETE',
}),
// 售后
aftersale: {
// 申请售后
apply: (data) =>
request({
url: 'order/aftersale',
method: 'POST',
data,
}),
list: (params) =>
request2({
url: 'trade/after-sale/page',
method: 'GET',
params,
custom: {
showLoading: false,
},
}),
// list: (params) =>
// request({
// url: 'order/aftersale',
// method: 'GET',
// params,
// custom: {
// showLoading: false,
// },
// }),
//取消售后
cancel: (id) =>
request({
url: 'order/aftersale/cancel/' + id,
method: 'PUT',
}),
//删除售后单
delete: (id) =>
request({
url: 'order/aftersale/' + id,
method: 'DELETE',
}),
// 售后详情
detail: (id) =>
request2({
url: 'trade/after-sale/get?id=' + id,
method: 'GET',
}),
},
//订单包裹
express: (id, orderId) =>
request({
url: 'order/express/' + id + `${orderId ? '/' + orderId : ''}`,
method: 'GET',
}),
};

View File

@ -1,9 +1,9 @@
import request2 from '@/sheep/request2'; import request from '@/sheep/request';
const ActivityApi = { const ActivityApi = {
// 获得单个商品,近期参与的每个活动 // 获得单个商品,近期参与的每个活动
getActivityListBySpuId: (spuId) => { getActivityListBySpuId: (spuId) => {
return request2({ return request({
url: '/app-api/promotion/activity/list-by-spu-id', url: '/app-api/promotion/activity/list-by-spu-id',
method: 'GET', method: 'GET',
params: { params: {

View File

@ -0,0 +1,28 @@
import request from '@/sheep/request';
const BargainApi = {
// 获得砍价记录的概要信息
getBargainRecordSummary: () => {
return request({
url: '/app-api/promotion/bargain-record/get-summary',
method: 'GET',
});
},
// 获得砍价活动分页
getBargainActivityPage: () => {
return request({
url: '/app-api/promotion/bargain-activity/page',
method: 'GET',
});
},
// 获得砍价活动详情
getBargainActivityDetail(params) {
return request({
url: '/app-api/promotion/bargain-activity/get-detail',
method: 'GET',
params,
});
},
};
export default BargainApi;

View File

@ -1,19 +1,19 @@
import request2 from "@/sheep/request2"; import request from "@/sheep/request";
const SeckillApi = { const SeckillApi = {
// 获得秒杀时间段列表 // 获得秒杀时间段列表
getSeckillConfigList: () => { getSeckillConfigList: () => {
return request2({ url: 'promotion/seckill-config/list', method: 'GET' }); return request({ url: 'promotion/seckill-config/list', method: 'GET' });
}, },
// 获得当前秒杀活动 // 获得当前秒杀活动
getNowSeckillActivity: () => { getNowSeckillActivity: () => {
return request2({ url: 'promotion/seckill-activity/get-now', method: 'GET' }); return request({ url: 'promotion/seckill-activity/get-now', method: 'GET' });
}, },
// 获得秒杀活动分页 // 获得秒杀活动分页
getSeckillActivityPage: (params) => { getSeckillActivityPage: (params) => {
return request2({ url: 'promotion/seckill-activity/page', method: 'GET', params }); return request({ url: 'promotion/seckill-activity/page', method: 'GET', params });
}, },
/** /**
@ -22,7 +22,7 @@ const SeckillApi = {
* @return {*} * @return {*}
*/ */
getSeckillActivity: (id) => { getSeckillActivity: (id) => {
return request2({ return request({
url: 'promotion/seckill-activity/get-detail', url: 'promotion/seckill-activity/get-detail',
method: 'GET', method: 'GET',
params: { id } params: { id }

View File

@ -1,103 +0,0 @@
import request from '@/sheep/request';
import { baseUrl, apiPath } from '@/sheep/config';
export default {
// 微信相关
wechat: {
// 第三方登录
login: (data) =>
request({
url: 'third/wechat/login',
method: 'POST',
data,
custom: {
showSuccess: true,
loadingMsg: '登陆中',
},
}),
// 绑定微信
bind: (data) =>
request({
url: 'third/wechat/bind',
method: 'POST',
data,
custom: {
showSuccess: true,
loadingMsg: '绑定中',
},
}),
// 公众号授权
oauthLogin: (data) =>
request({
url: 'third/wechat/oauthLogin',
method: 'GET',
data,
custom: {
showSuccess: true,
loadingMsg: '登陆中',
},
}),
// 获取小程序sessionKey后端不会给前端返回真实的sessionKey
getSessionId: (data) =>
request({
url: 'third/wechat/getSessionId',
method: 'POST',
data,
custom: {
showLoading: false,
},
}),
// 微信小程序 绑定一键获取的手机号
bindUserPhoneNumber: (data) =>
request({
url: 'third/wechat/bindUserPhoneNumber',
method: 'POST',
data,
custom: {
showSuccess: true,
loadingMsg: '获取中',
},
}),
// 小程序订阅消息
subscribeTemplate: (params) =>
request({
url: 'third/wechat/subscribeTemplate',
method: 'GET',
params: {
platform: 'miniProgram',
},
custom: {
showError: false,
showLoading: false,
},
}),
// 获取微信小程序码
getWxacode: (path) =>
`${baseUrl}${apiPath}third/wechat/wxacode?platform=miniProgram&payload=${encodeURIComponent(
JSON.stringify({
path,
}),
)}`,
},
// 苹果相关
apple: {
// 第三方登录
login: (data) =>
request({
url: 'third/apple/login',
method: 'POST',
data,
custom: {
showSuccess: true,
loadingMsg: '登陆中',
},
}),
},
};

View File

@ -1,23 +0,0 @@
import request from '@/sheep/request';
export default {
order: (id) =>
request({
url: 'trade/order/' + id,
method: 'GET',
custom: {
showLoading: false,
},
}),
orderLog: (params) =>
request({
url: 'trade/order',
method: 'GET',
params,
custom: {
showLoading: false,
},
}),
};

View File

@ -1,6 +1,17 @@
import request from '@/sheep/request'; import request from '@/sheep/request';
const AfterSaleApi = { const AfterSaleApi = {
// 获得售后分页
getAfterSalePage: (params) => {
return request({
url: `/app-api/trade/after-sale/page`,
method: 'GET',
params,
custom: {
showLoading: false,
},
});
},
// 创建售后 // 创建售后
createAfterSale: (data) => { createAfterSale: (data) => {
return request({ return request({

View File

@ -1,168 +0,0 @@
import request from '@/sheep/request';
import request2 from '@/sheep/request2';
import $platform from '@/sheep/platform';
export default {
// 添加分享记录
addShareLog: (data) =>
request({
url: 'share/add',
method: 'POST',
data,
custom: {
showError: false,
},
}),
share: {
list: (params) =>
request({
url: 'share/list',
method: 'GET',
params,
}),
},
address: {
default: () =>
request2({
url: 'member/address/get-default',
method: 'GET',
custom: {
showError: false,
},
}),
list: () =>
request2({
url: 'member/address/list',
method: 'GET',
custom: {},
}),
create: (data) =>
request2({
url: 'member/address/create',
method: 'POST',
data,
custom: {
showSuccess: true,
},
}),
update: (data) =>
request2({
url: 'member/address/update',
method: 'PUT',
data,
custom: {
showSuccess: true,
},
}),
detail: (id) =>
request2({
url: 'member/address/get?id=' + id,
method: 'GET',
}),
delete: (id) =>
request2({
url: 'member/address/delete?id=' + id,
method: 'DELETE',
}),
},
favorite: {
list: (params) =>
request2({
url: 'product/favorite/page',
method: 'GET',
params,
}),
do: (id) =>
request({
url: 'user/goodsLog/favorite',
method: 'POST',
data: {
goods_id: id,
},
custom: {
showSuccess: true,
auth: true,
},
}),
// 取消收藏
cancel: (id) =>
request2({
url: 'product/favorite/delete-list',
method: 'DELETE',
data: {
spuIds: id.split(',').map(item => item * 1),
// spuIds: id.split(',').join(','),
},
custom: {
showSuccess: true,
auth: true,
},
}),
// cancel: (id) =>
// request({
// url: 'user/goodsLog/favorite',
// method: 'POST',
// data: {
// goods_ids: id,
// },
// custom: {
// showSuccess: true,
// auth: true,
// },
// }),
},
view: {
list: (params) =>
request({
url: 'user/goodsLog/views',
method: 'GET',
params,
custom: {},
}),
delete: (data) =>
request({
url: 'user/goodsLog/viewDel',
method: 'DELETE',
data,
custom: {
showSuccess: true,
},
}),
},
wallet: {
log: (params) =>
request2({
// url: 'member/point/record/page',
url: 'pay/wallet-transaction/page',
method: 'GET',
params,
custom: {},
}),
},
account: {
info: (params) =>
request({
url: 'user/account',
method: 'GET',
params,
custom: {
showError: false,
auth: true,
},
}),
save: (data) =>
request({
url: 'user/account',
method: 'POST',
data,
custom: {
showSuccess: true,
auth: true,
},
}),
}
};

View File

@ -45,10 +45,10 @@
<script setup> <script setup>
import sheep from '@/sheep'; import sheep from '@/sheep';
import TemplateApi from '@/sheep/api/promotion/coupon'; import CouponApi from '@/sheep/api/promotion/coupon';
import { ref, onMounted } from 'vue'; import { ref, onMounted } from 'vue';
import {CouponTemplateValidityTypeEnum, PromotionDiscountTypeEnum} from "@/sheep/util/const"; import { CouponTemplateValidityTypeEnum, PromotionDiscountTypeEnum } from "@/sheep/util/const";
import {floatToFixed2, formatDate} from "@/sheep/util"; import { floatToFixed2, formatDate } from "@/sheep/util";
const props = defineProps({ const props = defineProps({
data: { data: {
@ -91,6 +91,7 @@
} }
return `未知【${coupon.discountType}` return `未知【${coupon.discountType}`
} }
// //
const formatValidityType = (row) => { const formatValidityType = (row) => {
if (row.validityType === CouponTemplateValidityTypeEnum.DATE.type) { if (row.validityType === CouponTemplateValidityTypeEnum.DATE.type) {
@ -103,9 +104,9 @@
} }
const couponList = ref([]); const couponList = ref([]);
// //
async function onGetCoupon(id) { async function onGetCoupon(id) {
const { error, msg } = await sheep.$api.coupon.get(id); const { error, msg } = await CouponApi.takeCoupon(id);
if (error === 0) { if (error === 0) {
uni.showToast({ uni.showToast({
title: msg, title: msg,
@ -116,7 +117,7 @@
await getCouponTemplateList() await getCouponTemplateList()
} }
const getCouponTemplateList = async () => { const getCouponTemplateList = async () => {
const { data } = await TemplateApi.getCouponTemplateListByIds(props.data.couponIds.join(',')); const { data } = await CouponApi.getCouponTemplateListByIds(props.data.couponIds.join(','));
couponList.value = data; couponList.value = data;
} }
onMounted(() => { onMounted(() => {

View File

@ -3,7 +3,7 @@ import $helper from '@/sheep/helper';
import dayjs from 'dayjs'; import dayjs from 'dayjs';
import { ref } from 'vue'; import { ref } from 'vue';
import test from '@/sheep/helper/test.js'; import test from '@/sheep/helper/test.js';
import $api from '@/sheep/api'; import AuthUtil from '@/sheep/api/member/auth';
// 打开授权弹框 // 打开授权弹框
export function showAuthModal(type = 'smsLogin') { export function showAuthModal(type = 'smsLogin') {
@ -94,7 +94,7 @@ export function getSmsCode(event, mobile) {
scene = 1; scene = 1;
break; break;
} }
$api.AuthUtil.sendSmsCode(mobile, scene).then((res) => { AuthUtil.sendSmsCode(mobile, scene).then((res) => {
if (res.code === 0) { if (res.code === 0) {
modalStore.$patch((state) => { modalStore.$patch((state) => {
state.lastTimer[event] = dayjs().unix(); state.lastTimer[event] = dayjs().unix();

View File

@ -1,4 +1,3 @@
import $api from '@/sheep/api';
import $url from '@/sheep/url'; import $url from '@/sheep/url';
import $router from '@/sheep/router'; import $router from '@/sheep/router';
import $platform from '@/sheep/platform'; import $platform from '@/sheep/platform';
@ -15,7 +14,6 @@ dayjs.extend(relativeTime);
dayjs.extend(duration); dayjs.extend(duration);
const sheep = { const sheep = {
$api,
$store, $store,
$url, $url,
$router, $router,

View File

@ -5,7 +5,6 @@
import jweixin, { ready } from 'weixin-js-sdk'; import jweixin, { ready } from 'weixin-js-sdk';
import $helper from '@/sheep/helper'; import $helper from '@/sheep/helper';
import third from '@/sheep/api/third';
import AuthUtil from '@/sheep/api/member/auth'; import AuthUtil from '@/sheep/api/member/auth';
let configSuccess = false; let configSuccess = false;

View File

@ -1,4 +1,3 @@
import third from '@/sheep/api/third';
import $wxsdk from '@/sheep/libs/sdk-h5-weixin'; import $wxsdk from '@/sheep/libs/sdk-h5-weixin';
import { getRootUrl } from '@/sheep/helper'; import { getRootUrl } from '@/sheep/helper';
import AuthUtil from '@/sheep/api/member/auth'; import AuthUtil from '@/sheep/api/member/auth';

View File

@ -135,6 +135,7 @@ http.interceptors.response.use(
icon: 'none', icon: 'none',
}); });
} }
// TODO 芋艿:全局的 error code 处理;例如说 401
return Promise.resolve(response.data); return Promise.resolve(response.data);
}, },
(error) => { (error) => {

View File

@ -1,226 +0,0 @@
/**
* Shopro-request
* @description api模块管理loading配置请求拦截错误处理
*/
import Request from 'luch-request';
import {
baseUrl,
apiPath
} from '@/sheep/config';
import $store from '@/sheep/store';
import $platform from '@/sheep/platform';
import {
showAuthModal
} from '@/sheep/hooks/useModal';
const options = {
// 显示操作成功消息 默认不显示
showSuccess: false,
// 成功提醒 默认使用后端返回值
successMsg: '',
// 显示失败消息 默认显示
showError: true,
// 失败提醒 默认使用后端返回信息
errorMsg: '',
// 显示请求时loading模态框 默认显示
showLoading: true,
// loading提醒文字
loadingMsg: '加载中',
// 需要授权才能请求 默认放开
auth: false,
// ...
};
// Loading全局实例
let LoadingInstance = {
target: null,
count: 0,
};
/**
* 关闭loading
*/
function closeLoading() {
if (LoadingInstance.count > 0) LoadingInstance.count--;
if (LoadingInstance.count === 0) uni.hideLoading();
}
/**
* @description 请求基础配置 可直接使用访问自定义请求
*/
const http = new Request({
baseURL: 'https://api.shopro.sheepjs.com/',
timeout: 8000,
method: 'GET',
header: {
Accept: 'text/json',
'Content-Type': 'application/json;charset=UTF-8',
platform: $platform.name,
},
// #ifdef APP-PLUS
sslVerify: false,
// #endif
// #ifdef H5
// 跨域请求时是否携带凭证cookies仅H5支持HBuilderX 2.6.15+
withCredentials: false,
// #endif
custom: options,
});
/**
* @description 请求拦截器
*/
http.interceptors.request.use(
(config) => {
// console.log(config);
if (config.custom.auth && !$store('user').isLogin) {
showAuthModal();
return Promise.reject();
}
if (config.custom.showLoading) {
LoadingInstance.count++;
LoadingInstance.count === 1 &&
uni.showLoading({
title: config.custom.loadingMsg,
mask: true,
fail: () => {
uni.hideLoading();
},
});
}
const token = uni.getStorageSync('token');
if (token) config.header['Authorization'] = token;
// TODO 芋艿:特殊处理
if (config.url.indexOf('/app-api/') !== -1) {
config.header['Accept'] = '*/*'
config.header['tenant-id'] = '1';
config.header['terminal'] = '20';
// config.header['Authorization'] = 'Bearer test247';
}
return config;
},
(error) => {
return Promise.reject(error);
},
);
/**
* @description 响应拦截器
*/
http.interceptors.response.use(
(response) => {
// 自动设置登陆令牌
if (response.header.authorization || response.header.Authorization) {
$store('user').setToken(response.header.authorization || response.header.Authorization);
}
response.config.custom.showLoading && closeLoading();
if (response.data.code !== 0) {
if (response.config.custom.showError)
uni.showToast({
title: response.data.msg || '服务器开小差啦,请稍后再试~',
icon: 'none',
mask: true,
});
return Promise.resolve(response.data);
}
if (
response.data.error === 0 &&
response.data.msg !== '' &&
response.config.custom.showSuccess
) {
uni.showToast({
title: response.config.custom.successMsg || response.data.msg,
icon: 'none',
});
}
return Promise.resolve(response.data);
},
(error) => {
const userStore = $store('user');
const isLogin = userStore.isLogin;
let errorMessage = '网络请求出错';
if (error !== undefined) {
switch (error.statusCode) {
case 400:
errorMessage = '请求错误';
break;
case 401:
if (isLogin) {
errorMessage = '您的登陆已过期';
} else {
errorMessage = '请先登录';
}
userStore.logout();
showAuthModal();
break;
case 403:
errorMessage = '拒绝访问';
break;
case 404:
errorMessage = '请求出错';
break;
case 408:
errorMessage = '请求超时';
break;
case 429:
errorMessage = '请求频繁, 请稍后再访问';
break;
case 500:
errorMessage = '服务器开小差啦,请稍后再试~';
break;
case 501:
errorMessage = '服务未实现';
break;
case 502:
errorMessage = '网络错误';
break;
case 503:
errorMessage = '服务不可用';
break;
case 504:
errorMessage = '网络超时';
break;
case 505:
errorMessage = 'HTTP版本不受支持';
break;
}
if (error.errMsg.includes('timeout')) errorMessage = '请求超时';
// #ifdef H5
if (error.errMsg.includes('Network'))
errorMessage = window.navigator.onLine ? '服务器异常' : '请检查您的网络连接';
// #endif
}
if (error && error.config) {
if (error.config.custom.showError === false) {
uni.showToast({
title: error.data?.msg || errorMessage,
icon: 'none',
mask: true,
});
}
error.config.custom.showLoading && closeLoading();
}
return false;
},
);
const request = (config) => {
if (config.url[0] !== '/') {
config.url = '/app-api/' + config.url;
}
// TODO 芋艿:额外拼接
if (config.url.indexOf('/app-api/') >= 0) {
// 设置接口地址
// config.url = 'http://api-dashboard.yudao.iocoder.cn' + config.url; // 调用【云端】
// config.url = 'https://app.test.huizhizao.vip/prod-api' + config.url; // 调用【云端】
config.url = 'http://127.0.0.1:48080' + config.url; // 调用【本地】
// config.url = 'http://yunai.natapp1.cc' + config.url; // 调用【natapp】
}
return http.middleware(config);
};
export default request;

View File

@ -1,4 +1,3 @@
import appApi from '@/sheep/api/app';
import diyTemplateApi from '@/sheep/api/promotion/diy/template'; import diyTemplateApi from '@/sheep/api/promotion/diy/template';
import { defineStore } from 'pinia'; import { defineStore } from 'pinia';
import $platform from '@/sheep/platform'; import $platform from '@/sheep/platform';

View File

@ -1,7 +1,7 @@
import { import {
defineStore defineStore
} from 'pinia'; } from 'pinia';
import userApi from '@/sheep/api/user'; // import userApi from '@/sheep/api/user';
import $share from '@/sheep/platform/share'; import $share from '@/sheep/platform/share';
import { import {
isEmpty, isEmpty,
@ -13,8 +13,6 @@ import app from './app';
import { import {
showAuthModal showAuthModal
} from '@/sheep/hooks/useModal'; } from '@/sheep/hooks/useModal';
import AuthUtil from '@/sheep/api/member/auth';
import BrokerageApi from '@/sheep/api/trade/brokerage';
import UserApi from '@/sheep/api/member/user'; import UserApi from '@/sheep/api/member/user';
import PayWalletApi from '@/sheep/api/pay/wallet'; import PayWalletApi from '@/sheep/api/pay/wallet';
import OrderApi from '@/sheep/api/trade/order'; import OrderApi from '@/sheep/api/trade/order';