App.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <script>
  2. var md5 = require("./common/md5.js");
  3. export default {
  4. globalData: { //https://stock.xazhima.com/
  5. shareUrl:'https://stock.xazhima.com/api/api.php',
  6. //shareUrl: 'https://guolu.xazhima.com/api/api.php', //开发环境全局接口域名 线上:https://guolu.xazhima.com/
  7. glbalHeight:'',
  8. globalTimestamp: (Date.now()).toString(),
  9. user_id: '',
  10. open_id:'',
  11. user_name:'',
  12. user_headUrl:'',
  13. isAuth:'',
  14. sessionId: '',
  15. cleanPayTime: '',
  16. pageSize: 5, // 列表加载的pageSize
  17. isSetPassword: '',
  18. times:'',
  19. total_times:'',
  20. isAndroid:Boolean,
  21. isIos:false
  22. },
  23. onLaunch: function() {
  24. console.log('App Launch')
  25. let equType = uni.getSystemInfoSync().platform;
  26.  switch(equType){
  27.     case 'android':
  28.        console.log('运行Android上')
  29.        break;
  30.     case 'ios':
  31.        console.log('运行iOS上');
  32. setTimeout(()=>{
  33. getApp().globalData.isIos = true
  34. },100)
  35.        break;
  36.     default:
  37.        console.log('运行在开发者工具上')
  38.        break;
  39. }
  40. },
  41. onShow: function() {
  42. console.log('App Show')
  43. },
  44. onHide: function() {
  45. console.log('App Hide')
  46. },
  47. methods:{
  48. getCodeRabot(res){
  49. uni.request({
  50. url:getApp().globalData.shareUrl, //需要设置为全局
  51. method: 'POST',
  52. header: {
  53. 'content-type': 'application/x-www-form-urlencoded'
  54. },
  55. data: {
  56. method: 'login',
  57. timestamp: getApp().globalData.globalTimestamp, //Date.now()
  58. code: res.code,
  59. sign: md5('login' + getApp().globalData.globalTimestamp),
  60. // invited:'invited'
  61. },
  62. success: res => {
  63. // 通过openid发起会员登录
  64. getApp().globalData.user_id = res.data.msg.id;
  65. getApp().globalData.open_id = res.data.msg.openid;
  66. getApp().globalData.isAuth = res.data.msg.isauth === '0';
  67. getApp().globalData.user_name = res.data.msg.name;
  68. getApp().globalData.user_headUrl = res.data.msg.headimg;
  69. getApp().globalData.times = res.data.msg.times;
  70. getApp().globalData.total_times = res.data.msg.total_times;
  71. }
  72. });
  73. },
  74. loginRabot(){
  75. uni.request({
  76. url: getApp().globalData.shareUrl, //需要设置为全局
  77. method: 'POST',
  78. header: {
  79. 'content-type': 'application/x-www-form-urlencoded'
  80. },
  81. data: {
  82. method: 'login',
  83. timestamp: getApp().globalData.globalTimestamp, //Date.now()
  84. wx_openid: res.data.data.openid,
  85. sign: md5('login' + getApp().globalData.globalTimestamp)
  86. },
  87. success: res => {
  88. if (res.data.code === 200) {
  89. if (res.data.data === 0) {
  90. // 没有会员数据,走默认注册逻辑
  91. } else {
  92. // 获取每个页面需要的memberId
  93. let member_id = res.data.data.member_id;
  94. getApp().globalData.member_id = member_id;
  95. }
  96. }
  97. }
  98. });
  99. }
  100. },
  101. }
  102. </script>
  103. <style>
  104. /*每个页面公共css */
  105. </style>