微信小程序
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.

3 年之前
3 年之前
3 年之前
3 年之前
1 年之前
3 年之前
3 年之前
1 年之前
1 年之前
1 年之前
1 年之前
3 年之前
1 年之前
3 年之前
1 年之前
3 年之前
3 年之前
3 年之前
3 年之前
3 年之前
3 年之前
3 年之前
3 年之前
3 年之前
3 年之前
1 年之前
3 年之前
3 年之前
3 年之前
1 年之前
3 年之前
1 年之前
3 年之前
3 年之前
1 年之前
3 年之前
3 年之前
1 年之前
3 年之前
3 年之前
3 年之前
1 年之前
3 年之前
3 年之前
1 年之前
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. // pages/index/index.js
  2. const APP = getApp();
  3. import * as UTIL from '../../../utils/util.js';
  4. import * as API from '../../../utils/API.js';
  5. import * as STORAGE from '../../../utils/storage'
  6. Page({
  7. data: {
  8. isIPhoneX:false,
  9. isIPX: APP.globalData.isIPX,
  10. privacyCheck:false, //用户协议
  11. showDialog:false,
  12. nowDress:'',
  13. showPhoneBtn:false
  14. },
  15. onShow: function (options) {
  16. // this.setData({
  17. // isIPhoneX:UTIL.isIPhoneX()
  18. // })
  19. var that = this;
  20. let url = wx.getStorageSync('dressCode')
  21. that.setData({
  22. nowDress: wx.getStorageSync('dressName')
  23. })
  24. console.log(getApp().globalData.APIURL);
  25. if (url == '' || url == undefined || url == null) {
  26. wx.redirectTo({
  27. url: '../region/region',
  28. })
  29. }else{
  30. //获取code
  31. UTIL.getCOdeFromWX({
  32. complate: (code) => {
  33. //获取openId
  34. //console.log('aaaa');
  35. that.getOpenIdFromFW(code);
  36. }
  37. });
  38. }
  39. // this.automaticLogin()
  40. //this.getUserInfo()
  41. //this.getPhoneNumber()
  42. },
  43. goRegion(){
  44. wx.navigateTo({
  45. url: '/pages/user/region/region',
  46. })
  47. },
  48. /**
  49. * 从服务端获取openId
  50. */
  51. getOpenIdFromFW(code) {
  52. let sendData = {
  53. code: code
  54. }
  55. //console.log(wx.getStorageSync('dressCode')+API.URL_GET_OPENID);
  56. UTIL.httpRequestNoneDetal(API.URL_GET_OPENID, sendData, "POST", {
  57. success: (res) => {
  58. //console.log(res);
  59. if (res.code == API.SUCCESS_CODE) {
  60. // UTIL.showToastNoneIcon("openId:" + res._data.openid);
  61. if(res.token){
  62. wx.setStorageSync('token', res.token);
  63. wx.setStorageSync('openId', res.data.openId);
  64. wx.setStorageSync('sessionKey', res.data.sessionKey);
  65. getApp().globalData.userInfo.token = res.token;
  66. }else{
  67. wx.setstorageSync('openId', res.data.openId);
  68. wx.setStorageSync('sessionKey', res.data.sessionkey);
  69. this.setData({showPhoneBtn:true})
  70. }
  71. } else {
  72. //未获取到openId
  73. // wx.setStorageSync('openId', res.data.openId);
  74. // wx.setStorageSync('sessionKey', res.data.sessionKey);
  75. this.setData({showPhoneBtn:true})
  76. }
  77. }
  78. })
  79. },
  80. goIndex(){
  81. if(this.data.privacyCheck == false){
  82. APP.showToast("请阅读并同意【服务须知】!");
  83. return;
  84. }
  85. wx.reLaunch({
  86. url: '/pages/index/index',
  87. })
  88. },
  89. //自动登录
  90. automaticLogin(){
  91. let automatic = STORAGE.getToken();
  92. let getOpenId = STORAGE.getOpenId();
  93. if(automatic == '' && getOpenId ==''){
  94. //console.log(1);
  95. UTIL.getCOdeFromWX({
  96. complate: (code) => {
  97. let sendData = {
  98. code: code
  99. }
  100. UTIL.httpRequestNoneDetal(API.URL_GET_OPENID, sendData, "POST", {
  101. success: (res) => {
  102. //console.log(res);
  103. if (res.code == API.SUCCESS_CODE) {
  104. wx.reLaunch({
  105. url: '/pages/index/index',
  106. })
  107. } else{
  108. this.getPhoneNumber()
  109. }
  110. }
  111. })
  112. }
  113. });
  114. }else{
  115. // wx.navigateTo({
  116. // url: '/pages/index/index',
  117. // })
  118. }
  119. },
  120. //用户隐私协议选项
  121. checkboxChange: function(res) {
  122. let checkStatus = false;
  123. if(res.detail.value.length!=0){
  124. checkStatus = true;
  125. }else{
  126. checkStatus = false;
  127. }
  128. this.setData({
  129. privacyCheck:checkStatus
  130. })
  131. },
  132. /* 获取用户信息*/
  133. getUserInfo(){
  134. UTIL.httpRequest(API.URL_GET_GETINFO, {method:'GET'}, {
  135. success: (res) => {
  136. if (res.code == API.SUCCESS_CODE) {
  137. this.setData({userInfoObj:res.user})
  138. }
  139. }
  140. })
  141. },
  142. //微信一键登录授权
  143. getPhoneNumber: function(res) {
  144. let that = this;
  145. let {
  146. detail
  147. } = res;
  148. if (!detail.encryptedData) {
  149. //允许授权
  150. APP.showToast("未获取到手机号码,登录失败!");
  151. return;
  152. }else if(this.data.privacyCheck == false){
  153. APP.showToast("请阅读并同意【服务须知】!");
  154. return;
  155. }
  156. //console.log(detail)
  157. let sendData = {
  158. sessionKey:STORAGE.getSessionKey(),
  159. iv:detail.iv,
  160. encryptedData:detail.encryptedData
  161. }
  162. UTIL.httpRequestNoneDetal(API.URL_POST_DECRYPTEDWXDATA, sendData, "POST", {
  163. success: (res) => {
  164. //console.log(res)
  165. if (res.code == API.SUCCESS_CODE) {
  166. let phoneNumber = res.data.phoneNumber;
  167. //微信手机号码绑定
  168. that.wxUserBand(phoneNumber)
  169. // UTIL.showToastNoneIcon("数据共:" + res._data.length + "条");
  170. } else {
  171. //待删
  172. UTIL.showToastNoneIcon(res.msg)
  173. }
  174. },
  175. fail: (res) => {
  176. //console.log("fail");
  177. UTIL.showToastNoneIcon(API.MSG_FAIL_HTTP)
  178. }
  179. })
  180. // UTIL.httpRequest(API.URL_POST_DECRYPTEDWXDATA, sendData,{
  181. // success: (res) => {
  182. // console.log(res);
  183. // // if (res.code == API.SUCCESS_CODE) {
  184. // // let phoneNumber = res.data.phoneNumber;
  185. // // //微信手机号码绑定
  186. // // that.wxUserBand(phoneNumber)
  187. // // // UTIL.showToastNoneIcon("数据共:" + res._data.length + "条");
  188. // // } else {
  189. // // //待删
  190. // // UTIL.showToastNoneIcon(res.msg)
  191. // // }
  192. // },
  193. // fail: (res) => {
  194. // console.log("fail");
  195. // UTIL.showToastNoneIcon(API.MSG_FAIL_HTTP)
  196. // }
  197. // });
  198. },
  199. wxUserBand(phone){
  200. let sendData = {
  201. openId:STORAGE.getOpenId(),
  202. phonenumber:phone
  203. }
  204. //console.log(STORAGE.getOpenId());
  205. UTIL.httpRequestNoneDetal(API.URL_POST_USERBAND, sendData,"POST",{
  206. success: (res) => {
  207. if (res.code == API.SUCCESS_CODE) {
  208. wx.setStorageSync('token', res.token);
  209. wx.reLaunch({
  210. // url: '/pages/user/region/region',
  211. url: '/pages/index/index',
  212. })
  213. }else{
  214. UTIL.showToastNoneIcon(res.msg)
  215. }
  216. },
  217. fail: (res) => {
  218. UTIL.showToastNoneIcon(API.MSG_FAIL_HTTP)
  219. }
  220. });
  221. //
  222. },
  223. //打开协议窗口
  224. openDialog(){
  225. this.setData({showDialog:true})
  226. },
  227. agree(){
  228. this.setData({
  229. privacyCheck:true
  230. })
  231. },
  232. goPhoneLogin(){
  233. wx.navigateTo({
  234. url: '/pages/phoneLogin',
  235. })
  236. }
  237. })