足力健前端,vue版本

index.js 37KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555
  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. var previewImage = {
  316. args (fromArgs) {
  317. let currentIndex = parseInt(fromArgs.current);
  318. if (isNaN(currentIndex)) {
  319. return
  320. }
  321. const urls = fromArgs.urls;
  322. if (!Array.isArray(urls)) {
  323. return
  324. }
  325. const len = urls.length;
  326. if (!len) {
  327. return
  328. }
  329. if (currentIndex < 0) {
  330. currentIndex = 0;
  331. } else if (currentIndex >= len) {
  332. currentIndex = len - 1;
  333. }
  334. if (currentIndex > 0) {
  335. fromArgs.current = urls[currentIndex];
  336. fromArgs.urls = urls.filter(
  337. (item, index) => index < currentIndex ? item !== urls[currentIndex] : true
  338. );
  339. } else {
  340. fromArgs.current = urls[0];
  341. }
  342. return {
  343. indicator: false,
  344. loop: false
  345. }
  346. }
  347. };
  348. function addSafeAreaInsets (result) {
  349. if (result.safeArea) {
  350. const safeArea = result.safeArea;
  351. result.safeAreaInsets = {
  352. top: safeArea.top,
  353. left: safeArea.left,
  354. right: result.windowWidth - safeArea.right,
  355. bottom: result.windowHeight - safeArea.bottom
  356. };
  357. }
  358. }
  359. const protocols = {
  360. previewImage,
  361. getSystemInfo: {
  362. returnValue: addSafeAreaInsets
  363. },
  364. getSystemInfoSync: {
  365. returnValue: addSafeAreaInsets
  366. }
  367. };
  368. const todos = [
  369. 'vibrate'
  370. ];
  371. const canIUses = [];
  372. const CALLBACKS = ['success', 'fail', 'cancel', 'complete'];
  373. function processCallback (methodName, method, returnValue) {
  374. return function (res) {
  375. return method(processReturnValue(methodName, res, returnValue))
  376. }
  377. }
  378. function processArgs (methodName, fromArgs, argsOption = {}, returnValue = {}, keepFromArgs = false) {
  379. if (isPlainObject(fromArgs)) { // 一般 api 的参数解析
  380. const toArgs = keepFromArgs === true ? fromArgs : {}; // returnValue 为 false 时,说明是格式化返回值,直接在返回值对象上修改赋值
  381. if (isFn(argsOption)) {
  382. argsOption = argsOption(fromArgs, toArgs) || {};
  383. }
  384. for (const key in fromArgs) {
  385. if (hasOwn(argsOption, key)) {
  386. let keyOption = argsOption[key];
  387. if (isFn(keyOption)) {
  388. keyOption = keyOption(fromArgs[key], fromArgs, toArgs);
  389. }
  390. if (!keyOption) { // 不支持的参数
  391. console.warn(`微信小程序 ${methodName}暂不支持${key}`);
  392. } else if (isStr(keyOption)) { // 重写参数 key
  393. toArgs[keyOption] = fromArgs[key];
  394. } else if (isPlainObject(keyOption)) { // {name:newName,value:value}可重新指定参数 key:value
  395. toArgs[keyOption.name ? keyOption.name : key] = keyOption.value;
  396. }
  397. } else if (CALLBACKS.indexOf(key) !== -1) {
  398. toArgs[key] = processCallback(methodName, fromArgs[key], returnValue);
  399. } else {
  400. if (!keepFromArgs) {
  401. toArgs[key] = fromArgs[key];
  402. }
  403. }
  404. }
  405. return toArgs
  406. } else if (isFn(fromArgs)) {
  407. fromArgs = processCallback(methodName, fromArgs, returnValue);
  408. }
  409. return fromArgs
  410. }
  411. function processReturnValue (methodName, res, returnValue, keepReturnValue = false) {
  412. if (isFn(protocols.returnValue)) { // 处理通用 returnValue
  413. res = protocols.returnValue(methodName, res);
  414. }
  415. return processArgs(methodName, res, returnValue, {}, keepReturnValue)
  416. }
  417. function wrapper (methodName, method) {
  418. if (hasOwn(protocols, methodName)) {
  419. const protocol = protocols[methodName];
  420. if (!protocol) { // 暂不支持的 api
  421. return function () {
  422. console.error(`微信小程序 暂不支持${methodName}`);
  423. }
  424. }
  425. return function (arg1, arg2) { // 目前 api 最多两个参数
  426. let options = protocol;
  427. if (isFn(protocol)) {
  428. options = protocol(arg1);
  429. }
  430. arg1 = processArgs(methodName, arg1, options.args, options.returnValue);
  431. const args = [arg1];
  432. if (typeof arg2 !== 'undefined') {
  433. args.push(arg2);
  434. }
  435. const returnValue = wx[options.name || methodName].apply(wx, args);
  436. if (isSyncApi(methodName)) { // 同步 api
  437. return processReturnValue(methodName, returnValue, options.returnValue, isContextApi(methodName))
  438. }
  439. return returnValue
  440. }
  441. }
  442. return method
  443. }
  444. const todoApis = Object.create(null);
  445. const TODOS = [
  446. 'onTabBarMidButtonTap',
  447. 'subscribePush',
  448. 'unsubscribePush',
  449. 'onPush',
  450. 'offPush',
  451. 'share'
  452. ];
  453. function createTodoApi (name) {
  454. return function todoApi ({
  455. fail,
  456. complete
  457. }) {
  458. const res = {
  459. errMsg: `${name}:fail:暂不支持 ${name} 方法`
  460. };
  461. isFn(fail) && fail(res);
  462. isFn(complete) && complete(res);
  463. }
  464. }
  465. TODOS.forEach(function (name) {
  466. todoApis[name] = createTodoApi(name);
  467. });
  468. var providers = {
  469. oauth: ['weixin'],
  470. share: ['weixin'],
  471. payment: ['wxpay'],
  472. push: ['weixin']
  473. };
  474. function getProvider ({
  475. service,
  476. success,
  477. fail,
  478. complete
  479. }) {
  480. let res = false;
  481. if (providers[service]) {
  482. res = {
  483. errMsg: 'getProvider:ok',
  484. service,
  485. provider: providers[service]
  486. };
  487. isFn(success) && success(res);
  488. } else {
  489. res = {
  490. errMsg: 'getProvider:fail:服务[' + service + ']不存在'
  491. };
  492. isFn(fail) && fail(res);
  493. }
  494. isFn(complete) && complete(res);
  495. }
  496. var extraApi = /*#__PURE__*/Object.freeze({
  497. __proto__: null,
  498. getProvider: getProvider
  499. });
  500. const getEmitter = (function () {
  501. if (typeof getUniEmitter === 'function') {
  502. /* eslint-disable no-undef */
  503. return getUniEmitter
  504. }
  505. let Emitter;
  506. return function getUniEmitter () {
  507. if (!Emitter) {
  508. Emitter = new Vue();
  509. }
  510. return Emitter
  511. }
  512. })();
  513. function apply (ctx, method, args) {
  514. return ctx[method].apply(ctx, args)
  515. }
  516. function $on () {
  517. return apply(getEmitter(), '$on', [...arguments])
  518. }
  519. function $off () {
  520. return apply(getEmitter(), '$off', [...arguments])
  521. }
  522. function $once () {
  523. return apply(getEmitter(), '$once', [...arguments])
  524. }
  525. function $emit () {
  526. return apply(getEmitter(), '$emit', [...arguments])
  527. }
  528. var eventApi = /*#__PURE__*/Object.freeze({
  529. __proto__: null,
  530. $on: $on,
  531. $off: $off,
  532. $once: $once,
  533. $emit: $emit
  534. });
  535. var api = /*#__PURE__*/Object.freeze({
  536. __proto__: null
  537. });
  538. const MPPage = Page;
  539. const MPComponent = Component;
  540. const customizeRE = /:/g;
  541. const customize = cached((str) => {
  542. return camelize(str.replace(customizeRE, '-'))
  543. });
  544. function initTriggerEvent (mpInstance) {
  545. {
  546. if (!wx.canIUse('nextTick')) {
  547. return
  548. }
  549. }
  550. const oldTriggerEvent = mpInstance.triggerEvent;
  551. mpInstance.triggerEvent = function (event, ...args) {
  552. return oldTriggerEvent.apply(mpInstance, [customize(event), ...args])
  553. };
  554. }
  555. function initHook (name, options) {
  556. const oldHook = options[name];
  557. if (!oldHook) {
  558. options[name] = function () {
  559. initTriggerEvent(this);
  560. };
  561. } else {
  562. options[name] = function (...args) {
  563. initTriggerEvent(this);
  564. return oldHook.apply(this, args)
  565. };
  566. }
  567. }
  568. Page = function (options = {}) {
  569. initHook('onLoad', options);
  570. return MPPage(options)
  571. };
  572. Component = function (options = {}) {
  573. initHook('created', options);
  574. return MPComponent(options)
  575. };
  576. const PAGE_EVENT_HOOKS = [
  577. 'onPullDownRefresh',
  578. 'onReachBottom',
  579. 'onShareAppMessage',
  580. 'onPageScroll',
  581. 'onResize',
  582. 'onTabItemTap'
  583. ];
  584. function initMocks (vm, mocks) {
  585. const mpInstance = vm.$mp[vm.mpType];
  586. mocks.forEach(mock => {
  587. if (hasOwn(mpInstance, mock)) {
  588. vm[mock] = mpInstance[mock];
  589. }
  590. });
  591. }
  592. function hasHook (hook, vueOptions) {
  593. if (!vueOptions) {
  594. return true
  595. }
  596. if (Vue.options && Array.isArray(Vue.options[hook])) {
  597. return true
  598. }
  599. vueOptions = vueOptions.default || vueOptions;
  600. if (isFn(vueOptions)) {
  601. if (isFn(vueOptions.extendOptions[hook])) {
  602. return true
  603. }
  604. if (vueOptions.super &&
  605. vueOptions.super.options &&
  606. Array.isArray(vueOptions.super.options[hook])) {
  607. return true
  608. }
  609. return false
  610. }
  611. if (isFn(vueOptions[hook])) {
  612. return true
  613. }
  614. const mixins = vueOptions.mixins;
  615. if (Array.isArray(mixins)) {
  616. return !!mixins.find(mixin => hasHook(hook, mixin))
  617. }
  618. }
  619. function initHooks (mpOptions, hooks, vueOptions) {
  620. hooks.forEach(hook => {
  621. if (hasHook(hook, vueOptions)) {
  622. mpOptions[hook] = function (args) {
  623. return this.$vm && this.$vm.__call_hook(hook, args)
  624. };
  625. }
  626. });
  627. }
  628. function initVueComponent (Vue, vueOptions) {
  629. vueOptions = vueOptions.default || vueOptions;
  630. let VueComponent;
  631. if (isFn(vueOptions)) {
  632. VueComponent = vueOptions;
  633. } else {
  634. VueComponent = Vue.extend(vueOptions);
  635. }
  636. vueOptions = VueComponent.options;
  637. return [VueComponent, vueOptions]
  638. }
  639. function initSlots (vm, vueSlots) {
  640. if (Array.isArray(vueSlots) && vueSlots.length) {
  641. const $slots = Object.create(null);
  642. vueSlots.forEach(slotName => {
  643. $slots[slotName] = true;
  644. });
  645. vm.$scopedSlots = vm.$slots = $slots;
  646. }
  647. }
  648. function initVueIds (vueIds, mpInstance) {
  649. vueIds = (vueIds || '').split(',');
  650. const len = vueIds.length;
  651. if (len === 1) {
  652. mpInstance._$vueId = vueIds[0];
  653. } else if (len === 2) {
  654. mpInstance._$vueId = vueIds[0];
  655. mpInstance._$vuePid = vueIds[1];
  656. }
  657. }
  658. function initData (vueOptions, context) {
  659. let data = vueOptions.data || {};
  660. const methods = vueOptions.methods || {};
  661. if (typeof data === 'function') {
  662. try {
  663. data = data.call(context); // 支持 Vue.prototype 上挂的数据
  664. } catch (e) {
  665. if (process.env.VUE_APP_DEBUG) {
  666. console.warn('根据 Vue 的 data 函数初始化小程序 data 失败,请尽量确保 data 函数中不访问 vm 对象,否则可能影响首次数据渲染速度。', data);
  667. }
  668. }
  669. } else {
  670. try {
  671. // 对 data 格式化
  672. data = JSON.parse(JSON.stringify(data));
  673. } catch (e) {}
  674. }
  675. if (!isPlainObject(data)) {
  676. data = {};
  677. }
  678. Object.keys(methods).forEach(methodName => {
  679. if (context.__lifecycle_hooks__.indexOf(methodName) === -1 && !hasOwn(data, methodName)) {
  680. data[methodName] = methods[methodName];
  681. }
  682. });
  683. return data
  684. }
  685. const PROP_TYPES = [String, Number, Boolean, Object, Array, null];
  686. function createObserver (name) {
  687. return function observer (newVal, oldVal) {
  688. if (this.$vm) {
  689. this.$vm[name] = newVal; // 为了触发其他非 render watcher
  690. }
  691. }
  692. }
  693. function initBehaviors (vueOptions, initBehavior) {
  694. const vueBehaviors = vueOptions.behaviors;
  695. const vueExtends = vueOptions.extends;
  696. const vueMixins = vueOptions.mixins;
  697. let vueProps = vueOptions.props;
  698. if (!vueProps) {
  699. vueOptions.props = vueProps = [];
  700. }
  701. const behaviors = [];
  702. if (Array.isArray(vueBehaviors)) {
  703. vueBehaviors.forEach(behavior => {
  704. behaviors.push(behavior.replace('uni://', `${"wx"}://`));
  705. if (behavior === 'uni://form-field') {
  706. if (Array.isArray(vueProps)) {
  707. vueProps.push('name');
  708. vueProps.push('value');
  709. } else {
  710. vueProps.name = {
  711. type: String,
  712. default: ''
  713. };
  714. vueProps.value = {
  715. type: [String, Number, Boolean, Array, Object, Date],
  716. default: ''
  717. };
  718. }
  719. }
  720. });
  721. }
  722. if (isPlainObject(vueExtends) && vueExtends.props) {
  723. behaviors.push(
  724. initBehavior({
  725. properties: initProperties(vueExtends.props, true)
  726. })
  727. );
  728. }
  729. if (Array.isArray(vueMixins)) {
  730. vueMixins.forEach(vueMixin => {
  731. if (isPlainObject(vueMixin) && vueMixin.props) {
  732. behaviors.push(
  733. initBehavior({
  734. properties: initProperties(vueMixin.props, true)
  735. })
  736. );
  737. }
  738. });
  739. }
  740. return behaviors
  741. }
  742. function parsePropType (key, type, defaultValue, file) {
  743. // [String]=>String
  744. if (Array.isArray(type) && type.length === 1) {
  745. return type[0]
  746. }
  747. return type
  748. }
  749. function initProperties (props, isBehavior = false, file = '') {
  750. const properties = {};
  751. if (!isBehavior) {
  752. properties.vueId = {
  753. type: String,
  754. value: ''
  755. };
  756. properties.vueSlots = { // 小程序不能直接定义 $slots 的 props,所以通过 vueSlots 转换到 $slots
  757. type: null,
  758. value: [],
  759. observer: function (newVal, oldVal) {
  760. const $slots = Object.create(null);
  761. newVal.forEach(slotName => {
  762. $slots[slotName] = true;
  763. });
  764. this.setData({
  765. $slots
  766. });
  767. }
  768. };
  769. }
  770. if (Array.isArray(props)) { // ['title']
  771. props.forEach(key => {
  772. properties[key] = {
  773. type: null,
  774. observer: createObserver(key)
  775. };
  776. });
  777. } else if (isPlainObject(props)) { // {title:{type:String,default:''},content:String}
  778. Object.keys(props).forEach(key => {
  779. const opts = props[key];
  780. if (isPlainObject(opts)) { // title:{type:String,default:''}
  781. let value = opts.default;
  782. if (isFn(value)) {
  783. value = value();
  784. }
  785. opts.type = parsePropType(key, opts.type);
  786. properties[key] = {
  787. type: PROP_TYPES.indexOf(opts.type) !== -1 ? opts.type : null,
  788. value,
  789. observer: createObserver(key)
  790. };
  791. } else { // content:String
  792. const type = parsePropType(key, opts);
  793. properties[key] = {
  794. type: PROP_TYPES.indexOf(type) !== -1 ? type : null,
  795. observer: createObserver(key)
  796. };
  797. }
  798. });
  799. }
  800. return properties
  801. }
  802. function wrapper$1 (event) {
  803. // TODO 又得兼容 mpvue 的 mp 对象
  804. try {
  805. event.mp = JSON.parse(JSON.stringify(event));
  806. } catch (e) {}
  807. event.stopPropagation = noop;
  808. event.preventDefault = noop;
  809. event.target = event.target || {};
  810. if (!hasOwn(event, 'detail')) {
  811. event.detail = {};
  812. }
  813. if (hasOwn(event, 'markerId')) {
  814. event.detail = typeof event.detail === 'object' ? event.detail : {};
  815. event.detail.markerId = event.markerId;
  816. }
  817. if (isPlainObject(event.detail)) {
  818. event.target = Object.assign({}, event.target, event.detail);
  819. }
  820. return event
  821. }
  822. function getExtraValue (vm, dataPathsArray) {
  823. let context = vm;
  824. dataPathsArray.forEach(dataPathArray => {
  825. const dataPath = dataPathArray[0];
  826. const value = dataPathArray[2];
  827. if (dataPath || typeof value !== 'undefined') { // ['','',index,'disable']
  828. const propPath = dataPathArray[1];
  829. const valuePath = dataPathArray[3];
  830. const vFor = dataPath ? vm.__get_value(dataPath, context) : context;
  831. if (Number.isInteger(vFor)) {
  832. context = value;
  833. } else if (!propPath) {
  834. context = vFor[value];
  835. } else {
  836. if (Array.isArray(vFor)) {
  837. context = vFor.find(vForItem => {
  838. return vm.__get_value(propPath, vForItem) === value
  839. });
  840. } else if (isPlainObject(vFor)) {
  841. context = Object.keys(vFor).find(vForKey => {
  842. return vm.__get_value(propPath, vFor[vForKey]) === value
  843. });
  844. } else {
  845. console.error('v-for 暂不支持循环数据:', vFor);
  846. }
  847. }
  848. if (valuePath) {
  849. context = vm.__get_value(valuePath, context);
  850. }
  851. }
  852. });
  853. return context
  854. }
  855. function processEventExtra (vm, extra, event) {
  856. const extraObj = {};
  857. if (Array.isArray(extra) && extra.length) {
  858. /**
  859. *[
  860. * ['data.items', 'data.id', item.data.id],
  861. * ['metas', 'id', meta.id]
  862. *],
  863. *[
  864. * ['data.items', 'data.id', item.data.id],
  865. * ['metas', 'id', meta.id]
  866. *],
  867. *'test'
  868. */
  869. extra.forEach((dataPath, index) => {
  870. if (typeof dataPath === 'string') {
  871. if (!dataPath) { // model,prop.sync
  872. extraObj['$' + index] = vm;
  873. } else {
  874. if (dataPath === '$event') { // $event
  875. extraObj['$' + index] = event;
  876. } else if (dataPath.indexOf('$event.') === 0) { // $event.target.value
  877. extraObj['$' + index] = vm.__get_value(dataPath.replace('$event.', ''), event);
  878. } else {
  879. extraObj['$' + index] = vm.__get_value(dataPath);
  880. }
  881. }
  882. } else {
  883. extraObj['$' + index] = getExtraValue(vm, dataPath);
  884. }
  885. });
  886. }
  887. return extraObj
  888. }
  889. function getObjByArray (arr) {
  890. const obj = {};
  891. for (let i = 1; i < arr.length; i++) {
  892. const element = arr[i];
  893. obj[element[0]] = element[1];
  894. }
  895. return obj
  896. }
  897. function processEventArgs (vm, event, args = [], extra = [], isCustom, methodName) {
  898. let isCustomMPEvent = false; // wxcomponent 组件,传递原始 event 对象
  899. if (isCustom) { // 自定义事件
  900. isCustomMPEvent = event.currentTarget &&
  901. event.currentTarget.dataset &&
  902. event.currentTarget.dataset.comType === 'wx';
  903. if (!args.length) { // 无参数,直接传入 event 或 detail 数组
  904. if (isCustomMPEvent) {
  905. return [event]
  906. }
  907. return event.detail.__args__ || event.detail
  908. }
  909. }
  910. const extraObj = processEventExtra(vm, extra, event);
  911. const ret = [];
  912. args.forEach(arg => {
  913. if (arg === '$event') {
  914. if (methodName === '__set_model' && !isCustom) { // input v-model value
  915. ret.push(event.target.value);
  916. } else {
  917. if (isCustom && !isCustomMPEvent) {
  918. ret.push(event.detail.__args__[0]);
  919. } else { // wxcomponent 组件或内置组件
  920. ret.push(event);
  921. }
  922. }
  923. } else {
  924. if (Array.isArray(arg) && arg[0] === 'o') {
  925. ret.push(getObjByArray(arg));
  926. } else if (typeof arg === 'string' && hasOwn(extraObj, arg)) {
  927. ret.push(extraObj[arg]);
  928. } else {
  929. ret.push(arg);
  930. }
  931. }
  932. });
  933. return ret
  934. }
  935. const ONCE = '~';
  936. const CUSTOM = '^';
  937. function isMatchEventType (eventType, optType) {
  938. return (eventType === optType) ||
  939. (
  940. optType === 'regionchange' &&
  941. (
  942. eventType === 'begin' ||
  943. eventType === 'end'
  944. )
  945. )
  946. }
  947. function handleEvent (event) {
  948. event = wrapper$1(event);
  949. // [['tap',[['handle',[1,2,a]],['handle1',[1,2,a]]]]]
  950. const dataset = (event.currentTarget || event.target).dataset;
  951. if (!dataset) {
  952. return console.warn('事件信息不存在')
  953. }
  954. const eventOpts = dataset.eventOpts || dataset['event-opts']; // 支付宝 web-view 组件 dataset 非驼峰
  955. if (!eventOpts) {
  956. return console.warn('事件信息不存在')
  957. }
  958. // [['handle',[1,2,a]],['handle1',[1,2,a]]]
  959. const eventType = event.type;
  960. const ret = [];
  961. eventOpts.forEach(eventOpt => {
  962. let type = eventOpt[0];
  963. const eventsArray = eventOpt[1];
  964. const isCustom = type.charAt(0) === CUSTOM;
  965. type = isCustom ? type.slice(1) : type;
  966. const isOnce = type.charAt(0) === ONCE;
  967. type = isOnce ? type.slice(1) : type;
  968. if (eventsArray && isMatchEventType(eventType, type)) {
  969. eventsArray.forEach(eventArray => {
  970. const methodName = eventArray[0];
  971. if (methodName) {
  972. let handlerCtx = this.$vm;
  973. if (
  974. handlerCtx.$options.generic &&
  975. handlerCtx.$parent &&
  976. handlerCtx.$parent.$parent
  977. ) { // mp-weixin,mp-toutiao 抽象节点模拟 scoped slots
  978. handlerCtx = handlerCtx.$parent.$parent;
  979. }
  980. if (methodName === '$emit') {
  981. handlerCtx.$emit.apply(handlerCtx,
  982. processEventArgs(
  983. this.$vm,
  984. event,
  985. eventArray[1],
  986. eventArray[2],
  987. isCustom,
  988. methodName
  989. ));
  990. return
  991. }
  992. const handler = handlerCtx[methodName];
  993. if (!isFn(handler)) {
  994. throw new Error(` _vm.${methodName} is not a function`)
  995. }
  996. if (isOnce) {
  997. if (handler.once) {
  998. return
  999. }
  1000. handler.once = true;
  1001. }
  1002. ret.push(handler.apply(handlerCtx, processEventArgs(
  1003. this.$vm,
  1004. event,
  1005. eventArray[1],
  1006. eventArray[2],
  1007. isCustom,
  1008. methodName
  1009. )));
  1010. }
  1011. });
  1012. }
  1013. });
  1014. if (
  1015. eventType === 'input' &&
  1016. ret.length === 1 &&
  1017. typeof ret[0] !== 'undefined'
  1018. ) {
  1019. return ret[0]
  1020. }
  1021. }
  1022. const hooks = [
  1023. 'onShow',
  1024. 'onHide',
  1025. 'onError',
  1026. 'onPageNotFound'
  1027. ];
  1028. function parseBaseApp (vm, {
  1029. mocks,
  1030. initRefs
  1031. }) {
  1032. if (vm.$options.store) {
  1033. Vue.prototype.$store = vm.$options.store;
  1034. }
  1035. Vue.prototype.mpHost = "mp-weixin";
  1036. Vue.mixin({
  1037. beforeCreate () {
  1038. if (!this.$options.mpType) {
  1039. return
  1040. }
  1041. this.mpType = this.$options.mpType;
  1042. this.$mp = {
  1043. data: {},
  1044. [this.mpType]: this.$options.mpInstance
  1045. };
  1046. this.$scope = this.$options.mpInstance;
  1047. delete this.$options.mpType;
  1048. delete this.$options.mpInstance;
  1049. if (this.mpType !== 'app') {
  1050. initRefs(this);
  1051. initMocks(this, mocks);
  1052. }
  1053. }
  1054. });
  1055. const appOptions = {
  1056. onLaunch (args) {
  1057. if (this.$vm) { // 已经初始化过了,主要是为了百度,百度 onShow 在 onLaunch 之前
  1058. return
  1059. }
  1060. {
  1061. if (!wx.canIUse('nextTick')) { // 事实 上2.2.3 即可,简单使用 2.3.0 的 nextTick 判断
  1062. console.error('当前微信基础库版本过低,请将 微信开发者工具-详情-项目设置-调试基础库版本 更换为`2.3.0`以上');
  1063. }
  1064. }
  1065. this.$vm = vm;
  1066. this.$vm.$mp = {
  1067. app: this
  1068. };
  1069. this.$vm.$scope = this;
  1070. // vm 上也挂载 globalData
  1071. this.$vm.globalData = this.globalData;
  1072. this.$vm._isMounted = true;
  1073. this.$vm.__call_hook('mounted', args);
  1074. this.$vm.__call_hook('onLaunch', args);
  1075. }
  1076. };
  1077. // 兼容旧版本 globalData
  1078. appOptions.globalData = vm.$options.globalData || {};
  1079. // 将 methods 中的方法挂在 getApp() 中
  1080. const methods = vm.$options.methods;
  1081. if (methods) {
  1082. Object.keys(methods).forEach(name => {
  1083. appOptions[name] = methods[name];
  1084. });
  1085. }
  1086. initHooks(appOptions, hooks);
  1087. return appOptions
  1088. }
  1089. const mocks = ['__route__', '__wxExparserNodeId__', '__wxWebviewId__'];
  1090. function findVmByVueId (vm, vuePid) {
  1091. const $children = vm.$children;
  1092. // 优先查找直属(反向查找:https://github.com/dcloudio/uni-app/issues/1200)
  1093. for (let i = $children.length - 1; i >= 0; i--) {
  1094. const childVm = $children[i];
  1095. if (childVm.$scope._$vueId === vuePid) {
  1096. return childVm
  1097. }
  1098. }
  1099. // 反向递归查找
  1100. let parentVm;
  1101. for (let i = $children.length - 1; i >= 0; i--) {
  1102. parentVm = findVmByVueId($children[i], vuePid);
  1103. if (parentVm) {
  1104. return parentVm
  1105. }
  1106. }
  1107. }
  1108. function initBehavior (options) {
  1109. return Behavior(options)
  1110. }
  1111. function isPage () {
  1112. return !!this.route
  1113. }
  1114. function initRelation (detail) {
  1115. this.triggerEvent('__l', detail);
  1116. }
  1117. function initRefs (vm) {
  1118. const mpInstance = vm.$scope;
  1119. Object.defineProperty(vm, '$refs', {
  1120. get () {
  1121. const $refs = {};
  1122. const components = mpInstance.selectAllComponents('.vue-ref');
  1123. components.forEach(component => {
  1124. const ref = component.dataset.ref;
  1125. $refs[ref] = component.$vm || component;
  1126. });
  1127. const forComponents = mpInstance.selectAllComponents('.vue-ref-in-for');
  1128. forComponents.forEach(component => {
  1129. const ref = component.dataset.ref;
  1130. if (!$refs[ref]) {
  1131. $refs[ref] = [];
  1132. }
  1133. $refs[ref].push(component.$vm || component);
  1134. });
  1135. return $refs
  1136. }
  1137. });
  1138. }
  1139. function handleLink (event) {
  1140. const {
  1141. vuePid,
  1142. vueOptions
  1143. } = event.detail || event.value; // detail 是微信,value 是百度(dipatch)
  1144. let parentVm;
  1145. if (vuePid) {
  1146. parentVm = findVmByVueId(this.$vm, vuePid);
  1147. }
  1148. if (!parentVm) {
  1149. parentVm = this.$vm;
  1150. }
  1151. vueOptions.parent = parentVm;
  1152. }
  1153. function parseApp (vm) {
  1154. return parseBaseApp(vm, {
  1155. mocks,
  1156. initRefs
  1157. })
  1158. }
  1159. function createApp (vm) {
  1160. App(parseApp(vm));
  1161. return vm
  1162. }
  1163. function parseBaseComponent (vueComponentOptions, {
  1164. isPage,
  1165. initRelation
  1166. } = {}) {
  1167. const [VueComponent, vueOptions] = initVueComponent(Vue, vueComponentOptions);
  1168. const options = {
  1169. multipleSlots: true,
  1170. addGlobalClass: true,
  1171. ...(vueOptions.options || {})
  1172. };
  1173. {
  1174. // 微信 multipleSlots 部分情况有 bug,导致内容顺序错乱 如 u-list,提供覆盖选项
  1175. if (vueOptions['mp-weixin'] && vueOptions['mp-weixin'].options) {
  1176. Object.assign(options, vueOptions['mp-weixin'].options);
  1177. }
  1178. }
  1179. const componentOptions = {
  1180. options,
  1181. data: initData(vueOptions, Vue.prototype),
  1182. behaviors: initBehaviors(vueOptions, initBehavior),
  1183. properties: initProperties(vueOptions.props, false, vueOptions.__file),
  1184. lifetimes: {
  1185. attached () {
  1186. const properties = this.properties;
  1187. const options = {
  1188. mpType: isPage.call(this) ? 'page' : 'component',
  1189. mpInstance: this,
  1190. propsData: properties
  1191. };
  1192. initVueIds(properties.vueId, this);
  1193. // 处理父子关系
  1194. initRelation.call(this, {
  1195. vuePid: this._$vuePid,
  1196. vueOptions: options
  1197. });
  1198. // 初始化 vue 实例
  1199. this.$vm = new VueComponent(options);
  1200. // 处理$slots,$scopedSlots(暂不支持动态变化$slots)
  1201. initSlots(this.$vm, properties.vueSlots);
  1202. // 触发首次 setData
  1203. this.$vm.$mount();
  1204. },
  1205. ready () {
  1206. // 当组件 props 默认值为 true,初始化时传入 false 会导致 created,ready 触发, 但 attached 不触发
  1207. // https://developers.weixin.qq.com/community/develop/doc/00066ae2844cc0f8eb883e2a557800
  1208. if (this.$vm) {
  1209. this.$vm._isMounted = true;
  1210. this.$vm.__call_hook('mounted');
  1211. this.$vm.__call_hook('onReady');
  1212. }
  1213. },
  1214. detached () {
  1215. this.$vm && this.$vm.$destroy();
  1216. }
  1217. },
  1218. pageLifetimes: {
  1219. show (args) {
  1220. this.$vm && this.$vm.__call_hook('onPageShow', args);
  1221. },
  1222. hide () {
  1223. this.$vm && this.$vm.__call_hook('onPageHide');
  1224. },
  1225. resize (size) {
  1226. this.$vm && this.$vm.__call_hook('onPageResize', size);
  1227. }
  1228. },
  1229. methods: {
  1230. __l: handleLink,
  1231. __e: handleEvent
  1232. }
  1233. };
  1234. // externalClasses
  1235. if (vueOptions.externalClasses) {
  1236. componentOptions.externalClasses = vueOptions.externalClasses;
  1237. }
  1238. if (Array.isArray(vueOptions.wxsCallMethods)) {
  1239. vueOptions.wxsCallMethods.forEach(callMethod => {
  1240. componentOptions.methods[callMethod] = function (args) {
  1241. return this.$vm[callMethod](args)
  1242. };
  1243. });
  1244. }
  1245. if (isPage) {
  1246. return componentOptions
  1247. }
  1248. return [componentOptions, VueComponent]
  1249. }
  1250. function parseComponent (vueComponentOptions) {
  1251. return parseBaseComponent(vueComponentOptions, {
  1252. isPage,
  1253. initRelation
  1254. })
  1255. }
  1256. const hooks$1 = [
  1257. 'onShow',
  1258. 'onHide',
  1259. 'onUnload'
  1260. ];
  1261. hooks$1.push(...PAGE_EVENT_HOOKS);
  1262. function parseBasePage (vuePageOptions, {
  1263. isPage,
  1264. initRelation
  1265. }) {
  1266. const pageOptions = parseComponent(vuePageOptions);
  1267. initHooks(pageOptions.methods, hooks$1, vuePageOptions);
  1268. pageOptions.methods.onLoad = function (args) {
  1269. this.$vm.$mp.query = args; // 兼容 mpvue
  1270. this.$vm.__call_hook('onLoad', args);
  1271. };
  1272. return pageOptions
  1273. }
  1274. function parsePage (vuePageOptions) {
  1275. return parseBasePage(vuePageOptions, {
  1276. isPage,
  1277. initRelation
  1278. })
  1279. }
  1280. function createPage (vuePageOptions) {
  1281. {
  1282. return Component(parsePage(vuePageOptions))
  1283. }
  1284. }
  1285. function createComponent (vueOptions) {
  1286. {
  1287. return Component(parseComponent(vueOptions))
  1288. }
  1289. }
  1290. todos.forEach(todoApi => {
  1291. protocols[todoApi] = false;
  1292. });
  1293. canIUses.forEach(canIUseApi => {
  1294. const apiName = protocols[canIUseApi] && protocols[canIUseApi].name ? protocols[canIUseApi].name
  1295. : canIUseApi;
  1296. if (!wx.canIUse(apiName)) {
  1297. protocols[canIUseApi] = false;
  1298. }
  1299. });
  1300. let uni = {};
  1301. if (typeof Proxy !== 'undefined' && "mp-weixin" !== 'app-plus') {
  1302. uni = new Proxy({}, {
  1303. get (target, name) {
  1304. if (target[name]) {
  1305. return target[name]
  1306. }
  1307. if (baseApi[name]) {
  1308. return baseApi[name]
  1309. }
  1310. if (api[name]) {
  1311. return promisify(name, api[name])
  1312. }
  1313. {
  1314. if (extraApi[name]) {
  1315. return promisify(name, extraApi[name])
  1316. }
  1317. if (todoApis[name]) {
  1318. return promisify(name, todoApis[name])
  1319. }
  1320. }
  1321. if (eventApi[name]) {
  1322. return eventApi[name]
  1323. }
  1324. if (!hasOwn(wx, name) && !hasOwn(protocols, name)) {
  1325. return
  1326. }
  1327. return promisify(name, wrapper(name, wx[name]))
  1328. },
  1329. set (target, name, value) {
  1330. target[name] = value;
  1331. return true
  1332. }
  1333. });
  1334. } else {
  1335. Object.keys(baseApi).forEach(name => {
  1336. uni[name] = baseApi[name];
  1337. });
  1338. {
  1339. Object.keys(todoApis).forEach(name => {
  1340. uni[name] = promisify(name, todoApis[name]);
  1341. });
  1342. Object.keys(extraApi).forEach(name => {
  1343. uni[name] = promisify(name, todoApis[name]);
  1344. });
  1345. }
  1346. Object.keys(eventApi).forEach(name => {
  1347. uni[name] = eventApi[name];
  1348. });
  1349. Object.keys(api).forEach(name => {
  1350. uni[name] = promisify(name, api[name]);
  1351. });
  1352. Object.keys(wx).forEach(name => {
  1353. if (hasOwn(wx, name) || hasOwn(protocols, name)) {
  1354. uni[name] = promisify(name, wrapper(name, wx[name]));
  1355. }
  1356. });
  1357. }
  1358. wx.createApp = createApp;
  1359. wx.createPage = createPage;
  1360. wx.createComponent = createComponent;
  1361. var uni$1 = uni;
  1362. export default uni$1;
  1363. export { createApp, createComponent, createPage };