足力健前端,vue版本

index.js 37KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559
  1. import Vue from 'vue';
  2. const _toString = Object.prototype.toString;
  3. const hasOwnProperty = Object.prototype.hasOwnProperty;
  4. function isFn (fn) {
  5. return typeof fn === 'function'
  6. }
  7. function isStr (str) {
  8. return typeof str === 'string'
  9. }
  10. function isPlainObject (obj) {
  11. return _toString.call(obj) === '[object Object]'
  12. }
  13. function hasOwn (obj, key) {
  14. return hasOwnProperty.call(obj, key)
  15. }
  16. function noop () {}
  17. /**
  18. * Create a cached version of a pure function.
  19. */
  20. function cached (fn) {
  21. const cache = Object.create(null);
  22. return function cachedFn (str) {
  23. const hit = cache[str];
  24. return hit || (cache[str] = fn(str))
  25. }
  26. }
  27. /**
  28. * Camelize a hyphen-delimited string.
  29. */
  30. const camelizeRE = /-(\w)/g;
  31. const camelize = cached((str) => {
  32. return str.replace(camelizeRE, (_, c) => c ? c.toUpperCase() : '')
  33. });
  34. const HOOKS = [
  35. 'invoke',
  36. 'success',
  37. 'fail',
  38. 'complete',
  39. 'returnValue'
  40. ];
  41. const globalInterceptors = {};
  42. const scopedInterceptors = {};
  43. function mergeHook (parentVal, childVal) {
  44. const res = childVal
  45. ? parentVal
  46. ? parentVal.concat(childVal)
  47. : Array.isArray(childVal)
  48. ? childVal : [childVal]
  49. : parentVal;
  50. return res
  51. ? dedupeHooks(res)
  52. : res
  53. }
  54. function dedupeHooks (hooks) {
  55. const res = [];
  56. for (let i = 0; i < hooks.length; i++) {
  57. if (res.indexOf(hooks[i]) === -1) {
  58. res.push(hooks[i]);
  59. }
  60. }
  61. return res
  62. }
  63. function removeHook (hooks, hook) {
  64. const index = hooks.indexOf(hook);
  65. if (index !== -1) {
  66. hooks.splice(index, 1);
  67. }
  68. }
  69. function mergeInterceptorHook (interceptor, option) {
  70. Object.keys(option).forEach(hook => {
  71. if (HOOKS.indexOf(hook) !== -1 && isFn(option[hook])) {
  72. interceptor[hook] = mergeHook(interceptor[hook], option[hook]);
  73. }
  74. });
  75. }
  76. function removeInterceptorHook (interceptor, option) {
  77. if (!interceptor || !option) {
  78. return
  79. }
  80. Object.keys(option).forEach(hook => {
  81. if (HOOKS.indexOf(hook) !== -1 && isFn(option[hook])) {
  82. removeHook(interceptor[hook], option[hook]);
  83. }
  84. });
  85. }
  86. function addInterceptor (method, option) {
  87. if (typeof method === 'string' && isPlainObject(option)) {
  88. mergeInterceptorHook(scopedInterceptors[method] || (scopedInterceptors[method] = {}), option);
  89. } else if (isPlainObject(method)) {
  90. mergeInterceptorHook(globalInterceptors, method);
  91. }
  92. }
  93. function removeInterceptor (method, option) {
  94. if (typeof method === 'string') {
  95. if (isPlainObject(option)) {
  96. removeInterceptorHook(scopedInterceptors[method], option);
  97. } else {
  98. delete scopedInterceptors[method];
  99. }
  100. } else if (isPlainObject(method)) {
  101. removeInterceptorHook(globalInterceptors, method);
  102. }
  103. }
  104. function wrapperHook (hook) {
  105. return function (data) {
  106. return hook(data) || data
  107. }
  108. }
  109. function isPromise (obj) {
  110. return !!obj && (typeof obj === 'object' || typeof obj === 'function') && typeof obj.then === 'function'
  111. }
  112. function queue (hooks, data) {
  113. let promise = false;
  114. for (let i = 0; i < hooks.length; i++) {
  115. const hook = hooks[i];
  116. if (promise) {
  117. promise = Promise.then(wrapperHook(hook));
  118. } else {
  119. const res = hook(data);
  120. if (isPromise(res)) {
  121. promise = Promise.resolve(res);
  122. }
  123. if (res === false) {
  124. return {
  125. then () {}
  126. }
  127. }
  128. }
  129. }
  130. return promise || {
  131. then (callback) {
  132. return callback(data)
  133. }
  134. }
  135. }
  136. function wrapperOptions (interceptor, options = {}) {
  137. ['success', 'fail', 'complete'].forEach(name => {
  138. if (Array.isArray(interceptor[name])) {
  139. const oldCallback = options[name];
  140. options[name] = function callbackInterceptor (res) {
  141. queue(interceptor[name], res).then((res) => {
  142. /* eslint-disable no-mixed-operators */
  143. return isFn(oldCallback) && oldCallback(res) || res
  144. });
  145. };
  146. }
  147. });
  148. return options
  149. }
  150. function wrapperReturnValue (method, returnValue) {
  151. const returnValueHooks = [];
  152. if (Array.isArray(globalInterceptors.returnValue)) {
  153. returnValueHooks.push(...globalInterceptors.returnValue);
  154. }
  155. const interceptor = scopedInterceptors[method];
  156. if (interceptor && Array.isArray(interceptor.returnValue)) {
  157. returnValueHooks.push(...interceptor.returnValue);
  158. }
  159. returnValueHooks.forEach(hook => {
  160. returnValue = hook(returnValue) || returnValue;
  161. });
  162. return returnValue
  163. }
  164. function getApiInterceptorHooks (method) {
  165. const interceptor = Object.create(null);
  166. Object.keys(globalInterceptors).forEach(hook => {
  167. if (hook !== 'returnValue') {
  168. interceptor[hook] = globalInterceptors[hook].slice();
  169. }
  170. });
  171. const scopedInterceptor = scopedInterceptors[method];
  172. if (scopedInterceptor) {
  173. Object.keys(scopedInterceptor).forEach(hook => {
  174. if (hook !== 'returnValue') {
  175. interceptor[hook] = (interceptor[hook] || []).concat(scopedInterceptor[hook]);
  176. }
  177. });
  178. }
  179. return interceptor
  180. }
  181. function invokeApi (method, api, options, ...params) {
  182. const interceptor = getApiInterceptorHooks(method);
  183. if (interceptor && Object.keys(interceptor).length) {
  184. if (Array.isArray(interceptor.invoke)) {
  185. const res = queue(interceptor.invoke, options);
  186. return res.then((options) => {
  187. return api(wrapperOptions(interceptor, options), ...params)
  188. })
  189. } else {
  190. return api(wrapperOptions(interceptor, options), ...params)
  191. }
  192. }
  193. return api(options, ...params)
  194. }
  195. const promiseInterceptor = {
  196. returnValue (res) {
  197. if (!isPromise(res)) {
  198. return res
  199. }
  200. return res.then(res => {
  201. return res[1]
  202. }).catch(res => {
  203. return res[0]
  204. })
  205. }
  206. };
  207. const SYNC_API_RE =
  208. /^\$|sendNativeEvent|restoreGlobal|getCurrentSubNVue|getMenuButtonBoundingClientRect|^report|interceptors|Interceptor$|getSubNVueById|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$|base64ToArrayBuffer|arrayBufferToBase64/;
  209. const CONTEXT_API_RE = /^create|Manager$/;
  210. // Context例外情况
  211. const CONTEXT_API_RE_EXC = ['createBLEConnection'];
  212. // 同步例外情况
  213. const ASYNC_API = ['createBLEConnection'];
  214. const CALLBACK_API_RE = /^on|^off/;
  215. function isContextApi (name) {
  216. return CONTEXT_API_RE.test(name) && CONTEXT_API_RE_EXC.indexOf(name) === -1
  217. }
  218. function isSyncApi (name) {
  219. return SYNC_API_RE.test(name) && ASYNC_API.indexOf(name) === -1
  220. }
  221. function isCallbackApi (name) {
  222. return CALLBACK_API_RE.test(name) && name !== 'onPush'
  223. }
  224. function handlePromise (promise) {
  225. return promise.then(data => {
  226. return [null, data]
  227. })
  228. .catch(err => [err])
  229. }
  230. function shouldPromise (name) {
  231. if (
  232. isContextApi(name) ||
  233. isSyncApi(name) ||
  234. isCallbackApi(name)
  235. ) {
  236. return false
  237. }
  238. return true
  239. }
  240. /* eslint-disable no-extend-native */
  241. if (!Promise.prototype.finally) {
  242. Promise.prototype.finally = function (callback) {
  243. const promise = this.constructor;
  244. return this.then(
  245. value => promise.resolve(callback()).then(() => value),
  246. reason => promise.resolve(callback()).then(() => {
  247. throw reason
  248. })
  249. )
  250. };
  251. }
  252. function promisify (name, api) {
  253. if (!shouldPromise(name)) {
  254. return api
  255. }
  256. return function promiseApi (options = {}, ...params) {
  257. if (isFn(options.success) || isFn(options.fail) || isFn(options.complete)) {
  258. return wrapperReturnValue(name, invokeApi(name, api, options, ...params))
  259. }
  260. return wrapperReturnValue(name, handlePromise(new Promise((resolve, reject) => {
  261. invokeApi(name, api, Object.assign({}, options, {
  262. success: resolve,
  263. fail: reject
  264. }), ...params);
  265. })))
  266. }
  267. }
  268. const EPS = 1e-4;
  269. const BASE_DEVICE_WIDTH = 750;
  270. let isIOS = false;
  271. let deviceWidth = 0;
  272. let deviceDPR = 0;
  273. function checkDeviceWidth () {
  274. const {
  275. platform,
  276. pixelRatio,
  277. windowWidth
  278. } = wx.getSystemInfoSync(); // uni=>wx runtime 编译目标是 uni 对象,内部不允许直接使用 uni
  279. deviceWidth = windowWidth;
  280. deviceDPR = pixelRatio;
  281. isIOS = platform === 'ios';
  282. }
  283. function upx2px (number, newDeviceWidth) {
  284. if (deviceWidth === 0) {
  285. checkDeviceWidth();
  286. }
  287. number = Number(number);
  288. if (number === 0) {
  289. return 0
  290. }
  291. let result = (number / BASE_DEVICE_WIDTH) * (newDeviceWidth || deviceWidth);
  292. if (result < 0) {
  293. result = -result;
  294. }
  295. result = Math.floor(result + EPS);
  296. if (result === 0) {
  297. if (deviceDPR === 1 || !isIOS) {
  298. return 1
  299. } else {
  300. return 0.5
  301. }
  302. }
  303. return number < 0 ? -result : result
  304. }
  305. const interceptors = {
  306. promiseInterceptor
  307. };
  308. var baseApi = /*#__PURE__*/Object.freeze({
  309. __proto__: null,
  310. upx2px: upx2px,
  311. addInterceptor: addInterceptor,
  312. removeInterceptor: removeInterceptor,
  313. interceptors: interceptors
  314. });
  315. const protocols = {};
  316. const todos = [];
  317. const canIUses = [];
  318. const CALLBACKS = ['success', 'fail', 'cancel', 'complete'];
  319. function processCallback (methodName, method, returnValue) {
  320. return function (res) {
  321. return method(processReturnValue(methodName, res, returnValue))
  322. }
  323. }
  324. function processArgs (methodName, fromArgs, argsOption = {}, returnValue = {}, keepFromArgs = false) {
  325. if (isPlainObject(fromArgs)) { // 一般 api 的参数解析
  326. const toArgs = keepFromArgs === true ? fromArgs : {}; // returnValue 为 false 时,说明是格式化返回值,直接在返回值对象上修改赋值
  327. if (isFn(argsOption)) {
  328. argsOption = argsOption(fromArgs, toArgs) || {};
  329. }
  330. for (const key in fromArgs) {
  331. if (hasOwn(argsOption, key)) {
  332. let keyOption = argsOption[key];
  333. if (isFn(keyOption)) {
  334. keyOption = keyOption(fromArgs[key], fromArgs, toArgs);
  335. }
  336. if (!keyOption) { // 不支持的参数
  337. console.warn(`app-plus ${methodName}暂不支持${key}`);
  338. } else if (isStr(keyOption)) { // 重写参数 key
  339. toArgs[keyOption] = fromArgs[key];
  340. } else if (isPlainObject(keyOption)) { // {name:newName,value:value}可重新指定参数 key:value
  341. toArgs[keyOption.name ? keyOption.name : key] = keyOption.value;
  342. }
  343. } else if (CALLBACKS.indexOf(key) !== -1) {
  344. toArgs[key] = processCallback(methodName, fromArgs[key], returnValue);
  345. } else {
  346. if (!keepFromArgs) {
  347. toArgs[key] = fromArgs[key];
  348. }
  349. }
  350. }
  351. return toArgs
  352. } else if (isFn(fromArgs)) {
  353. fromArgs = processCallback(methodName, fromArgs, returnValue);
  354. }
  355. return fromArgs
  356. }
  357. function processReturnValue (methodName, res, returnValue, keepReturnValue = false) {
  358. if (isFn(protocols.returnValue)) { // 处理通用 returnValue
  359. res = protocols.returnValue(methodName, res);
  360. }
  361. return processArgs(methodName, res, returnValue, {}, keepReturnValue)
  362. }
  363. function wrapper (methodName, method) {
  364. if (hasOwn(protocols, methodName)) {
  365. const protocol = protocols[methodName];
  366. if (!protocol) { // 暂不支持的 api
  367. return function () {
  368. console.error(`app-plus 暂不支持${methodName}`);
  369. }
  370. }
  371. return function (arg1, arg2) { // 目前 api 最多两个参数
  372. let options = protocol;
  373. if (isFn(protocol)) {
  374. options = protocol(arg1);
  375. }
  376. arg1 = processArgs(methodName, arg1, options.args, options.returnValue);
  377. const args = [arg1];
  378. if (typeof arg2 !== 'undefined') {
  379. args.push(arg2);
  380. }
  381. const returnValue = wx[options.name || methodName].apply(wx, args);
  382. if (isSyncApi(methodName)) { // 同步 api
  383. return processReturnValue(methodName, returnValue, options.returnValue, isContextApi(methodName))
  384. }
  385. return returnValue
  386. }
  387. }
  388. return method
  389. }
  390. const todoApis = Object.create(null);
  391. const TODOS = [
  392. 'onTabBarMidButtonTap',
  393. 'subscribePush',
  394. 'unsubscribePush',
  395. 'onPush',
  396. 'offPush',
  397. 'share'
  398. ];
  399. function createTodoApi (name) {
  400. return function todoApi ({
  401. fail,
  402. complete
  403. }) {
  404. const res = {
  405. errMsg: `${name}:fail:暂不支持 ${name} 方法`
  406. };
  407. isFn(fail) && fail(res);
  408. isFn(complete) && complete(res);
  409. }
  410. }
  411. TODOS.forEach(function (name) {
  412. todoApis[name] = createTodoApi(name);
  413. });
  414. const getEmitter = (function () {
  415. if (typeof getUniEmitter === 'function') {
  416. /* eslint-disable no-undef */
  417. return getUniEmitter
  418. }
  419. let Emitter;
  420. return function getUniEmitter () {
  421. if (!Emitter) {
  422. Emitter = new Vue();
  423. }
  424. return Emitter
  425. }
  426. })();
  427. function apply (ctx, method, args) {
  428. return ctx[method].apply(ctx, args)
  429. }
  430. function $on () {
  431. return apply(getEmitter(), '$on', [...arguments])
  432. }
  433. function $off () {
  434. return apply(getEmitter(), '$off', [...arguments])
  435. }
  436. function $once () {
  437. return apply(getEmitter(), '$once', [...arguments])
  438. }
  439. function $emit () {
  440. return apply(getEmitter(), '$emit', [...arguments])
  441. }
  442. var eventApi = /*#__PURE__*/Object.freeze({
  443. __proto__: null,
  444. $on: $on,
  445. $off: $off,
  446. $once: $once,
  447. $emit: $emit
  448. });
  449. function requireNativePlugin (pluginName) {
  450. /* eslint-disable no-undef */
  451. if (typeof weex !== 'undefined') {
  452. return weex.requireModule(pluginName)
  453. }
  454. /* eslint-disable no-undef */
  455. return __requireNativePlugin__(pluginName)
  456. }
  457. function wrapper$1 (webview) {
  458. webview.$processed = true;
  459. webview.postMessage = function (data) {
  460. plus.webview.postMessageToUniNView({
  461. type: 'UniAppSubNVue',
  462. data
  463. }, webview.id);
  464. };
  465. let callbacks = [];
  466. webview.onMessage = function (callback) {
  467. callbacks.push(callback);
  468. };
  469. webview.$consumeMessage = function (e) {
  470. callbacks.forEach(callback => callback(e));
  471. };
  472. if (!webview.__uniapp_mask_id) {
  473. return
  474. }
  475. const maskColor = webview.__uniapp_mask;
  476. const maskWebview = webview.__uniapp_mask_id === '0' ? {
  477. setStyle ({
  478. mask
  479. }) {
  480. requireNativePlugin('uni-tabview').setMask({
  481. color: mask
  482. });
  483. }
  484. } : plus.webview.getWebviewById(webview.__uniapp_mask_id);
  485. const oldShow = webview.show;
  486. const oldHide = webview.hide;
  487. const oldClose = webview.close;
  488. const showMask = function () {
  489. maskWebview.setStyle({
  490. mask: maskColor
  491. });
  492. };
  493. const closeMask = function () {
  494. maskWebview.setStyle({
  495. mask: 'none'
  496. });
  497. };
  498. webview.show = function (...args) {
  499. showMask();
  500. return oldShow.apply(webview, args)
  501. };
  502. webview.hide = function (...args) {
  503. closeMask();
  504. return oldHide.apply(webview, args)
  505. };
  506. webview.close = function (...args) {
  507. closeMask();
  508. callbacks = [];
  509. return oldClose.apply(webview, args)
  510. };
  511. }
  512. function getSubNVueById (id) {
  513. const webview = plus.webview.getWebviewById(id);
  514. if (webview && !webview.$processed) {
  515. wrapper$1(webview);
  516. }
  517. return webview
  518. }
  519. var api = /*#__PURE__*/Object.freeze({
  520. __proto__: null,
  521. getSubNVueById: getSubNVueById,
  522. requireNativePlugin: requireNativePlugin
  523. });
  524. const MPPage = Page;
  525. const MPComponent = Component;
  526. const customizeRE = /:/g;
  527. const customize = cached((str) => {
  528. return camelize(str.replace(customizeRE, '-'))
  529. });
  530. function initTriggerEvent (mpInstance) {
  531. {
  532. if (!wx.canIUse('nextTick')) {
  533. return
  534. }
  535. }
  536. const oldTriggerEvent = mpInstance.triggerEvent;
  537. mpInstance.triggerEvent = function (event, ...args) {
  538. return oldTriggerEvent.apply(mpInstance, [customize(event), ...args])
  539. };
  540. }
  541. function initHook (name, options) {
  542. const oldHook = options[name];
  543. if (!oldHook) {
  544. options[name] = function () {
  545. initTriggerEvent(this);
  546. };
  547. } else {
  548. options[name] = function (...args) {
  549. initTriggerEvent(this);
  550. return oldHook.apply(this, args)
  551. };
  552. }
  553. }
  554. Page = function (options = {}) {
  555. initHook('onLoad', options);
  556. return MPPage(options)
  557. };
  558. Component = function (options = {}) {
  559. initHook('created', options);
  560. return MPComponent(options)
  561. };
  562. const PAGE_EVENT_HOOKS = [
  563. 'onPullDownRefresh',
  564. 'onReachBottom',
  565. 'onShareAppMessage',
  566. 'onPageScroll',
  567. 'onResize',
  568. 'onTabItemTap'
  569. ];
  570. function initMocks (vm, mocks) {
  571. const mpInstance = vm.$mp[vm.mpType];
  572. mocks.forEach(mock => {
  573. if (hasOwn(mpInstance, mock)) {
  574. vm[mock] = mpInstance[mock];
  575. }
  576. });
  577. }
  578. function hasHook (hook, vueOptions) {
  579. if (!vueOptions) {
  580. return true
  581. }
  582. if (Vue.options && Array.isArray(Vue.options[hook])) {
  583. return true
  584. }
  585. vueOptions = vueOptions.default || vueOptions;
  586. if (isFn(vueOptions)) {
  587. if (isFn(vueOptions.extendOptions[hook])) {
  588. return true
  589. }
  590. if (vueOptions.super &&
  591. vueOptions.super.options &&
  592. Array.isArray(vueOptions.super.options[hook])) {
  593. return true
  594. }
  595. return false
  596. }
  597. if (isFn(vueOptions[hook])) {
  598. return true
  599. }
  600. const mixins = vueOptions.mixins;
  601. if (Array.isArray(mixins)) {
  602. return !!mixins.find(mixin => hasHook(hook, mixin))
  603. }
  604. }
  605. function initHooks (mpOptions, hooks, vueOptions) {
  606. hooks.forEach(hook => {
  607. if (hasHook(hook, vueOptions)) {
  608. mpOptions[hook] = function (args) {
  609. return this.$vm && this.$vm.__call_hook(hook, args)
  610. };
  611. }
  612. });
  613. }
  614. function initVueComponent (Vue, vueOptions) {
  615. vueOptions = vueOptions.default || vueOptions;
  616. let VueComponent;
  617. if (isFn(vueOptions)) {
  618. VueComponent = vueOptions;
  619. } else {
  620. VueComponent = Vue.extend(vueOptions);
  621. }
  622. vueOptions = VueComponent.options;
  623. return [VueComponent, vueOptions]
  624. }
  625. function initSlots (vm, vueSlots) {
  626. if (Array.isArray(vueSlots) && vueSlots.length) {
  627. const $slots = Object.create(null);
  628. vueSlots.forEach(slotName => {
  629. $slots[slotName] = true;
  630. });
  631. vm.$scopedSlots = vm.$slots = $slots;
  632. }
  633. }
  634. function initVueIds (vueIds, mpInstance) {
  635. vueIds = (vueIds || '').split(',');
  636. const len = vueIds.length;
  637. if (len === 1) {
  638. mpInstance._$vueId = vueIds[0];
  639. } else if (len === 2) {
  640. mpInstance._$vueId = vueIds[0];
  641. mpInstance._$vuePid = vueIds[1];
  642. }
  643. }
  644. function initData (vueOptions, context) {
  645. let data = vueOptions.data || {};
  646. const methods = vueOptions.methods || {};
  647. if (typeof data === 'function') {
  648. try {
  649. data = data.call(context); // 支持 Vue.prototype 上挂的数据
  650. } catch (e) {
  651. if (process.env.VUE_APP_DEBUG) {
  652. console.warn('根据 Vue 的 data 函数初始化小程序 data 失败,请尽量确保 data 函数中不访问 vm 对象,否则可能影响首次数据渲染速度。', data);
  653. }
  654. }
  655. } else {
  656. try {
  657. // 对 data 格式化
  658. data = JSON.parse(JSON.stringify(data));
  659. } catch (e) {}
  660. }
  661. if (!isPlainObject(data)) {
  662. data = {};
  663. }
  664. Object.keys(methods).forEach(methodName => {
  665. if (context.__lifecycle_hooks__.indexOf(methodName) === -1 && !hasOwn(data, methodName)) {
  666. data[methodName] = methods[methodName];
  667. }
  668. });
  669. return data
  670. }
  671. const PROP_TYPES = [String, Number, Boolean, Object, Array, null];
  672. function createObserver (name) {
  673. return function observer (newVal, oldVal) {
  674. if (this.$vm) {
  675. this.$vm[name] = newVal; // 为了触发其他非 render watcher
  676. }
  677. }
  678. }
  679. function initBehaviors (vueOptions, initBehavior) {
  680. const vueBehaviors = vueOptions.behaviors;
  681. const vueExtends = vueOptions.extends;
  682. const vueMixins = vueOptions.mixins;
  683. let vueProps = vueOptions.props;
  684. if (!vueProps) {
  685. vueOptions.props = vueProps = [];
  686. }
  687. const behaviors = [];
  688. if (Array.isArray(vueBehaviors)) {
  689. vueBehaviors.forEach(behavior => {
  690. behaviors.push(behavior.replace('uni://', `${"wx"}://`));
  691. if (behavior === 'uni://form-field') {
  692. if (Array.isArray(vueProps)) {
  693. vueProps.push('name');
  694. vueProps.push('value');
  695. } else {
  696. vueProps.name = {
  697. type: String,
  698. default: ''
  699. };
  700. vueProps.value = {
  701. type: [String, Number, Boolean, Array, Object, Date],
  702. default: ''
  703. };
  704. }
  705. }
  706. });
  707. }
  708. if (isPlainObject(vueExtends) && vueExtends.props) {
  709. behaviors.push(
  710. initBehavior({
  711. properties: initProperties(vueExtends.props, true)
  712. })
  713. );
  714. }
  715. if (Array.isArray(vueMixins)) {
  716. vueMixins.forEach(vueMixin => {
  717. if (isPlainObject(vueMixin) && vueMixin.props) {
  718. behaviors.push(
  719. initBehavior({
  720. properties: initProperties(vueMixin.props, true)
  721. })
  722. );
  723. }
  724. });
  725. }
  726. return behaviors
  727. }
  728. function parsePropType (key, type, defaultValue, file) {
  729. // [String]=>String
  730. if (Array.isArray(type) && type.length === 1) {
  731. return type[0]
  732. }
  733. return type
  734. }
  735. function initProperties (props, isBehavior = false, file = '') {
  736. const properties = {};
  737. if (!isBehavior) {
  738. properties.vueId = {
  739. type: String,
  740. value: ''
  741. };
  742. properties.vueSlots = { // 小程序不能直接定义 $slots 的 props,所以通过 vueSlots 转换到 $slots
  743. type: null,
  744. value: [],
  745. observer: function (newVal, oldVal) {
  746. const $slots = Object.create(null);
  747. newVal.forEach(slotName => {
  748. $slots[slotName] = true;
  749. });
  750. this.setData({
  751. $slots
  752. });
  753. }
  754. };
  755. }
  756. if (Array.isArray(props)) { // ['title']
  757. props.forEach(key => {
  758. properties[key] = {
  759. type: null,
  760. observer: createObserver(key)
  761. };
  762. });
  763. } else if (isPlainObject(props)) { // {title:{type:String,default:''},content:String}
  764. Object.keys(props).forEach(key => {
  765. const opts = props[key];
  766. if (isPlainObject(opts)) { // title:{type:String,default:''}
  767. let value = opts.default;
  768. if (isFn(value)) {
  769. value = value();
  770. }
  771. opts.type = parsePropType(key, opts.type);
  772. properties[key] = {
  773. type: PROP_TYPES.indexOf(opts.type) !== -1 ? opts.type : null,
  774. value,
  775. observer: createObserver(key)
  776. };
  777. } else { // content:String
  778. const type = parsePropType(key, opts);
  779. properties[key] = {
  780. type: PROP_TYPES.indexOf(type) !== -1 ? type : null,
  781. observer: createObserver(key)
  782. };
  783. }
  784. });
  785. }
  786. return properties
  787. }
  788. function wrapper$2 (event) {
  789. // TODO 又得兼容 mpvue 的 mp 对象
  790. try {
  791. event.mp = JSON.parse(JSON.stringify(event));
  792. } catch (e) {}
  793. event.stopPropagation = noop;
  794. event.preventDefault = noop;
  795. event.target = event.target || {};
  796. if (!hasOwn(event, 'detail')) {
  797. event.detail = {};
  798. }
  799. if (hasOwn(event, 'markerId')) {
  800. event.detail = typeof event.detail === 'object' ? event.detail : {};
  801. event.detail.markerId = event.markerId;
  802. }
  803. if (isPlainObject(event.detail)) {
  804. event.target = Object.assign({}, event.target, event.detail);
  805. }
  806. return event
  807. }
  808. function getExtraValue (vm, dataPathsArray) {
  809. let context = vm;
  810. dataPathsArray.forEach(dataPathArray => {
  811. const dataPath = dataPathArray[0];
  812. const value = dataPathArray[2];
  813. if (dataPath || typeof value !== 'undefined') { // ['','',index,'disable']
  814. const propPath = dataPathArray[1];
  815. const valuePath = dataPathArray[3];
  816. const vFor = dataPath ? vm.__get_value(dataPath, context) : context;
  817. if (Number.isInteger(vFor)) {
  818. context = value;
  819. } else if (!propPath) {
  820. context = vFor[value];
  821. } else {
  822. if (Array.isArray(vFor)) {
  823. context = vFor.find(vForItem => {
  824. return vm.__get_value(propPath, vForItem) === value
  825. });
  826. } else if (isPlainObject(vFor)) {
  827. context = Object.keys(vFor).find(vForKey => {
  828. return vm.__get_value(propPath, vFor[vForKey]) === value
  829. });
  830. } else {
  831. console.error('v-for 暂不支持循环数据:', vFor);
  832. }
  833. }
  834. if (valuePath) {
  835. context = vm.__get_value(valuePath, context);
  836. }
  837. }
  838. });
  839. return context
  840. }
  841. function processEventExtra (vm, extra, event) {
  842. const extraObj = {};
  843. if (Array.isArray(extra) && extra.length) {
  844. /**
  845. *[
  846. * ['data.items', 'data.id', item.data.id],
  847. * ['metas', 'id', meta.id]
  848. *],
  849. *[
  850. * ['data.items', 'data.id', item.data.id],
  851. * ['metas', 'id', meta.id]
  852. *],
  853. *'test'
  854. */
  855. extra.forEach((dataPath, index) => {
  856. if (typeof dataPath === 'string') {
  857. if (!dataPath) { // model,prop.sync
  858. extraObj['$' + index] = vm;
  859. } else {
  860. if (dataPath === '$event') { // $event
  861. extraObj['$' + index] = event;
  862. } else if (dataPath.indexOf('$event.') === 0) { // $event.target.value
  863. extraObj['$' + index] = vm.__get_value(dataPath.replace('$event.', ''), event);
  864. } else {
  865. extraObj['$' + index] = vm.__get_value(dataPath);
  866. }
  867. }
  868. } else {
  869. extraObj['$' + index] = getExtraValue(vm, dataPath);
  870. }
  871. });
  872. }
  873. return extraObj
  874. }
  875. function getObjByArray (arr) {
  876. const obj = {};
  877. for (let i = 1; i < arr.length; i++) {
  878. const element = arr[i];
  879. obj[element[0]] = element[1];
  880. }
  881. return obj
  882. }
  883. function processEventArgs (vm, event, args = [], extra = [], isCustom, methodName) {
  884. let isCustomMPEvent = false; // wxcomponent 组件,传递原始 event 对象
  885. if (isCustom) { // 自定义事件
  886. isCustomMPEvent = event.currentTarget &&
  887. event.currentTarget.dataset &&
  888. event.currentTarget.dataset.comType === 'wx';
  889. if (!args.length) { // 无参数,直接传入 event 或 detail 数组
  890. if (isCustomMPEvent) {
  891. return [event]
  892. }
  893. return event.detail.__args__ || event.detail
  894. }
  895. }
  896. const extraObj = processEventExtra(vm, extra, event);
  897. const ret = [];
  898. args.forEach(arg => {
  899. if (arg === '$event') {
  900. if (methodName === '__set_model' && !isCustom) { // input v-model value
  901. ret.push(event.target.value);
  902. } else {
  903. if (isCustom && !isCustomMPEvent) {
  904. ret.push(event.detail.__args__[0]);
  905. } else { // wxcomponent 组件或内置组件
  906. ret.push(event);
  907. }
  908. }
  909. } else {
  910. if (Array.isArray(arg) && arg[0] === 'o') {
  911. ret.push(getObjByArray(arg));
  912. } else if (typeof arg === 'string' && hasOwn(extraObj, arg)) {
  913. ret.push(extraObj[arg]);
  914. } else {
  915. ret.push(arg);
  916. }
  917. }
  918. });
  919. return ret
  920. }
  921. const ONCE = '~';
  922. const CUSTOM = '^';
  923. function isMatchEventType (eventType, optType) {
  924. return (eventType === optType) ||
  925. (
  926. optType === 'regionchange' &&
  927. (
  928. eventType === 'begin' ||
  929. eventType === 'end'
  930. )
  931. )
  932. }
  933. function handleEvent (event) {
  934. event = wrapper$2(event);
  935. // [['tap',[['handle',[1,2,a]],['handle1',[1,2,a]]]]]
  936. const dataset = (event.currentTarget || event.target).dataset;
  937. if (!dataset) {
  938. return console.warn('事件信息不存在')
  939. }
  940. const eventOpts = dataset.eventOpts || dataset['event-opts']; // 支付宝 web-view 组件 dataset 非驼峰
  941. if (!eventOpts) {
  942. return console.warn('事件信息不存在')
  943. }
  944. // [['handle',[1,2,a]],['handle1',[1,2,a]]]
  945. const eventType = event.type;
  946. const ret = [];
  947. eventOpts.forEach(eventOpt => {
  948. let type = eventOpt[0];
  949. const eventsArray = eventOpt[1];
  950. const isCustom = type.charAt(0) === CUSTOM;
  951. type = isCustom ? type.slice(1) : type;
  952. const isOnce = type.charAt(0) === ONCE;
  953. type = isOnce ? type.slice(1) : type;
  954. if (eventsArray && isMatchEventType(eventType, type)) {
  955. eventsArray.forEach(eventArray => {
  956. const methodName = eventArray[0];
  957. if (methodName) {
  958. let handlerCtx = this.$vm;
  959. if (
  960. handlerCtx.$options.generic &&
  961. handlerCtx.$parent &&
  962. handlerCtx.$parent.$parent
  963. ) { // mp-weixin,mp-toutiao 抽象节点模拟 scoped slots
  964. handlerCtx = handlerCtx.$parent.$parent;
  965. }
  966. if (methodName === '$emit') {
  967. handlerCtx.$emit.apply(handlerCtx,
  968. processEventArgs(
  969. this.$vm,
  970. event,
  971. eventArray[1],
  972. eventArray[2],
  973. isCustom,
  974. methodName
  975. ));
  976. return
  977. }
  978. const handler = handlerCtx[methodName];
  979. if (!isFn(handler)) {
  980. throw new Error(` _vm.${methodName} is not a function`)
  981. }
  982. if (isOnce) {
  983. if (handler.once) {
  984. return
  985. }
  986. handler.once = true;
  987. }
  988. ret.push(handler.apply(handlerCtx, processEventArgs(
  989. this.$vm,
  990. event,
  991. eventArray[1],
  992. eventArray[2],
  993. isCustom,
  994. methodName
  995. )));
  996. }
  997. });
  998. }
  999. });
  1000. if (
  1001. eventType === 'input' &&
  1002. ret.length === 1 &&
  1003. typeof ret[0] !== 'undefined'
  1004. ) {
  1005. return ret[0]
  1006. }
  1007. }
  1008. const hooks = [
  1009. 'onShow',
  1010. 'onHide',
  1011. 'onError',
  1012. 'onPageNotFound'
  1013. ];
  1014. function parseBaseApp (vm, {
  1015. mocks,
  1016. initRefs
  1017. }) {
  1018. if (vm.$options.store) {
  1019. Vue.prototype.$store = vm.$options.store;
  1020. }
  1021. Vue.prototype.mpHost = "app-plus";
  1022. Vue.mixin({
  1023. beforeCreate () {
  1024. if (!this.$options.mpType) {
  1025. return
  1026. }
  1027. this.mpType = this.$options.mpType;
  1028. this.$mp = {
  1029. data: {},
  1030. [this.mpType]: this.$options.mpInstance
  1031. };
  1032. this.$scope = this.$options.mpInstance;
  1033. delete this.$options.mpType;
  1034. delete this.$options.mpInstance;
  1035. if (this.mpType !== 'app') {
  1036. initRefs(this);
  1037. initMocks(this, mocks);
  1038. }
  1039. }
  1040. });
  1041. const appOptions = {
  1042. onLaunch (args) {
  1043. if (this.$vm) { // 已经初始化过了,主要是为了百度,百度 onShow 在 onLaunch 之前
  1044. return
  1045. }
  1046. this.$vm = vm;
  1047. this.$vm.$mp = {
  1048. app: this
  1049. };
  1050. this.$vm.$scope = this;
  1051. // vm 上也挂载 globalData
  1052. this.$vm.globalData = this.globalData;
  1053. this.$vm._isMounted = true;
  1054. this.$vm.__call_hook('mounted', args);
  1055. this.$vm.__call_hook('onLaunch', args);
  1056. }
  1057. };
  1058. // 兼容旧版本 globalData
  1059. appOptions.globalData = vm.$options.globalData || {};
  1060. // 将 methods 中的方法挂在 getApp() 中
  1061. const methods = vm.$options.methods;
  1062. if (methods) {
  1063. Object.keys(methods).forEach(name => {
  1064. appOptions[name] = methods[name];
  1065. });
  1066. }
  1067. initHooks(appOptions, hooks);
  1068. return appOptions
  1069. }
  1070. const mocks = ['__route__', '__wxExparserNodeId__', '__wxWebviewId__'];
  1071. function findVmByVueId (vm, vuePid) {
  1072. const $children = vm.$children;
  1073. // 优先查找直属(反向查找:https://github.com/dcloudio/uni-app/issues/1200)
  1074. for (let i = $children.length - 1; i >= 0; i--) {
  1075. const childVm = $children[i];
  1076. if (childVm.$scope._$vueId === vuePid) {
  1077. return childVm
  1078. }
  1079. }
  1080. // 反向递归查找
  1081. let parentVm;
  1082. for (let i = $children.length - 1; i >= 0; i--) {
  1083. parentVm = findVmByVueId($children[i], vuePid);
  1084. if (parentVm) {
  1085. return parentVm
  1086. }
  1087. }
  1088. }
  1089. function initBehavior (options) {
  1090. return Behavior(options)
  1091. }
  1092. function isPage () {
  1093. return !!this.route
  1094. }
  1095. function initRelation (detail) {
  1096. this.triggerEvent('__l', detail);
  1097. }
  1098. function initRefs (vm) {
  1099. const mpInstance = vm.$scope;
  1100. Object.defineProperty(vm, '$refs', {
  1101. get () {
  1102. const $refs = {};
  1103. const components = mpInstance.selectAllComponents('.vue-ref');
  1104. components.forEach(component => {
  1105. const ref = component.dataset.ref;
  1106. $refs[ref] = component.$vm || component;
  1107. });
  1108. const forComponents = mpInstance.selectAllComponents('.vue-ref-in-for');
  1109. forComponents.forEach(component => {
  1110. const ref = component.dataset.ref;
  1111. if (!$refs[ref]) {
  1112. $refs[ref] = [];
  1113. }
  1114. $refs[ref].push(component.$vm || component);
  1115. });
  1116. return $refs
  1117. }
  1118. });
  1119. }
  1120. function handleLink (event) {
  1121. const {
  1122. vuePid,
  1123. vueOptions
  1124. } = event.detail || event.value; // detail 是微信,value 是百度(dipatch)
  1125. let parentVm;
  1126. if (vuePid) {
  1127. parentVm = findVmByVueId(this.$vm, vuePid);
  1128. }
  1129. if (!parentVm) {
  1130. parentVm = this.$vm;
  1131. }
  1132. vueOptions.parent = parentVm;
  1133. }
  1134. function parseApp (vm) {
  1135. return parseBaseApp(vm, {
  1136. mocks,
  1137. initRefs
  1138. })
  1139. }
  1140. const hooks$1 = [
  1141. 'onUniNViewMessage'
  1142. ];
  1143. function parseApp$1 (vm) {
  1144. const appOptions = parseApp(vm);
  1145. initHooks(appOptions, hooks$1);
  1146. return appOptions
  1147. }
  1148. function createApp (vm) {
  1149. App(parseApp$1(vm));
  1150. return vm
  1151. }
  1152. function parseBaseComponent (vueComponentOptions, {
  1153. isPage,
  1154. initRelation
  1155. } = {}) {
  1156. const [VueComponent, vueOptions] = initVueComponent(Vue, vueComponentOptions);
  1157. const options = {
  1158. multipleSlots: true,
  1159. addGlobalClass: true,
  1160. ...(vueOptions.options || {})
  1161. };
  1162. const componentOptions = {
  1163. options,
  1164. data: initData(vueOptions, Vue.prototype),
  1165. behaviors: initBehaviors(vueOptions, initBehavior),
  1166. properties: initProperties(vueOptions.props, false, vueOptions.__file),
  1167. lifetimes: {
  1168. attached () {
  1169. const properties = this.properties;
  1170. const options = {
  1171. mpType: isPage.call(this) ? 'page' : 'component',
  1172. mpInstance: this,
  1173. propsData: properties
  1174. };
  1175. initVueIds(properties.vueId, this);
  1176. // 处理父子关系
  1177. initRelation.call(this, {
  1178. vuePid: this._$vuePid,
  1179. vueOptions: options
  1180. });
  1181. // 初始化 vue 实例
  1182. this.$vm = new VueComponent(options);
  1183. // 处理$slots,$scopedSlots(暂不支持动态变化$slots)
  1184. initSlots(this.$vm, properties.vueSlots);
  1185. // 触发首次 setData
  1186. this.$vm.$mount();
  1187. },
  1188. ready () {
  1189. // 当组件 props 默认值为 true,初始化时传入 false 会导致 created,ready 触发, 但 attached 不触发
  1190. // https://developers.weixin.qq.com/community/develop/doc/00066ae2844cc0f8eb883e2a557800
  1191. if (this.$vm) {
  1192. this.$vm._isMounted = true;
  1193. this.$vm.__call_hook('mounted');
  1194. this.$vm.__call_hook('onReady');
  1195. }
  1196. },
  1197. detached () {
  1198. this.$vm && this.$vm.$destroy();
  1199. }
  1200. },
  1201. pageLifetimes: {
  1202. show (args) {
  1203. this.$vm && this.$vm.__call_hook('onPageShow', args);
  1204. },
  1205. hide () {
  1206. this.$vm && this.$vm.__call_hook('onPageHide');
  1207. },
  1208. resize (size) {
  1209. this.$vm && this.$vm.__call_hook('onPageResize', size);
  1210. }
  1211. },
  1212. methods: {
  1213. __l: handleLink,
  1214. __e: handleEvent
  1215. }
  1216. };
  1217. // externalClasses
  1218. if (vueOptions.externalClasses) {
  1219. componentOptions.externalClasses = vueOptions.externalClasses;
  1220. }
  1221. if (Array.isArray(vueOptions.wxsCallMethods)) {
  1222. vueOptions.wxsCallMethods.forEach(callMethod => {
  1223. componentOptions.methods[callMethod] = function (args) {
  1224. return this.$vm[callMethod](args)
  1225. };
  1226. });
  1227. }
  1228. if (isPage) {
  1229. return componentOptions
  1230. }
  1231. return [componentOptions, VueComponent]
  1232. }
  1233. function parseComponent (vueComponentOptions) {
  1234. return parseBaseComponent(vueComponentOptions, {
  1235. isPage,
  1236. initRelation
  1237. })
  1238. }
  1239. function parseComponent$1 (vueComponentOptions) {
  1240. const componentOptions = parseComponent(vueComponentOptions);
  1241. componentOptions.methods.$getAppWebview = function () {
  1242. return plus.webview.getWebviewById(`${this.__wxWebviewId__}`)
  1243. };
  1244. return componentOptions
  1245. }
  1246. const hooks$2 = [
  1247. 'onShow',
  1248. 'onHide',
  1249. 'onUnload'
  1250. ];
  1251. hooks$2.push(...PAGE_EVENT_HOOKS);
  1252. function parseBasePage (vuePageOptions, {
  1253. isPage,
  1254. initRelation
  1255. }) {
  1256. const pageOptions = parseComponent$1(vuePageOptions);
  1257. initHooks(pageOptions.methods, hooks$2, vuePageOptions);
  1258. pageOptions.methods.onLoad = function (args) {
  1259. this.$vm.$mp.query = args; // 兼容 mpvue
  1260. this.$vm.__call_hook('onLoad', args);
  1261. };
  1262. return pageOptions
  1263. }
  1264. function parsePage (vuePageOptions) {
  1265. return parseBasePage(vuePageOptions, {
  1266. isPage,
  1267. initRelation
  1268. })
  1269. }
  1270. const hooks$3 = [
  1271. 'onBackPress',
  1272. 'onNavigationBarButtonTap',
  1273. 'onNavigationBarSearchInputChanged',
  1274. 'onNavigationBarSearchInputConfirmed',
  1275. 'onNavigationBarSearchInputClicked',
  1276. 'onNavigationBarSearchInputFocusChanged'
  1277. ];
  1278. function parsePage$1 (vuePageOptions) {
  1279. const pageOptions = parsePage(vuePageOptions);
  1280. initHooks(pageOptions.methods, hooks$3);
  1281. return pageOptions
  1282. }
  1283. function createPage (vuePageOptions) {
  1284. {
  1285. return Component(parsePage$1(vuePageOptions))
  1286. }
  1287. }
  1288. function createComponent (vueOptions) {
  1289. {
  1290. return Component(parseComponent$1(vueOptions))
  1291. }
  1292. }
  1293. todos.forEach(todoApi => {
  1294. protocols[todoApi] = false;
  1295. });
  1296. canIUses.forEach(canIUseApi => {
  1297. const apiName = protocols[canIUseApi] && protocols[canIUseApi].name ? protocols[canIUseApi].name
  1298. : canIUseApi;
  1299. if (!wx.canIUse(apiName)) {
  1300. protocols[canIUseApi] = false;
  1301. }
  1302. });
  1303. let uni = {};
  1304. if (typeof Proxy !== 'undefined' && "app-plus" !== 'app-plus') {
  1305. uni = new Proxy({}, {
  1306. get (target, name) {
  1307. if (target[name]) {
  1308. return target[name]
  1309. }
  1310. if (baseApi[name]) {
  1311. return baseApi[name]
  1312. }
  1313. if (api[name]) {
  1314. return promisify(name, api[name])
  1315. }
  1316. if (eventApi[name]) {
  1317. return eventApi[name]
  1318. }
  1319. if (!hasOwn(wx, name) && !hasOwn(protocols, name)) {
  1320. return
  1321. }
  1322. return promisify(name, wrapper(name, wx[name]))
  1323. },
  1324. set (target, name, value) {
  1325. target[name] = value;
  1326. return true
  1327. }
  1328. });
  1329. } else {
  1330. Object.keys(baseApi).forEach(name => {
  1331. uni[name] = baseApi[name];
  1332. });
  1333. Object.keys(eventApi).forEach(name => {
  1334. uni[name] = eventApi[name];
  1335. });
  1336. Object.keys(api).forEach(name => {
  1337. uni[name] = promisify(name, api[name]);
  1338. });
  1339. Object.keys(wx).forEach(name => {
  1340. if (hasOwn(wx, name) || hasOwn(protocols, name)) {
  1341. uni[name] = promisify(name, wrapper(name, wx[name]));
  1342. }
  1343. });
  1344. }
  1345. {
  1346. if (typeof global !== 'undefined') {
  1347. global.uni = uni;
  1348. global.UniEmitter = eventApi;
  1349. }
  1350. }
  1351. wx.createApp = createApp;
  1352. wx.createPage = createPage;
  1353. wx.createComponent = createComponent;
  1354. var uni$1 = uni;
  1355. export default uni$1;
  1356. export { createApp, createComponent, createPage };