App.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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.session_key = res.data.data.session_key;
  75. getApp().globalData.open_id = res.data.data.openid;
  76. getApp().globalData.user_status = res.data.data.status;
  77. that.$isResolve();
  78. // getApp().globalData.globalAuth = res.data.data.status ? true : false;
  79. // getApp().globalData.user_phone = res.data.data.phone;
  80. // uni.hideLoading()
  81. }
  82. },
  83. fail: () => {
  84. console.log("连接失败");
  85. }
  86. });
  87. },
  88. }
  89. };
  90. </script>
  91. <style>
  92. /*每个页面公共css */
  93. @import '@/common/uni.css';
  94. page {
  95. height: 100%;
  96. }
  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-wrap {
  125. display: flex;
  126. flex-wrap: wrap;
  127. }
  128. .items-center {
  129. align-items: center;
  130. }
  131. </style>