|
|
|
@ -2,35 +2,57 @@
|
|
|
|
|
/**
|
|
|
|
|
* 操作用户token
|
|
|
|
|
*/
|
|
|
|
|
import CONFIG from '@/config'
|
|
|
|
|
import CryptoJS from './crypto-js.min.js'
|
|
|
|
|
const tName = 'ht-h5_1_test'
|
|
|
|
|
const isScrect = CONFIG.isPro
|
|
|
|
|
const Screct = {
|
|
|
|
|
getData(key) {
|
|
|
|
|
const text = uni.getStorageSync(key)
|
|
|
|
|
if (text) {
|
|
|
|
|
if (isScrect) {
|
|
|
|
|
const localJosn = CryptoJS.AES.decrypt(text, key).toString(CryptoJS.enc.Utf8);
|
|
|
|
|
return JSON.parse(localJosn).val
|
|
|
|
|
}
|
|
|
|
|
return text
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
return null
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
setData(key, val) {
|
|
|
|
|
let v = val
|
|
|
|
|
if (isScrect) {
|
|
|
|
|
const info = {
|
|
|
|
|
val,
|
|
|
|
|
ts: tName
|
|
|
|
|
}
|
|
|
|
|
v = CryptoJS.AES.encrypt(JSON.stringify(info), key).toString()
|
|
|
|
|
}
|
|
|
|
|
uni.setStorageSync(key, v)
|
|
|
|
|
return v
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function setToken(value) {
|
|
|
|
|
uni.setStorageSync('token', value);
|
|
|
|
|
console.log('存储用户信息成功');
|
|
|
|
|
return Screct.setData('token', value)
|
|
|
|
|
}
|
|
|
|
|
export function getToken() {
|
|
|
|
|
let token = uni.getStorageSync('token');
|
|
|
|
|
return token;
|
|
|
|
|
return Screct.getData('token')
|
|
|
|
|
}
|
|
|
|
|
export function removeToken() {
|
|
|
|
|
uni.removeStorageSync('token');
|
|
|
|
|
uni.removeStorageSync('token');
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* 操作用户信息
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
export function setUserInfo(value) {
|
|
|
|
|
try {
|
|
|
|
|
let newValue = JSON.stringify(value);
|
|
|
|
|
uni.setStorageSync('userinfo', newValue);
|
|
|
|
|
console.log('存储用户信息成功');
|
|
|
|
|
} catch (e) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
console.log('存储用户信息成功');
|
|
|
|
|
return Screct.setData('userinfo', value)
|
|
|
|
|
}
|
|
|
|
|
export function getUserInfo() {
|
|
|
|
|
let userinfo = uni.getStorageSync('userinfo');
|
|
|
|
|
if (userinfo) {
|
|
|
|
|
return JSON.parse(userinfo);
|
|
|
|
|
}
|
|
|
|
|
return Screct.getData('userinfo')
|
|
|
|
|
}
|
|
|
|
|
export function removeUserInfo(){
|
|
|
|
|
uni.removeStorageSync('userinfo');
|
|
|
|
@ -81,63 +103,39 @@ export function setGoodsHistory(item) {
|
|
|
|
|
if (!hasGoods) {
|
|
|
|
|
goodsdata = goodsLength >= 20 ? goodsdata.slice(0, goodsLength - 1) : goodsdata
|
|
|
|
|
goodsdata.unshift(item)
|
|
|
|
|
const newValue = JSON.stringify(goodsdata);
|
|
|
|
|
uni.setStorageSync('goodsHistory', newValue);
|
|
|
|
|
console.log('新增浏览历史');
|
|
|
|
|
return Screct.setData('goodsHistory', goodsdata)
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
const newValue = JSON.stringify([item]);
|
|
|
|
|
uni.setStorageSync('goodsHistory', newValue);
|
|
|
|
|
console.log('新增浏览历史');
|
|
|
|
|
const newValue = [item];
|
|
|
|
|
return Screct.setData('goodsHistory', newValue)
|
|
|
|
|
}
|
|
|
|
|
} catch (e) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
export function getGoodsHistory(value) {
|
|
|
|
|
let goodsdata = uni.getStorageSync('goodsHistory');
|
|
|
|
|
if (goodsdata) {
|
|
|
|
|
return JSON.parse(goodsdata);
|
|
|
|
|
}
|
|
|
|
|
return []
|
|
|
|
|
return Screct.getData('goodsHistory') || []
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* 存储商品信息
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
export function setGoodsData(value) {
|
|
|
|
|
try {
|
|
|
|
|
let newValue = JSON.stringify(value);
|
|
|
|
|
uni.setStorageSync('goodsdata', newValue);
|
|
|
|
|
console.log('存储商品信息成功');
|
|
|
|
|
} catch (e) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
return Screct.setData('goodsdata', value)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function getGoodsData() {
|
|
|
|
|
let goodsdata = uni.getStorageSync('goodsdata');
|
|
|
|
|
|
|
|
|
|
if (goodsdata) {
|
|
|
|
|
return JSON.parse(goodsdata);
|
|
|
|
|
}
|
|
|
|
|
return Screct.getData('goodsdata')
|
|
|
|
|
}
|
|
|
|
|
// 存储用户地址
|
|
|
|
|
export function setAddress(value) {
|
|
|
|
|
try {
|
|
|
|
|
let newValue = JSON.stringify(value);
|
|
|
|
|
uni.setStorageSync('address', newValue);
|
|
|
|
|
console.log('存储地址信息成功', newValue);
|
|
|
|
|
} catch (e) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
return Screct.setData('address', value)
|
|
|
|
|
}
|
|
|
|
|
export function getAddress() {
|
|
|
|
|
let address = uni.getStorageSync('address');
|
|
|
|
|
|
|
|
|
|
if (address) {
|
|
|
|
|
return JSON.parse(address);
|
|
|
|
|
}
|
|
|
|
|
return Screct.getData('address')
|
|
|
|
|
}
|
|
|
|
|
export function removeAddress() {
|
|
|
|
|
uni.removeStorageSync('address');
|
|
|
|
@ -171,38 +169,29 @@ export function getlocation() { //获取位置信息
|
|
|
|
|
}
|
|
|
|
|
export function setCart(value){ //模拟存储购物车数据
|
|
|
|
|
try {
|
|
|
|
|
let data = getCart() || []
|
|
|
|
|
const data = getCart() || []
|
|
|
|
|
data.push(value)
|
|
|
|
|
let newValue = JSON.stringify(data);
|
|
|
|
|
uni.setStorageSync('cart', newValue);
|
|
|
|
|
// console.log('存储购物车数据成功', newValue);
|
|
|
|
|
return Screct.setData('cart', data)
|
|
|
|
|
} catch (e) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 有问题 只是一个获取cart而已 当一个商品多个数量时 有问题进行修改 yang
|
|
|
|
|
export function getCart() { //模拟获取购物车数据
|
|
|
|
|
let cart = uni.getStorageSync('cart');
|
|
|
|
|
if (cart) {
|
|
|
|
|
return JSON.parse(cart);
|
|
|
|
|
}
|
|
|
|
|
return []
|
|
|
|
|
return Screct.getData('cart') || []
|
|
|
|
|
}
|
|
|
|
|
// 获取购物车数量 yang
|
|
|
|
|
export function getCartNumber() {
|
|
|
|
|
if(uni.getStorageSync('cart')){
|
|
|
|
|
let cart = JSON.parse(uni.getStorageSync('cart'));
|
|
|
|
|
|
|
|
|
|
if (cart) {
|
|
|
|
|
var num = 0;
|
|
|
|
|
for(var i=0;i<cart.length;i++){
|
|
|
|
|
|
|
|
|
|
// console.log(cart[i])
|
|
|
|
|
num = cart[i].number +num
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
return num;
|
|
|
|
|
const cart = getCart()
|
|
|
|
|
if(cart.length > 0){
|
|
|
|
|
var num = 0;
|
|
|
|
|
for(var i=0;i<cart.length;i++){
|
|
|
|
|
|
|
|
|
|
// console.log(cart[i])
|
|
|
|
|
num = cart[i].number +num
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
return num;
|
|
|
|
|
}else{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
@ -213,8 +202,7 @@ export function removeCart() { //模拟删除购物车数据
|
|
|
|
|
}
|
|
|
|
|
// 重置购物车数据 yang
|
|
|
|
|
export function resetCart(cart) { //
|
|
|
|
|
let newValue = JSON.stringify(cart)
|
|
|
|
|
uni.setStorageSync('cart',newValue);
|
|
|
|
|
return Screct.setData('cart', cart)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function setPickaddress(value){ //存储收件地址
|
|
|
|
@ -257,35 +245,27 @@ export function removeToaddress() { //删除取件地址
|
|
|
|
|
|
|
|
|
|
export function setSalesGoods(value) {
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
|
|
let newValue = JSON.stringify(value);
|
|
|
|
|
uni.setStorageSync('SalesGoods', newValue);
|
|
|
|
|
return Screct.setData('SalesGoods', value)
|
|
|
|
|
|
|
|
|
|
} catch (e) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
export function getSalesGoods() {
|
|
|
|
|
let GoodsDetails = uni.getStorageSync('SalesGoods');
|
|
|
|
|
|
|
|
|
|
if (GoodsDetails) {
|
|
|
|
|
return JSON.parse(GoodsDetails);
|
|
|
|
|
}
|
|
|
|
|
return Screct.getData('SalesGoods')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function setSalesGoodsItem(value) {
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
|
|
let newValue = JSON.stringify(value);
|
|
|
|
|
uni.setStorageSync('SalesGoodsItem', newValue);
|
|
|
|
|
return Screct.setData('SalesGoodsItem', value)
|
|
|
|
|
|
|
|
|
|
} catch (e) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
export function getSalesGoodsItem() {
|
|
|
|
|
let GoodsDetails = uni.getStorageSync('SalesGoodsItem');
|
|
|
|
|
if (GoodsDetails) {
|
|
|
|
|
return JSON.parse(GoodsDetails);
|
|
|
|
|
}
|
|
|
|
|
return Screct.getData('SalesGoodsItem')
|
|
|
|
|
}
|
|
|
|
|
export function rmSalesGoodsItem() {
|
|
|
|
|
uni.removeStorageSync('SalesGoodsItem')
|
|
|
|
@ -296,20 +276,16 @@ export function rmSalesGoodsItem() {
|
|
|
|
|
// 由于无法调取接口 点击商品进入详情只能把数据暂存在缓存内 然后详情页获取该数据渲染
|
|
|
|
|
export function setGoodsDetails(value) {
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
|
|
let newValue = JSON.stringify(value);
|
|
|
|
|
uni.setStorageSync('GoodsDetails', newValue);
|
|
|
|
|
console.log('存储商品信息成功');
|
|
|
|
|
console.log('存储商品信息成功');
|
|
|
|
|
return Screct.setData('GoodsDetails', value)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} catch (e) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
export function getGoodsDetails() {
|
|
|
|
|
let GoodsDetails = uni.getStorageSync('GoodsDetails');
|
|
|
|
|
|
|
|
|
|
if (GoodsDetails) {
|
|
|
|
|
return JSON.parse(GoodsDetails);
|
|
|
|
|
}
|
|
|
|
|
return Screct.getData('GoodsDetails')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|