Commit 8c35b037 by yixinjj

添加获取本地缓存的处理

1 parent 54ecd7e3
...@@ -10,6 +10,8 @@ ...@@ -10,6 +10,8 @@
var wv var wv
import { mapState } from 'vuex' import { mapState } from 'vuex'
import { Ws } from '@/ws/Ws.js'
import config from '@/config.js'
export default { export default {
computed: { computed: {
...mapState('audio', ['isEnd', 'isStart']) ...mapState('audio', ['isEnd', 'isStart'])
...@@ -24,6 +26,7 @@ export default { ...@@ -24,6 +26,7 @@ export default {
uni.setKeepScreenOn({ uni.setKeepScreenOn({
keepScreenOn: true keepScreenOn: true
}) })
const ws = new Ws({ url: config.SOCKET_ADDRESS, token: 123456, deviceId: 1, onMessage: () => {} })
}, },
methods: { methods: {
setAPPVersion() { setAPPVersion() {
......
...@@ -7,7 +7,7 @@ export const IMG_URL = "https://img02.glsx.com.cn/weapp/resource/app-tape/"; ...@@ -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"]; export const DEFAULT_GET_STORAGEKEY = ["sessionId", "merchantId", "userInfo"];
// 缓存get方法key的对应才映射值 // 缓存get方法key的对应才映射值
export const STORAGE_OBJECTkEY = { export const STORAGE_OBJECTKEY = {
DEFAULT_GET_STORAGEKEY, DEFAULT_GET_STORAGEKEY,
mock_data: "mock_data", mock_data: "mock_data",
storageFile: "storageFile", storageFile: "storageFile",
......
import Storage from './storage' import Storage from './storage'
import storageApi from './storageApi' import storageApi from './storageApi'
module.exports = { Storage, storageApi }
\ No newline at end of file \ No newline at end of file
import * as constData from './constantData'
module.exports = { Storage, storageApi,constData }
\ No newline at end of file \ No newline at end of file
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* 微信小程序标准版:统一封装的 storage 操作类 * 微信小程序标准版:统一封装的 storage 操作类
*/ */
import { DEFAULT_GET_STORAGEKEY, STORAGE_OBJECTkEY } from './constantData' import { DEFAULT_GET_STORAGEKEY, STORAGE_OBJECTKEY } from './constantData'
class Storage { class Storage {
types = { types = {
1: 'get', // get 1: 'get', // get
...@@ -36,7 +36,7 @@ class Storage { ...@@ -36,7 +36,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] // if STORAGE_OBJECTKEY[key]
return tmpKey return tmpKey
} }
return key return key
...@@ -52,7 +52,7 @@ class Storage { ...@@ -52,7 +52,7 @@ class Storage {
if (key) { if (key) {
// 判断值是否是指定的对象值 // 判断值是否是指定的对象值
let tmpKey = this.checkKeyType(key, 1) let tmpKey = this.checkKeyType(key, 1)
let isObjectKey = STORAGE_OBJECTkEY[tmpKey] let isObjectKey = STORAGE_OBJECTKEY[tmpKey]
// console.log(key) // console.log(key)
// console.log(isObjectKey) // console.log(isObjectKey)
if (isObjectKey) { if (isObjectKey) {
......
import { STORAGE_OBJECTkEY } from './constantData' import { STORAGE_OBJECTKEY } from './constantData'
// console.log(storage) // console.log(storage)
/** */ /** */
// 实例化对象存储 // 实例化对象存储
...@@ -60,13 +60,13 @@ export function setSystem_info(that) { ...@@ -60,13 +60,13 @@ export function setSystem_info(that) {
} }
export function getRecords() { export function getRecords() {
return storage.get(STORAGE_OBJECTkEY.recordList) return storage.get(STORAGE_OBJECTKEY.recordList)
} }
export function setRecords(data) { export function setRecords(data) {
storage.set(STORAGE_OBJECTkEY.recordList, data) storage.set(STORAGE_OBJECTKEY.recordList, data)
} }
export function removeRecords() { export function removeRecords() {
storage.rm(STORAGE_OBJECTkEY.recordList) storage.rm(STORAGE_OBJECTKEY.recordList)
} }
export default{ export default{
getSessionId, getSessionId,
......
...@@ -32,7 +32,7 @@ export class Ws { ...@@ -32,7 +32,7 @@ export class Ws {
WsTyps.MessageTypes.Private, WsTyps.MessageTypes.Private,
function (data) { function (data) {
const worker = CommandFactory.getInstance().dispatch(data.command) const worker = CommandFactory.getInstance().dispatch(data.command)
worker.work(this.deviceId, data) worker.work(this.deviceId, data,this)
this.onMessage && this.onMessage(data) this.onMessage && this.onMessage(data)
}.bind(this) }.bind(this)
) )
...@@ -46,7 +46,7 @@ export class Ws { ...@@ -46,7 +46,7 @@ export class Ws {
console.log('ws error', msg) console.log('ws error', msg)
}) })
} }
send(type = WsTyps.MessageTypes.Private, data) { send(data,type = WsTyps.MessageTypes.Private ) {
this.ws.emit(type, data) this.ws.emit(type, data)
} }
} }
import { constData } from '../../utils/cache'
export default class StorageWorker { export default class StorageWorker {
constructor() {} constructor() {}
work(deviceId, data) { work(deviceId, data,ws) {
const store=uni.getStorageInfoSync() let key = data
console.log('store',store) const payload = data.payload
// console.log(`收到WebSocket 消息: deviceId->${deviceId}, data->${typeof data ==='[object Object]'?JSON.stringify(data):data}`) 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!