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

176 line
4.8KB

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