东风启辰小程序端
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.

169 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. },
  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 (avatarUrl, nickName) {//提交用户信息
  134. this.wxRequest(this.globalData.urlRoot + "userInfo/updateUserInfo", { avatarUrl: avatarUrl, nickName: nickName }, res => { }, this, "POST")
  135. },
  136. codeVerify: function (card) {//身份证号码验证
  137. 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]$)/;
  138. return rule.test(card);
  139. },
  140. mobileVerify: function (mobile) {//手机号验证
  141. let rule = /^1\d{10}$/;
  142. return rule.test(mobile);
  143. },
  144. callMobile: function (e) {//拨打电话
  145. wx.makePhoneCall({
  146. phoneNumber: e //仅为示例,并非真实的电话号码
  147. })
  148. },
  149. sharePack: function () {//分享
  150. return {
  151. title: '',
  152. imageUrl: "",
  153. path: "/pages/index/index"
  154. }
  155. },
  156. addformId: function (e) {//添加formid
  157. console.log("下面是formid");
  158. console.log(e);
  159. this.wxRequest(this.globalData.urlRoot + "/msg/addFormId", { formid: e }, res => {
  160. // if(res.code==200){
  161. // console.log(res.msg);
  162. // }else{
  163. // console.log(res.msg);
  164. // }
  165. console.log(res.msg);
  166. }, this, "POST");
  167. }
  168. })