<template>
    <div class="form-page">
      <div class="page-header">
        <h2 class="page-title">{{ pageTitle }}</h2>
      </div>
  
      <!-- 主要内容容器 -->
      <slot name="content"></slot>
  
      <!-- 底部按钮区 -->
      <div class="form-actions">
        <slot name="btn"></slot>
      </div>
    </div>
  </template>
  
  <script setup lang="ts" name="CommonForm">
  import { ref, onMounted, onBeforeUnmount } from 'vue';
  import { useRoute, useRouter } from 'vue-router';
  
  // --- 路由与Store ---
  const route = useRoute();
  const router = useRouter();
  
  const pageTitle = ref(''); // 页面标题
  const isDetail = ref(false); // 是否为详情模式
  const isEdit = ref(false); // 是否为编辑模式
  
  onMounted(async () => {
    const { type, id } = route.query;
    try {
      switch (type as string) {
        case 'add':
          pageTitle.value = '水上交通安全信息发布与处置完成管理 新增发布';
          isEdit.value = false;
          break;
        case 'edit':
          pageTitle.value = '水上交通安全信息发布与处置完成管理 编辑发布';
          isEdit.value = true;
          break;
        case 'detail':
          pageTitle.value = '水上交通安全信息发布与处置完成管理 查看发布';
          isDetail.value = true;
          break;
        default:
          throw new Error(`无效操作类型: ${type}`);
      }
    } catch (error) {
      handleBack();
    } finally {}
  });
  
  const handleBack = () => {
    router.go(-1);
  };
  
  onBeforeUnmount(() => {
    isDetail.value = false;
    isEdit.value = false;
  });
  </script>
  
  <style scoped lang="scss">
  .form-page {
    padding: 20px;
    background-color: #fff;
  }
  
  .page-header {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    margin-bottom: 30px;
  
    .page-title {
      font-size: 22px;
      font-weight: 500;
      color: #5070ae;
    }
  }
  
  .form-actions {
    display: flex;
    justify-content: center;
    margin-top: 40px;
    gap: 16px;
  
    .el-button {
      padding: 8px 24px;
    }
  }
  
  // 响应式调整
  @media (max-width: 768px) {
    .form-container {
      padding: 15px;
    }
  
    .page-header {
      flex-direction: column;
      align-items: flex-start;
      gap: 10px;
    }
  }
  </style>