StoreHeader.vue 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <template>
  2. <div class="store-share-header">
  3. <div class="wrap">
  4. <div class="img">
  5. <img :src="storeInfo.logoUrl" alt="">
  6. </div>
  7. <div class="title">
  8. <h1>{{storeInfo.storeName}}</h1>
  9. <p>{{storeInfo.description | descFilter}}</p>
  10. </div>
  11. </div>
  12. </div>
  13. </template>
  14. <script>
  15. let getRealLen = function (str) {
  16. let len = 0
  17. for (let i = 0; i < str.length; i++) {
  18. if (str.charCodeAt(i) > 127 || str.charCodeAt(i) === 94) {
  19. len += 2
  20. } else {
  21. len++
  22. }
  23. }
  24. return len
  25. }
  26. let cutOutString = function (str, len) {
  27. for (let i = 1; i <= str.length; i++) {
  28. if (getRealLen(str.substr(0, i)) > len) {
  29. str = str.substr(0, i - 1)
  30. break
  31. }
  32. }
  33. return str
  34. }
  35. export default {
  36. computed: {
  37. storeInfo () {
  38. return this.$store.state.shop.storeInfo.store.data
  39. }
  40. },
  41. filters: {
  42. descFilter: function (val) {
  43. return getRealLen(val) > 78 ? cutOutString(val, 78) + '...' : val
  44. }
  45. }
  46. }
  47. </script>
  48. <style lang="scss" scoped>
  49. .store-share-header {
  50. height: 1.9rem;
  51. background: #272a32;
  52. padding-top: .18rem;
  53. .wrap {
  54. height: 1.72rem;
  55. width: 7.16rem;
  56. margin: 0 auto;
  57. background: url('/images/mobile/@2x/shareStore/background@2x.png') no-repeat;
  58. background-size: cover;
  59. padding: .2rem 0 0 .4rem;
  60. > div {
  61. display: inline-block;
  62. vertical-align: middle;
  63. &.img {
  64. width: 1.24rem;
  65. height: 1.24rem;
  66. text-align: center;
  67. line-height: 1.24rem;
  68. border-radius: 2px;
  69. background: #fff;
  70. img {
  71. max-width: 1.24rem;
  72. max-height: 1.24rem;
  73. }
  74. }
  75. &.title {
  76. margin-left: .44rem;
  77. width: 5rem;
  78. h1 {
  79. font-size: .36rem;
  80. color: #fff;
  81. overflow: hidden;
  82. text-overflow: ellipsis;
  83. white-space: nowrap;
  84. width: 4.5rem;
  85. }
  86. p {
  87. font-size: .24rem;
  88. color: #fff;
  89. margin-top: .2rem;
  90. line-height: .32rem;
  91. overflow: hidden;
  92. max-height: .64rem;
  93. }
  94. }
  95. }
  96. }
  97. }
  98. </style>