uni-cart-fix.vue 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <template>
  2. <view class="cart-fix" @click="toCart">
  3. <!-- <u-image width="70rpx" height="70rpx" src="/static/cart.png"></u-image>
  4. <u-badge absolute :offset="[15,10]" type="error" :count="count"></u-badge> -->
  5. <drag-button
  6. :isDock="true"
  7. :existTabBar="true"
  8. :dragPic="dragPic"
  9. :badge="count"
  10. @btnClick="toCart"
  11. @btnTouchstart="btnTouchstart"
  12. @btnTouchend="btnTouchend"
  13. />
  14. </view>
  15. </template>
  16. <script>
  17. import dragButton from "@/components/drag-button/drag-button.vue";
  18. import {checkLogin} from '@/api/login.js'
  19. export default {
  20. components: {
  21. dragButton
  22. },
  23. props:{
  24. closeCurPage:{
  25. type: Boolean,
  26. default: false
  27. },
  28. dragPic: {
  29. type: String,
  30. default: ''
  31. }
  32. },
  33. computed: {
  34. count() {
  35. return this.$store.state.vuex_cartNums
  36. }
  37. },
  38. data() {
  39. return {
  40. hasLogin: false
  41. }
  42. },
  43. mounted() {
  44. // 是否登录
  45. checkLogin().then(res => {
  46. console.log(res,'checkLogin')
  47. this.hasLogin = res.status == 200
  48. })
  49. },
  50. methods: {
  51. toCart() {
  52. let _this = this
  53. if(!this.hasLogin) {
  54. uni.showModal({
  55. title: '提示',
  56. content: '您尚未登录或登录已过期,请先进行登录',
  57. success (res) {
  58. if (res.confirm) {
  59. uni.navigateTo({
  60. url: '/pages/login/login'
  61. });
  62. } else if (res.cancel) {
  63. console.log('用户点击取消');
  64. }
  65. }
  66. });
  67. return
  68. }
  69. if(_this.closeCurPage){
  70. uni.redirectTo({
  71. url:"/pagesA/cart/cart"
  72. })
  73. }else{
  74. uni.navigateTo({
  75. url:"/pagesA/cart/cart"
  76. })
  77. }
  78. },
  79. btnClick() {
  80. console.log('btnClick');
  81. },
  82. btnTouchstart() {
  83. console.log('btnTouchstart');
  84. },
  85. btnTouchend() {
  86. console.log('btnTouchend');
  87. },
  88. },
  89. }
  90. </script>
  91. <style lang="scss">
  92. .cart-fix{
  93. position: fixed;
  94. z-index: 100000;
  95. // background: rgba($color: #ffffff, $alpha: 0.7);
  96. // padding: 10upx;
  97. // border-radius: 100%;
  98. bottom: 40%;
  99. right: 2%;
  100. // box-shadow: 3upx 3upx 8upx #ccc;
  101. }
  102. </style>