请求处理代理
商品管理 商品分类 用户管理 桌台 代客下单 进销存 交班 预定座位 充值管理 存酒管理
This commit is contained in:
54
jeepay-ui-uapp-merchant/commons/utils/format.js
Normal file
54
jeepay-ui-uapp-merchant/commons/utils/format.js
Normal file
@@ -0,0 +1,54 @@
|
||||
/**
|
||||
* 格式化价格函数,将价格限定在指定的最小值和最大值范围内,并保留两位小数。
|
||||
*
|
||||
* @param {number} price - 需要格式化的价格。
|
||||
* @param {number} min - 价格的最小值。
|
||||
* @param {number} max - 价格的最大值,默认为100000000。
|
||||
* @param {Boolean} returnIsArea - 是否返回值符合范围区间,默认为false。
|
||||
* @returns {number} - 返回格式化后的价格,如果超出范围则返回最小值或最大值。
|
||||
*/
|
||||
export const formatPrice = (price,min=-Infinity, max = 100000000,returnIsArea=false ) => {
|
||||
if(price === undefined || price === null||price===''){
|
||||
return 0
|
||||
}
|
||||
// 将价格转换为浮点数并保留两位小数
|
||||
const newval = parseFloat((Math.floor(price * 100) / 100).toFixed(2))
|
||||
// 如果价格大于最大值,返回最大值
|
||||
if (newval > max) {
|
||||
return returnIsArea?{value:max,error:true}:max
|
||||
}
|
||||
// 如果价格小于最小值,返回最小值
|
||||
if (newval < min) {
|
||||
return returnIsArea?{value:min,error:true}:min
|
||||
}
|
||||
// 如果价格小于最小值,返回最小值
|
||||
if (newval < min) {
|
||||
return min
|
||||
}
|
||||
// 返回格式化后的价格
|
||||
return newval
|
||||
}
|
||||
export function returnReverseVal(val, isReturnString = true) {
|
||||
const isBol = typeof val === "boolean";
|
||||
const isString = typeof val === "string";
|
||||
let reverseNewval = "";
|
||||
if (isBol) {
|
||||
reverseNewval = !val;
|
||||
}
|
||||
if (isString) {
|
||||
reverseNewval = val === "true" ? "false" : "true";
|
||||
}
|
||||
return reverseNewval;
|
||||
}
|
||||
export function returnBoolean(val) {
|
||||
const isBol = typeof val === "boolean";
|
||||
const isString = typeof val === "string";
|
||||
let newval = "";
|
||||
if (isBol) {
|
||||
newval = val;
|
||||
}
|
||||
if (isString) {
|
||||
newval = val === "true" ? true : false;
|
||||
}
|
||||
return newval;
|
||||
}
|
||||
32
jeepay-ui-uapp-merchant/commons/utils/getDateArea.js
Normal file
32
jeepay-ui-uapp-merchant/commons/utils/getDateArea.js
Normal file
@@ -0,0 +1,32 @@
|
||||
function getDayArea(date = new Date(), type) {
|
||||
const now = date
|
||||
if (type === 'start') {
|
||||
const startOfDay = new Date(now.getFullYear(), now.getMonth(), now.getDate());
|
||||
return startOfDay
|
||||
}
|
||||
if (type === 'end') {
|
||||
const endOfDay = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 23, 59, 59, 999);
|
||||
return endOfDay;
|
||||
}
|
||||
return `${startOfDay}-${endOfDay}`
|
||||
}
|
||||
function getMonthArea(date = new Date(), type) {
|
||||
let now = date
|
||||
let currentMonthStart = new Date(now.getFullYear(), now.getMonth(), 1);
|
||||
let currentMonthEnd = new Date(now.getFullYear(), now.getMonth() + 1, 0 , 23, 59, 59, 999);
|
||||
if (type === 'start') {
|
||||
return currentMonthStart
|
||||
}
|
||||
if (type === 'end') {
|
||||
return currentMonthEnd;
|
||||
}
|
||||
return {
|
||||
start: currentMonthStart,
|
||||
end: currentMonthEnd
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
export default {
|
||||
getDayArea, getMonthArea
|
||||
}
|
||||
13
jeepay-ui-uapp-merchant/commons/utils/getQueryString.js
Normal file
13
jeepay-ui-uapp-merchant/commons/utils/getQueryString.js
Normal file
@@ -0,0 +1,13 @@
|
||||
/**
|
||||
* 获取url链接参数
|
||||
* @param {Object} url
|
||||
* @param {Object} name
|
||||
*/
|
||||
export function getQueryString(url, name) {
|
||||
var reg = new RegExp('(^|&|/?)' + name + '=([^&|/?]*)(&|/?|$)', 'i')
|
||||
var r = url.substr(1).match(reg)
|
||||
if (r != null) {
|
||||
return r[2]
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -71,9 +71,7 @@ const model = {
|
||||
if(pagesIdOrUrl.indexOf('PAGES_') == 0){
|
||||
pagesIdOrUrl = ALL_PAGES[pagesIdOrUrl]
|
||||
}
|
||||
|
||||
pagesIdOrUrl += model.object2param(params)
|
||||
|
||||
if(type == model.GO_TYPE_TO){
|
||||
uni.navigateTo(Object.assign({ url: pagesIdOrUrl }, extObject))
|
||||
}
|
||||
|
||||
6
jeepay-ui-uapp-merchant/commons/utils/returrn-data.js
Normal file
6
jeepay-ui-uapp-merchant/commons/utils/returrn-data.js
Normal file
@@ -0,0 +1,6 @@
|
||||
export const objToArrary = (obj) => {
|
||||
return Object.entries(obj).map(([key, value]) => ({
|
||||
key,
|
||||
...value,
|
||||
}))
|
||||
}
|
||||
@@ -52,6 +52,27 @@ const model = {
|
||||
return appCache.tokenVal
|
||||
}
|
||||
},
|
||||
// 获取和放置shopId
|
||||
shopId: (val, isDelete = false) => {
|
||||
if (isDelete) {
|
||||
appCache.shopId = ""
|
||||
return uni.removeStorageSync('shopId')
|
||||
}
|
||||
|
||||
if (val) {
|
||||
// 有值,为放置
|
||||
appCache.shopId = val
|
||||
uni.setStorageSync('shopId', val)
|
||||
} else {
|
||||
// 否则为获取
|
||||
|
||||
if (!appCache.shopId) {
|
||||
//缓存取不到,获取应用本地信息
|
||||
appCache.shopId = uni.getStorageSync('shopId')
|
||||
}
|
||||
return appCache.shopId
|
||||
}
|
||||
},
|
||||
|
||||
// 已经登录的用户记录
|
||||
loggedInUser: (addUserName = null, removeUserName = null) => {
|
||||
|
||||
14
jeepay-ui-uapp-merchant/commons/utils/useStroage.js
Normal file
14
jeepay-ui-uapp-merchant/commons/utils/useStroage.js
Normal file
@@ -0,0 +1,14 @@
|
||||
export default {
|
||||
get(key) {
|
||||
return uni.getStorageSync(key)
|
||||
},
|
||||
set(key, value) {
|
||||
uni.setStorageSync(key, value)
|
||||
},
|
||||
del(key) {
|
||||
uni.removeStorageSync(key)
|
||||
},
|
||||
clear() {
|
||||
uni.clearStorageSync()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user