[fix]本地数据加密

main
huyuanxiang 2 years ago
parent af3e8b68a1
commit 17f2b5dfeb

@ -154,7 +154,11 @@ $black: #333333;
color: #fff; color: #fff;
background-color: $color; background-color: $color;
} }
&.item1 {
color: $color;
border: 1upx solid $color;
background: transparent;
}
} }
.iconfont, .iconfont,
.weizhi_icon .icon-dizhi, .weizhi_icon .icon-dizhi,
@ -230,6 +234,11 @@ $black: #333333;
color: $color; color: $color;
} }
} }
&.mycollection {
.iconfont {
color: $color;
}
}
} }

@ -1,3 +1,6 @@
const isPro = true
export default { export default {
imgUrl: 'http://47.100.35.222:8080/jeecg-boot/sys/common/static/' imgUrl: 'http://47.100.35.222:8080/jeecg-boot/sys/common/static/',
apiUrl: isPro ? 'http://47.100.35.222:8080/jeecg-boot' : 'http://47.100.35.222:8080/jeecg-boot',
isPro
} }

@ -137,8 +137,7 @@
<view class="moneys"> <view class="moneys">
合计: <text >{{goods.totalAmount}}</text> 合计: <text >{{goods.totalAmount}}</text>
</view> </view>
<view class="btns" <view class="btns item1"
:style="'color:' + colors + ';border:1upx solid ' + colors + ';margin-right:20upx'"
@tap="changeOrderStatus(goods.state, 'cancel')"> @tap="changeOrderStatus(goods.state, 'cancel')">
取消订单 取消订单
</view> </view>

@ -1,7 +1,7 @@
<template> <template>
<!-- 我的足迹 --> <!-- 我的足迹 -->
<view> <view>
<view class="mycollection"> <view class="mycollection" :class="['theme', themeObj.name]">
<view class="cart_box"> <view class="cart_box">
<view v-for="(item, index) in dataList" :key="index" class="cart_list"> <view v-for="(item, index) in dataList" :key="index" class="cart_list">
<view class="cover" @tap="jumpDetails(item,index)" > <view class="cover" @tap="jumpDetails(item,index)" >
@ -43,6 +43,7 @@
data() { data() {
return { return {
colors: '', colors: '',
themeObj: app.globalData.themeObj,
dataList: getGoodsHistory(), dataList: getGoodsHistory(),
isShow: true isShow: true
}; };

@ -2,13 +2,43 @@
/** /**
* 操作用户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');
@ -18,19 +48,11 @@ export function removeToken() {
*/ */
export function setUserInfo(value) { export function setUserInfo(value) {
try {
let newValue = JSON.stringify(value);
uni.setStorageSync('userinfo', newValue);
console.log('存储用户信息成功'); console.log('存储用户信息成功');
} catch (e) { return Screct.setData('userinfo', value)
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,29 +169,21 @@ 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){
if (cart) {
var num = 0; var num = 0;
for(var i=0;i<cart.length;i++){ for(var i=0;i<cart.length;i++){
@ -202,7 +192,6 @@ export function getCartNumber() {
} }
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 {
let newValue = JSON.stringify(value);
uni.setStorageSync('GoodsDetails', newValue);
console.log('存储商品信息成功'); console.log('存储商品信息成功');
return Screct.setData('GoodsDetails', value)
} 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);
}
} }

File diff suppressed because one or more lines are too long

@ -5,8 +5,9 @@
* .then(res=>{console.log(res)}) * .then(res=>{console.log(res)})
*/ */
import { getToken, removeToken } from "./auth"; import { getToken, removeToken } from "./auth";
export const baseUrl = 'http://47.100.35.222:8080/jeecg-boot'; import CONFIG from '@/config'
export const baseUrl = CONFIG.apiUrl
const whitePath = ['/pages/login/index1']
async function request(mehtod, params, type = 'GET') { async function request(mehtod, params, type = 'GET') {
//创建一个名为request请求的方法函数 //创建一个名为request请求的方法函数
const token = getToken() const token = getToken()

Loading…
Cancel
Save