计算购物车钱之前

This commit is contained in:
wwz
2025-02-26 17:39:46 +08:00
parent f2513ef13a
commit 0ab9235f6c
33 changed files with 4225 additions and 903 deletions

View File

@@ -2,28 +2,29 @@ const debug = process.env.NODE_ENV == 'development' ? true : false;
// #ifdef H5
const proxyApi = "/api"
// #endif
// #ifdef MP-WEIXIN || APP || MP-ALIPAY
// const proxyApi = 'http://192.168.1.15:9888/cashierService' // 王伟
// const proxyApi = 'http://192.168.1.27:9888/cashierService' // 帆哥
// const proxyApiwws = 'ws://192.168.1.15:9888/netty' // 测试
// const proxyApi = 'https://wxcashiertest.sxczgkj.cn/cashierService' // 测试
// const proxyApiwws = 'wss://wxcashiertest.sxczgkj.cn/netty' // 测试
// const proxyApi = 'https://pre-cashier.sxczgkj.cn/cashierService' // 预发布
// const proxyApiwws = 'wss://pre-cashier.sxczgkj.cn/netty' // 预发布
const proxyApi = 'https://cashier.sxczgkj.cn/cashierService' // 线上
const proxyApiwws = 'wss://cashier.sxczgkj.cn/netty' // 线上
const proxyApi = 'https://tapi.cashier.sxczgkj.cn' // 调试地址
const proxyApiwws = 'wss://sockets.sxczgkj.com/wss' // 调试地址
// #endif
// #ifdef H5
const baseUrl = debug ? proxyApi + '/cashierService' : "https://cashier.sxczgkj.cn/cashierService"
const baseUrlwws = 'ws://cashier.sxczgkj.cn/cashierService'
const baseUrl = debug ? proxyApi : "https://tapi.cashier.sxczgkj.cn"
const baseUrlwws = 'wss://sockets.sxczgkj.com/wss'
// #endif
// #ifdef APP || MP-WEIXIN || MP-ALIPAY
const baseUrl = debug ? proxyApi : 'https://cashier.sxczgkj.cn/cashierService' // 线上
const baseUrlwws = debug ? proxyApiwws : 'wss://cashier.sxczgkj.cn/netty' // 线上
// const baseUrl = 'https://wxcashiertest.sxczgkj.cn/cashierService' // 测试
// const baseUrlwws = 'wss://wxcashiertest.sxczgkj.cn/netty' // 测试
const baseUrl = debug ? proxyApi : 'https://tapi.cashier.sxczgkj.cn' // 线上
const baseUrlwws = debug ? proxyApiwws : 'wss://sockets.sxczgkj.com/wss' // 线上
// #endif
// import VConsole from "./vConsole.js"

View File

@@ -5,39 +5,24 @@
* @return {String} 缓存值
*/
function get(key) {
try {
let res = uni.getStorageSync(key)
try {
let res = uni.getStorageSync(key)
if (!res) {
return ''
}
// res = JSON.parse(res)
if (!res) {
return ''
}
if (res.__expiretime && res.__expiretime < uni.utils.timestamp()) {
// res = JSON.parse(res)
if (res.__expiretime && res.__expiretime < uni.utils.timestamp()) {
remove(key)
return ''
} else {
try {
const parsed = JSON.parse(res);
C
} catch (e) {
return res
}
// // #ifdef H5
// try {
// const parsed = JSON.parse(res);
// return typeof parsed === 'object' && parsed !== null && !Array.isArray(parsed) ? parsed : ''
// } catch (e) {
// return res
// }
// // #endif
// // #ifndef H5
// return res
// // #endif
}
} catch (e) {
return ''
}
return ''
} else {
return res
}
} catch (e) {
return ''
}
}
@@ -48,19 +33,19 @@ function get(key) {
* @return {String} 缓存值
*/
function getStorageData(key) {
try {
let res = uni.getStorageSync(key);
try {
let res = uni.getStorageSync(key);
if (!res) {
return ''
}
if (!res) {
return ''
}
res = JSON.parse(res)
res = JSON.parse(res)
return res.data
} catch (e) {
return ''
}
return res.data
} catch (e) {
return ''
}
}
/**
@@ -72,20 +57,14 @@ function getStorageData(key) {
* @return void
*/
function set(key, value, expire = uni.conf.default_expire) {
let cacheItem = {}
cacheItem = value
let cacheItem = {}
cacheItem = value
// console.log(cacheItem)
// if (expire > 0) {
// cacheItem.__expiretime = uni.utils.timestamp() + expire
// }
// // #ifdef H5
// uni.setStorageSync(key, JSON.stringify(cacheItem))
// // #endif
// // #ifndef H5
// uni.setStorageSync(key, cacheItem)
// // #endif
uni.setStorageSync(key, JSON.stringify(cacheItem))
// uni.setStorageSync(key, cacheItem)
if (expire > 0) {
cacheItem.__expiretime = uni.utils.timestamp() + expire
}
// uni.setStorageSync(key,JSON.stringify(cacheItem))
uni.setStorageSync(key,cacheItem)
}
/**
@@ -97,14 +76,14 @@ function set(key, value, expire = uni.conf.default_expire) {
* @return {Promise} Promise对象
*/
async function remember(key, callback, expire = uni.conf.default_expire) {
let ret = this.get(key)
if (ret) {
return ret
} else {
ret = await callback()
set(key, ret, expire)
return ret
}
let ret = this.get(key)
if (ret) {
return ret
} else {
ret = await callback()
set(key, ret, expire)
return ret
}
}
/**
@@ -114,7 +93,7 @@ async function remember(key, callback, expire = uni.conf.default_expire) {
* @return {void}
*/
function remove(key) {
uni.removeStorageSync(key)
uni.removeStorageSync(key)
}
/**
@@ -124,22 +103,22 @@ function remove(key) {
* @return void
*/
function removeList(prefix) {
let keys = uni.getStorageInfoSync().keys
if (keys && keys.length > 0) {
keys.forEach(key => {
if (key.indexOf(prefix) === 0) {
uni.removeStorageSync(key)
}
})
}
let keys = uni.getStorageInfoSync().keys
if (keys && keys.length > 0) {
keys.forEach(key => {
if (key.indexOf(prefix) === 0) {
uni.removeStorageSync(key)
}
})
}
}
function _randomRemove() {
const info = uni.getStorageInfoSync()
if (info.currentSize > 0.7 * info.limitSize ||
info.keys.length > uni.conf.autoRemoveCache.count ||
info.currentSize > uni.conf.autoRemoveCache.size) {
for (let i = 0; i < 100; i++) {
if (info.currentSize > 0.7 * info.limitSize
|| info.keys.length > uni.conf.autoRemoveCache.count
|| info.currentSize > uni.conf.autoRemoveCache.size) {
for (let i = 0; i < 100; i++) {
if (info.keys.length < 1) {
return
}
@@ -152,9 +131,9 @@ function _randomRemove() {
function _removeExpired(key) {
let res = uni.getStorageSync(key);
if (!res) {
return
return
}
res = JSON.parse(res)
if (res.__expiretime && res.__expiretime < uni.utils.timestamp()) {
remove(key)
@@ -163,13 +142,13 @@ function _removeExpired(key) {
function _autoRemoveExpired() {
const info = uni.getStorageInfoSync()
if (info.currentSize > 0.7 * info.limitSize ||
info.keys.length > uni.conf.autoRemoveCache.count ||
info.currentSize > uni.conf.autoRemoveCache.size) {
if (info.currentSize > 0.7 * info.limitSize
|| info.keys.length > uni.conf.autoRemoveCache.count
|| info.currentSize > uni.conf.autoRemoveCache.size) {
if (info.keys && info.keys.length > 0) {
info.keys.forEach(key => {
_removeExpired(key)
})
info.keys.forEach(key => {
_removeExpired(key)
})
}
}
}
@@ -179,7 +158,7 @@ function autoRemove(is_once = true) {
if (info.currentSize > 0.9 * info.limitSize) {
clearMemory()
}
if (is_once) {
_autoRemoveExpired()
} else {
@@ -190,13 +169,13 @@ function autoRemove(is_once = true) {
function clearFetch(url) {
const prefixCacheKey = 'memory:fetch:' + url
removeList(prefixCacheKey)
const prefixCacheKey = 'memory:fetch:' + url
removeList(prefixCacheKey)
}
function clearMemory() {
const prefixCacheKey = 'memory:'
removeList(prefixCacheKey)
const prefixCacheKey = 'memory:'
removeList(prefixCacheKey)
}
/**
@@ -205,22 +184,22 @@ function clearMemory() {
* @return void
*/
function clear() {
uni.clearStorageSync()
uni.clearStorageSync()
}
function getInfo() {
return uni.getStorageInfoSync()
return uni.getStorageInfoSync()
}
uni.cache = {
get,
getStorageData,
set,
remove,
remember,
clearFetch,
clearMemory,
clear,
getInfo,
get,
getStorageData,
set,
remove,
remember,
clearFetch,
clearMemory,
clear,
getInfo,
autoRemove,
}