index.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <template>
  2. </template>
  3. <script>
  4. import md5 from "../../common/md5.js";
  5. export default {
  6. data() {
  7. return {
  8. }
  9. },
  10. onLoad() {
  11. uni.showLoading({
  12. title: '加载中'
  13. });
  14. let Self = this;
  15. // console.log('login=',res);
  16. // if(uni.getSystemInfoSync().platform === 'devtools')
  17. // {           
  18. //   console.log('H5') 
  19. // let openid = this.getQueryString('openid');
  20. // getApp().globalData.openid = openid;              
  21. // }else{                          
  22. //   console.log('运行在手机中') 
  23. // let openid = 'asds';
  24. // getApp().globalData.openid = openid;               
  25. // }
  26. let openid = this.getQueryString('openid');
  27. getApp().globalData.openid = openid; 
  28. Self.requestMyGameList(function(gameList){
  29. getApp().globalData.gameList = gameList;
  30. Self.goToHome();
  31. });
  32. },
  33. methods: {
  34. login(callback)
  35. {
  36. let api = 'login?'
  37. let openid = this.getQueryString('openid');
  38. // let timestamp = this.getQueryString('timestamp');
  39. // let sign = this.getQueryString('sign');
  40. getApp().globalData.openid = openid;
  41. let url = this.home_url+api+'open_id='+openid;
  42. // console.log('url=',url);
  43. uni.request({
  44. url:url,
  45. method:'GET',
  46. success: (res) => {
  47. return callback(res);
  48. },
  49. fail: (res) => {
  50. return callback('fail');
  51. }
  52. })
  53. },
  54. getQueryString: function(name) {
  55. const reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');
  56. const search = window.location.search.split('?')[1] || '';
  57. const r = search.match(reg) || [];
  58. return r[2];
  59. },
  60. requestMyGameList(callback)
  61. {
  62. let url = this.home_url+'getGameList?';
  63. console.log('gameList_url=',url);
  64. uni.request({
  65. url:url,
  66. method:'GET',
  67. success: (res) => {
  68. let gameList = res.data.list;
  69. // console.log(gameList)
  70. return callback(gameList);
  71. },
  72. fail: (res) => {
  73. return callback('fail');
  74. }
  75. })
  76. // uni.request({
  77. // header: {
  78. // 'Content-Type': 'application/x-www-form-urlencoded'
  79. // },
  80. // url: url, //仅为示例,并非真实接口地址。
  81. // method: 'POST',
  82. // data: {
  83. // url: _url
  84. // },
  85. // dataType:'json',
  86. // success: (res) => {
  87. // console.log('gameList=',res)
  88. // let gameList = res.data.list;
  89. // // console.log(gameList)
  90. // return callback(gameList);
  91. // }
  92. // });
  93. },
  94. goToHome()
  95. {
  96. uni.hideLoading();
  97. uni.navigateTo({
  98. url: '/pages/Home/Home',
  99. });
  100. }
  101. }
  102. }
  103. </script>
  104. <style>
  105. </style>