<template>
  <div class="about-page">
    <h2>关于 — Vue3 子应用</h2>

    <div class="card">
      <h4>路由冲突验证</h4>
      <p>
        此页面路径为 <code>/about</code>，与主应用的同名路由
        <strong>不会冲突</strong>。
      </p>
      <p>
        因为在主应用中，此子应用的 URL 前缀是 <code>/vue3-app</code>，
        访问此页面的实际 URL 是：
      </p>
      <div class="url-demo">
        <code>http://localhost:8080/vue3-app/about</code>
      </div>
      <p class="note">
        主应用的 <code>/about</code> 和子应用的 <code>/about</code>
        处于不同的 URL 命名空间，互不干扰。
      </p>
    </div>

    <div class="card">
      <h4>micro-app 环境信息</h4>
      <table>
        <tbody>
        <tr>
          <td>是否微前端环境</td>
          <td><code>{{ isMicroApp ? '是' : '否（独立运行）' }}</code></td>
        </tr>
        <tr>
          <td>baseroute</td>
          <td><code>{{ baseRoute }}</code></td>
        </tr>
        <tr>
          <td>应用名称</td>
          <td><code>{{ appName }}</code></td>
        </tr>
        <tr>
          <td>window.location.pathname</td>
          <td><code>{{ locationPath }}</code></td>
        </tr>
        </tbody>
      </table>
    </div>

    <router-link to="/" class="back-link">← 返回首页</router-link>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue'

const isMicroApp = !!(window as any).__MICRO_APP_ENVIRONMENT__
const baseRoute = (window as any).__MICRO_APP_BASE_ROUTE__ || '/'
const appName = (window as any).__MICRO_APP_NAME__ || '独立运行'
const locationPath = ref(window.location.pathname)
</script>

<style scoped>
.about-page {
  max-width: 720px;
  margin: 0 auto;
  padding: 40px 24px;
}

.about-page h2 {
  font-size: 24px;
  font-weight: 700;
  color: #42b883;
  margin-bottom: 24px;
  text-align: center;
}

.card {
  padding: 24px;
  background: #fff;
  border-radius: 10px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
  margin-bottom: 20px;
}

.card h4 {
  font-size: 16px;
  color: #444;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid #f0f0f0;
}

.card p {
  font-size: 14px;
  color: #666;
  line-height: 1.8;
}

.card code {
  background: #f0faf3;
  color: #2e7d32;
  padding: 2px 6px;
  border-radius: 3px;
  font-size: 13px;
}

.url-demo {
  margin: 12px 0;
  padding: 12px;
  background: #f5f5f5;
  border-radius: 6px;
  text-align: center;
}

.url-demo code {
  font-size: 14px;
  color: #42b883;
  word-break: break-all;
}

.note {
  margin-top: 12px;
  padding: 8px 16px;
  background: #fff3e0;
  border-radius: 6px;
  font-size: 13px !important;
  color: #e65100 !important;
}

table {
  width: 100%;
  border-collapse: collapse;
}

td {
  padding: 8px 12px;
  border-bottom: 1px solid #f0f0f0;
  font-size: 14px;
}

td:first-child {
  color: #999;
  width: 120px;
}

td code {
  background: #f5f5f5;
  padding: 2px 6px;
  border-radius: 3px;
  font-size: 13px;
  color: #42b883;
}

.back-link {
  display: inline-block;
  margin-top: 16px;
  color: #42b883;
  text-decoration: none;
  font-size: 14px;
}

.back-link:hover {
  text-decoration: underline;
}
</style>
