App.vue 4.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. if (expandParam.isUse != 1){
  36. console.log('获取到的拓客端参数',expandParam)
  37. if (new Date().getTime() <= expandParam.timestamp){
  38. if (isNew){
  39. //登录成功,且是新用户,触发首页的自定义事件
  40. uni.$emit("loginSuccess")
  41. }else {
  42. that.$api.addRecordForAttach({
  43. ...expandParam,
  44. isNew:0,
  45. isBindSuccess:0,
  46. }).then(res=>{
  47. expandParam.isUse = 1
  48. uni.setStorageSync('expandParam', expandParam)
  49. console.log('+++++++++老用户,扫码推广失败记录!++++++++++++++++')
  50. })
  51. // uni.removeStorageSync('expandParam');
  52. }
  53. }else {
  54. uni.showModal({
  55. title: '温馨提示',
  56. content: ' 当前二维码已过期,请重新扫码',
  57. showCancel:false,
  58. success: function (res) {
  59. if (res.confirm) {
  60. console.log('用户点击确定');
  61. } else if (res.cancel) {
  62. console.log('用户点击取消');
  63. }
  64. }
  65. });
  66. expandParam.isUse = 1
  67. uni.setStorageSync('expandParam', expandParam)
  68. // uni.removeStorageSync('expandParam');
  69. }
  70. }
  71. }
  72. //用户扫码技师端进入小程序,携带的参数。 暂无操作
  73. let promotionParam = uni.getStorageSync('promotionParam')
  74. })
  75. },
  76. })
  77. },
  78. onHide: function () {
  79. console.log('App Hide')
  80. }
  81. }
  82. </script>