contact.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <script>
  2. import { isString, isToday } from "utils/validate";
  3. import { timeFormat } from "utils";
  4. export default {
  5. name: "LemonContact",
  6. components: {},
  7. data() {
  8. return {};
  9. },
  10. props: {
  11. contact: Object,
  12. simple: Boolean,
  13. timeFormat: {
  14. type: Function,
  15. default(val) {
  16. return timeFormat(val, isToday(val) ? "h:i" : "y/m/d");
  17. }
  18. }
  19. },
  20. render() {
  21. const { contact } = this;
  22. return (
  23. <div
  24. class={["lemon-contact", { "lemon-contact--name-center": this.simple }]}
  25. on-click={e => this._handleClick(e, contact)}
  26. >
  27. <lemon-badge
  28. count={!this.simple ? contact.unread : 0}
  29. class="lemon-contact__avatar"
  30. native-on-click={e => this._handleBubbleClick(e, contact)}
  31. >
  32. <lemon-avatar
  33. size={40}
  34. native-on-click={e => this._handleAvatarClick(e, contact)}
  35. src={contact.avatar}
  36. />
  37. </lemon-badge>
  38. <div class="lemon-contact__inner">
  39. <p class="lemon-contact__label">
  40. <span class="lemon-contact__name">{contact.displayName}</span>
  41. {!this.simple && (
  42. <span class="lemon-contact__time">
  43. {this.timeFormat(contact.lastSendTime)}
  44. </span>
  45. )}
  46. </p>
  47. {!this.simple && (
  48. <p class="lemon-contact__content">
  49. {isString(contact.lastContent) ? (
  50. <span domProps={{ innerHTML: contact.lastContent }} />
  51. ) : (
  52. contact.lastContent
  53. )}
  54. </p>
  55. )}
  56. </div>
  57. </div>
  58. );
  59. },
  60. created() {},
  61. mounted() {},
  62. computed: {},
  63. watch: {},
  64. methods: {
  65. _handleClick(e, data) {
  66. this.$emit("click", data);
  67. },
  68. _handleAvatarClick(e, data) {
  69. e.stopPropagation();
  70. this.$emit("avatar-click", data);
  71. },
  72. _handleBubbleClick(e, data) {
  73. e.stopPropagation();
  74. this.$emit("bubble-click", data);
  75. }
  76. }
  77. };
  78. </script>
  79. <style lang="stylus">
  80. @import '~styles/utils/index'
  81. +b(lemon-contact)
  82. padding 10px 14px
  83. cursor pointer
  84. user-select none
  85. box-sizing border-box
  86. overflow hidden
  87. background #efefef
  88. p
  89. margin 0
  90. +m(active)
  91. background #bebdbd
  92. &:hover:not(.lemon-contact--active)
  93. background #e3e3e3
  94. .el-badge__content
  95. border-color #ddd
  96. +e(avatar)
  97. float left
  98. margin-right 10px
  99. img
  100. display block
  101. .ant-badge-count
  102. display inline-block
  103. padding 0 4px
  104. height 18px
  105. line-height 18px
  106. min-width 18px
  107. top -4px
  108. right 7px
  109. +e(label)
  110. display flex
  111. +e(time)
  112. font-size 12px
  113. line-height 18px
  114. padding-left 6px
  115. color #999
  116. white-space nowrap
  117. +e(name)
  118. display block
  119. width 100%
  120. ellipsis()
  121. +e(content)
  122. font-size 12px
  123. color #999
  124. ellipsis()
  125. img
  126. height 14px
  127. display inline-block
  128. vertical-align middle
  129. margin 0 1px
  130. +m(name-center)
  131. +e(label)
  132. padding-bottom 0
  133. line-height 38px
  134. </style>