足力健前端,vue版本

index.js 38KB

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