feat: 修改文档

This commit is contained in:
wangdan-fit2cloud 2023-11-10 11:36:04 +08:00
parent 6cf411eec1
commit 9f9d65a74b
7 changed files with 86 additions and 17 deletions

View File

@ -99,6 +99,17 @@ const putDocument: (dataset_id: string, document_id: string, data: any) => Promi
return put(`${prefix}/${dataset_id}/document/${document_id}`, data)
}
/**
*
* @param dataset_id, document_id,
*/
const delDocument: (dataset_id: string, document_id: string) => Promise<Result<boolean>> = (
dataset_id,
document_id
) => {
return del(`${prefix}/${dataset_id}/document/${document_id}`)
}
export default {
getDateset,
getAllDateset,
@ -106,5 +117,6 @@ export default {
postDateset,
postSplitDocument,
getDocument,
putDocument
putDocument,
delDocument
}

View File

@ -56,9 +56,10 @@ const putMemberPermissions: (member_id: String, body: any) => Promise<Result<any
member_id,
body
) => {
return put(`${prefix}/${member_id}`, undefined, body)
return put(`${prefix}/${member_id}`, body)
}
export default {
getTeamMember,
postCreatTeamMember,

View File

@ -12,12 +12,12 @@
<div class="flex align-center" v-if="isEdit">
<el-input ref="inputRef" v-model="writeValue" placeholder="请输入"></el-input>
<span class="ml-4">
<el-button type="primary" text @click="submit">
<el-button type="primary" text @click="submit" :disabled="loading">
<el-icon><Select /></el-icon>
</el-button>
</span>
<span>
<el-button text @click="isEdit = false">
<el-button text @click="isEdit = false" :disabled="loading">
<el-icon><CloseBold /></el-icon>
</el-button>
</span>
@ -41,6 +41,7 @@ const props = defineProps({
const emit = defineEmits(['change'])
const isEdit = ref(false)
const writeValue = ref('')
const loading = ref(false)
watch(isEdit, (bool) => {
if (!bool) {
@ -49,8 +50,12 @@ watch(isEdit, (bool) => {
})
function submit() {
loading.value = true
emit('change', writeValue.value)
setTimeout(() => {
isEdit.value = false
loading.value = false
}, 200)
}
function editNameHandle(row: any) {
writeValue.value = props.data

View File

@ -149,8 +149,8 @@ export const put: (
params?: unknown,
data?: unknown,
loading?: NProgress | Ref<boolean>
) => Promise<Result<any>> = (url, params, data, loading) => {
return promise(request({ url: url, method: 'put', params, data }), loading)
) => Promise<Result<any>> = (url, data, params, loading) => {
return promise(request({ url: url, method: 'put', data, params }), loading)
}
/**

View File

@ -1,7 +1,7 @@
<template>
<LayoutContainer header="文档">
<div class="main-calc-height">
<div class="p-24" v-loading="loading">
<div class="p-24">
<div class="flex-between">
<el-button type="primary" @click="router.push({ path: '/dataset/upload' })"
>上传文档</el-button
@ -22,6 +22,7 @@
@changePage="handleCurrentChange"
@cell-mouse-enter="cellMouseEnter"
@cell-mouse-leave="cellMouseLeave"
v-loading="loading"
>
<el-table-column prop="name" label="文件名称" min-width="280">
<template #default="{ row }">
@ -53,7 +54,7 @@
</el-table-column>
<el-table-column prop="name" label="启动状态">
<template #default="{ row }">
<el-switch v-model="row.is_active" />
<el-switch v-model="row.is_active" @change="changeState($event, row)" />
</template>
</el-table-column>
<el-table-column prop="create_time" label="创建时间" width="170">
@ -77,7 +78,7 @@
</span>
<span class="ml-4">
<el-tooltip effect="dark" content="删除" placement="top">
<el-button type="primary" text>
<el-button type="primary" text @click="deleteDocument(row)">
<el-icon><Delete /></el-icon>
</el-button>
</el-tooltip>
@ -95,12 +96,11 @@ import { useRouter, useRoute } from 'vue-router'
import datasetApi from '@/api/dataset'
import { toThousands } from '@/utils/utils'
import { datetimeFormat } from '@/utils/time'
import { MsgSuccess, MsgConfirm } from '@/utils/message'
const router = useRouter()
const route = useRoute()
const { params } = route
const { datasetId } = params
const inputRef = ref()
const { datasetId } = params as any
const loading = ref(false)
const filterText = ref('')
@ -113,7 +113,58 @@ const paginationConfig = reactive({
total: 0
})
function editName(val: string) {}
function deleteDocument(row: any) {
MsgConfirm(
`是否删除文档:${row.name} ?`,
`此文档下的 ${row.paragraph_count} 个分段都会被删除,请谨慎操作。`,
{
confirmButtonText: '删除',
confirmButtonClass: 'danger'
}
)
.then(() => {
loading.value = true
datasetApi
.delDocument(datasetId, row.id)
.then(() => {
MsgSuccess('删除成功')
getList()
})
.catch(() => {
loading.value = false
})
})
.catch(() => {})
}
function updateData(documentId: string, data: any) {
loading.value = true
datasetApi
.putDocument(datasetId, documentId, data)
.then((res) => {
const index = documentData.value.findIndex((v) => v.id === documentId)
documentData.value.splice(index, 1, res.data)
MsgSuccess('修改成功')
loading.value = false
})
.catch(() => {
loading.value = false
})
}
function changeState(bool: Boolean, row: any) {
const obj = {
is_active: bool
}
currentMouseId.value && updateData(row.id, obj)
}
function editName(val: string) {
const obj = {
name: val
}
currentMouseId.value && updateData(currentMouseId.value, obj)
}
function cellMouseEnter(row: any) {
currentMouseId.value = row.id

View File

@ -74,7 +74,7 @@ function editHandle(item: any, index: number, cIndex: number) {
}
function deleteHandle(item: any, index: number, cIndex: number) {
MsgConfirm(`是否删除分段:${item.title}`, `删除后将不会存入数据集,对本地文档无影响。`, {
MsgConfirm(`是否删除分段:${item.title} ?`, `删除后将不会存入数据集,对本地文档无影响。`, {
confirmButtonText: '删除',
confirmButtonClass: 'danger'
})

View File

@ -76,7 +76,7 @@ function loadDataset() {}
function deleteDateset(row: any) {
MsgConfirm(
`是否删除数据集:${row.name}`,
`是否删除数据集:${row.name} ?`,
`此数据集关联 ${row.char_length} 个应用,删除后无法恢复,请谨慎操作。`,
{
confirmButtonText: '删除',