history.vue 1.9 KB

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