Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
saas_plus
/
business-assistant
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit cbc1396a
authored
Oct 11, 2022
by
张立顺
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
修改storage配置
1 parent
97b1dcb1
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
32 additions
and
39 deletions
utils/cache/storage.js
utils/cache/storageApi.js
utils/cache/userInfo.js
utils/constantData.js
utils/cache/storage.js
View file @
cbc1396
...
@@ -39,6 +39,7 @@ class Storage {
...
@@ -39,6 +39,7 @@ class Storage {
throw
new
Error
(
`Storage
${
this
.
types
[
type
]}
func: key can not be empty`
)
throw
new
Error
(
`Storage
${
this
.
types
[
type
]}
func: key can not be empty`
)
return
false
return
false
}
}
// if STORAGE_OBJECTkEY[key]
return
tmpKey
return
tmpKey
}
}
return
key
return
key
...
@@ -51,38 +52,17 @@ class Storage {
...
@@ -51,38 +52,17 @@ class Storage {
*/
*/
get
=
(
key
,
syncFlag
=
true
)
=>
{
get
=
(
key
,
syncFlag
=
true
)
=>
{
// 有值默认取key值
// 有值默认取key值
debugger
//
debugger
if
(
key
)
{
if
(
key
)
{
// 判断值是否是指定的对象值
// 判断值是否是指定的对象值
let
tmpKey
=
this
.
checkKeyType
(
key
,
1
)
let
tmpKey
=
this
.
checkKeyType
(
key
,
1
)
let
isObjectKey
=
STORAGE_OBJECTkEY
[
key
]
let
isObjectKey
=
STORAGE_OBJECTkEY
[
tmpKey
]
console
.
log
(
key
)
console
.
log
(
isObjectKey
)
if
(
isObjectKey
)
{
if
(
isObjectKey
)
{
return
this
.
getObjectKeyValue
(
isObjectKey
)
return
this
.
getObjectKeyValue
(
isObjectKey
)
}
else
{
}
else
{
if
(
syncFlag
)
{
throw
new
Error
(
`Storage
${
this
.
types
[
1
]}
func: key must be register`
)
tmpKey
=
this
.
addEvnToKey
(
tmpKey
)
let
res
=
wx
.
getStorageSync
(
tmpKey
)
if
(
res
)
{
return
JSON
.
parse
(
res
)
}
else
{
// reject(errMsg)
return
''
}
}
else
{
return
new
Promise
((
resolve
,
reject
)
=>
{
wx
.
getStorage
({
key
:
tmpKey
,
success
:
res
=>
{
resolve
(
JSON
.
parse
(
res
.
data
))
},
fail
:
err
=>
{
// console.log(err)
// reject(errMsg)
resolve
(
''
)
}
})
})
}
}
}
}
else
{
}
else
{
return
this
.
getObjectKeyValue
(
DEFAULT_GET_STORAGEKEY
)
return
this
.
getObjectKeyValue
(
DEFAULT_GET_STORAGEKEY
)
...
@@ -93,15 +73,27 @@ class Storage {
...
@@ -93,15 +73,27 @@ class Storage {
*
*
* @param {*} 空key返回默认定义数组的值
* @param {*} 空key返回默认定义数组的值
*/
*/
getObjectKeyValue
(
ObjectList
)
{
getObjectKeyValue
(
key
)
{
// ObjectList
if
(
typeof
key
==
'string'
)
{
key
=
this
.
addEvnToKey
(
key
)
let
res
=
wx
.
getStorageSync
(
key
)
if
(
res
)
{
return
JSON
.
parse
(
res
)
}
else
{
// reject(errMsg)
return
''
}
}
else
{
let
Obj
=
{}
let
Obj
=
{}
ObjectList
.
forEach
(
key
=>
{
key
.
forEach
(
key
=>
{
let
defaultKey
=
this
.
addEvnToKey
(
key
)
let
defaultKey
=
this
.
addEvnToKey
(
key
)
let
res
=
wx
.
getStorageSync
(
defaultKey
)
let
res
=
wx
.
getStorageSync
(
defaultKey
)
Obj
[
key
]
=
res
?
JSON
.
parse
(
res
)
:
''
Obj
[
key
]
=
res
?
JSON
.
parse
(
res
)
:
''
})
})
return
Obj
return
Obj
}
}
}
/**
/**
*
*
* @param {*} key | 要操作的键值
* @param {*} key | 要操作的键值
...
...
utils/cache/storageApi.js
View file @
cbc1396
...
@@ -4,16 +4,16 @@ const $Storage = new Storage()
...
@@ -4,16 +4,16 @@ const $Storage = new Storage()
// console.log($Storage)
// console.log($Storage)
/** */
/** */
export
function
getSessionId
()
{
export
function
getSessionId
()
{
return
$Storage
.
get
(
's
crm_shopmall_s
essionId'
)
return
$Storage
.
get
(
'sessionId'
)
}
}
export
function
setSessionId
(
sessionId
)
{
export
function
setSessionId
(
sessionId
)
{
$Storage
.
set
(
's
crm_shopmall_s
essionId'
,
sessionId
)
$Storage
.
set
(
'sessionId'
,
sessionId
)
}
}
export
function
getUserInfo
()
{
export
function
getUserInfo
()
{
return
$Storage
.
get
(
'
scrm_shopmall_
userInfo'
)
return
$Storage
.
get
(
'userInfo'
)
}
}
export
function
setUserInfo
(
data
)
{
export
function
setUserInfo
(
data
)
{
$Storage
.
set
(
'
scrm_shopmall_
userInfo'
,
data
)
$Storage
.
set
(
'userInfo'
,
data
)
}
}
export
function
removeSystemStorage
()
{
export
function
removeSystemStorage
()
{
// $Storage.rm('srcm_shopmall_user_info')
// $Storage.rm('srcm_shopmall_user_info')
...
@@ -35,22 +35,22 @@ export function getStorageSync(key) {
...
@@ -35,22 +35,22 @@ export function getStorageSync(key) {
/**设置标题栏 */
/**设置标题栏 */
export
function
setNavigationBarTitleText
(
title
)
{
export
function
setNavigationBarTitleText
(
title
)
{
$Storage
.
set
(
'
dj_shopmall_
app_title'
,
title
)
$Storage
.
set
(
'app_title'
,
title
)
}
}
/**获取app标题 */
/**获取app标题 */
export
function
getNavigationBarTitleText
()
{
export
function
getNavigationBarTitleText
()
{
return
$Storage
.
get
(
'
dj_shopmall_
app_title'
)
return
$Storage
.
get
(
'app_title'
)
}
}
/** 存储设备信息 */
/** 存储设备信息 */
export
function
setSystem_info
(
that
)
{
export
function
setSystem_info
(
that
)
{
let
info
=
$Storage
.
get
(
's
rcm_shopmall_s
ystem_info'
)
let
info
=
$Storage
.
get
(
'system_info'
)
!
info
&&
!
info
&&
wx
.
getSystemInfo
({
wx
.
getSystemInfo
({
success
(
res
)
{
success
(
res
)
{
// console.log(res)
// console.log(res)
$Storage
.
set
(
's
rcm_shopmall_s
ystem_info'
,
res
)
$Storage
.
set
(
'system_info'
,
res
)
}
}
})
})
}
}
utils/cache/userInfo.js
View file @
cbc1396
/**获取用户信息 */
/**获取用户信息 */
export
function
getUserInfo
()
{
export
function
getUserInfo
()
{
let
user
=
wx
.
$storage
.
get
(
'
srcm_shopmall_user_i
nfo'
)
||
null
let
user
=
wx
.
$storage
.
get
(
'
userI
nfo'
)
||
null
return
user
return
user
}
}
/**设置用户信息 */
/**设置用户信息 */
export
function
setUserInfo
(
userInfo
)
{
export
function
setUserInfo
(
userInfo
)
{
wx
.
$storage
.
set
(
'
srcm_shopmall_user_i
nfo'
,
userInfo
)
wx
.
$storage
.
set
(
'
userI
nfo'
,
userInfo
)
}
}
export
function
isMember
(
isNeedToHttp
,
callBack
)
{
export
function
isMember
(
isNeedToHttp
,
callBack
)
{
...
...
utils/constantData.js
View file @
cbc1396
...
@@ -8,5 +8,6 @@ export const STORAGE_OBJECTkEY = {
...
@@ -8,5 +8,6 @@ export const STORAGE_OBJECTkEY = {
DEFAULT_GET_STORAGEKEY
,
DEFAULT_GET_STORAGEKEY
,
sessionId
:
'sessionId'
,
sessionId
:
'sessionId'
,
userInfo
:
'userInfo'
,
userInfo
:
'userInfo'
,
systemInfo
:
'systemInfo'
system_info
:
'systemInfo'
,
app_title
:
'appTitle'
}
}
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment