ConversationBoardContainer.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. <template>
  2. <div class="conversation-board-container">
  3. <div class="conversation-board-left"></div>
  4. <div class="conversation-board-main">
  5. <BoardWelcome />
  6. <BoardTags @change="handleTagChange" />
  7. <template v-if="api_status === 2">
  8. <div class="infomations-container">
  9. <a-spin :size="32" />
  10. </div>
  11. </template>
  12. <template v-if="api_status === 3">
  13. <BoardAgentList @itemActive="handleItemActive" :list="list_agents" />
  14. <div class="infomations-container" v-if="list_agents.length === 0">
  15. <a-empty> {{ $t('conversation.history_empty') }} </a-empty>
  16. </div>
  17. </template>
  18. <template v-if="api_status === 4">
  19. <div class="infomations-container">
  20. <a-result status="warning" :title="api_message"> </a-result>
  21. </div>
  22. </template>
  23. <template v-if="api_status === 5">
  24. <div class="infomations-container">
  25. <a-result status="error" :title="api_message"> </a-result>
  26. </div>
  27. </template>
  28. <div class="conversation-board-placeholder"></div>
  29. </div>
  30. <div class="conversation-board-right"></div>
  31. </div>
  32. </template>
  33. <script setup>
  34. import { ref, onMounted } from 'vue';
  35. import BoardWelcome from '../../modules/conversation-board/BoardWelcome.vue';
  36. import BoardTags from '../../modules/conversation-board/BoardTags.vue';
  37. import BoardAgentList from '../../modules/conversation-board/BoardAgentList.vue';
  38. import { conversationBoardAgentList } from '../../modules/conversation-board/api-conversation-board';
  39. import { useAllAgentStore } from '../../base/store/use-all-agents';
  40. const emit = defineEmits(['agentActive']);
  41. const selected_id = ref('');
  42. // api请求的状态
  43. const api_status = ref(1); // api状态 1 请求未启动 2 请求进心中 3 请求已成功 4 请求失败(网络成功,但是code不等于200) 5 请求出错
  44. const api_message = ref(''); // 请求消息 与 api_status 对应的 message 消息内容
  45. // 历史记录列表数据
  46. const list_agents = ref([]); // 历史记录的列表数据
  47. // store中保存的agents
  48. const allAgents = useAllAgentStore();
  49. const handleTagChange = (tag_id) => {
  50. selected_id.value = tag_id;
  51. handleApiRequest();
  52. };
  53. const handleItemActive = (target_id) => {
  54. emit('agentActive', target_id);
  55. };
  56. /**
  57. * 处理请求参数
  58. */
  59. const formatListOptions = () => {
  60. const obj = {};
  61. if (selected_id.value) {
  62. obj.label = selected_id.value;
  63. }
  64. return obj;
  65. };
  66. /**
  67. * 调用api请求
  68. */
  69. const handleApiRequest = () => {
  70. // const cache_agents = allAgents.agents;
  71. // if (cache_agents.length !== 0) {
  72. // list_agents.value = cache_agents;
  73. // return;
  74. // }
  75. // 处理查询参数
  76. const opts = formatListOptions();
  77. // 进入加载状态
  78. api_status.value = 2;
  79. api_message.value = '';
  80. conversationBoardAgentList(opts)
  81. .then((res) => {
  82. if (res.code / 1 === 200) {
  83. // 成功
  84. const res_list = res.data; // 历史记录列表
  85. list_agents.value = res_list;
  86. // // 在store中缓存数据
  87. // allAgents.setList(res_list);
  88. // api请求成功
  89. api_status.value = 3;
  90. api_message.value = 'success';
  91. } else {
  92. // api请求成功,但是业务失败
  93. api_status.value = 4;
  94. api_message.value = res.msg;
  95. }
  96. })
  97. .catch((err) => {
  98. console.log(err);
  99. // api请求出错
  100. api_status.value = 5;
  101. api_message.value = err.message;
  102. });
  103. };
  104. onMounted(() => {
  105. // 调用api
  106. handleApiRequest();
  107. });
  108. </script>
  109. <style lang="css" scoped>
  110. .conversation-board-container {
  111. display: flex;
  112. justify-content: center;
  113. margin-left: auto;
  114. margin-right: auto;
  115. }
  116. .conversation-board-left {
  117. width: 25%;
  118. flex-shrink: 0;
  119. }
  120. .conversation-board-right {
  121. width: 25%;
  122. flex-shrink: 0;
  123. }
  124. .conversation-board-main {
  125. /* width: 60%; */
  126. flex-grow: 1;
  127. height: 100%;
  128. margin-left: auto;
  129. margin-right: auto;
  130. margin-top: 150px;
  131. display: flex;
  132. flex-direction: column;
  133. justify-content: center;
  134. }
  135. /* 底部占位元素 */
  136. .conversation-board-placeholder {
  137. height: 50px;
  138. }
  139. .conversation-board-main .infomations-container {
  140. display: flex;
  141. justify-content: center;
  142. align-items: center;
  143. min-height: 200px;
  144. }
  145. </style>