message.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. <template>
  2. <div :data-id="info.id">
  3. <!--文本-->
  4. <div v-if="info.type==='text'">
  5. <div v-if="info.self===true" class="list-right">
  6. <div v-if="info.error" class="item-error" @click="clickError(info.error)">
  7. <Icon type="md-alert" />
  8. </div>
  9. <div class="item-right">
  10. <div class="item-username" @click="clickUser">
  11. <em class="item-name"><user-view :username="info.username" placement="left"/></em>
  12. <em v-if="info.indate" class="item-date">{{formatCDate(info.indate)}}</em>
  13. </div>
  14. <div class="item-text">
  15. <div class="item-text-view" v-html="textMsg(info.text)"></div>
  16. </div>
  17. </div>
  18. <img class="item-userimg" @click="clickUser" :src="info.userimg" onerror="this.src=window.location.origin+'/images/other/avatar.png'"/>
  19. </div>
  20. <div v-else-if="info.self===false" class="list-item">
  21. <img class="item-userimg" @click="clickUser" :src="info.userimg" onerror="this.src=window.location.origin+'/images/other/avatar.png'"/>
  22. <div class="item-left">
  23. <div class="item-username" @click="clickUser">
  24. <em class="item-name"><user-view :username="info.username" placement="right"/></em>
  25. <em v-if="info.__usertag" class="item-tag">{{info.__usertag}}</em>
  26. <em v-if="info.indate" class="item-date">{{formatCDate(info.indate)}}</em>
  27. </div>
  28. <div class="item-text">
  29. <div class="item-text-view" v-html="textMsg(info.text)"></div>
  30. </div>
  31. </div>
  32. </div>
  33. </div>
  34. <!--图片-->
  35. <div v-else-if="info.type==='image'">
  36. <div v-if="info.self===true" class="list-right">
  37. <div v-if="info.error" class="item-error" @click="clickError(info.error)">
  38. <Icon type="md-alert" />
  39. </div>
  40. <div class="item-right">
  41. <div class="item-username" @click="clickUser">
  42. <em class="item-name"><user-view :username="info.username" placement="left"/></em>
  43. <em v-if="info.indate" class="item-date">{{formatCDate(info.indate)}}</em>
  44. </div>
  45. <a class="item-image" :href="info.url" target="_blank">
  46. <img class="item-image-view" :src="info.url"/>
  47. </a>
  48. </div>
  49. <img class="item-userimg" @click="clickUser" :src="info.userimg" onerror="this.src=window.location.origin+'/images/other/avatar.png'"/>
  50. </div>
  51. <div v-else-if="info.self===false" class="list-item">
  52. <img class="item-userimg" @click="clickUser" :src="info.userimg" onerror="this.src=window.location.origin+'/images/other/avatar.png'"/>
  53. <div class="item-left">
  54. <div class="item-username" @click="clickUser">
  55. <em class="item-name"><user-view :username="info.username" placement="right"/></em>
  56. <em v-if="info.__usertag" class="item-tag">{{info.__usertag}}</em>
  57. <em v-if="info.indate" class="item-date">{{formatCDate(info.indate)}}</em>
  58. </div>
  59. <a class="item-image" :href="info.url" target="_blank">
  60. <img class="item-image-view" :src="info.url"/>
  61. </a>
  62. </div>
  63. </div>
  64. </div>
  65. <!--通知-->
  66. <div v-else-if="info.type==='notice'">
  67. <div class="item-notice">{{info.notice}}</div>
  68. </div>
  69. </div>
  70. </template>
  71. <style lang="scss" scoped>
  72. /*通用*/
  73. .list-item, .list-right {
  74. display: flex;
  75. width: 100%;
  76. padding-top: 7px;
  77. padding-bottom: 7px;
  78. background-color: #E8EBF2;
  79. .item-left, .item-right {
  80. display: flex;
  81. flex-direction: column;
  82. max-width: 80%;
  83. .item-username {
  84. font-size: 12px;
  85. padding-top: 1px;
  86. padding-bottom: 4px;
  87. display: flex;
  88. flex-direction: row;
  89. align-items: center;
  90. em {
  91. display: inline-block;
  92. font-style: normal;
  93. &.item-name {
  94. color: #888888;
  95. }
  96. &.item-tag {
  97. color: #ffffff;
  98. background-color: #ff0000;
  99. line-height: 16px;
  100. padding: 2px 4px;
  101. margin-left: 3px;
  102. border-radius: 2px;
  103. font-size: 12px;
  104. transform: scale(0.8);
  105. font-weight: 600;
  106. }
  107. &.item-date {
  108. margin-left: 4px;
  109. color: #aaaaaa;
  110. }
  111. }
  112. }
  113. }
  114. .item-left {
  115. align-items: flex-start;
  116. }
  117. .item-right {
  118. align-items: flex-end;
  119. .item-username {
  120. text-align: right;
  121. }
  122. }
  123. .item-userimg {
  124. width: 38px;
  125. height: 38px;
  126. margin-left: 8px;
  127. margin-right: 8px;
  128. border-radius: 3px;
  129. }
  130. .item-error {
  131. cursor: pointer;
  132. width: 48px;
  133. position: relative;
  134. > i {
  135. color: #ff0000;
  136. font-size: 18px;
  137. position: absolute;
  138. top: 50%;
  139. left: 50%;
  140. transform: translate(-50%, -50%);
  141. }
  142. }
  143. }
  144. .list-right {
  145. justify-content: flex-end;
  146. }
  147. /*文本*/
  148. .item-text {
  149. display: inline-block;
  150. border-radius: 6px;
  151. padding: 8px;
  152. background-color: #ffffff;
  153. .item-text-view {
  154. max-width: 520px;
  155. color: #242424;
  156. font-size: 14px;
  157. line-height: 18px;
  158. word-break: break-all;
  159. }
  160. }
  161. /*图片*/
  162. .item-image {
  163. display: inline-block;
  164. text-decoration: none;
  165. .item-image-view {
  166. max-width: 220px;
  167. max-height: 220px;
  168. border-radius: 6px;
  169. }
  170. }
  171. /*通知*/
  172. .item-notice {
  173. color: #777777;
  174. font-size: 12px;
  175. text-align: center;
  176. padding: 12px 24px;
  177. }
  178. </style>
  179. <script>
  180. export default {
  181. name: 'ChatMessage',
  182. props: {
  183. info: {
  184. type: Object,
  185. default: {},
  186. },
  187. },
  188. mounted() {
  189. },
  190. methods: {
  191. textMsg(text) {
  192. return (text + "").replace(/\n/, '<br/>');
  193. },
  194. formatCDate(v) {
  195. let string = '';
  196. if ($A.runNum(v) > 0) {
  197. if ($A.formatDate('Ymd') === $A.formatDate('Ymd', v)) {
  198. string = $A.formatDate('H:i', v)
  199. } else if ($A.formatDate('Y') === $A.formatDate('Y', v)) {
  200. string = $A.formatDate('m-d', v)
  201. } else {
  202. string = $A.formatDate('Y-m-d', v)
  203. }
  204. }
  205. return string ? '(' + string + ')' : '';
  206. },
  207. clickError(err) {
  208. this.$Modal.error({
  209. title: "错误详情",
  210. content: err
  211. });
  212. },
  213. clickUser(e) {
  214. this.$emit('clickUser', this.info, e);
  215. },
  216. }
  217. }
  218. </script>