Message.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421
  1. <template>
  2. <div :data-id="info.id">
  3. <!--文本、任务、报告、视频通话-->
  4. <div v-if="info.type==='text' || info.type==='taskB' || info.type==='report' || info.type==='video' || info.type==='voice'">
  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"><UserView :username="userName" :info="info" placement="left"/></em>
  12. <em v-if="info.indate" class="item-date">{{formatCDate(info.indate)}}</em>
  13. </div>
  14. <div class="item-text" :class="{'text-emoji':textIsEmoji(info.text), 'text-error':info.error}">
  15. <div class="item-text-view">{{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 v-else-if="info.type==='video' || info.type==='voice'" class="item-link">
  23. <Icon v-if="info.type==='voice'" type="ios-call-outline"/>
  24. <Icon v-else type="ios-videocam-outline"/>
  25. <span>{{$L('通话时长:%', formatSecond(info.other.second))}}</span>
  26. </div>
  27. </div>
  28. <UserImg :info="info" @click="clickUser" class="item-userimg"/>
  29. </div>
  30. <div v-else-if="info.self===false" class="list-item">
  31. <UserImg :info="info" @click="clickUser" class="item-userimg"/>
  32. <div class="item-left">
  33. <div class="item-username" @click="clickUser">
  34. <em class="item-name"><UserView :username="userName" :info="info" placement="right"/></em>
  35. <em v-if="info.__usertag" class="item-tag">{{info.__usertag}}</em>
  36. <em v-if="info.indate" class="item-date">{{formatCDate(info.indate)}}</em>
  37. </div>
  38. <div class="item-text" :class="{'text-emoji':textIsEmoji(info.text), 'text-error':info.error}">
  39. <div class="item-text-view">{{textMsg(info.text)}}</div>
  40. </div>
  41. <template v-if="info.type==='taskB'">
  42. <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>
  43. <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>
  44. </template>
  45. <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>
  46. <div v-else-if="info.type==='video' || info.type==='voice'" class="item-link">
  47. <Icon v-if="info.type==='voice'" type="ios-call-outline"/>
  48. <Icon v-else type="ios-videocam-outline"/>
  49. <span>{{$L('通话时长:%', formatSecond(info.other.second))}}</span>
  50. </div>
  51. </div>
  52. </div>
  53. </div>
  54. <!--图片、文件-->
  55. <div v-else-if="info.type==='image' || info.type==='file'">
  56. <div v-if="info.self===true" class="list-right">
  57. <div v-if="info.error" class="item-error" @click="clickError(info.error)">
  58. <Icon type="md-alert" />
  59. </div>
  60. <div class="item-right">
  61. <div class="item-username" @click="clickUser">
  62. <em class="item-name"><UserView :username="userName" :info="info" placement="left"/></em>
  63. <em v-if="info.indate" class="item-date">{{formatCDate(info.indate)}}</em>
  64. </div>
  65. <div v-if="info.url==='loading'" class="item-loading">
  66. <WLoading/>
  67. </div>
  68. <a v-else class="item-file" :href="info.url" target="_blank">
  69. <div v-if="info.type==='file'" class="item-file-box">
  70. <img class="item-file-thumb" :src="info.filethumb"/>
  71. <div class="item-file-info">
  72. <div class="item-file-name">{{info.filename}}</div>
  73. <div class="item-file-size">{{$A.bytesToSize($A.runNum(info.filesize) * 1024)}}</div>
  74. </div>
  75. </div>
  76. <img v-else class="item-file-img" :style="imageStyle(info)" :src="info.url"/>
  77. </a>
  78. </div>
  79. <UserImg :info="info" @click="clickUser" class="item-userimg"/>
  80. </div>
  81. <div v-else-if="info.self===false" class="list-item">
  82. <UserImg :info="info" @click="clickUser" class="item-userimg"/>
  83. <div class="item-left">
  84. <div class="item-username" @click="clickUser">
  85. <em class="item-name"><UserView :username="userName" :info="info" placement="right"/></em>
  86. <em v-if="info.__usertag" class="item-tag">{{info.__usertag}}</em>
  87. <em v-if="info.indate" class="item-date">{{formatCDate(info.indate)}}</em>
  88. </div>
  89. <div v-if="info.url==='loading'" class="item-loading">
  90. <WLoading/>
  91. </div>
  92. <a v-else class="item-file" :href="info.url" target="_blank">
  93. <div v-if="info.type==='file'" class="item-file-box">
  94. <img class="item-file-thumb" :src="info.filethumb"/>
  95. <div class="item-file-info">
  96. <div class="item-file-name">{{info.filename}}</div>
  97. <div class="item-file-size">{{$A.bytesToSize($A.runNum(info.filesize) * 1024)}}</div>
  98. </div>
  99. </div>
  100. <img v-else class="item-file-img" :style="imageStyle(info)" :src="info.url"/>
  101. </a>
  102. </div>
  103. </div>
  104. </div>
  105. <!--通知-->
  106. <div v-else-if="info.type==='notice'">
  107. <div class="item-notice">{{info.notice}}</div>
  108. </div>
  109. </div>
  110. </template>
  111. <style lang="scss" scoped>
  112. /*通用*/
  113. .list-item, .list-right {
  114. display: flex;
  115. width: 100%;
  116. padding-top: 7px;
  117. padding-bottom: 7px;
  118. background-color: #E8EBF2;
  119. .item-left, .item-right {
  120. display: flex;
  121. flex-direction: column;
  122. max-width: 80%;
  123. .item-username {
  124. font-size: 12px;
  125. padding-top: 1px;
  126. padding-bottom: 4px;
  127. display: flex;
  128. flex-direction: row;
  129. align-items: center;
  130. em {
  131. display: inline-block;
  132. font-style: normal;
  133. &.item-name {
  134. color: #888888;
  135. }
  136. &.item-tag {
  137. color: #ffffff;
  138. background-color: #ff0000;
  139. line-height: 16px;
  140. padding: 2px 4px;
  141. margin-left: 3px;
  142. border-radius: 2px;
  143. font-size: 12px;
  144. transform: scale(0.8);
  145. font-weight: 600;
  146. }
  147. &.item-date {
  148. margin-left: 4px;
  149. color: #aaaaaa;
  150. }
  151. }
  152. }
  153. }
  154. .item-left {
  155. align-items: flex-start;
  156. }
  157. .item-right {
  158. align-items: flex-end;
  159. .item-username {
  160. text-align: right;
  161. }
  162. .item-link {
  163. transform-origin: right center;
  164. }
  165. }
  166. .item-userimg {
  167. width: 38px;
  168. height: 38px;
  169. margin-left: 8px;
  170. margin-right: 8px;
  171. border-radius: 3px;
  172. font-size: 20px;
  173. }
  174. .item-error {
  175. cursor: pointer;
  176. width: 48px;
  177. position: relative;
  178. > i {
  179. color: #ff0000;
  180. font-size: 18px;
  181. position: absolute;
  182. top: 50%;
  183. left: 50%;
  184. transform: translate(-50%, -50%);
  185. }
  186. }
  187. }
  188. .list-right {
  189. justify-content: flex-end;
  190. }
  191. /*文本*/
  192. .item-text {
  193. display: inline-block;
  194. border-radius: 6px;
  195. padding: 8px;
  196. background-color: #ffffff;
  197. max-height: 580px;
  198. overflow: auto;
  199. &.text-emoji {
  200. background-color: transparent;
  201. .item-text-view {
  202. font-size: 52px;
  203. line-height: normal;
  204. }
  205. }
  206. &.text-error {
  207. box-shadow: 0 0 4px 0 #ffa1a1;
  208. }
  209. .item-text-view {
  210. max-width: 520px;
  211. color: #242424;
  212. font-size: 14px;
  213. line-height: 18px;
  214. word-break: break-all;
  215. }
  216. }
  217. /*信息底标*/
  218. .item-link {
  219. display: flex;
  220. align-items: center;
  221. max-width: 100%;
  222. font-size: 12px;
  223. color: #ffffff;
  224. background-color: #cacaca;
  225. margin-top: 6px;
  226. margin-bottom: -2px;
  227. height: 20px;
  228. line-height: 20px;
  229. padding: 0 5px;
  230. border-radius: 4px;
  231. transform: scale(0.96);
  232. transform-origin: left center;
  233. > i {
  234. font-size: 14px;
  235. padding-right: 2px;
  236. }
  237. > span {
  238. white-space: nowrap;
  239. }
  240. > a {
  241. color: #3D90E2;
  242. padding-left: 3px;
  243. overflow: hidden;
  244. text-overflow: ellipsis;
  245. white-space: nowrap;
  246. max-width: 100%;
  247. }
  248. }
  249. /*加载中*/
  250. .item-loading {
  251. display: flex;
  252. justify-content: center;
  253. align-items: center;
  254. width: 28px;
  255. height: 28px;
  256. margin: 24px;
  257. }
  258. /*文件、图片*/
  259. .item-file {
  260. display: inline-block;
  261. text-decoration: none;
  262. .item-file-box {
  263. background: #ffffff;
  264. display: flex;
  265. align-items: center;
  266. padding: 10px 14px;
  267. border-radius: 3px;
  268. width: 220px;
  269. .item-file-thumb {
  270. width: 36px;
  271. }
  272. .item-file-info {
  273. margin-left: 12px;
  274. display: flex;
  275. flex-direction: column;
  276. justify-content: center;
  277. .item-file-name {
  278. color: #333333;
  279. font-size: 14px;
  280. line-height: 18px;
  281. word-break: break-all;
  282. text-overflow: ellipsis;
  283. overflow: hidden;
  284. display: -webkit-box;
  285. -webkit-line-clamp: 2;
  286. -webkit-box-orient: vertical;
  287. }
  288. .item-file-size {
  289. padding-top: 4px;
  290. color: #666666;
  291. font-size: 14px;
  292. }
  293. }
  294. }
  295. .item-file-img {
  296. max-width: 220px;
  297. max-height: 220px;
  298. border-radius: 6px;
  299. }
  300. }
  301. /*通知*/
  302. .item-notice {
  303. color: #777777;
  304. font-size: 12px;
  305. text-align: center;
  306. padding: 12px 24px;
  307. }
  308. </style>
  309. <script>
  310. export default {
  311. name: 'ChatMessage',
  312. props: {
  313. info: {
  314. type: Object,
  315. default: {},
  316. },
  317. },
  318. mounted() {
  319. },
  320. computed: {
  321. userName() {
  322. return this.info.send_username || this.info.username;
  323. },
  324. userImg() {
  325. return this.info.send_userimg || this.info.userimg;
  326. },
  327. imageStyle() {
  328. return function (info) {
  329. const {width, height} = info;
  330. if (width && height) {
  331. let maxWidth = 220,
  332. maxHeight = 220,
  333. tempWidth = width,
  334. tempHeight = height;
  335. if (width > maxWidth || height > maxHeight) {
  336. if (width > height) {
  337. tempWidth = maxWidth;
  338. tempHeight = height * (maxWidth / width);
  339. } else {
  340. tempWidth = width * (maxHeight / height);
  341. tempHeight = maxHeight;
  342. }
  343. }
  344. return {
  345. width: tempWidth + 'px',
  346. height: tempHeight + 'px',
  347. };
  348. }
  349. return {};
  350. }
  351. }
  352. },
  353. methods: {
  354. textMsg(text) {
  355. return (text + "").replace(/\n/, '<br/>');
  356. },
  357. textIsEmoji(text) {
  358. return text.replace(/[\uD800-\uDBFF][\uDC00-\uDFFF]/g, "_") === "_";
  359. },
  360. formatCDate(v) {
  361. let string = '';
  362. if ($A.runNum(v) > 0) {
  363. if ($A.formatDate('Ymd') === $A.formatDate('Ymd', v)) {
  364. string = $A.formatDate('H:i', v)
  365. } else if ($A.formatDate('Y') === $A.formatDate('Y', v)) {
  366. string = $A.formatDate('m-d', v)
  367. } else {
  368. string = $A.formatDate('Y-m-d', v)
  369. }
  370. }
  371. return string ? '(' + string + ')' : '';
  372. },
  373. clickError(err) {
  374. this.$Modal.error({
  375. title: this.$L("错误详情"),
  376. content: err
  377. });
  378. },
  379. clickUser(e) {
  380. this.$emit('clickUser', this.info, e);
  381. },
  382. fileDownUrl(id) {
  383. return $A.apiUrl('project/files/download?fileid=' + id);
  384. },
  385. formatSecond(d) {
  386. if (d > 3600) {
  387. return Math.ceil(d / 3600) + '小时';
  388. } else if (d > 60) {
  389. return Math.ceil(d / 60) + '分钟';
  390. } else {
  391. return d + '秒';
  392. }
  393. }
  394. }
  395. }
  396. </script>