源文件
This commit is contained in:
110
jeepay-ui-uapp-face/http/apiManager.js
Normal file
110
jeepay-ui-uapp-face/http/apiManager.js
Normal file
@@ -0,0 +1,110 @@
|
||||
/**
|
||||
* api接口管理, 全部以$开头
|
||||
* @author terrfly
|
||||
* @site https://www.jeequan.com
|
||||
* @date 2021/12/17 09:57
|
||||
*/
|
||||
|
||||
import http from './http.js';
|
||||
import { Base64 } from 'js-base64';
|
||||
|
||||
export const req = {
|
||||
list: (uri, params) => {
|
||||
return http.req(uri, params, 'GET', false);
|
||||
},
|
||||
|
||||
add: (uri, data) => {
|
||||
return http.req(uri, data, 'POST', false);
|
||||
},
|
||||
|
||||
getById: (uri, bizId) => {
|
||||
return http.req(`${uri}/${bizId}`, {}, 'GET', false);
|
||||
},
|
||||
|
||||
updateById: (uri, bizId, data) => {
|
||||
return http.req(`${uri}/${bizId}`, data, 'PUT', false);
|
||||
},
|
||||
|
||||
delById: (uri, bizId) => {
|
||||
return http.req(`${uri}/${bizId}`, {}, 'DELETE', false);
|
||||
},
|
||||
};
|
||||
// 登录
|
||||
export const $login = (v) => {
|
||||
// 登录类型
|
||||
let lt = '';
|
||||
|
||||
// #ifdef H5 || MP-WEIXIN || MP-ALIPAY
|
||||
lt = Base64.encode('FACEAPP');
|
||||
// #endif
|
||||
|
||||
let data = {
|
||||
ia: Base64.encode(v.username),
|
||||
ip: Base64.encode(v.pwd),
|
||||
lt: lt,
|
||||
};
|
||||
return http.req('/api/anon/auth/validate', data, 'POST');
|
||||
};
|
||||
/** 支付订单列表 */
|
||||
export const API_URL_PAY_ORDER_LIST = '/api/payOrder';
|
||||
/* 订单退款 */
|
||||
export function $payOrderRefund(vdata) {
|
||||
return http.req(
|
||||
'/api/payOrder/refunds/' + vdata.payOrderId,
|
||||
{
|
||||
refundAmount: vdata.refundAmountNum,
|
||||
refundReason: vdata.refundReason,
|
||||
refundPassword: Base64.encode(vdata.refundPassword),
|
||||
},
|
||||
'POST'
|
||||
);
|
||||
}
|
||||
/* 获取个人信息 */
|
||||
export function $userInfo(cid1, cid2) {
|
||||
return http.req('/api/current/user', { cid1, cid2 }, 'GET');
|
||||
}
|
||||
// 首页 交易数据
|
||||
export const $indexPayment = () => {
|
||||
return http.req(
|
||||
'/api/mainChart/payDayCount',
|
||||
{ queryDateRange: 'today' },
|
||||
'GET'
|
||||
);
|
||||
};
|
||||
// 上下班 打卡接口
|
||||
export const $workRecords = (workState) => {
|
||||
return http.req('/api/user/workRecords', { workState: workState }, 'POST');
|
||||
};
|
||||
// 获取交班列表
|
||||
export const $handover = () => {
|
||||
return http.req('/api/user/workRecords/stats', {}, 'GET');
|
||||
};
|
||||
/* 支付接口*/
|
||||
export function $appPay(amount, authCode) {
|
||||
let data = { amount, wayCode: 'AUTO_BAR', authCode };
|
||||
return http.req('/api/pay/app', data, 'POST');
|
||||
}
|
||||
// 支付方式统计
|
||||
export const $payTypeStat = (data) => {
|
||||
return http.req('/api/statistic', data, 'GET');
|
||||
};
|
||||
// 总支付方式统计
|
||||
export const $payTypeStatAll = (data) => {
|
||||
return http.req('/api/statistic/total', data, 'GET');
|
||||
};
|
||||
// 交班列表
|
||||
export const $handoverList = (params) => {
|
||||
return http.req('/api/user/workRecords', params, 'GET');
|
||||
};
|
||||
// 交班详情
|
||||
export const $getHandoverById = (id) => {
|
||||
return req.getById('/api/user/workRecords', id);
|
||||
};
|
||||
// 获取公司信息 技术支持电话
|
||||
export const $getCompanyInfos = () => {
|
||||
return http.req('/api/anon/siteInfos?queryConfig=1', {}, 'GET');
|
||||
};
|
||||
// 获取刷脸设备广告
|
||||
export const $adBannerList = (params) => {
|
||||
return http.req('/api/advert/faceDevice',params,'GET')
|
||||
};
|
||||
184
jeepay-ui-uapp-face/http/http.js
Normal file
184
jeepay-ui-uapp-face/http/http.js
Normal file
@@ -0,0 +1,184 @@
|
||||
/**
|
||||
* HTTP的封装, 基于uni.request
|
||||
* 包括: 通用响应结果的处理 和 业务的增删改查函数
|
||||
*
|
||||
* @author terrfly
|
||||
* @site https://www.jeequan.com
|
||||
* @date 2021/12/16 18:35
|
||||
*/
|
||||
|
||||
// 导入全局属性
|
||||
import appConfig from '@/config/appConfig.js';
|
||||
import storageManage from '@/commons/utils/storageManage.js';
|
||||
import { sm4DecryptByResData } from '@/commons/utils/encryptUtil.js';
|
||||
import infoBox from "@/commons/utils/infoBox.js"
|
||||
// 多少 ms 以内, 不提示loading
|
||||
const loadingShowTime = 200;
|
||||
|
||||
// 通用处理逻辑
|
||||
function commonsProcess(showLoading, httpReqCallback) {
|
||||
// 判断是否请求完成(用作 是否loading )
|
||||
// 包括: 'ing', 'ingLoading', 'finish'
|
||||
let reqState = 'ing';
|
||||
|
||||
// 是否已经提示的错误信息
|
||||
let isShowErrorToast = false;
|
||||
|
||||
// 请求完成, 需要处理的动作
|
||||
let reqFinishFunc = () => {
|
||||
if (reqState == 'ingLoading') {
|
||||
// 关闭loading弹层
|
||||
uni.hideLoading();
|
||||
}
|
||||
reqState = 'finish'; // 请求完毕
|
||||
};
|
||||
|
||||
// 明确显示loading
|
||||
if (showLoading) {
|
||||
// xx ms内响应完成,不提示loading
|
||||
setTimeout(() => {
|
||||
if (reqState == 'ing') {
|
||||
reqState = 'ingLoading';
|
||||
uni.showLoading();
|
||||
}
|
||||
}, loadingShowTime);
|
||||
}
|
||||
|
||||
return httpReqCallback()
|
||||
.then((httpData) => {
|
||||
reqFinishFunc(); // 请求完毕的动作
|
||||
|
||||
// 从http响应数据中解构响应数据 [ 响应码、 bodyData ]
|
||||
let { statusCode, data } = httpData;
|
||||
// 避免混淆重新命名
|
||||
let bodyData = data;
|
||||
if (statusCode == 401) {
|
||||
// 清楚 token
|
||||
storageManage.token(null, true);
|
||||
|
||||
// 提示信息
|
||||
isShowErrorToast = true;
|
||||
uni
|
||||
.showToast({
|
||||
title: '请登录',
|
||||
icon: 'none',
|
||||
duration: 3000,
|
||||
})
|
||||
.then(() => {
|
||||
uni.reLaunch({
|
||||
url: '/pages/login/login',
|
||||
});
|
||||
});
|
||||
return Promise.reject(bodyData); // 跳转到catch函数
|
||||
}
|
||||
// http响应码不正确
|
||||
if (statusCode != 200) {
|
||||
isShowErrorToast = true;
|
||||
uni.showToast({
|
||||
title: '服务器异常',
|
||||
});
|
||||
return Promise.reject(bodyData); // 跳转到catch函数
|
||||
}
|
||||
|
||||
// 业务响应异常
|
||||
if (bodyData.code != 0) {
|
||||
isShowErrorToast = true;
|
||||
return Promise.reject(bodyData);
|
||||
}
|
||||
|
||||
// 加密数据
|
||||
if (!bodyData.data && bodyData.encryptData) {
|
||||
return Promise.resolve({
|
||||
bizData: sm4DecryptByResData(bodyData.encryptData),
|
||||
code: bodyData.code,
|
||||
});
|
||||
}
|
||||
|
||||
// 构造请求成功的响应数据
|
||||
return Promise.resolve({
|
||||
bizData: bodyData.data,
|
||||
code: bodyData.code,
|
||||
});
|
||||
})
|
||||
.catch((res) => {
|
||||
reqFinishFunc(); // 请求完毕的动作
|
||||
// 如果没有提示错误, 那么此处提示 异常。
|
||||
if (!isShowErrorToast) {
|
||||
uni.showToast({
|
||||
title: `请求网络异常`,
|
||||
icon: 'none',
|
||||
});
|
||||
}else if(res.code != 0){
|
||||
setTimeout(()=>{
|
||||
infoBox.showToast(res.msg)
|
||||
},200)
|
||||
}
|
||||
|
||||
return Promise.reject(res);
|
||||
})
|
||||
.finally(() => {
|
||||
// finally 是 then结束后再执行, 此处不适用。 需要在请求完成后立马调用: reqFinishFunc()
|
||||
});
|
||||
}
|
||||
|
||||
// 默认 显示loading(控制 xxs 内 不提示loading )
|
||||
function req(uri, data, method = 'GET', showLoading = true, extParams = {}) {
|
||||
// 放置token
|
||||
let headerObject = {};
|
||||
headerObject[appConfig.tokenKey] = storageManage.token();
|
||||
headerObject.facedevice = JSON.stringify({
|
||||
deviceNo: storageManage.deviceNo(), //写入设备号
|
||||
//#ifdef MP-WEIXIN
|
||||
provider: 'wxpayQWPro', //微信刷脸支付
|
||||
//#endif
|
||||
//#ifdef MP-ALIPAY
|
||||
provider: 'alipayQT', //支付宝刷脸支付
|
||||
//#endif
|
||||
});
|
||||
|
||||
return commonsProcess(showLoading, () => {
|
||||
return uni.request(
|
||||
Object.assign(
|
||||
{
|
||||
url: appConfig.env.JEEPAY_BASE_URL + uri,
|
||||
data: data,
|
||||
method: method,
|
||||
header: headerObject,
|
||||
},
|
||||
extParams
|
||||
)
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
// 上传
|
||||
function upload(uri, data, file, showLoading = true, extParams = {}) {
|
||||
// 放置token
|
||||
let headerObject = {};
|
||||
headerObject[appConfig.tokenKey] = storageManage.token();
|
||||
return commonsProcess(showLoading, () => {
|
||||
return uni
|
||||
.uploadFile(
|
||||
Object.assign(
|
||||
{
|
||||
url: appConfig.env.JEEPAY_BASE_URL + uri,
|
||||
formData: data,
|
||||
name: 'file',
|
||||
filePath: file.path,
|
||||
header: headerObject,
|
||||
},
|
||||
extParams
|
||||
)
|
||||
)
|
||||
.then((httpData) => {
|
||||
// uni.upload 返回bodyData 的是 string类型。 需要解析。
|
||||
httpData.data = JSON.parse(httpData.data);
|
||||
return Promise.resolve(httpData);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
export default {
|
||||
req: req,
|
||||
upload: upload,
|
||||
};
|
||||
Reference in New Issue
Block a user