messageshow.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <template>
  2. <view class="m-item" :id="'message'+cid">
  3. <view class="m-left">
  4. <image class="head_icon" src="https://img-cdn-qiniu.dcloud.net.cn/uniapp/app/homeHL.png" v-if="message.user=='home'"></image>
  5. </view>
  6. <view class="m-content">
  7. <view class="m-content-head" :class="{'m-content-head-right':message.user=='customer'}">
  8. <view :class="'m-content-head-'+message.user">
  9. <rich-text :nodes="message.content.replace(this.reg, emotion)"></rich-text></view>
  10. </view>
  11. </view>
  12. <view class="m-right">
  13. <image class="head_icon" src="https://img-cdn-qiniu.dcloud.net.cn/uniapp/app/customerHL.png" v-if="message.user=='customer'"></image>
  14. </view>
  15. </view>
  16. </template>
  17. <script>
  18. export default {
  19. props: {
  20. message: {
  21. type: Object,
  22. default () {
  23. return {};
  24. }
  25. },
  26. cid: {
  27. type: [Number, String],
  28. default: ''
  29. }
  30. },
  31. data() {
  32. return {
  33. reg: /\#[\S]{1,3}\;/gi
  34. }
  35. },
  36. methods: {
  37. emotion(res) {
  38. //console.log('mess', res)
  39. let word = res.replace(/\#|\;/gi, '')
  40. //console.log(word)
  41. const list = ['微笑', '撇嘴', '色', '发呆', '得意', '流泪', '害羞', '闭嘴', '睡', '大哭', '尴尬', '发怒', '调皮', '呲牙', '惊讶', '难过', '酷',
  42. '冷汗', '抓狂', '吐', '偷笑', '可爱', '白眼', '傲慢', '饥饿', '困', '惊恐', '流汗', '憨笑', '大兵', '奋斗', '咒骂', '疑问', '嘘', '晕', '折磨', '衰',
  43. '骷髅', '敲打', '再见', '擦汗', '抠鼻', '鼓掌', '糗大了', '坏笑', '左哼哼', '右哼哼', '哈欠', '鄙视', '委屈', '快哭了', '阴险', '亲亲', '吓', '可怜',
  44. '菜刀', '西瓜', '啤酒', '篮球', '乒乓', '咖啡', '饭', '猪头', '玫瑰', '凋谢', '示爱', '爱心', '心碎', '蛋糕', '闪电', '炸弹', '刀', '足球', '瓢虫',
  45. '便便', '月亮', '太阳', '礼物', '拥抱', '强', '弱', '握手', '胜利', '抱拳', '勾引', '拳头', '差劲', '爱你', 'NO', 'OK', '爱情', '飞吻', '跳跳',
  46. '发抖', '怄火', '转圈', '磕头', '回头', '跳绳', '挥手', '激动', '街舞', '献吻', '左太极', '右太极'
  47. ]
  48. let index = list.indexOf(word)
  49. return `<img src="https://res.wx.qq.com/mpres/htmledition/images/icon/emotion/${index}.gif" align="middle">`
  50. }
  51. }
  52. }
  53. </script>
  54. <style>
  55. .m-item {
  56. display: flex;
  57. flex-direction: row;
  58. padding-top: 40upx;
  59. }
  60. .m-left {
  61. display: flex;
  62. width: 120upx;
  63. justify-content: center;
  64. align-items: flex-start;
  65. }
  66. .m-content {
  67. display: flex;
  68. flex: 1;
  69. flex-direction: column;
  70. justify-content: center;
  71. word-break: break-all;
  72. }
  73. .m-right {
  74. display: flex;
  75. width: 120upx;
  76. justify-content: center;
  77. align-items: flex-start;
  78. }
  79. .head_icon {
  80. width: 80upx;
  81. height: 80upx;
  82. }
  83. .m-content-head {
  84. position: relative;
  85. }
  86. .m-content-head-right {
  87. display: flex;
  88. justify-content: flex-end;
  89. }
  90. .m-content-head-home {
  91. text-align: left;
  92. background: #1482d1;
  93. border: 1px #1482d1 solid;
  94. border-radius: 20upx;
  95. padding: 20upx;
  96. color: white;
  97. display: inline-block;
  98. }
  99. .m-content-head-home:before {
  100. border: 15upx solid transparent;
  101. border-right: 15upx solid #1482d1;
  102. left: -26upx;
  103. width: 0;
  104. height: 0;
  105. position: absolute;
  106. content: ' '
  107. }
  108. .m-content-head-customer {
  109. border: 1upx white solid;
  110. background: white;
  111. border-radius: 20upx;
  112. padding: 20upx;
  113. }
  114. .m-content-head-customer:after {
  115. border: 15upx solid transparent;
  116. border-left: 15upx solid white;
  117. top: 20upx;
  118. right: -26upx;
  119. width: 0;
  120. height: 0;
  121. position: absolute;
  122. content: ' '
  123. }
  124. </style>