msg-item.vue 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408
  1. <template>
  2. <view class="">
  3. <view class="dialogue-box"
  4. :class="item.msg_type == 2 ||item.msg_type == 3 ?'dialogue-box-one':'dialogue-box-two'">
  5. <view class="time">
  6. {{item.created_at}}
  7. </view>
  8. <view class="dialogue">
  9. <view class="dialogue-text" :class="item.msg_type == 2 ?'dialogue-text-one':'dialogue-text-two'"
  10. v-if="(item.msg_type == 1 ||item.msg_type == 2) && showText">
  11. <!-- {{item.content}} -->
  12. <!-- {{showText}}-->
  13. <view class="" :class="item.msg_type == 2?'showText-color-one':'showText-color-two'"
  14. v-html="showText"></view>
  15. <view class="align-items-center flex-justify-end" v-if="item.msg_type == 2">
  16. <view class="fs-28 fc-9 fz-class" @click="copy(showText)">
  17. 复制
  18. </view>
  19. </view>
  20. <view class="voice-box" v-if="item.voice_url">
  21. <view class="voice-box-left" v-if="item.msg_type == 1">
  22. <image @click="voiceTwo" v-if="!voiceShwo" class="voice-img"
  23. src="@/static/img/chat/voice-n.png" mode="">
  24. </image>
  25. <image @click="voice(true,item)" v-else class="voice-img"
  26. src="@/static/img/chat/voice-y.png" mode="">
  27. </image>
  28. </view>
  29. <view class="voice-box-left" v-else-if="item.msg_type == 2">
  30. <image @click="voiceTwo" v-if="!voiceShwo" class="voice-img"
  31. src="@/static/img/chat/voice-n-two.png" mode=""></image>
  32. <image @click="voice(true,item)" v-else class="voice-img"
  33. src="@/static/img/chat/voice-y-two.png" mode="">
  34. </image>
  35. </view>
  36. <image v-if="item.msg_type == 2" class="voice-box-right"
  37. src="../../static/img/chat/voice-img.png" mode="">
  38. </image>
  39. <image v-else class="voice-box-right" src="../../static/img/chat/voice-two-img.png" mode="">
  40. </image>
  41. </view>
  42. </view>
  43. <view class="dialogue-text dialogue-text-one loading " v-if="item.msg_type == 2 && showText ==''">
  44. <text></text>
  45. <text></text>
  46. <text></text>
  47. <text></text>
  48. </view>
  49. <view class="initial-box dialogue-text-one" v-if="item.msg_type == 3">
  50. <view class="initial-title">
  51. {{item.title}}
  52. </view>
  53. <view class="initial-style" v-for="(itemTwo,indexTwo) in item.text" :key="indexTwo"
  54. @click="selectStyle(itemTwo.type)">
  55. {{itemTwo.msg}}
  56. </view>
  57. </view>
  58. </view>
  59. <view class="dialogue">
  60. <view class="diaologue-img-box" v-if="item.img_url">
  61. <image class="diaologue-img" @click="lookImg(item.img_url)" :src="item.img_url" mode="aspectFill">
  62. </image>
  63. </view>
  64. </view>
  65. <view class="dialogue">
  66. <view class="diaologue-file-box" v-if="item.file_url">
  67. <image class="diaologue-file-img" src="@/static/img/chat/wj-img.png" mode="aspectFill"></image>
  68. <view class="diaologue-file-name-box">
  69. <view class="diaologue-file-name">
  70. {{fileName(item.file_url)}}
  71. </view>
  72. <!-- <view class="diaologue-file-time">
  73. 2023-12-15
  74. </view> -->
  75. </view>
  76. </view>
  77. </view>
  78. </view>
  79. </view>
  80. </template>
  81. <script>
  82. import tools from '@/service/tools'
  83. export default {
  84. props: {
  85. item: {
  86. default: function() {
  87. return ''
  88. }
  89. },
  90. msgText: {
  91. default: function() {
  92. return ''
  93. }
  94. },
  95. showType: {
  96. default: function() {
  97. return false
  98. }
  99. }
  100. },
  101. data() {
  102. return {
  103. showText: '',
  104. num: 1,
  105. id: '',
  106. voiceShwo: true,
  107. voiceUrl: '',
  108. voiceStyle: true,
  109. };
  110. },
  111. watch: {
  112. 'msgText': function() {
  113. if (this.msgText !== '') {
  114. this.setText()
  115. }
  116. }
  117. },
  118. mounted() {
  119. this.setText()
  120. },
  121. methods: {
  122. copy(value) {
  123. uni.setClipboardData({
  124. data: value,
  125. success() {
  126. tools.success('复制成功')
  127. },
  128. fail() {
  129. tools.error("复制失败")
  130. }
  131. })
  132. },
  133. voice(bur, id) {
  134. if (this.voiceStyle) {
  135. this.voiceUrl = uni.createInnerAudioContext();
  136. this.voiceUrl.autoplay = true;
  137. this.voiceUrl.src = this.item.voice_url;
  138. this.voiceUrl.play();
  139. this.voiceShwo = false;
  140. } else {
  141. this.voiceUrl.play();
  142. this.voiceShwo = false;
  143. };
  144. this.voiceUrl.onEnded((res) => {
  145. this.voiceShwo = true;
  146. this.voiceStyle = true
  147. })
  148. },
  149. voiceTwo() {
  150. this.voiceUrl.pause();
  151. this.voiceShwo = true;
  152. this.voiceStyle = false
  153. },
  154. fileName(item) {
  155. let fileName = item.match(/\/([^\/]+)$/)[1];
  156. return fileName
  157. },
  158. lookImg(item) {
  159. let imgList = []
  160. imgList.push(item)
  161. uni.previewImage({
  162. current: 0,
  163. urls: imgList,
  164. });
  165. },
  166. selectStyle(type) {
  167. this.$emit('selectStyle', type)
  168. },
  169. setText() {
  170. if (this.showType) {
  171. this.appear(this.msgText)
  172. } else {
  173. // console.log('---------------------------------'+this.msgText)
  174. // this.showText = this.msgText.replace(/\/n/g, 'aaaaa');
  175. this.showText = this.msgText;
  176. // console.log(this.showText)
  177. }
  178. },
  179. appear(content) {
  180. if (content === '') {
  181. return
  182. }
  183. const _this = this;
  184. this.showText = "";
  185. clearTimeout(this.timer);
  186. let speed = 50; //设置定时的速度 越来越快
  187. let count = 1;
  188. content = content.replace(/\/n/g, '<br/>');
  189. // console.log(content)
  190. let num = 1;
  191. function changeContent() {
  192. _this.showText = content.substring(0, count); //截取字符串
  193. count++;
  194. if (count !== content.length + 1) {
  195. speed -= 1;
  196. if (speed < 5) speed = 5;
  197. _this.timer = setTimeout(changeContent, speed);
  198. if (_this.showText.length % 100 === 0) _this.$emit('refresh', false)
  199. } else {
  200. console.log("执行");
  201. _this.$emit('refresh', true)
  202. }
  203. }
  204. changeContent();
  205. },
  206. }
  207. }
  208. </script>
  209. <style lang="scss">
  210. .fz-class {
  211. padding: 5rpx 0 0;
  212. }
  213. .loading {
  214. width: auto;
  215. height: 15rpx;
  216. display: flex;
  217. align-items: center;
  218. padding: 17rpx 30rpx;
  219. }
  220. .loading text {
  221. // display: inline-block;
  222. width: 15rpx;
  223. height: 15rpx;
  224. margin-right: 5px;
  225. border-radius: 50%;
  226. background: #F2BA0B;
  227. -webkit-animation: load 1.04s ease infinite;
  228. }
  229. .loading text:last-child {
  230. margin-right: 0px;
  231. }
  232. @-webkit-keyframes load {
  233. 0% {
  234. opacity: 1;
  235. }
  236. 100% {
  237. opacity: 0;
  238. }
  239. }
  240. .loading text:nth-child(1) {
  241. -webkit-animation-delay: 0.13s;
  242. }
  243. .loading text:nth-child(2) {
  244. -webkit-animation-delay: 0.26s;
  245. }
  246. .loading text:nth-child(3) {
  247. -webkit-animation-delay: 0.39s;
  248. }
  249. .loading text:nth-child(4) {
  250. -webkit-animation-delay: 0.52s;
  251. }
  252. .dialogue-box {
  253. // width: 100%;
  254. height: auto;
  255. margin: 0 0 40rpx 0;
  256. display: flex;
  257. flex-direction: column;
  258. .time {
  259. font-size: 24rpx;
  260. color: #999999;
  261. margin: 0 0 8rpx 0;
  262. }
  263. .dialogue {
  264. // word-break: break-all;
  265. // font-size: 30rpx;
  266. .dialogue-text {
  267. padding: 24rpx;
  268. box-sizing: border-box;
  269. white-space: pre-wrap;
  270. .voice-box {
  271. padding: 20rpx 0 0 0;
  272. display: flex;
  273. align-items: center;
  274. .voice-box-left {
  275. .voice-img {
  276. width: 48rpx;
  277. height: 48rpx;
  278. margin: 0 16rpx 0 0;
  279. }
  280. }
  281. .voice-box-right {
  282. width: 120rpx;
  283. height: 26rpx;
  284. }
  285. }
  286. }
  287. .showText-color-one {
  288. color: #333333;
  289. }
  290. .showText-color-two {
  291. color: #FFFFFF;
  292. }
  293. .diaologue-img-box {
  294. max-width: 638rpx;
  295. height: auto;
  296. background: #fff;
  297. margin: 8rpx 0 0 0;
  298. .diaologue-img {
  299. border-radius: 20rpx;
  300. }
  301. }
  302. .diaologue-file-box {
  303. display: flex;
  304. align-items: center;
  305. padding: 24rpx;
  306. box-sizing: border-box;
  307. // background: #fff;
  308. border: 2rpx solid #EEEEEE;
  309. border-radius: 10rpx;
  310. margin: 8rpx 0 0 0;
  311. .diaologue-file-img {
  312. width: 63rpx;
  313. height: 77rpx;
  314. margin: 0 16rpx 0 0;
  315. }
  316. .diaologue-file-name-box {
  317. .diaologue-file-name {
  318. max-width: 534rpx;
  319. font-size: 30rpx;
  320. color: #323333;
  321. margin: 0 0 4rpx 0;
  322. white-space: nowrap;
  323. text-overflow: ellipsis;
  324. overflow: hidden;
  325. word-break: break-all;
  326. }
  327. .diaologue-file-time {
  328. font-size: 24rpx;
  329. color: #999999;
  330. }
  331. }
  332. }
  333. .dialogue-text-one {
  334. background: #F7F8FC;
  335. border-radius: 10rpx 10rpx 10rpx 0;
  336. }
  337. .dialogue-text-two {
  338. background: #5CC2FF;
  339. border-radius: 10rpx 10rpx 0 10rpx;
  340. max-width: 592rpx;
  341. }
  342. .initial-box {
  343. padding: 24rpx;
  344. box-sizing: border-box;
  345. .initial-title {
  346. font-size: 30rpx;
  347. font-weight: 600;
  348. color: #333333;
  349. // margin: 0 0 12rpx 0;
  350. padding: 0 0 12rpx 0;
  351. }
  352. .initial-style {
  353. font-size: 30rpx;
  354. color: #2F80ED;
  355. margin: 0 0 12rpx 0;
  356. }
  357. .initial-style:last-child {
  358. margin: 0;
  359. }
  360. }
  361. }
  362. }
  363. .dialogue-box-one {
  364. align-items: flex-start;
  365. }
  366. .dialogue-box-two {
  367. align-items: flex-end;
  368. }
  369. </style>