message.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  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)"><span>{{$L('来自关注任务')}}:</span><a href="javascript:void(0)">{{info.other.title}}</a></div>
  19. <div v-if="info.other.type==='file'" class="item-link"><span>{{$L('来自关注任务')}}:</span><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)"><span>{{$L('来自工作报告')}}:</span><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)"><span>{{$L('来自关注任务')}}:</span><a href="javascript:void(0)">{{info.other.title}}</a></div>
  38. <div v-if="info.other.type==='file'" class="item-link"><span>{{$L('来自关注任务')}}:</span><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)"><span>{{$L('来自工作报告')}}:</span><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. .item-link {
  133. transform-origin: right center;
  134. }
  135. }
  136. .item-userimg {
  137. width: 38px;
  138. height: 38px;
  139. margin-left: 8px;
  140. margin-right: 8px;
  141. border-radius: 3px;
  142. }
  143. .item-error {
  144. cursor: pointer;
  145. width: 48px;
  146. position: relative;
  147. > i {
  148. color: #ff0000;
  149. font-size: 18px;
  150. position: absolute;
  151. top: 50%;
  152. left: 50%;
  153. transform: translate(-50%, -50%);
  154. }
  155. }
  156. }
  157. .list-right {
  158. justify-content: flex-end;
  159. }
  160. /*文本*/
  161. .item-text {
  162. display: inline-block;
  163. border-radius: 6px;
  164. padding: 8px;
  165. background-color: #ffffff;
  166. .item-text-view {
  167. max-width: 520px;
  168. color: #242424;
  169. font-size: 14px;
  170. line-height: 18px;
  171. word-break: break-all;
  172. }
  173. }
  174. /*信息底标*/
  175. .item-link {
  176. display: flex;
  177. align-items: center;
  178. max-width: 100%;
  179. font-size: 12px;
  180. color: #ffffff;
  181. background-color: #cacaca;
  182. margin-top: 6px;
  183. margin-bottom: -2px;
  184. height: 20px;
  185. line-height: 20px;
  186. padding: 0 5px;
  187. border-radius: 4px;
  188. transform: scale(0.96);
  189. transform-origin: left center;
  190. > span {
  191. white-space: nowrap;
  192. }
  193. > a {
  194. color: #3D90E2;
  195. padding-left: 3px;
  196. overflow: hidden;
  197. text-overflow: ellipsis;
  198. white-space: nowrap;
  199. max-width: 100%;
  200. }
  201. }
  202. /*图片*/
  203. .item-image {
  204. display: inline-block;
  205. text-decoration: none;
  206. .item-image-view {
  207. max-width: 220px;
  208. max-height: 220px;
  209. border-radius: 6px;
  210. }
  211. }
  212. /*通知*/
  213. .item-notice {
  214. color: #777777;
  215. font-size: 12px;
  216. text-align: center;
  217. padding: 12px 24px;
  218. }
  219. </style>
  220. <script>
  221. export default {
  222. name: 'ChatMessage',
  223. props: {
  224. info: {
  225. type: Object,
  226. default: {},
  227. },
  228. },
  229. mounted() {
  230. },
  231. methods: {
  232. textMsg(text) {
  233. return (text + "").replace(/\n/, '<br/>');
  234. },
  235. formatCDate(v) {
  236. let string = '';
  237. if ($A.runNum(v) > 0) {
  238. if ($A.formatDate('Ymd') === $A.formatDate('Ymd', v)) {
  239. string = $A.formatDate('H:i', v)
  240. } else if ($A.formatDate('Y') === $A.formatDate('Y', v)) {
  241. string = $A.formatDate('m-d', v)
  242. } else {
  243. string = $A.formatDate('Y-m-d', v)
  244. }
  245. }
  246. return string ? '(' + string + ')' : '';
  247. },
  248. clickError(err) {
  249. this.$Modal.error({
  250. title: this.$L("错误详情"),
  251. content: err
  252. });
  253. },
  254. clickUser(e) {
  255. this.$emit('clickUser', this.info, e);
  256. },
  257. fileDownUrl(id) {
  258. return $A.aUrl('project/files/download?fileid=' + id);
  259. }
  260. }
  261. }
  262. </script>