index3.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <script setup>
  2. import { ref, onMounted, watch } from 'vue';
  3. import { NButton, NSpace, NDrawer, NDrawerContent, NCard } from 'naive-ui';
  4. import { ChatAsk, ChatAnswer } from '@/components/Chat';
  5. import allBookData from "./all_book3.json";
  6. const dataSource = ref([]);
  7. const errIds = ref([]);
  8. const visible = ref(false);
  9. const pageNum = ref(0);
  10. const pageSize = 10;
  11. const totalPages = Math.ceil(allBookData.length / pageSize);
  12. watch(pageNum, (num) => {
  13. dataSource.value = allBookData.slice((num - 1) * pageSize, num * pageSize).map(item => ({
  14. ...item,
  15. isDisable: errIds.value.includes(item.id),
  16. history: [
  17. ...item.history,
  18. [item.instruction, item.output]
  19. ]
  20. }))
  21. })
  22. const changeVisible = () => {
  23. visible.value = !visible.value;
  24. }
  25. const handleNextPage = () => {
  26. if ( pageNum.value === totalPages ) return alert("已经是最后一页了");
  27. pageNum.value += 1;
  28. localStorage.setItem('pageNum', pageNum.value)
  29. }
  30. const handleError = item => {
  31. item.isDisable = true;
  32. errIds.value.push(item.id);
  33. localStorage.setItem('errIds', JSON.stringify( errIds.value ));
  34. }
  35. onMounted(() => {
  36. const localIds = localStorage.getItem('errIds');
  37. const localNum = localStorage.getItem('pageNum');
  38. const ids = localIds ? JSON.parse(localIds) : [];
  39. const num = localNum ? Number(localNum) : 1;
  40. errIds.value = ids;
  41. pageNum.value = num;
  42. })
  43. </script>
  44. <template>
  45. <section class="page-container">
  46. <header class="header flex items-center">
  47. <NSpace>
  48. <n-button @click="handleNextPage">下一页</n-button>
  49. <n-button @click="changeVisible">显示错误id</n-button>
  50. </NSpace>
  51. <p class="ml-[30px] space-x-[10px]">
  52. <span>{{ pageNum }}</span>
  53. <span> / </span>
  54. <span>{{ totalPages }}</span>
  55. </p>
  56. </header>
  57. <div class="main">
  58. <NCard :title="item.id" v-for="item in dataSource" :key="item.id" class="mb-[20px]">
  59. <div v-for="arr, i in item.history" :key="i + item.id" class="pt-[40px]">
  60. <ChatAsk :content="arr[0]"></ChatAsk>
  61. <ChatAnswer :content="arr[1]" :toggleVisibleIcons="false"></ChatAnswer>
  62. <hr>
  63. </div>
  64. <div class="answer-btns pt-[20px]">
  65. <NSpace>
  66. <NButton :type="item.isDisable? '' : 'error'" @click="handleError(item)" :disabled="item.isDisable">
  67. {{ item.isDisable ? '已审核' : '错' }}
  68. </NButton>
  69. </NSpace>
  70. </div>
  71. </NCard>
  72. </div>
  73. </section>
  74. <NDrawer placement="right" v-model:show="visible" width="800" title="错误ID">
  75. <n-drawer-content :title="'错误ID列表 -- ' + errIds.length + ' 个'">
  76. <!-- <div class="py-[30px]">{{ errIds.join(',') }}</div> -->
  77. <!-- <hr> -->
  78. <ul class="grid grid-cols-5">
  79. <li v-for="item in errIds" :key="item">{{ item }}</li>
  80. </ul>
  81. </n-drawer-content>
  82. </NDrawer>
  83. </template>
  84. <style lang="scss" scoped>
  85. .page-container {
  86. width: 100vw;
  87. height: 100vh;
  88. background: #edf7fc;
  89. .header {
  90. display: flex;
  91. justify-content: center;
  92. padding: 20px 0;
  93. background: #fff;
  94. }
  95. .main {
  96. width: 1000px;
  97. height: calc(100% - 74px);
  98. margin: 0 auto;
  99. overflow-y: scroll;
  100. .answer-block {
  101. border-bottom: 1px solid #000000;
  102. padding-bottom: 20px;
  103. }
  104. .answer-btns {
  105. display: flex;
  106. justify-content: flex-end;
  107. }
  108. }
  109. }
  110. </style>