history.vue 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <template>
  2. <view>
  3. <cu-custom bgColor="bg-cyan" :isBack="true">
  4. <block slot="backText">返回</block>
  5. <block slot="content">聊天历史</block>
  6. </cu-custom>
  7. <view class="cu-chat">
  8. <block v-for="(x,i) in msgList" :key="i">
  9. <!-- 用户消息 -->
  10. <view v-if="x.my && x.type === 'msg'" class="cu-item self" :class="[i === 0 ? 'first' : '', i === 1 ? 'sec' : '']">
  11. <view class="main">
  12. <view class="content bg-cyan shadow" @click="x.msg && $squni.copy(x.msg)">
  13. <text>{{ x.msg }}</text>
  14. </view>
  15. </view>
  16. <image class="cu-avatar round" src="/static/logo-100.png">
  17. <view v-if="i === 0" class="date">{{ x.date }}</view>
  18. </view>
  19. <!-- AI消息 -->
  20. <view v-if="!x.my && x.type === 'msg'" class="cu-item" :class="[i === 0 ? 'first' : '', i === 1 ? 'sec' : '']">
  21. <image class="cu-avatar round chat-avatar" src="/static/robot.png">
  22. <view class="main">
  23. <view class="content shadow" @click="x.msg && $squni.copy(x.msg)">
  24. <text>{{ x.msg }}</text>
  25. </view>
  26. </view>
  27. <view v-if="i === 0" class="date">{{ x.date }}</view>
  28. </view>
  29. <view v-if="x.type === 'error'" class="cu-info">
  30. <text class="cuIcon-roundclosefill text-red "></text> {{ x.msg }}
  31. </view>
  32. </block>
  33. <view v-if="msgList.length === 0" class="text-center gray margin-top">无历史聊天记录</view>
  34. </view>
  35. </view>
  36. </template>
  37. <script>
  38. export default {
  39. data() {
  40. return {
  41. msgList: []
  42. }
  43. },
  44. onShow() {
  45. this.msgList = this.$squni.getStorageSync('chatHistory') || []
  46. },
  47. methods: {
  48. }
  49. }
  50. </script>
  51. <style>
  52. page {
  53. padding-bottom: 200upx;
  54. }
  55. .cu-item:not(.first) {
  56. padding-bottom: 0upx;
  57. }
  58. .cu-item.sec {
  59. padding-top: 0upx;
  60. }
  61. .main .content {
  62. word-wrap: break-word;
  63. }
  64. .cu-chat .cu-item>.main {
  65. max-width: calc(100% - 160upx);
  66. }
  67. </style>