App.vue 3.5 KB

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