diff --git a/build/rollup.config.app.js b/build/rollup.config.app.js index e343eb8975ef12ecf43fff69ff459a8e41ae2e3e..5933262570978de06e9b8806f3cd41b3c282c83c 100644 --- a/build/rollup.config.app.js +++ b/build/rollup.config.app.js @@ -18,8 +18,10 @@ if (process.env.UNI_SERVICE === 'legacy') { } else if (process.env.UNI_SERVICE === 'uni') { input = 'src/platforms/app-plus/service/uni/index.js' output.file = 'packages/uni-app-plus-nvue/dist/uni.js' - output.banner = - 'export function createUniInstance(weex, plus, __uniConfig, __uniRoutes, UniServiceJSBridge, getApp, getCurrentPages){\n' + output.banner = +`export function createUniInstance(weex, plus, __uniConfig, __uniRoutes, UniServiceJSBridge, getApp, getCurrentPages){ +var localStorage = plus.storage +` output.footer = '\n return uni$1 \n}' } diff --git a/packages/uni-app-plus-nvue/dist/index.js b/packages/uni-app-plus-nvue/dist/index.js index 769f9fcb486830104dd6a1eeb7859301bce3df28..3ceec0d36bd8cec0af0a7a6596fc03fcaffdabed 100644 --- a/packages/uni-app-plus-nvue/dist/index.js +++ b/packages/uni-app-plus-nvue/dist/index.js @@ -677,7 +677,7 @@ let waiting; let waitingTimeout; let toast = false; let toastTimeout; - +// 此处设计不对 function initPopup (on, { plus }) { diff --git a/packages/uni-app-plus-nvue/dist/uni.js b/packages/uni-app-plus-nvue/dist/uni.js index 84f5568eec274dfa21f55f3d7e61898bb57b90f5..51a53fd24e0df70a748cf947c7b1ff8d85261fce 100644 --- a/packages/uni-app-plus-nvue/dist/uni.js +++ b/packages/uni-app-plus-nvue/dist/uni.js @@ -1,4 +1,5 @@ export function createUniInstance(weex, plus, __uniConfig, __uniRoutes, UniServiceJSBridge, getApp, getCurrentPages){ +var localStorage = plus.storage const _toString = Object.prototype.toString; const hasOwnProperty = Object.prototype.hasOwnProperty; @@ -1855,7 +1856,7 @@ function wrapper (name, invokeMethod, extras) { } } -// 尽早将 invokeCallbackHandler 挂在 UniServiceJSBridge 中 +UniServiceJSBridge.publishHandler = UniServiceJSBridge.emit; UniServiceJSBridge.invokeCallbackHandler = invokeCallbackHandler; function createCommonjsModule(fn, module) { @@ -2252,28 +2253,23 @@ function switchTab$1 (args) { return onAppRoute('switchTab', args) } -function getStorageHolder () { - return plus.storage -} - function setStorage$1 ({ key, data } = {}) { - const storageHolder = getStorageHolder(); const value = { type: typeof data === 'object' ? 'object' : 'string', data: data }; - storageHolder.setItem(key, JSON.stringify(value)); - const keyList = storageHolder.getItem('uni-storage-keys'); + localStorage.setItem(key, JSON.stringify(value)); + const keyList = localStorage.getItem('uni-storage-keys'); if (!keyList) { - storageHolder.setItem('uni-storage-keys', JSON.stringify([key])); + localStorage.setItem('uni-storage-keys', JSON.stringify([key])); } else { const keys = JSON.parse(keyList); if (keys.indexOf(key) < 0) { keys.push(key); - storageHolder.setItem('uni-storage-keys', JSON.stringify(keys)); + localStorage.setItem('uni-storage-keys', JSON.stringify(keys)); } } return { @@ -2291,7 +2287,7 @@ function setStorageSync$1 (key, data) { function getStorage ({ key } = {}) { - const data = getStorageHolder().getItem(key); + const data = localStorage.getItem(key); return data ? { data: JSON.parse(data).data, errMsg: 'getStorage:ok' @@ -2311,15 +2307,14 @@ function getStorageSync (key) { function removeStorage ({ key } = {}) { - const storageHolder = getStorageHolder(); - const keyList = storageHolder.getItem('uni-storage-keys'); + const keyList = localStorage.getItem('uni-storage-keys'); if (keyList) { const keys = JSON.parse(keyList); const index = keys.indexOf(key); keys.splice(index, 1); - storageHolder.setItem('uni-storage-keys', JSON.stringify(keys)); + localStorage.setItem('uni-storage-keys', JSON.stringify(keys)); } - storageHolder.removeItem(key); + localStorage.removeItem(key); return { errMsg: 'removeStorage:ok' } @@ -2332,7 +2327,7 @@ function removeStorageSync (key) { } function clearStorage () { - getStorageHolder().clear(); + localStorage.clear(); return { errMsg: 'clearStorage:ok' } @@ -2343,7 +2338,7 @@ function clearStorageSync () { } function getStorageInfo () { // TODO 暂时先不做大小的转换 - const keyList = getStorageHolder().getItem('uni-storage-keys'); + const keyList = localStorage.getItem('uni-storage-keys'); return keyList ? { keys: JSON.parse(keyList), currentSize: 0, diff --git a/src/core/service/api/storage.js b/src/core/service/api/storage.js index acfa7de880e8cd73afb0057dd25f3e34fba78c5c..59e220fac293e4327a08e433c95500fb0562b623 100644 --- a/src/core/service/api/storage.js +++ b/src/core/service/api/storage.js @@ -1,28 +1,20 @@ -function getStorageHolder () { - if (__PLATFORM__ === 'h5') { - return localStorage - } - return plus.storage -} - export function setStorage ({ key, data } = {}) { - const storageHolder = getStorageHolder() const value = { type: typeof data === 'object' ? 'object' : 'string', data: data } - storageHolder.setItem(key, JSON.stringify(value)) - const keyList = storageHolder.getItem('uni-storage-keys') + localStorage.setItem(key, JSON.stringify(value)) + const keyList = localStorage.getItem('uni-storage-keys') if (!keyList) { - storageHolder.setItem('uni-storage-keys', JSON.stringify([key])) + localStorage.setItem('uni-storage-keys', JSON.stringify([key])) } else { const keys = JSON.parse(keyList) if (keys.indexOf(key) < 0) { keys.push(key) - storageHolder.setItem('uni-storage-keys', JSON.stringify(keys)) + localStorage.setItem('uni-storage-keys', JSON.stringify(keys)) } } return { @@ -40,7 +32,7 @@ export function setStorageSync (key, data) { export function getStorage ({ key } = {}) { - const data = getStorageHolder().getItem(key) + const data = localStorage.getItem(key) return data ? { data: JSON.parse(data).data, errMsg: 'getStorage:ok' @@ -60,15 +52,14 @@ export function getStorageSync (key) { export function removeStorage ({ key } = {}) { - const storageHolder = getStorageHolder() - const keyList = storageHolder.getItem('uni-storage-keys') + const keyList = localStorage.getItem('uni-storage-keys') if (keyList) { const keys = JSON.parse(keyList) const index = keys.indexOf(key) keys.splice(index, 1) - storageHolder.setItem('uni-storage-keys', JSON.stringify(keys)) + localStorage.setItem('uni-storage-keys', JSON.stringify(keys)) } - storageHolder.removeItem(key) + localStorage.removeItem(key) return { errMsg: 'removeStorage:ok' } @@ -81,7 +72,7 @@ export function removeStorageSync (key) { } export function clearStorage () { - getStorageHolder().clear() + localStorage.clear() return { errMsg: 'clearStorage:ok' } @@ -92,7 +83,7 @@ export function clearStorageSync () { } export function getStorageInfo () { // TODO 暂时先不做大小的转换 - const keyList = getStorageHolder().getItem('uni-storage-keys') + const keyList = localStorage.getItem('uni-storage-keys') return keyList ? { keys: JSON.parse(keyList), currentSize: 0, diff --git a/src/platforms/app-plus/service/uni/polyfill.js b/src/platforms/app-plus/service/uni/polyfill.js index c00b2505d610eb20f6f6a70069a448e8fdacd649..c08b29e8ccd231d90772b96a23db0bcb74abeb2e 100644 --- a/src/platforms/app-plus/service/uni/polyfill.js +++ b/src/platforms/app-plus/service/uni/polyfill.js @@ -1,5 +1,6 @@ import { invokeCallbackHandler } from 'uni-helpers/api' -// 尽早将 invokeCallbackHandler 挂在 UniServiceJSBridge 中 + +UniServiceJSBridge.publishHandler = UniServiceJSBridge.emit UniServiceJSBridge.invokeCallbackHandler = invokeCallbackHandler diff --git a/src/platforms/app-plus/service/uni/popup.js b/src/platforms/app-plus/service/uni/popup.js index 1bd1a3c27506313a91ac3af0319f8e20ed18ebcb..9ffe27ec5fca4419aea7c6808dd7fe8b62ab1cd7 100644 --- a/src/platforms/app-plus/service/uni/popup.js +++ b/src/platforms/app-plus/service/uni/popup.js @@ -2,7 +2,7 @@ let waiting let waitingTimeout let toast = false let toastTimeout - +// 此处设计不对 export default function initPopup (on, { plus }) {