足力健前端,vue版本

index.js 53KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265
  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. } = my.getSystemInfoSync(); // uni=>my 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. // 不支持的 API 列表
  316. const todos = [
  317. // 'getRecorderManager',
  318. // 'getBackgroundAudioManager',
  319. // 'createInnerAudioContext',
  320. // 'createCameraContext',
  321. // 'createLivePlayerContext',
  322. // 'startAccelerometer',
  323. // 'startCompass',
  324. // 'authorize',
  325. // 'chooseInvoiceTitle',
  326. // 'addTemplate',
  327. // 'deleteTemplate',
  328. // 'getTemplateLibraryById',
  329. // 'getTemplateLibraryList',
  330. // 'getTemplateList',
  331. // 'sendTemplateMessage',
  332. // 'setEnableDebug',
  333. // 'getExtConfig',
  334. // 'getExtConfigSync',
  335. // 'onWindowResize',
  336. // 'offWindowResize'
  337. ];
  338. // 存在兼容性的 API 列表
  339. const canIUses = [
  340. 'startPullDownRefresh',
  341. 'setTabBarItem',
  342. 'setTabBarStyle',
  343. 'hideTabBar',
  344. 'showTabBar',
  345. 'setTabBarBadge',
  346. 'removeTabBarBadge',
  347. 'showTabBarRedDot',
  348. 'hideTabBarRedDot',
  349. 'openSetting',
  350. 'getSetting',
  351. 'createIntersectionObserver',
  352. 'getUpdateManager',
  353. 'setBackgroundColor',
  354. 'setBackgroundTextStyle',
  355. 'checkIsSupportSoterAuthentication',
  356. 'startSoterAuthentication',
  357. 'checkIsSoterEnrolledInDevice',
  358. 'openDocument',
  359. 'createVideoContext',
  360. 'onMemoryWarning',
  361. 'addPhoneContact'
  362. ];
  363. function _handleNetworkInfo (result) {
  364. switch (result.networkType) {
  365. case 'NOTREACHABLE':
  366. result.networkType = 'none';
  367. break
  368. case 'WWAN':
  369. // TODO ?
  370. result.networkType = '3g';
  371. break
  372. default:
  373. result.networkType = result.networkType.toLowerCase();
  374. break
  375. }
  376. return {}
  377. }
  378. function _handleSystemInfo (result) {
  379. let platform = result.platform ? result.platform.toLowerCase() : 'devtools';
  380. if (!~['android', 'ios'].indexOf(platform)) {
  381. platform = 'devtools';
  382. }
  383. result.platform = platform;
  384. }
  385. const protocols = { // 需要做转换的 API 列表
  386. returnValue (methodName, res = {}) { // 通用 returnValue 解析
  387. if (res.error || res.errorMessage) {
  388. res.errMsg = `${methodName}:fail ${res.errorMessage || res.error}`;
  389. delete res.error;
  390. delete res.errorMessage;
  391. } else {
  392. res.errMsg = `${methodName}:ok`;
  393. }
  394. return res
  395. },
  396. request: {
  397. name: my.canIUse('request') ? 'request' : 'httpRequest',
  398. args (fromArgs) {
  399. if (!fromArgs.header) { // 默认增加 header 参数,方便格式化 content-type
  400. fromArgs.header = {};
  401. }
  402. const headers = {
  403. 'content-type': 'application/json'
  404. };
  405. Object.keys(fromArgs.header).forEach(key => {
  406. headers[key.toLocaleLowerCase()] = fromArgs.header[key];
  407. });
  408. return {
  409. header (header = {}, toArgs) {
  410. return {
  411. name: 'headers',
  412. value: headers
  413. }
  414. },
  415. data (data) {
  416. // 钉钉在content-type为application/json时,不会自动序列化
  417. if (my.dd && headers['content-type'].indexOf('application/json') === 0) {
  418. return {
  419. name: 'data',
  420. value: JSON.stringify(data)
  421. }
  422. }
  423. return {
  424. name: 'data',
  425. value: data
  426. }
  427. },
  428. method: 'method', // TODO 支付宝小程序仅支持 get,post
  429. responseType: false
  430. }
  431. },
  432. returnValue: {
  433. status: 'statusCode',
  434. headers: 'header'
  435. }
  436. },
  437. setNavigationBarColor: {
  438. name: 'setNavigationBar',
  439. args: {
  440. frontColor: false,
  441. animation: false
  442. }
  443. },
  444. setNavigationBarTitle: {
  445. name: 'setNavigationBar'
  446. },
  447. showModal ({
  448. showCancel = true
  449. } = {}) {
  450. if (showCancel) {
  451. return {
  452. name: 'confirm',
  453. args: {
  454. cancelColor: false,
  455. confirmColor: false,
  456. cancelText: 'cancelButtonText',
  457. confirmText: 'confirmButtonText'
  458. },
  459. returnValue (fromRes, toRes) {
  460. toRes.confirm = fromRes.confirm;
  461. toRes.cancel = !fromRes.confirm;
  462. }
  463. }
  464. }
  465. return {
  466. name: 'alert',
  467. args: {
  468. confirmColor: false,
  469. confirmText: 'buttonText'
  470. },
  471. returnValue (fromRes, toRes) {
  472. toRes.confirm = true;
  473. toRes.cancel = false;
  474. }
  475. }
  476. },
  477. showToast ({
  478. icon = 'success'
  479. } = {}) {
  480. const args = {
  481. title: 'content',
  482. icon: 'type',
  483. duration: false,
  484. image: false,
  485. mask: false
  486. };
  487. if (icon === 'loading') {
  488. return {
  489. name: 'showLoading',
  490. args
  491. }
  492. }
  493. return {
  494. name: 'showToast',
  495. args
  496. }
  497. },
  498. showActionSheet: {
  499. name: 'showActionSheet',
  500. args: {
  501. itemList: 'items',
  502. itemColor: false
  503. },
  504. returnValue: {
  505. index: 'tapIndex'
  506. }
  507. },
  508. showLoading: {
  509. args: {
  510. title: 'content',
  511. mask: false
  512. }
  513. },
  514. uploadFile: {
  515. args: {
  516. name: 'fileName'
  517. }
  518. // 从测试结果看,是有返回对象的,文档上没有说明。
  519. },
  520. downloadFile: {
  521. returnValue: {
  522. apFilePath: 'tempFilePath'
  523. }
  524. },
  525. getFileInfo: {
  526. args: {
  527. filePath: 'apFilePath'
  528. }
  529. },
  530. chooseVideo: {
  531. // 支付宝小程序文档中未找到(仅在getSetting处提及),但实际可用
  532. returnValue: {
  533. apFilePath: 'tempFilePath'
  534. }
  535. },
  536. connectSocket: {
  537. args: {
  538. method: false,
  539. protocols: false
  540. }
  541. // TODO 有没有返回值还需要测试下
  542. },
  543. chooseImage: {
  544. returnValue: {
  545. apFilePaths: 'tempFilePaths'
  546. }
  547. },
  548. previewImage: {
  549. args (fromArgs) {
  550. // 支付宝小程序的 current 是索引值,而非图片地址。
  551. const currentIndex = Number(fromArgs.current);
  552. if (isNaN(currentIndex)) {
  553. if (fromArgs.current && Array.isArray(fromArgs.urls)) {
  554. const index = fromArgs.urls.indexOf(fromArgs.current);
  555. fromArgs.current = ~index ? index : 0;
  556. }
  557. } else {
  558. fromArgs.current = currentIndex;
  559. }
  560. return {
  561. indicator: false,
  562. loop: false
  563. }
  564. }
  565. },
  566. saveFile: {
  567. args: {
  568. tempFilePath: 'apFilePath'
  569. },
  570. returnValue: {
  571. apFilePath: 'savedFilePath'
  572. }
  573. },
  574. getSavedFileInfo: {
  575. args: {
  576. filePath: 'apFilePath'
  577. },
  578. returnValue (result) {
  579. if (result.fileList && result.fileList.length) {
  580. result.fileList.forEach(file => {
  581. file.filePath = file.apFilePath;
  582. delete file.apFilePath;
  583. });
  584. }
  585. return {}
  586. }
  587. },
  588. removeSavedFile: {
  589. args: {
  590. filePath: 'apFilePath'
  591. }
  592. },
  593. getLocation: {
  594. args: {
  595. type: false,
  596. altitude: false
  597. }
  598. },
  599. openLocation: {
  600. args: {
  601. // TODO address 参数在阿里上是必传的
  602. }
  603. },
  604. getNetworkType: {
  605. returnValue: _handleNetworkInfo
  606. },
  607. onNetworkStatusChange: {
  608. returnValue: _handleNetworkInfo
  609. },
  610. stopAccelerometer: {
  611. name: 'offAccelerometerChange'
  612. },
  613. stopCompass: {
  614. name: 'offCompassChange'
  615. },
  616. scanCode: {
  617. name: 'scan',
  618. args (fromArgs) {
  619. if (fromArgs.scanType) {
  620. switch (fromArgs.scanType[0]) {
  621. case 'qrCode':
  622. fromArgs.type = 'qr';
  623. break
  624. case 'barCode':
  625. fromArgs.type = 'bar';
  626. break
  627. }
  628. }
  629. return {
  630. onlyFromCamera: 'hideAlbum'
  631. }
  632. },
  633. returnValue: {
  634. code: 'result'
  635. }
  636. },
  637. setClipboardData: {
  638. name: 'setClipboard',
  639. args: {
  640. data: 'text'
  641. }
  642. },
  643. getClipboardData: {
  644. name: 'getClipboard',
  645. returnValue: {
  646. text: 'data'
  647. }
  648. },
  649. pageScrollTo: {
  650. args: {
  651. duration: false
  652. }
  653. },
  654. login: {
  655. name: 'getAuthCode',
  656. returnValue (result) {
  657. result.code = result.authCode;
  658. }
  659. },
  660. getUserInfo: {
  661. name: my.canIUse('getOpenUserInfo') ? 'getOpenUserInfo' : 'getAuthUserInfo',
  662. returnValue (result) {
  663. if (my.canIUse('getOpenUserInfo')) {
  664. let response = {};
  665. try {
  666. response = JSON.parse(result.response).response;
  667. } catch (e) {}
  668. result.nickName = response.nickName;
  669. result.avatar = response.avatar;
  670. }
  671. result.userInfo = {
  672. nickName: result.nickName,
  673. avatarUrl: result.avatar
  674. };
  675. }
  676. },
  677. requestPayment: {
  678. name: 'tradePay',
  679. args: {
  680. orderInfo: 'tradeNO'
  681. }
  682. },
  683. getBLEDeviceServices: {
  684. returnValue (result) {
  685. result.services.forEach((item) => {
  686. item.uuid = item.serviceId;
  687. });
  688. }
  689. },
  690. createBLEConnection: {
  691. name: 'connectBLEDevice',
  692. args: {
  693. timeout: false
  694. }
  695. },
  696. closeBLEConnection: {
  697. name: 'disconnectBLEDevice'
  698. },
  699. onBLEConnectionStateChange: {
  700. name: 'onBLEConnectionStateChanged'
  701. },
  702. makePhoneCall: {
  703. args: {
  704. phoneNumber: 'number'
  705. }
  706. },
  707. stopGyroscope: {
  708. name: 'offGyroscopeChange'
  709. },
  710. getSystemInfo: {
  711. returnValue: _handleSystemInfo
  712. },
  713. getSystemInfoSync: {
  714. returnValue: _handleSystemInfo
  715. },
  716. // 文档没提到,但是实测可用。
  717. canvasToTempFilePath: {
  718. returnValue (result) {
  719. // 真机的情况下会有 tempFilePath 这个值,因此需要主动修改。
  720. result.tempFilePath = result.apFilePath;
  721. }
  722. },
  723. setScreenBrightness: {
  724. args: {
  725. value: 'brightness'
  726. }
  727. },
  728. getScreenBrightness: {
  729. returnValue: {
  730. brightness: 'value'
  731. }
  732. },
  733. showShareMenu: {
  734. name: 'showSharePanel'
  735. },
  736. hideHomeButton: {
  737. name: 'hideBackHome'
  738. },
  739. saveImageToPhotosAlbum: {
  740. name: 'saveImage',
  741. args: {
  742. filePath: 'url'
  743. }
  744. },
  745. saveVideoToPhotosAlbum: {
  746. args: {
  747. filePath: 'src'
  748. }
  749. },
  750. chooseAddress: {
  751. name: 'getAddress',
  752. returnValue (result) {
  753. const info = result.result || {};
  754. result.userName = info.fullname;
  755. result.provinceName = info.prov;
  756. result.cityName = info.city;
  757. result.detailInfo = info.address;
  758. result.telNumber = info.mobilePhone;
  759. result.errMsg = result.resultStatus;
  760. }
  761. }
  762. };
  763. const CALLBACKS = ['success', 'fail', 'cancel', 'complete'];
  764. function processCallback (methodName, method, returnValue) {
  765. return function (res) {
  766. return method(processReturnValue(methodName, res, returnValue))
  767. }
  768. }
  769. function processArgs (methodName, fromArgs, argsOption = {}, returnValue = {}, keepFromArgs = false) {
  770. if (isPlainObject(fromArgs)) { // 一般 api 的参数解析
  771. const toArgs = keepFromArgs === true ? fromArgs : {}; // returnValue 为 false 时,说明是格式化返回值,直接在返回值对象上修改赋值
  772. if (isFn(argsOption)) {
  773. argsOption = argsOption(fromArgs, toArgs) || {};
  774. }
  775. for (const key in fromArgs) {
  776. if (hasOwn(argsOption, key)) {
  777. let keyOption = argsOption[key];
  778. if (isFn(keyOption)) {
  779. keyOption = keyOption(fromArgs[key], fromArgs, toArgs);
  780. }
  781. if (!keyOption) { // 不支持的参数
  782. console.warn(`支付宝小程序 ${methodName}暂不支持${key}`);
  783. } else if (isStr(keyOption)) { // 重写参数 key
  784. toArgs[keyOption] = fromArgs[key];
  785. } else if (isPlainObject(keyOption)) { // {name:newName,value:value}可重新指定参数 key:value
  786. toArgs[keyOption.name ? keyOption.name : key] = keyOption.value;
  787. }
  788. } else if (CALLBACKS.indexOf(key) !== -1) {
  789. toArgs[key] = processCallback(methodName, fromArgs[key], returnValue);
  790. } else {
  791. if (!keepFromArgs) {
  792. toArgs[key] = fromArgs[key];
  793. }
  794. }
  795. }
  796. return toArgs
  797. } else if (isFn(fromArgs)) {
  798. fromArgs = processCallback(methodName, fromArgs, returnValue);
  799. }
  800. return fromArgs
  801. }
  802. function processReturnValue (methodName, res, returnValue, keepReturnValue = false) {
  803. if (isFn(protocols.returnValue)) { // 处理通用 returnValue
  804. res = protocols.returnValue(methodName, res);
  805. }
  806. return processArgs(methodName, res, returnValue, {}, keepReturnValue)
  807. }
  808. function wrapper (methodName, method) {
  809. if (hasOwn(protocols, methodName)) {
  810. const protocol = protocols[methodName];
  811. if (!protocol) { // 暂不支持的 api
  812. return function () {
  813. console.error(`支付宝小程序 暂不支持${methodName}`);
  814. }
  815. }
  816. return function (arg1, arg2) { // 目前 api 最多两个参数
  817. let options = protocol;
  818. if (isFn(protocol)) {
  819. options = protocol(arg1);
  820. }
  821. arg1 = processArgs(methodName, arg1, options.args, options.returnValue);
  822. const args = [arg1];
  823. if (typeof arg2 !== 'undefined') {
  824. args.push(arg2);
  825. }
  826. const returnValue = my[options.name || methodName].apply(my, args);
  827. if (isSyncApi(methodName)) { // 同步 api
  828. return processReturnValue(methodName, returnValue, options.returnValue, isContextApi(methodName))
  829. }
  830. return returnValue
  831. }
  832. }
  833. return method
  834. }
  835. const todoApis = Object.create(null);
  836. const TODOS = [
  837. 'onTabBarMidButtonTap',
  838. 'subscribePush',
  839. 'unsubscribePush',
  840. 'onPush',
  841. 'offPush',
  842. 'share'
  843. ];
  844. function createTodoApi (name) {
  845. return function todoApi ({
  846. fail,
  847. complete
  848. }) {
  849. const res = {
  850. errMsg: `${name}:fail:暂不支持 ${name} 方法`
  851. };
  852. isFn(fail) && fail(res);
  853. isFn(complete) && complete(res);
  854. }
  855. }
  856. TODOS.forEach(function (name) {
  857. todoApis[name] = createTodoApi(name);
  858. });
  859. var providers = {
  860. oauth: ['alipay'],
  861. share: ['alipay'],
  862. payment: ['alipay'],
  863. push: ['alipay']
  864. };
  865. function getProvider ({
  866. service,
  867. success,
  868. fail,
  869. complete
  870. }) {
  871. let res = false;
  872. if (providers[service]) {
  873. res = {
  874. errMsg: 'getProvider:ok',
  875. service,
  876. provider: providers[service]
  877. };
  878. isFn(success) && success(res);
  879. } else {
  880. res = {
  881. errMsg: 'getProvider:fail:服务[' + service + ']不存在'
  882. };
  883. isFn(fail) && fail(res);
  884. }
  885. isFn(complete) && complete(res);
  886. }
  887. var extraApi = /*#__PURE__*/Object.freeze({
  888. __proto__: null,
  889. getProvider: getProvider
  890. });
  891. const getEmitter = (function () {
  892. if (typeof getUniEmitter === 'function') {
  893. /* eslint-disable no-undef */
  894. return getUniEmitter
  895. }
  896. let Emitter;
  897. return function getUniEmitter () {
  898. if (!Emitter) {
  899. Emitter = new Vue();
  900. }
  901. return Emitter
  902. }
  903. })();
  904. function apply (ctx, method, args) {
  905. return ctx[method].apply(ctx, args)
  906. }
  907. function $on () {
  908. return apply(getEmitter(), '$on', [...arguments])
  909. }
  910. function $off () {
  911. return apply(getEmitter(), '$off', [...arguments])
  912. }
  913. function $once () {
  914. return apply(getEmitter(), '$once', [...arguments])
  915. }
  916. function $emit () {
  917. return apply(getEmitter(), '$emit', [...arguments])
  918. }
  919. var eventApi = /*#__PURE__*/Object.freeze({
  920. __proto__: null,
  921. $on: $on,
  922. $off: $off,
  923. $once: $once,
  924. $emit: $emit
  925. });
  926. function setStorageSync (key, data) {
  927. return my.setStorageSync({
  928. key,
  929. data
  930. })
  931. }
  932. function getStorageSync (key) {
  933. const result = my.getStorageSync({
  934. key
  935. });
  936. // 支付宝平台会返回一个 success 值,但是目前测试的结果这个始终是 true。当没有存储数据的时候,其它平台会返回空字符串。
  937. return result.data !== null ? result.data : ''
  938. }
  939. function removeStorageSync (key) {
  940. return my.removeStorageSync({
  941. key
  942. })
  943. }
  944. function startGyroscope (params) {
  945. if (hasOwn(params, 'interval')) {
  946. console.warn('支付宝小程序 startGyroscope暂不支持interval');
  947. }
  948. params.success && params.success({
  949. errMsg: 'startGyroscope:ok'
  950. });
  951. params.complete && params.complete({
  952. errMsg: 'startGyroscope:ok'
  953. });
  954. }
  955. function createExecCallback (execCallback) {
  956. return function wrapperExecCallback (res) {
  957. this.actions.forEach((action, index) => {
  958. (action._$callbacks || []).forEach(callback => {
  959. callback(res[index]);
  960. });
  961. });
  962. if (isFn(execCallback)) {
  963. execCallback(res);
  964. }
  965. }
  966. }
  967. function addCallback (callback) {
  968. if (isFn(callback)) {
  969. const action = this.actions[this.actions.length - 1];
  970. if (action) {
  971. (action._$callbacks || (action._$callbacks = [])).push(callback);
  972. }
  973. }
  974. }
  975. function createSelectorQuery () {
  976. const query = my.createSelectorQuery();
  977. const oldExec = query.exec;
  978. const oldScrollOffset = query.scrollOffset;
  979. const oldBoundingClientRect = query.boundingClientRect;
  980. query.exec = function exec (callback) {
  981. return oldExec.call(this, createExecCallback(callback).bind(this))
  982. };
  983. query.scrollOffset = function scrollOffset (callback) {
  984. const ret = oldScrollOffset.call(this);
  985. addCallback.call(this, callback);
  986. return ret
  987. };
  988. query.boundingClientRect = function boundingClientRect (callback) {
  989. const ret = oldBoundingClientRect.call(this);
  990. addCallback.call(this, callback);
  991. return ret
  992. };
  993. if (!query.fields) {
  994. query.fields = function ({ rect, size, scrollOffset } = {}, callback) {
  995. if (rect || size) {
  996. this.boundingClientRect();
  997. }
  998. if (scrollOffset) {
  999. this.scrollOffset();
  1000. }
  1001. addCallback.call(this, callback);
  1002. return this
  1003. };
  1004. }
  1005. if (!query.in) {
  1006. query.in = function () {
  1007. return this
  1008. };
  1009. }
  1010. return query
  1011. }
  1012. function createIntersectionObserver (component, options) {
  1013. if (options && options.observeAll) {
  1014. options.selectAll = options.observeAll;
  1015. delete options.observeAll;
  1016. }
  1017. return my.createIntersectionObserver(options)
  1018. }
  1019. var api = /*#__PURE__*/Object.freeze({
  1020. __proto__: null,
  1021. setStorageSync: setStorageSync,
  1022. getStorageSync: getStorageSync,
  1023. removeStorageSync: removeStorageSync,
  1024. startGyroscope: startGyroscope,
  1025. createSelectorQuery: createSelectorQuery,
  1026. createIntersectionObserver: createIntersectionObserver
  1027. });
  1028. const PAGE_EVENT_HOOKS = [
  1029. 'onPullDownRefresh',
  1030. 'onReachBottom',
  1031. 'onShareAppMessage',
  1032. 'onPageScroll',
  1033. 'onResize',
  1034. 'onTabItemTap'
  1035. ];
  1036. function initMocks (vm, mocks) {
  1037. const mpInstance = vm.$mp[vm.mpType];
  1038. mocks.forEach(mock => {
  1039. if (hasOwn(mpInstance, mock)) {
  1040. vm[mock] = mpInstance[mock];
  1041. }
  1042. });
  1043. }
  1044. function hasHook (hook, vueOptions) {
  1045. if (!vueOptions) {
  1046. return true
  1047. }
  1048. if (Vue.options && Array.isArray(Vue.options[hook])) {
  1049. return true
  1050. }
  1051. vueOptions = vueOptions.default || vueOptions;
  1052. if (isFn(vueOptions)) {
  1053. if (isFn(vueOptions.extendOptions[hook])) {
  1054. return true
  1055. }
  1056. if (vueOptions.super &&
  1057. vueOptions.super.options &&
  1058. Array.isArray(vueOptions.super.options[hook])) {
  1059. return true
  1060. }
  1061. return false
  1062. }
  1063. if (isFn(vueOptions[hook])) {
  1064. return true
  1065. }
  1066. const mixins = vueOptions.mixins;
  1067. if (Array.isArray(mixins)) {
  1068. return !!mixins.find(mixin => hasHook(hook, mixin))
  1069. }
  1070. }
  1071. function initHooks (mpOptions, hooks, vueOptions) {
  1072. hooks.forEach(hook => {
  1073. if (hasHook(hook, vueOptions)) {
  1074. mpOptions[hook] = function (args) {
  1075. return this.$vm && this.$vm.__call_hook(hook, args)
  1076. };
  1077. }
  1078. });
  1079. }
  1080. function initVueComponent (Vue, vueOptions) {
  1081. vueOptions = vueOptions.default || vueOptions;
  1082. let VueComponent;
  1083. if (isFn(vueOptions)) {
  1084. VueComponent = vueOptions;
  1085. } else {
  1086. VueComponent = Vue.extend(vueOptions);
  1087. }
  1088. vueOptions = VueComponent.options;
  1089. return [VueComponent, vueOptions]
  1090. }
  1091. function initVueIds (vueIds, mpInstance) {
  1092. vueIds = (vueIds || '').split(',');
  1093. const len = vueIds.length;
  1094. if (len === 1) {
  1095. mpInstance._$vueId = vueIds[0];
  1096. } else if (len === 2) {
  1097. mpInstance._$vueId = vueIds[0];
  1098. mpInstance._$vuePid = vueIds[1];
  1099. }
  1100. }
  1101. function initData (vueOptions, context) {
  1102. let data = vueOptions.data || {};
  1103. const methods = vueOptions.methods || {};
  1104. if (typeof data === 'function') {
  1105. try {
  1106. data = data.call(context); // 支持 Vue.prototype 上挂的数据
  1107. } catch (e) {
  1108. if (process.env.VUE_APP_DEBUG) {
  1109. console.warn('根据 Vue 的 data 函数初始化小程序 data 失败,请尽量确保 data 函数中不访问 vm 对象,否则可能影响首次数据渲染速度。', data);
  1110. }
  1111. }
  1112. } else {
  1113. try {
  1114. // 对 data 格式化
  1115. data = JSON.parse(JSON.stringify(data));
  1116. } catch (e) {}
  1117. }
  1118. if (!isPlainObject(data)) {
  1119. data = {};
  1120. }
  1121. Object.keys(methods).forEach(methodName => {
  1122. if (context.__lifecycle_hooks__.indexOf(methodName) === -1 && !hasOwn(data, methodName)) {
  1123. data[methodName] = methods[methodName];
  1124. }
  1125. });
  1126. return data
  1127. }
  1128. const PROP_TYPES = [String, Number, Boolean, Object, Array, null];
  1129. function createObserver (name) {
  1130. return function observer (newVal, oldVal) {
  1131. if (this.$vm) {
  1132. this.$vm[name] = newVal; // 为了触发其他非 render watcher
  1133. }
  1134. }
  1135. }
  1136. function initBehaviors (vueOptions, initBehavior) {
  1137. const vueBehaviors = vueOptions.behaviors;
  1138. const vueExtends = vueOptions.extends;
  1139. const vueMixins = vueOptions.mixins;
  1140. let vueProps = vueOptions.props;
  1141. if (!vueProps) {
  1142. vueOptions.props = vueProps = [];
  1143. }
  1144. const behaviors = [];
  1145. if (Array.isArray(vueBehaviors)) {
  1146. vueBehaviors.forEach(behavior => {
  1147. behaviors.push(behavior.replace('uni://', `${"my"}://`));
  1148. if (behavior === 'uni://form-field') {
  1149. if (Array.isArray(vueProps)) {
  1150. vueProps.push('name');
  1151. vueProps.push('value');
  1152. } else {
  1153. vueProps.name = {
  1154. type: String,
  1155. default: ''
  1156. };
  1157. vueProps.value = {
  1158. type: [String, Number, Boolean, Array, Object, Date],
  1159. default: ''
  1160. };
  1161. }
  1162. }
  1163. });
  1164. }
  1165. if (isPlainObject(vueExtends) && vueExtends.props) {
  1166. behaviors.push(
  1167. initBehavior({
  1168. properties: initProperties(vueExtends.props, true)
  1169. })
  1170. );
  1171. }
  1172. if (Array.isArray(vueMixins)) {
  1173. vueMixins.forEach(vueMixin => {
  1174. if (isPlainObject(vueMixin) && vueMixin.props) {
  1175. behaviors.push(
  1176. initBehavior({
  1177. properties: initProperties(vueMixin.props, true)
  1178. })
  1179. );
  1180. }
  1181. });
  1182. }
  1183. return behaviors
  1184. }
  1185. function parsePropType (key, type, defaultValue, file) {
  1186. // [String]=>String
  1187. if (Array.isArray(type) && type.length === 1) {
  1188. return type[0]
  1189. }
  1190. return type
  1191. }
  1192. function initProperties (props, isBehavior = false, file = '') {
  1193. const properties = {};
  1194. if (!isBehavior) {
  1195. properties.vueId = {
  1196. type: String,
  1197. value: ''
  1198. };
  1199. properties.vueSlots = { // 小程序不能直接定义 $slots 的 props,所以通过 vueSlots 转换到 $slots
  1200. type: null,
  1201. value: [],
  1202. observer: function (newVal, oldVal) {
  1203. const $slots = Object.create(null);
  1204. newVal.forEach(slotName => {
  1205. $slots[slotName] = true;
  1206. });
  1207. this.setData({
  1208. $slots
  1209. });
  1210. }
  1211. };
  1212. }
  1213. if (Array.isArray(props)) { // ['title']
  1214. props.forEach(key => {
  1215. properties[key] = {
  1216. type: null,
  1217. observer: createObserver(key)
  1218. };
  1219. });
  1220. } else if (isPlainObject(props)) { // {title:{type:String,default:''},content:String}
  1221. Object.keys(props).forEach(key => {
  1222. const opts = props[key];
  1223. if (isPlainObject(opts)) { // title:{type:String,default:''}
  1224. let value = opts.default;
  1225. if (isFn(value)) {
  1226. value = value();
  1227. }
  1228. opts.type = parsePropType(key, opts.type);
  1229. properties[key] = {
  1230. type: PROP_TYPES.indexOf(opts.type) !== -1 ? opts.type : null,
  1231. value,
  1232. observer: createObserver(key)
  1233. };
  1234. } else { // content:String
  1235. const type = parsePropType(key, opts);
  1236. properties[key] = {
  1237. type: PROP_TYPES.indexOf(type) !== -1 ? type : null,
  1238. observer: createObserver(key)
  1239. };
  1240. }
  1241. });
  1242. }
  1243. return properties
  1244. }
  1245. function wrapper$1 (event) {
  1246. // TODO 又得兼容 mpvue 的 mp 对象
  1247. try {
  1248. event.mp = JSON.parse(JSON.stringify(event));
  1249. } catch (e) {}
  1250. event.stopPropagation = noop;
  1251. event.preventDefault = noop;
  1252. event.target = event.target || {};
  1253. if (!hasOwn(event, 'detail')) {
  1254. event.detail = {};
  1255. }
  1256. if (hasOwn(event, 'markerId')) {
  1257. event.detail = typeof event.detail === 'object' ? event.detail : {};
  1258. event.detail.markerId = event.markerId;
  1259. }
  1260. if (isPlainObject(event.detail)) {
  1261. event.target = Object.assign({}, event.target, event.detail);
  1262. }
  1263. return event
  1264. }
  1265. function getExtraValue (vm, dataPathsArray) {
  1266. let context = vm;
  1267. dataPathsArray.forEach(dataPathArray => {
  1268. const dataPath = dataPathArray[0];
  1269. const value = dataPathArray[2];
  1270. if (dataPath || typeof value !== 'undefined') { // ['','',index,'disable']
  1271. const propPath = dataPathArray[1];
  1272. const valuePath = dataPathArray[3];
  1273. const vFor = dataPath ? vm.__get_value(dataPath, context) : context;
  1274. if (Number.isInteger(vFor)) {
  1275. context = value;
  1276. } else if (!propPath) {
  1277. context = vFor[value];
  1278. } else {
  1279. if (Array.isArray(vFor)) {
  1280. context = vFor.find(vForItem => {
  1281. return vm.__get_value(propPath, vForItem) === value
  1282. });
  1283. } else if (isPlainObject(vFor)) {
  1284. context = Object.keys(vFor).find(vForKey => {
  1285. return vm.__get_value(propPath, vFor[vForKey]) === value
  1286. });
  1287. } else {
  1288. console.error('v-for 暂不支持循环数据:', vFor);
  1289. }
  1290. }
  1291. if (valuePath) {
  1292. context = vm.__get_value(valuePath, context);
  1293. }
  1294. }
  1295. });
  1296. return context
  1297. }
  1298. function processEventExtra (vm, extra, event) {
  1299. const extraObj = {};
  1300. if (Array.isArray(extra) && extra.length) {
  1301. /**
  1302. *[
  1303. * ['data.items', 'data.id', item.data.id],
  1304. * ['metas', 'id', meta.id]
  1305. *],
  1306. *[
  1307. * ['data.items', 'data.id', item.data.id],
  1308. * ['metas', 'id', meta.id]
  1309. *],
  1310. *'test'
  1311. */
  1312. extra.forEach((dataPath, index) => {
  1313. if (typeof dataPath === 'string') {
  1314. if (!dataPath) { // model,prop.sync
  1315. extraObj['$' + index] = vm;
  1316. } else {
  1317. if (dataPath === '$event') { // $event
  1318. extraObj['$' + index] = event;
  1319. } else if (dataPath.indexOf('$event.') === 0) { // $event.target.value
  1320. extraObj['$' + index] = vm.__get_value(dataPath.replace('$event.', ''), event);
  1321. } else {
  1322. extraObj['$' + index] = vm.__get_value(dataPath);
  1323. }
  1324. }
  1325. } else {
  1326. extraObj['$' + index] = getExtraValue(vm, dataPath);
  1327. }
  1328. });
  1329. }
  1330. return extraObj
  1331. }
  1332. function getObjByArray (arr) {
  1333. const obj = {};
  1334. for (let i = 1; i < arr.length; i++) {
  1335. const element = arr[i];
  1336. obj[element[0]] = element[1];
  1337. }
  1338. return obj
  1339. }
  1340. function processEventArgs (vm, event, args = [], extra = [], isCustom, methodName) {
  1341. let isCustomMPEvent = false; // wxcomponent 组件,传递原始 event 对象
  1342. if (isCustom) { // 自定义事件
  1343. isCustomMPEvent = event.currentTarget &&
  1344. event.currentTarget.dataset &&
  1345. event.currentTarget.dataset.comType === 'wx';
  1346. if (!args.length) { // 无参数,直接传入 event 或 detail 数组
  1347. if (isCustomMPEvent) {
  1348. return [event]
  1349. }
  1350. return event.detail.__args__ || event.detail
  1351. }
  1352. }
  1353. const extraObj = processEventExtra(vm, extra, event);
  1354. const ret = [];
  1355. args.forEach(arg => {
  1356. if (arg === '$event') {
  1357. if (methodName === '__set_model' && !isCustom) { // input v-model value
  1358. ret.push(event.target.value);
  1359. } else {
  1360. if (isCustom && !isCustomMPEvent) {
  1361. ret.push(event.detail.__args__[0]);
  1362. } else { // wxcomponent 组件或内置组件
  1363. ret.push(event);
  1364. }
  1365. }
  1366. } else {
  1367. if (Array.isArray(arg) && arg[0] === 'o') {
  1368. ret.push(getObjByArray(arg));
  1369. } else if (typeof arg === 'string' && hasOwn(extraObj, arg)) {
  1370. ret.push(extraObj[arg]);
  1371. } else {
  1372. ret.push(arg);
  1373. }
  1374. }
  1375. });
  1376. return ret
  1377. }
  1378. const ONCE = '~';
  1379. const CUSTOM = '^';
  1380. function isMatchEventType (eventType, optType) {
  1381. return (eventType === optType) ||
  1382. (
  1383. optType === 'regionchange' &&
  1384. (
  1385. eventType === 'begin' ||
  1386. eventType === 'end'
  1387. )
  1388. )
  1389. }
  1390. function handleEvent (event) {
  1391. event = wrapper$1(event);
  1392. // [['tap',[['handle',[1,2,a]],['handle1',[1,2,a]]]]]
  1393. const dataset = (event.currentTarget || event.target).dataset;
  1394. if (!dataset) {
  1395. return console.warn('事件信息不存在')
  1396. }
  1397. const eventOpts = dataset.eventOpts || dataset['event-opts']; // 支付宝 web-view 组件 dataset 非驼峰
  1398. if (!eventOpts) {
  1399. return console.warn('事件信息不存在')
  1400. }
  1401. // [['handle',[1,2,a]],['handle1',[1,2,a]]]
  1402. const eventType = event.type;
  1403. const ret = [];
  1404. eventOpts.forEach(eventOpt => {
  1405. let type = eventOpt[0];
  1406. const eventsArray = eventOpt[1];
  1407. const isCustom = type.charAt(0) === CUSTOM;
  1408. type = isCustom ? type.slice(1) : type;
  1409. const isOnce = type.charAt(0) === ONCE;
  1410. type = isOnce ? type.slice(1) : type;
  1411. if (eventsArray && isMatchEventType(eventType, type)) {
  1412. eventsArray.forEach(eventArray => {
  1413. const methodName = eventArray[0];
  1414. if (methodName) {
  1415. let handlerCtx = this.$vm;
  1416. if (
  1417. handlerCtx.$options.generic &&
  1418. handlerCtx.$parent &&
  1419. handlerCtx.$parent.$parent
  1420. ) { // mp-weixin,mp-toutiao 抽象节点模拟 scoped slots
  1421. handlerCtx = handlerCtx.$parent.$parent;
  1422. }
  1423. if (methodName === '$emit') {
  1424. handlerCtx.$emit.apply(handlerCtx,
  1425. processEventArgs(
  1426. this.$vm,
  1427. event,
  1428. eventArray[1],
  1429. eventArray[2],
  1430. isCustom,
  1431. methodName
  1432. ));
  1433. return
  1434. }
  1435. const handler = handlerCtx[methodName];
  1436. if (!isFn(handler)) {
  1437. throw new Error(` _vm.${methodName} is not a function`)
  1438. }
  1439. if (isOnce) {
  1440. if (handler.once) {
  1441. return
  1442. }
  1443. handler.once = true;
  1444. }
  1445. ret.push(handler.apply(handlerCtx, processEventArgs(
  1446. this.$vm,
  1447. event,
  1448. eventArray[1],
  1449. eventArray[2],
  1450. isCustom,
  1451. methodName
  1452. )));
  1453. }
  1454. });
  1455. }
  1456. });
  1457. if (
  1458. eventType === 'input' &&
  1459. ret.length === 1 &&
  1460. typeof ret[0] !== 'undefined'
  1461. ) {
  1462. return ret[0]
  1463. }
  1464. }
  1465. const hooks = [
  1466. 'onShow',
  1467. 'onHide',
  1468. 'onError',
  1469. 'onPageNotFound'
  1470. ];
  1471. function parseBaseApp (vm, {
  1472. mocks,
  1473. initRefs
  1474. }) {
  1475. if (vm.$options.store) {
  1476. Vue.prototype.$store = vm.$options.store;
  1477. }
  1478. Vue.prototype.mpHost = "mp-alipay";
  1479. Vue.mixin({
  1480. beforeCreate () {
  1481. if (!this.$options.mpType) {
  1482. return
  1483. }
  1484. this.mpType = this.$options.mpType;
  1485. this.$mp = {
  1486. data: {},
  1487. [this.mpType]: this.$options.mpInstance
  1488. };
  1489. this.$scope = this.$options.mpInstance;
  1490. delete this.$options.mpType;
  1491. delete this.$options.mpInstance;
  1492. if (this.mpType !== 'app') {
  1493. initRefs(this);
  1494. initMocks(this, mocks);
  1495. }
  1496. }
  1497. });
  1498. const appOptions = {
  1499. onLaunch (args) {
  1500. if (this.$vm) { // 已经初始化过了,主要是为了百度,百度 onShow 在 onLaunch 之前
  1501. return
  1502. }
  1503. this.$vm = vm;
  1504. this.$vm.$mp = {
  1505. app: this
  1506. };
  1507. this.$vm.$scope = this;
  1508. // vm 上也挂载 globalData
  1509. this.$vm.globalData = this.globalData;
  1510. this.$vm._isMounted = true;
  1511. this.$vm.__call_hook('mounted', args);
  1512. this.$vm.__call_hook('onLaunch', args);
  1513. }
  1514. };
  1515. // 兼容旧版本 globalData
  1516. appOptions.globalData = vm.$options.globalData || {};
  1517. // 将 methods 中的方法挂在 getApp() 中
  1518. const methods = vm.$options.methods;
  1519. if (methods) {
  1520. Object.keys(methods).forEach(name => {
  1521. appOptions[name] = methods[name];
  1522. });
  1523. }
  1524. initHooks(appOptions, hooks);
  1525. return appOptions
  1526. }
  1527. function findVmByVueId (vm, vuePid) {
  1528. const $children = vm.$children;
  1529. // 优先查找直属(反向查找:https://github.com/dcloudio/uni-app/issues/1200)
  1530. for (let i = $children.length - 1; i >= 0; i--) {
  1531. const childVm = $children[i];
  1532. if (childVm.$scope._$vueId === vuePid) {
  1533. return childVm
  1534. }
  1535. }
  1536. // 反向递归查找
  1537. let parentVm;
  1538. for (let i = $children.length - 1; i >= 0; i--) {
  1539. parentVm = findVmByVueId($children[i], vuePid);
  1540. if (parentVm) {
  1541. return parentVm
  1542. }
  1543. }
  1544. }
  1545. function handleLink (event) {
  1546. const {
  1547. vuePid,
  1548. vueOptions
  1549. } = event.detail || event.value; // detail 是微信,value 是百度(dipatch)
  1550. let parentVm;
  1551. if (vuePid) {
  1552. parentVm = findVmByVueId(this.$vm, vuePid);
  1553. }
  1554. if (!parentVm) {
  1555. parentVm = this.$vm;
  1556. }
  1557. vueOptions.parent = parentVm;
  1558. }
  1559. const isArray = Array.isArray;
  1560. const keyList = Object.keys;
  1561. function equal (a, b) {
  1562. if (a === b) return true
  1563. if (a && b && typeof a === 'object' && typeof b === 'object') {
  1564. const arrA = isArray(a);
  1565. const arrB = isArray(b);
  1566. let i, length, key;
  1567. if (arrA && arrB) {
  1568. length = a.length;
  1569. if (length !== b.length) return false
  1570. for (i = length; i-- !== 0;) {
  1571. if (!equal(a[i], b[i])) return false
  1572. }
  1573. return true
  1574. }
  1575. if (arrA !== arrB) return false
  1576. const dateA = a instanceof Date;
  1577. const dateB = b instanceof Date;
  1578. if (dateA !== dateB) return false
  1579. if (dateA && dateB) return a.getTime() === b.getTime()
  1580. const regexpA = a instanceof RegExp;
  1581. const regexpB = b instanceof RegExp;
  1582. if (regexpA !== regexpB) return false
  1583. if (regexpA && regexpB) return a.toString() === b.toString()
  1584. const keys = keyList(a);
  1585. length = keys.length;
  1586. if (length !== keyList(b).length) {
  1587. return false
  1588. }
  1589. for (i = length; i-- !== 0;) {
  1590. if (!hasOwn.call(b, keys[i])) return false
  1591. }
  1592. for (i = length; i-- !== 0;) {
  1593. key = keys[i];
  1594. if (!equal(a[key], b[key])) return false
  1595. }
  1596. return true
  1597. }
  1598. return false
  1599. }
  1600. const customizeRE = /:/g;
  1601. const customize = cached((str) => {
  1602. return camelize(str.replace(customizeRE, '-'))
  1603. });
  1604. const isComponent2 = my.canIUse('component2');
  1605. const mocks = ['$id'];
  1606. function initRefs () {
  1607. }
  1608. function initBehavior ({
  1609. properties
  1610. }) {
  1611. const props = {};
  1612. Object.keys(properties).forEach(key => {
  1613. props[key] = properties[key].value;
  1614. });
  1615. return {
  1616. props
  1617. }
  1618. }
  1619. function initRelation (detail) {
  1620. this.props.onVueInit(detail);
  1621. }
  1622. function initSpecialMethods (mpInstance) {
  1623. if (!mpInstance.$vm) {
  1624. return
  1625. }
  1626. let path = mpInstance.is || mpInstance.route;
  1627. if (!path) {
  1628. return
  1629. }
  1630. if (path.indexOf('/') === 0) {
  1631. path = path.substr(1);
  1632. }
  1633. const specialMethods = my.specialMethods && my.specialMethods[path];
  1634. if (specialMethods) {
  1635. specialMethods.forEach(method => {
  1636. if (isFn(mpInstance.$vm[method])) {
  1637. mpInstance[method] = function (event) {
  1638. if (hasOwn(event, 'markerId')) {
  1639. event.detail = typeof event.detail === 'object' ? event.detail : {};
  1640. event.detail.markerId = event.markerId;
  1641. }
  1642. // TODO normalizeEvent
  1643. mpInstance.$vm[method](event);
  1644. };
  1645. }
  1646. });
  1647. }
  1648. }
  1649. function initChildVues (mpInstance) {
  1650. // 此时需保证当前 mpInstance 已经存在 $vm
  1651. if (!mpInstance.$vm) {
  1652. return
  1653. }
  1654. mpInstance._$childVues && mpInstance._$childVues.forEach(({
  1655. vuePid,
  1656. vueOptions,
  1657. VueComponent,
  1658. mpInstance: childMPInstance
  1659. }) => {
  1660. // 父子关系
  1661. handleLink.call(mpInstance, {
  1662. detail: {
  1663. vuePid,
  1664. vueOptions
  1665. }
  1666. });
  1667. childMPInstance.$vm = new VueComponent(vueOptions);
  1668. initSpecialMethods(childMPInstance);
  1669. handleRef.call(vueOptions.parent.$scope, childMPInstance);
  1670. childMPInstance.$vm.$mount();
  1671. initChildVues(childMPInstance);
  1672. childMPInstance.$vm._isMounted = true;
  1673. childMPInstance.$vm.__call_hook('mounted');
  1674. childMPInstance.$vm.__call_hook('onReady');
  1675. });
  1676. delete mpInstance._$childVues;
  1677. }
  1678. function handleRef (ref) {
  1679. if (!ref) {
  1680. return
  1681. }
  1682. const refName = ref.props['data-ref'];
  1683. const refInForName = ref.props['data-ref-in-for'];
  1684. if (refName) {
  1685. this.$vm.$refs[refName] = ref.$vm || ref;
  1686. } else if (refInForName) {
  1687. (this.$vm.$refs[refInForName] || (this.$vm.$refs[refInForName] = [])).push(ref.$vm || ref);
  1688. }
  1689. }
  1690. function triggerEvent (type, detail, options) {
  1691. const handler = this.props[customize('on-' + type)];
  1692. if (!handler) {
  1693. return
  1694. }
  1695. const eventOpts = this.props['data-event-opts'];
  1696. const target = {
  1697. dataset: {
  1698. eventOpts
  1699. }
  1700. };
  1701. handler({
  1702. type: customize(type),
  1703. target,
  1704. currentTarget: target,
  1705. detail
  1706. });
  1707. }
  1708. const IGNORES = ['$slots', '$scopedSlots'];
  1709. function createObserver$1 (isDidUpdate) {
  1710. return function observe (props) {
  1711. const prevProps = isDidUpdate ? props : this.props;
  1712. const nextProps = isDidUpdate ? this.props : props;
  1713. if (equal(prevProps, nextProps)) {
  1714. return
  1715. }
  1716. Object.keys(prevProps).forEach(name => {
  1717. if (IGNORES.indexOf(name) === -1) {
  1718. const prevValue = prevProps[name];
  1719. const nextValue = nextProps[name];
  1720. if (!isFn(prevValue) && !isFn(nextValue) && !equal(prevValue, nextValue)) {
  1721. this.$vm[name] = nextProps[name];
  1722. }
  1723. }
  1724. });
  1725. }
  1726. }
  1727. const handleLink$1 = (function () {
  1728. if (isComponent2) {
  1729. return function handleLink$1 (detail) {
  1730. return handleLink.call(this, {
  1731. detail
  1732. })
  1733. }
  1734. }
  1735. return function handleLink$1 (detail) {
  1736. if (this.$vm && this.$vm._isMounted) { // 父已初始化
  1737. return handleLink.call(this, {
  1738. detail: {
  1739. vuePid: detail.vuePid,
  1740. vueOptions: detail.vueOptions
  1741. }
  1742. })
  1743. }
  1744. // 支付宝通过 didMount 来实现,先子后父,故等父 ready 之后,统一初始化
  1745. (this._$childVues || (this._$childVues = [])).unshift(detail);
  1746. }
  1747. })();
  1748. function parseApp (vm) {
  1749. Object.defineProperty(Vue.prototype, '$slots', {
  1750. get () {
  1751. return this.$scope && this.$scope.props.$slots
  1752. },
  1753. set () {
  1754. }
  1755. });
  1756. Object.defineProperty(Vue.prototype, '$scopedSlots', {
  1757. get () {
  1758. return this.$scope && this.$scope.props.$scopedSlots
  1759. },
  1760. set () {
  1761. }
  1762. });
  1763. Vue.prototype.$onAliGetAuthorize = function onAliGetAuthorize (method, $event) {
  1764. my.getPhoneNumber({
  1765. success: (res) => {
  1766. $event.type = 'getphonenumber';
  1767. const response = JSON.parse(res.response).response;
  1768. if (response.code === '10000') { // success
  1769. $event.detail.errMsg = 'getPhoneNumber:ok';
  1770. $event.detail.encryptedData = res.response;
  1771. } else {
  1772. $event.detail.errMsg = 'getPhoneNumber:fail Error: ' + res.response;
  1773. }
  1774. this[method]($event);
  1775. },
  1776. fail: (res) => {
  1777. $event.type = 'getphonenumber';
  1778. $event.detail.errMsg = 'getPhoneNumber:fail';
  1779. this[method]($event);
  1780. }
  1781. });
  1782. };
  1783. Vue.prototype.$onAliAuthError = function $onAliAuthError (method, $event) {
  1784. $event.type = 'getphonenumber';
  1785. $event.detail.errMsg = 'getPhoneNumber:fail Error: ' + $event.detail.errorMessage;
  1786. this[method]($event);
  1787. };
  1788. return parseBaseApp(vm, {
  1789. mocks,
  1790. initRefs
  1791. })
  1792. }
  1793. function createApp (vm) {
  1794. App(parseApp(vm));
  1795. return vm
  1796. }
  1797. const hooks$1 = [
  1798. 'onShow',
  1799. 'onHide',
  1800. // mp-alipay 特有
  1801. 'onTitleClick',
  1802. 'onOptionMenuClick',
  1803. 'onPopMenuClick',
  1804. 'onPullIntercept'
  1805. ];
  1806. hooks$1.push(...PAGE_EVENT_HOOKS);
  1807. function parsePage (vuePageOptions) {
  1808. const [VueComponent, vueOptions] = initVueComponent(Vue, vuePageOptions);
  1809. const pageOptions = {
  1810. mixins: initBehaviors(vueOptions, initBehavior),
  1811. data: initData(vueOptions, Vue.prototype),
  1812. onLoad (args) {
  1813. const properties = this.props;
  1814. const options = {
  1815. mpType: 'page',
  1816. mpInstance: this,
  1817. propsData: properties
  1818. };
  1819. // 初始化 vue 实例
  1820. this.$vm = new VueComponent(options);
  1821. initSpecialMethods(this);
  1822. // 触发首次 setData
  1823. this.$vm.$mount();
  1824. this.$vm.$mp.query = args; // 兼容 mpvue
  1825. this.$vm.__call_hook('onLoad', args);
  1826. },
  1827. onReady () {
  1828. initChildVues(this);
  1829. this.$vm._isMounted = true;
  1830. this.$vm.__call_hook('mounted');
  1831. this.$vm.__call_hook('onReady');
  1832. },
  1833. onUnload () {
  1834. this.$vm.__call_hook('onUnload');
  1835. this.$vm.$destroy();
  1836. },
  1837. events: {
  1838. // 支付宝小程序有些页面事件只能放在events下
  1839. onBack () {
  1840. this.$vm.__call_hook('onBackPress');
  1841. }
  1842. },
  1843. __r: handleRef,
  1844. __e: handleEvent,
  1845. __l: handleLink$1
  1846. };
  1847. initHooks(pageOptions, hooks$1, vuePageOptions);
  1848. return pageOptions
  1849. }
  1850. function createPage (vuePageOptions) {
  1851. {
  1852. return Page(parsePage(vuePageOptions))
  1853. }
  1854. }
  1855. function initVm (VueComponent) {
  1856. if (this.$vm) {
  1857. return
  1858. }
  1859. const properties = this.props;
  1860. const options = {
  1861. mpType: 'component',
  1862. mpInstance: this,
  1863. propsData: properties
  1864. };
  1865. initVueIds(properties.vueId, this);
  1866. if (isComponent2) {
  1867. // 处理父子关系
  1868. initRelation.call(this, {
  1869. vuePid: this._$vuePid,
  1870. vueOptions: options
  1871. });
  1872. // 初始化 vue 实例
  1873. this.$vm = new VueComponent(options);
  1874. // 触发首次 setData
  1875. this.$vm.$mount();
  1876. } else {
  1877. // 处理父子关系
  1878. initRelation.call(this, {
  1879. vuePid: this._$vuePid,
  1880. vueOptions: options,
  1881. VueComponent,
  1882. mpInstance: this
  1883. });
  1884. if (options.parent) { // 父组件已经初始化,直接初始化子,否则放到父组件的 didMount 中处理
  1885. // 初始化 vue 实例
  1886. this.$vm = new VueComponent(options);
  1887. handleRef.call(options.parent.$scope, this);
  1888. // 触发首次 setData
  1889. this.$vm.$mount();
  1890. initChildVues(this);
  1891. this.$vm._isMounted = true;
  1892. this.$vm.__call_hook('mounted');
  1893. this.$vm.__call_hook('onReady');
  1894. }
  1895. }
  1896. }
  1897. function parseComponent (vueComponentOptions) {
  1898. const [VueComponent, vueOptions] = initVueComponent(Vue, vueComponentOptions);
  1899. const properties = initProperties(vueOptions.props, false, vueOptions.__file);
  1900. const props = {
  1901. onVueInit: function () {}
  1902. };
  1903. Object.keys(properties).forEach(key => {
  1904. if (key !== 'vueSlots') {
  1905. props[key] = properties[key].value;
  1906. }
  1907. });
  1908. const componentOptions = {
  1909. mixins: initBehaviors(vueOptions, initBehavior),
  1910. data: initData(vueOptions, Vue.prototype),
  1911. props,
  1912. didMount () {
  1913. if (my.dd) { // 钉钉小程序底层基础库有 bug,组件嵌套使用时,在 didMount 中无法及时调用 props 中的方法
  1914. setTimeout(() => {
  1915. initVm.call(this, VueComponent);
  1916. }, 4);
  1917. } else {
  1918. initVm.call(this, VueComponent);
  1919. }
  1920. initSpecialMethods(this);
  1921. if (isComponent2) {
  1922. this.$vm._isMounted = true;
  1923. this.$vm.__call_hook('mounted');
  1924. this.$vm.__call_hook('onReady');
  1925. }
  1926. },
  1927. didUnmount () {
  1928. this.$vm && this.$vm.$destroy();
  1929. },
  1930. methods: {
  1931. __r: handleRef,
  1932. __e: handleEvent,
  1933. __l: handleLink$1,
  1934. triggerEvent
  1935. }
  1936. };
  1937. if (isComponent2) {
  1938. componentOptions.onInit = function onInit () {
  1939. initVm.call(this, VueComponent);
  1940. };
  1941. componentOptions.deriveDataFromProps = createObserver$1();
  1942. } else {
  1943. componentOptions.didUpdate = createObserver$1(true);
  1944. }
  1945. return componentOptions
  1946. }
  1947. function createComponent (vueOptions) {
  1948. {
  1949. return my.defineComponent(parseComponent(vueOptions))
  1950. }
  1951. }
  1952. todos.forEach(todoApi => {
  1953. protocols[todoApi] = false;
  1954. });
  1955. canIUses.forEach(canIUseApi => {
  1956. const apiName = protocols[canIUseApi] && protocols[canIUseApi].name ? protocols[canIUseApi].name
  1957. : canIUseApi;
  1958. if (!my.canIUse(apiName)) {
  1959. protocols[canIUseApi] = false;
  1960. }
  1961. });
  1962. let uni = {};
  1963. if (typeof Proxy !== 'undefined' && "mp-alipay" !== 'app-plus') {
  1964. uni = new Proxy({}, {
  1965. get (target, name) {
  1966. if (target[name]) {
  1967. return target[name]
  1968. }
  1969. if (baseApi[name]) {
  1970. return baseApi[name]
  1971. }
  1972. if (api[name]) {
  1973. return promisify(name, api[name])
  1974. }
  1975. {
  1976. if (extraApi[name]) {
  1977. return promisify(name, extraApi[name])
  1978. }
  1979. if (todoApis[name]) {
  1980. return promisify(name, todoApis[name])
  1981. }
  1982. }
  1983. if (eventApi[name]) {
  1984. return eventApi[name]
  1985. }
  1986. if (!hasOwn(my, name) && !hasOwn(protocols, name)) {
  1987. return
  1988. }
  1989. return promisify(name, wrapper(name, my[name]))
  1990. },
  1991. set (target, name, value) {
  1992. target[name] = value;
  1993. return true
  1994. }
  1995. });
  1996. } else {
  1997. Object.keys(baseApi).forEach(name => {
  1998. uni[name] = baseApi[name];
  1999. });
  2000. {
  2001. Object.keys(todoApis).forEach(name => {
  2002. uni[name] = promisify(name, todoApis[name]);
  2003. });
  2004. Object.keys(extraApi).forEach(name => {
  2005. uni[name] = promisify(name, todoApis[name]);
  2006. });
  2007. }
  2008. Object.keys(eventApi).forEach(name => {
  2009. uni[name] = eventApi[name];
  2010. });
  2011. Object.keys(api).forEach(name => {
  2012. uni[name] = promisify(name, api[name]);
  2013. });
  2014. Object.keys(my).forEach(name => {
  2015. if (hasOwn(my, name) || hasOwn(protocols, name)) {
  2016. uni[name] = promisify(name, wrapper(name, my[name]));
  2017. }
  2018. });
  2019. }
  2020. my.createApp = createApp;
  2021. my.createPage = createPage;
  2022. my.createComponent = createComponent;
  2023. var uni$1 = uni;
  2024. export default uni$1;
  2025. export { createApp, createComponent, createPage };