|
|
@@ -62,12 +62,14 @@
|
|
|
width="50%">
|
|
|
<el-upload
|
|
|
class="upload-demo"
|
|
|
- action="/api/upload/inte"
|
|
|
- :on-success="handleInteUploadSuccess"
|
|
|
- :on-error="handleUploadError"
|
|
|
+ ref="inteUpload"
|
|
|
+ action="#"
|
|
|
:file-list="inteFileList"
|
|
|
accept=".doc,.docx,.pdf,.xlsx,.xls"
|
|
|
- :auto-upload="false">
|
|
|
+ :auto-upload="false"
|
|
|
+ :on-change="handleInteFileChange"
|
|
|
+ :limit="1"
|
|
|
+ >
|
|
|
<el-button slot="trigger" size="small" type="primary">选取文件</el-button>
|
|
|
<el-button style="margin-left: 10px;" size="small" type="success" @click="submitInteUpload">
|
|
|
上传到服务器
|
|
|
@@ -88,12 +90,14 @@
|
|
|
width="50%">
|
|
|
<el-upload
|
|
|
class="upload-demo"
|
|
|
- action="/api/upload/target"
|
|
|
- :on-success="handleTargetUploadSuccess"
|
|
|
- :on-error="handleUploadError"
|
|
|
+ ref="targetUpload"
|
|
|
+ action="#"
|
|
|
:file-list="targetFileList"
|
|
|
accept=".doc,.docx,.pdf,.xlsx,.xls"
|
|
|
- :auto-upload="false">
|
|
|
+ :auto-upload="false"
|
|
|
+ :on-change="handleTargetFileChange"
|
|
|
+ :limit="1"
|
|
|
+ >
|
|
|
<el-button slot="trigger" size="small" type="primary">选取文件</el-button>
|
|
|
<el-button style="margin-left: 10px;" size="small" type="success" @click="submitTargetUpload">
|
|
|
上传到服务器
|
|
|
@@ -132,8 +136,16 @@
|
|
|
import DarkLayout from '@/components/GlobalComponents/DarkLayout.vue'
|
|
|
import InterferenceCard from '@/components/Components/InterferenceCard.vue'
|
|
|
import DarkDialog from "@/components/Components/DarkDialog.vue";
|
|
|
-import {planningSchemePage} from "@/api/planningScheme";
|
|
|
+import {
|
|
|
+ planningSchemePage,
|
|
|
+ planningSchemeUpdate, planningSchemeUpdateInte,
|
|
|
+ planningSchemeUpdateTarget,
|
|
|
+ planningSchemeUploadTarget
|
|
|
+} from "@/api/planningScheme";
|
|
|
import {exportSolutionToWord} from "@/views/planningSchem/comprehensive/wordExporter";
|
|
|
+import { baseURL,contentType,tokenName } from "@/config";
|
|
|
+import store from "@/store";
|
|
|
+import {doUpload} from "@/api/tool/ossTool";
|
|
|
|
|
|
export default {
|
|
|
components: {
|
|
|
@@ -240,6 +252,7 @@ export default {
|
|
|
pageSize: 10,
|
|
|
total: 0
|
|
|
},
|
|
|
+ selectPlan:null,
|
|
|
showAdvancedSearch: false,
|
|
|
showInteUpload: false, // 干扰方案上传弹窗
|
|
|
showTargetUpload: false, // 靶标方案上传弹窗
|
|
|
@@ -263,23 +276,85 @@ export default {
|
|
|
},
|
|
|
|
|
|
// 干扰方案上传成功处理
|
|
|
- handleInteUploadSuccess(response, file, fileList) {
|
|
|
+ async handleInteUploadSuccess(response, file, fileList) {
|
|
|
+ if(response.code !==200){
|
|
|
+ this.$message.success('干扰方案上传失败');
|
|
|
+ return;
|
|
|
+ }
|
|
|
this.$message.success('干扰方案上传成功');
|
|
|
- this.showInteUpload = false;
|
|
|
- this.inteFileList = [];
|
|
|
- // 上传成功后可以刷新数据
|
|
|
- this.fetchData();
|
|
|
+
|
|
|
+ const fileJson = JSON.stringify(
|
|
|
+ fileList.map(item => ({
|
|
|
+ fileName: item.name,
|
|
|
+ fileHttp: item.response?.data?.url || '',
|
|
|
+ fileType: item.response?.data?.type || '',
|
|
|
+ type: 1
|
|
|
+ })).filter(item => item.fileHttp)
|
|
|
+ );
|
|
|
+
|
|
|
+ try {
|
|
|
+ await planningSchemeUpdate({
|
|
|
+ id: this.selectPlan.id,
|
|
|
+ interferenceSchemeStatus: '已导入',
|
|
|
+ schemeSubPlan: fileJson
|
|
|
+ });
|
|
|
+
|
|
|
+ this.showInteUpload = false;
|
|
|
+ this.inteFileList = [];
|
|
|
+ this.handleQuery();
|
|
|
+ } catch (err) {
|
|
|
+ console.error('更新方案失败:', err);
|
|
|
+ this.$message.error('方案更新失败');
|
|
|
+ }
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
// 靶标方案上传成功处理
|
|
|
- handleTargetUploadSuccess(response, file, fileList) {
|
|
|
+ async handleTargetUploadSuccess(response, file, fileList) {
|
|
|
+ if(response.code !==200){
|
|
|
+ this.$message.success('靶标方案上传失败');
|
|
|
+ return;
|
|
|
+ }
|
|
|
this.$message.success('靶标方案上传成功');
|
|
|
- this.showTargetUpload = false;
|
|
|
- this.targetFileList = [];
|
|
|
- // 上传成功后可以刷新数据
|
|
|
- this.fetchData();
|
|
|
+
|
|
|
+ // 1. 将 fileList 转为 JSON(和干扰方案保持一致)
|
|
|
+ const fileJson = JSON.stringify(
|
|
|
+ fileList.map(item => ({
|
|
|
+ fileName: item.name,
|
|
|
+ fileHttp: item.response?.data?.url || '',
|
|
|
+ fileType: item.response?.data?.type || '',
|
|
|
+ type: 2
|
|
|
+ })).filter(item => item.fileHttp) // 过滤掉上传失败的文件
|
|
|
+ );
|
|
|
+
|
|
|
+ try {
|
|
|
+ // 2. 调用 API 更新靶标方案
|
|
|
+ await planningSchemeUpdate({
|
|
|
+ id: this.selectPlan.id,
|
|
|
+ schemeSubPlan: fileJson
|
|
|
+ });
|
|
|
+
|
|
|
+ // 3. 更新 UI 状态
|
|
|
+ this.showTargetUpload = false;
|
|
|
+ this.targetFileList = [];
|
|
|
+
|
|
|
+ // 4. 刷新数据
|
|
|
+ this.handleQuery();
|
|
|
+ } catch (err) {
|
|
|
+ console.error('靶标方案更新失败:', err);
|
|
|
+ this.$message.error('靶标方案保存失败,请重试');
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ // 同步干扰方案文件列表
|
|
|
+ handleInteFileChange(file, fileList) {
|
|
|
+ this.inteFileList = fileList; // ✅ 手动同步
|
|
|
+ },
|
|
|
+
|
|
|
+ // 同步靶标方案文件列表
|
|
|
+ handleTargetFileChange(file, fileList) {
|
|
|
+ this.targetFileList = fileList; // ✅ 手动同步
|
|
|
},
|
|
|
|
|
|
// 上传失败处理
|
|
|
@@ -287,28 +362,151 @@ export default {
|
|
|
this.$message.error('文件上传失败,请重试');
|
|
|
},
|
|
|
|
|
|
+ /**
|
|
|
+ * 合并 schemeSubPlan
|
|
|
+ * @param {Array} existingList - 已有的文件列表(解析后的)
|
|
|
+ * @param {Object} newFile - 新上传的文件信息 { fileName, fileHttp, fileType, type }
|
|
|
+ * @returns {Array} 合并后的列表
|
|
|
+ */
|
|
|
+ mergeSchemeSubPlan(existingList, newFile) {
|
|
|
+ // 1. 先过滤掉同 type 的旧文件(保证每个 type 只有一个)
|
|
|
+ const filtered = existingList.filter(item => item.type !== newFile.type);
|
|
|
+
|
|
|
+ // 2. 添加新文件
|
|
|
+ return [...filtered, newFile];
|
|
|
+ },
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 解析 schemeSubPlan 字符串为数组
|
|
|
+ * @returns {Array} 解析后的文件列表
|
|
|
+ */
|
|
|
+ parseSchemeSubPlan() {
|
|
|
+ try {
|
|
|
+ console.log(this.selectPlan.schemeSubPlan)
|
|
|
+ const str = this.selectPlan.schemeSubPlan;
|
|
|
+ return str ? JSON.parse(str) : [];
|
|
|
+ } catch (error) {
|
|
|
+ console.error('解析 schemeSubPlan 失败:', error);
|
|
|
+ return [];
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
// 提交干扰方案上传
|
|
|
- submitInteUpload() {
|
|
|
+ async submitInteUpload() {
|
|
|
if (this.inteFileList.length === 0) {
|
|
|
this.$message.warning('请先选择文件');
|
|
|
return;
|
|
|
}
|
|
|
- // 手动触发上传
|
|
|
- document.querySelector('.upload-demo [type="file"]').dispatchEvent(
|
|
|
- new Event('change', { bubbles: true })
|
|
|
- );
|
|
|
+
|
|
|
+ const formData = new FormData();
|
|
|
+ this.inteFileList.forEach(file => {
|
|
|
+ if (file.raw) {
|
|
|
+ formData.append('files', file.raw);
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ try {
|
|
|
+ const response = await doUpload(formData);
|
|
|
+ if (response.code !== 0) {
|
|
|
+ this.$message.error(`上传失败: ${response.msg || '未知错误'}`);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // ✅ 1. 构造新文件对象
|
|
|
+ const newFile = {
|
|
|
+ fileName: this.inteFileList[0].name,
|
|
|
+ fileHttp: response.data.fileStoragePath,
|
|
|
+ fileType: response.data.suffix,
|
|
|
+ type: 1 // 干扰方案
|
|
|
+ };
|
|
|
+
|
|
|
+ // ✅ 2. 解析已有数据
|
|
|
+ const existingList = this.parseSchemeSubPlan();
|
|
|
+
|
|
|
+ // ✅ 3. 合并
|
|
|
+ const mergedList = this.mergeSchemeSubPlan(existingList, newFile);
|
|
|
+
|
|
|
+ // ✅ 4. 转为 JSON 字符串
|
|
|
+ const fileJson = JSON.stringify(mergedList);
|
|
|
+
|
|
|
+ // ✅ 5. 更新干扰方案
|
|
|
+ await planningSchemeUpdateInte({
|
|
|
+ id: this.selectPlan.id,
|
|
|
+ schemeSubPlan: fileJson
|
|
|
+ });
|
|
|
+
|
|
|
+ // ✅ 6. 成功后清空
|
|
|
+ this.showInteUpload = false;
|
|
|
+ this.inteFileList = [];
|
|
|
+ this.$refs.inteUpload?.clearFiles(); // 注意:是 inteUpload,不是 targetUpload
|
|
|
+
|
|
|
+ // ✅ 7. 刷新
|
|
|
+ this.handleQuery();
|
|
|
+ this.$message.success('干扰方案上传并更新成功');
|
|
|
+
|
|
|
+ } catch (error) {
|
|
|
+ console.error('上传或更新失败:', error);
|
|
|
+ this.$message.error('操作失败:' + (error.message || '请重试'));
|
|
|
+ }
|
|
|
},
|
|
|
|
|
|
// 提交靶标方案上传
|
|
|
- submitTargetUpload() {
|
|
|
+ async submitTargetUpload() {
|
|
|
if (this.targetFileList.length === 0) {
|
|
|
this.$message.warning('请先选择文件');
|
|
|
return;
|
|
|
}
|
|
|
- // 手动触发上传
|
|
|
- document.querySelector('.upload-demo [type="file"]').dispatchEvent(
|
|
|
- new Event('change', { bubbles: true })
|
|
|
- );
|
|
|
+
|
|
|
+ const formData = new FormData();
|
|
|
+ this.targetFileList.forEach(file => {
|
|
|
+ if (file.raw) {
|
|
|
+ formData.append('files', file.raw);
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ try {
|
|
|
+ const response = await doUpload(formData);
|
|
|
+ if (response.code !== 0) {
|
|
|
+ this.$message.error(`上传失败: ${response.msg || '未知错误'}`);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // ✅ 1. 构造新文件对象
|
|
|
+ const newFile = {
|
|
|
+ fileName: this.targetFileList[0].name,
|
|
|
+ fileHttp: response.data.fileStoragePath,
|
|
|
+ fileType: response.data.suffix,
|
|
|
+ type: 2 // 靶标方案
|
|
|
+ };
|
|
|
+
|
|
|
+ // ✅ 2. 解析已有数据
|
|
|
+ const existingList = this.parseSchemeSubPlan();
|
|
|
+
|
|
|
+ // ✅ 3. 合并
|
|
|
+ const mergedList = this.mergeSchemeSubPlan(existingList, newFile);
|
|
|
+
|
|
|
+ // ✅ 4. 转为 JSON 字符串
|
|
|
+ const fileJson = JSON.stringify(mergedList);
|
|
|
+
|
|
|
+ // ✅ 5. 更新靶标方案
|
|
|
+ await planningSchemeUpdateTarget({
|
|
|
+ id: this.selectPlan.id,
|
|
|
+ schemeSubPlan: fileJson
|
|
|
+ });
|
|
|
+
|
|
|
+ // ✅ 6. 成功后清空
|
|
|
+ this.showTargetUpload = false;
|
|
|
+ this.targetFileList = [];
|
|
|
+ this.$refs.targetUpload?.clearFiles();
|
|
|
+
|
|
|
+ // ✅ 7. 刷新
|
|
|
+ this.handleQuery();
|
|
|
+ this.$message.success('靶标方案上传并更新成功');
|
|
|
+
|
|
|
+ } catch (error) {
|
|
|
+ console.error('上传或更新失败:', error);
|
|
|
+ this.$message.error('操作失败:' + (error.message || '请重试'));
|
|
|
+ }
|
|
|
},
|
|
|
|
|
|
handleClose(done) {
|
|
|
@@ -334,9 +532,11 @@ export default {
|
|
|
// 根据不同类型和状态判断显示上传还是跳转
|
|
|
if (val.type === "inte" && plan.interferenceSchemeStatus === '未导入') {
|
|
|
console.log("干扰方案未导入,显示上传组件")
|
|
|
+ this.selectPlan = plan;
|
|
|
this.showInteUpload = true;
|
|
|
} else if (val.type === "target" && plan.targetSchemeStatus === '未导入') {
|
|
|
console.log("靶标方案未导入,显示上传组件")
|
|
|
+ this.selectPlan = plan;
|
|
|
this.showTargetUpload = true;
|
|
|
} else if (val.type === "meas") {
|
|
|
this.$router.push({path: "/childPlan/measPlan", query: {val, plan}})
|