App.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <style lang="scss">
  2. /* 注意要写在第一行,同时给style标签加入lang="scss"属性 */
  3. @import "uview-ui/index.scss";
  4. </style>
  5. <script>
  6. export default {
  7. onLaunch: function () {
  8. console.log('App Launch')
  9. },
  10. onShow: function () {
  11. console.log('App Show 小程序显示了+++++++++++++++++++++++')
  12. let that = this;
  13. wx.login({
  14. success(re) {
  15. that.$api.wxLogin({code: re.code}).then(res => {
  16. console.log('++++++++++登录返回了++++++++++++++++', res)
  17. uni.setStorageSync('userInfo', res.data.data.userInfo)
  18. uni.setStorageSync('accessToken', res.data.data.access_token)
  19. let isNew = res.data.data.isNew
  20. uni.removeStorageSync('parent_member_id');
  21. //用户点击用户分享进入小程序,进行绑定操作
  22. let shareUserId = uni.getStorageSync('shareUserId')
  23. if (shareUserId) {
  24. that.$api.scanCode({
  25. openId: res.data.data.userInfo.otherId,
  26. memberId: shareUserId
  27. }).then(res => {
  28. console.log('用户分享用户绑定成功', res)
  29. uni.removeStorageSync('shareUserId');
  30. })
  31. }
  32. //用户扫码拓客端进入小程序,携带的参数,进行绑定操作
  33. let expandParam = uni.getStorageSync('expandParam')
  34. if (expandParam) {
  35. console.log('获取到的拓客端参数',expandParam)
  36. if (new Date().getTime() <= expandParam.timestamp){
  37. if (isNew){
  38. //登录成功,且是新用户,触发首页的自定义事件
  39. uni.$emit("loginSuccess")
  40. //用户扫码拓客端进入小程序
  41. // that.$api.userBindMember(
  42. // {
  43. // ...expandParam,
  44. // memberId: res.data.data.userInfo.id
  45. // }
  46. // ).then(res1 => {
  47. // console.log('拓客端推广用户绑定成功!')
  48. //
  49. // that.$api.addRecordForAttach({
  50. // ...expandParam,
  51. // isNew:1,
  52. // isBindSuccess:1,
  53. // }).then(res=>{
  54. // console.log('+++++++++新用户,扫码推广成功记录!++++++++++++++++')
  55. // })
  56. //
  57. // uni.removeStorageSync('expandParam');
  58. // }).catch(err=>{
  59. //
  60. // that.$api.addRecordForAttach({
  61. // ...expandParam,
  62. // isNew:1,
  63. // isBindSuccess:0,
  64. // }).then(res=>{
  65. // console.log('+++++++++新用户,扫码推广失败记录!++++++++++++++++')
  66. // })
  67. //
  68. // uni.removeStorageSync('expandParam');
  69. // })
  70. }else {
  71. that.$api.addRecordForAttach({
  72. ...expandParam,
  73. isNew:0,
  74. isBindSuccess:0,
  75. }).then(res=>{
  76. console.log('+++++++++老用户,扫码推广失败记录!++++++++++++++++')
  77. })
  78. uni.removeStorageSync('expandParam');
  79. }
  80. }else {
  81. uni.showModal({
  82. title: '温馨提示',
  83. content: ' 当前二维码已过期,请重新扫码',
  84. showCancel:false,
  85. success: function (res) {
  86. if (res.confirm) {
  87. console.log('用户点击确定');
  88. } else if (res.cancel) {
  89. console.log('用户点击取消');
  90. }
  91. }
  92. });
  93. uni.removeStorageSync('expandParam');
  94. }
  95. }
  96. //用户扫码技师端进入小程序,携带的参数。 暂无操作
  97. let promotionParam = uni.getStorageSync('promotionParam')
  98. })
  99. },
  100. })
  101. },
  102. onHide: function () {
  103. console.log('App Hide')
  104. }
  105. }
  106. </script>