[fix]本地数据加密

main
huyuanxiang 2 years ago
parent af3e8b68a1
commit 17f2b5dfeb

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

@ -1,3 +1,6 @@
const isPro = true
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">
合计: <text >{{goods.totalAmount}}</text>
</view>
<view class="btns"
:style="'color:' + colors + ';border:1upx solid ' + colors + ';margin-right:20upx'"
<view class="btns item1"
@tap="changeOrderStatus(goods.state, 'cancel')">
取消订单
</view>

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

@ -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++){
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
// console.log(cart[i])
num = cart[i].number +num
}
return 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 {
return Screct.setData('SalesGoods', value)
let newValue = JSON.stringify(value);
uni.setStorageSync('SalesGoods', newValue);
} 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 {
console.log('存储商品信息成功');
return Screct.setData('GoodsDetails', value)
let newValue = JSON.stringify(value);
uni.setStorageSync('GoodsDetails', newValue);
console.log('存储商品信息成功');
} catch (e) {
return;
}
}
export function getGoodsDetails() {
let GoodsDetails = uni.getStorageSync('GoodsDetails');
if (GoodsDetails) {
return JSON.parse(GoodsDetails);
}
return Screct.getData('GoodsDetails')
}

File diff suppressed because one or more lines are too long

@ -5,8 +5,9 @@
* .then(res=>{console.log(res)})
*/
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') {
//创建一个名为request请求的方法函数
const token = getToken()

Loading…
Cancel
Save