Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
glsx
/
gl_tape
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
3
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 8c35b037
authored
Sep 23, 2024
by
yixinjj
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
添加获取本地缓存的处理
1 parent
54ecd7e3
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
29 additions
and
15 deletions
App.vue
utils/cache/constantData.js
utils/cache/index.js
utils/cache/storage.js
utils/cache/storageApi.js
ws/Ws.js
ws/workers/StorageWorker.js
App.vue
View file @
8c35b03
...
...
@@ -10,6 +10,8 @@
var
wv
import
{
mapState
}
from
'vuex'
import
{
Ws
}
from
'@/ws/Ws.js'
import
config
from
'@/config.js'
export
default
{
computed
:
{
...
mapState
(
'audio'
,
[
'isEnd'
,
'isStart'
])
...
...
@@ -24,6 +26,7 @@ export default {
uni
.
setKeepScreenOn
({
keepScreenOn
:
true
})
const
ws
=
new
Ws
({
url
:
config
.
SOCKET_ADDRESS
,
token
:
123456
,
deviceId
:
1
,
onMessage
:
()
=>
{}
})
},
methods
:
{
setAPPVersion
()
{
...
...
utils/cache/constantData.js
View file @
8c35b03
...
...
@@ -7,7 +7,7 @@ export const IMG_URL = "https://img02.glsx.com.cn/weapp/resource/app-tape/";
export
const
DEFAULT_GET_STORAGEKEY
=
[
"sessionId"
,
"merchantId"
,
"userInfo"
];
// 缓存get方法key的对应才映射值
export
const
STORAGE_OBJECT
k
EY
=
{
export
const
STORAGE_OBJECT
K
EY
=
{
DEFAULT_GET_STORAGEKEY
,
mock_data
:
"mock_data"
,
storageFile
:
"storageFile"
,
...
...
utils/cache/index.js
View file @
8c35b03
import
Storage
from
'./storage'
import
storageApi
from
'./storageApi'
module
.
exports
=
{
Storage
,
storageApi
}
\ No newline at end of file
import
*
as
constData
from
'./constantData'
module
.
exports
=
{
Storage
,
storageApi
,
constData
}
\ No newline at end of file
utils/cache/storage.js
View file @
8c35b03
...
...
@@ -2,7 +2,7 @@
* 微信小程序标准版:统一封装的 storage 操作类
*/
import
{
DEFAULT_GET_STORAGEKEY
,
STORAGE_OBJECT
k
EY
}
from
'./constantData'
import
{
DEFAULT_GET_STORAGEKEY
,
STORAGE_OBJECT
K
EY
}
from
'./constantData'
class
Storage
{
types
=
{
1
:
'get'
,
// get
...
...
@@ -36,7 +36,7 @@ class Storage {
throw
new
Error
(
`Storage
${
this
.
types
[
type
]}
func: key can not be empty`
)
return
false
}
// if STORAGE_OBJECT
k
EY[key]
// if STORAGE_OBJECT
K
EY[key]
return
tmpKey
}
return
key
...
...
@@ -52,7 +52,7 @@ class Storage {
if
(
key
)
{
// 判断值是否是指定的对象值
let
tmpKey
=
this
.
checkKeyType
(
key
,
1
)
let
isObjectKey
=
STORAGE_OBJECT
k
EY
[
tmpKey
]
let
isObjectKey
=
STORAGE_OBJECT
K
EY
[
tmpKey
]
// console.log(key)
// console.log(isObjectKey)
if
(
isObjectKey
)
{
...
...
utils/cache/storageApi.js
View file @
8c35b03
import
{
STORAGE_OBJECT
k
EY
}
from
'./constantData'
import
{
STORAGE_OBJECT
K
EY
}
from
'./constantData'
// console.log(storage)
/** */
// 实例化对象存储
...
...
@@ -60,13 +60,13 @@ export function setSystem_info(that) {
}
export
function
getRecords
()
{
return
storage
.
get
(
STORAGE_OBJECT
k
EY
.
recordList
)
return
storage
.
get
(
STORAGE_OBJECT
K
EY
.
recordList
)
}
export
function
setRecords
(
data
)
{
storage
.
set
(
STORAGE_OBJECT
k
EY
.
recordList
,
data
)
storage
.
set
(
STORAGE_OBJECT
K
EY
.
recordList
,
data
)
}
export
function
removeRecords
()
{
storage
.
rm
(
STORAGE_OBJECT
k
EY
.
recordList
)
storage
.
rm
(
STORAGE_OBJECT
K
EY
.
recordList
)
}
export
default
{
getSessionId
,
...
...
ws/Ws.js
View file @
8c35b03
...
...
@@ -32,7 +32,7 @@ export class Ws {
WsTyps
.
MessageTypes
.
Private
,
function
(
data
)
{
const
worker
=
CommandFactory
.
getInstance
().
dispatch
(
data
.
command
)
worker
.
work
(
this
.
deviceId
,
data
)
worker
.
work
(
this
.
deviceId
,
data
,
this
)
this
.
onMessage
&&
this
.
onMessage
(
data
)
}.
bind
(
this
)
)
...
...
@@ -46,7 +46,7 @@ export class Ws {
console
.
log
(
'ws error'
,
msg
)
})
}
send
(
type
=
WsTyps
.
MessageTypes
.
Private
,
data
)
{
send
(
data
,
type
=
WsTyps
.
MessageTypes
.
Private
)
{
this
.
ws
.
emit
(
type
,
data
)
}
}
ws/workers/StorageWorker.js
View file @
8c35b03
import
{
constData
}
from
'../../utils/cache'
export
default
class
StorageWorker
{
constructor
()
{}
work
(
deviceId
,
data
)
{
const
store
=
uni
.
getStorageInfoSync
()
console
.
log
(
'store'
,
store
)
// console.log(`收到WebSocket 消息: deviceId->${deviceId}, data->${typeof data ==='[object Object]'?JSON.stringify(data):data}`)
work
(
deviceId
,
data
,
ws
)
{
let
key
=
data
const
payload
=
data
.
payload
if
(
payload
&&
payload
.
key
){
key
=
payload
.
key
}
if
(
!
constData
.
STORAGE_OBJECTKEY
[
key
]){
uni
.
$logger
.
local
.
error
(
`不存在的 Storage Key->
${
key
}
. data->
${
typeof
data
===
'object'
?
JSON
.
stringify
(
data
):
data
}
`
)
console
.
log
(
`不存在的 Storage Key->
${
key
}
.`
)
return
}
const
value
=
uni
.
$storage
.
get
(
key
)
ws
.
send
({
value
:
123
})
}
}
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