TopSetting.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <template>
  2. <a-space size="large">
  3. <a-input
  4. v-model="searchText"
  5. :placeholder="$t('management.search')"
  6. style="width: 300px"
  7. allow-clear
  8. @input="handleSearch"
  9. >
  10. <template #prefix>
  11. <icon-search />
  12. </template>
  13. </a-input>
  14. <a-button v-hasPermi="'system:knowledge:add'" type="primary" size="large" @click="handleCreate">
  15. <template #icon>
  16. <icon-plus />
  17. </template>
  18. {{ $t('management.createKnowledgeBase') }}
  19. </a-button>
  20. </a-space>
  21. <ModalCreateKb v-model:visible="visible" :target_icon="target_icon" @select_icon="selectIcon"></ModalCreateKb>
  22. <ModalSelectIcon
  23. v-model:show_select_icon="show_select_icon"
  24. :target_icon="target_icon"
  25. @sendIcon="sendIcon"
  26. @clearTargetIcon="clearTargetIcon"
  27. ></ModalSelectIcon>
  28. </template>
  29. <script setup>
  30. import { ref, onUnmounted } from 'vue';
  31. // import { Message } from '@arco-design/web-vue';
  32. import { Message } from '../../3rd-libs/arco-vue-libs';
  33. import ModalCreateKb from './ModalCreateKb.vue';
  34. import ModalSelectIcon from './ModalSelectIcon.vue';
  35. import { funcDebounce } from '../../utils/utils';
  36. import { bus_knowledgeSearch, bus_knowledgeIconEdit } from '../../base/event-bus';
  37. import { updateOwnKnowledgeIcon } from '../../apis/knowledge';
  38. import { useI18n } from 'vue-i18n';
  39. const { t } = useI18n();
  40. const searchText = ref('');
  41. // 模态框控制
  42. const visible = ref(false);
  43. const show_select_icon = ref(false);
  44. const target_icon = ref('');
  45. const edit_icon_data = ref(null);
  46. // 搜索
  47. const handleSearch = funcDebounce(
  48. () => {
  49. bus_knowledgeSearch.emit(searchText.value);
  50. },
  51. 300,
  52. false
  53. );
  54. // 创建知识库
  55. const handleCreate = () => {
  56. visible.value = true;
  57. };
  58. const selectIcon = () => {
  59. show_select_icon.value = true;
  60. };
  61. const sendIcon = (icon) => {
  62. console.log(icon);
  63. target_icon.value = icon;
  64. console.log(target_icon);
  65. if (!edit_icon_data.value) return;
  66. // 编辑
  67. updateOwnKnowledgeIcon(edit_icon_data.value.id, target_icon.value)
  68. .then((res) => {
  69. if (res.code == 200) {
  70. Message.success(t('management.edit_success'));
  71. } else {
  72. Message.error(t('management.edit_fail'));
  73. }
  74. })
  75. .catch(() => {
  76. Message.error(t('management.edit_fail'));
  77. })
  78. .finally(() => {
  79. target_icon.value = '';
  80. // 更新知识库列表
  81. bus_knowledgeSearch.emit(searchText.value);
  82. edit_icon_data.value = null;
  83. });
  84. };
  85. const clearTargetIcon = () => {
  86. target_icon.value = '';
  87. edit_icon_data.value = null;
  88. };
  89. bus_knowledgeIconEdit.on((item) => {
  90. show_select_icon.value = true;
  91. edit_icon_data.value = item;
  92. target_icon.value = item.icon;
  93. });
  94. onUnmounted(() => {
  95. bus_knowledgeIconEdit.off();
  96. });
  97. </script>
  98. <style scoped lang="css">
  99. .arco-input-wrapper {
  100. background-color: var(--color-bg-5);
  101. }
  102. </style>