ChatMessage.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <template>
  2. <view class="div chat-message">
  3. <!--商品信息-->
  4. <view class="div" v-if="item.instant_message_type==1">
  5. <view class="div dstouch-chat-product" @click="goNavigate('/pages/home/goodsdetail/Goodsdetail',{goods_id:item.instant_message.goods_id})">
  6. <view class="div goods-pic">
  7. <image mode="aspectFit" class="img" :src="item.instant_message.goods_image_url" alt="">
  8. </view>
  9. <view class="div goods-info">
  10. <view class="div goods-name">{{item.instant_message.goods_name}}</view>
  11. <view class="div goods-price">¥{{item.instant_message.goods_price}}</view>
  12. </view>
  13. </view>
  14. </view>
  15. <!--聊天信息-->
  16. <view class="div" v-else>
  17. <view class="div" v-if="item.instant_message_from_id">
  18. <view v-if="item.if_show_time" class="div time">{{ $moment.unix(item.instant_message_add_time).format('YYYY-MM-DD HH:mm') }}</view>
  19. <view class="dl" :class="item.instant_message_from_id!=t_id?'msg-me':'msg-other'">
  20. <view class="dt">
  21. <image mode="aspectFit" class="img" :src="((item.instant_message_from_id!=t_id)?item.instant_message_to_avatar:item.instant_message_from_avatar)+'?'+time" alt=""><text class="i"></text>
  22. </view>
  23. <rich-text class="dd" :nodes='getContent(item.instant_message)'></rich-text>
  24. </view>
  25. </view>
  26. </view>
  27. </view>
  28. </template>
  29. <script>
  30. import { urlencode } from '@/util/common'
  31. import { env } from '../../../static/config'
  32. export default {
  33. data () {
  34. return {
  35. time: '',
  36. smilies_array: {
  37. ':smile:': { image: 'smile.gif', text: '微笑' },
  38. ':sad:': { image: 'sad.gif', text: '难过' },
  39. ':biggrin:': { image: 'biggrin.gif', text: '呲牙' },
  40. ':cry:': { image: 'cry.gif', text: '大哭' },
  41. ':huffy:': { image: 'huffy.gif', text: '发怒' },
  42. ':shocked:': { image: 'shocked.gif', text: '惊讶' },
  43. ':tongue:': { image: 'tongue.gif', text: '调皮' },
  44. ':shy:': { image: 'shy.gif', text: '害羞' },
  45. ':titter:': { image: 'titter.gif', text: '偷笑' },
  46. ':sweat:': { image: 'sweat.gif', text: '流汗' },
  47. ':mad:': { image: 'mad.gif', text: '抓狂' },
  48. ':lol:': { image: 'lol.gif', text: '阴险' },
  49. ':loveliness:': { image: 'loveliness.gif', text: '可爱' },
  50. ':funk:': { image: 'funk.gif', text: '惊恐' },
  51. ':curse:': { image: 'curse.gif', text: '咒骂' },
  52. ':dizzy:': { image: 'dizzy.gif', text: '晕' },
  53. ':shutup:': { image: 'shutup.gif', text: '闭嘴' },
  54. ':sleepy:': { image: 'sleepy.gif', text: '睡' },
  55. ':hug:': { image: 'hug.gif', text: '拥抱' },
  56. ':victory:': { image: 'victory.gif', text: '胜利' },
  57. ':sun:': { image: 'sun.gif', text: '太阳' },
  58. ':moon:': { image: 'moon.gif', text: '月亮' },
  59. ':kiss:': { image: 'kiss.gif', text: '示爱' },
  60. ':handshake:': { image: 'handshake.gif', text: '握手' }
  61. }
  62. }
  63. },
  64. props: {
  65. item: {},
  66. t_id: {}
  67. },
  68. created () {
  69. this.time = new Date().getTime()
  70. },
  71. methods:{
  72. goNavigate(path,query=false){
  73. uni.navigateTo({url:path+(query?('?'+urlencode(query)):'')})
  74. },
  75. getContent (content) {
  76. for (var key in this.smilies_array) {
  77. let smile = this.smilies_array[key]
  78. let reg = new RegExp('' + key, 'g')
  79. content = content.replace(reg, "<image mode='aspectFit' class='img' title='" + smile.text + "' alt='" + smile.text + "' src='" + this.getSmile(smile.image) + "'>")
  80. }
  81. return content
  82. },
  83. getSmile (smile) {
  84. return env.SITE_URL + '/static/plugins/js/smilies/images/' + smile
  85. }
  86. }
  87. }
  88. </script>
  89. <style scoped lang="scss">
  90. .dstouch-chat-product { width: 93%; margin: 0.5rem auto; padding: 0.5rem 0; border: solid 0.05rem #DDD; background-color: #FFF; position: relative;}
  91. .dstouch-chat-product .goods-pic { width: 2.5rem; height: 2.5rem; position: absolute; top: 0.5rem; left: 0.5rem;}
  92. .dstouch-chat-product .goods-pic .img { width: 100%;}
  93. .dstouch-chat-product .goods-info { margin: 0 0.5rem 0 3.5rem;}
  94. .dstouch-chat-product .goods-name { font-size:$subFontSize; line-height: 0.7rem; height: 1.4rem; overflow: hidden; margin-bottom: 0.3rem; color: #000;}
  95. .dstouch-chat-product .goods-price { font-size:$fontSize; line-height: 0.9rem; height: 0.9rem; color: #f23030; font-weight: 600;}
  96. .chat-message .time{text-align: center;font-size:$fontSize;color:gray}
  97. .chat-message .dl { position: relative; min-height: 2.2rem; padding: 0.2rem 0; margin-bottom: 0.2rem; overflow: hidden;}
  98. .chat-message .dl.msg-other { animation: optionMsgLeft 0.5s ease-in-out; -webkit-animation:optionMsgLeft 0.5s ease-in-out;}
  99. @keyframes optionMsgLeft
  100. {
  101. from { opacity: 0.5; left: -100%; right:100%;}
  102. to { opacity: 1; left: 0; right:0;}
  103. }
  104. @-webkit-keyframes optionMsgLeft
  105. {
  106. from { opacity: 0.5; left: -100%; right:100%;}
  107. to { opacity: 1; left: 0; right:0;}
  108. }
  109. .chat-message .dl.msg-me {animation: optionMsgRight 0.5s ease-in-out; -webkit-animation:optionMsgRight 0.5s ease-in-out;}
  110. @keyframes optionMsgRight
  111. {
  112. from { opacity: 0.5; left: 100%; right:-100%;}
  113. to { opacity: 1; left: 0; right:0;}
  114. }
  115. @-webkit-keyframes optionMsgRight
  116. {
  117. from { opacity: 0.5; left: 100%; right:-100%;}
  118. to { opacity: 1; left: 0; right:0;}
  119. }
  120. .chat-message .dl .dt { width: 2rem; height: 2rem; position: absolute; top: 0.3rem;}
  121. .chat-message .dl .dt .i { width: 0.5rem; height: 0.5rem; position: absolute; top: 0.5rem; background-repeat: no-repeat; background-position: 50% 50%; background-size: 100%;}
  122. .chat-message .dl .dt .img { max-width: 2rem; max-height: 2rem; border-radius: 100%;}
  123. .chat-message .dl.msg-other .dt { left: 0.4rem;}
  124. .chat-message .dl.msg-other .dt .i { left: 2.3rem; background-image: url(../../../static/image/chat/chat-msg-other.png);}
  125. .chat-message .dl.msg-me .dt { right: 0.4rem;}
  126. .chat-message .dl.msg-me .dt .i { right: 2.3rem; background-image: url(../../../static/image/chat/chat-msg-me.png);}
  127. .chat-message .dl .dd { display: block; max-width: 10rem; padding: 0.4rem 0.6rem; border-radius: 0.4rem; min-height: 0.9rem; font-size:$subFontSize; line-height: 0.9rem; color: #000; word-wrap: break-word;}
  128. .chat-message .dl .dd .img { background: #FFF; max-width: 8rem; max-height: 8rem; padding: 0.2rem; border-radius: 0.3rem; vertical-align: text-bottom; margin: 0 0.2rem;}
  129. .chat-message .dl.msg-other .dd { margin-left: 3rem; float: left; background-color: #FFF;}
  130. .chat-message .dl.msg-me .dd { margin-right: 3rem; float: right; background-color: #FFD779;}
  131. </style>