contact.vue 3.2 KB

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