app.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. //app.js
  2. //请配置请求url
  3. //请修改开发者工具中【详情】->【AppID】改为自己的Appid
  4. //请前往后台【小程序】->【小程序配置】填写自己的 appId and AppSecret
  5. const URL ='http://activity.crmeb.net';
  6. const util = require('utils/util.js');
  7. App({
  8. onLaunch: function (option) {
  9. if (URL==''){
  10. console.error("请配置请求url\n请修改开发者工具中【详情】->【AppID】改为自己的Appid\n请前往后台【小程序】->【小程序配置】填写自己的 appId and AppSecret");
  11. return false;
  12. }
  13. var that = this;
  14. if (option.query.hasOwnProperty('scene')){
  15. switch (option.scene) {
  16. //扫描小程序码
  17. case 1047:
  18. that.globalData.code = option.query.scene;
  19. break;
  20. //长按图片识别小程序码
  21. case 1048:
  22. that.globalData.code = option.query.scene;
  23. break;
  24. //手机相册选取小程序码
  25. case 1049:
  26. that.globalData.code = option.query.scene;
  27. break;
  28. //直接进入小程序
  29. case 1001:
  30. that.globalData.spid = option.query.scene;
  31. break;
  32. }
  33. }
  34. this.getMyMenus();
  35. // 获取导航高度;
  36. wx.getSystemInfo({
  37. success: res => {
  38. //导航高度
  39. this.globalData.navHeight = res.statusBarHeight * (750 / res.windowWidth) + 97;
  40. }, fail(err) {
  41. console.log(err);
  42. }
  43. })
  44. },
  45. globalData: {
  46. navHeight: 0,
  47. routineStyle: '#ffffff',
  48. openPages: '',
  49. spid: 0,
  50. code:0,
  51. urlImages: '',
  52. url: URL,
  53. token: '',
  54. isLog:false,
  55. MyMenus:[],
  56. header: {
  57. 'content-type': 'application/json',
  58. 'token': ''
  59. }
  60. },
  61. /**
  62. *
  63. * 获取个人中心图标
  64. */
  65. getMyMenus: function () {
  66. var that = this;
  67. if (that.globalData.MyMenus.legnth) return;
  68. that.baseGet(that.U({ c: 'public_api', a: 'get_my_naviga'},that.globalData.url), function (res) {
  69. that.globalData.MyMenus = res.data.routine_my_menus;
  70. });
  71. },
  72. /*
  73. * POST 访问快捷方法
  74. * @param string | object url 访问地址
  75. * @param callable successCallback 成功执行函数
  76. * @param callable errorCallback 失败执行函数
  77. * @param object header 访问header头
  78. */
  79. basePost: function (url, data, successCallback, errorCallback, header) {
  80. if (header == undefined) header = this.globalData.header;
  81. header['token'] = this.globalData.token;
  82. util.basePost(url, data, successCallback, errorCallback,header);
  83. },
  84. /*
  85. * GET 访问快捷方法
  86. * @param string | object url 访问地址
  87. * @param callable successCallback 成功执行函数
  88. * @param callable errorCallback 失败执行函数
  89. * @param isMsg 错误信息提醒 默认提醒
  90. * @param object header 访问header头
  91. */
  92. baseGet: function (url, successCallback, errorCallback, isMsg, header) {
  93. if (header == undefined) header = this.globalData.header;
  94. header['token'] = this.globalData.token;
  95. util.baseGet(url, successCallback, errorCallback, isMsg,header);
  96. },
  97. /*
  98. * 信息提示 + 跳转
  99. * @param object opt {title:'提示语',icon:''} | url
  100. * @param object to_url 跳转url 有5种跳转方式 {tab:1-5,url:跳转地址}
  101. */
  102. Tips: function (opt, to_url) {
  103. return util.Tips(opt, to_url);
  104. },
  105. /*
  106. * 访问Url拼接
  107. * @param object opt {c:'控制器',a:'方法',q:{get参数},p:{parma参数}}
  108. * @param url 接口访问地址
  109. * @return string
  110. */
  111. U: function (opt,url){
  112. return util.U(opt,url);
  113. },
  114. /**
  115. * 快捷调取助手函数
  116. */
  117. help:function()
  118. {
  119. return util.$h;
  120. },
  121. /*
  122. * 合并数组
  123. * @param array list 请求返回数据
  124. * @param array sp 原始数组
  125. * @return array
  126. */
  127. SplitArray: function (list, sp) { return util.SplitArray(list, sp)},
  128. })