App.vue 3.7 KB

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