From 6f15a5a1af1140f93a5954ba3ef6f82c1d2e86b9 Mon Sep 17 00:00:00 2001 From: fxy060608 Date: Tue, 22 Feb 2022 20:35:20 +0800 Subject: [PATCH] refactor: onCreateVueApp --- packages/uni-api/src/index.ts | 2 +- .../uni-app-plus/dist/uni-app-service.es.js | 490 +++++++++--------- packages/uni-h5-vite/lib/api.json | 2 +- packages/uni-h5/dist/uni-h5.cjs.js | 286 +++++----- packages/uni-h5/dist/uni-h5.es.js | 301 ++++++----- packages/uni-mp-alipay/dist/uni.api.esm.js | 36 +- packages/uni-mp-baidu/dist/uni.api.esm.js | 36 +- packages/uni-mp-core/src/api/index.ts | 2 +- packages/uni-mp-kuaishou/dist/uni.api.esm.js | 36 +- packages/uni-mp-lark/dist/uni.api.esm.js | 36 +- packages/uni-mp-qq/dist/uni.api.esm.js | 36 +- packages/uni-mp-toutiao/dist/uni.api.esm.js | 36 +- packages/uni-mp-weixin/dist/uni.api.esm.js | 36 +- .../uni-quickapp-webview/dist/uni.api.esm.js | 36 +- packages/uni-shared/dist/uni-shared.cjs.js | 20 + packages/uni-shared/dist/uni-shared.d.ts | 11 + packages/uni-shared/dist/uni-shared.es.js | 20 +- packages/uni-shared/src/index.ts | 1 + .../src/onCreateVueApp.ts | 0 packages/uni-stat/dist/uni-stat.es.js | 27 +- packages/uni-vue/src/index.ts | 4 +- 21 files changed, 738 insertions(+), 716 deletions(-) rename packages/{uni-vue => uni-shared}/src/onCreateVueApp.ts (100%) diff --git a/packages/uni-api/src/index.ts b/packages/uni-api/src/index.ts index 8b80b72a6..9072840cd 100644 --- a/packages/uni-api/src/index.ts +++ b/packages/uni-api/src/index.ts @@ -103,7 +103,7 @@ export * from './protocols/ad/fullScreenVideoAd' export * from './protocols/ad/interstitialAd' export * from './protocols/ad/interactiveAd' -export { onCreateVueApp } from '@dcloudio/uni-vue' +export { onCreateVueApp } from '@dcloudio/uni-shared' // helpers export { diff --git a/packages/uni-app-plus/dist/uni-app-service.es.js b/packages/uni-app-plus/dist/uni-app-service.es.js index 2ab4ddad4..381d4b1c8 100644 --- a/packages/uni-app-plus/dist/uni-app-service.es.js +++ b/packages/uni-app-plus/dist/uni-app-service.es.js @@ -696,6 +696,24 @@ var serviceContext = (function (vue) { ON_NAVIGATION_BAR_SEARCH_INPUT_FOCUS_CHANGED, ]; + let vueApp$1; + const createVueAppHooks = []; + /** + * 提供 createApp 的回调事件,方便三方插件接收 App 对象,处理挂靠全局 mixin 之类的逻辑 + * @param hook + */ + function onCreateVueApp(hook) { + // TODO 每个 nvue 页面都会触发 + if (vueApp$1) { + return hook(vueApp$1); + } + createVueAppHooks.push(hook); + } + function invokeCreateVueAppHook(app) { + vueApp$1 = app; + createVueAppHooks.forEach((hook) => hook(app)); + } + const E = function () { // Keep this empty so it's easier to inherit from // (via https://github.com/lipsmack from https://github.com/scottcorgan/tiny-emitter/issues/3) @@ -11634,10 +11652,6 @@ var serviceContext = (function (vue) { }); }); - ({ - [ON_SHOW]: [], - [ON_HIDE]: [], - }); const API_GET_ENTER_OPTIONS_SYNC = 'getEnterOptionsSync'; const getEnterOptionsSync = defineSyncApi(API_GET_ENTER_OPTIONS_SYNC, () => { return getEnterOptions(); @@ -13165,249 +13179,6 @@ var serviceContext = (function (vue) { }, }; - function injectLifecycleHook(name, hook, publicThis, instance) { - if (isFunction(hook)) { - vue.injectHook(name, hook.bind(publicThis), instance); - } - } - function initHooks(options, instance, publicThis) { - const mpType = options.mpType || publicThis.$mpType; - // 为了组件也可以监听部分生命周期,故不再判断mpType,统一添加on开头的生命周期 - Object.keys(options).forEach((name) => { - if (name.indexOf('on') === 0) { - const hooks = options[name]; - if (isArray$1(hooks)) { - hooks.forEach((hook) => injectLifecycleHook(name, hook, publicThis, instance)); - } - else { - injectLifecycleHook(name, hooks, publicThis, instance); - } - } - }); - if (mpType === 'page') { - instance.__isVisible = true; - try { - invokeHook(publicThis, ON_LOAD, instance.attrs.__pageQuery); - delete instance.attrs.__pageQuery; - } - catch (e) { - console.error(e.message + LINEFEED + e.stack); - } - vue.nextTick(() => { - // 延迟onShow,保证组件的onShow也可以监听到 - invokeHook(publicThis, ON_SHOW); - }); - } - } - - function initRenderjs(options, instance) { - initModules(instance, options.$renderjs, options['$' + RENDERJS_MODULES]); - } - function initModules(instance, modules, moduleIds = {}) { - if (!isArray$1(modules)) { - return; - } - const ownerId = instance.uid; - // 在vue的定制内核中,通过$wxsModules来判断事件函数源码中是否包含该模块调用 - // !$wxsModules.find(module => invokerSourceCode.indexOf('.' + module + '.') > -1) - const $wxsModules = (instance.$wxsModules || - (instance.$wxsModules = [])); - const ctx = instance.ctx; - modules.forEach((module) => { - if (moduleIds[module]) { - ctx[module] = proxyModule(ownerId, moduleIds[module], module); - $wxsModules.push(module); - } - else { - if ((process.env.NODE_ENV !== 'production')) { - console.error(formatLog('initModules', modules, moduleIds)); - } - } - }); - } - function proxyModule(ownerId, moduleId, module) { - const target = {}; - return new Proxy(target, { - get(_, p) { - return (target[p] || - (target[p] = createModuleFunction(ownerId, moduleId, module, p))); - }, - }); - } - function createModuleFunction(ownerId, moduleId, module, name) { - const target = () => { }; - const toJSON = () => WXS_PROTOCOL + JSON.stringify([ownerId, moduleId, module + '.' + name]); - return new Proxy(target, { - get(_, p) { - if (p === 'toJSON') { - return toJSON; - } - return (target[p] || - (target[p] = createModuleFunction(ownerId, moduleId, module + '.' + name, p))); - }, - apply(_target, _thisArg, args) { - return (WXS_PROTOCOL + - JSON.stringify([ownerId, moduleId, module + '.' + name, [...args]])); - }, - }); - } - - function initWxs(options, instance) { - initModules(instance, options.$wxs, options['$' + WXS_MODULES]); - } - - function applyOptions(options, instance, publicThis) { - { - initWxs(options, instance); - initRenderjs(options, instance); - } - initHooks(options, instance, publicThis); - } - - function set(target, key, val) { - return (target[key] = val); - } - - function errorHandler(err, instance, info) { - if (!instance) { - throw err; - } - const app = getApp(); - if (!app || !app.$vm) { - throw err; - } - { - invokeHook(app.$vm, ON_ERROR, err); - } - } - function mergeAsArray(to, from) { - return to ? [...new Set([].concat(to, from))] : from; - } - function initOptionMergeStrategies(optionMergeStrategies) { - UniLifecycleHooks.forEach((name) => { - optionMergeStrategies[name] = mergeAsArray; - }); - } - - let realAtob; - const b64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; - const b64re = /^(?:[A-Za-z\d+/]{4})*?(?:[A-Za-z\d+/]{2}(?:==)?|[A-Za-z\d+/]{3}=?)?$/; - if (typeof atob !== 'function') { - realAtob = function (str) { - str = String(str).replace(/[\t\n\f\r ]+/g, ''); - if (!b64re.test(str)) { - throw new Error("Failed to execute 'atob' on 'Window': The string to be decoded is not correctly encoded."); - } - // Adding the padding if missing, for semplicity - str += '=='.slice(2 - (str.length & 3)); - var bitmap; - var result = ''; - var r1; - var r2; - var i = 0; - for (; i < str.length;) { - bitmap = - (b64.indexOf(str.charAt(i++)) << 18) | - (b64.indexOf(str.charAt(i++)) << 12) | - ((r1 = b64.indexOf(str.charAt(i++))) << 6) | - (r2 = b64.indexOf(str.charAt(i++))); - result += - r1 === 64 - ? String.fromCharCode((bitmap >> 16) & 255) - : r2 === 64 - ? String.fromCharCode((bitmap >> 16) & 255, (bitmap >> 8) & 255) - : String.fromCharCode((bitmap >> 16) & 255, (bitmap >> 8) & 255, bitmap & 255); - } - return result; - }; - } - else { - // 注意atob只能在全局对象上调用,例如:`const Base64 = {atob};Base64.atob('xxxx')`是错误的用法 - realAtob = atob; - } - function b64DecodeUnicode(str) { - return decodeURIComponent(realAtob(str) - .split('') - .map(function (c) { - return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2); - }) - .join('')); - } - function getCurrentUserInfo() { - const token = uni.getStorageSync('uni_id_token') || ''; - const tokenArr = token.split('.'); - if (!token || tokenArr.length !== 3) { - return { - uid: null, - role: [], - permission: [], - tokenExpired: 0, - }; - } - let userInfo; - try { - userInfo = JSON.parse(b64DecodeUnicode(tokenArr[1])); - } - catch (error) { - throw new Error('获取当前用户信息出错,详细错误信息为:' + error.message); - } - userInfo.tokenExpired = userInfo.exp * 1000; - delete userInfo.exp; - delete userInfo.iat; - return userInfo; - } - function uniIdMixin(globalProperties) { - globalProperties.uniIDHasRole = function (roleId) { - const { role } = getCurrentUserInfo(); - return role.indexOf(roleId) > -1; - }; - globalProperties.uniIDHasPermission = function (permissionId) { - const { permission } = getCurrentUserInfo(); - return this.uniIDHasRole('admin') || permission.indexOf(permissionId) > -1; - }; - globalProperties.uniIDTokenValid = function () { - const { tokenExpired } = getCurrentUserInfo(); - return tokenExpired > Date.now(); - }; - } - - let vueApp$1; - const createVueAppHooks = []; - /** - * 提供 createApp 的回调事件,方便三方插件接收 App 对象,处理挂靠全局 mixin 之类的逻辑 - * @param hook - */ - function onCreateVueApp(hook) { - // TODO 每个 nvue 页面都会触发 - if (vueApp$1) { - return hook(vueApp$1); - } - createVueAppHooks.push(hook); - } - function invokeCreateVueAppHook(app) { - vueApp$1 = app; - createVueAppHooks.forEach((hook) => hook(app)); - } - - function initApp(app) { - const appConfig = app._context.config; - if (isFunction(app._component.onError)) { - appConfig.errorHandler = errorHandler; - } - initOptionMergeStrategies(appConfig.optionMergeStrategies); - const globalProperties = appConfig.globalProperties; - { - uniIdMixin(globalProperties); - } - { - globalProperties.$set = set; - globalProperties.$applyOptions = applyOptions; - } - { - invokeCreateVueAppHook(app); - } - } - function warpPlusSuccessCallback(resolve, after) { return function successCallback(data) { delete data.code; @@ -17356,6 +17127,231 @@ var serviceContext = (function (vue) { }, errorCallback); }, RequestPaymentProtocol); + function injectLifecycleHook(name, hook, publicThis, instance) { + if (isFunction(hook)) { + vue.injectHook(name, hook.bind(publicThis), instance); + } + } + function initHooks(options, instance, publicThis) { + const mpType = options.mpType || publicThis.$mpType; + // 为了组件也可以监听部分生命周期,故不再判断mpType,统一添加on开头的生命周期 + Object.keys(options).forEach((name) => { + if (name.indexOf('on') === 0) { + const hooks = options[name]; + if (isArray$1(hooks)) { + hooks.forEach((hook) => injectLifecycleHook(name, hook, publicThis, instance)); + } + else { + injectLifecycleHook(name, hooks, publicThis, instance); + } + } + }); + if (mpType === 'page') { + instance.__isVisible = true; + try { + invokeHook(publicThis, ON_LOAD, instance.attrs.__pageQuery); + delete instance.attrs.__pageQuery; + } + catch (e) { + console.error(e.message + LINEFEED + e.stack); + } + vue.nextTick(() => { + // 延迟onShow,保证组件的onShow也可以监听到 + invokeHook(publicThis, ON_SHOW); + }); + } + } + + function initRenderjs(options, instance) { + initModules(instance, options.$renderjs, options['$' + RENDERJS_MODULES]); + } + function initModules(instance, modules, moduleIds = {}) { + if (!isArray$1(modules)) { + return; + } + const ownerId = instance.uid; + // 在vue的定制内核中,通过$wxsModules来判断事件函数源码中是否包含该模块调用 + // !$wxsModules.find(module => invokerSourceCode.indexOf('.' + module + '.') > -1) + const $wxsModules = (instance.$wxsModules || + (instance.$wxsModules = [])); + const ctx = instance.ctx; + modules.forEach((module) => { + if (moduleIds[module]) { + ctx[module] = proxyModule(ownerId, moduleIds[module], module); + $wxsModules.push(module); + } + else { + if ((process.env.NODE_ENV !== 'production')) { + console.error(formatLog('initModules', modules, moduleIds)); + } + } + }); + } + function proxyModule(ownerId, moduleId, module) { + const target = {}; + return new Proxy(target, { + get(_, p) { + return (target[p] || + (target[p] = createModuleFunction(ownerId, moduleId, module, p))); + }, + }); + } + function createModuleFunction(ownerId, moduleId, module, name) { + const target = () => { }; + const toJSON = () => WXS_PROTOCOL + JSON.stringify([ownerId, moduleId, module + '.' + name]); + return new Proxy(target, { + get(_, p) { + if (p === 'toJSON') { + return toJSON; + } + return (target[p] || + (target[p] = createModuleFunction(ownerId, moduleId, module + '.' + name, p))); + }, + apply(_target, _thisArg, args) { + return (WXS_PROTOCOL + + JSON.stringify([ownerId, moduleId, module + '.' + name, [...args]])); + }, + }); + } + + function initWxs(options, instance) { + initModules(instance, options.$wxs, options['$' + WXS_MODULES]); + } + + function applyOptions(options, instance, publicThis) { + { + initWxs(options, instance); + initRenderjs(options, instance); + } + initHooks(options, instance, publicThis); + } + + function set(target, key, val) { + return (target[key] = val); + } + + function errorHandler(err, instance, info) { + if (!instance) { + throw err; + } + const app = getApp(); + if (!app || !app.$vm) { + throw err; + } + { + invokeHook(app.$vm, ON_ERROR, err); + } + } + function mergeAsArray(to, from) { + return to ? [...new Set([].concat(to, from))] : from; + } + function initOptionMergeStrategies(optionMergeStrategies) { + UniLifecycleHooks.forEach((name) => { + optionMergeStrategies[name] = mergeAsArray; + }); + } + + let realAtob; + const b64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; + const b64re = /^(?:[A-Za-z\d+/]{4})*?(?:[A-Za-z\d+/]{2}(?:==)?|[A-Za-z\d+/]{3}=?)?$/; + if (typeof atob !== 'function') { + realAtob = function (str) { + str = String(str).replace(/[\t\n\f\r ]+/g, ''); + if (!b64re.test(str)) { + throw new Error("Failed to execute 'atob' on 'Window': The string to be decoded is not correctly encoded."); + } + // Adding the padding if missing, for semplicity + str += '=='.slice(2 - (str.length & 3)); + var bitmap; + var result = ''; + var r1; + var r2; + var i = 0; + for (; i < str.length;) { + bitmap = + (b64.indexOf(str.charAt(i++)) << 18) | + (b64.indexOf(str.charAt(i++)) << 12) | + ((r1 = b64.indexOf(str.charAt(i++))) << 6) | + (r2 = b64.indexOf(str.charAt(i++))); + result += + r1 === 64 + ? String.fromCharCode((bitmap >> 16) & 255) + : r2 === 64 + ? String.fromCharCode((bitmap >> 16) & 255, (bitmap >> 8) & 255) + : String.fromCharCode((bitmap >> 16) & 255, (bitmap >> 8) & 255, bitmap & 255); + } + return result; + }; + } + else { + // 注意atob只能在全局对象上调用,例如:`const Base64 = {atob};Base64.atob('xxxx')`是错误的用法 + realAtob = atob; + } + function b64DecodeUnicode(str) { + return decodeURIComponent(realAtob(str) + .split('') + .map(function (c) { + return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2); + }) + .join('')); + } + function getCurrentUserInfo() { + const token = uni.getStorageSync('uni_id_token') || ''; + const tokenArr = token.split('.'); + if (!token || tokenArr.length !== 3) { + return { + uid: null, + role: [], + permission: [], + tokenExpired: 0, + }; + } + let userInfo; + try { + userInfo = JSON.parse(b64DecodeUnicode(tokenArr[1])); + } + catch (error) { + throw new Error('获取当前用户信息出错,详细错误信息为:' + error.message); + } + userInfo.tokenExpired = userInfo.exp * 1000; + delete userInfo.exp; + delete userInfo.iat; + return userInfo; + } + function uniIdMixin(globalProperties) { + globalProperties.uniIDHasRole = function (roleId) { + const { role } = getCurrentUserInfo(); + return role.indexOf(roleId) > -1; + }; + globalProperties.uniIDHasPermission = function (permissionId) { + const { permission } = getCurrentUserInfo(); + return this.uniIDHasRole('admin') || permission.indexOf(permissionId) > -1; + }; + globalProperties.uniIDTokenValid = function () { + const { tokenExpired } = getCurrentUserInfo(); + return tokenExpired > Date.now(); + }; + } + + function initApp(app) { + const appConfig = app._context.config; + if (isFunction(app._component.onError)) { + appConfig.errorHandler = errorHandler; + } + initOptionMergeStrategies(appConfig.optionMergeStrategies); + const globalProperties = appConfig.globalProperties; + { + uniIdMixin(globalProperties); + } + { + globalProperties.$set = set; + globalProperties.$applyOptions = applyOptions; + } + { + invokeCreateVueAppHook(app); + } + } + let isInitEntryPage = false; function initEntry() { if (isInitEntryPage) { diff --git a/packages/uni-h5-vite/lib/api.json b/packages/uni-h5-vite/lib/api.json index db8402ad3..c83e4061a 100644 --- a/packages/uni-h5-vite/lib/api.json +++ b/packages/uni-h5-vite/lib/api.json @@ -1,4 +1,5 @@ [ + "onCreateVueApp", "$emit", "$off", "$on", @@ -80,7 +81,6 @@ "offWindowResize", "onAccelerometerChange", "onCompassChange", - "onCreateVueApp", "onGyroscopeChange", "onLocaleChange", "onMemoryWarning", diff --git a/packages/uni-h5/dist/uni-h5.cjs.js b/packages/uni-h5/dist/uni-h5.cjs.js index 6a6bb9ddd..9a33de258 100644 --- a/packages/uni-h5/dist/uni-h5.cjs.js +++ b/packages/uni-h5/dist/uni-h5.cjs.js @@ -1455,151 +1455,6 @@ const SetNavigationBarTitleProtocol = { }; const API_SHOW_NAVIGATION_BAR_LOADING = "showNavigationBarLoading"; const API_HIDE_NAVIGATION_BAR_LOADING = "hideNavigationBarLoading"; -function injectLifecycleHook(name, hook, publicThis, instance) { - if (shared.isFunction(hook)) { - vue.injectHook(name, hook.bind(publicThis), instance); - } -} -function initHooks(options, instance, publicThis) { - const mpType = options.mpType || publicThis.$mpType; - Object.keys(options).forEach((name) => { - if (name.indexOf("on") === 0) { - const hooks = options[name]; - if (shared.isArray(hooks)) { - hooks.forEach((hook) => injectLifecycleHook(name, hook, publicThis, instance)); - } else { - injectLifecycleHook(name, hooks, publicThis, instance); - } - } - }); - if (mpType === "page") { - instance.__isVisible = true; - try { - invokeHook(publicThis, uniShared.ON_LOAD, instance.attrs.__pageQuery); - delete instance.attrs.__pageQuery; - } catch (e2) { - console.error(e2.message + uniShared.LINEFEED + e2.stack); - } - vue.nextTick(() => { - invokeHook(publicThis, uniShared.ON_SHOW); - }); - } -} -function applyOptions(options, instance, publicThis) { - initHooks(options, instance, publicThis); -} -function set(target, key, val) { - return target[key] = val; -} -function errorHandler(err, instance, info) { - if (!instance) { - throw err; - } - const app = getApp(); - if (!app || !app.$vm) { - throw err; - } - { - invokeHook(app.$vm, uniShared.ON_ERROR, err); - } -} -function mergeAsArray(to, from) { - return to ? [...new Set([].concat(to, from))] : from; -} -function initOptionMergeStrategies(optionMergeStrategies) { - uniShared.UniLifecycleHooks.forEach((name) => { - optionMergeStrategies[name] = mergeAsArray; - }); -} -let realAtob; -const b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="; -const b64re = /^(?:[A-Za-z\d+/]{4})*?(?:[A-Za-z\d+/]{2}(?:==)?|[A-Za-z\d+/]{3}=?)?$/; -if (typeof atob !== "function") { - realAtob = function(str) { - str = String(str).replace(/[\t\n\f\r ]+/g, ""); - if (!b64re.test(str)) { - throw new Error("Failed to execute 'atob' on 'Window': The string to be decoded is not correctly encoded."); - } - str += "==".slice(2 - (str.length & 3)); - var bitmap; - var result = ""; - var r1; - var r2; - var i = 0; - for (; i < str.length; ) { - bitmap = b64.indexOf(str.charAt(i++)) << 18 | b64.indexOf(str.charAt(i++)) << 12 | (r1 = b64.indexOf(str.charAt(i++))) << 6 | (r2 = b64.indexOf(str.charAt(i++))); - result += r1 === 64 ? String.fromCharCode(bitmap >> 16 & 255) : r2 === 64 ? String.fromCharCode(bitmap >> 16 & 255, bitmap >> 8 & 255) : String.fromCharCode(bitmap >> 16 & 255, bitmap >> 8 & 255, bitmap & 255); - } - return result; - }; -} else { - realAtob = atob; -} -function b64DecodeUnicode(str) { - return decodeURIComponent(realAtob(str).split("").map(function(c) { - return "%" + ("00" + c.charCodeAt(0).toString(16)).slice(-2); - }).join("")); -} -function getCurrentUserInfo() { - const token = uni.getStorageSync("uni_id_token") || ""; - const tokenArr = token.split("."); - if (!token || tokenArr.length !== 3) { - return { - uid: null, - role: [], - permission: [], - tokenExpired: 0 - }; - } - let userInfo; - try { - userInfo = JSON.parse(b64DecodeUnicode(tokenArr[1])); - } catch (error) { - throw new Error("\u83B7\u53D6\u5F53\u524D\u7528\u6237\u4FE1\u606F\u51FA\u9519\uFF0C\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F\u4E3A\uFF1A" + error.message); - } - userInfo.tokenExpired = userInfo.exp * 1e3; - delete userInfo.exp; - delete userInfo.iat; - return userInfo; -} -function uniIdMixin(globalProperties) { - globalProperties.uniIDHasRole = function(roleId) { - const { role } = getCurrentUserInfo(); - return role.indexOf(roleId) > -1; - }; - globalProperties.uniIDHasPermission = function(permissionId) { - const { permission } = getCurrentUserInfo(); - return this.uniIDHasRole("admin") || permission.indexOf(permissionId) > -1; - }; - globalProperties.uniIDTokenValid = function() { - const { tokenExpired } = getCurrentUserInfo(); - return tokenExpired > Date.now(); - }; -} -const createVueAppHooks = []; -function invokeCreateVueAppHook(app) { - createVueAppHooks.forEach((hook) => hook(app)); -} -function initApp$1(app) { - const appConfig = app._context.config; - if (shared.isFunction(app._component.onError)) { - appConfig.errorHandler = errorHandler; - } - initOptionMergeStrategies(appConfig.optionMergeStrategies); - const globalProperties = appConfig.globalProperties; - { - if (__UNI_FEATURE_UNI_CLOUD__) { - uniIdMixin(globalProperties); - } - } - { - globalProperties.$set = set; - globalProperties.$applyOptions = applyOptions; - } - { - invokeCreateVueAppHook(app); - } -} function saveImage(base64, dirname, callback) { callback(null, base64); } @@ -6687,6 +6542,147 @@ function useContextInfo(_id) { const id = _id || vm.id || `context${index$g++}`; return `${type}.${id}`; } +function injectLifecycleHook(name, hook, publicThis, instance) { + if (shared.isFunction(hook)) { + vue.injectHook(name, hook.bind(publicThis), instance); + } +} +function initHooks(options, instance, publicThis) { + const mpType = options.mpType || publicThis.$mpType; + Object.keys(options).forEach((name) => { + if (name.indexOf("on") === 0) { + const hooks = options[name]; + if (shared.isArray(hooks)) { + hooks.forEach((hook) => injectLifecycleHook(name, hook, publicThis, instance)); + } else { + injectLifecycleHook(name, hooks, publicThis, instance); + } + } + }); + if (mpType === "page") { + instance.__isVisible = true; + try { + invokeHook(publicThis, uniShared.ON_LOAD, instance.attrs.__pageQuery); + delete instance.attrs.__pageQuery; + } catch (e2) { + console.error(e2.message + uniShared.LINEFEED + e2.stack); + } + vue.nextTick(() => { + invokeHook(publicThis, uniShared.ON_SHOW); + }); + } +} +function applyOptions(options, instance, publicThis) { + initHooks(options, instance, publicThis); +} +function set(target, key, val) { + return target[key] = val; +} +function errorHandler(err, instance, info) { + if (!instance) { + throw err; + } + const app = getApp(); + if (!app || !app.$vm) { + throw err; + } + { + invokeHook(app.$vm, uniShared.ON_ERROR, err); + } +} +function mergeAsArray(to, from) { + return to ? [...new Set([].concat(to, from))] : from; +} +function initOptionMergeStrategies(optionMergeStrategies) { + uniShared.UniLifecycleHooks.forEach((name) => { + optionMergeStrategies[name] = mergeAsArray; + }); +} +let realAtob; +const b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="; +const b64re = /^(?:[A-Za-z\d+/]{4})*?(?:[A-Za-z\d+/]{2}(?:==)?|[A-Za-z\d+/]{3}=?)?$/; +if (typeof atob !== "function") { + realAtob = function(str) { + str = String(str).replace(/[\t\n\f\r ]+/g, ""); + if (!b64re.test(str)) { + throw new Error("Failed to execute 'atob' on 'Window': The string to be decoded is not correctly encoded."); + } + str += "==".slice(2 - (str.length & 3)); + var bitmap; + var result = ""; + var r1; + var r2; + var i = 0; + for (; i < str.length; ) { + bitmap = b64.indexOf(str.charAt(i++)) << 18 | b64.indexOf(str.charAt(i++)) << 12 | (r1 = b64.indexOf(str.charAt(i++))) << 6 | (r2 = b64.indexOf(str.charAt(i++))); + result += r1 === 64 ? String.fromCharCode(bitmap >> 16 & 255) : r2 === 64 ? String.fromCharCode(bitmap >> 16 & 255, bitmap >> 8 & 255) : String.fromCharCode(bitmap >> 16 & 255, bitmap >> 8 & 255, bitmap & 255); + } + return result; + }; +} else { + realAtob = atob; +} +function b64DecodeUnicode(str) { + return decodeURIComponent(realAtob(str).split("").map(function(c) { + return "%" + ("00" + c.charCodeAt(0).toString(16)).slice(-2); + }).join("")); +} +function getCurrentUserInfo() { + const token = uni.getStorageSync("uni_id_token") || ""; + const tokenArr = token.split("."); + if (!token || tokenArr.length !== 3) { + return { + uid: null, + role: [], + permission: [], + tokenExpired: 0 + }; + } + let userInfo; + try { + userInfo = JSON.parse(b64DecodeUnicode(tokenArr[1])); + } catch (error) { + throw new Error("\u83B7\u53D6\u5F53\u524D\u7528\u6237\u4FE1\u606F\u51FA\u9519\uFF0C\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F\u4E3A\uFF1A" + error.message); + } + userInfo.tokenExpired = userInfo.exp * 1e3; + delete userInfo.exp; + delete userInfo.iat; + return userInfo; +} +function uniIdMixin(globalProperties) { + globalProperties.uniIDHasRole = function(roleId) { + const { role } = getCurrentUserInfo(); + return role.indexOf(roleId) > -1; + }; + globalProperties.uniIDHasPermission = function(permissionId) { + const { permission } = getCurrentUserInfo(); + return this.uniIDHasRole("admin") || permission.indexOf(permissionId) > -1; + }; + globalProperties.uniIDTokenValid = function() { + const { tokenExpired } = getCurrentUserInfo(); + return tokenExpired > Date.now(); + }; +} +function initApp$1(app) { + const appConfig = app._context.config; + if (shared.isFunction(app._component.onError)) { + appConfig.errorHandler = errorHandler; + } + initOptionMergeStrategies(appConfig.optionMergeStrategies); + const globalProperties = appConfig.globalProperties; + { + if (__UNI_FEATURE_UNI_CLOUD__) { + uniIdMixin(globalProperties); + } + } + { + globalProperties.$set = set; + globalProperties.$applyOptions = applyOptions; + } + { + uniShared.invokeCreateVueAppHook(app); + } +} const pageMetaKey = PolySymbol(process.env.NODE_ENV !== "production" ? "UniPageMeta" : "upm"); function usePageMeta() { return vue.inject(pageMetaKey); diff --git a/packages/uni-h5/dist/uni-h5.es.js b/packages/uni-h5/dist/uni-h5.es.js index dbf9bf9f7..6ba849cc2 100644 --- a/packages/uni-h5/dist/uni-h5.es.js +++ b/packages/uni-h5/dist/uni-h5.es.js @@ -1,6 +1,7 @@ -import { withModifiers, createVNode, getCurrentInstance, ref, defineComponent, openBlock, createElementBlock, provide, computed, watch, onUnmounted, inject, onBeforeUnmount, mergeProps, nextTick, injectHook, reactive, onActivated, onMounted, onBeforeMount, withDirectives, vShow, shallowRef, watchEffect, isVNode, Fragment, markRaw, Comment, createTextVNode, onBeforeActivate, onBeforeDeactivate, createBlock, renderList, onDeactivated, createApp, Transition, effectScope, withCtx, KeepAlive, resolveDynamicComponent, createElementVNode, normalizeStyle, renderSlot } from "vue"; +import { withModifiers, createVNode, getCurrentInstance, ref, defineComponent, openBlock, createElementBlock, provide, computed, watch, onUnmounted, inject, onBeforeUnmount, mergeProps, reactive, onActivated, onMounted, nextTick, onBeforeMount, withDirectives, vShow, shallowRef, watchEffect, isVNode, Fragment, markRaw, Comment, createTextVNode, injectHook, onBeforeActivate, onBeforeDeactivate, createBlock, renderList, onDeactivated, createApp, Transition, effectScope, withCtx, KeepAlive, resolveDynamicComponent, createElementVNode, normalizeStyle, renderSlot } from "vue"; import { isString, extend, stringifyStyle, parseStringStyle, isPlainObject, isFunction, capitalize, camelize, isArray, hasOwn, isObject, toRawType, makeMap as makeMap$1, isPromise, hyphenate, invokeArrayFns as invokeArrayFns$1 } from "@vue/shared"; -import { once, UNI_STORAGE_LOCALE, I18N_JSON_DELIMITERS, Emitter, passive, initCustomDatasetOnce, resolveComponentInstance, addLeadingSlash, invokeArrayFns, resolveOwnerVm, resolveOwnerEl, ON_WXS_INVOKE_CALL_METHOD, normalizeTarget, ON_RESIZE, ON_APP_ENTER_FOREGROUND, ON_APP_ENTER_BACKGROUND, ON_SHOW, ON_HIDE, ON_PAGE_SCROLL, ON_REACH_BOTTOM, EventChannel, SCHEME_RE, DATA_RE, getCustomDataset, LINEFEED, ON_ERROR, callOptions, PRIMARY_COLOR, removeLeadingSlash, getLen, ON_LOAD, UniLifecycleHooks, debounce, NAVBAR_HEIGHT, parseQuery, ON_UNLOAD, ON_REACH_BOTTOM_DISTANCE, decodedQuery, WEB_INVOKE_APPSERVICE, ON_WEB_INVOKE_APP_SERVICE, updateElementStyle, ON_BACK_PRESS, parseUrl, addFont, scrollTo, RESPONSIVE_MIN_WIDTH, formatDateTime, ON_NAVIGATION_BAR_BUTTON_TAP, ON_NAVIGATION_BAR_SEARCH_INPUT_CLICKED, ON_NAVIGATION_BAR_SEARCH_INPUT_FOCUS_CHANGED, ON_NAVIGATION_BAR_SEARCH_INPUT_CHANGED, ON_NAVIGATION_BAR_SEARCH_INPUT_CONFIRMED, ON_PULL_DOWN_REFRESH } from "@dcloudio/uni-shared"; +import { once, UNI_STORAGE_LOCALE, I18N_JSON_DELIMITERS, Emitter, passive, initCustomDatasetOnce, resolveComponentInstance, addLeadingSlash, invokeArrayFns, resolveOwnerVm, resolveOwnerEl, ON_WXS_INVOKE_CALL_METHOD, normalizeTarget, ON_RESIZE, ON_APP_ENTER_FOREGROUND, ON_APP_ENTER_BACKGROUND, ON_SHOW, ON_HIDE, ON_PAGE_SCROLL, ON_REACH_BOTTOM, EventChannel, SCHEME_RE, DATA_RE, getCustomDataset, LINEFEED, ON_ERROR, callOptions, PRIMARY_COLOR, removeLeadingSlash, getLen, debounce, ON_LOAD, UniLifecycleHooks, invokeCreateVueAppHook, NAVBAR_HEIGHT, parseQuery, ON_UNLOAD, ON_REACH_BOTTOM_DISTANCE, decodedQuery, WEB_INVOKE_APPSERVICE, ON_WEB_INVOKE_APP_SERVICE, updateElementStyle, ON_BACK_PRESS, parseUrl, addFont, scrollTo, RESPONSIVE_MIN_WIDTH, onCreateVueApp, formatDateTime, ON_NAVIGATION_BAR_BUTTON_TAP, ON_NAVIGATION_BAR_SEARCH_INPUT_CLICKED, ON_NAVIGATION_BAR_SEARCH_INPUT_FOCUS_CHANGED, ON_NAVIGATION_BAR_SEARCH_INPUT_CHANGED, ON_NAVIGATION_BAR_SEARCH_INPUT_CONFIRMED, ON_PULL_DOWN_REFRESH } from "@dcloudio/uni-shared"; +export { onCreateVueApp } from "@dcloudio/uni-shared"; import { initVueI18n, isI18nStr, LOCALE_EN, LOCALE_ES, LOCALE_FR, LOCALE_ZH_HANS, LOCALE_ZH_HANT } from "@dcloudio/uni-i18n"; import { useRoute, createRouter, createWebHistory, createWebHashHistory, useRouter, isNavigationFailure, RouterView } from "vue-router"; const isEnableLocale = /* @__PURE__ */ once(() => typeof __uniConfig !== "undefined" && __uniConfig.locales && !!Object.keys(__uniConfig.locales).length); @@ -5417,159 +5418,6 @@ const SetTabBarBadgeOptions = { } }, IndexOptions.formatArgs) }; -function injectLifecycleHook(name, hook, publicThis, instance2) { - if (isFunction(hook)) { - injectHook(name, hook.bind(publicThis), instance2); - } -} -function initHooks(options, instance2, publicThis) { - const mpType = options.mpType || publicThis.$mpType; - Object.keys(options).forEach((name) => { - if (name.indexOf("on") === 0) { - const hooks = options[name]; - if (isArray(hooks)) { - hooks.forEach((hook) => injectLifecycleHook(name, hook, publicThis, instance2)); - } else { - injectLifecycleHook(name, hooks, publicThis, instance2); - } - } - }); - if (mpType === "page") { - instance2.__isVisible = true; - try { - invokeHook(publicThis, ON_LOAD, instance2.attrs.__pageQuery); - delete instance2.attrs.__pageQuery; - } catch (e2) { - console.error(e2.message + LINEFEED + e2.stack); - } - nextTick(() => { - invokeHook(publicThis, ON_SHOW); - }); - } -} -function applyOptions(options, instance2, publicThis) { - initHooks(options, instance2, publicThis); -} -function set(target, key, val) { - return target[key] = val; -} -function errorHandler(err, instance2, info) { - if (!instance2) { - throw err; - } - const app = getApp(); - if (!app || !app.$vm) { - throw err; - } - { - invokeHook(app.$vm, ON_ERROR, err); - } -} -function mergeAsArray(to, from) { - return to ? [...new Set([].concat(to, from))] : from; -} -function initOptionMergeStrategies(optionMergeStrategies) { - UniLifecycleHooks.forEach((name) => { - optionMergeStrategies[name] = mergeAsArray; - }); -} -let realAtob; -const b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="; -const b64re = /^(?:[A-Za-z\d+/]{4})*?(?:[A-Za-z\d+/]{2}(?:==)?|[A-Za-z\d+/]{3}=?)?$/; -if (typeof atob !== "function") { - realAtob = function(str) { - str = String(str).replace(/[\t\n\f\r ]+/g, ""); - if (!b64re.test(str)) { - throw new Error("Failed to execute 'atob' on 'Window': The string to be decoded is not correctly encoded."); - } - str += "==".slice(2 - (str.length & 3)); - var bitmap; - var result = ""; - var r1; - var r2; - var i = 0; - for (; i < str.length; ) { - bitmap = b64.indexOf(str.charAt(i++)) << 18 | b64.indexOf(str.charAt(i++)) << 12 | (r1 = b64.indexOf(str.charAt(i++))) << 6 | (r2 = b64.indexOf(str.charAt(i++))); - result += r1 === 64 ? String.fromCharCode(bitmap >> 16 & 255) : r2 === 64 ? String.fromCharCode(bitmap >> 16 & 255, bitmap >> 8 & 255) : String.fromCharCode(bitmap >> 16 & 255, bitmap >> 8 & 255, bitmap & 255); - } - return result; - }; -} else { - realAtob = atob; -} -function b64DecodeUnicode(str) { - return decodeURIComponent(realAtob(str).split("").map(function(c) { - return "%" + ("00" + c.charCodeAt(0).toString(16)).slice(-2); - }).join("")); -} -function getCurrentUserInfo() { - const token = uni.getStorageSync("uni_id_token") || ""; - const tokenArr = token.split("."); - if (!token || tokenArr.length !== 3) { - return { - uid: null, - role: [], - permission: [], - tokenExpired: 0 - }; - } - let userInfo; - try { - userInfo = JSON.parse(b64DecodeUnicode(tokenArr[1])); - } catch (error) { - throw new Error("\u83B7\u53D6\u5F53\u524D\u7528\u6237\u4FE1\u606F\u51FA\u9519\uFF0C\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F\u4E3A\uFF1A" + error.message); - } - userInfo.tokenExpired = userInfo.exp * 1e3; - delete userInfo.exp; - delete userInfo.iat; - return userInfo; -} -function uniIdMixin(globalProperties) { - globalProperties.uniIDHasRole = function(roleId) { - const { role } = getCurrentUserInfo(); - return role.indexOf(roleId) > -1; - }; - globalProperties.uniIDHasPermission = function(permissionId) { - const { permission } = getCurrentUserInfo(); - return this.uniIDHasRole("admin") || permission.indexOf(permissionId) > -1; - }; - globalProperties.uniIDTokenValid = function() { - const { tokenExpired } = getCurrentUserInfo(); - return tokenExpired > Date.now(); - }; -} -let vueApp; -const createVueAppHooks = []; -function onCreateVueApp(hook) { - if (vueApp) { - return hook(vueApp); - } - createVueAppHooks.push(hook); -} -function invokeCreateVueAppHook(app) { - vueApp = app; - createVueAppHooks.forEach((hook) => hook(app)); -} -function initApp$1(app) { - const appConfig = app._context.config; - if (isFunction(app._component.onError)) { - appConfig.errorHandler = errorHandler; - } - initOptionMergeStrategies(appConfig.optionMergeStrategies); - const globalProperties = appConfig.globalProperties; - { - if (__UNI_FEATURE_UNI_CLOUD__) { - uniIdMixin(globalProperties); - } - } - { - globalProperties.$set = set; - globalProperties.$applyOptions = applyOptions; - } - { - invokeCreateVueAppHook(app); - } -} const initIntersectionObserverPolyfill = function() { if (typeof window !== "object") { return; @@ -13649,6 +13497,147 @@ function useContextInfo(_id) { function getContextInfo(el) { return el.__uniContextInfo; } +function injectLifecycleHook(name, hook, publicThis, instance2) { + if (isFunction(hook)) { + injectHook(name, hook.bind(publicThis), instance2); + } +} +function initHooks(options, instance2, publicThis) { + const mpType = options.mpType || publicThis.$mpType; + Object.keys(options).forEach((name) => { + if (name.indexOf("on") === 0) { + const hooks = options[name]; + if (isArray(hooks)) { + hooks.forEach((hook) => injectLifecycleHook(name, hook, publicThis, instance2)); + } else { + injectLifecycleHook(name, hooks, publicThis, instance2); + } + } + }); + if (mpType === "page") { + instance2.__isVisible = true; + try { + invokeHook(publicThis, ON_LOAD, instance2.attrs.__pageQuery); + delete instance2.attrs.__pageQuery; + } catch (e2) { + console.error(e2.message + LINEFEED + e2.stack); + } + nextTick(() => { + invokeHook(publicThis, ON_SHOW); + }); + } +} +function applyOptions(options, instance2, publicThis) { + initHooks(options, instance2, publicThis); +} +function set(target, key, val) { + return target[key] = val; +} +function errorHandler(err, instance2, info) { + if (!instance2) { + throw err; + } + const app = getApp(); + if (!app || !app.$vm) { + throw err; + } + { + invokeHook(app.$vm, ON_ERROR, err); + } +} +function mergeAsArray(to, from) { + return to ? [...new Set([].concat(to, from))] : from; +} +function initOptionMergeStrategies(optionMergeStrategies) { + UniLifecycleHooks.forEach((name) => { + optionMergeStrategies[name] = mergeAsArray; + }); +} +let realAtob; +const b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="; +const b64re = /^(?:[A-Za-z\d+/]{4})*?(?:[A-Za-z\d+/]{2}(?:==)?|[A-Za-z\d+/]{3}=?)?$/; +if (typeof atob !== "function") { + realAtob = function(str) { + str = String(str).replace(/[\t\n\f\r ]+/g, ""); + if (!b64re.test(str)) { + throw new Error("Failed to execute 'atob' on 'Window': The string to be decoded is not correctly encoded."); + } + str += "==".slice(2 - (str.length & 3)); + var bitmap; + var result = ""; + var r1; + var r2; + var i = 0; + for (; i < str.length; ) { + bitmap = b64.indexOf(str.charAt(i++)) << 18 | b64.indexOf(str.charAt(i++)) << 12 | (r1 = b64.indexOf(str.charAt(i++))) << 6 | (r2 = b64.indexOf(str.charAt(i++))); + result += r1 === 64 ? String.fromCharCode(bitmap >> 16 & 255) : r2 === 64 ? String.fromCharCode(bitmap >> 16 & 255, bitmap >> 8 & 255) : String.fromCharCode(bitmap >> 16 & 255, bitmap >> 8 & 255, bitmap & 255); + } + return result; + }; +} else { + realAtob = atob; +} +function b64DecodeUnicode(str) { + return decodeURIComponent(realAtob(str).split("").map(function(c) { + return "%" + ("00" + c.charCodeAt(0).toString(16)).slice(-2); + }).join("")); +} +function getCurrentUserInfo() { + const token = uni.getStorageSync("uni_id_token") || ""; + const tokenArr = token.split("."); + if (!token || tokenArr.length !== 3) { + return { + uid: null, + role: [], + permission: [], + tokenExpired: 0 + }; + } + let userInfo; + try { + userInfo = JSON.parse(b64DecodeUnicode(tokenArr[1])); + } catch (error) { + throw new Error("\u83B7\u53D6\u5F53\u524D\u7528\u6237\u4FE1\u606F\u51FA\u9519\uFF0C\u8BE6\u7EC6\u9519\u8BEF\u4FE1\u606F\u4E3A\uFF1A" + error.message); + } + userInfo.tokenExpired = userInfo.exp * 1e3; + delete userInfo.exp; + delete userInfo.iat; + return userInfo; +} +function uniIdMixin(globalProperties) { + globalProperties.uniIDHasRole = function(roleId) { + const { role } = getCurrentUserInfo(); + return role.indexOf(roleId) > -1; + }; + globalProperties.uniIDHasPermission = function(permissionId) { + const { permission } = getCurrentUserInfo(); + return this.uniIDHasRole("admin") || permission.indexOf(permissionId) > -1; + }; + globalProperties.uniIDTokenValid = function() { + const { tokenExpired } = getCurrentUserInfo(); + return tokenExpired > Date.now(); + }; +} +function initApp$1(app) { + const appConfig = app._context.config; + if (isFunction(app._component.onError)) { + appConfig.errorHandler = errorHandler; + } + initOptionMergeStrategies(appConfig.optionMergeStrategies); + const globalProperties = appConfig.globalProperties; + { + if (__UNI_FEATURE_UNI_CLOUD__) { + uniIdMixin(globalProperties); + } + } + { + globalProperties.$set = set; + globalProperties.$applyOptions = applyOptions; + } + { + invokeCreateVueAppHook(app); + } +} const pageMetaKey = PolySymbol(process.env.NODE_ENV !== "production" ? "UniPageMeta" : "upm"); function usePageMeta() { return inject(pageMetaKey); @@ -22015,4 +22004,4 @@ var index = /* @__PURE__ */ defineSystemComponent({ return openBlock(), createBlock("div", clazz, [loadingVNode]); } }); -export { $emit, $off, $on, $once, index$8 as Ad, index$7 as AdContentPage, index$6 as AdDraw, index$1 as AsyncErrorComponent, index as AsyncLoadingComponent, index$y as Button, index$5 as Camera, index$w as Canvas, index$u as Checkbox, index$v as CheckboxGroup, index$a as CoverImage, index$b as CoverView, index$t as Editor, index$A as Form, index$s as Icon, index$r as Image, Input, index$z as Label, LayoutComponent, index$4 as LivePlayer, index$3 as LivePusher, Map$1 as Map, MovableArea, MovableView, index$q as Navigator, index$2 as PageComponent, index$9 as Picker, PickerView, PickerViewColumn, index$p as Progress, index$n as Radio, index$o as RadioGroup, ResizeSensor, index$m as RichText, ScrollView, index$l as Slider, Swiper, SwiperItem, index$k as Switch, index$j as Text, index$i as Textarea, UniServiceJSBridge$1 as UniServiceJSBridge, UniViewJSBridge$1 as UniViewJSBridge, index$e as Video, index$h as View, index$d as WebView, addInterceptor, addPhoneContact, arrayBufferToBase64, base64ToArrayBuffer, canIUse, canvasGetImageData, canvasPutImageData, canvasToTempFilePath, chooseFile, chooseImage, chooseLocation, chooseVideo, clearStorage, clearStorageSync, closePreviewImage, closeSocket, connectSocket, createAnimation$1 as createAnimation, createCameraContext, createCanvasContext, createInnerAudioContext, createIntersectionObserver, createLivePlayerContext, createMapContext, createMediaQueryObserver, createSelectorQuery, createVideoContext, cssBackdropFilter, cssConstant, cssEnv, cssVar, downloadFile, getApp$1 as getApp, getClipboardData, getCurrentPages$1 as getCurrentPages, getEnterOptionsSync, getFileInfo, getImageInfo, getLaunchOptionsSync, getLeftWindowStyle, getLocale, getLocation, getNetworkType, getProvider, getPushCid, getRealPath, getRecorderManager, getRightWindowStyle, getSavedFileInfo, getSavedFileList, getScreenBrightness, getSelectedTextRange$1 as getSelectedTextRange, getStorage, getStorageInfo, getStorageInfoSync, getStorageSync, getSystemInfo, getSystemInfoSync, getTopWindowStyle, getVideoInfo, hideKeyboard, hideLeftWindow, hideLoading, hideNavigationBarLoading, hideRightWindow, hideTabBar, hideTabBarRedDot, hideToast, hideTopWindow, interceptors, invokePushCallback, loadFontFace, login, makePhoneCall, navigateBack, navigateTo, offAccelerometerChange, offCompassChange, offNetworkStatusChange, offPushMessage, offWindowResize, onAccelerometerChange, onCompassChange, onCreateVueApp, onGyroscopeChange, onLocaleChange, onMemoryWarning, onNetworkStatusChange, onPushMessage, onSocketClose, onSocketError, onSocketMessage, onSocketOpen, onTabBarMidButtonTap, onUserCaptureScreen, onWindowResize, openDocument, openLocation, pageScrollTo, index$f as plugin, preloadPage, previewImage, reLaunch, redirectTo, removeInterceptor, removeSavedFileInfo, removeStorage, removeStorageSync, removeTabBarBadge, request, saveFile, saveImageToPhotosAlbum, saveVideoToPhotosAlbum, scanCode, sendSocketMessage, setClipboardData, setKeepScreenOn, setLeftWindowStyle, setLocale, setNavigationBarColor, setNavigationBarTitle, setPageMeta, setRightWindowStyle, setScreenBrightness, setStorage, setStorageSync, setTabBarBadge, setTabBarItem, setTabBarStyle, setTopWindowStyle, setupApp, setupPage, setupWindow, showActionSheet, showLeftWindow, showLoading, showModal, showNavigationBarLoading, showRightWindow, showTabBar, showTabBarRedDot, showToast, showTopWindow, startAccelerometer, startCompass, startGyroscope, startPullDownRefresh, stopAccelerometer, stopCompass, stopGyroscope, stopPullDownRefresh, switchTab, uni$1 as uni, uploadFile, upx2px, useI18n, useTabBar, vibrateLong, vibrateShort }; +export { $emit, $off, $on, $once, index$8 as Ad, index$7 as AdContentPage, index$6 as AdDraw, index$1 as AsyncErrorComponent, index as AsyncLoadingComponent, index$y as Button, index$5 as Camera, index$w as Canvas, index$u as Checkbox, index$v as CheckboxGroup, index$a as CoverImage, index$b as CoverView, index$t as Editor, index$A as Form, index$s as Icon, index$r as Image, Input, index$z as Label, LayoutComponent, index$4 as LivePlayer, index$3 as LivePusher, Map$1 as Map, MovableArea, MovableView, index$q as Navigator, index$2 as PageComponent, index$9 as Picker, PickerView, PickerViewColumn, index$p as Progress, index$n as Radio, index$o as RadioGroup, ResizeSensor, index$m as RichText, ScrollView, index$l as Slider, Swiper, SwiperItem, index$k as Switch, index$j as Text, index$i as Textarea, UniServiceJSBridge$1 as UniServiceJSBridge, UniViewJSBridge$1 as UniViewJSBridge, index$e as Video, index$h as View, index$d as WebView, addInterceptor, addPhoneContact, arrayBufferToBase64, base64ToArrayBuffer, canIUse, canvasGetImageData, canvasPutImageData, canvasToTempFilePath, chooseFile, chooseImage, chooseLocation, chooseVideo, clearStorage, clearStorageSync, closePreviewImage, closeSocket, connectSocket, createAnimation$1 as createAnimation, createCameraContext, createCanvasContext, createInnerAudioContext, createIntersectionObserver, createLivePlayerContext, createMapContext, createMediaQueryObserver, createSelectorQuery, createVideoContext, cssBackdropFilter, cssConstant, cssEnv, cssVar, downloadFile, getApp$1 as getApp, getClipboardData, getCurrentPages$1 as getCurrentPages, getEnterOptionsSync, getFileInfo, getImageInfo, getLaunchOptionsSync, getLeftWindowStyle, getLocale, getLocation, getNetworkType, getProvider, getPushCid, getRealPath, getRecorderManager, getRightWindowStyle, getSavedFileInfo, getSavedFileList, getScreenBrightness, getSelectedTextRange$1 as getSelectedTextRange, getStorage, getStorageInfo, getStorageInfoSync, getStorageSync, getSystemInfo, getSystemInfoSync, getTopWindowStyle, getVideoInfo, hideKeyboard, hideLeftWindow, hideLoading, hideNavigationBarLoading, hideRightWindow, hideTabBar, hideTabBarRedDot, hideToast, hideTopWindow, interceptors, invokePushCallback, loadFontFace, login, makePhoneCall, navigateBack, navigateTo, offAccelerometerChange, offCompassChange, offNetworkStatusChange, offPushMessage, offWindowResize, onAccelerometerChange, onCompassChange, onGyroscopeChange, onLocaleChange, onMemoryWarning, onNetworkStatusChange, onPushMessage, onSocketClose, onSocketError, onSocketMessage, onSocketOpen, onTabBarMidButtonTap, onUserCaptureScreen, onWindowResize, openDocument, openLocation, pageScrollTo, index$f as plugin, preloadPage, previewImage, reLaunch, redirectTo, removeInterceptor, removeSavedFileInfo, removeStorage, removeStorageSync, removeTabBarBadge, request, saveFile, saveImageToPhotosAlbum, saveVideoToPhotosAlbum, scanCode, sendSocketMessage, setClipboardData, setKeepScreenOn, setLeftWindowStyle, setLocale, setNavigationBarColor, setNavigationBarTitle, setPageMeta, setRightWindowStyle, setScreenBrightness, setStorage, setStorageSync, setTabBarBadge, setTabBarItem, setTabBarStyle, setTopWindowStyle, setupApp, setupPage, setupWindow, showActionSheet, showLeftWindow, showLoading, showModal, showNavigationBarLoading, showRightWindow, showTabBar, showTabBarRedDot, showToast, showTopWindow, startAccelerometer, startCompass, startGyroscope, startPullDownRefresh, stopAccelerometer, stopCompass, stopGyroscope, stopPullDownRefresh, switchTab, uni$1 as uni, uploadFile, upx2px, useI18n, useTabBar, vibrateLong, vibrateShort }; diff --git a/packages/uni-mp-alipay/dist/uni.api.esm.js b/packages/uni-mp-alipay/dist/uni.api.esm.js index 9097489cb..b5619b63e 100644 --- a/packages/uni-mp-alipay/dist/uni.api.esm.js +++ b/packages/uni-mp-alipay/dist/uni.api.esm.js @@ -1,5 +1,23 @@ import { isArray, hasOwn, isString, isPlainObject, isObject, capitalize, toRawType, makeMap, isFunction, isPromise, extend } from '@vue/shared'; +let vueApp; +const createVueAppHooks = []; +/** + * 提供 createApp 的回调事件,方便三方插件接收 App 对象,处理挂靠全局 mixin 之类的逻辑 + * @param hook + */ +function onCreateVueApp(hook) { + // TODO 每个 nvue 页面都会触发 + if (vueApp) { + return hook(vueApp); + } + createVueAppHooks.push(hook); +} +function invokeCreateVueAppHook(app) { + vueApp = app; + createVueAppHooks.forEach((hook) => hook(app)); +} + const eventChannels = {}; const eventChannelStack = []; let id = 0; @@ -661,24 +679,6 @@ const offPushMessage = (fn) => { } }; -let vueApp; -const createVueAppHooks = []; -/** - * 提供 createApp 的回调事件,方便三方插件接收 App 对象,处理挂靠全局 mixin 之类的逻辑 - * @param hook - */ -function onCreateVueApp(hook) { - // TODO 每个 nvue 页面都会触发 - if (vueApp) { - return hook(vueApp); - } - createVueAppHooks.push(hook); -} -function invokeCreateVueAppHook(app) { - vueApp = app; - createVueAppHooks.forEach((hook) => hook(app)); -} - const SYNC_API_RE = /^\$|getLocale|setLocale|sendNativeEvent|restoreGlobal|getCurrentSubNVue|getMenuButtonBoundingClientRect|^report|interceptors|Interceptor$|getSubNVueById|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$|base64ToArrayBuffer|arrayBufferToBase64/; const CONTEXT_API_RE = /^create|Manager$/; // Context例外情况 diff --git a/packages/uni-mp-baidu/dist/uni.api.esm.js b/packages/uni-mp-baidu/dist/uni.api.esm.js index c978a158a..b9841620b 100644 --- a/packages/uni-mp-baidu/dist/uni.api.esm.js +++ b/packages/uni-mp-baidu/dist/uni.api.esm.js @@ -1,5 +1,23 @@ import { isArray, hasOwn, isString, isPlainObject, isObject, capitalize, toRawType, makeMap, isFunction, isPromise, extend } from '@vue/shared'; +let vueApp; +const createVueAppHooks = []; +/** + * 提供 createApp 的回调事件,方便三方插件接收 App 对象,处理挂靠全局 mixin 之类的逻辑 + * @param hook + */ +function onCreateVueApp(hook) { + // TODO 每个 nvue 页面都会触发 + if (vueApp) { + return hook(vueApp); + } + createVueAppHooks.push(hook); +} +function invokeCreateVueAppHook(app) { + vueApp = app; + createVueAppHooks.forEach((hook) => hook(app)); +} + const eventChannels = {}; const eventChannelStack = []; let id = 0; @@ -661,24 +679,6 @@ const offPushMessage = (fn) => { } }; -let vueApp; -const createVueAppHooks = []; -/** - * 提供 createApp 的回调事件,方便三方插件接收 App 对象,处理挂靠全局 mixin 之类的逻辑 - * @param hook - */ -function onCreateVueApp(hook) { - // TODO 每个 nvue 页面都会触发 - if (vueApp) { - return hook(vueApp); - } - createVueAppHooks.push(hook); -} -function invokeCreateVueAppHook(app) { - vueApp = app; - createVueAppHooks.forEach((hook) => hook(app)); -} - const SYNC_API_RE = /^\$|getLocale|setLocale|sendNativeEvent|restoreGlobal|getCurrentSubNVue|getMenuButtonBoundingClientRect|^report|interceptors|Interceptor$|getSubNVueById|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$|base64ToArrayBuffer|arrayBufferToBase64/; const CONTEXT_API_RE = /^create|Manager$/; // Context例外情况 diff --git a/packages/uni-mp-core/src/api/index.ts b/packages/uni-mp-core/src/api/index.ts index 076291f79..9b2e3debd 100644 --- a/packages/uni-mp-core/src/api/index.ts +++ b/packages/uni-mp-core/src/api/index.ts @@ -18,7 +18,7 @@ import { offPushMessage, invokePushCallback, } from '@dcloudio/uni-api/src/service/plugin/push' -import { invokeCreateVueAppHook, onCreateVueApp } from '@dcloudio/uni-vue' +import { invokeCreateVueAppHook, onCreateVueApp } from '@dcloudio/uni-shared' import { promisify } from './promise' import { initWrapper } from './wrapper' diff --git a/packages/uni-mp-kuaishou/dist/uni.api.esm.js b/packages/uni-mp-kuaishou/dist/uni.api.esm.js index 0c5ed88e6..aebe12758 100644 --- a/packages/uni-mp-kuaishou/dist/uni.api.esm.js +++ b/packages/uni-mp-kuaishou/dist/uni.api.esm.js @@ -1,5 +1,23 @@ import { isArray, hasOwn, isString, isPlainObject, isObject, capitalize, toRawType, makeMap, isFunction, isPromise, extend } from '@vue/shared'; +let vueApp; +const createVueAppHooks = []; +/** + * 提供 createApp 的回调事件,方便三方插件接收 App 对象,处理挂靠全局 mixin 之类的逻辑 + * @param hook + */ +function onCreateVueApp(hook) { + // TODO 每个 nvue 页面都会触发 + if (vueApp) { + return hook(vueApp); + } + createVueAppHooks.push(hook); +} +function invokeCreateVueAppHook(app) { + vueApp = app; + createVueAppHooks.forEach((hook) => hook(app)); +} + const eventChannels = {}; const eventChannelStack = []; let id = 0; @@ -661,24 +679,6 @@ const offPushMessage = (fn) => { } }; -let vueApp; -const createVueAppHooks = []; -/** - * 提供 createApp 的回调事件,方便三方插件接收 App 对象,处理挂靠全局 mixin 之类的逻辑 - * @param hook - */ -function onCreateVueApp(hook) { - // TODO 每个 nvue 页面都会触发 - if (vueApp) { - return hook(vueApp); - } - createVueAppHooks.push(hook); -} -function invokeCreateVueAppHook(app) { - vueApp = app; - createVueAppHooks.forEach((hook) => hook(app)); -} - const SYNC_API_RE = /^\$|getLocale|setLocale|sendNativeEvent|restoreGlobal|getCurrentSubNVue|getMenuButtonBoundingClientRect|^report|interceptors|Interceptor$|getSubNVueById|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$|base64ToArrayBuffer|arrayBufferToBase64/; const CONTEXT_API_RE = /^create|Manager$/; // Context例外情况 diff --git a/packages/uni-mp-lark/dist/uni.api.esm.js b/packages/uni-mp-lark/dist/uni.api.esm.js index 9edd88fc5..3fac7651c 100644 --- a/packages/uni-mp-lark/dist/uni.api.esm.js +++ b/packages/uni-mp-lark/dist/uni.api.esm.js @@ -1,5 +1,23 @@ import { isArray, hasOwn, isString, isPlainObject, isObject, capitalize, toRawType, makeMap, isFunction, isPromise, extend } from '@vue/shared'; +let vueApp; +const createVueAppHooks = []; +/** + * 提供 createApp 的回调事件,方便三方插件接收 App 对象,处理挂靠全局 mixin 之类的逻辑 + * @param hook + */ +function onCreateVueApp(hook) { + // TODO 每个 nvue 页面都会触发 + if (vueApp) { + return hook(vueApp); + } + createVueAppHooks.push(hook); +} +function invokeCreateVueAppHook(app) { + vueApp = app; + createVueAppHooks.forEach((hook) => hook(app)); +} + const eventChannels = {}; const eventChannelStack = []; let id = 0; @@ -661,24 +679,6 @@ const offPushMessage = (fn) => { } }; -let vueApp; -const createVueAppHooks = []; -/** - * 提供 createApp 的回调事件,方便三方插件接收 App 对象,处理挂靠全局 mixin 之类的逻辑 - * @param hook - */ -function onCreateVueApp(hook) { - // TODO 每个 nvue 页面都会触发 - if (vueApp) { - return hook(vueApp); - } - createVueAppHooks.push(hook); -} -function invokeCreateVueAppHook(app) { - vueApp = app; - createVueAppHooks.forEach((hook) => hook(app)); -} - const SYNC_API_RE = /^\$|getLocale|setLocale|sendNativeEvent|restoreGlobal|getCurrentSubNVue|getMenuButtonBoundingClientRect|^report|interceptors|Interceptor$|getSubNVueById|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$|base64ToArrayBuffer|arrayBufferToBase64/; const CONTEXT_API_RE = /^create|Manager$/; // Context例外情况 diff --git a/packages/uni-mp-qq/dist/uni.api.esm.js b/packages/uni-mp-qq/dist/uni.api.esm.js index 0a467fbe8..dc26037b0 100644 --- a/packages/uni-mp-qq/dist/uni.api.esm.js +++ b/packages/uni-mp-qq/dist/uni.api.esm.js @@ -1,5 +1,23 @@ import { isArray, hasOwn, isString, isPlainObject, isObject, capitalize, toRawType, makeMap, isFunction, isPromise, extend } from '@vue/shared'; +let vueApp; +const createVueAppHooks = []; +/** + * 提供 createApp 的回调事件,方便三方插件接收 App 对象,处理挂靠全局 mixin 之类的逻辑 + * @param hook + */ +function onCreateVueApp(hook) { + // TODO 每个 nvue 页面都会触发 + if (vueApp) { + return hook(vueApp); + } + createVueAppHooks.push(hook); +} +function invokeCreateVueAppHook(app) { + vueApp = app; + createVueAppHooks.forEach((hook) => hook(app)); +} + const eventChannels = {}; const eventChannelStack = []; let id = 0; @@ -661,24 +679,6 @@ const offPushMessage = (fn) => { } }; -let vueApp; -const createVueAppHooks = []; -/** - * 提供 createApp 的回调事件,方便三方插件接收 App 对象,处理挂靠全局 mixin 之类的逻辑 - * @param hook - */ -function onCreateVueApp(hook) { - // TODO 每个 nvue 页面都会触发 - if (vueApp) { - return hook(vueApp); - } - createVueAppHooks.push(hook); -} -function invokeCreateVueAppHook(app) { - vueApp = app; - createVueAppHooks.forEach((hook) => hook(app)); -} - const SYNC_API_RE = /^\$|getLocale|setLocale|sendNativeEvent|restoreGlobal|getCurrentSubNVue|getMenuButtonBoundingClientRect|^report|interceptors|Interceptor$|getSubNVueById|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$|base64ToArrayBuffer|arrayBufferToBase64/; const CONTEXT_API_RE = /^create|Manager$/; // Context例外情况 diff --git a/packages/uni-mp-toutiao/dist/uni.api.esm.js b/packages/uni-mp-toutiao/dist/uni.api.esm.js index 4368b92c7..09d30b7d5 100644 --- a/packages/uni-mp-toutiao/dist/uni.api.esm.js +++ b/packages/uni-mp-toutiao/dist/uni.api.esm.js @@ -1,5 +1,23 @@ import { isArray, hasOwn, isString, isPlainObject, isObject, capitalize, toRawType, makeMap, isFunction, isPromise, extend } from '@vue/shared'; +let vueApp; +const createVueAppHooks = []; +/** + * 提供 createApp 的回调事件,方便三方插件接收 App 对象,处理挂靠全局 mixin 之类的逻辑 + * @param hook + */ +function onCreateVueApp(hook) { + // TODO 每个 nvue 页面都会触发 + if (vueApp) { + return hook(vueApp); + } + createVueAppHooks.push(hook); +} +function invokeCreateVueAppHook(app) { + vueApp = app; + createVueAppHooks.forEach((hook) => hook(app)); +} + const eventChannels = {}; const eventChannelStack = []; let id = 0; @@ -661,24 +679,6 @@ const offPushMessage = (fn) => { } }; -let vueApp; -const createVueAppHooks = []; -/** - * 提供 createApp 的回调事件,方便三方插件接收 App 对象,处理挂靠全局 mixin 之类的逻辑 - * @param hook - */ -function onCreateVueApp(hook) { - // TODO 每个 nvue 页面都会触发 - if (vueApp) { - return hook(vueApp); - } - createVueAppHooks.push(hook); -} -function invokeCreateVueAppHook(app) { - vueApp = app; - createVueAppHooks.forEach((hook) => hook(app)); -} - const SYNC_API_RE = /^\$|getLocale|setLocale|sendNativeEvent|restoreGlobal|getCurrentSubNVue|getMenuButtonBoundingClientRect|^report|interceptors|Interceptor$|getSubNVueById|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$|base64ToArrayBuffer|arrayBufferToBase64/; const CONTEXT_API_RE = /^create|Manager$/; // Context例外情况 diff --git a/packages/uni-mp-weixin/dist/uni.api.esm.js b/packages/uni-mp-weixin/dist/uni.api.esm.js index ed39b3492..d0c95dd32 100644 --- a/packages/uni-mp-weixin/dist/uni.api.esm.js +++ b/packages/uni-mp-weixin/dist/uni.api.esm.js @@ -1,5 +1,23 @@ import { isArray, hasOwn, isString, isPlainObject, isObject, capitalize, toRawType, makeMap, isFunction, isPromise, extend } from '@vue/shared'; +let vueApp; +const createVueAppHooks = []; +/** + * 提供 createApp 的回调事件,方便三方插件接收 App 对象,处理挂靠全局 mixin 之类的逻辑 + * @param hook + */ +function onCreateVueApp(hook) { + // TODO 每个 nvue 页面都会触发 + if (vueApp) { + return hook(vueApp); + } + createVueAppHooks.push(hook); +} +function invokeCreateVueAppHook(app) { + vueApp = app; + createVueAppHooks.forEach((hook) => hook(app)); +} + function getBaseSystemInfo() { return wx.getSystemInfoSync() } @@ -625,24 +643,6 @@ const offPushMessage = (fn) => { } }; -let vueApp; -const createVueAppHooks = []; -/** - * 提供 createApp 的回调事件,方便三方插件接收 App 对象,处理挂靠全局 mixin 之类的逻辑 - * @param hook - */ -function onCreateVueApp(hook) { - // TODO 每个 nvue 页面都会触发 - if (vueApp) { - return hook(vueApp); - } - createVueAppHooks.push(hook); -} -function invokeCreateVueAppHook(app) { - vueApp = app; - createVueAppHooks.forEach((hook) => hook(app)); -} - const SYNC_API_RE = /^\$|getLocale|setLocale|sendNativeEvent|restoreGlobal|getCurrentSubNVue|getMenuButtonBoundingClientRect|^report|interceptors|Interceptor$|getSubNVueById|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$|base64ToArrayBuffer|arrayBufferToBase64/; const CONTEXT_API_RE = /^create|Manager$/; // Context例外情况 diff --git a/packages/uni-quickapp-webview/dist/uni.api.esm.js b/packages/uni-quickapp-webview/dist/uni.api.esm.js index bf26c5c65..b8e03aaf7 100644 --- a/packages/uni-quickapp-webview/dist/uni.api.esm.js +++ b/packages/uni-quickapp-webview/dist/uni.api.esm.js @@ -1,5 +1,23 @@ import { isArray, hasOwn, isString, isPlainObject, isObject, capitalize, toRawType, makeMap, isFunction, isPromise, extend } from '@vue/shared'; +let vueApp; +const createVueAppHooks = []; +/** + * 提供 createApp 的回调事件,方便三方插件接收 App 对象,处理挂靠全局 mixin 之类的逻辑 + * @param hook + */ +function onCreateVueApp(hook) { + // TODO 每个 nvue 页面都会触发 + if (vueApp) { + return hook(vueApp); + } + createVueAppHooks.push(hook); +} +function invokeCreateVueAppHook(app) { + vueApp = app; + createVueAppHooks.forEach((hook) => hook(app)); +} + const eventChannels = {}; const eventChannelStack = []; let id = 0; @@ -661,24 +679,6 @@ const offPushMessage = (fn) => { } }; -let vueApp; -const createVueAppHooks = []; -/** - * 提供 createApp 的回调事件,方便三方插件接收 App 对象,处理挂靠全局 mixin 之类的逻辑 - * @param hook - */ -function onCreateVueApp(hook) { - // TODO 每个 nvue 页面都会触发 - if (vueApp) { - return hook(vueApp); - } - createVueAppHooks.push(hook); -} -function invokeCreateVueAppHook(app) { - vueApp = app; - createVueAppHooks.forEach((hook) => hook(app)); -} - const SYNC_API_RE = /^\$|getLocale|setLocale|sendNativeEvent|restoreGlobal|getCurrentSubNVue|getMenuButtonBoundingClientRect|^report|interceptors|Interceptor$|getSubNVueById|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$|base64ToArrayBuffer|arrayBufferToBase64/; const CONTEXT_API_RE = /^create|Manager$/; // Context例外情况 diff --git a/packages/uni-shared/dist/uni-shared.cjs.js b/packages/uni-shared/dist/uni-shared.cjs.js index ca42fafb2..01e3b1246 100644 --- a/packages/uni-shared/dist/uni-shared.cjs.js +++ b/packages/uni-shared/dist/uni-shared.cjs.js @@ -1294,6 +1294,24 @@ const MINI_PROGRAM_PAGE_RUNTIME_HOOKS = /*#__PURE__*/ (() => { }; })(); +let vueApp; +const createVueAppHooks = []; +/** + * 提供 createApp 的回调事件,方便三方插件接收 App 对象,处理挂靠全局 mixin 之类的逻辑 + * @param hook + */ +function onCreateVueApp(hook) { + // TODO 每个 nvue 页面都会触发 + if (vueApp) { + return hook(vueApp); + } + createVueAppHooks.push(hook); +} +function invokeCreateVueAppHook(app) { + vueApp = app; + createVueAppHooks.forEach((hook) => hook(app)); +} + const E = function () { // Keep this empty so it's easier to inherit from // (via https://github.com/lipsmack from https://github.com/scottcorgan/tiny-emitter/issues/3) @@ -1477,6 +1495,7 @@ exports.getLen = getLen; exports.getValueByDataPath = getValueByDataPath; exports.initCustomDatasetOnce = initCustomDatasetOnce; exports.invokeArrayFns = invokeArrayFns; +exports.invokeCreateVueAppHook = invokeCreateVueAppHook; exports.isAppNVueNativeTag = isAppNVueNativeTag; exports.isAppNativeTag = isAppNativeTag; exports.isBuiltInComponent = isBuiltInComponent; @@ -1489,6 +1508,7 @@ exports.isRootHook = isRootHook; exports.normalizeDataset = normalizeDataset; exports.normalizeEventType = normalizeEventType; exports.normalizeTarget = normalizeTarget; +exports.onCreateVueApp = onCreateVueApp; exports.once = once; exports.parseEventName = parseEventName; exports.parseQuery = parseQuery; diff --git a/packages/uni-shared/dist/uni-shared.d.ts b/packages/uni-shared/dist/uni-shared.d.ts index a6be5fa5a..5c426dd7f 100644 --- a/packages/uni-shared/dist/uni-shared.d.ts +++ b/packages/uni-shared/dist/uni-shared.d.ts @@ -1,3 +1,4 @@ +import type { App } from 'vue'; import type { ComponentInternalInstance } from '@vue/runtime-core'; import { ComponentOptionsBase } from '@vue/runtime-core'; import type { ComponentPublicInstance } from '@vue/runtime-core'; @@ -122,6 +123,8 @@ export declare function createRpx2Unit(unit: string, unitRatio: number, unitPrec export declare function createUniEvent(evt: Record): UniEvent; +declare type CreateVueAppHook = (app: App) => void; + export declare function customizeEvent(str: string): string; export declare const DATA_RE: RegExp; @@ -242,6 +245,8 @@ export declare type InsertAction = [typeof ACTION_TYPE_INSERT, number, number, n export declare const invokeArrayFns: (fns: Function[], arg?: any) => any; +export declare function invokeCreateVueAppHook(app: App): void; + export declare function isAppNativeTag(tag: string): boolean; export declare function isAppNVueNativeTag(tag: string): boolean; @@ -476,6 +481,12 @@ export declare const ON_WXS_INVOKE_CALL_METHOD = "onWxsInvokeCallMethod"; export declare function once any>(fn: T, ctx?: unknown): T; +/** + * 提供 createApp 的回调事件,方便三方插件接收 App 对象,处理挂靠全局 mixin 之类的逻辑 + * @param hook + */ +export declare function onCreateVueApp(hook: CreateVueAppHook): void; + declare interface Options { success?: (res: any) => void; fail?: (res: any) => void; diff --git a/packages/uni-shared/dist/uni-shared.es.js b/packages/uni-shared/dist/uni-shared.es.js index be3207f24..1aa2498e1 100644 --- a/packages/uni-shared/dist/uni-shared.es.js +++ b/packages/uni-shared/dist/uni-shared.es.js @@ -1290,6 +1290,24 @@ const MINI_PROGRAM_PAGE_RUNTIME_HOOKS = /*#__PURE__*/ (() => { }; })(); +let vueApp; +const createVueAppHooks = []; +/** + * 提供 createApp 的回调事件,方便三方插件接收 App 对象,处理挂靠全局 mixin 之类的逻辑 + * @param hook + */ +function onCreateVueApp(hook) { + // TODO 每个 nvue 页面都会触发 + if (vueApp) { + return hook(vueApp); + } + createVueAppHooks.push(hook); +} +function invokeCreateVueAppHook(app) { + vueApp = app; + createVueAppHooks.forEach((hook) => hook(app)); +} + const E = function () { // Keep this empty so it's easier to inherit from // (via https://github.com/lipsmack from https://github.com/scottcorgan/tiny-emitter/issues/3) @@ -1347,4 +1365,4 @@ function getEnvLocale() { return (lang && lang.replace(/[.:].*/, '')) || 'en'; } -export { ACTION_TYPE_ADD_EVENT, ACTION_TYPE_ADD_WXS_EVENT, ACTION_TYPE_CREATE, ACTION_TYPE_EVENT, ACTION_TYPE_INSERT, ACTION_TYPE_PAGE_CREATE, ACTION_TYPE_PAGE_CREATED, ACTION_TYPE_PAGE_SCROLL, ACTION_TYPE_REMOVE, ACTION_TYPE_REMOVE_ATTRIBUTE, ACTION_TYPE_REMOVE_EVENT, ACTION_TYPE_SET_ATTRIBUTE, ACTION_TYPE_SET_TEXT, ATTR_CHANGE_PREFIX, ATTR_CLASS, ATTR_INNER_HTML, ATTR_STYLE, ATTR_TEXT_CONTENT, ATTR_V_OWNER_ID, ATTR_V_RENDERJS, ATTR_V_SHOW, BACKGROUND_COLOR, BUILT_IN_TAGS, BUILT_IN_TAG_NAMES, COMPONENT_NAME_PREFIX, COMPONENT_PREFIX, COMPONENT_SELECTOR_PREFIX, DATA_RE, E$1 as Emitter, EventChannel, EventModifierFlags, I18N_JSON_DELIMITERS, JSON_PROTOCOL, LINEFEED, MINI_PROGRAM_PAGE_RUNTIME_HOOKS, NAVBAR_HEIGHT, NODE_TYPE_COMMENT, NODE_TYPE_ELEMENT, NODE_TYPE_PAGE, NODE_TYPE_TEXT, NVUE_BUILT_IN_TAGS, NVUE_U_BUILT_IN_TAGS, ON_ADD_TO_FAVORITES, ON_APP_ENTER_BACKGROUND, ON_APP_ENTER_FOREGROUND, ON_BACK_PRESS, ON_ERROR, ON_HIDE, ON_KEYBOARD_HEIGHT_CHANGE, ON_LAUNCH, ON_LOAD, ON_NAVIGATION_BAR_BUTTON_TAP, ON_NAVIGATION_BAR_SEARCH_INPUT_CHANGED, ON_NAVIGATION_BAR_SEARCH_INPUT_CLICKED, ON_NAVIGATION_BAR_SEARCH_INPUT_CONFIRMED, ON_NAVIGATION_BAR_SEARCH_INPUT_FOCUS_CHANGED, ON_PAGE_NOT_FOUND, ON_PAGE_SCROLL, ON_PULL_DOWN_REFRESH, ON_REACH_BOTTOM, ON_REACH_BOTTOM_DISTANCE, ON_READY, ON_RESIZE, ON_SHARE_APP_MESSAGE, ON_SHARE_TIMELINE, ON_SHOW, ON_TAB_ITEM_TAP, ON_THEME_CHANGE, ON_UNHANDLE_REJECTION, ON_UNLOAD, ON_WEB_INVOKE_APP_SERVICE, ON_WXS_INVOKE_CALL_METHOD, PLUS_RE, PRIMARY_COLOR, RENDERJS_MODULES, RESPONSIVE_MIN_WIDTH, SCHEME_RE, SELECTED_COLOR, SLOT_DEFAULT_NAME, TABBAR_HEIGHT, TAGS, UNI_SSR, UNI_SSR_DATA, UNI_SSR_GLOBAL_DATA, UNI_SSR_STORE, UNI_SSR_TITLE, UNI_STORAGE_LOCALE, UniBaseNode, UniCommentNode, UniElement, UniEvent, UniInputElement, UniLifecycleHooks, UniNode, UniTextAreaElement, UniTextNode, WEB_INVOKE_APPSERVICE, WXS_MODULES, WXS_PROTOCOL, addFont, addLeadingSlash, cache, cacheStringFunction, callOptions, createIsCustomElement, createRpx2Unit, createUniEvent, customizeEvent, debounce, decode, decodedQuery, defaultMiniProgramRpx2Unit, defaultNVueRpx2Unit, defaultRpx2Unit, dynamicSlotName, forcePatchProp, formatAppLog, formatDateTime, formatH5Log, formatLog, getCustomDataset, getEnvLocale, getLen, getValueByDataPath, initCustomDatasetOnce, invokeArrayFns, isAppNVueNativeTag, isAppNativeTag, isBuiltInComponent, isComponentInternalInstance, isComponentTag, isH5CustomElement, isH5NativeTag, isMiniProgramNativeTag, isRootHook, normalizeDataset, normalizeEventType, normalizeTarget, once, parseEventName, parseQuery, parseUrl, passive, plusReady, removeLeadingSlash, resolveComponentInstance, resolveOwnerEl, resolveOwnerVm, sanitise, scrollTo, stringifyQuery, updateElementStyle }; +export { ACTION_TYPE_ADD_EVENT, ACTION_TYPE_ADD_WXS_EVENT, ACTION_TYPE_CREATE, ACTION_TYPE_EVENT, ACTION_TYPE_INSERT, ACTION_TYPE_PAGE_CREATE, ACTION_TYPE_PAGE_CREATED, ACTION_TYPE_PAGE_SCROLL, ACTION_TYPE_REMOVE, ACTION_TYPE_REMOVE_ATTRIBUTE, ACTION_TYPE_REMOVE_EVENT, ACTION_TYPE_SET_ATTRIBUTE, ACTION_TYPE_SET_TEXT, ATTR_CHANGE_PREFIX, ATTR_CLASS, ATTR_INNER_HTML, ATTR_STYLE, ATTR_TEXT_CONTENT, ATTR_V_OWNER_ID, ATTR_V_RENDERJS, ATTR_V_SHOW, BACKGROUND_COLOR, BUILT_IN_TAGS, BUILT_IN_TAG_NAMES, COMPONENT_NAME_PREFIX, COMPONENT_PREFIX, COMPONENT_SELECTOR_PREFIX, DATA_RE, E$1 as Emitter, EventChannel, EventModifierFlags, I18N_JSON_DELIMITERS, JSON_PROTOCOL, LINEFEED, MINI_PROGRAM_PAGE_RUNTIME_HOOKS, NAVBAR_HEIGHT, NODE_TYPE_COMMENT, NODE_TYPE_ELEMENT, NODE_TYPE_PAGE, NODE_TYPE_TEXT, NVUE_BUILT_IN_TAGS, NVUE_U_BUILT_IN_TAGS, ON_ADD_TO_FAVORITES, ON_APP_ENTER_BACKGROUND, ON_APP_ENTER_FOREGROUND, ON_BACK_PRESS, ON_ERROR, ON_HIDE, ON_KEYBOARD_HEIGHT_CHANGE, ON_LAUNCH, ON_LOAD, ON_NAVIGATION_BAR_BUTTON_TAP, ON_NAVIGATION_BAR_SEARCH_INPUT_CHANGED, ON_NAVIGATION_BAR_SEARCH_INPUT_CLICKED, ON_NAVIGATION_BAR_SEARCH_INPUT_CONFIRMED, ON_NAVIGATION_BAR_SEARCH_INPUT_FOCUS_CHANGED, ON_PAGE_NOT_FOUND, ON_PAGE_SCROLL, ON_PULL_DOWN_REFRESH, ON_REACH_BOTTOM, ON_REACH_BOTTOM_DISTANCE, ON_READY, ON_RESIZE, ON_SHARE_APP_MESSAGE, ON_SHARE_TIMELINE, ON_SHOW, ON_TAB_ITEM_TAP, ON_THEME_CHANGE, ON_UNHANDLE_REJECTION, ON_UNLOAD, ON_WEB_INVOKE_APP_SERVICE, ON_WXS_INVOKE_CALL_METHOD, PLUS_RE, PRIMARY_COLOR, RENDERJS_MODULES, RESPONSIVE_MIN_WIDTH, SCHEME_RE, SELECTED_COLOR, SLOT_DEFAULT_NAME, TABBAR_HEIGHT, TAGS, UNI_SSR, UNI_SSR_DATA, UNI_SSR_GLOBAL_DATA, UNI_SSR_STORE, UNI_SSR_TITLE, UNI_STORAGE_LOCALE, UniBaseNode, UniCommentNode, UniElement, UniEvent, UniInputElement, UniLifecycleHooks, UniNode, UniTextAreaElement, UniTextNode, WEB_INVOKE_APPSERVICE, WXS_MODULES, WXS_PROTOCOL, addFont, addLeadingSlash, cache, cacheStringFunction, callOptions, createIsCustomElement, createRpx2Unit, createUniEvent, customizeEvent, debounce, decode, decodedQuery, defaultMiniProgramRpx2Unit, defaultNVueRpx2Unit, defaultRpx2Unit, dynamicSlotName, forcePatchProp, formatAppLog, formatDateTime, formatH5Log, formatLog, getCustomDataset, getEnvLocale, getLen, getValueByDataPath, initCustomDatasetOnce, invokeArrayFns, invokeCreateVueAppHook, isAppNVueNativeTag, isAppNativeTag, isBuiltInComponent, isComponentInternalInstance, isComponentTag, isH5CustomElement, isH5NativeTag, isMiniProgramNativeTag, isRootHook, normalizeDataset, normalizeEventType, normalizeTarget, onCreateVueApp, once, parseEventName, parseQuery, parseUrl, passive, plusReady, removeLeadingSlash, resolveComponentInstance, resolveOwnerEl, resolveOwnerVm, sanitise, scrollTo, stringifyQuery, updateElementStyle }; diff --git a/packages/uni-shared/src/index.ts b/packages/uni-shared/src/index.ts index 497ace212..7c2ec59e8 100644 --- a/packages/uni-shared/src/index.ts +++ b/packages/uni-shared/src/index.ts @@ -13,6 +13,7 @@ export * from './debounce' export * from './constants' export * from './EventChannel' export * from './lifecycle' +export * from './onCreateVueApp' export { default as Emitter } from './TinyEmitter' export * from './node/locale' diff --git a/packages/uni-vue/src/onCreateVueApp.ts b/packages/uni-shared/src/onCreateVueApp.ts similarity index 100% rename from packages/uni-vue/src/onCreateVueApp.ts rename to packages/uni-shared/src/onCreateVueApp.ts diff --git a/packages/uni-stat/dist/uni-stat.es.js b/packages/uni-stat/dist/uni-stat.es.js index 00278cb7f..9a6acad50 100644 --- a/packages/uni-stat/dist/uni-stat.es.js +++ b/packages/uni-stat/dist/uni-stat.es.js @@ -1,11 +1,11 @@ var version = "3.0.0-alpha-3031220220222002"; -const STAT_VERSION = version; -const STAT_URL = 'https://tongji.dcloud.io/uni/stat'; -const STAT_H5_URL = 'https://tongji.dcloud.io/uni/stat.gif'; -const PAGE_PVER_TIME = 1800; -const APP_PVER_TIME = 300; -const OPERATING_TIME = 10; +const STAT_VERSION = version; +const STAT_URL = 'https://tongji.dcloud.io/uni/stat'; +const STAT_H5_URL = 'https://tongji.dcloud.io/uni/stat.gif'; +const PAGE_PVER_TIME = 1800; +const APP_PVER_TIME = 300; +const OPERATING_TIME = 10; const DIFF_TIME = 60 * 1000 * 60 * 24; const statConfig$1 = { @@ -895,15 +895,12 @@ const stat = Stat$1.getInstance(); let isHide = false; const lifecycle = { onLaunch(options) { - console.log('onLaunch') stat.report(options, this); }, onReady() { - console.log('onReady') stat.ready(this); }, onLoad(options) { - console.log('onLoad') stat.load(options, this); // 重写分享,获取分享上报事件 if (this.$scope && this.$scope.onShareAppMessage) { @@ -915,17 +912,14 @@ const lifecycle = { } }, onShow() { - console.log('onShow') isHide = false; stat.show(this); }, onHide() { - console.log('onHide') isHide = true; stat.hide(this); }, onUnload() { - console.log('onUnload') if (isHide) { isHide = false; return @@ -938,17 +932,16 @@ const lifecycle = { }; function main() { - // if (process.env.NODE_ENV === 'development') { - // uni.report = function (type, options) {}; - // } else { + if (process.env.NODE_ENV === 'development') { + uni.report = function (type, options) {}; + } else { uni.onCreateVueApp((app) => { - console.log('onCreateVueApp') app.mixin(lifecycle); uni.report = function (type, options) { stat.sendEvent(type, options); }; }); - // } + } } main(); diff --git a/packages/uni-vue/src/index.ts b/packages/uni-vue/src/index.ts index 0ca89412d..5dc65ba3b 100644 --- a/packages/uni-vue/src/index.ts +++ b/packages/uni-vue/src/index.ts @@ -1,14 +1,12 @@ import { App } from 'vue' import { isFunction } from '@vue/shared' +import { invokeCreateVueAppHook } from '@dcloudio/uni-shared' import { applyOptions } from './componentOptions' import { set } from './componentInstance' import { errorHandler, initOptionMergeStrategies } from './appConfig' import { uniIdMixin } from './uni-id-mixin' -import { invokeCreateVueAppHook } from './onCreateVueApp' - -export { onCreateVueApp, invokeCreateVueAppHook } from './onCreateVueApp' export function initApp(app: App) { const appConfig = app._context.config -- GitLab