东风启辰小程序端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

5 jaren geleden
5 jaren geleden
5 jaren geleden
5 jaren geleden
5 jaren geleden
5 jaren geleden
5 jaren geleden
5 jaren geleden
5 jaren geleden
5 jaren geleden
5 jaren geleden
5 jaren geleden
5 jaren geleden
5 jaren geleden
5 jaren geleden
5 jaren geleden
5 jaren geleden
5 jaren geleden
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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. certificationState:0,//1车主,2合伙人,3同事
  39. },
  40. // 获取openId
  41. getOpenid: function (code) {
  42. wx.showLoading({
  43. title: '加载中',
  44. mask: true,
  45. })
  46. this.wxRequest(this.globalData.urlRoot + "wxInfo/getOpenid", { code: code }, res => {
  47. wx.hideLoading();
  48. console.log(res);
  49. if (res.code == 200) {
  50. wx.setStorageSync("openid", res.data.openid);
  51. wx.setStorageSync("session_key", res.data.session_key);
  52. this.globalData.openid = res.data.openid;
  53. this.globalData.session_key = res.data.session_key;
  54. if (this.globalData.openidSuccessFuc) {
  55. this.globalData.openidSuccessFuc();
  56. }
  57. } else {
  58. wx.showToast({
  59. title: res.msg,
  60. icon: "none"
  61. })
  62. }
  63. }, this);
  64. },
  65. /**
  66. * wx.request
  67. */
  68. wxRequest: function (url, params, callback, thisArg, methods, openid) {
  69. let that = this;
  70. var httpUrl = url;
  71. var str = "";
  72. var count = 0;
  73. for (let key in params) {
  74. if (count) {
  75. str += "&" + key + "=" + params[key];
  76. } else {
  77. str += key + "=" + params[key];
  78. }
  79. count++;
  80. }
  81. if (str) {
  82. httpUrl += "?" + str;
  83. }
  84. if (!methods) {
  85. methods = "GET";
  86. }
  87. if (methods == "POST") {
  88. wx.request({
  89. url: url,
  90. data: params,
  91. method: methods,
  92. header: {
  93. "content-type": "application/x-www-form-urlencoded",
  94. "OPENID": this.globalData.openid
  95. },
  96. success: function (re) {
  97. // if (re.data.code == -1002) {
  98. // wx.removeStorageSync('openid');
  99. // that.wxLogin();
  100. // // that.wxRequest(url, params, callback, thisArg, methods, openid);
  101. // }
  102. if (callback && thisArg) {
  103. callback.call(thisArg, re.data);
  104. }
  105. },
  106. fail: function (re) {
  107. wx.hideLoading();
  108. }
  109. })
  110. } else {
  111. wx.request({
  112. url: httpUrl,
  113. method: methods,
  114. header: {
  115. "OPENID": this.globalData.openid,
  116. },
  117. success: function (re) {
  118. if (re.data.code == -1002) {
  119. wx.removeStorageSync('openid');
  120. that.wxLogin();
  121. // that.wxRequest(url, params, callback, thisArg, methods, openid);
  122. }
  123. if (callback && thisArg) {
  124. callback.call(thisArg, re.data);
  125. }
  126. },
  127. fail: function (res) {
  128. wx.hideLoading();
  129. }
  130. })
  131. }
  132. },
  133. submitUserMsg: function (data) {//提交用户信息
  134. this.wxRequest(this.globalData.urlRoot + "/login/submitWxInfo", { userInfo: data }, res => {
  135. }, 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. })