import XEUtils from 'xe-utils' import MaliLoading from '../modal/loading' import globalStore from '../config/store' export function defineH5Transfer (vueOpts: any = {}) { return { ...vueOpts, onLoad (options) { if (options) { const { _url, _fnName, _syncStorage } = options let data = {} let url = _url ? decodeURIComponent(_url) : '' if (options && _syncStorage) { data = XEUtils.toStringJSON(decodeURIComponent(_syncStorage)) } if (globalStore.webview) { if (globalStore.webview.setStorage) { globalStore.webview.setStorage({ data }) } if (globalStore.webview.redirectPath) { url = globalStore.webview.redirectPath({ url }) || url } } if (vueOpts.onStorage) { vueOpts.onStorage.call(this, { data }) } if (vueOpts.onLoad) { vueOpts.onLoad.call(this, data) } MaliLoading.show() setTimeout(() => { if (url && ['navigateTo', 'redirectTo'].includes(_fnName)) { uni.redirectTo({ url: url, complete () { MaliLoading.hide() } }) } else { MaliLoading.hide() } }, 300) } } } } const MaliWebview = { defineH5Transfer } export default MaliWebview