东风启辰小程序端
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

5 年前
5 年前
5 年前
5 年前
5 年前
5 年前
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  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. var userMobile = wx.getStorageSync('userMobile');
  13. if (userMobile){
  14. this.globalData.userMobile = userMobile;
  15. }
  16. var friendOpenid = wx.getStorageSync('friendOpenid');
  17. if (friendOpenid) {
  18. this.globalData.friendOpenid = friendOpenid;
  19. }
  20. var userInfoData = wx.getStorageSync("userInfoData");
  21. if (userInfoData){
  22. this.globalData.userInfoData = {};
  23. this.globalData.userInfoData.avatarUrl = userInfoData.avatarUrl;
  24. this.globalData.userInfoData.nickName = userInfoData.nickName;
  25. this.globalData.userInfoData.userLevel = userInfoData.userLevel;
  26. }else{
  27. if (openid){
  28. this.getUserInfo();
  29. }
  30. }
  31. var userPhoneType = wx.getStorageSync('userPhoneType');
  32. if (userPhoneType) {
  33. this.globalData.userPhoneType = userPhoneType;
  34. } else {
  35. this.getPhoneType();
  36. }
  37. },
  38. getPhoneType() {//获取手机类型
  39. wx.getSystemInfo({
  40. success: res => {
  41. wx.setStorageSync("userPhoneType", res.platform);
  42. this.globalData.userPhoneType = res.platform;
  43. }
  44. })
  45. },
  46. wxLogin() {
  47. wx.login({
  48. success: res => {
  49. if (res.code) {
  50. this.getOpenid(res.code);
  51. } else {
  52. console.log('登录失败!' + res.errMsg)
  53. }
  54. }
  55. })
  56. },
  57. globalData: {
  58. urlRoot: "https://dongfengqichen.jiyou-tech.com/",//测试接口根目录
  59. // urlRoot: "",//接口根目录
  60. urlStatic:"https://www.jiyou-tech.com/2020/496_qichen/static",//静态资源根目录
  61. openid: "",//OPENID
  62. friendOpenid:"",//推荐人的openid
  63. session_key: "",//session_key
  64. openidSuccessFuc: null,//方法回调
  65. nowPage:'1',//当前tabBar
  66. isRegister:false,//是否已注册
  67. userMobile:null,//用户手机号
  68. isFirstLogin:true,//是否为第一次登录
  69. indexData:{},//首页数据
  70. myCenterData:null,//个人中心数据
  71. userInfoData:null,
  72. certificationState:0,//1车主,2合伙人,3同事
  73. mobileData:null,
  74. userPhoneType:null,
  75. kvurl:null
  76. },
  77. // 获取openId
  78. getOpenid: function (code) {
  79. wx.showLoading({
  80. title: '加载中',
  81. mask: true,
  82. })
  83. this.wxRequest(this.globalData.urlRoot + "wxInfo/getOpenid", { code: code }, res => {
  84. wx.hideLoading();
  85. if (res.code == 200) {
  86. wx.setStorageSync("openid", res.data.openid);
  87. wx.setStorageSync("session_key", res.data.session_key);
  88. this.globalData.openid = res.data.openid;
  89. this.globalData.session_key = res.data.session_key;
  90. if (this.globalData.openidSuccessFuc) {
  91. this.globalData.openidSuccessFuc();
  92. }
  93. if(this.globalData.mobileData){
  94. this.getMobile2(this.globalData.mobileData.encryptedData, this.globalData.mobileData.iv, this.globalData.mobileData.callback, this.globalData.mobileData.thisArg);
  95. }
  96. var userInfoData = wx.getStorageSync("userInfoData");
  97. if (!userInfoData) {
  98. this.getUserInfo();
  99. }
  100. } else {
  101. wx.showToast({
  102. title: res.msg,
  103. icon: "none"
  104. })
  105. }
  106. }, this);
  107. },
  108. /**
  109. * wx.request
  110. */
  111. wxRequest: function (url, params, callback, thisArg, methods, openid) {
  112. let that = this;
  113. var httpUrl = url;
  114. var str = "";
  115. var count = 0;
  116. for (let key in params) {
  117. if (count) {
  118. str += "&" + key + "=" + params[key];
  119. } else {
  120. str += key + "=" + params[key];
  121. }
  122. count++;
  123. }
  124. if (str) {
  125. httpUrl += "?" + str;
  126. }
  127. if (!methods) {
  128. methods = "GET";
  129. }
  130. if (methods == "POST") {
  131. wx.request({
  132. url: url,
  133. data: params,
  134. method: methods,
  135. header: {
  136. "content-type": "application/x-www-form-urlencoded",
  137. "VERSION": '100',
  138. "OPENID": this.globalData.openid
  139. },
  140. success: function (re) {
  141. // if (re.data.code == -1002) {
  142. // wx.removeStorageSync('openid');
  143. // that.wxLogin();
  144. // // that.wxRequest(url, params, callback, thisArg, methods, openid);
  145. // }
  146. if (callback && thisArg) {
  147. callback.call(thisArg, re.data);
  148. }
  149. },
  150. fail: function (re) {
  151. wx.hideLoading();
  152. }
  153. })
  154. } else {
  155. wx.request({
  156. url: httpUrl,
  157. method: methods,
  158. header: {
  159. "OPENID": this.globalData.openid,
  160. "VERSION": '100'
  161. },
  162. success: function (re) {
  163. if (re.data.code == -1002) {
  164. wx.removeStorageSync('openid');
  165. that.wxLogin();
  166. // that.wxRequest(url, params, callback, thisArg, methods, openid);
  167. }
  168. if (callback && thisArg) {
  169. callback.call(thisArg, re.data);
  170. }
  171. },
  172. fail: function (res) {
  173. wx.hideLoading();
  174. }
  175. })
  176. }
  177. },
  178. submitUserMsg: function (avatarUrl, nickName) {//提交用户信息
  179. this.wxRequest(this.globalData.urlRoot + "userInfo/updateUserInfo", { avatarUrl: avatarUrl, nickName: nickName }, res => {
  180. if (res.code == 200) {
  181. this.globalData.userInfoData = {};
  182. this.globalData.userInfoData.avatarUrl = avatarUrl;
  183. this.globalData.userInfoData.nickName = nickName;
  184. wx.setStorageSync('userInfoData', {
  185. avatarUrl: avatarUrl,
  186. nickName: nickName,
  187. userLevel:1
  188. })
  189. }
  190. }, this, "POST")
  191. },
  192. codeVerify: function (card) {//身份证号码验证
  193. 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]$)/;
  194. return rule.test(card);
  195. },
  196. mobileVerify: function (mobile) {//手机号验证
  197. let rule = /^1\d{10}$/;
  198. return rule.test(mobile);
  199. },
  200. callMobile: function (e) {//拨打电话
  201. wx.makePhoneCall({
  202. phoneNumber: e //仅为示例,并非真实的电话号码
  203. })
  204. },
  205. sharePack: function () {//分享
  206. return {
  207. title: '',
  208. imageUrl: "",
  209. path: "/pages/index/index"
  210. }
  211. },
  212. addformId: function (e) {//添加formid
  213. this.wxRequest(this.globalData.urlRoot + "/msg/addFormId", { formid: e }, res => {
  214. console.log(res.msg);
  215. }, this, "POST");
  216. },
  217. getMobile: function (encryptedData, iv, callback, thisArg) {//检查登录态是否过期
  218. wx.checkSession({
  219. success: res => {
  220. this.getMobile2(encryptedData,iv,callback,thisArg);
  221. },
  222. fail: res => {
  223. this.globalData.mobileData = {};
  224. this.globalData.mobileData.encryptedData = encryptedData;
  225. this.globalData.mobileData.iv = iv;
  226. this.globalData.mobileData.callback = callback;
  227. this.globalData.mobileData.thisArg = thisArg;
  228. this.wxLogin();
  229. }
  230. })
  231. },
  232. getMobile2: function (encryptedData, iv, callback, thisArg) {//和后台置换手机号
  233. this.globalData.mobileData = null;
  234. this.wxRequest(this.globalData.urlRoot + "userInfo/getUserPhoneNumber", { encryptedData: encryptedData, iv: iv }, res => {
  235. if (res.code == 200) {
  236. if (res.data && res.data.decodeData) {
  237. wx.setStorageSync('userMobile', res.data.decodeData.phoneNumber);
  238. this.globalData.userMobile = res.data.decodeData.phoneNumber;
  239. }
  240. }
  241. if (callback && thisArg) {
  242. callback.call(thisArg, res);
  243. }
  244. }, this, "POST");
  245. },
  246. getUserInfo: function () {//获取个人信息
  247. this.wxRequest(this.globalData.urlRoot +"userInfo/getUserInfo",{},res=>{
  248. if(res.code==200){
  249. if (res.data && res.data.avatarUrl) {
  250. this.globalData.userInfoData = {};
  251. this.globalData.userInfoData.avatarUrl = res.data.avatarUrl;
  252. this.globalData.userInfoData.nickName = res.data.nickName;
  253. this.globalData.userInfoData.userLevel = res.data.userLevel;
  254. wx.setStorageSync('userInfoData', {
  255. avatarUrl: res.data.avatarUrl,
  256. nickName: res.data.nickName,
  257. userLevel: res.data.userLevel
  258. })
  259. }
  260. }
  261. },this)
  262. }
  263. })