App.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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. user_department:'',
  21. user_real_name:'',
  22. },
  23. onLaunch: function () {
  24. console.log("App Launch");
  25. // let equType = uni.getSystemInfoSync().platform;
  26. //  switch(equType){
  27. //     case 'android':
  28. //        console.log('运行Android上')
  29. // setTimeout(()=>{
  30. // getApp().globalData.isAndroid = true
  31. // },100)
  32. //        break;
  33. //     case 'ios':
  34. //        console.log('运行iOS上');
  35. //        break;
  36. //     default:
  37. //        console.log('运行在开发者工具上')
  38. //        break;
  39. // }
  40. this.loginLoad();
  41. },
  42. onShow: function () {
  43. console.log("App Show");
  44. // uni.hideTabBar({})
  45. },
  46. onHide: function () {
  47. console.log("App Hide");
  48. },
  49. methods:{
  50. loginLoad(){
  51. let that = this;
  52. uni.login({
  53. success(res) {
  54. that.loginRequest(res.code)
  55. }
  56. })
  57. },
  58. loginRequest(codeRes){
  59. let that = this;
  60. let md5Sign = md5("method="+'user'+"&timestamp="+getApp().globalData.globalTimestamp+"&secret="+getApp().globalData.secret)
  61. let url = getApp().globalData.shareUrl+'api/api.php'+'?method=user&action=login&timestamp='+getApp().globalData.globalTimestamp +'&sign='+md5Sign
  62. uni.request({
  63. url:url,
  64. method: 'POST',
  65. header: {
  66. 'content-type': 'application/x-www-form-urlencoded'
  67. },
  68. data: {
  69. code:codeRes
  70. },
  71. success: (res) => {
  72. console.log(res)
  73. if(res.data.code === 200){
  74. getApp().globalData.open_id = res.data.data.openid;
  75. getApp().globalData.user_status = res.data.data.status;
  76. getApp().globalData.session_key = res.data.data.session_key
  77. getApp().globalData.user_phone = res.data.data.phone;
  78. that.$isResolve();
  79. // uni.hideLoading()
  80. }
  81. },
  82. fail: () => {
  83. console.log("连接失败");
  84. }
  85. });
  86. },
  87. }
  88. };
  89. </script>
  90. <style>
  91. /*每个页面公共css */
  92. @import '@/common/uni.css';
  93. page {
  94. height: 100%;
  95. }
  96. *{touch-action: none;}
  97. .display-flex-start {
  98. display: flex;
  99. align-items: center;
  100. }
  101. .display-flex-end {
  102. display: flex;
  103. justify-content: flex-end;
  104. align-items: center;
  105. }
  106. .display-between {
  107. display: flex;
  108. justify-content: space-between;
  109. }
  110. .display-around {
  111. display: flex;
  112. justify-content: space-around;
  113. }
  114. .display-between-column {
  115. display: flex;
  116. flex-direction: column;
  117. justify-content: space-between;
  118. }
  119. .display-around-column {
  120. display: flex;
  121. flex-direction: column;
  122. justify-content: space-around;
  123. }
  124. .display-evenly-column {
  125. display: flex;
  126. flex-direction: column;
  127. justify-content: space-evenly;
  128. }
  129. .display-wrap {
  130. display: flex;
  131. flex-wrap: wrap;
  132. }
  133. .items-center {
  134. align-items: center;
  135. }
  136. .margin-top-10{
  137. margin-top: 10%;
  138. }
  139. .shareParent {
  140. width: 100%;
  141. height: 100%;
  142. position: fixed;
  143. }
  144. .margin-right-10 {
  145. margin-right: 10rpx;
  146. }
  147. .margin-top-1 {
  148. margin-top: 1%;
  149. }
  150. .margin-right-0 {
  151. margin-right: 0!important;
  152. }
  153. </style>