|
@@ -2,14 +2,17 @@
|
|
|
<PagingTable url="/knowledge/base" :where="where" ref="table">
|
|
<PagingTable url="/knowledge/base" :where="where" ref="table">
|
|
|
<template #filter>
|
|
<template #filter>
|
|
|
<ElButton :icon="Plus" @click="onEdit()">添加</ElButton>
|
|
<ElButton :icon="Plus" @click="onEdit()">添加</ElButton>
|
|
|
|
|
+ <ElButton :icon="Refresh" @click="table.refresh()"></ElButton>
|
|
|
</template>
|
|
</template>
|
|
|
<ElTableColumn prop="id" label="#" width="80" />
|
|
<ElTableColumn prop="id" label="#" width="80" />
|
|
|
<ElTableColumn prop="name" label="名称" />
|
|
<ElTableColumn prop="name" label="名称" />
|
|
|
<ElTableColumn prop="description" label="描述" />
|
|
<ElTableColumn prop="description" label="描述" />
|
|
|
|
|
+ <ElTableColumn prop="orgId" label="企业ID" />
|
|
|
<ElTableColumn prop="createdAt" label="创建时间" :formatter="timeFormatter" width="150" />
|
|
<ElTableColumn prop="createdAt" label="创建时间" :formatter="timeFormatter" width="150" />
|
|
|
- <ElTableColumn label="操作" align="center" width="160">
|
|
|
|
|
|
|
+ <ElTableColumn label="操作" align="center" width="200">
|
|
|
<template #default="{ row }">
|
|
<template #default="{ row }">
|
|
|
<ElButton @click="onEdit(row)">编辑</ElButton>
|
|
<ElButton @click="onEdit(row)">编辑</ElButton>
|
|
|
|
|
+ <ElButton @click="showFiles(row)">文件</ElButton>
|
|
|
<ElButton @click="deleteRow(row)" type="danger">删除</ElButton>
|
|
<ElButton @click="deleteRow(row)" type="danger">删除</ElButton>
|
|
|
</template>
|
|
</template>
|
|
|
</ElTableColumn>
|
|
</ElTableColumn>
|
|
@@ -21,40 +24,43 @@
|
|
|
<ElFormItem prop="description" label="描述">
|
|
<ElFormItem prop="description" label="描述">
|
|
|
<ElInput v-model="model.description" placeholder="请输入描述" />
|
|
<ElInput v-model="model.description" placeholder="请输入描述" />
|
|
|
</ElFormItem>
|
|
</ElFormItem>
|
|
|
|
|
+ <ElFormItem prop="orgId" label="企业ID" v-if="role === 'admin'">
|
|
|
|
|
+ <ElInputNumber :controls="false" v-model="model.orgId" placeholder="请输入企业ID" />
|
|
|
|
|
+ </ElFormItem>
|
|
|
</EditDialog>
|
|
</EditDialog>
|
|
|
|
|
|
|
|
- <ElDialog>
|
|
|
|
|
- <PagingTable url="/knowledge/base" :where="where" ref="table">
|
|
|
|
|
|
|
+ <ElDialog v-model="showFileDialog" :title="selectedBase?.name" width="80%">
|
|
|
|
|
+ <PagingTable url="/knowledge/file" :where="{ knowledgeId: selectedBase?.id }" ref="fileTable">
|
|
|
<template #filter>
|
|
<template #filter>
|
|
|
- <ElButton :icon="Plus" @click="onEdit()">添加</ElButton>
|
|
|
|
|
|
|
+ <ElButton :icon="Plus" @click="uploadFile()">添加</ElButton>
|
|
|
|
|
+ <ElButton :icon="Refresh" @click="fileTable.refresh()"></ElButton>
|
|
|
</template>
|
|
</template>
|
|
|
<ElTableColumn prop="id" label="#" width="80" />
|
|
<ElTableColumn prop="id" label="#" width="80" />
|
|
|
- <ElTableColumn prop="name" label="名称" />
|
|
|
|
|
- <ElTableColumn prop="description" label="描述" />
|
|
|
|
|
|
|
+ <ElTableColumn prop="orgId" label="企业ID" />
|
|
|
|
|
+ <ElTableColumn prop="knowledgeId" label="知识库ID" />
|
|
|
|
|
+ <ElTableColumn prop="fileName" label="文件名" show-overflow-tooltip />
|
|
|
|
|
+ <ElTableColumn prop="fileHash" label="文件Hash" show-overflow-tooltip />
|
|
|
|
|
+ <ElTableColumn prop="status" label="状态" align="center">
|
|
|
|
|
+ <template #default="{ row }">
|
|
|
|
|
+ <ElTag :type="fileStatusTagType(row.status)">{{
|
|
|
|
|
+ fileStatusFormatter(null, null, row.status)
|
|
|
|
|
+ }}</ElTag>
|
|
|
|
|
+ </template>
|
|
|
|
|
+ </ElTableColumn>
|
|
|
<ElTableColumn prop="createdAt" label="创建时间" :formatter="timeFormatter" width="150" />
|
|
<ElTableColumn prop="createdAt" label="创建时间" :formatter="timeFormatter" width="150" />
|
|
|
- <ElTableColumn label="操作" align="center" width="160">
|
|
|
|
|
|
|
+ <ElTableColumn label="操作" align="center" width="100">
|
|
|
<template #default="{ row }">
|
|
<template #default="{ row }">
|
|
|
- <ElButton @click="onEdit(row)">编辑</ElButton>
|
|
|
|
|
- <ElButton @click="deleteRow(row)" type="danger">删除</ElButton>
|
|
|
|
|
|
|
+ <ElButton @click="deleteFile(row)" type="danger">删除</ElButton>
|
|
|
</template>
|
|
</template>
|
|
|
</ElTableColumn>
|
|
</ElTableColumn>
|
|
|
</PagingTable>
|
|
</PagingTable>
|
|
|
</ElDialog>
|
|
</ElDialog>
|
|
|
-
|
|
|
|
|
- <EditDialog v-model="showEditDialog" :model="model" :rules="rules" :on-submit="submit" @success="table.refresh()">
|
|
|
|
|
- <ElFormItem prop="name" label="名称">
|
|
|
|
|
- <ElInput v-model="model.name" placeholder="请输入名称" />
|
|
|
|
|
- </ElFormItem>
|
|
|
|
|
- <ElFormItem prop="description" label="描述">
|
|
|
|
|
- <ElInput v-model="model.description" placeholder="请输入描述" />
|
|
|
|
|
- </ElFormItem>
|
|
|
|
|
- </EditDialog>
|
|
|
|
|
</template>
|
|
</template>
|
|
|
<script setup>
|
|
<script setup>
|
|
|
-import { ref, computed } from 'vue'
|
|
|
|
|
|
|
+import { ref, computed, nextTick } from 'vue'
|
|
|
import PagingTable from '@/components/PagingTable.vue'
|
|
import PagingTable from '@/components/PagingTable.vue'
|
|
|
-import { useTimeFormatter } from '@/utils/formatter'
|
|
|
|
|
-import { Plus } from '@vicons/tabler'
|
|
|
|
|
|
|
+import { useEnumFormatter, useTimeFormatter } from '@/utils/formatter'
|
|
|
|
|
+import { Plus, Refresh } from '@vicons/tabler'
|
|
|
import EditDialog from '@/components/EditDialog.vue'
|
|
import EditDialog from '@/components/EditDialog.vue'
|
|
|
import { setupEditDialog } from '@/utils/editDialog'
|
|
import { setupEditDialog } from '@/utils/editDialog'
|
|
|
import { http } from '@/plugins/http'
|
|
import { http } from '@/plugins/http'
|
|
@@ -62,11 +68,14 @@ import { ElMessage, ElMessageBox } from 'element-plus'
|
|
|
import { useClipboard } from '@vueuse/core'
|
|
import { useClipboard } from '@vueuse/core'
|
|
|
import { storeToRefs } from 'pinia'
|
|
import { storeToRefs } from 'pinia'
|
|
|
import { useUserStore } from '@/stores/user'
|
|
import { useUserStore } from '@/stores/user'
|
|
|
-
|
|
|
|
|
-const user = storeToRefs(useUserStore())
|
|
|
|
|
|
|
+import { FileStatus } from '@/enums'
|
|
|
|
|
+import { useFileDialog } from '@vueuse/core'
|
|
|
|
|
+const { user } = storeToRefs(useUserStore())
|
|
|
|
|
+const role = computed(() => user.value?.roles[0])
|
|
|
const where = computed(() => {
|
|
const where = computed(() => {
|
|
|
|
|
+ if (role.value === 'admin') return {}
|
|
|
return {
|
|
return {
|
|
|
- orgId: user.orgId
|
|
|
|
|
|
|
+ orgId: user.value.orgId
|
|
|
}
|
|
}
|
|
|
})
|
|
})
|
|
|
const timeFormatter = useTimeFormatter()
|
|
const timeFormatter = useTimeFormatter()
|
|
@@ -74,10 +83,14 @@ const table = ref(null)
|
|
|
const model = ref({})
|
|
const model = ref({})
|
|
|
const rules = {
|
|
const rules = {
|
|
|
name: [{ required: true, message: '请输入名称', trigger: 'blur' }],
|
|
name: [{ required: true, message: '请输入名称', trigger: 'blur' }],
|
|
|
- description: [{ required: true, message: '请输入描述', trigger: 'blur' }]
|
|
|
|
|
|
|
+ description: [{ required: true, message: '请输入描述', trigger: 'blur' }],
|
|
|
|
|
+ orgId: [{ required: true, message: '请输入企业ID', trigger: 'blur' }]
|
|
|
}
|
|
}
|
|
|
const { showEditDialog, onEdit } = setupEditDialog(model)
|
|
const { showEditDialog, onEdit } = setupEditDialog(model)
|
|
|
async function submit() {
|
|
async function submit() {
|
|
|
|
|
+ if (!model.value.orgId) {
|
|
|
|
|
+ model.value.orgId = user.value.orgId
|
|
|
|
|
+ }
|
|
|
await http.put(model.value.id ? `/knowledge/base/${model.value.id}` : '/knowledge/base', model.value)
|
|
await http.put(model.value.id ? `/knowledge/base/${model.value.id}` : '/knowledge/base', model.value)
|
|
|
ElMessage.success('保存成功')
|
|
ElMessage.success('保存成功')
|
|
|
}
|
|
}
|
|
@@ -93,4 +106,60 @@ async function deleteRow(row) {
|
|
|
if ('cancel' !== error) ElMessage.error(error.message)
|
|
if ('cancel' !== error) ElMessage.error(error.message)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+const selectedBase = ref(null)
|
|
|
|
|
+const fileTable = ref(null)
|
|
|
|
|
+function showFiles(row) {
|
|
|
|
|
+ selectedBase.value = row
|
|
|
|
|
+ showFileDialog.value = true
|
|
|
|
|
+ nextTick(() => {
|
|
|
|
|
+ fileTable.value.refresh()
|
|
|
|
|
+ })
|
|
|
|
|
+}
|
|
|
|
|
+const showFileDialog = ref(false)
|
|
|
|
|
+const fileStatusFormatter = useEnumFormatter(FileStatus)
|
|
|
|
|
+function fileStatusTagType(status) {
|
|
|
|
|
+ switch (status) {
|
|
|
|
|
+ case 'pending':
|
|
|
|
|
+ return 'info'
|
|
|
|
|
+ case 'processing':
|
|
|
|
|
+ return ''
|
|
|
|
|
+ case 'done':
|
|
|
|
|
+ return 'success'
|
|
|
|
|
+ case 'failed':
|
|
|
|
|
+ return 'danger'
|
|
|
|
|
+ default:
|
|
|
|
|
+ return 'info'
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+const uploading = ref(false)
|
|
|
|
|
+function uploadFile() {
|
|
|
|
|
+ const { files, open, reset, onChange } = useFileDialog({ accept: 'application/pdf' })
|
|
|
|
|
+ onChange(async (files) => {
|
|
|
|
|
+ console.log(files[0])
|
|
|
|
|
+ uploading.value = true
|
|
|
|
|
+ try {
|
|
|
|
|
+ const formData = new FormData()
|
|
|
|
|
+ formData.append('file', files[0])
|
|
|
|
|
+ await http.put(`/knowledge/base/${selectedBase.value.id}/file`, formData)
|
|
|
|
|
+ } catch (error) {
|
|
|
|
|
+ ElMessage.error(error.message)
|
|
|
|
|
+ } finally {
|
|
|
|
|
+ uploading.value = false
|
|
|
|
|
+ fileTable.value.refresh()
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
+ open()
|
|
|
|
|
+}
|
|
|
|
|
+async function deleteFile(row) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ await ElMessageBox.confirm('此操作将永久删除数据, 是否继续?', '提示', {
|
|
|
|
|
+ type: 'warning'
|
|
|
|
|
+ })
|
|
|
|
|
+ await http.delete(`/knowledge/file/${row.id}`)
|
|
|
|
|
+ ElMessage.success('删除成功')
|
|
|
|
|
+ fileTable.value.refresh()
|
|
|
|
|
+ } catch (error) {
|
|
|
|
|
+ if ('cancel' !== error) ElMessage.error(error.message)
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
</script>
|
|
</script>
|