app.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. // app.js
  2. var domain = "http://192.168.5.4:8088"
  3. // domain = "http://192.168.2.90:8088"
  4. // domain = "https://cansino-fxcapi.vandh.cn/prod-api"
  5. // domain = "https://fxc.vandh.cn/prod-api"
  6. domain = "http://test-fxc.vandh.cn/prod-api"
  7. var serverDomain = domain + ""
  8. var downloadDomain = "https://oss.zhongyihz.cn"
  9. App({
  10. onLaunch: function () {
  11. // 获取系统状态栏信息
  12. wx.getSystemInfo({
  13. success: e => {
  14. this.globalData.StatusBar = e.statusBarHeight;
  15. let capsule = wx.getMenuButtonBoundingClientRect();
  16. if (capsule) {
  17. this.globalData.Custom = capsule;
  18. this.globalData.CustomBar = capsule.bottom + capsule.top - e.statusBarHeight;
  19. } else {
  20. this.globalData.CustomBar = e.statusBarHeight + 50;
  21. }
  22. }
  23. })
  24. if(!wx.getStorageSync('status')){
  25. wx.setStorageSync('status', JSON.stringify(this.globalData.status));
  26. }
  27. if(!wx.getStorageInfoSync('labelStatus')){
  28. wx.setStorageSync('status', JSON.stringify(this.globalData.labelStatus));
  29. }
  30. },
  31. requestP: function (options = {}) {
  32. var that = this;
  33. let {
  34. needToken = true,
  35. url,
  36. data,
  37. method,
  38. dataType,
  39. contentType,
  40. responseType,
  41. success,
  42. fail,
  43. complete
  44. } = options;
  45. let header = {
  46. // "Authorization": 'Bearer ' + wx.getStorageSync('token'),
  47. "Authorization": wx.getStorageSync('token'),
  48. 'content-type': contentType || "application/x-www-form-urlencoded; charset=UTF-8", //"application/json"
  49. }
  50. if (!needToken) { //不允许带token的接口屏蔽token
  51. delete header.Authorization
  52. }
  53. return new Promise((res, rej) => {
  54. wx.request({
  55. url: that.globalData.$path + url,
  56. data: data, //JSON.stringify(data),
  57. header: header,
  58. method: method || "POST",
  59. contentType: contentType || "application/x-www-form-urlencoded; charset=UTF-8", //"application/json",
  60. dataType,
  61. responseType,
  62. success(r) {
  63. if (r.data.code == 200) {
  64. res(r);
  65. } else if (r.data.code == 401) {
  66. wx.redirectTo({
  67. url: '/pages/login/login',
  68. })
  69. } else if(r.data.code == 101) {
  70. that.showMsg(r.data.msg,'error');
  71. }else{
  72. rej(r);
  73. }
  74. wx.hideLoading()
  75. },
  76. fail(err) {
  77. console.log(err)
  78. // rej(err);
  79. wx.hideLoading()
  80. that.showMsg('请刷新重试','error');
  81. },
  82. complete
  83. });
  84. });
  85. },
  86. globalData: {
  87. app:"KXN",//用于切换不同app使用; KXN:康希诺
  88. $path: serverDomain,
  89. $filePath: downloadDomain,
  90. // appId: "wx92dc65d230789297",
  91. // secret: "d184c4c85ad2551924979e1de1f1e1c9",
  92. userInfo: null,
  93. share: false,
  94. title:'冷链追溯系统',
  95. tabarData:{},
  96. status:{
  97. checkedMap:true,
  98. statisticsInfo:true,
  99. statusLabelTest:true,
  100. statusLabelNum:true,
  101. statusLabelType:true,
  102. expressStatu:true,
  103. transportStatus:true,
  104. tempChart:true,
  105. onlineNum:true,
  106. packageStatu:true,
  107. onlineSituat:true,
  108. newSituat:true
  109. },
  110. labelStatus:{
  111. lableX101: true,
  112. lableX102: true,
  113. lableX103: true,
  114. lableX104: true,
  115. lableX105: true,
  116. lableX106: true,
  117. lableX107: true,
  118. lableX201: true,
  119. lableX202: true,
  120. lableX203: true,
  121. }
  122. },
  123. //上传文件
  124. wxUploadFile: function (options, ...params) {
  125. var that = this;
  126. options.url = that.globalData.$path + options.url //+ "?platSign=" + that.globalData.platSign
  127. options.header = {
  128. "Authorization" : 'Bearer ' +  wx.getStorageSync('token'),
  129. }
  130. return new Promise((resolve, reject) => {
  131. const extras = {
  132. success: resolve,
  133. fail: reject
  134. }
  135. wx.uploadFile({ ...options, ...extras }, ...params)
  136. })
  137. },
  138. showToptip: function (that, type, text, time = 2500) { //自定义toptip
  139. that.setData({
  140. CustomBar: this.globalData.CustomBar,
  141. tipType: {
  142. "error": "bg-red",
  143. "success": "bg-gradual-green",
  144. "worning": "bg-orange"
  145. } [type],
  146. tipText: text,
  147. tipStaus: "show"
  148. })
  149. setTimeout(function () {
  150. that.setData({
  151. tipStaus: null
  152. })
  153. }, time)
  154. },
  155. showMsg:function (title,type){
  156. wx.showToast({
  157. title: title,
  158. icon:type,
  159. duration: 1000,
  160. mask:true
  161. })
  162. }
  163. })