东风启辰小程序端
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

170 líneas
4.7KB

  1. //app.js
  2. App({
  3. onLaunch: function () {
  4. // 展示本地存储能力
  5. var openid = wx.getStorageSync('openid') || "";
  6. if (!openid) {
  7. // 登录
  8. this.wxLogin();
  9. } else {
  10. this.globalData.openid = openid;
  11. }
  12. },
  13. wxLogin() {
  14. wx.login({
  15. success: res => {
  16. if (res.code) {
  17. this.getOpenid(res.code);
  18. } else {
  19. console.log('登录失败!' + res.errMsg)
  20. }
  21. }
  22. })
  23. },
  24. globalData: {
  25. urlRoot: "https://dongfengqichen.jiyou-tech.com/",//测试接口根目录
  26. // urlRoot: "",//接口根目录
  27. urlStatic:"https://www.jiyou-tech.com/2020/496_qichen/static",//静态资源根目录
  28. openid: "",//OPENID
  29. friendOpenid:"",//推荐人的openid
  30. session_key: "",//session_key
  31. openidSuccessFuc: null,//方法回调
  32. nowPage:'0',//当前tabBar
  33. isRegister:false,//是否已注册
  34. userMobile:null,//用户手机号
  35. isFirstLogin:true,//是否为第一次登录
  36. indexData:{},//首页数据
  37. myCenterData:null,//个人中心数据
  38. userInfoData:null,
  39. certificationState:0,//1车主,2合伙人,3同事
  40. },
  41. // 获取openId
  42. getOpenid: function (code) {
  43. wx.showLoading({
  44. title: '加载中',
  45. mask: true,
  46. })
  47. this.wxRequest(this.globalData.urlRoot + "wxInfo/getOpenid", { code: code }, res => {
  48. wx.hideLoading();
  49. console.log(res);
  50. if (res.code == 200) {
  51. wx.setStorageSync("openid", res.data.openid);
  52. wx.setStorageSync("session_key", res.data.session_key);
  53. this.globalData.openid = res.data.openid;
  54. this.globalData.session_key = res.data.session_key;
  55. if (this.globalData.openidSuccessFuc) {
  56. this.globalData.openidSuccessFuc();
  57. }
  58. } else {
  59. wx.showToast({
  60. title: res.msg,
  61. icon: "none"
  62. })
  63. }
  64. }, this);
  65. },
  66. /**
  67. * wx.request
  68. */
  69. wxRequest: function (url, params, callback, thisArg, methods, openid) {
  70. let that = this;
  71. var httpUrl = url;
  72. var str = "";
  73. var count = 0;
  74. for (let key in params) {
  75. if (count) {
  76. str += "&" + key + "=" + params[key];
  77. } else {
  78. str += key + "=" + params[key];
  79. }
  80. count++;
  81. }
  82. if (str) {
  83. httpUrl += "?" + str;
  84. }
  85. if (!methods) {
  86. methods = "GET";
  87. }
  88. if (methods == "POST") {
  89. wx.request({
  90. url: url,
  91. data: params,
  92. method: methods,
  93. header: {
  94. "content-type": "application/x-www-form-urlencoded",
  95. "OPENID": this.globalData.openid
  96. },
  97. success: function (re) {
  98. // if (re.data.code == -1002) {
  99. // wx.removeStorageSync('openid');
  100. // that.wxLogin();
  101. // // that.wxRequest(url, params, callback, thisArg, methods, openid);
  102. // }
  103. if (callback && thisArg) {
  104. callback.call(thisArg, re.data);
  105. }
  106. },
  107. fail: function (re) {
  108. wx.hideLoading();
  109. }
  110. })
  111. } else {
  112. wx.request({
  113. url: httpUrl,
  114. method: methods,
  115. header: {
  116. "OPENID": this.globalData.openid,
  117. },
  118. success: function (re) {
  119. if (re.data.code == -1002) {
  120. wx.removeStorageSync('openid');
  121. that.wxLogin();
  122. // that.wxRequest(url, params, callback, thisArg, methods, openid);
  123. }
  124. if (callback && thisArg) {
  125. callback.call(thisArg, re.data);
  126. }
  127. },
  128. fail: function (res) {
  129. wx.hideLoading();
  130. }
  131. })
  132. }
  133. },
  134. submitUserMsg: function (avatarUrl, nickName) {//提交用户信息
  135. this.wxRequest(this.globalData.urlRoot + "userInfo/updateUserInfo", { avatarUrl: avatarUrl, nickName: nickName }, res => { }, this, "POST")
  136. },
  137. codeVerify: function (card) {//身份证号码验证
  138. let rule = /(^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$)|(^[1-9]\d{5}\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{2}[0-9Xx]$)/;
  139. return rule.test(card);
  140. },
  141. mobileVerify: function (mobile) {//手机号验证
  142. let rule = /^1\d{10}$/;
  143. return rule.test(mobile);
  144. },
  145. callMobile: function (e) {//拨打电话
  146. wx.makePhoneCall({
  147. phoneNumber: e //仅为示例,并非真实的电话号码
  148. })
  149. },
  150. sharePack: function () {//分享
  151. return {
  152. title: '',
  153. imageUrl: "",
  154. path: "/pages/index/index"
  155. }
  156. },
  157. addformId: function (e) {//添加formid
  158. console.log("下面是formid");
  159. console.log(e);
  160. this.wxRequest(this.globalData.urlRoot + "/msg/addFormId", { formid: e }, res => {
  161. // if(res.code==200){
  162. // console.log(res.msg);
  163. // }else{
  164. // console.log(res.msg);
  165. // }
  166. console.log(res.msg);
  167. }, this, "POST");
  168. }
  169. })