sessionItem.vue 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <template>
  2. <div class="chat-item"
  3. :class="item.session_id == curSession ? 'current' : ''"
  4. @click="changeSessionId(item.session_id)">
  5. <!-- <i class="ext">2</i> -->
  6. <img v-if="item.cover_photo" class="user-avatar" :src="item.cover_photo" alt="">
  7. <div v-else class="user-avatar"
  8. :class="`avatar_bg${bgColorNum(item.session_id)}`"
  9. :data-name="item.name.slice(0,2).toUpperCase()">
  10. </div>
  11. <div class="info">
  12. <h3>{{item.name}}</h3>
  13. <!-- <p>外媒:刘鹤现身中美经贸磋商“出人意料”,陆慷:“情理之中”</p> -->
  14. </div>
  15. </div>
  16. </template>
  17. <script>
  18. import { mapState } from 'vuex'
  19. export default {
  20. name: 'msgItem',
  21. props: {
  22. item: {
  23. type: Object
  24. }
  25. },
  26. computed: {
  27. ...mapState(['curSession', 'userId']),
  28. userInfo () {
  29. return this.$store.state.userInfo
  30. }
  31. },
  32. methods: {
  33. changeSessionId (id) {
  34. this.$store.commit('changeSessionId', id)
  35. },
  36. bgColorNum (str) {
  37. if (str.match('-')) {
  38. let num = 0
  39. str.split('-').forEach(e => {
  40. if (e !== this.userId) {
  41. num = e % 9
  42. }
  43. })
  44. return num
  45. } else {
  46. return str % 9
  47. }
  48. }
  49. }
  50. }
  51. </script>
  52. <style lang="scss" scoped>
  53. .chat-item{
  54. padding: 10px 13px 10px 20px;
  55. height: 40px;
  56. cursor: pointer;
  57. position: relative;
  58. @include webkitbox(1);
  59. &.current{
  60. background: #3f424c;
  61. cursor: default;
  62. }
  63. .info{
  64. @include flex(1);
  65. margin-right: 20px;
  66. margin-left: 10px;
  67. h3{
  68. font-size: 13px;
  69. color: #fff;
  70. line-height: 20px;
  71. }
  72. p{
  73. font-size: 12px;
  74. line-height: 20px;
  75. color: #7c8ca5;
  76. @include ellipsis;
  77. }
  78. }
  79. }
  80. </style>