message.vue 9.8 KB

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