index.vue 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <template>
  2. <div class="chat-at">
  3. <div class="bar-wrap">
  4. <div ref="container">
  5. <div class="item"
  6. v-for="(item, key) in filterList"
  7. :key="key"
  8. @click="atPerson(key)"
  9. :class="{'active': key === curInd}"
  10. >
  11. <div class="avatar" :class="`avatar_bg${item.user_id % 9}`">
  12. {{item.nick_name.slice(0,2).toUpperCase()}}
  13. </div>
  14. <span class="name">{{item.nick_name}}</span>
  15. </div>
  16. </div>
  17. </div>
  18. </div>
  19. </template>
  20. <script>
  21. import { mapState } from 'vuex'
  22. export default {
  23. name: 'chatAt',
  24. props: {
  25. curInd: {
  26. type: Number
  27. },
  28. filterList: {
  29. type: Array
  30. }
  31. },
  32. computed: {
  33. ...mapState([
  34. 'userId'
  35. ])
  36. },
  37. watch: {
  38. curInd (val) {
  39. this.scrollIntoView()
  40. }
  41. },
  42. methods: {
  43. atPerson (key) {
  44. let item = this.filterList[key]
  45. this.$emit('atperson', item.user_name)
  46. },
  47. scrollIntoView () {
  48. let dom = this.$refs.container.children[this.curInd]
  49. if (dom && dom.scrollIntoView) {
  50. dom.scrollIntoView({
  51. behavior: 'smooth',
  52. block: 'center',
  53. inline: 'nearest'
  54. })
  55. }
  56. }
  57. }
  58. }
  59. </script>
  60. <style lang="scss" scoped>
  61. .chat-at {
  62. position: absolute;
  63. top: -100px;
  64. left: 2px;
  65. right: 2px;
  66. height: 100px;
  67. background-color: #ffffff;
  68. border-top-left-radius: 4px;
  69. border-top-right-radius: 4px;
  70. box-shadow: 0 0 2px rgba($color: #3a3a3a, $alpha: .3);
  71. }
  72. .bar-wrap{
  73. height: 100%;
  74. overflow-y: scroll;
  75. &::-webkit-scrollbar {
  76. width: 8px;
  77. height: 6px;
  78. }
  79. &::-webkit-scrollbar-thumb {
  80. border-radius: 3px;
  81. -moz-border-radius: 3px;
  82. -webkit-border-radius: 3px;
  83. background-color: transparent;
  84. }
  85. &::-webkit-scrollbar-track {
  86. background-color: transparent;
  87. }
  88. &:hover{
  89. &::-webkit-scrollbar-thumb {
  90. background-color: rgba($color: #c3c3c3, $alpha: 0.3);
  91. }
  92. }
  93. }
  94. .item{
  95. padding: 6px 8px;
  96. line-height: 20px;
  97. cursor: pointer;
  98. &.active{
  99. background-color: #eeeeee;
  100. }
  101. &:hover{
  102. background-color: #eeeeee;
  103. }
  104. }
  105. .avatar{
  106. display: inline-block;
  107. vertical-align: middle;
  108. margin-right: 10px;
  109. width: 20px;
  110. height: 20px;
  111. border-radius: 2px;
  112. line-height: 20px;
  113. text-align: center;
  114. color: #ffffff;
  115. font-size: 12px;
  116. }
  117. .name{
  118. font-size: 12px;
  119. color: #333333;
  120. display: inline-block;
  121. }
  122. </style>