basic.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. <script>
  2. export default {
  3. name: "lemonMessageBasic",
  4. props: {
  5. message: {
  6. type: Object,
  7. default: () => {
  8. return {};
  9. }
  10. },
  11. timeFormat: {
  12. type: Function,
  13. default: () => ""
  14. },
  15. reverse: Boolean,
  16. hiddenTitle: Boolean
  17. },
  18. data() {
  19. return {};
  20. },
  21. render() {
  22. const { fromUser, status, sendTime } = this.message;
  23. return (
  24. <div
  25. class={[
  26. "lemon-message",
  27. {
  28. "lemon-message--reverse": this.reverse,
  29. "lemon-message--hidden-title": this.hiddenTitle
  30. }
  31. ]}
  32. >
  33. <div class="lemon-message__avatar">
  34. <lemon-avatar
  35. size={36}
  36. shape="square"
  37. src={fromUser.avatar}
  38. on-click={() => {
  39. console.log("message avatar click");
  40. }}
  41. />
  42. </div>
  43. <div class="lemon-message__inner">
  44. <div class="lemon-message__title">
  45. <span
  46. on-click={() => {
  47. console.log("message displayname click");
  48. }}
  49. >
  50. {fromUser.displayName}
  51. </span>
  52. <span class="lemon-message__time">{this.timeFormat(sendTime)}</span>
  53. </div>
  54. <div
  55. class="lemon-message__content"
  56. on-click={() => {
  57. console.log("message content click");
  58. }}
  59. >
  60. {this.useScopedSlots("content", this.message)}
  61. </div>
  62. <div class="lemon-message__status">{this._renderStatue(status)}</div>
  63. </div>
  64. </div>
  65. );
  66. },
  67. created() {},
  68. mounted() {},
  69. computed: {},
  70. watch: {},
  71. methods: {
  72. _renderStatue(status) {
  73. if (status == "going") {
  74. return <i class="lemon-icon-loading lemonani-spin" />;
  75. } else if (status == "failed") {
  76. return (
  77. <i
  78. class="lemon-icon-prompt"
  79. title="重发消息"
  80. style={{
  81. color: "#ff2525",
  82. cursor: "pointer"
  83. }}
  84. />
  85. );
  86. }
  87. return;
  88. },
  89. useScopedSlots(name, params, defVnode = "", context = this) {
  90. return context.$scopedSlots[name]
  91. ? context.$scopedSlots[name](params)
  92. : defVnode;
  93. }
  94. }
  95. };
  96. </script>
  97. <style lang="stylus">
  98. @import '~styles/utils/index'
  99. arrow()
  100. content ' '
  101. position absolute
  102. top 6px
  103. width 0
  104. height 0
  105. border 4px solid transparent
  106. +b(lemon-message)
  107. display flex
  108. padding 10px 0
  109. +e(time)
  110. color #bbb
  111. padding 0 4px
  112. +e(inner)
  113. position relative
  114. +e(avatar)
  115. padding-right 10px
  116. user-select none
  117. .lemon-avatar
  118. cursor pointer
  119. +e(title)
  120. display flex
  121. font-size 12px
  122. line-height 14px
  123. padding-bottom 6px
  124. user-select none
  125. color #999
  126. +e(content)
  127. font-size 14px
  128. line-height 20px
  129. padding 8px 10px
  130. background #fff
  131. border-radius 4px
  132. position relative
  133. margin 0 46px 0 0
  134. img
  135. video
  136. background #e9e9e9
  137. height 100px
  138. &:before
  139. arrow()
  140. left -4px
  141. border-left none
  142. border-right-color #fff
  143. +e(status)
  144. position absolute
  145. top 23px
  146. right 20px
  147. color #aaa
  148. font-size 20px
  149. +m(reverse)
  150. flex-direction row-reverse
  151. +e(title)
  152. flex-direction row-reverse
  153. +e(status)
  154. left 20px
  155. right auto
  156. +e(content)
  157. background #35d863
  158. margin 0 0 0 46px
  159. &:before
  160. arrow()
  161. left auto
  162. right -4px
  163. border-right none
  164. border-left-color #35d863
  165. +e(title)
  166. text-align right
  167. +e(avatar)
  168. padding-right 0
  169. padding-left 10px
  170. +m(hidden-title)
  171. +e(status)
  172. top 7px
  173. +e(title)
  174. display none
  175. +e(content)
  176. &:before
  177. top 14px
  178. </style>