index.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. Self.requestMyGameList(function(gameList){
  27. getApp().globalData.gameList = gameList;
  28. Self.goToHome();
  29. });
  30. },
  31. methods: {
  32. login(callback)
  33. {
  34. let api = 'login?'
  35. let openid = this.getQueryString('openid');
  36. // let timestamp = this.getQueryString('timestamp');
  37. // let sign = this.getQueryString('sign');
  38. getApp().globalData.openid = openid;
  39. let url = this.home_url+api+'open_id='+openid;
  40. // console.log('url=',url);
  41. uni.request({
  42. url:url,
  43. method:'GET',
  44. success: (res) => {
  45. return callback(res);
  46. },
  47. fail: (res) => {
  48. return callback('fail');
  49. }
  50. })
  51. },
  52. getQueryString: function(name) {
  53. const reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');
  54. const search = window.location.search.split('?')[1] || '';
  55. const r = search.match(reg) || [];
  56. return r[2];
  57. },
  58. requestMyGameList(callback)
  59. {
  60. let url = this.home_url+'getGameList?';
  61. console.log('gameList_url=',url);
  62. uni.request({
  63. url:url,
  64. method:'GET',
  65. success: (res) => {
  66. let gameList = res.data.list;
  67. // console.log(gameList)
  68. return callback(gameList);
  69. },
  70. fail: (res) => {
  71. return callback('fail');
  72. }
  73. })
  74. // uni.request({
  75. // header: {
  76. // 'Content-Type': 'application/x-www-form-urlencoded'
  77. // },
  78. // url: url, //仅为示例,并非真实接口地址。
  79. // method: 'POST',
  80. // data: {
  81. // url: _url
  82. // },
  83. // dataType:'json',
  84. // success: (res) => {
  85. // console.log('gameList=',res)
  86. // let gameList = res.data.list;
  87. // // console.log(gameList)
  88. // return callback(gameList);
  89. // }
  90. // });
  91. },
  92. goToHome()
  93. {
  94. uni.hideLoading();
  95. uni.navigateTo({
  96. url: '/pages/Home/Home',
  97. });
  98. }
  99. }
  100. }
  101. </script>
  102. <style>
  103. </style>