Commit 97b1dcb1 by 张立顺

修复storage bug

1 parent 1bfd8d22
<!-- pages/tab/output/components/merchant/mrechant.wxml -->
<!-- <text>pages/tab/output/components/merchant/mrechant.wxml</text> -->
<text>商户产值</text>
<!-- -->
<!-- 无门店 -->
<view>
<!-- <img src="" alt=""> -->
......
// pages/tab/output/output.js
import { getSessionId, setSessionId } from '~/utils/cache/storageApi'
Page({
/**
* 页面的初始数据
......@@ -26,7 +27,10 @@ Page({
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {},
onLoad(options) {
setSessionId('xxx')
console.log(getSessionId())
},
/**
* 生命周期函数--监听页面初次渲染完成
......
......@@ -2,7 +2,7 @@
* 微信小程序标准版:统一封装的 storage 操作类
*/
import { DEFAULT_GET_STORAGEKEY, GET_STORAGE_OBJECTkEY } from '~/utils/constantData'
import { DEFAULT_GET_STORAGEKEY, STORAGE_OBJECTkEY } from '~/utils/constantData'
class Storage {
types = {
1: 'get', // get
......@@ -14,7 +14,6 @@ class Storage {
trial: '体验版',
release: '正式版'
}
// getStorageKey = GET_STORAGE_OBJECTkEY
// defaultGetStorageKey = DEFAULT_GET_STORAGEKEY
/** 构造函数 */
constructor() {
......@@ -52,15 +51,16 @@ class Storage {
*/
get = (key, syncFlag = true) => {
// 有值默认取key值
debugger
if (key) {
// 判断值是否是指定的对象值
let tmpKey = this.checkKeyType(key, 1)
let isObjectKey = GET_STORAGE_OBJECTkEY[key]
let isObjectKey = STORAGE_OBJECTkEY[key]
if (isObjectKey) {
return this.getObjectKeyValue(isObjectKey)
} else {
if (syncFlag) {
tmpKey = this.addEvnToKey(tmpKey)
let res = wx.getStorageSync(tmpKey)
if (res) {
return JSON.parse(res)
......
......@@ -16,14 +16,14 @@ export function setUserInfo(data) {
$Storage.set('scrm_shopmall_userInfo', data)
}
export function removeSystemStorage() {
$Storage.rm('srcm_shopmall_user_info')
$Storage.rm('scrm_shopmall_sessionId')
$Storage.rm('guest_no')
$Storage.rm('equity_info')
$Storage.rm('packageList')
$Storage.rm('isVIP')
$Storage.rm('bizjiaUrl')
$Storage.rm('vip_card_info')
// $Storage.rm('srcm_shopmall_user_info')
// $Storage.rm('scrm_shopmall_sessionId')
// $Storage.rm('guest_no')
// $Storage.rm('equity_info')
// $Storage.rm('packageList')
// $Storage.rm('isVIP')
// $Storage.rm('bizjiaUrl')
// $Storage.rm('vip_card_info')
}
export function setStorageSync(key, data) {
$Storage.set(key, JSON.stringify(data))
......
......@@ -4,6 +4,9 @@ export const IMG_URL = 'https://img02.glsx.com.cn/weapp/resource/miniprogram-tes
export const DEFAULT_GET_STORAGEKEY = ['sessionId', 'merchantId', 'userInfo']
// 缓存get方法key的对应才映射值
export const GET_STORAGE_OBJECTkEY = {
super: ['sessionId', 'merchantId', 'userInfo']
export const STORAGE_OBJECTkEY = {
DEFAULT_GET_STORAGEKEY,
sessionId: 'sessionId',
userInfo: 'userInfo',
systemInfo: 'systemInfo'
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!