init
This commit is contained in:
25
common/http/config.js
Normal file
25
common/http/config.js
Normal file
@@ -0,0 +1,25 @@
|
||||
// http 请求配置项
|
||||
export default {
|
||||
// 开发者服务器接口地址
|
||||
|
||||
// url: '/api',
|
||||
url:'http://127.0.0.1:10220',
|
||||
// 请求的参数
|
||||
data: {},
|
||||
// 设置请求的 header,header 中不能设置 Referer。
|
||||
header: {
|
||||
// "Content-Type":"application/x-www-form-urlencoded"
|
||||
},
|
||||
// (需大写)有效值:OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
|
||||
method: "POST",
|
||||
// json 如果设为json,会尝试对返回的数据做一次 JSON.parse
|
||||
dataType: "json",
|
||||
// text 设置响应的数据类型。合法值:text、arraybuffer 1.7.0
|
||||
responseType: "text",
|
||||
// 收到开发者服务成功返回的回调函数
|
||||
success() {},
|
||||
// 接口调用失败的回调函数
|
||||
fail() {},
|
||||
// 接口调用结束的回调函数(调用成功、失败都会执行)
|
||||
complete() {},
|
||||
}
|
141
common/http/eatery/order.js
Normal file
141
common/http/eatery/order.js
Normal file
@@ -0,0 +1,141 @@
|
||||
import https from '../interface'
|
||||
/* handle: 默认false,true时自己处理401/404等错误,不交给全局处理 */
|
||||
|
||||
export default {
|
||||
/**
|
||||
* 分页查询订单列表
|
||||
* @param {Object} data - 查询参数
|
||||
* @param {number} data.pageNum - 页码
|
||||
* @param {number} data.pageSize - 每页条数
|
||||
* @param {string} [data.customerName] - 顾客姓名
|
||||
* @param {string} [data.tableId] - 桌号
|
||||
* @param {string} [data.startDate] - 开始日期(yyyy-MM-dd)
|
||||
* @param {string} [data.endDate] - 结束日期(yyyy-MM-dd)
|
||||
* @param {string} [data.paymentMethod] - 支付方式
|
||||
* @returns {Promise}
|
||||
*/
|
||||
getOrderPage(data) {
|
||||
return https({
|
||||
url: '/eatery/eateryOrder/pageList',
|
||||
method: 'get',
|
||||
data
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 获取订单详情
|
||||
* @param {Object} data - 参数
|
||||
* @param {string|number} data.id - 订单ID
|
||||
* @returns {Promise}
|
||||
*/
|
||||
getOrderDetail(data) {
|
||||
return https({
|
||||
url: `/eatery/eateryOrder/${data.id}`,
|
||||
method: 'get'
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 新增订单
|
||||
* @param {Object} data - 订单数据
|
||||
* @param {string} data.customerName - 顾客姓名
|
||||
* @param {string} data.tableId - 桌号
|
||||
* @param {string} data.orderDate - 订单日期(yyyy-MM-dd)
|
||||
* @param {number} data.totalAmount - 应收金额
|
||||
* @param {number} [data.discountAmount=0] - 优惠金额
|
||||
* @param {number} data.actualReceivedAmount - 实收金额
|
||||
* @param {number} [data.changeAmount=0] - 找零金额
|
||||
* @param {number} [data.zeroAmount=0] - 抹零金额
|
||||
* @param {string} data.paymentMethod - 支付方式
|
||||
* @param {number} data.productTotalCount - 商品总数量
|
||||
* @param {string} [data.remark] - 备注
|
||||
* @returns {Promise}
|
||||
*/
|
||||
addOrder(data) {
|
||||
return https({
|
||||
url: '/eatery/eateryOrder/order',
|
||||
method: 'post',
|
||||
data
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 修改订单
|
||||
* @param {Object} data - 订单数据(含id)
|
||||
* @param {string|number} data.id - 订单ID
|
||||
* @param {string} [data.customerName] - 顾客姓名
|
||||
* @param {string} [data.tableId] - 桌号
|
||||
* @param {string} [data.orderDate] - 订单日期(yyyy-MM-dd)
|
||||
* @param {number} [data.totalAmount] - 应收金额
|
||||
* @param {number} [data.discountAmount] - 优惠金额
|
||||
* @param {number} [data.actualReceivedAmount] - 实收金额
|
||||
* @param {number} [data.changeAmount] - 找零金额
|
||||
* @param {number} [data.zeroAmount] - 抹零金额
|
||||
* @param {string} [data.paymentMethod] - 支付方式
|
||||
* @param {number} [data.productTotalCount] - 商品总数量
|
||||
* @param {string} [data.remark] - 备注
|
||||
* @returns {Promise}
|
||||
*/
|
||||
updateOrder(data) {
|
||||
return https({
|
||||
url: '/eatery/eateryOrder',
|
||||
method: 'put',
|
||||
data
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 删除订单
|
||||
* @param {Object} data - 参数
|
||||
* @param {string|number} data.id - 订单ID(单个删除)或IDs(批量删除,逗号分隔)
|
||||
* @returns {Promise}
|
||||
*/
|
||||
deleteOrder(data) {
|
||||
return https({
|
||||
url: `/eatery/eateryOrder/${data.id}`,
|
||||
method: 'delete'
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 订单结算
|
||||
* @param {Object} data - 结算数据
|
||||
* @param {string|number} data.id - 订单ID
|
||||
* @param {string} data.paymentMethod - 支付方式
|
||||
* @param {number} [data.discountAmount=0] - 优惠金额
|
||||
* @param {number} [data.zeroAmount=0] - 抹零金额
|
||||
* @returns {Promise}
|
||||
*/
|
||||
settleOrder(data) {
|
||||
return https({
|
||||
url: '/eatery/eateryOrder/checkout',
|
||||
method: 'post',
|
||||
data
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 获取支付方式列表
|
||||
* @returns {Promise}
|
||||
*/
|
||||
getPaymentMethods() {
|
||||
return https({
|
||||
url: '/system/config/getPaymentConfig',
|
||||
method: 'get'
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 导出订单数据
|
||||
* @param {Object} data - 查询参数(同分页查询)
|
||||
* @returns {Promise}
|
||||
*/
|
||||
exportOrders(data) {
|
||||
return https({
|
||||
url: '/eatery/eateryOrder/export',
|
||||
method: 'get',
|
||||
data,
|
||||
responseType: 'blob' // 导出文件需指定响应类型
|
||||
})
|
||||
}
|
||||
}
|
109
common/http/index.js
Normal file
109
common/http/index.js
Normal file
@@ -0,0 +1,109 @@
|
||||
import https from './interface'
|
||||
/* handle 默认是false; true 为自己处理请求错误(401、404、405),不交给全局处理 */
|
||||
import { encrypt } from './../jsencrypt'
|
||||
export default {
|
||||
// 登录
|
||||
login (data) {
|
||||
return https({
|
||||
url: `/sys/app/login`,
|
||||
method: 'post',
|
||||
data: {
|
||||
...data,
|
||||
password: encrypt(data.password)
|
||||
}
|
||||
})
|
||||
},
|
||||
// 扫码核销
|
||||
updateVerification (data) {
|
||||
return https({
|
||||
url: `/api/userCollect/updateVerification`,
|
||||
method: 'put',
|
||||
data
|
||||
})
|
||||
},
|
||||
// 获取用户信息
|
||||
getInfo (data) {
|
||||
return https({
|
||||
url: `/sys/app/getInfo`,
|
||||
method: 'GET',
|
||||
data
|
||||
})
|
||||
},
|
||||
// 核销记录
|
||||
verificationList (data) {
|
||||
return https({
|
||||
url: `/api/userCollect/verificationList`,
|
||||
method: 'GET',
|
||||
data
|
||||
})
|
||||
},
|
||||
// 核销详情
|
||||
verificationDetail (data) {
|
||||
return https({
|
||||
url: `/api/userCollect/verificationDetail/${data.id}`,
|
||||
method: 'GET'
|
||||
})
|
||||
},
|
||||
// 扫码/手动核销详情
|
||||
handVerificationDetail (data) {
|
||||
return https({
|
||||
url: `/api/userCollect/handVerificationDetail`,
|
||||
method: 'GET',
|
||||
data
|
||||
})
|
||||
},
|
||||
// 获取待核销单详情
|
||||
getVerificationDetail (data) {
|
||||
return https({
|
||||
url: `/api/userCollect/getVerificationDetail`,
|
||||
method: 'GET',
|
||||
data
|
||||
})
|
||||
},
|
||||
// 小程序核销
|
||||
toVerification (data) {
|
||||
data.verificationType = '4';
|
||||
return https({
|
||||
url: `/api/userCollect/toVerification`,
|
||||
method: 'put',
|
||||
data
|
||||
})
|
||||
},
|
||||
// 手持机核销
|
||||
handheldVerification (data) {
|
||||
data.verificationType = '6';
|
||||
return https({
|
||||
// url: `/api/device/handheld/toVerification`,
|
||||
url: '/api/userCollect/toVerification',
|
||||
method: 'put',
|
||||
data
|
||||
})
|
||||
},
|
||||
// 游客画像
|
||||
getTouristPortrait () {
|
||||
return https({
|
||||
url: `/api/userCollect/getTouristPortrait`,
|
||||
method: 'GET'
|
||||
})
|
||||
},
|
||||
// 运营分析
|
||||
getOperationalAnalysis () {
|
||||
return https({
|
||||
url: `/api/userCollect/getOperationalAnalysis`,
|
||||
method: 'GET'
|
||||
})
|
||||
},
|
||||
// 实时监控
|
||||
getRealTimeMonitoring () {
|
||||
return https({
|
||||
url: `/api/userCollect/getRealTimeMonitoring`,
|
||||
method: 'GET'
|
||||
})
|
||||
},
|
||||
getHomeMsg(){
|
||||
return https({
|
||||
url: '/manageapi/shopHome',
|
||||
method: 'GET'
|
||||
})
|
||||
}
|
||||
}
|
85
common/http/interface.js
Normal file
85
common/http/interface.js
Normal file
@@ -0,0 +1,85 @@
|
||||
import _config from './config'; // 导入私有配置
|
||||
|
||||
export default function $http(options) {
|
||||
options.url = _config.url + options.url;
|
||||
if (options.type) _config.header['Content-Type'] = options.type;
|
||||
if (uni.getStorageSync("tourism_token")) {
|
||||
_config.header.Authorization = 'Bearer ' + uni.getStorageSync("tourism_token");
|
||||
} else _config.header.Authorization = '';
|
||||
return new Promise((resolve, reject) => {
|
||||
// 进行url字符串拼接
|
||||
// 拦截请求
|
||||
_config.complete = (response) => {
|
||||
// request請求访问成功
|
||||
if (response.statusCode === 200 || response.statusCode === 403) {
|
||||
// 接口请求成功
|
||||
if([401,403,404,405].includes(response.data.code)){
|
||||
_page_error(response.data.code , response.data.msg, options.url);
|
||||
}else{
|
||||
if(response.data.code!=200){
|
||||
if(response.data.msg && (response.data.msg.indexOf("用户不存在,请重新登录")!=-1 || response.data.msg.indexOf("请重新登录后进行操作")!=-1)){
|
||||
uni.removeStorageSync("tourism_token");
|
||||
uni.reLaunch({
|
||||
url:"/pages/index/index"
|
||||
})
|
||||
}else{
|
||||
_page_error(response.data.code , response.data.msg, options.url);
|
||||
}
|
||||
resolve(response.data);
|
||||
}else{
|
||||
resolve(response.data);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// 处理catch 请求,不在本页面之外处理,统一在这里处理
|
||||
if (options.handle) {
|
||||
reject(response)
|
||||
} else {
|
||||
try {
|
||||
Promise.reject(response).catch(err => {
|
||||
// console.error(err);
|
||||
_page_error(response.statusCode , response.errMsg, options.url);
|
||||
});
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
// 开始请求
|
||||
uni.request(Object.assign({}, _config, options));
|
||||
})
|
||||
}
|
||||
// request 錯誤
|
||||
function _page_error(err, msg, response) {
|
||||
switch (err) {
|
||||
case 401:
|
||||
// 错误码404的处理方式
|
||||
uni.showToast({ title: '登录已过期,请重新登录', icon: 'none', mask: true })
|
||||
uni.removeStorageSync("tourism_token");
|
||||
setTimeout(() => {
|
||||
uni.reLaunch({
|
||||
url: "/pages/login/login"
|
||||
})
|
||||
}, 1500)
|
||||
break;
|
||||
case 403:
|
||||
uni.showToast({
|
||||
title: "您没有权限,请联系管理员",
|
||||
icon: "none",
|
||||
mask: true
|
||||
})
|
||||
break;
|
||||
case 404:
|
||||
uni.showToast({ title: '请求页面不存在,请联系管理员', icon: 'none', mask: true })
|
||||
// 错误码404的处理方式
|
||||
break;
|
||||
case 405:
|
||||
console.error("错误的请求")
|
||||
break;
|
||||
case 500:
|
||||
if (response.indexOf('/api/userCollect/HandVerification') == -1 && response.indexOf('/api/device/handheld/toVerification') == -1 && response.indexOf('/api/userCollect/toVerification') == -1) uni.showToast({ title: msg, icon: 'none', mask: true });
|
||||
break;
|
||||
}
|
||||
}
|
12
common/jsencrypt.js
Normal file
12
common/jsencrypt.js
Normal file
@@ -0,0 +1,12 @@
|
||||
import JSEncrypt from './jsencrypt.min'
|
||||
|
||||
// 密钥对生成 http://web.chacuo.net/netrsakeypair
|
||||
|
||||
const publicKey = 'MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCXgKEE1zA47xfCqZ451FfkRMVj610bolAoorFpRv9KOjwFN3l9rG1IX2rhiftHsuKXJPMhGnkxxUAVq5iWfuKz1uWKkz6yL3rbOy3yv90FEUbHY/YY29pSkaS0avR0+9gLxq0a4s7MiD96jFat2Bz6rvHUWT3v309XyXps6RwEAwIDAQAB'
|
||||
|
||||
// 加密
|
||||
export function encrypt(txt) {
|
||||
const encryptor = new JSEncrypt()
|
||||
encryptor.setPublicKey(publicKey) // 设置公钥
|
||||
return encryptor.encrypt(txt) // 对数据进行加密
|
||||
}
|
1
common/jsencrypt.min.js
vendored
Normal file
1
common/jsencrypt.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
48
common/utils.js
Normal file
48
common/utils.js
Normal file
@@ -0,0 +1,48 @@
|
||||
import httpConfig from "@/common/http/config"
|
||||
export default {
|
||||
//时间格式化
|
||||
formatDate (formats, timestamp) {
|
||||
var formats = formats || 'Y.M.D';
|
||||
var myDate = timestamp ? new Date(timestamp) : new Date();
|
||||
var year = myDate.getFullYear();
|
||||
var month = formatDigit(myDate.getMonth() + 1);
|
||||
var day = formatDigit(myDate.getDate());
|
||||
var hour = formatDigit(myDate.getHours());
|
||||
var minute = formatDigit(myDate.getMinutes());
|
||||
var second = formatDigit(myDate.getSeconds());
|
||||
return formats.replace(/Y|M|D|h|m|s/g, function(matches) {
|
||||
return ({
|
||||
Y: year,
|
||||
M: month,
|
||||
D: day,
|
||||
h: hour,
|
||||
m: minute,
|
||||
s: second
|
||||
})[matches];
|
||||
});
|
||||
// 小于10补0
|
||||
function formatDigit (n) {
|
||||
return n.toString().replace(/^(\d)$/, '0$1');
|
||||
}
|
||||
},
|
||||
// 标准日期转换年月日
|
||||
transformTimestamp(timestamp){
|
||||
let a = new Date(timestamp).getTime();
|
||||
const date = new Date(a);
|
||||
const Y = date.getFullYear() + '年';
|
||||
const M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '月';
|
||||
const D = (date.getDate() < 10 ? '0'+date.getDate() : date.getDate()) + '日';
|
||||
const dateString = Y + M + D;
|
||||
return dateString;
|
||||
},
|
||||
// 截取年月日
|
||||
splitDate (str) {
|
||||
let newstr = str.substr(0, 10);
|
||||
let arr = newstr.split('-');
|
||||
return arr[0] + '年' + arr[1] + '月' + arr[2] + '日';
|
||||
},
|
||||
// 图片地址拼接
|
||||
getJointImg(image) {
|
||||
return image ? (httpConfig.url + image) : ''
|
||||
},
|
||||
}
|
Reference in New Issue
Block a user