<template>
  <div class="policy-container">
    <el-card>
      <div class="policy-content" v-html="policyContent"></div>
    </el-card>
  </div>
</template>

<script setup lang="ts">
import { ref, onMounted } from 'vue';
import DOMPurify from 'dompurify';
import { getPrivacyPolicyListMax } from '@/api/system/business/policy';

const policyContent = ref('');

onMounted(() => {
  fetchPolicy();
});

const fetchPolicy = async () => {
  try {
    const res = await getPrivacyPolicyListMax();
    policyContent.value = DOMPurify.sanitize(res.data.content || '<p>内容加载失败</p>');
  } catch (error) {
    console.error('获取隐私政策失败', error);
    policyContent.value = '<p>内容加载失败</p>';
  }
};
</script>

<style scoped>
.policy-container {
  padding: 20px;
  max-width: 800px;
  margin: 0 auto;
}

.policy-content {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  font-size: 14px;
  line-height: 1.6;
  color: #333;
  word-wrap: break-word;
}

/* 标题样式 */
.policy-content h1 {
  font-size: 24px;
  font-weight: bold;
  margin: 24px 0 16px 0;
  color: #2c3e50;
  text-align: center;
}

.policy-content h2 {
  font-size: 20px;
  font-weight: bold;
  margin: 20px 0 12px 0;
  color: #34495e;
  border-bottom: 1px solid #eee;
  padding-bottom: 8px;
}

.policy-content h3 {
  font-size: 18px;
  font-weight: bold;
  margin: 16px 0 10px 0;
  color: #555;
}

/* 段落样式 */
.policy-content p {
  margin: 12px 0;
  line-height: 1.7;
}

/* 列表样式 */
.policy-content ul,
.policy-content ol {
  margin: 12px 0;
  padding-left: 24px;
}

.policy-content li {
  margin: 8px 0;
  line-height: 1.6;
}

.policy-content ul li {
  list-style-type: disc;
}

.policy-content ol li {
  list-style-type: decimal;
}

/* 强调文本 */
.policy-content strong {
  font-weight: bold;
  color: #2c3e50;
}

.policy-content em {
  font-style: italic;
}

/* 链接样式 */
.policy-content a {
  color: #3498db;
  text-decoration: none;
}

.policy-content a:hover {
  text-decoration: underline;
}

/* 代码样式 */
.policy-content code {
  background-color: #f8f9fa;
  padding: 2px 4px;
  border-radius: 3px;
  font-family: 'Courier New', monospace;
  font-size: 13px;
}

/* 引用样式 */
.policy-content blockquote {
  border-left: 4px solid #ddd;
  margin: 16px 0;
  padding: 8px 16px;
  background-color: #f9f9f9;
  color: #666;
}

/* 表格样式 */
.policy-content table {
  width: 100%;
  border-collapse: collapse;
  margin: 16px 0;
}

.policy-content table th,
.policy-content table td {
  border: 1px solid #ddd;
  padding: 8px 12px;
  text-align: left;
}

.policy-content table th {
  background-color: #f2f2f2;
  font-weight: bold;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .policy-container {
    padding: 15px;
  }

  .policy-content {
    font-size: 13px;
  }

  .policy-content h1 {
    font-size: 20px;
    margin: 20px 0 14px 0;
  }

  .policy-content h2 {
    font-size: 18px;
    margin: 18px 0 10px 0;
  }

  .policy-content h3 {
    font-size: 16px;
    margin: 14px 0 8px 0;
  }

  .el-card {
    width: 100%;
    margin: 0 auto;
  }

  .policy-content ul,
  .policy-content ol {
    padding-left: 20px;
  }
}

/* 处理可能的空白内容 */
.policy-content:empty::before {
  content: '暂无内容';
  color: #999;
  font-style: italic;
}
</style>
