新增导入项目方法,修改上传数据源方法
This commit is contained in:
parent
d0de412782
commit
6f6f62f04c
@ -124,3 +124,11 @@ export function exportProject(queryParams: any) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//导入项目
|
||||||
|
export function importProject(data:any){
|
||||||
|
return request({
|
||||||
|
url:'/projects/importProject' ,
|
||||||
|
method: 'Post',
|
||||||
|
data: data
|
||||||
|
});
|
||||||
|
}
|
||||||
@ -11,13 +11,14 @@ import { addAlgorithms,deleteAlgorithms,trainAlgorithmsPage,trainPublish,trainSt
|
|||||||
import { useUserStore } from '@/store/modules/user';
|
import { useUserStore } from '@/store/modules/user';
|
||||||
import { searchAlgorithmsPage,algorithmsType } from "@/api/business/algorithm";
|
import { searchAlgorithmsPage,algorithmsType } from "@/api/business/algorithm";
|
||||||
import { getDictItemById } from '@/api/dict';
|
import { getDictItemById } from '@/api/dict';
|
||||||
|
import { getToken } from '@/utils/auth'
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
import SockJS from 'sockjs-client'
|
import SockJS from 'sockjs-client'
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
import * as Stomp from 'stompjs';
|
import * as Stomp from 'stompjs';
|
||||||
import Page from '@/components/Pagination/page.vue'
|
import Page from '@/components/Pagination/page.vue'
|
||||||
|
import * as XLSX from 'xlsx'
|
||||||
const userStore = useUserStore();
|
const userStore = useUserStore();
|
||||||
|
|
||||||
const apiUrl = import.meta.env.VITE_APP_BASE_API; // 基础路径
|
const apiUrl = import.meta.env.VITE_APP_BASE_API; // 基础路径
|
||||||
const webSocketUrl = import.meta.env.VITE_APP_WS_API;
|
const webSocketUrl = import.meta.env.VITE_APP_WS_API;
|
||||||
const fileList:any = ref([])
|
const fileList:any = ref([])
|
||||||
@ -161,6 +162,11 @@ function addClick() {
|
|||||||
supportedDeviceTypes: "",
|
supportedDeviceTypes: "",
|
||||||
defaultHyperParams: "",
|
defaultHyperParams: "",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
input_cols.value = []
|
||||||
|
target_col.value = ""
|
||||||
|
fileFlow.value = null
|
||||||
|
|
||||||
trainParamsData.value = []
|
trainParamsData.value = []
|
||||||
algorithmsTypeData.value = []
|
algorithmsTypeData.value = []
|
||||||
fileList.value = []
|
fileList.value = []
|
||||||
@ -170,21 +176,30 @@ function addClick() {
|
|||||||
//新建训练任务-确认按钮/修改按钮
|
//新建训练任务-确认按钮/修改按钮
|
||||||
function confirmClick(formEl: any) {
|
function confirmClick(formEl: any) {
|
||||||
formEl.validate((valid: any) => {
|
formEl.validate((valid: any) => {
|
||||||
|
|
||||||
if(fileList.value.length == 0){
|
|
||||||
return ElMessage({
|
|
||||||
type: "error",
|
|
||||||
message: "请上传数据源类型",
|
|
||||||
});
|
|
||||||
}
|
|
||||||
if (valid) {
|
if (valid) {
|
||||||
|
if(fileFlow.value == null || fileFlow.value.uid == null){
|
||||||
|
return ElMessage({
|
||||||
|
type: "error",
|
||||||
|
message: "请上传数据集",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if(input_cols.value.length == 0 ){
|
||||||
|
return ElMessage({
|
||||||
|
type: "error",
|
||||||
|
message: "特征列不能为空",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if(target_col.value == null || target_col.value == ""){
|
||||||
|
return ElMessage({
|
||||||
|
type: "error",
|
||||||
|
message: "目标列不能为空",
|
||||||
|
});
|
||||||
|
}
|
||||||
if(isSwitch.value == true){
|
if(isSwitch.value == true){
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
isSwitch.value = true
|
isSwitch.value = true
|
||||||
|
|
||||||
const data = new FormData()
|
const data = new FormData()
|
||||||
|
|
||||||
if(algorithmsTypeData.value.length != 0){
|
if(algorithmsTypeData.value.length != 0){
|
||||||
let template:any = {}
|
let template:any = {}
|
||||||
algorithmsTypeData.value.forEach((element:any) => {
|
algorithmsTypeData.value.forEach((element:any) => {
|
||||||
@ -193,13 +208,13 @@ function confirmClick(formEl: any) {
|
|||||||
info.value.trainParams = JSON.stringify(template)
|
info.value.trainParams = JSON.stringify(template)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let infoTemp = JSON.parse(JSON.stringify(info.value))
|
||||||
|
let feature_map_config = {
|
||||||
|
input_cols: input_cols.value,
|
||||||
data.append('task', JSON.stringify(info.value))
|
target_col: target_col.value,
|
||||||
if (fileList.value.length > 0) {
|
|
||||||
data.append('file', fileList.value[0].raw)
|
|
||||||
}
|
}
|
||||||
|
infoTemp.feature_map_config = JSON.stringify(feature_map_config)
|
||||||
|
data.append('task', JSON.stringify(feature_map_config))
|
||||||
dialogVisibles.value = false
|
dialogVisibles.value = false
|
||||||
addAlgorithms(data).then((res: any) => {
|
addAlgorithms(data).then((res: any) => {
|
||||||
dialogVisibles.value = false;
|
dialogVisibles.value = false;
|
||||||
@ -227,6 +242,7 @@ function handleClose() {
|
|||||||
}
|
}
|
||||||
function handleClosed(){
|
function handleClosed(){
|
||||||
modelVisible.value = false
|
modelVisible.value = false
|
||||||
|
tableVisible.value = false
|
||||||
}
|
}
|
||||||
//修改训练任务
|
//修改训练任务
|
||||||
function viewClick(row: any) {
|
function viewClick(row: any) {
|
||||||
@ -260,9 +276,6 @@ function viewClick(row: any) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
}, 2000);
|
}, 2000);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
dialogViewVisible.value = true;
|
dialogViewVisible.value = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -460,6 +473,106 @@ const objectSpanMethod = ({
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
const fileFlow:any = ref(null)
|
||||||
|
function handlePreview(file: any){
|
||||||
|
// loadingtext.value = "正在导入数据,请耐心等待!"
|
||||||
|
loading.value = true
|
||||||
|
fileFlow.value = file
|
||||||
|
input_cols.value = []
|
||||||
|
target_col.value = ""
|
||||||
|
}
|
||||||
|
|
||||||
|
const upload:any = ref(null)
|
||||||
|
const columnsData:any = ref([])
|
||||||
|
function handlesSuccess(file: any) {
|
||||||
|
columnsData.value = []
|
||||||
|
input_cols.value = []
|
||||||
|
target_col.value = ''
|
||||||
|
loading.value = false
|
||||||
|
if(file !== false && file.code == '0'){
|
||||||
|
columnsData.value = file.data.columns
|
||||||
|
ElMessage({
|
||||||
|
message: "导入成功!",
|
||||||
|
type: "success",
|
||||||
|
});
|
||||||
|
}else{
|
||||||
|
ElMessage({
|
||||||
|
message: "导入失败!",
|
||||||
|
type: "error",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
gettableData()
|
||||||
|
upload.value.clearFiles()
|
||||||
|
}
|
||||||
|
function handleError(file: any){
|
||||||
|
loading.value = false
|
||||||
|
ElMessage({
|
||||||
|
message: "导入失败!",
|
||||||
|
type: "error",
|
||||||
|
});
|
||||||
|
upload.value.clearFiles()
|
||||||
|
}
|
||||||
|
|
||||||
|
const input_cols = ref([])
|
||||||
|
const target_col = ref('')
|
||||||
|
|
||||||
|
|
||||||
|
const tableHeaders:any = ref([])
|
||||||
|
const tableXlsxData:any = ref([])
|
||||||
|
// const tableData = ref([])
|
||||||
|
function previewData(){
|
||||||
|
const file:any = fileFlow.value
|
||||||
|
const reader = new FileReader()
|
||||||
|
reader.onload = (e:any) => {
|
||||||
|
try {
|
||||||
|
// 解析二进制数据
|
||||||
|
const data = new Uint8Array(e.target.result)
|
||||||
|
const workbook = XLSX.read(data, { type: 'array' })
|
||||||
|
|
||||||
|
// 取第一个工作表
|
||||||
|
const firstSheetName = workbook.SheetNames[0]
|
||||||
|
const worksheet = workbook.Sheets[firstSheetName]
|
||||||
|
|
||||||
|
// 转换为JSON格式
|
||||||
|
const jsonData:any = XLSX.utils.sheet_to_json(worksheet)
|
||||||
|
|
||||||
|
// 提取表头
|
||||||
|
let columnsTemp = jsonData.length ? Object.keys(jsonData[0]) : []
|
||||||
|
|
||||||
|
let columns:any = [{
|
||||||
|
key: 'order',
|
||||||
|
dataKey: 'order',
|
||||||
|
width: 70,
|
||||||
|
title: '序号',
|
||||||
|
align: 'center',
|
||||||
|
}]
|
||||||
|
for(let i = 0;i<columnsTemp.length;i++){
|
||||||
|
columns.push({
|
||||||
|
key: columnsTemp[i],
|
||||||
|
dataKey: columnsTemp[i],
|
||||||
|
title: columnsTemp[i],
|
||||||
|
width: 150,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
tableHeaders.value = columns
|
||||||
|
// 处理数据(确保空单元格显示占位符)
|
||||||
|
tableXlsxData.value = jsonData.map((item:any, index:number) => ({
|
||||||
|
...item,
|
||||||
|
order: index + 1,
|
||||||
|
}))
|
||||||
|
debugger
|
||||||
|
} catch (error) {
|
||||||
|
console.error('文件解析失败:', error)
|
||||||
|
alert('文件格式不正确或已损坏')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
reader.readAsArrayBuffer(file)
|
||||||
|
tableVisible.value = true
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const tableVisible = ref(false)
|
||||||
|
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@ -550,17 +663,39 @@ const objectSpanMethod = ({
|
|||||||
<el-option v-for="item in equipmentData" :key="item.itemCode" :label="item.dictName" :value="item.itemCode" ></el-option>
|
<el-option v-for="item in equipmentData" :key="item.itemCode" :label="item.dictName" :value="item.itemCode" ></el-option>
|
||||||
</el-select>
|
</el-select>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="算法类型" prop="algorithmType" style="width: 100%;" >
|
|
||||||
<el-select v-model="info.algorithmType" placeholder="请选择算法类型" @change="selectAlgorithmType">
|
<el-form-item label="上传数据源" style="width: 100%;" >
|
||||||
<el-option v-for="item in algorithmData" :key="item.algorithmType" :label="item.name" :value="item.algorithmType" ></el-option>
|
<el-upload accept=".xlsx" ref="upload" class="upload-demo"
|
||||||
</el-select v-model="info.algorithmType">
|
:action=" apiUrl + '/train/upload' "
|
||||||
</el-form-item>
|
:headers="{ token: getToken() }"
|
||||||
<el-form-item label="数据源类型" style="width: 100%;" >
|
:show-file-list="false"
|
||||||
<el-upload accept=".xlsx" ref="upload" class="upload-demo" action="" :on-change="handlefilechange" :on-remove="handlefileremove" :auto-upload="false" :file-list="fileList" style="width: calc(100% - 70px);position:relative">
|
:before-upload="handlePreview"
|
||||||
|
:on-success="handlesSuccess"
|
||||||
|
:on-error="handleError">
|
||||||
<template #trigger>
|
<template #trigger>
|
||||||
<el-button type="primary">点击上传</el-button>
|
<el-button type="primary">点击上传</el-button>
|
||||||
</template>
|
</template>
|
||||||
</el-upload>
|
</el-upload>
|
||||||
|
<el-button type="primary" v-if="columnsData.length > 0" @click="previewData" style="margin-left: 20px;">预览数据</el-button>
|
||||||
|
</el-form-item>
|
||||||
|
|
||||||
|
<el-form-item label="特征列" style="width: 100%;" v-if="columnsData.length > 0">
|
||||||
|
<el-checkbox-group v-model="input_cols">
|
||||||
|
<el-checkbox v-for="item in columnsData" :key="item" :label="item">{{item}}</el-checkbox>
|
||||||
|
</el-checkbox-group>
|
||||||
|
</el-form-item>
|
||||||
|
|
||||||
|
<el-form-item label="目标列" style="width: 100%;" v-if="columnsData.length > 0">
|
||||||
|
<el-radio-group v-model="target_col" >
|
||||||
|
<el-radio v-for="item in columnsData" :key="item" :label="item">{{item}}</el-radio>
|
||||||
|
</el-radio-group>
|
||||||
|
</el-form-item>
|
||||||
|
|
||||||
|
|
||||||
|
<el-form-item label="算法类型" prop="algorithmType" style="width: 100%;" >
|
||||||
|
<el-select v-model="info.algorithmType" placeholder="请选择算法类型" @change="selectAlgorithmType">
|
||||||
|
<el-option v-for="item in algorithmData" :key="item.algorithmType" :label="item.name" :value="item.algorithmType" ></el-option>
|
||||||
|
</el-select v-model="info.algorithmType">
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="参数配置" style="width: 100%;" >
|
<el-form-item label="参数配置" style="width: 100%;" >
|
||||||
<div>
|
<div>
|
||||||
@ -628,8 +763,8 @@ const objectSpanMethod = ({
|
|||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="设备类型" style="width: 100%;" >
|
<el-form-item label="设备类型" style="width: 100%;" >
|
||||||
<el-select v-model="info.deviceType" placeholder="请选择设备类型" :disabled="true">
|
<el-select v-model="info.deviceType" placeholder="请选择设备类型" :disabled="true">
|
||||||
<el-option v-for="item in equipmentData" :key="item.itemCode" :label="item.dictName" :value="item.itemCode" ></el-option>
|
<el-option v-for="item in equipmentData" :key="item.itemCode" :label="item.dictName" :value="item.itemCode" ></el-option>
|
||||||
</el-select>
|
</el-select>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="训练参数" style="width: 100%;">
|
<el-form-item label="训练参数" style="width: 100%;">
|
||||||
<div v-for="item in trainParamsData" :key="item" style="margin-bottom: 10px;">
|
<div v-for="item in trainParamsData" :key="item" style="margin-bottom: 10px;">
|
||||||
@ -637,7 +772,6 @@ const objectSpanMethod = ({
|
|||||||
:
|
:
|
||||||
<el-input v-model="item.value" style="width: 300px" :disabled="true"></el-input>
|
<el-input v-model="item.value" style="width: 300px" :disabled="true"></el-input>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="特征映射快照" style="width: 100%;" >
|
<el-form-item label="特征映射快照" style="width: 100%;" >
|
||||||
<el-input type="textarea" v-model="info.featureMapSnapshot" style="width: 100%" placeholder="输入特征映射快照" disabled></el-input>
|
<el-input type="textarea" v-model="info.featureMapSnapshot" style="width: 100%" placeholder="输入特征映射快照" disabled></el-input>
|
||||||
@ -645,10 +779,6 @@ const objectSpanMethod = ({
|
|||||||
<el-form-item label="创建时间" style="width: 100%;" >
|
<el-form-item label="创建时间" style="width: 100%;" >
|
||||||
<el-input v-model="info.createdAt" style="width: 100%" :disabled="true" ></el-input>
|
<el-input v-model="info.createdAt" style="width: 100%" :disabled="true" ></el-input>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<!-- <el-form-item label="更新时间" style="width: 100%;" >
|
|
||||||
<el-input v-model="info.updatedAt" style="width: 100%" :disabled="true"></el-input>
|
|
||||||
</el-form-item> -->
|
|
||||||
|
|
||||||
</el-form>
|
</el-form>
|
||||||
<div v-else style="width: 100%; height: calc(100% - 50px);">
|
<div v-else style="width: 100%; height: calc(100% - 50px);">
|
||||||
<div v-if="info.status == 'Success'" style="width: 100%; height:100%">
|
<div v-if="info.status == 'Success'" style="width: 100%; height:100%">
|
||||||
@ -694,6 +824,25 @@ const objectSpanMethod = ({
|
|||||||
<el-button type="primary" style="margin-left: 60px;" @click="confirmsClick">确定</el-button>
|
<el-button type="primary" style="margin-left: 60px;" @click="confirmsClick">确定</el-button>
|
||||||
</el-form>
|
</el-form>
|
||||||
</el-dialog>
|
</el-dialog>
|
||||||
|
<el-dialog v-model="tableVisible" :close-on-click-modal="false"
|
||||||
|
:modal="false" draggable :before-close="handleClosed" title="预览数据表格"
|
||||||
|
append-to-body width="1280px">
|
||||||
|
|
||||||
|
|
||||||
|
<div style="height:calc(100vh - 100px)">
|
||||||
|
<el-auto-resizer>
|
||||||
|
<template #default="{ height, width }">
|
||||||
|
<el-table-v2
|
||||||
|
:columns="tableHeaders"
|
||||||
|
:data="tableXlsxData"
|
||||||
|
:width="width"
|
||||||
|
:height="height"
|
||||||
|
fixed
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
|
</el-auto-resizer>
|
||||||
|
</div>
|
||||||
|
</el-dialog>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
|||||||
@ -7,7 +7,8 @@ export default {
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { onMounted, ref, nextTick } from "vue";
|
import { onMounted, ref, nextTick } from "vue";
|
||||||
import { ElForm, ElMessage, ElMessageBox } from "element-plus";
|
import { ElForm, ElMessage, ElMessageBox } from "element-plus";
|
||||||
import { searchProjectsLsit,addProjects,updateProjects,deleteProjects,deleteBatchProjects,visibilityProjects,exportAllExports,exportProject} from "@/api/business/project";
|
import { searchProjectsLsit,addProjects,updateProjects,deleteProjects,deleteBatchProjects,
|
||||||
|
visibilityProjects,exportAllExports,exportProject,importProject} from "@/api/business/project";
|
||||||
import Page from '@/components/Pagination/page.vue'
|
import Page from '@/components/Pagination/page.vue'
|
||||||
import ScenarioModel from '@/views/component/scenario/index.vue'
|
import ScenarioModel from '@/views/component/scenario/index.vue'
|
||||||
import Antvx6 from '@/components/antvx6/index.vue'
|
import Antvx6 from '@/components/antvx6/index.vue'
|
||||||
@ -256,26 +257,63 @@ function exportProjectClick(row: any){
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const projectFile = ref(null)
|
||||||
function handlePreview(){
|
function handlePreview(data: any){
|
||||||
|
projectFile.value = data
|
||||||
// loadingtext.value = "正在导入数据,请耐心等待!"
|
// loadingtext.value = "正在导入数据,请耐心等待!"
|
||||||
loading.value = true
|
loading.value = true
|
||||||
}
|
}
|
||||||
const upload:any = ref(null)
|
const upload:any = ref(null)
|
||||||
function handlesSuccess(file: any) {
|
function handlesSuccess(file: any) {
|
||||||
if(file !== false){
|
if(file !== false){
|
||||||
|
if(file.code == '2'){
|
||||||
|
ElMessageBox.confirm("项目ID已存在,是否覆盖导入吗?", "删除提示", {
|
||||||
|
confirmButtonText: "确定",
|
||||||
|
cancelButtonText: "取消",
|
||||||
|
type: "warning",
|
||||||
|
}).then(() => {
|
||||||
|
let data:any = new FormData()
|
||||||
|
data.append('overwrite', 'true')
|
||||||
|
data.append('file', projectFile.value)
|
||||||
|
loading.value = true
|
||||||
|
importProject(data).then((response:any) => {
|
||||||
|
loading.value = false
|
||||||
|
if(response.code == 0){
|
||||||
|
gettableData();
|
||||||
|
ElMessage({
|
||||||
|
type: "success",
|
||||||
|
message: "上传成功",
|
||||||
|
});
|
||||||
|
}else{
|
||||||
|
ElMessage({
|
||||||
|
message: "导入失败!",
|
||||||
|
type: "error",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}).catch(() => {
|
||||||
|
loading.value = false
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}else if(file.code == 1){
|
||||||
ElMessage({
|
ElMessage({
|
||||||
message: "导入成功!",
|
message: file.msg,
|
||||||
type: "success",
|
type: "error",
|
||||||
});
|
});
|
||||||
}else{
|
}else{
|
||||||
ElMessage({
|
ElMessage({
|
||||||
message: "导入失败!",
|
message: "导入成功!",
|
||||||
type: "error",
|
type: "success",
|
||||||
});
|
});
|
||||||
|
gettableData()
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
ElMessage({
|
||||||
|
message: "导入失败!",
|
||||||
|
type: "error",
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
gettableData()
|
loading.value = false
|
||||||
upload.value.clearFiles()
|
upload.value.clearFiles()
|
||||||
}
|
}
|
||||||
function handleError(file: any){
|
function handleError(file: any){
|
||||||
@ -306,7 +344,7 @@ function handleError(file: any){
|
|||||||
ref="upload"
|
ref="upload"
|
||||||
accept=".xlsx,.xls"
|
accept=".xlsx,.xls"
|
||||||
class="upload-demo"
|
class="upload-demo"
|
||||||
:action=" url + '/projects/import' "
|
:action=" url + '/projects/importProject' "
|
||||||
:headers="{ token: getToken() }"
|
:headers="{ token: getToken() }"
|
||||||
:show-file-list="false"
|
:show-file-list="false"
|
||||||
:before-upload="handlePreview"
|
:before-upload="handlePreview"
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user