app.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. var app = getApp();
  2. // var wxh = require('../../utils/wxh.js');
  3. App({
  4. onLaunch: function (option) {
  5. // 展示本地存储能力
  6. var that = this;
  7. if (option.query.hasOwnProperty('scene')) {
  8. var sceneCode = option.query.scene.split('-');
  9. if (sceneCode.length == 1) { //分享链接进入获取推广人二维码ID
  10. that.globalData.spreadid = sceneCode[0];
  11. } else if (sceneCode.length == 2) { //扫码进入进入获取推广人二维码ID
  12. that.globalData.spreadid = sceneCode[0];
  13. if (sceneCode[1]){
  14. wx.reLaunch({ url: option.path + '?id=' + sceneCode[1] });
  15. }
  16. }
  17. }
  18. var logs = wx.getStorageSync('logs') || []
  19. logs.unshift(Date.now())
  20. wx.setStorageSync('logs', logs)
  21. that.getRoutineConfig();
  22. },
  23. globalData: {
  24. config:null,//小程序相关配置
  25. uid: null,
  26. uidShare:null,//我的推广二维码ID
  27. openid:'',
  28. openPages:'',//记录要访问的页面
  29. spreadid: 0,//推广人二维码ID 2.5.36
  30. spid:0,//推广人二维码ID
  31. urlImages: '',
  32. url: 'https://shop.crmeb.net/',
  33. },
  34. //获取小程序配置
  35. getRoutineConfig:function(){
  36. var that = this;
  37. wx.request({
  38. url: that.globalData.url + '/routine/logins/get_routine_config',
  39. method: 'post',
  40. dataType  : 'json',
  41. success: function (res) {
  42. if(res.data.code == 200 ){
  43. that.globalData.config = res.data.data.routine_config;
  44. that.setBarColor('#FFFFFF');
  45. }else{
  46. wx.showToast({
  47. title: '请求接口错误',
  48. icon: 'none',
  49. duration: 1500,
  50. })
  51. }
  52. },
  53. fail:function(){
  54. wx.showToast({
  55. title: '配置信息获取失败',
  56. icon: 'none',
  57. duration: 1500,
  58. })
  59. }
  60. })
  61. },
  62. setBarColor: function (routine_style = '#FFFFFF'){
  63. var that = this;
  64. wx.setNavigationBarColor({
  65. frontColor: '#000000',
  66. backgroundColor: routine_style,
  67. })
  68. },
  69. setUserInfo : function(){
  70. var that = this;
  71. if (that.globalData.uid == null) {//是否存在用户信息,如果不存在跳转到首页
  72. setTimeout(function () {
  73. wx.navigateTo({
  74. url: '/pages/loading/loading',
  75. })
  76. }, 1500)
  77. }
  78. },
  79. rp: function (n) {
  80. var cnum = ['零', '一', '二', '三', '四', '五', '六', '七', '八', '九'];
  81. var s = '';
  82. n = '' + n; // 数字转为字符串
  83. for (var i = 0; i < n.length; i++) {
  84. s += cnum[parseInt(n.charAt(i))];
  85. }
  86. return s;
  87. },
  88. U: function (opt) {
  89. var m = opt.m || 'routine', c = opt.c || 'auth_api', a = opt.a || 'index', q = opt.q || '',
  90. p = opt.p || {}, params = '', gets = '';
  91. params = Object.keys(p).map(function (key) {
  92. return key + '/' + p[key];
  93. }).join('/');
  94. gets = Object.keys(q).map(function (key) {
  95. return key + '=' + q[key];
  96. }).join('&');
  97. return this.globalData.url + '/' + m + '/' + c + '/' + a + '/uid/' + this.globalData.uid + (params == '' ? '' : '/' + params) + (gets == '' ? '' : '?' + gets) + '&uid='+this.globalData.uid;
  98. },
  99. baseGet: function (url, successCallback, errorCallback) {
  100. var that = this;
  101. var header = {
  102. 'content-type': 'application/x-www-form-urlencoded'
  103. };
  104. wx.request({
  105. url: url,
  106. method: 'get',
  107. header: header,
  108. success: function (res) {
  109. if (res.data.code == 200) {
  110. successCallback && successCallback(res.data);
  111. } else {
  112. errorCallback && errorCallback(res.data);
  113. that.Tips({ title: res.data.msg });
  114. }
  115. }, fail: function (res) {
  116. console.log('submit fail');
  117. },
  118. complete: function (res) {
  119. }
  120. });
  121. },
  122. Tips: function (opt, to_url) {
  123. var title = opt.title || '', icon = opt.icon || 'none', endtime = opt.endtime || 2000;
  124. wx.showToast({
  125. title: title,
  126. icon: 'none',
  127. duration: endtime,
  128. })
  129. if (to_url != undefined) {
  130. if (typeof to_url == 'object') {
  131. var tab = to_url.tab || 1, url = to_url.url || '';
  132. switch (tab) {
  133. case 1:
  134. //一定时间后跳转至 table
  135. setTimeout(function () {
  136. wx.switchTab({
  137. url: url
  138. })
  139. }, endtime);
  140. break;
  141. case 2:
  142. //跳转至非table页面
  143. setTimeout(function () {
  144. wx.navigateTo({
  145. url: url,
  146. })
  147. }, endtime);
  148. break;
  149. case 3:
  150. //返回上页面
  151. setTimeout(function () {
  152. wx.navigateBack({
  153. delta: parseInt(url),
  154. })
  155. }, endtime);
  156. break;
  157. case 4:
  158. //关闭当前所有页面跳转至非table页面
  159. setTimeout(function () {
  160. wx.reLaunch({
  161. url: url,
  162. })
  163. }, endtime);
  164. break;
  165. case 5:
  166. //关闭当前页面跳转至非table页面
  167. setTimeout(function () {
  168. wx.redirectTo({
  169. url: url,
  170. })
  171. }, endtime);
  172. break;
  173. }
  174. } else {
  175. setTimeout(function () {
  176. wx.navigateTo({
  177. url: to_url,
  178. })
  179. }, endtime);
  180. }
  181. }
  182. },
  183. })