message.vue 9.4 KB

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