index.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586
  1. <template>
  2. <div>
  3. <DarkLayout :query-form="queryForm">
  4. <!-- 查询表单插槽 -->
  5. <template #query-form>
  6. <el-form-item label="方案名称">
  7. <el-input
  8. v-model="queryForm.taskName"
  9. placeholder="请输入方案名称"
  10. clearable
  11. />
  12. </el-form-item>
  13. <el-form-item label="方案代号">
  14. <el-input
  15. v-model="queryForm.taskCode"
  16. placeholder="请输入任务代号"
  17. clearable
  18. />
  19. </el-form-item>
  20. </template>
  21. <!-- Header右侧操作按钮 -->
  22. <template #header-actions>
  23. <el-button type="primary" @click="handleQuery">查询</el-button>
  24. <el-button class="blue-btn" @click="resetQuery">重置</el-button>
  25. <el-button class="blue-btn" @click="handleAdd">新增</el-button>
  26. </template>
  27. <!-- 主要内容 -->
  28. <template #main>
  29. <OverallCard
  30. v-if="plans.length > 0"
  31. v-for="plan in plans"
  32. :key="plan.id"
  33. :plan="plan"
  34. @view-detail="handleViewDetail"
  35. @export-plan="handleExportPlan"
  36. @link-to="(val) => linkTo(val, plan)"
  37. />
  38. <el-empty v-else description="暂无方案数据" />
  39. </template>
  40. <!-- 底部右侧分页 -->
  41. <template #footer-actions>
  42. <el-pagination
  43. @size-change="handleSizeChange"
  44. @current-change="handleCurrentChange"
  45. :current-page="pagination.currentPage"
  46. :page-sizes="[10, 20, 50, 100]"
  47. :page-size="pagination.pageSize"
  48. layout="total, sizes, prev, pager, next, jumper"
  49. :total="pagination.total"
  50. />
  51. </template>
  52. </DarkLayout>
  53. <!-- 干扰方案上传弹窗 -->
  54. <DarkDialog
  55. :visible.sync="showInteUpload"
  56. title="上传干扰方案"
  57. width="50%">
  58. <el-upload
  59. class="upload-demo"
  60. ref="inteUpload"
  61. action="#"
  62. :file-list="inteFileList"
  63. accept=".doc,.docx,.pdf,.xlsx,.xls"
  64. :auto-upload="false"
  65. :on-change="handleInteFileChange"
  66. :limit="1"
  67. >
  68. <el-button slot="trigger" size="small" type="primary">选取文件</el-button>
  69. <el-button style="margin-left: 10px;" size="small" type="success" @click="submitInteUpload">
  70. 上传到服务器
  71. </el-button>
  72. <div slot="tip" class="el-upload__tip">
  73. 只能上传doc、docx、pdf、xlsx、xls格式的文件
  74. </div>
  75. </el-upload>
  76. <span slot="footer" class="dialog-footer">
  77. <el-button @click="showInteUpload = false">取消</el-button>
  78. </span>
  79. </DarkDialog>
  80. <!-- 靶标方案上传弹窗 -->
  81. <DarkDialog
  82. :visible.sync="showTargetUpload"
  83. title="上传靶标方案"
  84. width="50%">
  85. <el-upload
  86. class="upload-demo"
  87. ref="targetUpload"
  88. action="#"
  89. :file-list="targetFileList"
  90. accept=".doc,.docx,.pdf,.xlsx,.xls"
  91. :auto-upload="false"
  92. :on-change="handleTargetFileChange"
  93. :limit="1"
  94. >
  95. <el-button slot="trigger" size="small" type="primary">选取文件</el-button>
  96. <el-button style="margin-left: 10px;" size="small" type="success" @click="submitTargetUpload">
  97. 上传到服务器
  98. </el-button>
  99. <div slot="tip" class="el-upload__tip">
  100. 只能上传doc、docx、pdf、xlsx、xls格式的文件
  101. </div>
  102. </el-upload>
  103. <span slot="footer" class="dialog-footer">
  104. <el-button @click="showTargetUpload = false">取消</el-button>
  105. </span>
  106. </DarkDialog>
  107. <!-- 任务详情弹窗 -->
  108. <DarkDialog title="任务详情"
  109. :visible.sync="dialogVisible"
  110. width="50%"
  111. :before-close="handleClose">
  112. <el-descriptions :column="2" border>
  113. <el-descriptions-item label="方案名称">{{ currentPlan.planName }}</el-descriptions-item>
  114. <el-descriptions-item label="任务名称">{{ currentPlan.taskName }}</el-descriptions-item>
  115. <el-descriptions-item label="任务代号">{{ currentPlan.taskCode }}</el-descriptions-item>
  116. <el-descriptions-item label="开始时间">{{ currentPlan.startTime }}</el-descriptions-item>
  117. <el-descriptions-item label="结束时间">{{ currentPlan.endTime }}</el-descriptions-item>
  118. <el-descriptions-item label="编制状态">{{ currentPlan.compileStatus }}</el-descriptions-item>
  119. <el-descriptions-item label="状态">{{ currentPlan.status }}</el-descriptions-item>
  120. </el-descriptions>
  121. <span slot="footer" class="dialog-footer">
  122. <el-button @click="dialogVisible = false">关闭</el-button>
  123. </span>
  124. </DarkDialog>
  125. </div>
  126. </template>
  127. <script>
  128. import DarkLayout from '@/components/GlobalComponents/DarkLayout.vue'
  129. import InterferenceCard from '@/components/Components/InterferenceCard.vue'
  130. import DarkDialog from "@/components/Components/DarkDialog.vue";
  131. import {
  132. planningSchemePage,
  133. planningSchemeUpdate, planningSchemeUpdateInte,
  134. planningSchemeUpdateTarget,
  135. planningSchemeUploadTarget
  136. } from "@/api/planningScheme";
  137. import {exportSolutionToWord} from "@/views/planningSchem/comprehensive/wordExporter";
  138. import { baseURL,contentType,tokenName } from "@/config";
  139. import store from "@/store";
  140. import {doUpload} from "@/api/tool/ossTool";
  141. export default {
  142. components: {
  143. DarkDialog,
  144. DarkLayout,
  145. InterferenceCard
  146. },
  147. data() {
  148. return {
  149. tableData: [
  150. {
  151. date: '2023-06-01',
  152. name: '张三',
  153. address: '北京市海淀区'
  154. },
  155. {
  156. date: '2023-06-02',
  157. name: '李四',
  158. address: '上海市浦东新区'
  159. }
  160. ],
  161. dialogVisible: false,
  162. currentPlan: {}, // 当前选中的任务数据
  163. queryForm: {
  164. taskName: '',
  165. taskCode: ''
  166. },
  167. plans:[],
  168. planss: [
  169. {
  170. id: '1',
  171. fightAway:"对陆",
  172. planName: '新型导弹打击试验',
  173. taskName: '新型导弹打击试验',
  174. taskCode: 'TASK-2023-001',
  175. startTime: '2023-01-01',
  176. endTime: '2023-12-31',
  177. status: '有效',
  178. interferenceSchemeStatus: '已导入',
  179. measurementSchemeStatus: '已编制',
  180. targetSchemeStatus: '已导入',
  181. version: 'V1.0.0'
  182. },
  183. {
  184. id: '2',
  185. fightAway:"对陆",
  186. planName: '电子对抗演练',
  187. taskName: '电子对抗演练',
  188. taskCode: 'TASK-2023-002',
  189. startTime: '2023-02-01',
  190. endTime: '2023-11-30',
  191. status: '待审核',
  192. interferenceSchemeStatus: '已导入',
  193. measurementSchemeStatus: '已编制',
  194. targetSchemeStatus: '未导入',
  195. version: 'V1.1.0'
  196. },
  197. {
  198. id: '4',
  199. fightAway:"对陆",
  200. planName: '电子对抗演练',
  201. taskName: '电子对抗演练',
  202. taskCode: 'TASK-2023-003',
  203. startTime: '2023-03-01',
  204. endTime: '2023-10-31',
  205. status: '草稿',
  206. interferenceSchemeStatus: '未导入',
  207. measurementSchemeStatus: '未编制',
  208. targetSchemeStatus: '未导入',
  209. version: 'V0.9.0'
  210. },
  211. {
  212. id: '3',
  213. fightAway:"对陆",
  214. planName: '新型导弹打击试验',
  215. taskName: '新型导弹打击试验',
  216. taskCode: 'TASK-2023-003',
  217. startTime: '2023-03-01',
  218. endTime: '2023-10-31',
  219. status: '草稿',
  220. interferenceSchemeStatus: '已导入',
  221. measurementSchemeStatus: '未编制',
  222. targetSchemeStatus: '未导入',
  223. version: 'V0.9.0'
  224. },
  225. {
  226. id: '9',
  227. fightAway:"对陆",
  228. planName: '电子对抗演练',
  229. taskName: '电子对抗演练',
  230. taskCode: 'TASK-2023-001',
  231. startTime: '2023-01-01',
  232. endTime: '2023-12-31',
  233. status: '有效',
  234. interferenceSchemeStatus: '已导入',
  235. measurementSchemeStatus: '已编制',
  236. targetSchemeStatus: '未导入',
  237. version: 'V1.0.0'
  238. },
  239. ],
  240. pagination: {
  241. currentPage: 1,
  242. pageSize: 10,
  243. total: 0
  244. },
  245. selectPlan:null,
  246. showAdvancedSearch: false,
  247. showInteUpload: false, // 干扰方案上传弹窗
  248. showTargetUpload: false, // 靶标方案上传弹窗
  249. inteFileList: [], // 干扰方案文件列表
  250. targetFileList: [] // 靶标方案文件列表
  251. }
  252. },
  253. mounted() {
  254. this.handleQuery();
  255. },
  256. methods: {
  257. // 页面导航方法
  258. navigateTo(type, isOk) {
  259. if (type === "inte") {
  260. console.log("跳转至干扰方案", {isOk})
  261. this.$router.push({path: "/childPlan/intePlan", query: {isOk}})
  262. } else if (type === "target") {
  263. this.$router.push({path: "/childPlan/targetPlan", query: {isOk}})
  264. }
  265. },
  266. // 干扰方案上传成功处理
  267. async handleInteUploadSuccess(response, file, fileList) {
  268. if(response.code !==200){
  269. this.$message.success('干扰方案上传失败');
  270. return;
  271. }
  272. this.$message.success('干扰方案上传成功');
  273. const fileJson = JSON.stringify(
  274. fileList.map(item => ({
  275. fileName: item.name,
  276. fileHttp: item.response?.data?.url || '',
  277. fileType: item.response?.data?.type || '',
  278. type: 1
  279. })).filter(item => item.fileHttp)
  280. );
  281. try {
  282. await planningSchemeUpdate({
  283. id: this.selectPlan.id,
  284. interferenceSchemeStatus: '已导入',
  285. schemeSubPlan: fileJson
  286. });
  287. this.showInteUpload = false;
  288. this.inteFileList = [];
  289. this.handleQuery();
  290. } catch (err) {
  291. console.error('更新方案失败:', err);
  292. this.$message.error('方案更新失败');
  293. }
  294. },
  295. // 靶标方案上传成功处理
  296. async handleTargetUploadSuccess(response, file, fileList) {
  297. if(response.code !==200){
  298. this.$message.success('靶标方案上传失败');
  299. return;
  300. }
  301. this.$message.success('靶标方案上传成功');
  302. // 1. 将 fileList 转为 JSON(和干扰方案保持一致)
  303. const fileJson = JSON.stringify(
  304. fileList.map(item => ({
  305. fileName: item.name,
  306. fileHttp: item.response?.data?.url || '',
  307. fileType: item.response?.data?.type || '',
  308. type: 2
  309. })).filter(item => item.fileHttp) // 过滤掉上传失败的文件
  310. );
  311. try {
  312. // 2. 调用 API 更新靶标方案
  313. await planningSchemeUpdate({
  314. id: this.selectPlan.id,
  315. schemeSubPlan: fileJson
  316. });
  317. // 3. 更新 UI 状态
  318. this.showTargetUpload = false;
  319. this.targetFileList = [];
  320. // 4. 刷新数据
  321. this.handleQuery();
  322. } catch (err) {
  323. console.error('靶标方案更新失败:', err);
  324. this.$message.error('靶标方案保存失败,请重试');
  325. }
  326. },
  327. // 同步干扰方案文件列表
  328. handleInteFileChange(file, fileList) {
  329. this.inteFileList = fileList; // ✅ 手动同步
  330. },
  331. // 同步靶标方案文件列表
  332. handleTargetFileChange(file, fileList) {
  333. this.targetFileList = fileList; // ✅ 手动同步
  334. },
  335. // 上传失败处理
  336. handleUploadError(err, file, fileList) {
  337. this.$message.error('文件上传失败,请重试');
  338. },
  339. /**
  340. * 合并 schemeSubPlan
  341. * @param {Array} existingList - 已有的文件列表(解析后的)
  342. * @param {Object} newFile - 新上传的文件信息 { fileName, fileHttp, fileType, type }
  343. * @returns {Array} 合并后的列表
  344. */
  345. mergeSchemeSubPlan(existingList, newFile) {
  346. // 1. 先过滤掉同 type 的旧文件(保证每个 type 只有一个)
  347. const filtered = existingList.filter(item => item.type !== newFile.type);
  348. // 2. 添加新文件
  349. return [...filtered, newFile];
  350. },
  351. /**
  352. * 解析 schemeSubPlan 字符串为数组
  353. * @returns {Array} 解析后的文件列表
  354. */
  355. parseSchemeSubPlan() {
  356. try {
  357. console.log(this.selectPlan.schemeSubPlan)
  358. const str = this.selectPlan.schemeSubPlan;
  359. return str ? JSON.parse(str) : [];
  360. } catch (error) {
  361. console.error('解析 schemeSubPlan 失败:', error);
  362. return [];
  363. }
  364. },
  365. // 提交干扰方案上传
  366. async submitInteUpload() {
  367. if (this.inteFileList.length === 0) {
  368. this.$message.warning('请先选择文件');
  369. return;
  370. }
  371. const formData = new FormData();
  372. this.inteFileList.forEach(file => {
  373. if (file.raw) {
  374. formData.append('files', file.raw);
  375. }
  376. });
  377. try {
  378. const response = await doUpload(formData);
  379. if (response.code !== 0) {
  380. this.$message.error(`上传失败: ${response.msg || '未知错误'}`);
  381. return;
  382. }
  383. // ✅ 1. 构造新文件对象
  384. const newFile = {
  385. fileName: this.inteFileList[0].name,
  386. fileHttp: response.data.fileStoragePath,
  387. fileType: response.data.suffix,
  388. type: 1 // 干扰方案
  389. };
  390. // ✅ 2. 解析已有数据
  391. const existingList = this.parseSchemeSubPlan();
  392. // ✅ 3. 合并
  393. const mergedList = this.mergeSchemeSubPlan(existingList, newFile);
  394. // ✅ 4. 转为 JSON 字符串
  395. const fileJson = JSON.stringify(mergedList);
  396. // ✅ 5. 更新干扰方案
  397. await planningSchemeUpdateInte({
  398. id: this.selectPlan.id,
  399. schemeSubPlan: fileJson
  400. });
  401. // ✅ 6. 成功后清空
  402. this.showInteUpload = false;
  403. this.inteFileList = [];
  404. this.$refs.inteUpload?.clearFiles(); // 注意:是 inteUpload,不是 targetUpload
  405. // ✅ 7. 刷新
  406. this.handleQuery();
  407. this.$message.success('干扰方案上传并更新成功');
  408. } catch (error) {
  409. console.error('上传或更新失败:', error);
  410. this.$message.error('操作失败:' + (error.message || '请重试'));
  411. }
  412. },
  413. // 提交靶标方案上传
  414. async submitTargetUpload() {
  415. if (this.targetFileList.length === 0) {
  416. this.$message.warning('请先选择文件');
  417. return;
  418. }
  419. const formData = new FormData();
  420. this.targetFileList.forEach(file => {
  421. if (file.raw) {
  422. formData.append('files', file.raw);
  423. }
  424. });
  425. try {
  426. const response = await doUpload(formData);
  427. if (response.code !== 0) {
  428. this.$message.error(`上传失败: ${response.msg || '未知错误'}`);
  429. return;
  430. }
  431. // ✅ 1. 构造新文件对象
  432. const newFile = {
  433. fileName: this.targetFileList[0].name,
  434. fileHttp: response.data.fileStoragePath,
  435. fileType: response.data.suffix,
  436. type: 2 // 靶标方案
  437. };
  438. // ✅ 2. 解析已有数据
  439. const existingList = this.parseSchemeSubPlan();
  440. // ✅ 3. 合并
  441. const mergedList = this.mergeSchemeSubPlan(existingList, newFile);
  442. // ✅ 4. 转为 JSON 字符串
  443. const fileJson = JSON.stringify(mergedList);
  444. // ✅ 5. 更新靶标方案
  445. await planningSchemeUpdateTarget({
  446. id: this.selectPlan.id,
  447. schemeSubPlan: fileJson
  448. });
  449. // ✅ 6. 成功后清空
  450. this.showTargetUpload = false;
  451. this.targetFileList = [];
  452. this.$refs.targetUpload?.clearFiles();
  453. // ✅ 7. 刷新
  454. this.handleQuery();
  455. this.$message.success('靶标方案上传并更新成功');
  456. } catch (error) {
  457. console.error('上传或更新失败:', error);
  458. this.$message.error('操作失败:' + (error.message || '请重试'));
  459. }
  460. },
  461. handleClose(done) {
  462. done();
  463. },
  464. handleViewDetail(plan) {
  465. this.$router.push({ path: '/planningSchem/overallPlanDesign',query:{batchId:plan.batchId} })
  466. },
  467. //导出
  468. async handleExportPlan(plan) {
  469. try {
  470. await exportSolutionToWord(plan.batchId);
  471. this.$message.success('导出Word成功');
  472. } catch (error) {
  473. this.$message.error(error.message || '导出Word失败');
  474. }
  475. // this.$message.success("导出成功!")
  476. },
  477. // 子方案跳转,增加plan参数用于获取方案状态
  478. linkTo(val, plan) {
  479. console.log('linkTo参数:', val, '方案状态:', plan)
  480. // 根据不同类型和状态判断显示上传还是跳转
  481. if (val.type === "inte" && plan.interferenceSchemeStatus === '未导入') {
  482. console.log("干扰方案未导入,显示上传组件")
  483. this.selectPlan = plan;
  484. this.showInteUpload = true;
  485. } else if (val.type === "target" && plan.targetSchemeStatus === '未导入') {
  486. console.log("靶标方案未导入,显示上传组件")
  487. this.selectPlan = plan;
  488. this.showTargetUpload = true;
  489. } else if (val.type === "meas") {
  490. this.$router.push({path: "/childPlan/measPlan", query: {val, plan}})
  491. } else {
  492. // 已导入/已编制状态正常跳转
  493. this.navigateTo(val.type, val.isOk);
  494. }
  495. },
  496. async handleQuery() {
  497. // 查询逻辑
  498. const res = await planningSchemePage({
  499. ...this.queryForm,
  500. pageNo:this.pagination.currentPage,
  501. pageSize:this.pagination.pageSize,
  502. })
  503. this.plans = res.data.records
  504. this.pagination.total = res.data.total
  505. },
  506. resetQuery() {
  507. this.queryForm = {
  508. taskName: '',
  509. taskCode: ''
  510. }
  511. this.handleQuery()
  512. },
  513. handleAdd() {
  514. this.$router.push({path: '/childPlans/associationTask'})
  515. },
  516. handleSizeChange(val) {
  517. this.pagination.pageSize = val
  518. this.fetchData()
  519. },
  520. handleCurrentChange(val) {
  521. this.pagination.currentPage = val
  522. this.fetchData()
  523. },
  524. fetchData() {
  525. // 获取数据逻辑
  526. }
  527. }
  528. }
  529. </script>
  530. <style scoped>
  531. </style>