my.js 56 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837
  1. "use strict";
  2. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  3. function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
  4. function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
  5. function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
  6. var utils = require("./utils");
  7. var propsPolyfill = require("./propsPolyfill");
  8. var descObj = require("./desc.js");
  9. var apiObj = {
  10. startBeaconDiscovery: {
  11. fn: function fn() {
  12. var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  13. var startBeaconDiscoveryParams = descObj.startBeaconDiscovery.body.params.props;
  14. var params = utils.defineGetter(obj, startBeaconDiscoveryParams, function (_obj, prop) {
  15. utils.warn("startBeaconDiscovery\u7684\u53C2\u6570\u4E0D\u652F\u6301 ".concat(prop, " \u5C5E\u6027!"), {
  16. apiName: "startBeaconDiscovery/".concat(prop),
  17. errorType: startBeaconDiscoveryParams[prop].type,
  18. type: 'api'
  19. });
  20. });
  21. return my.startBeaconDiscovery(params);
  22. }
  23. },
  24. stopBeaconDiscovery: {
  25. fn: function fn() {
  26. var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  27. my.stopBeaconDiscovery(obj);
  28. }
  29. },
  30. onBeaconUpdate: {
  31. fn: function fn(cb) {
  32. return my.onBeaconUpdate({
  33. success: cb,
  34. fail: cb
  35. });
  36. }
  37. },
  38. onBeaconServiceChange: {
  39. fn: function fn(cb) {
  40. return my.onBeaconServiceChange({
  41. success: cb,
  42. fail: cb,
  43. complete: cb
  44. });
  45. }
  46. },
  47. getBeacons: {
  48. fn: function fn() {
  49. var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  50. return my.getBeacons(obj);
  51. }
  52. },
  53. writeBLECharacteristicValue: {
  54. fn: function fn() {
  55. var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  56. if (obj.value) {
  57. obj.value = utils.ab2hex(obj.value);
  58. }
  59. my.writeBLECharacteristicValue(obj);
  60. }
  61. },
  62. createBLEConnection: {
  63. fn: function fn() {
  64. var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  65. return my.connectBLEDevice(obj);
  66. }
  67. },
  68. closeBLEConnection: {
  69. fn: function fn() {
  70. var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  71. return my.disconnectBLEDevice(obj);
  72. }
  73. },
  74. onBLEConnectionStateChange: {
  75. fn: function fn() {
  76. var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  77. return my.onBLEConnectionStateChanged(obj);
  78. }
  79. },
  80. onBLECharacteristicValueChange: {
  81. fn: function fn(cb) {
  82. my.onBLECharacteristicValueChange(function (res) {
  83. res.value = utils.changeType(res.value);
  84. cb && cb(res);
  85. });
  86. }
  87. },
  88. getBLEDeviceServices: {
  89. fn: function fn() {
  90. var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  91. my.getBLEDeviceServices(_objectSpread(_objectSpread({}, obj), {}, {
  92. success: function success(res) {
  93. if (res.services) {
  94. res.services.forEach(function (item) {
  95. item.uuid = item.serviceId;
  96. delete item.serviceId;
  97. });
  98. }
  99. obj.success && obj.success(res);
  100. }
  101. }));
  102. }
  103. },
  104. getBLEDeviceCharacteristics: {
  105. fn: function fn() {
  106. var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  107. my.getBLEDeviceCharacteristics(_objectSpread(_objectSpread({}, obj), {}, {
  108. success: function success(res) {
  109. if (res.characteristics) {
  110. res.characteristics.forEach(function (item) {
  111. item.uuid = item.characteristicId;
  112. delete item.characteristicId;
  113. });
  114. }
  115. obj.success && obj.success(res);
  116. }
  117. }));
  118. }
  119. },
  120. addPhoneContact: {
  121. fn: function fn() {
  122. var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  123. if (obj.weChatNumber) {
  124. obj.alipayAccount = obj.weChatNumber;
  125. }
  126. my.addPhoneContact(obj);
  127. }
  128. },
  129. startBluetoothDevicesDiscovery: {
  130. fn: function fn() {
  131. var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  132. if (obj.interval) {
  133. obj.interval = Math.round(obj.interval);
  134. }
  135. my.startBluetoothDevicesDiscovery(obj);
  136. }
  137. },
  138. onBluetoothDeviceFound: {
  139. fn: function fn(cb) {
  140. var onBluetoothDeviceFoundProps = descObj.onBluetoothDeviceFound.body.returnValue.props;
  141. my.onBluetoothDeviceFound(function (res) {
  142. var arr = res.devices.map(function (item) {
  143. item.advertisData = utils.changeType(item.advertisData);
  144. return utils.defineGetter(item, onBluetoothDeviceFoundProps, function (obj, prop) {
  145. utils.warn("onBluetoothDeviceFound\u7684\u8FD4\u56DE\u503C\u4E0D\u652F\u6301 ".concat(prop, " \u5C5E\u6027!"), {
  146. apiName: "onBluetoothDeviceFound/".concat(prop),
  147. errorType: onBluetoothDeviceFoundProps[prop].type,
  148. type: 'api'
  149. });
  150. });
  151. });
  152. res.devices = arr;
  153. cb && cb(res);
  154. });
  155. }
  156. },
  157. getBluetoothDevices: {
  158. fn: function fn() {
  159. var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  160. var getBluetoothDevicesProps = descObj.getBluetoothDevices.body.returnValue.props.devices.props;
  161. my.getBluetoothDevices(_objectSpread(_objectSpread({}, obj), {}, {
  162. success: function success(res) {
  163. var arr = res.devices.map(function (item) {
  164. item.advertisData = utils.changeType(item.advertisData);
  165. return utils.defineGetter(item, getBluetoothDevicesProps, function (_obj, prop) {
  166. utils.warn("getBluetoothDevices\u7684\u8FD4\u56DE\u503C\u4E0D\u652F\u6301 ".concat(prop, " \u5C5E\u6027!"), {
  167. apiName: "getBluetoothDevices/".concat(prop),
  168. errorType: getBluetoothDevicesProps[prop].type,
  169. type: 'api'
  170. });
  171. });
  172. });
  173. res.devices = arr;
  174. obj.success && obj.success(res);
  175. }
  176. }));
  177. }
  178. },
  179. setClipboardData: {
  180. fn: function fn() {
  181. var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  182. if (obj.data) {
  183. obj.text = obj.data;
  184. delete obj.data;
  185. }
  186. my.setClipboard(obj);
  187. }
  188. },
  189. getClipboardData: {
  190. fn: function fn() {
  191. var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  192. my.getClipboard(_objectSpread(_objectSpread({}, obj), {}, {
  193. success: function success(res) {
  194. res.data = res.text;
  195. delete res.text;
  196. obj.success && obj.success(res);
  197. }
  198. }));
  199. }
  200. },
  201. onNetworkStatusChange: {
  202. fn: function fn(cb) {
  203. my.onNetworkStatusChange(function (res) {
  204. res.networkType = res.networkType.toLowerCase();
  205. var typeObjMap = {
  206. unknown: 'unknown',
  207. wifi: 'wifi',
  208. '2g': '2g',
  209. '3g': '3g',
  210. '4g': '4g'
  211. };
  212. if (res && !res.isConnected) {
  213. res.networkType = 'none';
  214. } else {
  215. res.networkType = typeObjMap[res.networkType] || res.networkType;
  216. }
  217. cb && cb(res);
  218. });
  219. }
  220. },
  221. setScreenBrightness: {
  222. fn: function fn() {
  223. var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  224. if (obj.value) {
  225. obj.brightness = obj.value;
  226. delete obj.value;
  227. }
  228. my.setScreenBrightness(obj);
  229. }
  230. },
  231. getScreenBrightness: {
  232. fn: function fn() {
  233. var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  234. my.getScreenBrightness({
  235. success: function success(res) {
  236. res.value = res.brightness;
  237. delete res.brightness;
  238. obj.success && obj.success(res);
  239. },
  240. fail: function fail(res) {
  241. obj.fail && obj.fail(res);
  242. }
  243. });
  244. }
  245. },
  246. scanCode: {
  247. fn: function fn() {
  248. var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  249. obj.hideAlbum = obj.onlyFromCamera || false;
  250. my.scan(obj);
  251. }
  252. },
  253. stopGyroscope: {
  254. fn: function fn() {
  255. var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  256. var stopGyroscopeParams = descObj.stopGyroscope.body.params.props;
  257. var params = utils.defineGetter(obj, stopGyroscopeParams, function (_obj, prop) {
  258. utils.warn("stopGyroscope\u7684\u53C2\u6570\u4E0D\u652F\u6301 ".concat(prop, " \u5C5E\u6027!"), {
  259. apiName: "stopGyroscope".concat(prop),
  260. errorType: stopGyroscopeParams[prop].type,
  261. type: 'api'
  262. });
  263. });
  264. return my.offGyroscopeChange(params);
  265. }
  266. },
  267. onCompassChange: {
  268. fn: function fn(cb) {
  269. var onCompassChangeReturnValue = descObj.onCompassChange.body.returnValue.props;
  270. my.onCompassChange(function (res) {
  271. var _res = utils.defineGetter(res, onCompassChangeReturnValue, function (obj, prop) {
  272. utils.warn("onCompassChange\u7684\u8FD4\u56DE\u503C\u4E0D\u652F\u6301 ".concat(prop, " \u5C5E\u6027!"), {
  273. apiName: "onCompassChange/".concat(prop),
  274. errorType: onCompassChangeReturnValue[prop].type,
  275. type: 'api'
  276. });
  277. });
  278. cb && cb(_res);
  279. });
  280. }
  281. },
  282. stopCompass: {
  283. fn: function fn() {
  284. var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  285. var stopCompassParams = descObj.stopCompass.body.params.props;
  286. var params = utils.defineGetter(obj, stopCompassParams, function (_obj, prop) {
  287. utils.warn("stopCompass\u7684\u53C2\u6570\u4E0D\u652F\u6301 ".concat(prop, " \u5C5E\u6027!"), {
  288. apiName: "stopCompass/".concat(prop),
  289. errorType: stopCompassParams[prop].type,
  290. type: 'api'
  291. });
  292. });
  293. return my.offCompassChange(params);
  294. }
  295. },
  296. stopAccelerometer: {
  297. fn: function fn() {
  298. var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  299. var stopAccelerometerParams = descObj.stopAccelerometer.body.params.props;
  300. var params = utils.defineGetter(obj, stopAccelerometerParams, function (_obj, prop) {
  301. utils.warn("stopAccelerometer\u7684\u53C2\u6570\u4E0D\u652F\u6301 ".concat(prop, " \u5C5E\u6027!"), {
  302. apiName: "stopCompass/".concat(prop),
  303. errorType: stopAccelerometerParams[prop].type,
  304. type: 'api'
  305. });
  306. });
  307. return my.offAccelerometerChange(params);
  308. }
  309. },
  310. makePhoneCall: {
  311. fn: function fn() {
  312. var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  313. var makePhoneCallParams = descObj.makePhoneCall.body.params.props;
  314. if (obj.phoneNumber) {
  315. obj.number = obj.phoneNumber;
  316. delete obj.phoneNumber;
  317. }
  318. var params = utils.defineGetter(obj, makePhoneCallParams, function (_obj, prop) {
  319. utils.warn("makePhoneCall\u7684\u53C2\u6570\u4E0D\u652F\u6301 ".concat(prop, " \u5C5E\u6027!"), {
  320. apiName: "makePhoneCall/".concat(prop),
  321. errorType: makePhoneCallParams[prop].type,
  322. type: 'api'
  323. });
  324. });
  325. return my.makePhoneCall(params);
  326. }
  327. },
  328. canIUse: {
  329. fn: function fn(params) {
  330. var paramsList = params.split('.');
  331. if (paramsList[1] && paramsList[1] === 'success') {
  332. paramsList[1] = 'return';
  333. }
  334. var str = paramsList.join('.');
  335. return my.canIUse(str);
  336. }
  337. },
  338. getSystemInfoSync: {
  339. fn: function fn() {
  340. var ret = my.getSystemInfoSync();
  341. var getSystemInfoSyncProps = descObj.getSystemInfoSync.body.returnValue.props;
  342. ret = utils.defineGetter(ret, getSystemInfoSyncProps, function (obj, prop) {
  343. utils.warn("getSystemInfoSync\u7684\u8FD4\u56DE\u503C\u4E0D\u652F\u6301 ".concat(prop, " \u5C5E\u6027!"), {
  344. apiName: "getSystemInfoSync/".concat(prop),
  345. errorType: getSystemInfoSyncProps[prop].type,
  346. type: 'api'
  347. });
  348. });
  349. /**
  350. * 处理Android屏幕宽度返回值
  351. */
  352. if (ret.platform.toLowerCase() === 'android') {
  353. ret.platform = 'android';
  354. ret.screenWidth /= ret.pixelRatio;
  355. ret.screenHeight /= ret.pixelRatio;
  356. } else if (ret.platform.toLowerCase() === 'ios') {
  357. ret.platform = 'ios'; // mock的安全区位置信息(模拟器iphonex screenHeight:812)
  358. if (ret.screenHeight >= propsPolyfill.screenHeight) {
  359. ret.safeArea = propsPolyfill.safeArea;
  360. ret.safeArea.bottom = ret.screenHeight - propsPolyfill.safeHeight;
  361. } else {
  362. ret.safeArea = {
  363. bottom: ret.screenHeight,
  364. height: ret.screenHeight,
  365. left: 0,
  366. right: ret.screenWidth,
  367. top: ret.statusBarHeight,
  368. width: ret.screenWidth
  369. };
  370. }
  371. } // mock的版本,确保微信小程序源码里读取后和目标版本匹配都能通过
  372. ret.SDKVersion = '10.0.0';
  373. return ret;
  374. }
  375. },
  376. getSystemInfo: {
  377. fn: function fn() {
  378. var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  379. var getSystemInfoProps = descObj.getSystemInfo.body.returnValue.props;
  380. my.getSystemInfo(_objectSpread(_objectSpread({}, obj), {}, {
  381. success: function success(res) {
  382. res = utils.defineGetter(res, getSystemInfoProps, function (_obj, prop) {
  383. utils.warn("getSystemInfo\u7684\u8FD4\u56DE\u503C\u4E0D\u652F\u6301 ".concat(prop, " \u5C5E\u6027!"), {
  384. apiName: "getSystemInfo/".concat(prop),
  385. errorType: getSystemInfoProps[prop].type,
  386. type: 'api'
  387. });
  388. });
  389. /**
  390. * 处理Android屏幕宽度返回值
  391. */
  392. if (res.platform.toLowerCase() === 'android') {
  393. res.platform = 'android';
  394. res.screenWidth /= res.pixelRatio;
  395. res.screenHeight /= res.pixelRatio;
  396. } else if (res.platform.toLowerCase() === 'ios') {
  397. res.platform = 'ios';
  398. if (res.screenHeight >= propsPolyfill.screenHeight) {
  399. res.safeArea = propsPolyfill.safeArea;
  400. res.safeArea.bottom = res.screenHeight - propsPolyfill.safeHeight;
  401. } else {
  402. res.safeArea = {
  403. bottom: res.screenHeight,
  404. height: res.screenHeight,
  405. left: 0,
  406. right: res.screenWidth,
  407. top: res.statusBarHeight,
  408. width: res.screenWidth
  409. };
  410. }
  411. } // mock的版本,确保微信小程序源码里读取后和目标版本匹配都能通过
  412. res.SDKVersion = '10.0.0';
  413. obj.success && obj.success(res);
  414. }
  415. }));
  416. }
  417. },
  418. showToast: {
  419. fn: function fn() {
  420. var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  421. var showToastProps = descObj.showToast.body.params.props;
  422. if (obj.title) {
  423. obj.content = obj.title;
  424. delete obj.title;
  425. }
  426. if (!obj.duration) {
  427. obj.duration = 2000;
  428. }
  429. if (obj.icon) {
  430. if (obj.icon === 'success') {
  431. obj.type = 'success';
  432. } else if (obj.icon === 'loading') {
  433. obj.type = 'none';
  434. utils.warn('showToast暂不支持loading', {
  435. apiName: 'showToast/loading',
  436. errorType: 0,
  437. type: 'api'
  438. });
  439. } else {
  440. obj.type = 'none';
  441. }
  442. delete obj.icon;
  443. } else {
  444. obj.type = 'success';
  445. }
  446. var params = utils.defineGetter(obj, showToastProps, function (_obj, prop) {
  447. utils.warn("showToast\u7684\u53C2\u6570\u4E0D\u652F\u6301 ".concat(prop, " \u5C5E\u6027!"), {
  448. apiName: "showToast/".concat(prop),
  449. errorType: showToastProps[prop].type,
  450. type: 'api'
  451. });
  452. });
  453. my.showToast(params);
  454. }
  455. },
  456. showModal: {
  457. fn: function fn() {
  458. var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  459. var showModalProps = descObj.showModal.body.params.props;
  460. if (obj.cancelText !== undefined) {
  461. obj.cancelButtonText = obj.cancelText;
  462. delete obj.cancelText;
  463. }
  464. if (obj.confirmText !== undefined) {
  465. obj.confirmButtonText = obj.confirmText;
  466. delete obj.confirmText;
  467. }
  468. var params = utils.defineGetter(obj, showModalProps, function (_obj, prop) {
  469. utils.warn("showModal\u7684\u53C2\u6570\u4E0D\u652F\u6301 ".concat(prop, " \u5C5E\u6027!"), {
  470. apiName: "showModal/".concat(prop),
  471. errorType: showModalProps[prop].type,
  472. type: 'api'
  473. });
  474. });
  475. my.confirm(_objectSpread(_objectSpread({}, params), {}, {
  476. success: function success(res) {
  477. if (res.confirm) {
  478. res.cancel = false;
  479. } else {
  480. res.cancel = true;
  481. }
  482. obj.success && obj.success(res);
  483. }
  484. }));
  485. }
  486. },
  487. showLoading: {
  488. fn: function fn() {
  489. var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  490. var showLoadingProps = descObj.showLoading.body.params.props;
  491. if (obj.title) {
  492. obj.content = obj.title;
  493. delete obj.title;
  494. }
  495. var params = utils.defineGetter(obj, showLoadingProps, function (_obj, prop) {
  496. utils.warn("showLoading\u7684\u53C2\u6570\u4E0D\u652F\u6301 ".concat(prop, " \u5C5E\u6027!"), {
  497. apiName: "showLoading/".concat(prop),
  498. errorType: showLoadingProps[prop].type,
  499. type: 'api'
  500. });
  501. });
  502. my.showLoading(params);
  503. }
  504. },
  505. showActionSheet: {
  506. fn: function fn() {
  507. var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  508. var showActionSheetProps = descObj.showActionSheet.body.params.props;
  509. if (obj.itemList) {
  510. obj.items = obj.itemList;
  511. delete obj.itemList;
  512. }
  513. var params = utils.defineGetter(obj, showActionSheetProps, function (_obj, prop) {
  514. utils.warn("showActionSheet\u7684\u53C2\u6570\u4E0D\u652F\u6301 ".concat(prop, " \u5C5E\u6027!"), {
  515. apiName: "showActionSheet/".concat(prop),
  516. errorType: showActionSheetProps[prop].type,
  517. type: 'api'
  518. });
  519. });
  520. my.showActionSheet(_objectSpread(_objectSpread({}, params), {}, {
  521. success: function success(res) {
  522. res.tapIndex = res.index;
  523. delete res.index;
  524. obj.success && obj.success(res);
  525. }
  526. }));
  527. }
  528. },
  529. hideToast: {
  530. fn: function fn(obj) {
  531. try {
  532. my.hideToast();
  533. obj.success && obj.success({
  534. errMsg: 'hideToast: ok'
  535. });
  536. } catch (err) {
  537. obj.fail && obj.fail(err);
  538. } finally {
  539. obj.complete && obj.complete({
  540. errMsg: 'hideToast: ok'
  541. });
  542. }
  543. }
  544. },
  545. hideLoading: {
  546. fn: function fn(obj) {
  547. try {
  548. my.hideLoading();
  549. obj.success && obj.success({
  550. errMsg: 'hideLoading: ok'
  551. });
  552. } catch (err) {
  553. obj.fail && obj.fail(err);
  554. } finally {
  555. obj.complete && obj.complete({
  556. errMsg: 'hideLoading: ok'
  557. });
  558. }
  559. }
  560. },
  561. showNavigationBarLoading: {
  562. fn: function fn() {
  563. var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  564. try {
  565. my.showNavigationBarLoading();
  566. obj.success && obj.success({
  567. errMsg: 'showNavigationBarLoading: ok'
  568. });
  569. } catch (err) {
  570. obj.fail && obj.fail(err);
  571. } finally {
  572. obj.complete && obj.complete({
  573. errMsg: 'showNavigationBarLoading: ok'
  574. });
  575. }
  576. }
  577. },
  578. setNavigationBarTitle: {
  579. fn: function fn() {
  580. var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  581. return my.setNavigationBar(obj);
  582. }
  583. },
  584. setNavigationBarColor: {
  585. fn: function fn() {
  586. var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  587. return my.setNavigationBar(obj);
  588. }
  589. },
  590. hideNavigationBarLoading: {
  591. fn: function fn() {
  592. var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  593. try {
  594. my.hideNavigationBarLoading();
  595. obj.success && obj.success({
  596. errMsg: 'hideNavigationBarLoading: ok'
  597. });
  598. } catch (err) {
  599. obj.fail && obj.fail(err);
  600. } finally {
  601. obj.complete && obj.complete({
  602. errMsg: 'hideNavigationBarLoading: ok'
  603. });
  604. }
  605. }
  606. },
  607. setTabBarStyle: {
  608. fn: function fn() {
  609. var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  610. if (obj.color && obj.color.length === 4) {
  611. var color = obj.color.slice(1);
  612. obj.color = "#".concat(color).concat(color);
  613. }
  614. my.setTabBarStyle(obj);
  615. }
  616. },
  617. setTabBarItem: {
  618. fn: function fn() {
  619. var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  620. if (!obj.iconPath || !obj.selectedIconPath) {
  621. utils.warn('setTabBarItem的iconPath和selectedIconPath是必传的!', {
  622. apiName: 'setTabBarItem/iconPath和selectedIconPath',
  623. errorType: 0,
  624. type: 'api'
  625. });
  626. }
  627. my.setTabBarItem(obj);
  628. }
  629. },
  630. stopPullDownRefresh: {
  631. fn: function fn() {
  632. var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  633. try {
  634. my.stopPullDownRefresh();
  635. obj.success && obj.success({
  636. errMsg: 'stopPullDownRefresh: ok'
  637. });
  638. } catch (err) {
  639. obj.fail && obj.fail(err);
  640. } finally {
  641. obj.complete && obj.complete({
  642. errMsg: 'stopPullDownRefresh: ok'
  643. });
  644. }
  645. }
  646. },
  647. pageScrollTo: {
  648. fn: function fn() {
  649. var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  650. var pageScrollToParams = descObj.pageScrollTo.body.params.props;
  651. var params = utils.defineGetter(obj, pageScrollToParams, function (_obj, prop) {
  652. utils.warn("pageScrollTo\u7684\u53C2\u6570\u4E0D\u652F\u6301 ".concat(prop, " \u5C5E\u6027!"), {
  653. apiName: "pageScrollTo/".concat(prop),
  654. errorType: pageScrollToParams[prop].type,
  655. type: 'api'
  656. });
  657. });
  658. my.pageScrollTo(params);
  659. try {
  660. my.pageScrollTo();
  661. obj.success && obj.success({
  662. errMsg: 'pageScrollTo: ok'
  663. });
  664. } catch (err) {
  665. obj.fail && obj.fail(err);
  666. } finally {
  667. obj.complete && obj.complete({
  668. errMsg: 'pageScrollTo: ok'
  669. });
  670. }
  671. }
  672. },
  673. request: {
  674. fn: function fn() {
  675. var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  676. if (obj.header) {
  677. obj.headers = obj.header;
  678. delete obj.header;
  679. }
  680. obj.method = obj.method || 'GET';
  681. obj.method = obj.method.toUpperCase();
  682. if (obj.method !== 'GET' && obj.method !== 'POST') {
  683. utils.warn("request\u6682\u4E0D\u652F\u6301".concat(obj.method, "\u8BF7\u6C42\u65B9\u5F0F"), {
  684. apiName: "request/".concat(obj.method),
  685. errorType: 0,
  686. type: 'api'
  687. });
  688. obj.method = 'GET';
  689. }
  690. if (obj.responseType) {
  691. utils.warn('支付宝暂不支持responseType', {
  692. apiName: 'request/responseType',
  693. errorType: 0,
  694. type: 'api'
  695. });
  696. }
  697. var task = my.request(_objectSpread(_objectSpread({}, obj), {}, {
  698. success: function success(res) {
  699. res.header = res.headers;
  700. res.statusCode = res.status;
  701. delete res.headers;
  702. delete res.status;
  703. obj.success && obj.success(res);
  704. },
  705. fail: function fail(err) {
  706. var errMsg = 'request:fail abort';
  707. if (err.errorMessage === errMsg) {
  708. err = {
  709. errMsg: errMsg
  710. };
  711. }
  712. obj.fail && obj.fail(err);
  713. },
  714. complete: function complete(res) {
  715. obj.complete && obj.complete(res);
  716. }
  717. }));
  718. task = task || {};
  719. task.onHeadersReceived = function () {};
  720. task.offHeadersReceived = function () {};
  721. return task;
  722. }
  723. },
  724. createMapContext: {
  725. fn: function fn() {
  726. var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  727. var createMapContextProps = descObj.createMapContext.body.returnValue.props;
  728. var data = my.createMapContext(obj);
  729. for (var key in createMapContextProps) {
  730. if (createMapContextProps[key].type === 0) {
  731. data[key] = function () {};
  732. }
  733. }
  734. return utils.defineGetter(data, createMapContextProps, function (_obj, prop) {
  735. utils.warn("createMapContext\u7684\u8FD4\u56DE\u503C\u4E0D\u652F\u6301 ".concat(prop, " \u5C5E\u6027!"), {
  736. apiName: "createMapContext/".concat(prop),
  737. errorType: createMapContextProps[prop].type,
  738. type: 'api'
  739. });
  740. });
  741. }
  742. },
  743. createVideoContext: {
  744. fn: function fn(id, that) {
  745. if (that) {
  746. utils.warn('createVideoContext暂不支持传递实例this', {
  747. apiName: 'createVideoContext',
  748. errorType: 0,
  749. type: 'api'
  750. });
  751. }
  752. return my.createVideoContext(id);
  753. }
  754. },
  755. createCameraContext: {
  756. fn: function fn() {
  757. var id = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
  758. var res = my.createCameraContext(id);
  759. res.setZoom = function () {
  760. utils.warn('支付宝暂不支持setZoom', {
  761. apiName: 'createCameraContext/setZoom',
  762. errorType: 0,
  763. type: 'api'
  764. });
  765. };
  766. return res;
  767. }
  768. },
  769. previewImage: {
  770. fn: function fn() {
  771. var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  772. var imgList = obj.urls || [];
  773. var index = imgList.indexOf(obj.current);
  774. obj.current = index;
  775. return my.previewImage(obj);
  776. }
  777. },
  778. compressImage: {
  779. fn: function fn() {
  780. var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  781. if (obj.src) {
  782. obj.apFilePaths = [obj.src];
  783. delete obj.src;
  784. }
  785. my.compressImage(_objectSpread(_objectSpread({}, obj), {}, {
  786. success: function success(res) {
  787. res.tempFilePath = res.apFilePaths[0];
  788. delete res.apFilePath;
  789. obj.success && obj.success(res);
  790. }
  791. }));
  792. }
  793. },
  794. chooseImage: {
  795. fn: function fn() {
  796. var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  797. if (!obj.count) {
  798. obj.count = 9;
  799. }
  800. my.chooseImage(_objectSpread(_objectSpread({}, obj), {}, {
  801. // success(res) {
  802. // res.tempFilePaths = res.apFilePaths
  803. // delete res.apFilePath
  804. // utils.warn('暂不支持tempFiles', {
  805. // apiName: 'chooseImage/tempFiles',
  806. // errorType: 0,
  807. // type: 'api',
  808. // })
  809. // obj.success && obj.success(res)
  810. // },
  811. fail: function fail(err) {
  812. err.errMsg = err.errorMessage || '';
  813. }
  814. }));
  815. }
  816. },
  817. saveImageToPhotosAlbum: {
  818. fn: function fn() {
  819. var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  820. if (obj.filePath) {
  821. obj.url = obj.filePath;
  822. }
  823. return my.saveImage(obj);
  824. }
  825. },
  826. openLocation: {
  827. fn: function fn() {
  828. var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  829. if (obj.scale) {
  830. utils.warn('支付宝scale的取值为3-19,默认15', {
  831. apiName: 'openLocation/scale',
  832. errorType: 4,
  833. type: 'api'
  834. });
  835. if (obj.scale > 19) {
  836. obj.scale = 19;
  837. } else if (obj.scale < 3) {
  838. obj.scale = 3;
  839. }
  840. }
  841. return my.openLocation(obj);
  842. }
  843. },
  844. getLocation: {
  845. fn: function fn() {
  846. var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  847. var type = obj.type || 'wgs84';
  848. var getLocationProps = descObj.getLocation.body.returnValue.props;
  849. my.getLocation(_objectSpread(_objectSpread({}, obj), {}, {
  850. type: 0,
  851. success: function success(res) {
  852. var data = res;
  853. if (type === 'wgs84') {
  854. var lnglat = utils.gcj02towgs84(res.longitude, res.latitude);
  855. data = Object.assign(res, {
  856. longitude: lnglat[0],
  857. latitude: lnglat[1]
  858. });
  859. }
  860. data = utils.defineGetter(data, getLocationProps, function (_obj, prop) {
  861. utils.warn("getLocation\u7684\u8FD4\u56DE\u503C\u4E0D\u652F\u6301 ".concat(prop, " \u5C5E\u6027!"), {
  862. apiName: "getLocation/".concat(prop),
  863. errorType: getLocationProps[prop].type,
  864. type: 'api'
  865. });
  866. });
  867. obj.success && obj.success(data);
  868. }
  869. }));
  870. }
  871. },
  872. openCard: {
  873. fn: function fn(obj) {
  874. var openCardParams = descObj.openCard.body.params.props;
  875. var params = utils.defineGetter(obj, openCardParams, function (_obj, prop) {
  876. utils.warn("openCard\u7684\u53C2\u6570\u4E0D\u652F\u6301 ".concat(prop, " \u5C5E\u6027!"), {
  877. apiName: "openCard/".concat(prop),
  878. errorType: openCardParams[prop].type,
  879. type: 'api'
  880. });
  881. });
  882. return my.openCardList(params);
  883. }
  884. },
  885. login: {
  886. fn: function fn() {
  887. var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  888. my.getAuthCode({
  889. scopes: 'auth_base',
  890. success: function success(res) {
  891. var resObj = {
  892. code: res.authCode
  893. };
  894. if (res.authCode) {
  895. resObj.errMsg = 'login:ok';
  896. if (obj.success) {
  897. obj.success(resObj);
  898. }
  899. } else {
  900. resObj.errMsg = 'login:fail';
  901. if (obj.success) {
  902. obj.success(resObj);
  903. }
  904. }
  905. },
  906. fail: function fail(err) {
  907. if (obj.fail) {
  908. obj.fail(err);
  909. }
  910. },
  911. complete: function complete(res) {
  912. if (res.authCode) {
  913. var resObj = {
  914. code: res.authCode,
  915. errMsg: 'login:ok'
  916. };
  917. if (obj.complete) {
  918. obj.complete(resObj);
  919. }
  920. } else if (obj.complete) {
  921. obj.complete(res);
  922. }
  923. }
  924. });
  925. }
  926. },
  927. hideKeyboard: {
  928. fn: function fn() {
  929. var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  930. my.hideKeyboard(obj);
  931. if (typeof obj.success === 'function') {
  932. obj.success();
  933. }
  934. if (typeof obj.complete === 'function') {
  935. obj.complete();
  936. }
  937. }
  938. },
  939. getNetworkType: {
  940. fn: function fn() {
  941. var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  942. my.getNetworkType(_objectSpread(_objectSpread({}, obj), {}, {
  943. success: function success(res) {
  944. res.networkType = res.networkType.toLowerCase();
  945. var typeObjMap = {
  946. unknown: 'unknown',
  947. wifi: 'wifi',
  948. '2g': '2g',
  949. '3g': '3g',
  950. '4g': '4g'
  951. };
  952. if (res && !res.networkAvailable) {
  953. res.networkType = 'none';
  954. } else {
  955. res.networkType = typeObjMap[res.networkType] || res.networkType;
  956. }
  957. obj.success && obj.success(res);
  958. }
  959. }));
  960. }
  961. },
  962. canvasToTempFilePath: {
  963. fn: function fn() {
  964. var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  965. var ctx = my.createCanvasContext(obj.canvasId);
  966. ctx.toTempFilePath(_objectSpread(_objectSpread({}, obj), {}, {
  967. success: function success(res) {
  968. res.tempFilePath = res.apFilePath;
  969. delete res.apFilePath;
  970. obj.success && obj.success(res);
  971. }
  972. }));
  973. }
  974. },
  975. canvasPutImageData: {
  976. fn: function fn() {
  977. var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  978. var ctx = my.createCanvasContext(obj.canvasId);
  979. ctx.putImageData(_objectSpread(_objectSpread({}, obj), {}, {
  980. success: function success(res) {
  981. obj.success && obj.success(res);
  982. }
  983. }));
  984. }
  985. },
  986. canvasGetImageData: {
  987. fn: function fn() {
  988. var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  989. var ctx = my.createCanvasContext(obj.canvasId);
  990. ctx.getImageData(_objectSpread(_objectSpread({}, obj), {}, {
  991. success: function success(res) {
  992. obj.success && obj.success(res);
  993. }
  994. }));
  995. }
  996. },
  997. saveFile: {
  998. fn: function fn() {
  999. var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  1000. if (obj.tempFilePath) {
  1001. obj.apFilePath = obj.tempFilePath;
  1002. delete obj.tempFilePath;
  1003. }
  1004. my.saveFile(_objectSpread(_objectSpread({}, obj), {}, {
  1005. success: function success(res) {
  1006. res.savedFilePath = res.apFilePath;
  1007. delete res.apFilePath;
  1008. obj.success && obj.success(res);
  1009. }
  1010. }));
  1011. }
  1012. },
  1013. removeSavedFile: {
  1014. fn: function fn() {
  1015. var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  1016. if (obj.filePath) {
  1017. obj.apFilePath = obj.filePath;
  1018. delete obj.filePath;
  1019. }
  1020. return my.removeSavedFile(obj);
  1021. }
  1022. },
  1023. getSavedFileList: {
  1024. fn: function fn() {
  1025. var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  1026. my.getSavedFileList({
  1027. success: function success(res) {
  1028. if (res.fileList.length) {
  1029. var ret = res.fileList.map(function (item) {
  1030. item.filePath = item.apFilePath;
  1031. delete item.apFilePath;
  1032. return item;
  1033. });
  1034. res.fileList = ret;
  1035. obj.success && obj.success(res);
  1036. } else {
  1037. obj.success && obj.success(res);
  1038. }
  1039. }
  1040. });
  1041. }
  1042. },
  1043. getSavedFileInfo: {
  1044. fn: function fn() {
  1045. var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  1046. if (obj.filePath) {
  1047. obj.apFilePath = obj.filePath;
  1048. delete obj.filePath;
  1049. }
  1050. return my.getSavedFileInfo(obj);
  1051. }
  1052. },
  1053. getFileInfo: {
  1054. fn: function fn() {
  1055. var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  1056. if (obj.filePath) {
  1057. obj.apFilePath = obj.filePath;
  1058. delete obj.filePath;
  1059. }
  1060. return my.getFileInfo(obj);
  1061. }
  1062. },
  1063. downloadFile: {
  1064. fn: function fn() {
  1065. var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  1066. var downloadFileReturnValue = descObj.downloadFile.body.returnValue.props;
  1067. if (obj.filePath !== undefined) {
  1068. utils.warn('支付宝暂不支持 filePath', {
  1069. apiName: 'downloadFile/filePath',
  1070. errorType: 0,
  1071. type: 'api'
  1072. });
  1073. }
  1074. my.downloadFile(_objectSpread(_objectSpread({}, obj), {}, {
  1075. success: function success(res) {
  1076. res.tempFilePath = res.apFilePath;
  1077. if (res.apFilePath) {
  1078. res.statusCode = 200;
  1079. }
  1080. delete res.apFilePath;
  1081. if (!res.statusCode) {
  1082. utils.warn('支付宝暂不支持statusCode', {
  1083. apiName: 'downloadFile/statusCode',
  1084. errorType: 0,
  1085. type: 'api'
  1086. });
  1087. }
  1088. obj.success && obj.success(res);
  1089. }
  1090. }));
  1091. var task = {
  1092. abort: function abort() {},
  1093. offHeadersReceived: function offHeadersReceived() {},
  1094. offProgressUpdate: function offProgressUpdate() {},
  1095. onHeadersReceived: function onHeadersReceived() {},
  1096. onProgressUpdate: function onProgressUpdate() {}
  1097. };
  1098. return utils.defineGetter(task, downloadFileReturnValue, function (_obj, prop) {
  1099. utils.warn("downloadFile\u7684\u8FD4\u56DE\u503C\u4E0D\u652F\u6301 ".concat(prop, " \u5C5E\u6027!"), {
  1100. apiName: "downloadFile/".concat(prop),
  1101. errorType: downloadFileReturnValue[prop].type,
  1102. type: 'api'
  1103. });
  1104. });
  1105. }
  1106. },
  1107. uploadFile: {
  1108. fn: function fn() {
  1109. var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  1110. var uploadFileValue = descObj.uploadFile.body.returnValue.props;
  1111. if (obj.name) {
  1112. obj.fileName = obj.name;
  1113. delete obj.name;
  1114. }
  1115. var pathArr = obj.filePath.split('.');
  1116. obj.fileType = 'image';
  1117. var fileType = {
  1118. video: ['ogg', 'avi', 'wma', 'rmvb', 'rm', 'flash', 'mp4', '3gp'],
  1119. audio: ['wav', 'mp3']
  1120. };
  1121. var typeName = pathArr[pathArr.length - 1];
  1122. Object.keys(fileType).forEach(function (key) {
  1123. fileType[key].forEach(function (item) {
  1124. if (typeName.toLowerCase() === item) {
  1125. obj.fileType = key;
  1126. }
  1127. });
  1128. });
  1129. my.uploadFile(obj);
  1130. var task = {
  1131. abort: function abort() {},
  1132. offHeadersReceived: function offHeadersReceived() {},
  1133. offProgressUpdate: function offProgressUpdate() {},
  1134. onHeadersReceived: function onHeadersReceived() {},
  1135. onProgressUpdate: function onProgressUpdate() {}
  1136. };
  1137. return utils.defineGetter(task, uploadFileValue, function (_obj, prop) {
  1138. utils.warn("uploadFile\u7684\u8FD4\u56DE\u503C\u4E0D\u652F\u6301 ".concat(prop, " \u5C5E\u6027!"), {
  1139. apiName: "uploadFile/".concat(prop),
  1140. errorType: uploadFileValue[prop].type,
  1141. type: 'api'
  1142. });
  1143. });
  1144. }
  1145. },
  1146. connectSocket: {
  1147. fn: function fn() {
  1148. var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  1149. var connectSocketParams = descObj.connectSocket.body.params.props;
  1150. var params = utils.defineGetter(obj, connectSocketParams, function (_obj, prop) {
  1151. utils.warn("connectSocket\u7684\u53C2\u6570\u4E0D\u652F\u6301 ".concat(prop, " \u5C5E\u6027!"), {
  1152. apiName: "connectSocket/".concat(prop),
  1153. errorType: connectSocketParams[prop].type,
  1154. type: 'api'
  1155. });
  1156. });
  1157. my.connectSocket(params);
  1158. var task = {
  1159. close: function close() {
  1160. var _obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  1161. my.closeSocket(_obj);
  1162. },
  1163. onClose: function onClose(fn) {
  1164. my.onSocketClose(fn);
  1165. },
  1166. onError: function onError(fn) {
  1167. my.offSocketOpen(fn);
  1168. },
  1169. onMessage: function onMessage(fn) {
  1170. my.onSocketMessage(fn);
  1171. },
  1172. onOpen: function onOpen(fn) {
  1173. my.onSocketOpen(function (res) {
  1174. fn(res);
  1175. });
  1176. },
  1177. send: function send() {
  1178. var _obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  1179. my.sendSocketMessage(_obj);
  1180. }
  1181. };
  1182. return task;
  1183. }
  1184. },
  1185. onSocketOpen: {
  1186. fn: function fn(obj) {
  1187. my.onSocketOpen(function (res) {
  1188. utils.warn('onSocketOpen 成功回调缺少header', {
  1189. apiName: 'onSocketOpen/header',
  1190. errorType: 0,
  1191. type: 'api'
  1192. });
  1193. obj(res);
  1194. });
  1195. }
  1196. },
  1197. closeSocket: {
  1198. fn: function fn() {
  1199. var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  1200. var closeSocketParams = descObj.closeSocket.body.params.props;
  1201. var params = utils.defineGetter(obj, closeSocketParams, function (_obj, prop) {
  1202. utils.warn("closeSocket\u7684\u53C2\u6570\u4E0D\u652F\u6301 ".concat(prop, " \u5C5E\u6027!"), {
  1203. apiName: "closeSocket/".concat(prop),
  1204. errorType: closeSocketParams[prop].type,
  1205. type: 'api'
  1206. });
  1207. });
  1208. my.closeSocket(params);
  1209. }
  1210. },
  1211. getRecorderManager: {
  1212. fn: function fn() {
  1213. var getRecorderManagerProps = descObj.getRecorderManager.body.returnValue.props;
  1214. var RecorderManager = my.getRecorderManager();
  1215. for (var key in getRecorderManagerProps) {
  1216. if (getRecorderManagerProps[key].type === 0) {
  1217. RecorderManager[key] = function () {};
  1218. }
  1219. }
  1220. return utils.defineGetter(RecorderManager, getRecorderManagerProps, function (obj, prop) {
  1221. utils.warn("getRecorderManager\u7684\u8FD4\u56DE\u503C\u4E0D\u652F\u6301 ".concat(prop, " \u5C5E\u6027!"), {
  1222. apiName: "getRecorderManager/".concat(prop),
  1223. errorType: getRecorderManagerProps[prop].type,
  1224. type: 'api'
  1225. });
  1226. });
  1227. }
  1228. },
  1229. setStorageSync: {
  1230. fn: function fn() {
  1231. var key = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
  1232. var data = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
  1233. return my.setStorageSync({
  1234. key: key,
  1235. data: data
  1236. });
  1237. }
  1238. },
  1239. getStorage: {
  1240. fn: function fn(obj) {
  1241. return my.getStorage({
  1242. key: obj.key,
  1243. success: function success(res) {
  1244. if (res.message && res.message === '查无此key' && typeof obj.fail === 'function') {
  1245. var Msg = {
  1246. errMsg: 'getStorage:fail data not found'
  1247. };
  1248. obj.fail(Msg);
  1249. } else if (typeof obj.success === 'function') {
  1250. obj.success(res);
  1251. }
  1252. },
  1253. complete: function complete(res) {
  1254. if (typeof obj.complete === 'function') {
  1255. if (res.message && res.message === '查无此key') {
  1256. var Msg = {
  1257. errMsg: 'getStorage:fail data not found'
  1258. };
  1259. obj.complete(Msg);
  1260. } else {
  1261. obj.complete(res);
  1262. }
  1263. }
  1264. }
  1265. });
  1266. }
  1267. },
  1268. getStorageSync: {
  1269. fn: function fn() {
  1270. var key = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
  1271. var storeData = my.getStorageSync({
  1272. key: key
  1273. });
  1274. return storeData.data || '';
  1275. }
  1276. },
  1277. removeStorageSync: {
  1278. fn: function fn() {
  1279. var key = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
  1280. return my.removeStorageSync({
  1281. key: key
  1282. });
  1283. }
  1284. },
  1285. removeStorage: {
  1286. fn: function fn(obj) {
  1287. var Msg = {
  1288. errMsg: 'removeStorage:ok'
  1289. };
  1290. return my.removeStorage(_objectSpread(_objectSpread({}, obj), {}, {
  1291. success: function success() {
  1292. if (typeof obj.success === 'function') {
  1293. obj.success(Msg);
  1294. }
  1295. },
  1296. complete: function complete() {
  1297. if (typeof obj.complete === 'function') {
  1298. obj.complete(Msg);
  1299. }
  1300. }
  1301. }));
  1302. }
  1303. },
  1304. createSelectorQuery: {
  1305. fn: function fn() {
  1306. var SQ = my.createSelectorQuery();
  1307. function Query() {
  1308. var _this = this;
  1309. this.query = SQ;
  1310. this._selectType = 0; // 0: array, 1: object
  1311. this["in"] = function (p) {
  1312. if (typeof this.query["in"] === 'function') {
  1313. this.query["in"](p);
  1314. return this;
  1315. } else {
  1316. return this;
  1317. }
  1318. };
  1319. this.select = function (p) {
  1320. var s = utils.parseSelector(p);
  1321. this.query.select(s);
  1322. this._selectType = 1;
  1323. return this;
  1324. };
  1325. this.node = function () {
  1326. utils.warn('支付宝暂不支持使用SelectorQuery NodesRef.node', {
  1327. apiName: 'SelectorQuery NodesRef.node',
  1328. errorType: 0,
  1329. type: 'api'
  1330. });
  1331. return _this;
  1332. };
  1333. this.selectAll = function (p) {
  1334. var s = utils.parseSelector(p);
  1335. this.query.selectAll(s);
  1336. return this;
  1337. };
  1338. this.selectViewport = function (p) {
  1339. this.query.selectViewport(p);
  1340. return this;
  1341. };
  1342. this.boundingClientRect = function (p) {
  1343. this.query.boundingClientRect();
  1344. this.exec(p);
  1345. return this;
  1346. };
  1347. this.scrollOffset = function (p) {
  1348. var self = this;
  1349. this.query.scrollOffset().exec(function (ret) {
  1350. if (self._selectType) {
  1351. self._selectType = 0;
  1352. if (Array.isArray(ret) && ret.length === 1) {
  1353. ret = ret[0];
  1354. }
  1355. }
  1356. p && p(ret);
  1357. });
  1358. return this;
  1359. };
  1360. this.exec = function (p) {
  1361. var _this2 = this;
  1362. this.query.exec(function (ret) {
  1363. if (Array.isArray(ret)) {
  1364. ret = ret.map(function (obj) {
  1365. return Array.isArray(obj) ? obj.map(function (item) {
  1366. return _objectSpread(_objectSpread({}, item), {}, {
  1367. id: utils.nextUid()
  1368. });
  1369. }) : _objectSpread(_objectSpread({}, obj), {}, {
  1370. id: utils.nextUid()
  1371. });
  1372. });
  1373. }
  1374. if (_this2._selectType) {
  1375. _this2._selectType = 0;
  1376. if (Array.isArray(ret)) {
  1377. if (ret.length === 1) {
  1378. ret = ret[0];
  1379. } else if (ret.length > 1) {
  1380. utils.warn('支付宝SelectorQuery.exec查询结果按请求次序构成数组,数组中每项为一次查询的结果', {
  1381. apiName: 'boundingClientRect',
  1382. errorType: 1,
  1383. type: 'api'
  1384. });
  1385. }
  1386. }
  1387. }
  1388. p && p(ret);
  1389. });
  1390. return this;
  1391. };
  1392. }
  1393. Query.prototype = SQ;
  1394. var res = new Query();
  1395. return res;
  1396. }
  1397. },
  1398. createIntersectionObserver: {
  1399. fn: function fn() {
  1400. var _my;
  1401. var OB = (_my = my).createIntersectionObserver.apply(_my, arguments);
  1402. function Observer() {
  1403. this.observer = OB;
  1404. this.relativeTo = function () {
  1405. var t = utils.parseSelector(arguments.length <= 0 ? undefined : arguments[0]);
  1406. var o = arguments.length <= 1 ? undefined : arguments[1];
  1407. this.observer.relativeTo(t, o);
  1408. return this;
  1409. };
  1410. this.relativeToViewport = function () {
  1411. var _this$observer;
  1412. (_this$observer = this.observer).relativeToViewport.apply(_this$observer, arguments);
  1413. return this;
  1414. };
  1415. this.observe = function () {
  1416. var t = utils.parseSelector(arguments.length <= 0 ? undefined : arguments[0]);
  1417. var cb = arguments.length <= 1 ? undefined : arguments[1];
  1418. this.observer.observe(t, function (ret) {
  1419. cb && cb(ret);
  1420. });
  1421. };
  1422. }
  1423. Observer.prototype = OB;
  1424. var res = new Observer();
  1425. return res;
  1426. }
  1427. },
  1428. createAnimation: {
  1429. fn: function fn() {
  1430. var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  1431. if (obj.timingFunction) {
  1432. obj.timeFunction = obj.timingFunction;
  1433. delete obj.timingFunction;
  1434. }
  1435. var animation = my.createAnimation(obj);
  1436. animation.config.delay = animation.config.delay || 0;
  1437. animation.option = {
  1438. transition: animation.config,
  1439. transformOrigin: animation.config.transformOrigin
  1440. };
  1441. return animation;
  1442. }
  1443. },
  1444. showShareMenu: {
  1445. fn: function fn() {
  1446. return my.showSharePanel();
  1447. }
  1448. },
  1449. saveVideoToPhotosAlbum: {
  1450. fn: function fn() {
  1451. var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  1452. var params = _objectSpread(_objectSpread({}, obj), {}, {
  1453. src: obj.filePath
  1454. });
  1455. return my.saveVideoToPhotosAlbum(params);
  1456. }
  1457. },
  1458. chooseAddress: {
  1459. fn: function fn() {
  1460. var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  1461. my.getAddress({
  1462. success: function success(_res) {
  1463. var result = {};
  1464. var res = _res.result;
  1465. result.cityName = res.city;
  1466. result.countyName = res.area;
  1467. result.detailInfo = res.street;
  1468. result.errMsg = 'chooseAddress:ok';
  1469. result.nationalCode = '';
  1470. result.postalCode = '';
  1471. result.provinceName = res.prov;
  1472. result.telNumber = res.mobilePhone;
  1473. result.userName = res.fullname;
  1474. obj.success && obj.success(result);
  1475. }
  1476. });
  1477. }
  1478. },
  1479. chooseVideo: {
  1480. fn: function fn() {
  1481. var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  1482. my.chooseVideo({
  1483. success: function success(result) {
  1484. result.tempFilePath = result.apFilePath;
  1485. delete result.apFilePath;
  1486. obj.success && obj.success(result);
  1487. }
  1488. });
  1489. }
  1490. },
  1491. getUpdateManager: {
  1492. fn: function fn() {
  1493. return my.getUpdateManager();
  1494. }
  1495. },
  1496. getUserInfo: {
  1497. fn: function fn(obj) {
  1498. var getUserInfoSuccessRes = descObj.getUserInfo.body.params.props;
  1499. if (obj.withCredentials || obj.lang) {
  1500. utils.warn('GetAuthUserInfo不支持 withCredentials 或 lang 参数.', {
  1501. apiName: 'getUserInfo/withCredentials 或 getUserInfo/lang',
  1502. errorType: 0,
  1503. type: 'api'
  1504. });
  1505. }
  1506. my.getAuthCode({
  1507. scopes: 'auth_user',
  1508. success: function success() {
  1509. my.getAuthUserInfo(_objectSpread(_objectSpread({}, obj), {}, {
  1510. success: function success(res) {
  1511. utils.defineGetter(res, getUserInfoSuccessRes, function (_obj, prop) {
  1512. utils.warn("getUserInfo\u7684\u53C2\u6570\u4E0D\u652F\u6301 ".concat(prop, " \u5C5E\u6027!"), {
  1513. apiName: "getUserInfo/".concat(prop),
  1514. errorType: getUserInfoSuccessRes[prop].type,
  1515. type: 'api'
  1516. });
  1517. });
  1518. var _res = {};
  1519. _res.userInfo = res;
  1520. _res.userInfo.avatarUrl = res.avatar;
  1521. obj.success && obj.success(_res);
  1522. }
  1523. }));
  1524. }
  1525. });
  1526. }
  1527. },
  1528. reportAnalytics: {
  1529. fn: function fn(key, value) {
  1530. if (_typeof(value) !== 'object') {
  1531. if (!(value instanceof Object)) {
  1532. value = {
  1533. data: value
  1534. };
  1535. }
  1536. }
  1537. return my.reportAnalytics(key, value);
  1538. }
  1539. },
  1540. requestPayment: {
  1541. fn: function fn() {
  1542. var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  1543. var requestPaymentParams = descObj.requestPayment.body.params.props;
  1544. var params = utils.defineGetter(obj, requestPaymentParams, function (_obj, prop) {
  1545. utils.warn("requestPayment\u7684\u53C2\u6570\u4E0D\u652F\u6301 ".concat(prop, " \u5C5E\u6027!"), {
  1546. apiName: "requestPayment/".concat(prop),
  1547. errorType: requestPaymentParams[prop].type,
  1548. type: 'api'
  1549. });
  1550. });
  1551. return my.tradePay(params);
  1552. }
  1553. },
  1554. authorize: {
  1555. fn: function fn() {
  1556. var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  1557. var authorizeParams = descObj.authorize.body.params.props;
  1558. if (obj.scope) {
  1559. delete obj.scope;
  1560. obj.scopes = 'auth_user';
  1561. }
  1562. var params = utils.defineGetter(obj, authorizeParams, function (_obj, prop) {
  1563. utils.warn("authorize\u7684\u53C2\u6570\u4E0D\u652F\u6301 ".concat(prop, " \u5C5E\u6027!"), {
  1564. apiName: "authorize/".concat(prop),
  1565. errorType: authorizeParams[prop].type,
  1566. type: 'api'
  1567. });
  1568. });
  1569. return my.getAuthCode(params);
  1570. }
  1571. },
  1572. addCard: {
  1573. fn: function fn(obj) {
  1574. var addCardParams = descObj.addCard.body.params.props;
  1575. var params = utils.defineGetter(obj, addCardParams, function (_obj, prop) {
  1576. utils.warn("addCard\u7684\u53C2\u6570\u4E0D\u652F\u6301 ".concat(prop, " \u5C5E\u6027!"), {
  1577. apiName: "startSoterAuthentication/".concat(prop),
  1578. errorType: addCardParams[prop].type,
  1579. type: 'api'
  1580. });
  1581. });
  1582. return my.addCardAuth(params);
  1583. }
  1584. },
  1585. startSoterAuthentication: {
  1586. fn: function fn(obj) {
  1587. var startSoterAuthenticationParams = descObj.startSoterAuthentication.body.params.props;
  1588. var params = utils.defineGetter(obj, startSoterAuthenticationParams, function (_obj, prop) {
  1589. utils.warn("startSoterAuthentication\u7684\u53C2\u6570\u4E0D\u652F\u6301 ".concat(prop, " \u5C5E\u6027!"), {
  1590. apiName: prop,
  1591. errorType: startSoterAuthenticationParams[prop].type,
  1592. type: 'api'
  1593. });
  1594. });
  1595. return my.ap.faceVerify(params);
  1596. }
  1597. },
  1598. getSetting: {
  1599. fn: function fn() {
  1600. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  1601. function setLocation(cb) {
  1602. my.getLocation({
  1603. success: function success(res) {
  1604. res.authSetting['scope.userLocation'] = true;
  1605. cb && cb();
  1606. }
  1607. });
  1608. }
  1609. if (my.getSetting) {
  1610. my.getSetting(_objectSpread(_objectSpread({}, options), {}, {
  1611. success: function success(res) {
  1612. var success = options.success;
  1613. if (!success) {
  1614. return;
  1615. }
  1616. success({
  1617. authSetting: utils.mapAuthSetting(res.authSetting)
  1618. });
  1619. }
  1620. }));
  1621. } else {
  1622. var res = {};
  1623. res.authSetting = {};
  1624. /**
  1625. * scope=[userInfo, location, album, camera, audioRecord]
  1626. */
  1627. if (options && options.success) {
  1628. setLocation(function () {
  1629. options.success(res);
  1630. });
  1631. }
  1632. }
  1633. }
  1634. },
  1635. openSetting: {
  1636. fn: function fn() {
  1637. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  1638. my.openSetting(_objectSpread(_objectSpread({}, options), {}, {
  1639. success: function success(res) {
  1640. var success = options.success;
  1641. if (!success) {
  1642. return;
  1643. }
  1644. success({
  1645. authSetting: utils.mapAuthSetting(res.authSetting)
  1646. });
  1647. }
  1648. }));
  1649. }
  1650. },
  1651. hideHomeButton: {
  1652. fn: function fn() {
  1653. var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  1654. var hideHomeButtonProps = descObj.hideHomeButton.body.params.props;
  1655. var param = utils.defineGetter(obj, hideHomeButtonProps, function (_obj, prop) {
  1656. utils.warn("hideHomeButton\u7684\u8FD4\u56DE\u503C\u4E0D\u652F\u6301 ".concat(prop, " \u5C5E\u6027!"), {
  1657. apiName: "hideHomeButton/".concat(prop),
  1658. errorType: hideHomeButtonProps[prop].type,
  1659. type: 'api'
  1660. });
  1661. });
  1662. return my.hideBackHome(param);
  1663. }
  1664. },
  1665. cloud: {
  1666. init: function init() {
  1667. utils.warn('支付宝暂不支持init', {
  1668. apiName: 'cloud/init',
  1669. errorType: 0,
  1670. type: 'api'
  1671. });
  1672. }
  1673. },
  1674. nextTick: function nextTick(fn) {
  1675. var delay = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
  1676. if (typeof fn === 'function') {
  1677. if (!delay) {
  1678. Promise.resolve().then(fn);
  1679. } else {
  1680. setTimeout(fn, delay);
  1681. }
  1682. }
  1683. }
  1684. };
  1685. module.exports = apiObj;