App.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. .display-flex-start {
  97. display: flex;
  98. align-items: center;
  99. }
  100. .display-flex-end {
  101. display: flex;
  102. justify-content: flex-end;
  103. align-items: center;
  104. }
  105. .display-between {
  106. display: flex;
  107. justify-content: space-between;
  108. }
  109. .display-around {
  110. display: flex;
  111. justify-content: space-around;
  112. }
  113. .display-between-column {
  114. display: flex;
  115. flex-direction: column;
  116. justify-content: space-between;
  117. }
  118. .display-around-column {
  119. display: flex;
  120. flex-direction: column;
  121. justify-content: space-around;
  122. }
  123. .display-wrap {
  124. display: flex;
  125. flex-wrap: wrap;
  126. }
  127. .items-center {
  128. align-items: center;
  129. }
  130. </style>