runtimeProcess.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. "use strict";
  2. 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; }
  3. 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; }
  4. 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; }
  5. var myApi = require('./my');
  6. var utils = require('./utils.js');
  7. var globalVar = require('./config').global;
  8. var hasProxy = typeof Proxy !== 'undefined';
  9. var _Proxy = function _Proxy() {};
  10. if (hasProxy) {
  11. _Proxy = Proxy;
  12. }
  13. var myProxy = null;
  14. /**
  15. * runtime error catch
  16. */
  17. function warnApi(api) {
  18. var iscanIuse = globalVar.canIUse(api); // my下有此方法,但目前不可用
  19. if (!iscanIuse || api === 'getFileSystemManager') {
  20. utils.warn("\u652F\u4ED8\u5B9D\u6682\u4E0D\u652F\u6301".concat(api), {
  21. apiName: api,
  22. errorType: 0,
  23. type: 'api'
  24. });
  25. return function () {
  26. console.error("\u652F\u4ED8\u5B9D\u6682\u4E0D\u652F\u6301".concat(api));
  27. };
  28. }
  29. }
  30. module.exports = function () {
  31. var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  32. if (myProxy) {
  33. return myProxy;
  34. }
  35. var _obj = Object.assign({}, obj, myApi);
  36. if (!hasProxy) {
  37. Object.keys(myApi).forEach(function (attr) {
  38. Object.defineProperty(_obj, attr, {
  39. get: function get() {
  40. var ret;
  41. if (myApi[attr]) {
  42. ret = function ret() {
  43. var o = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  44. var args = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
  45. if (args) {
  46. return myApi[attr].fn(o, args);
  47. }
  48. return myApi[attr].fn(o);
  49. };
  50. } else {
  51. var helpFn = warnApi(attr);
  52. ret = obj[attr] || helpFn;
  53. }
  54. return ret;
  55. }
  56. });
  57. });
  58. return _obj;
  59. }
  60. myProxy = new _Proxy(_obj, {
  61. get: function get(target, attr) {
  62. var ret;
  63. if (typeof attr === 'string' && myApi[attr]) {
  64. if (typeof myApi[attr].fn === 'function') {
  65. ret = function ret() {
  66. var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  67. var args = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
  68. if (args) {
  69. return myApi[attr].fn(opts, args);
  70. }
  71. return myApi[attr].fn(opts);
  72. };
  73. } else {
  74. ret = myApi[attr];
  75. }
  76. } else {
  77. var helpFn = warnApi(attr);
  78. ret = target[attr] || helpFn;
  79. }
  80. return ret;
  81. }
  82. });
  83. return myProxy;
  84. };
  85. /**
  86. * for bindgetuserinfo open-type of button
  87. */
  88. myApi.getUserInfoWrap = {
  89. fn: function fn() {
  90. var e = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  91. var fn = arguments.length > 1 ? arguments[1] : undefined;
  92. globalVar.getAuthCode({
  93. scopes: 'auth_user',
  94. success: function success() {
  95. globalVar.getAuthUserInfo({
  96. success: function success(userInfo) {
  97. fn && fn(_objectSpread(_objectSpread({}, e), {}, {
  98. detail: {
  99. userInfo: userInfo
  100. }
  101. }));
  102. }
  103. });
  104. },
  105. fail: function fail(res) {
  106. fn && fn(_objectSpread(_objectSpread({}, e), {}, {
  107. detail: res
  108. }));
  109. }
  110. });
  111. }
  112. };
  113. /**
  114. * for bindgetphonenumber open-type of button
  115. */
  116. myApi.getPhoneNumberWrap = {
  117. fn: function fn() {
  118. var e = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  119. var fn = arguments.length > 1 ? arguments[1] : undefined;
  120. globalVar.getPhoneNumber({
  121. success: function success(res) {
  122. var encryptedData = res.response;
  123. e = _objectSpread(_objectSpread({}, e), {}, {
  124. detail: encryptedData,
  125. res: res
  126. });
  127. fn && fn(e);
  128. },
  129. fail: function fail(res) {
  130. e = _objectSpread(_objectSpread({}, e), {}, {
  131. detail: {},
  132. res: res
  133. });
  134. fn && fn(e);
  135. }
  136. });
  137. }
  138. };