App.vue 3.1 KB

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