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