代客下单修改,登录页面修改,部分页面调整,请求封装调整
This commit is contained in:
19
http/yskApi/account/shopStaff.js
Normal file
19
http/yskApi/account/shopStaff.js
Normal file
@@ -0,0 +1,19 @@
|
||||
import http from '../http.js'
|
||||
const request = http.request
|
||||
import {accountUrl} from '../prveUrl.js'
|
||||
|
||||
/**
|
||||
* 当前登录员工信息
|
||||
* @returns
|
||||
*/
|
||||
export function shopStaffInfo(params) {
|
||||
return request({
|
||||
url: accountUrl+`/admin/shopStaff/info`,
|
||||
method: 'get',
|
||||
params: {
|
||||
shopId: uni.getStorageSync('shopId'),
|
||||
...params
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,24 +1,22 @@
|
||||
/**
|
||||
* 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 infoBox from "@/commons/utils/infoBox.js"
|
||||
import go from '@/commons/utils/go.js';
|
||||
import {
|
||||
reject
|
||||
} from 'lodash';
|
||||
import appConfig from "@/config/appConfig.js";
|
||||
import storageManage from "@/commons/utils/storageManage.js";
|
||||
import infoBox from "@/commons/utils/infoBox.js";
|
||||
import go from "@/commons/utils/go.js";
|
||||
import { reject } from "lodash";
|
||||
// 测试服
|
||||
// let baseUrl = 'http://192.168.1.31'
|
||||
// let baseUrl = 'https://admintestpapi.sxczgkj.cn'
|
||||
// const proxyApiwws = 'ws://192.168.1.31:2348' // 调试地址
|
||||
// const proxyApiwws = 'ws://192.168.1.31:2348' // 调试地址
|
||||
//预发布
|
||||
// let baseUrl = 'https://pre-cashieradmin.sxczgkj.cn'
|
||||
|
||||
@@ -27,189 +25,196 @@ import {
|
||||
// let baseUrl = 'https://cashier.sxczgkj.com'
|
||||
|
||||
// 本地测
|
||||
let baseUrl = "http://192.168.1.42"
|
||||
let baseUrl = "http://192.168.1.42";
|
||||
// #ifdef H5
|
||||
baseUrl = '/ysk'
|
||||
baseUrl = "/ysk";
|
||||
// #endif
|
||||
|
||||
// let baseUrl = 'http://192.168.1.15:8000'
|
||||
// 巩
|
||||
// let baseUrl = 'http://192.168.1.9:8000'
|
||||
// 多少 ms 以内, 不提示loading
|
||||
const loadingShowTime = 200
|
||||
|
||||
// 多少 ms 以内, 不提示loading
|
||||
const loadingShowTime = 200;
|
||||
|
||||
function getHeader() {
|
||||
const headerObject = {}
|
||||
headerObject["token"] = uni.getStorageSync('tokenInfo').tokenValue
|
||||
headerObject["shopId"] = uni.getStorageSync("shopId"),
|
||||
// shopId:shopInfo.value.id
|
||||
headerObject["Content-Type"] = 'application/json;charset=UTF-8'
|
||||
headerObject["platformType"] ="PAD"
|
||||
return headerObject
|
||||
const headerObject = {};
|
||||
headerObject["token"] = uni.getStorageSync("tokenInfo").tokenValue;
|
||||
(headerObject["shopId"] = uni.getStorageSync("shopId")),
|
||||
// shopId:shopInfo.value.id
|
||||
(headerObject["Content-Type"] = "application/json;charset=UTF-8");
|
||||
headerObject["platformType"] = "PAD";
|
||||
return headerObject;
|
||||
}
|
||||
|
||||
// 通用处理逻辑
|
||||
// 通用处理逻辑
|
||||
function commonsProcess(showLoading, httpReqCallback) {
|
||||
// 判断是否请求完成(用作 是否loading )
|
||||
// 包括: 'ing', 'ingLoading', 'finish'
|
||||
let reqState = "ing";
|
||||
|
||||
// 判断是否请求完成(用作 是否loading )
|
||||
// 包括: 'ing', 'ingLoading', 'finish'
|
||||
let reqState = 'ing'
|
||||
// 是否已经提示的错误信息
|
||||
let isShowErrorToast = false;
|
||||
|
||||
// 是否已经提示的错误信息
|
||||
let isShowErrorToast = false
|
||||
// 请求完成, 需要处理的动作
|
||||
let reqFinishFunc = () => {
|
||||
if (reqState == "ingLoading") {
|
||||
// 关闭loading弹层
|
||||
infoBox.hideLoading();
|
||||
}
|
||||
reqState = "finish"; // 请求完毕
|
||||
};
|
||||
|
||||
// 明确显示loading
|
||||
if (showLoading) {
|
||||
// xx ms内响应完成,不提示loading
|
||||
setTimeout(() => {
|
||||
if (reqState == "ing") {
|
||||
reqState = "ingLoading";
|
||||
infoBox.showLoading();
|
||||
}
|
||||
}, loadingShowTime);
|
||||
}
|
||||
|
||||
// 请求完成, 需要处理的动作
|
||||
let reqFinishFunc = () => {
|
||||
return httpReqCallback()
|
||||
.then((httpData) => {
|
||||
reqFinishFunc(); // 请求完毕的动作
|
||||
// 从http响应数据中解构响应数据 [ 响应码、 bodyData ]
|
||||
let { statusCode, data } = httpData;
|
||||
// 避免混淆重新命名
|
||||
let bodyData = data;
|
||||
console.log('bodyData',bodyData)
|
||||
|
||||
if (reqState == 'ingLoading') { // 关闭loading弹层
|
||||
infoBox.hideLoading()
|
||||
}
|
||||
reqState = 'finish' // 请求完毕
|
||||
}
|
||||
if (statusCode == 500) {
|
||||
isShowErrorToast = true;
|
||||
return Promise.reject(bodyData); // 跳转到catch函数
|
||||
}
|
||||
if (statusCode == 401) {
|
||||
isShowErrorToast = true;
|
||||
|
||||
// 明确显示loading
|
||||
if (showLoading) {
|
||||
// xx ms内响应完成,不提示loading
|
||||
setTimeout(() => {
|
||||
if (reqState == 'ing') {
|
||||
reqState = 'ingLoading'
|
||||
infoBox.showLoading()
|
||||
}
|
||||
}, loadingShowTime)
|
||||
}
|
||||
return Promise.reject(bodyData); // 跳转到catch函数
|
||||
}
|
||||
|
||||
return httpReqCallback().then((httpData) => {
|
||||
reqFinishFunc(); // 请求完毕的动作
|
||||
// 从http响应数据中解构响应数据 [ 响应码、 bodyData ]
|
||||
let {
|
||||
statusCode,
|
||||
data
|
||||
} = httpData
|
||||
// 避免混淆重新命名
|
||||
let bodyData = data
|
||||
if (statusCode == 500) {
|
||||
isShowErrorToast = true
|
||||
return Promise.reject(bodyData) // 跳转到catch函数
|
||||
}
|
||||
if (statusCode == 401) {
|
||||
// http响应码不正确
|
||||
if (statusCode != 200 && statusCode != 204 && statusCode != 201) {
|
||||
isShowErrorToast = true;
|
||||
data.message =
|
||||
data.message == "Bad credentials" ? "用户名或密码错误" : data.message;
|
||||
infoBox.showToast(data.message || "服务器异常");
|
||||
return Promise.reject(bodyData); // 跳转到catch函数
|
||||
}
|
||||
// 构造请求成功的响应数据
|
||||
if (bodyData.code == 501) {
|
||||
return Promise.reject(bodyData); // 跳转到catch函数
|
||||
}
|
||||
return Promise.resolve(bodyData.data);
|
||||
})
|
||||
.catch((res) => {
|
||||
if (res.code == 401 || res.code == 501) {
|
||||
storageManage.token(null, true);
|
||||
infoBox.showErrorToast(res.message || "请登录").then(() => {
|
||||
uni.redirectTo({
|
||||
url: "/pages/login/index",
|
||||
});
|
||||
reject();
|
||||
});
|
||||
}
|
||||
|
||||
isShowErrorToast = true
|
||||
if (res.status == 500) {
|
||||
infoBox.showErrorToast(res.message || "服务器异常").then(() => {});
|
||||
}
|
||||
|
||||
return Promise.reject(bodyData) // 跳转到catch函数
|
||||
}
|
||||
// http响应码不正确
|
||||
if (statusCode != 200 && statusCode != 204 && statusCode != 201) {
|
||||
isShowErrorToast = true
|
||||
data.message = data.message == 'Bad credentials' ? '用户名或密码错误' : data.message
|
||||
infoBox.showToast(data.message || '服务器异常')
|
||||
return Promise.reject(bodyData) // 跳转到catch函数
|
||||
}
|
||||
|
||||
// 构造请求成功的响应数据
|
||||
return Promise.resolve(bodyData)
|
||||
reqFinishFunc(); // 请求完毕的动作
|
||||
|
||||
}).catch(res => {
|
||||
if (res.status == 401) {
|
||||
storageManage.token(null, true)
|
||||
infoBox.showErrorToast(res.message || '请登录').then(() => {
|
||||
uni.redirectTo({
|
||||
url: '/pages/login/index'
|
||||
})
|
||||
reject()
|
||||
})
|
||||
}
|
||||
|
||||
if (res.status == 500) {
|
||||
infoBox.showErrorToast(res.message || '服务器异常').then(() => {})
|
||||
}
|
||||
|
||||
reqFinishFunc(); // 请求完毕的动作
|
||||
|
||||
// 如果没有提示错误, 那么此处提示 异常。
|
||||
if (!isShowErrorToast) {
|
||||
infoBox.showErrorToast(`请求网络异常`)
|
||||
}
|
||||
|
||||
return Promise.reject(res)
|
||||
|
||||
}).finally(() => { // finally 是 then结束后再执行, 此处不适用。 需要在请求完成后立马调用: reqFinishFunc()
|
||||
|
||||
});
|
||||
// 如果没有提示错误, 那么此处提示 异常。
|
||||
if (!isShowErrorToast) {
|
||||
infoBox.showErrorToast(`请求网络异常`);
|
||||
}
|
||||
|
||||
return Promise.reject(res);
|
||||
})
|
||||
.finally(() => {
|
||||
// finally 是 then结束后再执行, 此处不适用。 需要在请求完成后立马调用: reqFinishFunc()
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
// 默认 显示loading(控制 xxs 内 不提示loading )
|
||||
function req(uri, data, method = "GET", showLoading = true, extParams = {}) {
|
||||
return commonsProcess(showLoading, () => {
|
||||
return uni.request(
|
||||
Object.assign({
|
||||
url: baseUrl + uri,
|
||||
data: data,
|
||||
method: method,
|
||||
header: getHeader()
|
||||
}, extParams)
|
||||
)
|
||||
})
|
||||
return commonsProcess(showLoading, () => {
|
||||
return uni.request(
|
||||
Object.assign(
|
||||
{
|
||||
url: baseUrl + uri,
|
||||
data: data,
|
||||
method: method,
|
||||
header: getHeader(),
|
||||
},
|
||||
extParams
|
||||
)
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
// 默认 显示loading(控制 xxs 内 不提示loading )
|
||||
function request(args) {
|
||||
const {
|
||||
url,
|
||||
data,
|
||||
params,
|
||||
method = "GET",
|
||||
showLoading = true,
|
||||
extParams = {}
|
||||
} = args
|
||||
let headerObject = {}
|
||||
return commonsProcess(showLoading, () => {
|
||||
// console.log('baseUrl+');
|
||||
// console.log(baseUrl + url);
|
||||
return uni.request(
|
||||
Object.assign({
|
||||
url: baseUrl + url,
|
||||
data: params || data,
|
||||
method: method,
|
||||
header: getHeader()
|
||||
}, extParams)
|
||||
)
|
||||
})
|
||||
const {
|
||||
url,
|
||||
data,
|
||||
params,
|
||||
method = "GET",
|
||||
showLoading = true,
|
||||
extParams = {},
|
||||
} = args;
|
||||
let headerObject = {};
|
||||
return commonsProcess(showLoading, () => {
|
||||
// console.log('baseUrl+');
|
||||
// console.log(baseUrl + url);
|
||||
return uni.request(
|
||||
Object.assign(
|
||||
{
|
||||
url: baseUrl + url,
|
||||
data: params || data,
|
||||
method: method,
|
||||
header: getHeader(),
|
||||
},
|
||||
extParams
|
||||
)
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
// 上传
|
||||
function upload(uri, data, file, showLoading = true, extParams = {}) {
|
||||
// 放置token
|
||||
let headerObject = {}
|
||||
// 放置token
|
||||
let headerObject = {};
|
||||
|
||||
return commonsProcess(showLoading, () => {
|
||||
return uni.uploadFile(
|
||||
Object.assign({
|
||||
url: baseUrl + uri,
|
||||
formData: data,
|
||||
name: "file",
|
||||
filePath: file.path || file.url,
|
||||
header: getHeader()
|
||||
}, extParams)
|
||||
).then((httpData) => {
|
||||
// uni.upload 返回bodyData 的是 string类型。 需要解析。
|
||||
httpData.data = JSON.parse(httpData.data)
|
||||
return Promise.resolve(httpData)
|
||||
}).catch(err => {
|
||||
uni.hideLoading()
|
||||
infoBox.showErrorToast(`上传失败`)
|
||||
})
|
||||
})
|
||||
return commonsProcess(showLoading, () => {
|
||||
return uni
|
||||
.uploadFile(
|
||||
Object.assign(
|
||||
{
|
||||
url: baseUrl + uri,
|
||||
formData: data,
|
||||
name: "file",
|
||||
filePath: file.path || file.url,
|
||||
header: getHeader(),
|
||||
},
|
||||
extParams
|
||||
)
|
||||
)
|
||||
.then((httpData) => {
|
||||
// uni.upload 返回bodyData 的是 string类型。 需要解析。
|
||||
httpData.data = JSON.parse(httpData.data);
|
||||
return Promise.resolve(httpData);
|
||||
})
|
||||
.catch((err) => {
|
||||
uni.hideLoading();
|
||||
infoBox.showErrorToast(`上传失败`);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
export default {
|
||||
req: req,
|
||||
request,
|
||||
upload: upload
|
||||
}
|
||||
req: req,
|
||||
request,
|
||||
upload: upload,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user