HistoryItem.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. <template>
  2. <div v-if="is_label_item" :class="item_klass">
  3. <template v-if="history.client_field_timestamp_type === 'today'">{{ $t('conversation.history_today') }}</template>
  4. <template v-if="history.client_field_timestamp_type === 'month'">{{ $t('conversation.history_month') }}</template>
  5. <template v-if="history.client_field_timestamp_type === 'earlier'">{{
  6. $t('conversation.history_earlier')
  7. }}</template>
  8. </div>
  9. <div v-if="show_current_item" :class="item_klass">
  10. <div class="history-item-icon" @click="handleClick">
  11. <!-- <img :src="history_icon" /> -->
  12. <img :src="agent_icon" />
  13. </div>
  14. <div class="history-item-intro">
  15. <div class="history-item-intro-title" @click="handleClick">{{ history.name }}</div>
  16. </div>
  17. <div class="history-item-actions">
  18. <span class="history-item-time">{{ time_display }}</span>
  19. <span class="history-item-delete">
  20. <BtnHistoryItemDelete :target_id="history.id" @deleteSuccess="handleDeleteSuccess" />
  21. </span>
  22. </div>
  23. </div>
  24. </template>
  25. <script setup>
  26. import { ref, computed } from 'vue';
  27. import { formatTimestamp2Hours, formatTimestamp2Weekend, formatTimestamp2Date } from '../../utils/datetime';
  28. import { useLocaleStore } from '../../base/store/use-locale';
  29. import { getIcon4Question } from '../conversation-dialog/get-icon-4-dialog';
  30. import BtnHistoryItemDelete from './BtnHistoryItemDelete.vue';
  31. const props = defineProps({
  32. history: Object,
  33. index: Number,
  34. agent_icon: String
  35. });
  36. const emit = defineEmits(['active', 'delete']);
  37. const is_deleted = ref(false);
  38. const history_icon = getIcon4Question();
  39. /**
  40. * history示例数据
  41. * ------------------------------------------------
  42. {
  43. app_type: 1,
  44. base: null,
  45. create_date: 'Mon, 09 Dec 2024 06:09:32 GMT',
  46. create_time: 1733724572892,
  47. dialog_id: '7f0e55765afb11ef8d760242ac120006',
  48. icon: '',
  49. id: '288f9882b5f411efa2ac0242ac120005',
  50. name: '\u5982\u4f55\u521b\u5efa\u65b0\u4f1a\u8bdd\u554a',
  51. update_date: 'Mon, 09 Dec 2024 06:10:23 GMT',
  52. update_time: 1733724623307,
  53. user_id: '9f5fbce754ac11ef8857f0d4e2e8b768',
  54. client_field_content_type: 'content',
  55. client_field_timestamp_type: 'month'
  56. }
  57. * ------------------------------------------------------
  58. */
  59. const locale = useLocaleStore();
  60. const is_label_item = computed(() => {
  61. return props.history.client_field_content_type === 'label';
  62. });
  63. const is_data_item = computed(() => {
  64. return props.history.client_field_content_type === 'content';
  65. });
  66. // 是否显示当前的数据项目
  67. const show_current_item = computed(() => {
  68. return is_data_item.value && !is_deleted.value;
  69. });
  70. const item_klass = computed(() => {
  71. const obj = {
  72. 'conversation-history-item': true
  73. };
  74. obj[`item-${props.index}`] = true; // 绑定序号
  75. obj[`item-${props.history.id}`] = true; // 绑定唯一ID
  76. obj[props.history.client_field_timestamp_type] = true;
  77. if (is_label_item.value) {
  78. obj['conversation-history-section-title'] = true;
  79. }
  80. if (is_data_item.value) {
  81. obj['conversation-history-section-data'] = true;
  82. }
  83. return obj;
  84. });
  85. /**
  86. * 格式化时间的展示
  87. */
  88. const time_display = computed(() => {
  89. const p_tp = props.history.client_field_timestamp_type; // 列表的类别
  90. const tm_stp = props.history.create_time; // 数据项目的创建时间戳
  91. const cur_locale_value = locale.value;
  92. if (p_tp === 'today') {
  93. return formatTimestamp2Hours(tm_stp, cur_locale_value);
  94. }
  95. if (p_tp === 'month') {
  96. return formatTimestamp2Weekend(tm_stp, cur_locale_value);
  97. }
  98. if (p_tp === 'earlier') {
  99. return formatTimestamp2Date(tm_stp, cur_locale_value);
  100. }
  101. return '';
  102. });
  103. /**
  104. * 点击事件
  105. * 分发ID值
  106. */
  107. const handleClick = () => {
  108. emit('active', props.history.id);
  109. };
  110. const handleItemDelete = () => {
  111. emit('delete', props.history.id);
  112. };
  113. const handleDeleteSuccess = () => {
  114. is_deleted.value = true;
  115. };
  116. </script>
  117. <style lang="css" scoped>
  118. .conversation-history-section-title {
  119. font-size: 20px;
  120. font-weight: bold;
  121. margin-top: 16px;
  122. margin-bottom: 16px;
  123. color: var(--color-text-1);
  124. }
  125. .conversation-history-item {
  126. /* padding: 30px 40px 30px 40px; */
  127. display: flex;
  128. justify-content: space-between;
  129. align-items: center;
  130. }
  131. .conversation-history-section-data {
  132. background-color: var(--color-bg-1);
  133. padding: 20px 20px 20px 20px;
  134. border-radius: 15px;
  135. margin-top: 10px;
  136. margin-bottom: 10px;
  137. color: var(--color-text-1);
  138. }
  139. .conversation-history-section-data:hover {
  140. /* box-shadow: 0 0 5px var(--color-text-1); */
  141. box-shadow: 0 0 5px var(--color-text-4);
  142. }
  143. .conversation-history-section-data:hover .history-item-time {
  144. display: none;
  145. }
  146. .conversation-history-section-data:hover .history-item-delete {
  147. display: inline-block;
  148. }
  149. .history-item-icon {
  150. width: 20px;
  151. height: 20px;
  152. /* background-color: #ccc; */
  153. /* border-radius: 18px; */
  154. margin-right: 13px;
  155. cursor: pointer;
  156. flex-shrink: 0;
  157. }
  158. .history-item-icon img {
  159. width: 100%;
  160. }
  161. .history-item-intro {
  162. display: flex;
  163. align-items: center;
  164. flex-grow: 1;
  165. }
  166. .history-item-intro-title {
  167. font-size: 14px;
  168. font-weight: 400;
  169. line-height: 19.6px;
  170. cursor: pointer;
  171. /* margin-bottom: 8px; */
  172. }
  173. .history-item-intro-desc {
  174. }
  175. .history-item-actions {
  176. min-width: 60px;
  177. flex-shrink: 0;
  178. text-align: center;
  179. }
  180. .history-item-time {
  181. }
  182. .history-item-delete {
  183. display: none;
  184. cursor: pointer;
  185. }
  186. </style>