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

332 行
11KB

  1. //app.js
  2. App({
  3. onLaunch: function (options) {
  4. console.log(options);
  5. this.globalData.sceneSource = options.scene;
  6. if (options.referrerInfo && options.referrerInfo.extraData && options.referrerInfo.extraData.source) {
  7. this.globalData.sceneSource = options.referrerInfo.extraData.source;
  8. } else if (options.query && options.query.scene) {
  9. var scene = decodeURIComponent(options.query.scene);
  10. var source = scene.split("&");
  11. for (let i = 0; i < source.length; i++) {
  12. var split = source[i].split("=");
  13. source[i] = [split[0], split[1]];
  14. if (split[0] == "source") {
  15. this.globalData.sceneSource = split[1];
  16. }
  17. }
  18. }
  19. // 展示本地存储能力
  20. var openid = wx.getStorageSync('openid') || "";
  21. if (!openid) {
  22. // 登录
  23. this.wxLogin();
  24. } else {
  25. this.globalData.openid = openid;
  26. this.addAppEnter();
  27. this.getBuyState();
  28. }
  29. var entered = wx.getStorageSync('entered');
  30. if (entered) {
  31. this.globalData.entered = entered;
  32. }
  33. var userMobile = wx.getStorageSync('userMobile');
  34. if (userMobile){
  35. this.globalData.userMobile = userMobile;
  36. }
  37. var parentOpenid = wx.getStorageSync('parentOpenid');
  38. if (parentOpenid) {
  39. this.globalData.parentOpenid = parentOpenid;
  40. }
  41. var certificationInfo = wx.getStorageSync('certificationInfo');
  42. if (certificationInfo) {
  43. this.globalData.certificationInfo = certificationInfo;
  44. }
  45. var userInfoData = wx.getStorageSync("userInfoData");
  46. if (userInfoData){
  47. this.globalData.userInfoData = {};
  48. this.globalData.userInfoData.avatarUrl = userInfoData.avatarUrl;
  49. this.globalData.userInfoData.nickName = userInfoData.nickName;
  50. this.globalData.userInfoData.userLevel = userInfoData.userLevel;
  51. }else{
  52. if (openid){
  53. this.getUserInfo();
  54. }
  55. }
  56. var userPhoneType = wx.getStorageSync('userPhoneType');
  57. if (userPhoneType) {
  58. this.globalData.userPhoneType = userPhoneType;
  59. } else {
  60. this.getPhoneType();
  61. }
  62. },
  63. getPhoneType() {//获取手机类型
  64. wx.getSystemInfo({
  65. success: res => {
  66. wx.setStorageSync("userPhoneType", res.platform);
  67. this.globalData.userPhoneType = res.platform;
  68. }
  69. })
  70. },
  71. wxLogin() {
  72. wx.login({
  73. success: res => {
  74. if (res.code) {
  75. this.getOpenid(res.code);
  76. } else {
  77. console.log('登录失败!' + res.errMsg)
  78. }
  79. }
  80. })
  81. },
  82. globalData: {
  83. // urlRoot: "https://dongfengqichen.jiyou-tech.com/",//测试接口根目录
  84. urlRoot: "https://xing.venucia.com/api/",//接口根目录
  85. // urlStatic: "https://www.jiyou-tech.com/2020/496_qichen/static",//测试静态资源根目录
  86. urlStatic: "https://xingb.venucia.com/resource",//静态资源根目录
  87. openid: "",//OPENID
  88. parentOpenid:"",//推荐人的openid
  89. session_key: "",//session_key
  90. openidSuccessFuc: null,//方法回调
  91. buyStateSuccessFuc:null,
  92. nowPage:'0',//当前tabBar
  93. isRegister:false,//是否已注册
  94. userMobile:null,//用户手机号
  95. isFirstLogin: true,//是否为第一次登录
  96. isFirstLucky: true,//是否为第一次进入幸运星抓手
  97. indexData:{},//首页数据
  98. myCenterData:null,//个人中心数据
  99. userInfoData:{
  100. "avatarUrl":"",
  101. "nickName":""
  102. },
  103. certificationState:0,//1车主,2合伙人,3同事
  104. mobileData:null,
  105. userPhoneType:null,
  106. kvurl:null,
  107. kvurlH:0,
  108. certificationInfo:false,
  109. getBuyState:null,
  110. entered:false,
  111. authenticationStatus:null,
  112. skipType:null,
  113. sceneSource:'',
  114. addPageEnterState:{
  115. index:false,
  116. luckyStar:false,
  117. star:false,
  118. myCenter:false,
  119. guessPrize:false,
  120. everyday:false
  121. }
  122. },
  123. // 获取openId
  124. getOpenid: function (code) {
  125. wx.showLoading({
  126. title: '加载中',
  127. mask: true,
  128. })
  129. this.wxRequest(this.globalData.urlRoot + "wxInfo/getOpenid", { code: code }, res => {
  130. wx.hideLoading();
  131. if (res.code == 200) {
  132. wx.setStorageSync("openid", res.data.openid);
  133. wx.setStorageSync("session_key", res.data.session_key);
  134. this.globalData.openid = res.data.openid;
  135. this.globalData.session_key = res.data.session_key;
  136. if (this.globalData.openidSuccessFuc) {
  137. this.globalData.openidSuccessFuc();
  138. }
  139. if(this.globalData.mobileData){
  140. this.getMobile2(this.globalData.mobileData.encryptedData, this.globalData.mobileData.iv, this.globalData.mobileData.callback, this.globalData.mobileData.thisArg);
  141. }
  142. var userInfoData = wx.getStorageSync("userInfoData");
  143. if (!userInfoData) {
  144. this.getUserInfo();
  145. }
  146. this.addAppEnter();
  147. this.getBuyState();
  148. } else {
  149. wx.showToast({
  150. title: res.msg,
  151. icon: "none"
  152. })
  153. }
  154. }, this);
  155. },
  156. /**
  157. * wx.request
  158. */
  159. wxRequest: function (url, params, callback, thisArg, methods, openid) {
  160. let that = this;
  161. var httpUrl = url;
  162. var str = "";
  163. var count = 0;
  164. for (let key in params) {
  165. if (count) {
  166. str += "&" + key + "=" + params[key];
  167. } else {
  168. str += key + "=" + params[key];
  169. }
  170. count++;
  171. }
  172. if (str) {
  173. httpUrl += "?" + str;
  174. }
  175. if (!methods) {
  176. methods = "GET";
  177. }
  178. if (methods == "POST") {
  179. wx.request({
  180. url: url,
  181. data: params,
  182. method: methods,
  183. header: {
  184. "content-type": "application/x-www-form-urlencoded",
  185. "VERSION": '100',
  186. "OPENID": this.globalData.openid
  187. },
  188. success: function (re) {
  189. // if (re.data.code == -1002) {
  190. // wx.removeStorageSync('openid');
  191. // that.wxLogin();
  192. // // that.wxRequest(url, params, callback, thisArg, methods, openid);
  193. // }
  194. if (callback && thisArg) {
  195. callback.call(thisArg, re.data);
  196. }
  197. },
  198. fail: function (re) {
  199. wx.hideLoading();
  200. }
  201. })
  202. } else {
  203. wx.request({
  204. url: httpUrl,
  205. method: methods,
  206. header: {
  207. "OPENID": this.globalData.openid,
  208. "VERSION": '100'
  209. },
  210. success: function (re) {
  211. if (re.data.code == -1002) {
  212. wx.removeStorageSync('openid');
  213. // that.wxLogin();
  214. // that.wxRequest(url, params, callback, thisArg, methods, openid);
  215. }
  216. if (callback && thisArg) {
  217. callback.call(thisArg, re.data);
  218. }
  219. },
  220. fail: function (res) {
  221. wx.hideLoading();
  222. }
  223. })
  224. }
  225. },
  226. submitUserMsg: function (avatarUrl, nickName) {//提交用户信息
  227. this.wxRequest(this.globalData.urlRoot + "userInfo/updateUserInfo", { avatarUrl: avatarUrl, nickName: nickName }, res => {
  228. if (res.code == 200) {
  229. this.globalData.userInfoData = {};
  230. this.globalData.userInfoData.avatarUrl = avatarUrl;
  231. this.globalData.userInfoData.nickName = nickName;
  232. wx.setStorageSync('userInfoData', {
  233. avatarUrl: avatarUrl,
  234. nickName: nickName,
  235. userLevel:1
  236. })
  237. }
  238. }, this, "POST")
  239. },
  240. codeVerify: function (card) {//身份证号码验证
  241. 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]$)/;
  242. return rule.test(card);
  243. },
  244. mobileVerify: function (mobile) {//手机号验证
  245. let rule = /^1\d{10}$/;
  246. return rule.test(mobile);
  247. },
  248. callMobile: function (e) {//拨打电话
  249. wx.makePhoneCall({
  250. phoneNumber: e //仅为示例,并非真实的电话号码
  251. })
  252. },
  253. sharePack: function () {//分享
  254. return {
  255. title: '',
  256. imageUrl: "",
  257. path: "/pages/index/index"
  258. }
  259. },
  260. addformId: function (e) {//添加formid
  261. this.wxRequest(this.globalData.urlRoot + "/msg/addFormId", { formid: e }, res => {
  262. console.log(res.msg);
  263. }, this, "POST");
  264. },
  265. getMobile: function (encryptedData, iv, callback, thisArg) {//检查登录态是否过期
  266. wx.checkSession({
  267. success: res => {
  268. this.getMobile2(encryptedData,iv,callback,thisArg);
  269. },
  270. fail: res => {
  271. this.globalData.mobileData = {};
  272. this.globalData.mobileData.encryptedData = encryptedData;
  273. this.globalData.mobileData.iv = iv;
  274. this.globalData.mobileData.callback = callback;
  275. this.globalData.mobileData.thisArg = thisArg;
  276. this.wxLogin();
  277. }
  278. })
  279. },
  280. getMobile2: function (encryptedData, iv, callback, thisArg) {//和后台置换手机号
  281. this.globalData.mobileData = null;
  282. this.wxRequest(this.globalData.urlRoot + "userInfo/getUserPhoneNumber", { encryptedData: encryptedData, iv: iv }, res => {
  283. if (res.code == 200) {
  284. if (res.data && res.data.decodeData) {
  285. wx.setStorageSync('userMobile', res.data.decodeData.phoneNumber);
  286. this.globalData.userMobile = res.data.decodeData.phoneNumber;
  287. }
  288. }
  289. if (callback && thisArg) {
  290. callback.call(thisArg, res);
  291. }
  292. }, this, "POST");
  293. },
  294. getUserInfo: function () {//获取个人信息
  295. this.wxRequest(this.globalData.urlRoot +"userInfo/getUserInfo",{},res=>{
  296. if(res.code==200){
  297. if (res.data && res.data.avatarUrl) {
  298. this.globalData.userInfoData = {};
  299. this.globalData.userInfoData.avatarUrl = res.data.avatarUrl;
  300. this.globalData.userInfoData.nickName = res.data.nickName;
  301. this.globalData.userInfoData.userLevel = res.data.userLevel;
  302. wx.setStorageSync('userInfoData', {
  303. avatarUrl: res.data.avatarUrl,
  304. nickName: res.data.nickName,
  305. userLevel: res.data.userLevel
  306. })
  307. }
  308. }
  309. },this)
  310. },
  311. getBuyState: function () {//查询是否已下订
  312. this.wxRequest(this.globalData.urlRoot + "wxPay/getBuyState", {}, res => {
  313. if (res.code == 200) {
  314. if (res.data) {
  315. res.data.cdate = res.data.cdate ? res.data.cdate : "";
  316. this.globalData.getBuyState = res.data;
  317. if (this.globalData.buyStateSuccessFuc){
  318. this.globalData.buyStateSuccessFuc();
  319. }
  320. }
  321. }
  322. }, this);
  323. },
  324. addAppEnter: function () {//小程序整体pv统计
  325. this.wxRequest(this.globalData.urlRoot + "statistics/addAppEnter", { scene:this.globalData.sceneSource}, res => {
  326. }, this,"POST");
  327. },
  328. addPageEnter: function (e) {//小程序页面pv统计
  329. this.wxRequest(this.globalData.urlRoot + "statistics/addPageEnter", { scene: this.globalData.sceneSource, statisticsType:e }, res => {
  330. }, this, "POST");
  331. }
  332. })