代码更新

This commit is contained in:
GaoHao
2025-02-26 19:46:20 +08:00
parent 7519ffced3
commit b4a0393d2d
413 changed files with 7483 additions and 60762 deletions

View File

@@ -1,47 +0,0 @@
import request from './businessHttp.js'
import useStorage from '@/commons/utils/useStroage.js'
/**
* 登录
* @param {Object} data
*/
export function login(data) {
return request('/login/wx/merchant/login', data, 'post')
}
/**
* 桌台列表
* @param {Object} areaId
*/
export function tableList(areaId) {
return request('/table/list', {
shopId: useStorage.get('userInfo').shopId,
areaId: areaId
}, 'post')
}
/**
* 区域列表
* @param {Object} data
*/
export function areaList(data) {
return request('/table/area', {
shopId: useStorage.get('userInfo').shopId
})
}
/**
* 绑定桌码
* @param {Object} data
*/
export function tableBinding(data) {
return request('/table/binding', data, 'post')
}
/**
* 登录获取openid
* @param {Object} data
*/
export function wxlogin(data) {
return request('/login/wx/business/login', data)
}

View File

@@ -1,52 +0,0 @@
/**
* 因为两个小程序接口不一致餐饮商超商家端的接口使用该http
*/
import useStorage from '@/commons/utils/useStroage.js'
import go from '@/commons/utils/go.js';
// const baseURL = 'http://192.168.2.128:9000/cashierService'
// const baseURL = 'http://192.168.2.41:9888/cashierService'
let baseURL = 'https://wxcashiertest.sxczgkj.cn/cashierService'
// #ifdef H5
baseURL = '/ysk'
// #endif
// const baseURL = 'https://cashier.sxczgkj.cn/cashierService'
export default function(api = '', data = {}, method = 'GET') {
return new Promise((resolve, reject) => {
uni.request({
url: `${baseURL}${api}`,
method: method,
data: data,
header: {
'environment': 'wx',
'type': 'ios',
'version': '1.0.0',
'token': useStorage.get('iToken'),
'Authorization': useStorage.get('iToken'),
'Content-Type': 'application/json'
},
success: res => {
if (res.data.code == 0) {
resolve(res.data)
} else {
uni.showToast({
icon: 'none',
"title": res.data.msg
})
if(res.data.code==-4){
setTimeout(()=>{
go.to('PAGES_LOGIN', {}, 'redirect')
},2000)
}
reject(res.data.msg)
}
},
fail: err => {
uni.showToast({
icon: 'none',
"title": err.errMsg
})
reject(err)
}
})
})
}

View File

@@ -10,64 +10,77 @@
// 导入全局属性
import appConfig from '@/config/appConfig.js'
import storageManage from '@/commons/utils/storageManage.js'
import { sm4DecryptByResData } from '@/commons/utils/encryptUtil.js'
import {
sm4DecryptByResData
} from '@/commons/utils/encryptUtil.js'
import infoBox from "@/commons/utils/infoBox.js"
import go from '@/commons/utils/go.js';
let baseUrl = 'http://101.37.12.135:8080'
// #ifdef H5
baseUrl = '/server3/mch'
// #endif
// #ifndef H5
baseUrl = 'http://101.37.12.135:8080/mch'
// #endif
import { reject } from 'lodash';
// 测试服
let baseUrl = 'https://tapi.cashier.sxczgkj.cn/'
//预发布
// let baseUrl = 'https://pre-cashieradmin.sxczgkj.cn'
//正式
// let baseUrl = 'https://cashieradmin.sxczgkj.cn'
// 多少 ms 以内, 不提示loading
const loadingShowTime = 200
function getHeader(){
const headerObject={}
headerObject["token"] = storageManage.token()
return headerObject
}
// 通用处理逻辑
function commonsProcess(showLoading, httpReqCallback){
function commonsProcess(showLoading, httpReqCallback) {
// 判断是否请求完成(用作 是否loading
// 包括: 'ing', 'ingLoading', 'finish'
let reqState = 'ing'
// 是否已经提示的错误信息
let isShowErrorToast = false
let isShowErrorToast = false
// 请求完成, 需要处理的动作
let reqFinishFunc = () => {
if(reqState == 'ingLoading'){ // 关闭loading弹层
infoBox.hideLoading()
if (reqState == 'ingLoading') { // 关闭loading弹层
infoBox.hideLoading()
}
reqState = 'finish' // 请求完毕
}
// 明确显示loading
if(showLoading){
if (showLoading) {
// xx ms内响应完成不提示loading
setTimeout(() => {
if(reqState == 'ing'){
reqState = 'ingLoading'
infoBox.showLoading()
}
}, loadingShowTime)
if (reqState == 'ing') {
reqState = 'ingLoading'
infoBox.showLoading()
}
}, loadingShowTime)
}
return httpReqCallback().then((httpData) => {
reqFinishFunc(); // 请求完毕的动作
// 从http响应数据中解构响应数据 [ 响应码、 bodyData ]
let { statusCode, data } = httpData
let {
statusCode,
data
} = httpData
// 避免混淆重新命名
let bodyData = data
if(statusCode == 401){
// 清楚 token
storageManage.token(null, true)
if (statusCode == 500) {
isShowErrorToast = true
return Promise.reject(bodyData) // 跳转到catch函数
}
if (statusCode == 501) {
// storageManage.token(null, true)
// 提示信息
isShowErrorToast = true
// infoBox.showErrorToast('请登录').then(() => {
@@ -76,86 +89,147 @@ function commonsProcess(showLoading, httpReqCallback){
return Promise.reject(bodyData) // 跳转到catch函数
}
// http响应码不正确
if(statusCode != 200){
if (statusCode != 200 && statusCode != 204 && statusCode != 201) {
isShowErrorToast = true
infoBox.showToast('服务器异常')
bodyData.msg=bodyData.msg=='Bad credentials'?'用户名或密码错误':bodyData.msg
infoBox.showToast(bodyData.msg || '服务器异常')
return Promise.reject(bodyData) // 跳转到catch函数
}
// 业务响应异常
if(bodyData.code != 0){
// // 业务响应异常
if (bodyData.hasOwnProperty('code') && bodyData.code != 200) {
isShowErrorToast = true
infoBox.showToast(bodyData.msg)
if(bodyData.code == 5005){ // 密码已过期, 直接跳转到更改密码页面
uni.reLaunch({url: '/pageUser/setting/updatePwd'})
}
if(bodyData.code == 500){ // 密码已过期, 直接跳转到更改密码页面
uni.redirectTo({url: '/pages/login/index'})
}
return Promise.reject(bodyData)
// if (bodyData.code == 5005) { // 密码已过期, 直接跳转到更改密码页面
// uni.reLaunch({
// url: '/pageUser/setting/updatePwd'
// })
// }
// if(bodyData.code == 500){ // 密码已过期, 直接跳转到更改密码页面
// uni.redirectTo({url: '/pages/login/index'})
// }
return Promise.reject(bodyData) // 跳转到catch函数
}
// 加密数据
if(!bodyData.data && bodyData.encryptData){
return Promise.resolve({ bizData: sm4DecryptByResData(bodyData.encryptData), code: bodyData.code })
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 => {
return Promise.resolve(bodyData.data)
}).catch(res => {
console.log(res)
if(res.code==501){
storageManage.token(null, true)
infoBox.showToast(res.msg||'请登录').then(() => {
uni.redirectTo({url: '/pages/login/index'})
reject()
})
}
// if(res.status==400){
// storageManage.token(null, true)
// infoBox.showErrorToast('').then(() => {
// go.to("PAGES_LOGIN", {}, go.GO_TYPE_RELAUNCH)
// })
// }
if(res.code==500){
infoBox.showToast(res.msg||'服务器异常').then(() => {})
}
// if(res&&res.msg){
// infoBox.showErrorToast(res.msg)
// }
reqFinishFunc(); // 请求完毕的动作
// 如果没有提示错误, 那么此处提示 异常。
if(!isShowErrorToast){
if (!isShowErrorToast) {
infoBox.showToast(`请求网络异常`)
}
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["satoken"] = storageManage.token()
function req(uri, data, method = "GET", showLoading = true, extParams = {}) {
// headerObject[appConfig.tokenKey] = storageManage.token()
return commonsProcess(showLoading, () => {
return uni.request(
Object.assign({url: baseUrl + uri, data: data, method: method, header: headerObject}, extParams )
)
}
)
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 = {}
// headerObject[appConfig.tokenKey] = storageManage.token()
return commonsProcess(showLoading, () => {
return uni.request(
Object.assign({
url: baseUrl + url,
data: params||data,
method: method,
header: getHeader()
}, extParams)
)
})
}
// 上传
function upload(uri, data, file, showLoading = true, extParams = {}){
function upload(uri, data, file, showLoading = true, extParams = {}) {
// 放置token
let headerObject = {}
headerObject[appConfig.tokenKey] = storageManage.token()
// headerObject[appConfig.tokenKey] = storageManage.token()
return commonsProcess(showLoading, () => {
return uni.uploadFile(
Object.assign({url: baseUrl + 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)
})
}
)
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,
upload : upload
}
req: req,
request,
upload: upload
}

View File

@@ -1,182 +0,0 @@
/**
* 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"
import go from '@/commons/utils/go.js';
let baseUrl = 'http://101.37.12.135:8080'
// #ifdef H5
baseUrl = '/server3'
// #endif
// 多少 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弹层
infoBox.hideLoading()
}
reqState = 'finish' // 请求完毕
}
// 明确显示loading
if (showLoading) {
// xx ms内响应完成不提示loading
setTimeout(() => {
if (reqState == 'ing') {
reqState = 'ingLoading'
infoBox.showLoading()
}
}, loadingShowTime)
}
return httpReqCallback().then((httpData) => {
console.log(httpData);
reqFinishFunc(); // 请求完毕的动作
// 从http响应数据中解构响应数据 [ 响应码、 bodyData ]
let {
statusCode,
data
} = httpData
// 避免混淆重新命名
let bodyData = data
if (statusCode == 401) {
// 清楚 token
storageManage.token(null, true)
// 提示信息
isShowErrorToast = true
infoBox.showErrorToast('请登录').then(() => {
go.to("PAGES_LOGIN", {}, go.GO_TYPE_RELAUNCH)
})
return Promise.reject(bodyData) // 跳转到catch函数
}
// http响应码不正确
if (statusCode != 200) {
isShowErrorToast = true
infoBox.showErrorToast('服务器异常')
return Promise.reject(bodyData) // 跳转到catch函数
}
// 业务响应异常
if (bodyData.code != 200) {
isShowErrorToast = true
infoBox.showToast(bodyData.msg)
if (bodyData.code == 5005) { // 密码已过期, 直接跳转到更改密码页面
uni.reLaunch({
url: '/pageUser/setting/updatePwd'
})
}
if(bodyData.code == 500){ // 密码已过期, 直接跳转到更改密码页面
uni.redirectTo({url: '/pages/login/index'})
}
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) {
infoBox.showErrorToast(`请求网络异常`)
}
return Promise.reject(res)
}).finally(() => { // finally 是 then结束后再执行, 此处不适用。 需要在请求完成后立马调用: reqFinishFunc()
});
}
// 默认 显示loading(控制 xxs 内 不提示loading )
function req(uri, data, method = "GET", showLoading = true, extParams = {}) {
let headerObject = {}
// headerObject[appConfig.tokenKey] = storageManage.token()
headerObject["satoken"] = storageManage.token()
headerObject["content-type"] = 'application/json'
return commonsProcess(showLoading, () => {
return uni.request(
Object.assign({
url: baseUrl + uri,
data: data,
method: method,
header: headerObject
}, extParams)
)
})
}
// 上传
function upload(uri, data, file, showLoading = true, extParams = {}) {
// 放置token
let headerObject = {}
// headerObject[appConfig.tokenKey] = storageManage.token()
headerObject["satoken"] = 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
}

View File

@@ -1,11 +0,0 @@
import http from './http.js'
import appConfig from '@/config/appConfig.js'
import {
Base64
} from 'js-base64'
import infoBox from '@/commons/utils/infoBox.js'
/* 登录 */
export function $login(postData) {
// return http.req('/login', params, 'GET')
return http.req('/login', postData, 'POST')
}

View File

@@ -16,8 +16,9 @@ import {
import infoBox from "@/commons/utils/infoBox.js"
import go from '@/commons/utils/go.js';
import { reject } from 'lodash';
// 测试服
let baseUrl = 'https://admintestpapi.sxczgkj.cn'
let baseUrl = 'https://tapi.cashier.sxczgkj.cn/'
//预发布
// let baseUrl = 'https://pre-cashieradmin.sxczgkj.cn'