App.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. <script>
  2. import md5 from '@/common/md5.js';
  3. export default {
  4. globalData: {
  5. shareUrl: "https://ng.xazhima.com/",
  6. //shareUrl:"https://kgwxxcx.xixianxinqu.gov.cn/1026airqt/",
  7. globalTimestamp: Date.now().toString(),
  8. secret: "AirQK_weichat_app_zhima",
  9. selectedIndex:0,
  10. isSider:false,
  11. user_id: '',
  12. open_id:'',
  13. user_status:'',
  14. user_name:'',
  15. user_phone:'',
  16. user_headUrl:'',
  17. globalAuth:false,
  18. session_key: '',
  19. isAndroid:false
  20. },
  21. onLaunch: function () {
  22. console.log("App Launch");
  23. // let equType = uni.getSystemInfoSync().platform;
  24. //  switch(equType){
  25. //     case 'android':
  26. //        console.log('运行Android上')
  27. // setTimeout(()=>{
  28. // getApp().globalData.isAndroid = true
  29. // },100)
  30. //        break;
  31. //     case 'ios':
  32. //        console.log('运行iOS上');
  33. //        break;
  34. //     default:
  35. //        console.log('运行在开发者工具上')
  36. //        break;
  37. // }
  38. this.loginLoad();
  39. },
  40. onShow: function () {
  41. console.log("App Show");
  42. // uni.hideTabBar({})
  43. },
  44. onHide: function () {
  45. console.log("App Hide");
  46. },
  47. methods:{
  48. loginLoad(){
  49. let that = this;
  50. uni.login({
  51. success(res) {
  52. console.log(res)
  53. that.loginRequest(res.code)
  54. }
  55. })
  56. },
  57. loginRequest(codeRes){
  58. let md5Sign = md5("method="+'user'+"&timestamp="+getApp().globalData.globalTimestamp+"&secret="+getApp().globalData.secret)
  59. let url = getApp().globalData.shareUrl+'api/api.php'+'?method=user&action=login&timestamp='+getApp().globalData.globalTimestamp +'&sign='+md5Sign
  60. uni.request({
  61. url:url,
  62. method: 'POST',
  63. header: {
  64. 'content-type': 'application/x-www-form-urlencoded'
  65. },
  66. data: {
  67. code:codeRes
  68. },
  69. success: (res) => {
  70. console.log(res)
  71. if(res.data.code === 200){
  72. // getApp().globalData.session_key = res.data.data.session_key;
  73. getApp().globalData.open_id = res.data.data.openid;
  74. getApp().globalData.user_status = res.data.data.status;
  75. this.getUserInfo(getApp().globalData.open_id)
  76. // getApp().globalData.globalAuth = res.data.data.status ? true : false;
  77. // getApp().globalData.user_phone = res.data.data.phone;
  78. // uni.hideLoading()
  79. }
  80. },
  81. fail: () => {
  82. console.log("连接失败");
  83. }
  84. });
  85. },
  86. getUserInfo(openid) {
  87. let md5Sign = md5(
  88. "method=" +
  89. "user" +
  90. "&timestamp=" +
  91. getApp().globalData.globalTimestamp +
  92. "&secret=" +
  93. getApp().globalData.secret
  94. );
  95. let url =
  96. getApp().globalData.shareUrl +
  97. "api/api.php" +
  98. "?method=user&action=info_by_openid&timestamp=" +
  99. getApp().globalData.globalTimestamp +
  100. "&sign=" +
  101. md5Sign;
  102. uni.request({
  103. url: url,
  104. method: "POST",
  105. header: {
  106. "content-type": "application/x-www-form-urlencoded",
  107. },
  108. data: {
  109. openid:openid,
  110. },
  111. success: (res) => {
  112. if (res.data.code === 200) {
  113. }
  114. },
  115. fail: () => {
  116. console.log("连接失败");
  117. },
  118. });
  119. },
  120. }
  121. };
  122. </script>
  123. <style>
  124. /*每个页面公共css */
  125. @import '@/common/uni.css';
  126. page {
  127. height: 100%;
  128. }
  129. .display-flex-start {
  130. display: flex;
  131. align-items: center;
  132. }
  133. .display-flex-end {
  134. display: flex;
  135. justify-content: flex-end;
  136. align-items: center;
  137. }
  138. .display-between {
  139. display: flex;
  140. justify-content: space-between;
  141. }
  142. .display-around {
  143. display: flex;
  144. justify-content: space-around;
  145. }
  146. .display-between-column {
  147. display: flex;
  148. flex-direction: column;
  149. justify-content: space-between;
  150. }
  151. .display-around-column {
  152. display: flex;
  153. flex-direction: column;
  154. justify-content: space-around;
  155. }
  156. .display-wrap {
  157. display: flex;
  158. flex-wrap: wrap;
  159. }
  160. .items-center {
  161. align-items: center;
  162. }
  163. </style>