东风启辰小程序端
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

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