knowledge-select.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <template>
  2. <CzrDialog
  3. :show="show"
  4. title="选择知识库"
  5. @onClose="$emit('update:show', false)"
  6. @onSubmit="onSubmit"
  7. width="62.5rem"
  8. height="auto"
  9. :loading="state.loading"
  10. >
  11. <div class="bm-form">
  12. <template v-for="item in state.list">
  13. <div
  14. class="knowledge-item __hover"
  15. :class="{ active: item.id == state.active.id }"
  16. @click="() => (state.active = item)"
  17. >
  18. <img src="@/assets/images/answer.png" />
  19. <div v-title>{{ item.name }}</div>
  20. </div>
  21. </template>
  22. </div>
  23. </CzrDialog>
  24. </template>
  25. <script setup lang="ts">
  26. import {
  27. computed,
  28. getCurrentInstance,
  29. nextTick,
  30. reactive,
  31. ref,
  32. watch,
  33. } from 'vue'
  34. import { ElMessage, ElMessageBox } from 'element-plus'
  35. import { useDialogStore, useDictionaryStore } from '@/stores'
  36. import { useRouter } from 'vue-router'
  37. const router = useRouter()
  38. const DictionaryStore = useDictionaryStore()
  39. const DialogStore = useDialogStore()
  40. const emit = defineEmits(['update:show', 'refresh'])
  41. const { proxy } = getCurrentInstance()
  42. const props = defineProps({
  43. show: { default: false },
  44. transfer: <any>{},
  45. })
  46. const state: any = reactive({
  47. loading: false,
  48. list: [],
  49. active: '',
  50. })
  51. watch(
  52. () => props.show,
  53. (n) => {
  54. if (n) {
  55. initDictionary()
  56. }
  57. },
  58. )
  59. const initDictionary = () => {
  60. const arr: any = []
  61. for (let i = 1; i <= 100; i++) {
  62. arr.push({
  63. id: i,
  64. name: '部门知识库-新_' + i,
  65. })
  66. }
  67. state.list = arr
  68. }
  69. const onSubmit = () => {
  70. let tips = '请确认是否将'
  71. if (props.transfer.row) {
  72. tips += props.transfer.row.name
  73. } else {
  74. tips += props.transfer.list.length + '个'
  75. if (props.transfer.type === 'text') {
  76. tips += '文档'
  77. } else if (props.transfer.type === 'qa') {
  78. tips += '问答'
  79. } else if (props.transfer.type === 'stage') {
  80. tips += '分段'
  81. }
  82. }
  83. tips += `迁移至${state.active.name}?`
  84. if (state.active.id) {
  85. DialogStore.confirm({
  86. content: tips,
  87. onSubmit: () => {
  88. state.loading = true
  89. ElMessage.success(`迁移成功!`)
  90. emit('update:show', false)
  91. emit('refresh')
  92. state.loading = false
  93. },
  94. })
  95. } else {
  96. ElMessage.warning(`请选择知识库!`)
  97. }
  98. }
  99. </script>
  100. <style lang="scss" scoped>
  101. .bm-form {
  102. display: grid;
  103. grid-template-columns: repeat(2, 1fr);
  104. gap: 1rem;
  105. max-height: 36rem;
  106. overflow-y: auto;
  107. .knowledge-item {
  108. height: 5.25rem;
  109. box-shadow: 0rem 0.25rem 0.63rem 0rem rgba(40, 83, 247, 0.05);
  110. border-radius: 0.63rem;
  111. border: var(--czr-border);
  112. display: flex;
  113. align-items: center;
  114. padding: 0 1.5rem;
  115. font-weight: bold;
  116. font-size: 1.25rem;
  117. color: #2e3238;
  118. gap: 1rem;
  119. > img {
  120. width: 2.13rem;
  121. height: 2.12rem;
  122. }
  123. &.active {
  124. background: #f3f5fe;
  125. box-shadow: 0rem 0.25rem 0.63rem 0rem rgba(40, 83, 247, 0.05);
  126. border-color: var(--czr-main-color);
  127. }
  128. }
  129. }
  130. </style>