app.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. "use strict";
  2. var utils = require('../../api/utils');
  3. var warnLife = utils.warnLife;
  4. var _require = require('./utils'),
  5. setIfWatch = _require.setIfWatch;
  6. var getUrl = function getUrl() {
  7. var pages = getCurrentPages();
  8. var url = pages[pages.length - 1].route;
  9. var _arr = url.split('/');
  10. var _name = _arr[_arr.length - 1];
  11. my.setStorageSync({
  12. key: '_pageMsg',
  13. data: {
  14. pageName: _name,
  15. pagePath: url
  16. }
  17. });
  18. };
  19. module.exports = {
  20. processTransformationApp: function processTransformationApp(_opts, options) {
  21. _opts = Object.assign(_opts, options);
  22. _opts.onLaunch = function (res) {
  23. if (!my.canIUse('component2')) {
  24. console.warn('《建议用户开启 component2 模式,详情:IDE 中的 详情 > 项目配置 中,勾选 component2》');
  25. }
  26. my.removeStorageSync({
  27. key: 'logInfo'
  28. });
  29. my.removeStorageSync({
  30. key: '_pageMsg'
  31. });
  32. getUrl();
  33. var body = {};
  34. function pre() {
  35. var params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  36. return utils.defineGetter(params, body.params, function (obj, prop) {
  37. warnLife("onLaunch's return value is not support ".concat(prop, " attribute!"), "onLaunch/".concat(prop));
  38. });
  39. }
  40. if (options.onLaunch) {
  41. body = {
  42. params: {
  43. scene: {
  44. type: 0,
  45. desc: 'missing'
  46. },
  47. shareTicket: {
  48. type: 0,
  49. desc: 'missing'
  50. }
  51. }
  52. };
  53. res = pre(res);
  54. if (typeof options.data === 'function') {
  55. options.data = options.data();
  56. }
  57. options.onLaunch.call(this, res);
  58. }
  59. if (options.onPageNotFound) {
  60. warnLife('There is no onPageNotFound life cycle', 'onPageNotFound');
  61. }
  62. if (options.onPageNotFound) {
  63. warnLife('There is no onPageNotFound life cycle', 'onPageNotFound');
  64. }
  65. };
  66. _opts.onShow = function (res) {
  67. setIfWatch(true);
  68. var body = {};
  69. function pre() {
  70. var params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  71. return utils.defineGetter(params, body.params, function (obj, prop) {
  72. warnLife("onShow's return value is not support ".concat(prop, " attribute!"), "onShow/".concat(prop));
  73. });
  74. }
  75. if (options.onShow) {
  76. body = {
  77. params: {
  78. scene: {
  79. type: 0,
  80. desc: 'missing'
  81. },
  82. shareTicket: {
  83. type: 0,
  84. desc: 'missing'
  85. }
  86. }
  87. };
  88. res = pre(res);
  89. options.onShow.call(this, res);
  90. }
  91. };
  92. _opts.onHide = function () {
  93. setIfWatch(false);
  94. if (options.onHide) {
  95. warnLife('', 'app/onHide');
  96. options.onHide.call(this);
  97. }
  98. };
  99. if (options.onError) {
  100. _opts.onError = function () {
  101. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  102. args[_key] = arguments[_key];
  103. }
  104. options.onError.apply(this, args);
  105. };
  106. }
  107. }
  108. };