index.vue 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <template>
  2. <div class="chat-at">
  3. <div class="bar-wrap" v-bar>
  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. export default {
  22. name: 'chatAt',
  23. props: {
  24. curInd: {
  25. type: Number
  26. },
  27. filterList: {
  28. type: Array
  29. }
  30. },
  31. watch: {
  32. curInd (val) {
  33. this.scrollIntoView()
  34. }
  35. },
  36. methods: {
  37. atPerson (key) {
  38. let item = this.filterList[key]
  39. this.$emit('atperson', item.nick_name)
  40. },
  41. scrollIntoView () {
  42. let dom = this.$refs.container.children[this.curInd]
  43. if (dom && dom.scrollIntoView) {
  44. dom.scrollIntoView({
  45. behavior: 'smooth',
  46. block: 'center',
  47. inline: 'nearest'
  48. })
  49. }
  50. }
  51. }
  52. }
  53. </script>
  54. <style lang="scss" scoped>
  55. .chat-at {
  56. position: absolute;
  57. top: -100px;
  58. left: 2px;
  59. right: 2px;
  60. height: 100px;
  61. background-color: #ffffff;
  62. border-top-left-radius: 4px;
  63. border-top-right-radius: 4px;
  64. box-shadow: 0 0 2px rgba($color: #3a3a3a, $alpha: .3);
  65. }
  66. .bar-wrap{
  67. height: 100px;
  68. }
  69. .item{
  70. padding: 6px 8px;
  71. line-height: 20px;
  72. cursor: pointer;
  73. &.active{
  74. background-color: #eeeeee;
  75. }
  76. &:hover{
  77. background-color: #eeeeee;
  78. }
  79. }
  80. .avatar{
  81. display: inline-block;
  82. vertical-align: middle;
  83. margin-right: 10px;
  84. width: 20px;
  85. height: 20px;
  86. border-radius: 2px;
  87. line-height: 20px;
  88. text-align: center;
  89. color: #ffffff;
  90. font-size: 12px;
  91. }
  92. .name{
  93. font-size: 12px;
  94. color: #333333;
  95. display: inline-block;
  96. }
  97. </style>