App.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. <script>
  2. import md5 from '@/common/md5.js';
  3. export default {
  4. globalData: {
  5. //shareUrl: "https://heater.xazhima.com/", 测试地址
  6. shareUrl:"https://h.xayuanju.com/",
  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.setStorageSync('openId', res.data.data.openid);
  95. // uni.hideLoading()
  96. }
  97. },
  98. fail: () => {
  99. console.log("连接失败");
  100. }
  101. });
  102. },
  103. }
  104. };
  105. </script>
  106. <style lang="scss">
  107. /*每个页面公共css */
  108. @import url("/components/gaoyia-parse/parse.css");
  109. @import '@/common/uni.css';
  110. page {
  111. height: 100%;
  112. }
  113. .display-flex-start {
  114. display: flex;
  115. align-items: center;
  116. }
  117. .display-flex-end {
  118. display: flex;
  119. justify-content: flex-end;
  120. align-items: center;
  121. }
  122. .display-between {
  123. display: flex;
  124. justify-content: space-between;
  125. }
  126. .display-around {
  127. display: flex;
  128. justify-content: space-around;
  129. }
  130. .display-between-column {
  131. display: flex;
  132. flex-direction: column;
  133. justify-content: space-between;
  134. }
  135. .display-around-column {
  136. display: flex;
  137. flex-direction: column;
  138. justify-content: space-around;
  139. }
  140. .display-wrap {
  141. display: flex;
  142. flex-wrap: wrap;
  143. }
  144. .items-center {
  145. align-items: center;
  146. }
  147. .uni-popup__wrapper.uni-custom.center .uni-popup__wrapper-box {
  148. max-height: 50%!important;
  149. }
  150. </style>