|
|
@@ -6,7 +6,7 @@
|
|
|
</div>
|
|
|
|
|
|
<el-alert
|
|
|
- title="支持上传文件和手动新增 QA 数据"
|
|
|
+ title="支持上传 CSV 文件批量导入问答对和手动新增 QA 数据"
|
|
|
type="info"
|
|
|
:closable="false"
|
|
|
show-icon
|
|
|
@@ -26,9 +26,11 @@
|
|
|
:on-error="handleUploadError"
|
|
|
:on-progress="handleUploadProgress"
|
|
|
:disabled="upload.isUploading || !baseId"
|
|
|
- accept="*"
|
|
|
+ accept=".csv"
|
|
|
>
|
|
|
- <el-button type="primary" icon="el-icon-upload2" :loading="upload.isUploading">上传文件</el-button>
|
|
|
+ <el-button type="primary" icon="el-icon-upload2" :loading="upload.isUploading">
|
|
|
+ {{ upload.isUploading ? '上传中...' : '上传CSV' }}
|
|
|
+ </el-button>
|
|
|
</el-upload>
|
|
|
</el-col>
|
|
|
<el-col :span="1.5">
|
|
|
@@ -86,7 +88,7 @@
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
-import { getToken } from '@/utils/auth'
|
|
|
+import { getToken, getTenantCode } from '@/utils/auth'
|
|
|
import { knowledgeApi } from '@/api/company/knowledge'
|
|
|
|
|
|
export default {
|
|
|
@@ -111,10 +113,13 @@ export default {
|
|
|
isUploading: false,
|
|
|
url: process.env.VUE_APP_BASE_API + '/knowledge/upload',
|
|
|
headers: {
|
|
|
- Authorization: 'Bearer ' + getToken()
|
|
|
+ Authorization: 'Bearer ' + getToken(),
|
|
|
+ 'tenant-code': getTenantCode()
|
|
|
},
|
|
|
data: {
|
|
|
- baseId: undefined
|
|
|
+ baseId: undefined,
|
|
|
+ collectionName: undefined,
|
|
|
+ collectionId: undefined
|
|
|
}
|
|
|
},
|
|
|
qaForm: {
|
|
|
@@ -146,6 +151,8 @@ export default {
|
|
|
}
|
|
|
this.queryParams.baseId = this.baseId
|
|
|
this.upload.data.baseId = this.baseId
|
|
|
+ this.upload.data.collectionName = this.cName
|
|
|
+ this.upload.data.collectionId = this.cId
|
|
|
this.getList()
|
|
|
},
|
|
|
async getList() {
|
|
|
@@ -230,15 +237,24 @@ export default {
|
|
|
handleUploadSuccess(response) {
|
|
|
this.upload.isUploading = false
|
|
|
if (response && (response.code === 200 || response.success)) {
|
|
|
- this.$message.success(response.msg || '上传成功')
|
|
|
+ const data = response.data || {}
|
|
|
+ const msg = data.success
|
|
|
+ ? `导入完成:共 ${data.total || 0} 条,成功 ${data.success || 0} 条`
|
|
|
+ : (response.msg || '上传成功')
|
|
|
+ this.$message.success(msg)
|
|
|
this.getList()
|
|
|
return
|
|
|
}
|
|
|
this.$message.error((response && response.msg) || '上传失败')
|
|
|
},
|
|
|
- handleUploadError() {
|
|
|
+ handleUploadError(err) {
|
|
|
this.upload.isUploading = false
|
|
|
- this.$message.error('上传失败')
|
|
|
+ try {
|
|
|
+ const errorMsg = JSON.parse(err.message || '{}')
|
|
|
+ this.$message.error(errorMsg.msg || '上传失败,请检查文件格式')
|
|
|
+ } catch {
|
|
|
+ this.$message.error('上传失败,请检查文件格式')
|
|
|
+ }
|
|
|
},
|
|
|
resetQaForm() {
|
|
|
this.qaForm = {
|