东风启辰小程序端
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

168 lines
4.6KB

  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. session_key: "",//session_key
  30. openidSuccessFuc: null,//方法回调
  31. nowPage:'1',//当前tabBar
  32. isRegister:false,//是否已注册
  33. userMobile:null,//用户手机号
  34. isFirstLogin:true,//是否为第一次登录
  35. indexData:{},//首页数据
  36. myCenterData:null//个人中心数据
  37. },
  38. // 获取openId
  39. getOpenid: function (code) {
  40. wx.showLoading({
  41. title: '加载中',
  42. mask: true,
  43. })
  44. this.wxRequest(this.globalData.urlRoot + "wxInfo/getOpenid", { code: code }, res => {
  45. wx.hideLoading();
  46. console.log(res);
  47. if (res.code == 200) {
  48. wx.setStorageSync("openid", res.data.openid);
  49. wx.setStorageSync("session_key", res.data.session_key);
  50. this.globalData.openid = res.data.openid;
  51. this.globalData.session_key = res.data.session_key;
  52. if (this.globalData.openidSuccessFuc) {
  53. this.globalData.openidSuccessFuc();
  54. }
  55. } else {
  56. wx.showToast({
  57. title: res.msg,
  58. icon: "none"
  59. })
  60. }
  61. }, this);
  62. },
  63. /**
  64. * wx.request
  65. */
  66. wxRequest: function (url, params, callback, thisArg, methods, openid) {
  67. let that = this;
  68. var httpUrl = url;
  69. var str = "";
  70. var count = 0;
  71. for (let key in params) {
  72. if (count) {
  73. str += "&" + key + "=" + params[key];
  74. } else {
  75. str += key + "=" + params[key];
  76. }
  77. count++;
  78. }
  79. if (str) {
  80. httpUrl += "?" + str;
  81. }
  82. if (!methods) {
  83. methods = "GET";
  84. }
  85. if (methods == "POST") {
  86. wx.request({
  87. url: url,
  88. data: params,
  89. method: methods,
  90. header: {
  91. "content-type": "application/x-www-form-urlencoded",
  92. "OPENID": this.globalData.openid
  93. },
  94. success: function (re) {
  95. // if (re.data.code == -1002) {
  96. // wx.removeStorageSync('openid');
  97. // that.wxLogin();
  98. // // that.wxRequest(url, params, callback, thisArg, methods, openid);
  99. // }
  100. if (callback && thisArg) {
  101. callback.call(thisArg, re.data);
  102. }
  103. },
  104. fail: function (re) {
  105. wx.hideLoading();
  106. }
  107. })
  108. } else {
  109. wx.request({
  110. url: httpUrl,
  111. method: methods,
  112. header: {
  113. "OPENID": this.globalData.openid,
  114. },
  115. success: function (re) {
  116. if (re.data.code == -1002) {
  117. wx.removeStorageSync('openid');
  118. that.wxLogin();
  119. // that.wxRequest(url, params, callback, thisArg, methods, openid);
  120. }
  121. if (callback && thisArg) {
  122. callback.call(thisArg, re.data);
  123. }
  124. },
  125. fail: function (res) {
  126. wx.hideLoading();
  127. }
  128. })
  129. }
  130. },
  131. submitUserMsg: function (data) {//提交用户信息
  132. this.wxRequest(this.globalData.urlRoot + "/login/submitWxInfo", { userInfo: data }, res => {
  133. }, this, "POST");
  134. },
  135. codeVerify: function (card) {//身份证号码验证
  136. 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]$)/;
  137. return rule.test(card);
  138. },
  139. mobileVerify: function (mobile) {//手机号验证
  140. let rule = /^1\d{10}$/;
  141. return rule.test(mobile);
  142. },
  143. callMobile: function (e) {//拨打电话
  144. wx.makePhoneCall({
  145. phoneNumber: e //仅为示例,并非真实的电话号码
  146. })
  147. },
  148. sharePack: function () {//分享
  149. return {
  150. title: '',
  151. imageUrl: "",
  152. path: "/pages/index/index"
  153. }
  154. },
  155. addformId: function (e) {//添加formid
  156. console.log("下面是formid");
  157. console.log(e);
  158. this.wxRequest(this.globalData.urlRoot + "/msg/addFormId", { formid: e }, res => {
  159. // if(res.code==200){
  160. // console.log(res.msg);
  161. // }else{
  162. // console.log(res.msg);
  163. // }
  164. console.log(res.msg);
  165. }, this, "POST");
  166. }
  167. })