detail.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <template>
  2. <div class="form-page">
  3. <div class="page-header">
  4. <h2 class="page-title">{{ pageTitle }}</h2>
  5. </div>
  6. <!-- 船舶基本信息 -->
  7. <BasicInformationOfVessel class="mb20" />
  8. <!-- 安检基本信息 -->
  9. <BasicInformationOfSecurity />
  10. <!-- 缺陷信息 -->
  11. <DefectInformation />
  12. <!-- 底部按钮区 -->
  13. <div class="form-actions">
  14. <slot name="btn">
  15. <el-button type="primary" @click="handleSubmit">发布通报</el-button>
  16. <el-button type="primary" @click="router.back">返回</el-button>
  17. </slot>
  18. </div>
  19. </div>
  20. </template>
  21. <script setup lang="ts" name="CommonForm">
  22. import { ref, onMounted, onBeforeUnmount } from 'vue';
  23. import { useRoute, useRouter } from 'vue-router';
  24. import BasicInformationOfVessel from '@/components/notificationDetailsParts/basicInformationOfVessel.vue';
  25. import BasicInformationOfSecurity from '@/components/notificationDetailsParts/basicInformationOfSecurity.vue';
  26. import DefectInformation from '@/components/notificationDetailsParts/defectInformation.vue';
  27. // --- 路由与Store ---
  28. const route = useRoute();
  29. const router = useRouter();
  30. const pageTitle = ref(''); // 页面标题
  31. const isDetail = ref(false); // 是否为详情模式
  32. const isEdit = ref(false); // 是否为编辑模式
  33. const noticeChildRef = ref<any>();
  34. onMounted(async () => {
  35. const { type, id } = route.query;
  36. try {
  37. switch (type as string) {
  38. case 'add':
  39. pageTitle.value = '安全检查通告信息 新增信息';
  40. isEdit.value = false;
  41. break;
  42. case 'edit':
  43. pageTitle.value = '安全检查通告信息 编辑信息';
  44. isEdit.value = true;
  45. break;
  46. case 'detail':
  47. pageTitle.value = '安全检查通告信息';
  48. isDetail.value = true;
  49. break;
  50. default:
  51. throw new Error(`无效操作类型: ${type}`);
  52. }
  53. } catch (error) {
  54. handleBack();
  55. } finally {}
  56. });
  57. const handleBack = () => {
  58. router.go(-1);
  59. };
  60. onBeforeUnmount(() => {
  61. isDetail.value = false;
  62. isEdit.value = false;
  63. });
  64. const handleSubmit = async () => {
  65. // 调用子组件的校验方法
  66. const isValid = await noticeChildRef.value.validateForm();
  67. if (isValid) {
  68. console.log('校验通过,执行提交逻辑');
  69. } else {
  70. console.log('校验失败,请检查表单');
  71. }
  72. };
  73. </script>
  74. <style scoped lang="scss">
  75. .form-page {
  76. padding: 20px;
  77. background-color: #fff;
  78. }
  79. .page-header {
  80. display: flex;
  81. align-items: center;
  82. justify-content: center;
  83. width: 100%;
  84. margin-bottom: 30px;
  85. .page-title {
  86. font-size: 22px;
  87. font-weight: 500;
  88. color: #5070ae;
  89. }
  90. }
  91. .form-actions {
  92. display: flex;
  93. justify-content: center;
  94. margin-top: 40px;
  95. gap: 16px;
  96. .el-button {
  97. padding: 8px 24px;
  98. }
  99. }
  100. // 响应式调整
  101. @media (max-width: 768px) {
  102. .form-container {
  103. padding: 15px;
  104. }
  105. .page-header {
  106. flex-direction: column;
  107. align-items: flex-start;
  108. gap: 10px;
  109. }
  110. }
  111. </style>