1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837 |
- "use strict";
- 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); }
- 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; }
- 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; }
- 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; }
- var utils = require("./utils");
- var propsPolyfill = require("./propsPolyfill");
- var descObj = require("./desc.js");
- var apiObj = {
- startBeaconDiscovery: {
- fn: function fn() {
- var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
- var startBeaconDiscoveryParams = descObj.startBeaconDiscovery.body.params.props;
- var params = utils.defineGetter(obj, startBeaconDiscoveryParams, function (_obj, prop) {
- utils.warn("startBeaconDiscovery\u7684\u53C2\u6570\u4E0D\u652F\u6301 ".concat(prop, " \u5C5E\u6027!"), {
- apiName: "startBeaconDiscovery/".concat(prop),
- errorType: startBeaconDiscoveryParams[prop].type,
- type: 'api'
- });
- });
- return my.startBeaconDiscovery(params);
- }
- },
- stopBeaconDiscovery: {
- fn: function fn() {
- var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
- my.stopBeaconDiscovery(obj);
- }
- },
- onBeaconUpdate: {
- fn: function fn(cb) {
- return my.onBeaconUpdate({
- success: cb,
- fail: cb
- });
- }
- },
- onBeaconServiceChange: {
- fn: function fn(cb) {
- return my.onBeaconServiceChange({
- success: cb,
- fail: cb,
- complete: cb
- });
- }
- },
- getBeacons: {
- fn: function fn() {
- var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
- return my.getBeacons(obj);
- }
- },
- writeBLECharacteristicValue: {
- fn: function fn() {
- var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
- if (obj.value) {
- obj.value = utils.ab2hex(obj.value);
- }
- my.writeBLECharacteristicValue(obj);
- }
- },
- createBLEConnection: {
- fn: function fn() {
- var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
- return my.connectBLEDevice(obj);
- }
- },
- closeBLEConnection: {
- fn: function fn() {
- var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
- return my.disconnectBLEDevice(obj);
- }
- },
- onBLEConnectionStateChange: {
- fn: function fn() {
- var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
- return my.onBLEConnectionStateChanged(obj);
- }
- },
- onBLECharacteristicValueChange: {
- fn: function fn(cb) {
- my.onBLECharacteristicValueChange(function (res) {
- res.value = utils.changeType(res.value);
- cb && cb(res);
- });
- }
- },
- getBLEDeviceServices: {
- fn: function fn() {
- var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
- my.getBLEDeviceServices(_objectSpread(_objectSpread({}, obj), {}, {
- success: function success(res) {
- if (res.services) {
- res.services.forEach(function (item) {
- item.uuid = item.serviceId;
- delete item.serviceId;
- });
- }
- obj.success && obj.success(res);
- }
- }));
- }
- },
- getBLEDeviceCharacteristics: {
- fn: function fn() {
- var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
- my.getBLEDeviceCharacteristics(_objectSpread(_objectSpread({}, obj), {}, {
- success: function success(res) {
- if (res.characteristics) {
- res.characteristics.forEach(function (item) {
- item.uuid = item.characteristicId;
- delete item.characteristicId;
- });
- }
- obj.success && obj.success(res);
- }
- }));
- }
- },
- addPhoneContact: {
- fn: function fn() {
- var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
- if (obj.weChatNumber) {
- obj.alipayAccount = obj.weChatNumber;
- }
- my.addPhoneContact(obj);
- }
- },
- startBluetoothDevicesDiscovery: {
- fn: function fn() {
- var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
- if (obj.interval) {
- obj.interval = Math.round(obj.interval);
- }
- my.startBluetoothDevicesDiscovery(obj);
- }
- },
- onBluetoothDeviceFound: {
- fn: function fn(cb) {
- var onBluetoothDeviceFoundProps = descObj.onBluetoothDeviceFound.body.returnValue.props;
- my.onBluetoothDeviceFound(function (res) {
- var arr = res.devices.map(function (item) {
- item.advertisData = utils.changeType(item.advertisData);
- return utils.defineGetter(item, onBluetoothDeviceFoundProps, function (obj, prop) {
- utils.warn("onBluetoothDeviceFound\u7684\u8FD4\u56DE\u503C\u4E0D\u652F\u6301 ".concat(prop, " \u5C5E\u6027!"), {
- apiName: "onBluetoothDeviceFound/".concat(prop),
- errorType: onBluetoothDeviceFoundProps[prop].type,
- type: 'api'
- });
- });
- });
- res.devices = arr;
- cb && cb(res);
- });
- }
- },
- getBluetoothDevices: {
- fn: function fn() {
- var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
- var getBluetoothDevicesProps = descObj.getBluetoothDevices.body.returnValue.props.devices.props;
- my.getBluetoothDevices(_objectSpread(_objectSpread({}, obj), {}, {
- success: function success(res) {
- var arr = res.devices.map(function (item) {
- item.advertisData = utils.changeType(item.advertisData);
- return utils.defineGetter(item, getBluetoothDevicesProps, function (_obj, prop) {
- utils.warn("getBluetoothDevices\u7684\u8FD4\u56DE\u503C\u4E0D\u652F\u6301 ".concat(prop, " \u5C5E\u6027!"), {
- apiName: "getBluetoothDevices/".concat(prop),
- errorType: getBluetoothDevicesProps[prop].type,
- type: 'api'
- });
- });
- });
- res.devices = arr;
- obj.success && obj.success(res);
- }
- }));
- }
- },
- setClipboardData: {
- fn: function fn() {
- var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
- if (obj.data) {
- obj.text = obj.data;
- delete obj.data;
- }
- my.setClipboard(obj);
- }
- },
- getClipboardData: {
- fn: function fn() {
- var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
- my.getClipboard(_objectSpread(_objectSpread({}, obj), {}, {
- success: function success(res) {
- res.data = res.text;
- delete res.text;
- obj.success && obj.success(res);
- }
- }));
- }
- },
- onNetworkStatusChange: {
- fn: function fn(cb) {
- my.onNetworkStatusChange(function (res) {
- res.networkType = res.networkType.toLowerCase();
- var typeObjMap = {
- unknown: 'unknown',
- wifi: 'wifi',
- '2g': '2g',
- '3g': '3g',
- '4g': '4g'
- };
- if (res && !res.isConnected) {
- res.networkType = 'none';
- } else {
- res.networkType = typeObjMap[res.networkType] || res.networkType;
- }
- cb && cb(res);
- });
- }
- },
- setScreenBrightness: {
- fn: function fn() {
- var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
- if (obj.value) {
- obj.brightness = obj.value;
- delete obj.value;
- }
- my.setScreenBrightness(obj);
- }
- },
- getScreenBrightness: {
- fn: function fn() {
- var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
- my.getScreenBrightness({
- success: function success(res) {
- res.value = res.brightness;
- delete res.brightness;
- obj.success && obj.success(res);
- },
- fail: function fail(res) {
- obj.fail && obj.fail(res);
- }
- });
- }
- },
- scanCode: {
- fn: function fn() {
- var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
- obj.hideAlbum = obj.onlyFromCamera || false;
- my.scan(obj);
- }
- },
- stopGyroscope: {
- fn: function fn() {
- var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
- var stopGyroscopeParams = descObj.stopGyroscope.body.params.props;
- var params = utils.defineGetter(obj, stopGyroscopeParams, function (_obj, prop) {
- utils.warn("stopGyroscope\u7684\u53C2\u6570\u4E0D\u652F\u6301 ".concat(prop, " \u5C5E\u6027!"), {
- apiName: "stopGyroscope".concat(prop),
- errorType: stopGyroscopeParams[prop].type,
- type: 'api'
- });
- });
- return my.offGyroscopeChange(params);
- }
- },
- onCompassChange: {
- fn: function fn(cb) {
- var onCompassChangeReturnValue = descObj.onCompassChange.body.returnValue.props;
- my.onCompassChange(function (res) {
- var _res = utils.defineGetter(res, onCompassChangeReturnValue, function (obj, prop) {
- utils.warn("onCompassChange\u7684\u8FD4\u56DE\u503C\u4E0D\u652F\u6301 ".concat(prop, " \u5C5E\u6027!"), {
- apiName: "onCompassChange/".concat(prop),
- errorType: onCompassChangeReturnValue[prop].type,
- type: 'api'
- });
- });
- cb && cb(_res);
- });
- }
- },
- stopCompass: {
- fn: function fn() {
- var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
- var stopCompassParams = descObj.stopCompass.body.params.props;
- var params = utils.defineGetter(obj, stopCompassParams, function (_obj, prop) {
- utils.warn("stopCompass\u7684\u53C2\u6570\u4E0D\u652F\u6301 ".concat(prop, " \u5C5E\u6027!"), {
- apiName: "stopCompass/".concat(prop),
- errorType: stopCompassParams[prop].type,
- type: 'api'
- });
- });
- return my.offCompassChange(params);
- }
- },
- stopAccelerometer: {
- fn: function fn() {
- var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
- var stopAccelerometerParams = descObj.stopAccelerometer.body.params.props;
- var params = utils.defineGetter(obj, stopAccelerometerParams, function (_obj, prop) {
- utils.warn("stopAccelerometer\u7684\u53C2\u6570\u4E0D\u652F\u6301 ".concat(prop, " \u5C5E\u6027!"), {
- apiName: "stopCompass/".concat(prop),
- errorType: stopAccelerometerParams[prop].type,
- type: 'api'
- });
- });
- return my.offAccelerometerChange(params);
- }
- },
- makePhoneCall: {
- fn: function fn() {
- var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
- var makePhoneCallParams = descObj.makePhoneCall.body.params.props;
- if (obj.phoneNumber) {
- obj.number = obj.phoneNumber;
- delete obj.phoneNumber;
- }
- var params = utils.defineGetter(obj, makePhoneCallParams, function (_obj, prop) {
- utils.warn("makePhoneCall\u7684\u53C2\u6570\u4E0D\u652F\u6301 ".concat(prop, " \u5C5E\u6027!"), {
- apiName: "makePhoneCall/".concat(prop),
- errorType: makePhoneCallParams[prop].type,
- type: 'api'
- });
- });
- return my.makePhoneCall(params);
- }
- },
- canIUse: {
- fn: function fn(params) {
- var paramsList = params.split('.');
- if (paramsList[1] && paramsList[1] === 'success') {
- paramsList[1] = 'return';
- }
- var str = paramsList.join('.');
- return my.canIUse(str);
- }
- },
- getSystemInfoSync: {
- fn: function fn() {
- var ret = my.getSystemInfoSync();
- var getSystemInfoSyncProps = descObj.getSystemInfoSync.body.returnValue.props;
- ret = utils.defineGetter(ret, getSystemInfoSyncProps, function (obj, prop) {
- utils.warn("getSystemInfoSync\u7684\u8FD4\u56DE\u503C\u4E0D\u652F\u6301 ".concat(prop, " \u5C5E\u6027!"), {
- apiName: "getSystemInfoSync/".concat(prop),
- errorType: getSystemInfoSyncProps[prop].type,
- type: 'api'
- });
- });
- /**
- * 处理Android屏幕宽度返回值
- */
- if (ret.platform.toLowerCase() === 'android') {
- ret.platform = 'android';
- ret.screenWidth /= ret.pixelRatio;
- ret.screenHeight /= ret.pixelRatio;
- } else if (ret.platform.toLowerCase() === 'ios') {
- ret.platform = 'ios'; // mock的安全区位置信息(模拟器iphonex screenHeight:812)
- if (ret.screenHeight >= propsPolyfill.screenHeight) {
- ret.safeArea = propsPolyfill.safeArea;
- ret.safeArea.bottom = ret.screenHeight - propsPolyfill.safeHeight;
- } else {
- ret.safeArea = {
- bottom: ret.screenHeight,
- height: ret.screenHeight,
- left: 0,
- right: ret.screenWidth,
- top: ret.statusBarHeight,
- width: ret.screenWidth
- };
- }
- } // mock的版本,确保微信小程序源码里读取后和目标版本匹配都能通过
- ret.SDKVersion = '10.0.0';
- return ret;
- }
- },
- getSystemInfo: {
- fn: function fn() {
- var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
- var getSystemInfoProps = descObj.getSystemInfo.body.returnValue.props;
- my.getSystemInfo(_objectSpread(_objectSpread({}, obj), {}, {
- success: function success(res) {
- res = utils.defineGetter(res, getSystemInfoProps, function (_obj, prop) {
- utils.warn("getSystemInfo\u7684\u8FD4\u56DE\u503C\u4E0D\u652F\u6301 ".concat(prop, " \u5C5E\u6027!"), {
- apiName: "getSystemInfo/".concat(prop),
- errorType: getSystemInfoProps[prop].type,
- type: 'api'
- });
- });
- /**
- * 处理Android屏幕宽度返回值
- */
- if (res.platform.toLowerCase() === 'android') {
- res.platform = 'android';
- res.screenWidth /= res.pixelRatio;
- res.screenHeight /= res.pixelRatio;
- } else if (res.platform.toLowerCase() === 'ios') {
- res.platform = 'ios';
- if (res.screenHeight >= propsPolyfill.screenHeight) {
- res.safeArea = propsPolyfill.safeArea;
- res.safeArea.bottom = res.screenHeight - propsPolyfill.safeHeight;
- } else {
- res.safeArea = {
- bottom: res.screenHeight,
- height: res.screenHeight,
- left: 0,
- right: res.screenWidth,
- top: res.statusBarHeight,
- width: res.screenWidth
- };
- }
- } // mock的版本,确保微信小程序源码里读取后和目标版本匹配都能通过
- res.SDKVersion = '10.0.0';
- obj.success && obj.success(res);
- }
- }));
- }
- },
- showToast: {
- fn: function fn() {
- var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
- var showToastProps = descObj.showToast.body.params.props;
- if (obj.title) {
- obj.content = obj.title;
- delete obj.title;
- }
- if (!obj.duration) {
- obj.duration = 2000;
- }
- if (obj.icon) {
- if (obj.icon === 'success') {
- obj.type = 'success';
- } else if (obj.icon === 'loading') {
- obj.type = 'none';
- utils.warn('showToast暂不支持loading', {
- apiName: 'showToast/loading',
- errorType: 0,
- type: 'api'
- });
- } else {
- obj.type = 'none';
- }
- delete obj.icon;
- } else {
- obj.type = 'success';
- }
- var params = utils.defineGetter(obj, showToastProps, function (_obj, prop) {
- utils.warn("showToast\u7684\u53C2\u6570\u4E0D\u652F\u6301 ".concat(prop, " \u5C5E\u6027!"), {
- apiName: "showToast/".concat(prop),
- errorType: showToastProps[prop].type,
- type: 'api'
- });
- });
- my.showToast(params);
- }
- },
- showModal: {
- fn: function fn() {
- var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
- var showModalProps = descObj.showModal.body.params.props;
- if (obj.cancelText !== undefined) {
- obj.cancelButtonText = obj.cancelText;
- delete obj.cancelText;
- }
- if (obj.confirmText !== undefined) {
- obj.confirmButtonText = obj.confirmText;
- delete obj.confirmText;
- }
- var params = utils.defineGetter(obj, showModalProps, function (_obj, prop) {
- utils.warn("showModal\u7684\u53C2\u6570\u4E0D\u652F\u6301 ".concat(prop, " \u5C5E\u6027!"), {
- apiName: "showModal/".concat(prop),
- errorType: showModalProps[prop].type,
- type: 'api'
- });
- });
- my.confirm(_objectSpread(_objectSpread({}, params), {}, {
- success: function success(res) {
- if (res.confirm) {
- res.cancel = false;
- } else {
- res.cancel = true;
- }
- obj.success && obj.success(res);
- }
- }));
- }
- },
- showLoading: {
- fn: function fn() {
- var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
- var showLoadingProps = descObj.showLoading.body.params.props;
- if (obj.title) {
- obj.content = obj.title;
- delete obj.title;
- }
- var params = utils.defineGetter(obj, showLoadingProps, function (_obj, prop) {
- utils.warn("showLoading\u7684\u53C2\u6570\u4E0D\u652F\u6301 ".concat(prop, " \u5C5E\u6027!"), {
- apiName: "showLoading/".concat(prop),
- errorType: showLoadingProps[prop].type,
- type: 'api'
- });
- });
- my.showLoading(params);
- }
- },
- showActionSheet: {
- fn: function fn() {
- var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
- var showActionSheetProps = descObj.showActionSheet.body.params.props;
- if (obj.itemList) {
- obj.items = obj.itemList;
- delete obj.itemList;
- }
- var params = utils.defineGetter(obj, showActionSheetProps, function (_obj, prop) {
- utils.warn("showActionSheet\u7684\u53C2\u6570\u4E0D\u652F\u6301 ".concat(prop, " \u5C5E\u6027!"), {
- apiName: "showActionSheet/".concat(prop),
- errorType: showActionSheetProps[prop].type,
- type: 'api'
- });
- });
- my.showActionSheet(_objectSpread(_objectSpread({}, params), {}, {
- success: function success(res) {
- res.tapIndex = res.index;
- delete res.index;
- obj.success && obj.success(res);
- }
- }));
- }
- },
- hideToast: {
- fn: function fn(obj) {
- try {
- my.hideToast();
- obj.success && obj.success({
- errMsg: 'hideToast: ok'
- });
- } catch (err) {
- obj.fail && obj.fail(err);
- } finally {
- obj.complete && obj.complete({
- errMsg: 'hideToast: ok'
- });
- }
- }
- },
- hideLoading: {
- fn: function fn(obj) {
- try {
- my.hideLoading();
- obj.success && obj.success({
- errMsg: 'hideLoading: ok'
- });
- } catch (err) {
- obj.fail && obj.fail(err);
- } finally {
- obj.complete && obj.complete({
- errMsg: 'hideLoading: ok'
- });
- }
- }
- },
- showNavigationBarLoading: {
- fn: function fn() {
- var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
- try {
- my.showNavigationBarLoading();
- obj.success && obj.success({
- errMsg: 'showNavigationBarLoading: ok'
- });
- } catch (err) {
- obj.fail && obj.fail(err);
- } finally {
- obj.complete && obj.complete({
- errMsg: 'showNavigationBarLoading: ok'
- });
- }
- }
- },
- setNavigationBarTitle: {
- fn: function fn() {
- var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
- return my.setNavigationBar(obj);
- }
- },
- setNavigationBarColor: {
- fn: function fn() {
- var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
- return my.setNavigationBar(obj);
- }
- },
- hideNavigationBarLoading: {
- fn: function fn() {
- var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
- try {
- my.hideNavigationBarLoading();
- obj.success && obj.success({
- errMsg: 'hideNavigationBarLoading: ok'
- });
- } catch (err) {
- obj.fail && obj.fail(err);
- } finally {
- obj.complete && obj.complete({
- errMsg: 'hideNavigationBarLoading: ok'
- });
- }
- }
- },
- setTabBarStyle: {
- fn: function fn() {
- var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
- if (obj.color && obj.color.length === 4) {
- var color = obj.color.slice(1);
- obj.color = "#".concat(color).concat(color);
- }
- my.setTabBarStyle(obj);
- }
- },
- setTabBarItem: {
- fn: function fn() {
- var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
- if (!obj.iconPath || !obj.selectedIconPath) {
- utils.warn('setTabBarItem的iconPath和selectedIconPath是必传的!', {
- apiName: 'setTabBarItem/iconPath和selectedIconPath',
- errorType: 0,
- type: 'api'
- });
- }
- my.setTabBarItem(obj);
- }
- },
- stopPullDownRefresh: {
- fn: function fn() {
- var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
- try {
- my.stopPullDownRefresh();
- obj.success && obj.success({
- errMsg: 'stopPullDownRefresh: ok'
- });
- } catch (err) {
- obj.fail && obj.fail(err);
- } finally {
- obj.complete && obj.complete({
- errMsg: 'stopPullDownRefresh: ok'
- });
- }
- }
- },
- pageScrollTo: {
- fn: function fn() {
- var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
- var pageScrollToParams = descObj.pageScrollTo.body.params.props;
- var params = utils.defineGetter(obj, pageScrollToParams, function (_obj, prop) {
- utils.warn("pageScrollTo\u7684\u53C2\u6570\u4E0D\u652F\u6301 ".concat(prop, " \u5C5E\u6027!"), {
- apiName: "pageScrollTo/".concat(prop),
- errorType: pageScrollToParams[prop].type,
- type: 'api'
- });
- });
- my.pageScrollTo(params);
- try {
- my.pageScrollTo();
- obj.success && obj.success({
- errMsg: 'pageScrollTo: ok'
- });
- } catch (err) {
- obj.fail && obj.fail(err);
- } finally {
- obj.complete && obj.complete({
- errMsg: 'pageScrollTo: ok'
- });
- }
- }
- },
- request: {
- fn: function fn() {
- var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
- if (obj.header) {
- obj.headers = obj.header;
- delete obj.header;
- }
- obj.method = obj.method || 'GET';
- obj.method = obj.method.toUpperCase();
- if (obj.method !== 'GET' && obj.method !== 'POST') {
- utils.warn("request\u6682\u4E0D\u652F\u6301".concat(obj.method, "\u8BF7\u6C42\u65B9\u5F0F"), {
- apiName: "request/".concat(obj.method),
- errorType: 0,
- type: 'api'
- });
- obj.method = 'GET';
- }
- if (obj.responseType) {
- utils.warn('支付宝暂不支持responseType', {
- apiName: 'request/responseType',
- errorType: 0,
- type: 'api'
- });
- }
- var task = my.request(_objectSpread(_objectSpread({}, obj), {}, {
- success: function success(res) {
- res.header = res.headers;
- res.statusCode = res.status;
- delete res.headers;
- delete res.status;
- obj.success && obj.success(res);
- },
- fail: function fail(err) {
- var errMsg = 'request:fail abort';
- if (err.errorMessage === errMsg) {
- err = {
- errMsg: errMsg
- };
- }
- obj.fail && obj.fail(err);
- },
- complete: function complete(res) {
- obj.complete && obj.complete(res);
- }
- }));
- task = task || {};
- task.onHeadersReceived = function () {};
- task.offHeadersReceived = function () {};
- return task;
- }
- },
- createMapContext: {
- fn: function fn() {
- var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
- var createMapContextProps = descObj.createMapContext.body.returnValue.props;
- var data = my.createMapContext(obj);
- for (var key in createMapContextProps) {
- if (createMapContextProps[key].type === 0) {
- data[key] = function () {};
- }
- }
- return utils.defineGetter(data, createMapContextProps, function (_obj, prop) {
- utils.warn("createMapContext\u7684\u8FD4\u56DE\u503C\u4E0D\u652F\u6301 ".concat(prop, " \u5C5E\u6027!"), {
- apiName: "createMapContext/".concat(prop),
- errorType: createMapContextProps[prop].type,
- type: 'api'
- });
- });
- }
- },
- createVideoContext: {
- fn: function fn(id, that) {
- if (that) {
- utils.warn('createVideoContext暂不支持传递实例this', {
- apiName: 'createVideoContext',
- errorType: 0,
- type: 'api'
- });
- }
- return my.createVideoContext(id);
- }
- },
- createCameraContext: {
- fn: function fn() {
- var id = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
- var res = my.createCameraContext(id);
- res.setZoom = function () {
- utils.warn('支付宝暂不支持setZoom', {
- apiName: 'createCameraContext/setZoom',
- errorType: 0,
- type: 'api'
- });
- };
- return res;
- }
- },
- previewImage: {
- fn: function fn() {
- var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
- var imgList = obj.urls || [];
- var index = imgList.indexOf(obj.current);
- obj.current = index;
- return my.previewImage(obj);
- }
- },
- compressImage: {
- fn: function fn() {
- var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
- if (obj.src) {
- obj.apFilePaths = [obj.src];
- delete obj.src;
- }
- my.compressImage(_objectSpread(_objectSpread({}, obj), {}, {
- success: function success(res) {
- res.tempFilePath = res.apFilePaths[0];
- delete res.apFilePath;
- obj.success && obj.success(res);
- }
- }));
- }
- },
- chooseImage: {
- fn: function fn() {
- var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
- if (!obj.count) {
- obj.count = 9;
- }
- my.chooseImage(_objectSpread(_objectSpread({}, obj), {}, {
- // success(res) {
- // res.tempFilePaths = res.apFilePaths
- // delete res.apFilePath
- // utils.warn('暂不支持tempFiles', {
- // apiName: 'chooseImage/tempFiles',
- // errorType: 0,
- // type: 'api',
- // })
- // obj.success && obj.success(res)
- // },
- fail: function fail(err) {
- err.errMsg = err.errorMessage || '';
- }
- }));
- }
- },
- saveImageToPhotosAlbum: {
- fn: function fn() {
- var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
- if (obj.filePath) {
- obj.url = obj.filePath;
- }
- return my.saveImage(obj);
- }
- },
- openLocation: {
- fn: function fn() {
- var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
- if (obj.scale) {
- utils.warn('支付宝scale的取值为3-19,默认15', {
- apiName: 'openLocation/scale',
- errorType: 4,
- type: 'api'
- });
- if (obj.scale > 19) {
- obj.scale = 19;
- } else if (obj.scale < 3) {
- obj.scale = 3;
- }
- }
- return my.openLocation(obj);
- }
- },
- getLocation: {
- fn: function fn() {
- var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
- var type = obj.type || 'wgs84';
- var getLocationProps = descObj.getLocation.body.returnValue.props;
- my.getLocation(_objectSpread(_objectSpread({}, obj), {}, {
- type: 0,
- success: function success(res) {
- var data = res;
- if (type === 'wgs84') {
- var lnglat = utils.gcj02towgs84(res.longitude, res.latitude);
- data = Object.assign(res, {
- longitude: lnglat[0],
- latitude: lnglat[1]
- });
- }
- data = utils.defineGetter(data, getLocationProps, function (_obj, prop) {
- utils.warn("getLocation\u7684\u8FD4\u56DE\u503C\u4E0D\u652F\u6301 ".concat(prop, " \u5C5E\u6027!"), {
- apiName: "getLocation/".concat(prop),
- errorType: getLocationProps[prop].type,
- type: 'api'
- });
- });
- obj.success && obj.success(data);
- }
- }));
- }
- },
- openCard: {
- fn: function fn(obj) {
- var openCardParams = descObj.openCard.body.params.props;
- var params = utils.defineGetter(obj, openCardParams, function (_obj, prop) {
- utils.warn("openCard\u7684\u53C2\u6570\u4E0D\u652F\u6301 ".concat(prop, " \u5C5E\u6027!"), {
- apiName: "openCard/".concat(prop),
- errorType: openCardParams[prop].type,
- type: 'api'
- });
- });
- return my.openCardList(params);
- }
- },
- login: {
- fn: function fn() {
- var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
- my.getAuthCode({
- scopes: 'auth_base',
- success: function success(res) {
- var resObj = {
- code: res.authCode
- };
- if (res.authCode) {
- resObj.errMsg = 'login:ok';
- if (obj.success) {
- obj.success(resObj);
- }
- } else {
- resObj.errMsg = 'login:fail';
- if (obj.success) {
- obj.success(resObj);
- }
- }
- },
- fail: function fail(err) {
- if (obj.fail) {
- obj.fail(err);
- }
- },
- complete: function complete(res) {
- if (res.authCode) {
- var resObj = {
- code: res.authCode,
- errMsg: 'login:ok'
- };
- if (obj.complete) {
- obj.complete(resObj);
- }
- } else if (obj.complete) {
- obj.complete(res);
- }
- }
- });
- }
- },
- hideKeyboard: {
- fn: function fn() {
- var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
- my.hideKeyboard(obj);
- if (typeof obj.success === 'function') {
- obj.success();
- }
- if (typeof obj.complete === 'function') {
- obj.complete();
- }
- }
- },
- getNetworkType: {
- fn: function fn() {
- var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
- my.getNetworkType(_objectSpread(_objectSpread({}, obj), {}, {
- success: function success(res) {
- res.networkType = res.networkType.toLowerCase();
- var typeObjMap = {
- unknown: 'unknown',
- wifi: 'wifi',
- '2g': '2g',
- '3g': '3g',
- '4g': '4g'
- };
- if (res && !res.networkAvailable) {
- res.networkType = 'none';
- } else {
- res.networkType = typeObjMap[res.networkType] || res.networkType;
- }
- obj.success && obj.success(res);
- }
- }));
- }
- },
- canvasToTempFilePath: {
- fn: function fn() {
- var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
- var ctx = my.createCanvasContext(obj.canvasId);
- ctx.toTempFilePath(_objectSpread(_objectSpread({}, obj), {}, {
- success: function success(res) {
- res.tempFilePath = res.apFilePath;
- delete res.apFilePath;
- obj.success && obj.success(res);
- }
- }));
- }
- },
- canvasPutImageData: {
- fn: function fn() {
- var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
- var ctx = my.createCanvasContext(obj.canvasId);
- ctx.putImageData(_objectSpread(_objectSpread({}, obj), {}, {
- success: function success(res) {
- obj.success && obj.success(res);
- }
- }));
- }
- },
- canvasGetImageData: {
- fn: function fn() {
- var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
- var ctx = my.createCanvasContext(obj.canvasId);
- ctx.getImageData(_objectSpread(_objectSpread({}, obj), {}, {
- success: function success(res) {
- obj.success && obj.success(res);
- }
- }));
- }
- },
- saveFile: {
- fn: function fn() {
- var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
- if (obj.tempFilePath) {
- obj.apFilePath = obj.tempFilePath;
- delete obj.tempFilePath;
- }
- my.saveFile(_objectSpread(_objectSpread({}, obj), {}, {
- success: function success(res) {
- res.savedFilePath = res.apFilePath;
- delete res.apFilePath;
- obj.success && obj.success(res);
- }
- }));
- }
- },
- removeSavedFile: {
- fn: function fn() {
- var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
- if (obj.filePath) {
- obj.apFilePath = obj.filePath;
- delete obj.filePath;
- }
- return my.removeSavedFile(obj);
- }
- },
- getSavedFileList: {
- fn: function fn() {
- var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
- my.getSavedFileList({
- success: function success(res) {
- if (res.fileList.length) {
- var ret = res.fileList.map(function (item) {
- item.filePath = item.apFilePath;
- delete item.apFilePath;
- return item;
- });
- res.fileList = ret;
- obj.success && obj.success(res);
- } else {
- obj.success && obj.success(res);
- }
- }
- });
- }
- },
- getSavedFileInfo: {
- fn: function fn() {
- var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
- if (obj.filePath) {
- obj.apFilePath = obj.filePath;
- delete obj.filePath;
- }
- return my.getSavedFileInfo(obj);
- }
- },
- getFileInfo: {
- fn: function fn() {
- var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
- if (obj.filePath) {
- obj.apFilePath = obj.filePath;
- delete obj.filePath;
- }
- return my.getFileInfo(obj);
- }
- },
- downloadFile: {
- fn: function fn() {
- var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
- var downloadFileReturnValue = descObj.downloadFile.body.returnValue.props;
- if (obj.filePath !== undefined) {
- utils.warn('支付宝暂不支持 filePath', {
- apiName: 'downloadFile/filePath',
- errorType: 0,
- type: 'api'
- });
- }
- my.downloadFile(_objectSpread(_objectSpread({}, obj), {}, {
- success: function success(res) {
- res.tempFilePath = res.apFilePath;
- if (res.apFilePath) {
- res.statusCode = 200;
- }
- delete res.apFilePath;
- if (!res.statusCode) {
- utils.warn('支付宝暂不支持statusCode', {
- apiName: 'downloadFile/statusCode',
- errorType: 0,
- type: 'api'
- });
- }
- obj.success && obj.success(res);
- }
- }));
- var task = {
- abort: function abort() {},
- offHeadersReceived: function offHeadersReceived() {},
- offProgressUpdate: function offProgressUpdate() {},
- onHeadersReceived: function onHeadersReceived() {},
- onProgressUpdate: function onProgressUpdate() {}
- };
- return utils.defineGetter(task, downloadFileReturnValue, function (_obj, prop) {
- utils.warn("downloadFile\u7684\u8FD4\u56DE\u503C\u4E0D\u652F\u6301 ".concat(prop, " \u5C5E\u6027!"), {
- apiName: "downloadFile/".concat(prop),
- errorType: downloadFileReturnValue[prop].type,
- type: 'api'
- });
- });
- }
- },
- uploadFile: {
- fn: function fn() {
- var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
- var uploadFileValue = descObj.uploadFile.body.returnValue.props;
- if (obj.name) {
- obj.fileName = obj.name;
- delete obj.name;
- }
- var pathArr = obj.filePath.split('.');
- obj.fileType = 'image';
- var fileType = {
- video: ['ogg', 'avi', 'wma', 'rmvb', 'rm', 'flash', 'mp4', '3gp'],
- audio: ['wav', 'mp3']
- };
- var typeName = pathArr[pathArr.length - 1];
- Object.keys(fileType).forEach(function (key) {
- fileType[key].forEach(function (item) {
- if (typeName.toLowerCase() === item) {
- obj.fileType = key;
- }
- });
- });
- my.uploadFile(obj);
- var task = {
- abort: function abort() {},
- offHeadersReceived: function offHeadersReceived() {},
- offProgressUpdate: function offProgressUpdate() {},
- onHeadersReceived: function onHeadersReceived() {},
- onProgressUpdate: function onProgressUpdate() {}
- };
- return utils.defineGetter(task, uploadFileValue, function (_obj, prop) {
- utils.warn("uploadFile\u7684\u8FD4\u56DE\u503C\u4E0D\u652F\u6301 ".concat(prop, " \u5C5E\u6027!"), {
- apiName: "uploadFile/".concat(prop),
- errorType: uploadFileValue[prop].type,
- type: 'api'
- });
- });
- }
- },
- connectSocket: {
- fn: function fn() {
- var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
- var connectSocketParams = descObj.connectSocket.body.params.props;
- var params = utils.defineGetter(obj, connectSocketParams, function (_obj, prop) {
- utils.warn("connectSocket\u7684\u53C2\u6570\u4E0D\u652F\u6301 ".concat(prop, " \u5C5E\u6027!"), {
- apiName: "connectSocket/".concat(prop),
- errorType: connectSocketParams[prop].type,
- type: 'api'
- });
- });
- my.connectSocket(params);
- var task = {
- close: function close() {
- var _obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
- my.closeSocket(_obj);
- },
- onClose: function onClose(fn) {
- my.onSocketClose(fn);
- },
- onError: function onError(fn) {
- my.offSocketOpen(fn);
- },
- onMessage: function onMessage(fn) {
- my.onSocketMessage(fn);
- },
- onOpen: function onOpen(fn) {
- my.onSocketOpen(function (res) {
- fn(res);
- });
- },
- send: function send() {
- var _obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
- my.sendSocketMessage(_obj);
- }
- };
- return task;
- }
- },
- onSocketOpen: {
- fn: function fn(obj) {
- my.onSocketOpen(function (res) {
- utils.warn('onSocketOpen 成功回调缺少header', {
- apiName: 'onSocketOpen/header',
- errorType: 0,
- type: 'api'
- });
- obj(res);
- });
- }
- },
- closeSocket: {
- fn: function fn() {
- var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
- var closeSocketParams = descObj.closeSocket.body.params.props;
- var params = utils.defineGetter(obj, closeSocketParams, function (_obj, prop) {
- utils.warn("closeSocket\u7684\u53C2\u6570\u4E0D\u652F\u6301 ".concat(prop, " \u5C5E\u6027!"), {
- apiName: "closeSocket/".concat(prop),
- errorType: closeSocketParams[prop].type,
- type: 'api'
- });
- });
- my.closeSocket(params);
- }
- },
- getRecorderManager: {
- fn: function fn() {
- var getRecorderManagerProps = descObj.getRecorderManager.body.returnValue.props;
- var RecorderManager = my.getRecorderManager();
- for (var key in getRecorderManagerProps) {
- if (getRecorderManagerProps[key].type === 0) {
- RecorderManager[key] = function () {};
- }
- }
- return utils.defineGetter(RecorderManager, getRecorderManagerProps, function (obj, prop) {
- utils.warn("getRecorderManager\u7684\u8FD4\u56DE\u503C\u4E0D\u652F\u6301 ".concat(prop, " \u5C5E\u6027!"), {
- apiName: "getRecorderManager/".concat(prop),
- errorType: getRecorderManagerProps[prop].type,
- type: 'api'
- });
- });
- }
- },
- setStorageSync: {
- fn: function fn() {
- var key = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
- var data = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
- return my.setStorageSync({
- key: key,
- data: data
- });
- }
- },
- getStorage: {
- fn: function fn(obj) {
- return my.getStorage({
- key: obj.key,
- success: function success(res) {
- if (res.message && res.message === '查无此key' && typeof obj.fail === 'function') {
- var Msg = {
- errMsg: 'getStorage:fail data not found'
- };
- obj.fail(Msg);
- } else if (typeof obj.success === 'function') {
- obj.success(res);
- }
- },
- complete: function complete(res) {
- if (typeof obj.complete === 'function') {
- if (res.message && res.message === '查无此key') {
- var Msg = {
- errMsg: 'getStorage:fail data not found'
- };
- obj.complete(Msg);
- } else {
- obj.complete(res);
- }
- }
- }
- });
- }
- },
- getStorageSync: {
- fn: function fn() {
- var key = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
- var storeData = my.getStorageSync({
- key: key
- });
- return storeData.data || '';
- }
- },
- removeStorageSync: {
- fn: function fn() {
- var key = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
- return my.removeStorageSync({
- key: key
- });
- }
- },
- removeStorage: {
- fn: function fn(obj) {
- var Msg = {
- errMsg: 'removeStorage:ok'
- };
- return my.removeStorage(_objectSpread(_objectSpread({}, obj), {}, {
- success: function success() {
- if (typeof obj.success === 'function') {
- obj.success(Msg);
- }
- },
- complete: function complete() {
- if (typeof obj.complete === 'function') {
- obj.complete(Msg);
- }
- }
- }));
- }
- },
- createSelectorQuery: {
- fn: function fn() {
- var SQ = my.createSelectorQuery();
- function Query() {
- var _this = this;
- this.query = SQ;
- this._selectType = 0; // 0: array, 1: object
- this["in"] = function (p) {
- if (typeof this.query["in"] === 'function') {
- this.query["in"](p);
- return this;
- } else {
- return this;
- }
- };
- this.select = function (p) {
- var s = utils.parseSelector(p);
- this.query.select(s);
- this._selectType = 1;
- return this;
- };
- this.node = function () {
- utils.warn('支付宝暂不支持使用SelectorQuery NodesRef.node', {
- apiName: 'SelectorQuery NodesRef.node',
- errorType: 0,
- type: 'api'
- });
- return _this;
- };
- this.selectAll = function (p) {
- var s = utils.parseSelector(p);
- this.query.selectAll(s);
- return this;
- };
- this.selectViewport = function (p) {
- this.query.selectViewport(p);
- return this;
- };
- this.boundingClientRect = function (p) {
- this.query.boundingClientRect();
- this.exec(p);
- return this;
- };
- this.scrollOffset = function (p) {
- var self = this;
- this.query.scrollOffset().exec(function (ret) {
- if (self._selectType) {
- self._selectType = 0;
- if (Array.isArray(ret) && ret.length === 1) {
- ret = ret[0];
- }
- }
- p && p(ret);
- });
- return this;
- };
- this.exec = function (p) {
- var _this2 = this;
- this.query.exec(function (ret) {
- if (Array.isArray(ret)) {
- ret = ret.map(function (obj) {
- return Array.isArray(obj) ? obj.map(function (item) {
- return _objectSpread(_objectSpread({}, item), {}, {
- id: utils.nextUid()
- });
- }) : _objectSpread(_objectSpread({}, obj), {}, {
- id: utils.nextUid()
- });
- });
- }
- if (_this2._selectType) {
- _this2._selectType = 0;
- if (Array.isArray(ret)) {
- if (ret.length === 1) {
- ret = ret[0];
- } else if (ret.length > 1) {
- utils.warn('支付宝SelectorQuery.exec查询结果按请求次序构成数组,数组中每项为一次查询的结果', {
- apiName: 'boundingClientRect',
- errorType: 1,
- type: 'api'
- });
- }
- }
- }
- p && p(ret);
- });
- return this;
- };
- }
- Query.prototype = SQ;
- var res = new Query();
- return res;
- }
- },
- createIntersectionObserver: {
- fn: function fn() {
- var _my;
- var OB = (_my = my).createIntersectionObserver.apply(_my, arguments);
- function Observer() {
- this.observer = OB;
- this.relativeTo = function () {
- var t = utils.parseSelector(arguments.length <= 0 ? undefined : arguments[0]);
- var o = arguments.length <= 1 ? undefined : arguments[1];
- this.observer.relativeTo(t, o);
- return this;
- };
- this.relativeToViewport = function () {
- var _this$observer;
- (_this$observer = this.observer).relativeToViewport.apply(_this$observer, arguments);
- return this;
- };
- this.observe = function () {
- var t = utils.parseSelector(arguments.length <= 0 ? undefined : arguments[0]);
- var cb = arguments.length <= 1 ? undefined : arguments[1];
- this.observer.observe(t, function (ret) {
- cb && cb(ret);
- });
- };
- }
- Observer.prototype = OB;
- var res = new Observer();
- return res;
- }
- },
- createAnimation: {
- fn: function fn() {
- var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
- if (obj.timingFunction) {
- obj.timeFunction = obj.timingFunction;
- delete obj.timingFunction;
- }
- var animation = my.createAnimation(obj);
- animation.config.delay = animation.config.delay || 0;
- animation.option = {
- transition: animation.config,
- transformOrigin: animation.config.transformOrigin
- };
- return animation;
- }
- },
- showShareMenu: {
- fn: function fn() {
- return my.showSharePanel();
- }
- },
- saveVideoToPhotosAlbum: {
- fn: function fn() {
- var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
- var params = _objectSpread(_objectSpread({}, obj), {}, {
- src: obj.filePath
- });
- return my.saveVideoToPhotosAlbum(params);
- }
- },
- chooseAddress: {
- fn: function fn() {
- var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
- my.getAddress({
- success: function success(_res) {
- var result = {};
- var res = _res.result;
- result.cityName = res.city;
- result.countyName = res.area;
- result.detailInfo = res.street;
- result.errMsg = 'chooseAddress:ok';
- result.nationalCode = '';
- result.postalCode = '';
- result.provinceName = res.prov;
- result.telNumber = res.mobilePhone;
- result.userName = res.fullname;
- obj.success && obj.success(result);
- }
- });
- }
- },
- chooseVideo: {
- fn: function fn() {
- var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
- my.chooseVideo({
- success: function success(result) {
- result.tempFilePath = result.apFilePath;
- delete result.apFilePath;
- obj.success && obj.success(result);
- }
- });
- }
- },
- getUpdateManager: {
- fn: function fn() {
- return my.getUpdateManager();
- }
- },
- getUserInfo: {
- fn: function fn(obj) {
- var getUserInfoSuccessRes = descObj.getUserInfo.body.params.props;
- if (obj.withCredentials || obj.lang) {
- utils.warn('GetAuthUserInfo不支持 withCredentials 或 lang 参数.', {
- apiName: 'getUserInfo/withCredentials 或 getUserInfo/lang',
- errorType: 0,
- type: 'api'
- });
- }
- my.getAuthCode({
- scopes: 'auth_user',
- success: function success() {
- my.getAuthUserInfo(_objectSpread(_objectSpread({}, obj), {}, {
- success: function success(res) {
- utils.defineGetter(res, getUserInfoSuccessRes, function (_obj, prop) {
- utils.warn("getUserInfo\u7684\u53C2\u6570\u4E0D\u652F\u6301 ".concat(prop, " \u5C5E\u6027!"), {
- apiName: "getUserInfo/".concat(prop),
- errorType: getUserInfoSuccessRes[prop].type,
- type: 'api'
- });
- });
- var _res = {};
- _res.userInfo = res;
- _res.userInfo.avatarUrl = res.avatar;
- obj.success && obj.success(_res);
- }
- }));
- }
- });
- }
- },
- reportAnalytics: {
- fn: function fn(key, value) {
- if (_typeof(value) !== 'object') {
- if (!(value instanceof Object)) {
- value = {
- data: value
- };
- }
- }
- return my.reportAnalytics(key, value);
- }
- },
- requestPayment: {
- fn: function fn() {
- var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
- var requestPaymentParams = descObj.requestPayment.body.params.props;
- var params = utils.defineGetter(obj, requestPaymentParams, function (_obj, prop) {
- utils.warn("requestPayment\u7684\u53C2\u6570\u4E0D\u652F\u6301 ".concat(prop, " \u5C5E\u6027!"), {
- apiName: "requestPayment/".concat(prop),
- errorType: requestPaymentParams[prop].type,
- type: 'api'
- });
- });
- return my.tradePay(params);
- }
- },
- authorize: {
- fn: function fn() {
- var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
- var authorizeParams = descObj.authorize.body.params.props;
- if (obj.scope) {
- delete obj.scope;
- obj.scopes = 'auth_user';
- }
- var params = utils.defineGetter(obj, authorizeParams, function (_obj, prop) {
- utils.warn("authorize\u7684\u53C2\u6570\u4E0D\u652F\u6301 ".concat(prop, " \u5C5E\u6027!"), {
- apiName: "authorize/".concat(prop),
- errorType: authorizeParams[prop].type,
- type: 'api'
- });
- });
- return my.getAuthCode(params);
- }
- },
- addCard: {
- fn: function fn(obj) {
- var addCardParams = descObj.addCard.body.params.props;
- var params = utils.defineGetter(obj, addCardParams, function (_obj, prop) {
- utils.warn("addCard\u7684\u53C2\u6570\u4E0D\u652F\u6301 ".concat(prop, " \u5C5E\u6027!"), {
- apiName: "startSoterAuthentication/".concat(prop),
- errorType: addCardParams[prop].type,
- type: 'api'
- });
- });
- return my.addCardAuth(params);
- }
- },
- startSoterAuthentication: {
- fn: function fn(obj) {
- var startSoterAuthenticationParams = descObj.startSoterAuthentication.body.params.props;
- var params = utils.defineGetter(obj, startSoterAuthenticationParams, function (_obj, prop) {
- utils.warn("startSoterAuthentication\u7684\u53C2\u6570\u4E0D\u652F\u6301 ".concat(prop, " \u5C5E\u6027!"), {
- apiName: prop,
- errorType: startSoterAuthenticationParams[prop].type,
- type: 'api'
- });
- });
- return my.ap.faceVerify(params);
- }
- },
- getSetting: {
- fn: function fn() {
- var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
- function setLocation(cb) {
- my.getLocation({
- success: function success(res) {
- res.authSetting['scope.userLocation'] = true;
- cb && cb();
- }
- });
- }
- if (my.getSetting) {
- my.getSetting(_objectSpread(_objectSpread({}, options), {}, {
- success: function success(res) {
- var success = options.success;
- if (!success) {
- return;
- }
- success({
- authSetting: utils.mapAuthSetting(res.authSetting)
- });
- }
- }));
- } else {
- var res = {};
- res.authSetting = {};
- /**
- * scope=[userInfo, location, album, camera, audioRecord]
- */
- if (options && options.success) {
- setLocation(function () {
- options.success(res);
- });
- }
- }
- }
- },
- openSetting: {
- fn: function fn() {
- var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
- my.openSetting(_objectSpread(_objectSpread({}, options), {}, {
- success: function success(res) {
- var success = options.success;
- if (!success) {
- return;
- }
- success({
- authSetting: utils.mapAuthSetting(res.authSetting)
- });
- }
- }));
- }
- },
- hideHomeButton: {
- fn: function fn() {
- var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
- var hideHomeButtonProps = descObj.hideHomeButton.body.params.props;
- var param = utils.defineGetter(obj, hideHomeButtonProps, function (_obj, prop) {
- utils.warn("hideHomeButton\u7684\u8FD4\u56DE\u503C\u4E0D\u652F\u6301 ".concat(prop, " \u5C5E\u6027!"), {
- apiName: "hideHomeButton/".concat(prop),
- errorType: hideHomeButtonProps[prop].type,
- type: 'api'
- });
- });
- return my.hideBackHome(param);
- }
- },
- cloud: {
- init: function init() {
- utils.warn('支付宝暂不支持init', {
- apiName: 'cloud/init',
- errorType: 0,
- type: 'api'
- });
- }
- },
- nextTick: function nextTick(fn) {
- var delay = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
- if (typeof fn === 'function') {
- if (!delay) {
- Promise.resolve().then(fn);
- } else {
- setTimeout(fn, delay);
- }
- }
- }
- };
- module.exports = apiObj;
|