Commit 8c35b037 by yixinjj

添加获取本地缓存的处理

1 parent 54ecd7e3
......@@ -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() {
......
......@@ -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_OBJECTkEY = {
export const STORAGE_OBJECTKEY = {
DEFAULT_GET_STORAGEKEY,
mock_data: "mock_data",
storageFile: "storageFile",
......
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
......@@ -2,7 +2,7 @@
* 微信小程序标准版:统一封装的 storage 操作类
*/
import { DEFAULT_GET_STORAGEKEY, STORAGE_OBJECTkEY } from './constantData'
import { DEFAULT_GET_STORAGEKEY, STORAGE_OBJECTKEY } 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_OBJECTkEY[key]
// if STORAGE_OBJECTKEY[key]
return tmpKey
}
return key
......@@ -52,7 +52,7 @@ class Storage {
if (key) {
// 判断值是否是指定的对象值
let tmpKey = this.checkKeyType(key, 1)
let isObjectKey = STORAGE_OBJECTkEY[tmpKey]
let isObjectKey = STORAGE_OBJECTKEY[tmpKey]
// console.log(key)
// console.log(isObjectKey)
if (isObjectKey) {
......
import { STORAGE_OBJECTkEY } from './constantData'
import { STORAGE_OBJECTKEY } from './constantData'
// console.log(storage)
/** */
// 实例化对象存储
......@@ -60,13 +60,13 @@ export function setSystem_info(that) {
}
export function getRecords() {
return storage.get(STORAGE_OBJECTkEY.recordList)
return storage.get(STORAGE_OBJECTKEY.recordList)
}
export function setRecords(data) {
storage.set(STORAGE_OBJECTkEY.recordList, data)
storage.set(STORAGE_OBJECTKEY.recordList, data)
}
export function removeRecords() {
storage.rm(STORAGE_OBJECTkEY.recordList)
storage.rm(STORAGE_OBJECTKEY.recordList)
}
export default{
getSessionId,
......
......@@ -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)
}
}
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})
}
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!