msg-item.vue 9.4 KB

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