App.vue 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <script>
  2. import md5 from '@/common/md5.js';
  3. export default {
  4. globalData: {
  5. //shareUrl: 'https://gdoctor.xazhima.com/api/v1.0/api.php', //开发环境全局接口域名 线上:https://guolu.xazhima.com/
  6. shareUrl: "https://kiq.xazhima.com/",
  7. globalTimestamp: Date.now().toString(),
  8. secret: "AirQK_weichat_app_zhima",
  9. selectedIndex:0,
  10. user_id: '',
  11. open_id:'',
  12. user_status:'',
  13. user_name:'',
  14. user_phone:'',
  15. user_headUrl:'',
  16. isAuth:false,
  17. session_key: '',
  18. },
  19. onLaunch: function () {
  20. console.log("App Launch");
  21. this.loginLoad();
  22. },
  23. onShow: function () {
  24. console.log("App Show");
  25. },
  26. onHide: function () {
  27. console.log("App Hide");
  28. },
  29. methods:{
  30. loginLoad(){
  31. let that = this;
  32. uni.login({
  33. success(res) {
  34. that.loginRequest(res.code)
  35. }
  36. })
  37. },
  38. loginRequest(codeRes){
  39. let md5Sign = md5("method="+'user'+"&timestamp="+getApp().globalData.globalTimestamp+"&secret="+getApp().globalData.secret)
  40. let url = getApp().globalData.shareUrl+'api/api.php'+'?method=user&source=user&action=login&timestamp='+getApp().globalData.globalTimestamp +'&sign='+md5Sign
  41. uni.request({
  42. url:url,
  43. method: 'POST',
  44. header: {
  45. 'content-type': 'application/x-www-form-urlencoded'
  46. },
  47. data: {
  48. code:codeRes
  49. },
  50. success: (res) => {
  51. console.log(res)
  52. if(res.data.code === 200){
  53. getApp().globalData.session_key = res.data.data.session_key;
  54. getApp().globalData.open_id = res.data.data.openid;
  55. getApp().globalData.user_status = res.data.data.status;
  56. getApp().globalData.user_phone = res.data.data.phone;
  57. }
  58. },
  59. fail: () => {
  60. console.log("连接失败");
  61. }
  62. });
  63. },
  64. }
  65. };
  66. </script>
  67. <style>
  68. /*每个页面公共css */
  69. .display-flex-start {
  70. display: flex;
  71. align-items: center;
  72. }
  73. .display-flex-end {
  74. display: flex;
  75. justify-content: flex-end;
  76. align-items: center;
  77. }
  78. .display-between {
  79. display: flex;
  80. justify-content: space-between;
  81. }
  82. .display-around {
  83. display: flex;
  84. justify-content: space-around;
  85. }
  86. .display-between-column {
  87. display: flex;
  88. flex-direction: column;
  89. justify-content: space-between;
  90. }
  91. .display-around-column {
  92. display: flex;
  93. flex-direction: column;
  94. justify-content: space-around;
  95. }
  96. .display-wrap {
  97. display: flex;
  98. flex-wrap: wrap;
  99. }
  100. .items-center {
  101. align-items: center;
  102. }
  103. </style>