<template>
  <div class="profile-detail">
    <div class="nav-bar">
      <div class="back-btn" @click="goBack">
        <i class="arrow-left"></i>
      </div>
      <div class="title">央企文化</div>
    </div>
    <div class="content">
      <div class="content-card">
        <div class="card-header">
          <div class="header-title">企业文化详情</div>
        </div>
        <div class="card-body">
          <template v-if="processedContent.type === 'iframe'">
            <iframe :src="processedContent.url" frameborder="0" class="content-iframe"></iframe>
          </template>
          <template v-else>
            <div class="content-text" v-html="newsDetail.content"></div>
          </template>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { getNewsDetail } from '@/api/home';
export default {
  name: 'ProfileDetail',
  data() {
    return {
      newsDetail: {}
    }
  },
  computed: {
    processedContent() {
      if (!this.newsDetail.content) return { type: 'content', content: '' };
      
      // 尝试从content中提取URL
      const urlMatch = this.newsDetail.content.match(/https?:\/\/[^\s<>"']+/g);
      
      if (urlMatch && (urlMatch[0].includes('.html') || urlMatch[0].includes('.com'))) {
        // 如果找到URL并且是HTML页面或.com网站，使用iframe展示
        return {
          type: 'iframe',
          url: urlMatch[0]
        };
      } else {
        // 否则保持原有的content展示方式
        return {
          type: 'content',
          content: this.newsDetail.content
        };
      }
    }
  },
  methods: {
    goBack() {
      this.$router.go(-1)
    },
    async getNewsDetail() {
      const formData = new FormData();
      formData.append('id', 8)
      const res = await getNewsDetail(formData)
      this.newsDetail = res.data
    }
  },
  mounted() {
    this.getNewsDetail()
  }
}
</script>

<style lang="scss" scoped>
.profile-detail {
  min-height: 100vh;
  background: linear-gradient(to bottom, #2f9580 0%, #4fb3a1 100%);
}

.nav-bar {
  height: 56px;
  background: rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(10px);
  color: #fff;
  display: flex;
  align-items: center;
  position: relative;
  padding: 0 15px;
}

.back-btn {
  width: 40px;
  height: 40px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.3s ease;
}

.back-btn:hover {
  background: rgba(255, 255, 255, 0.3);
  transform: scale(1.05);
}

.arrow-left {
  width: 12px;
  height: 12px;
  border-left: 2px solid #fff;
  border-bottom: 2px solid #fff;
  transform: rotate(45deg);
}

.title {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  font-size: 18px;
  font-weight: 600;
}

.content {
  padding: 20px;
  min-height: calc(100vh - 56px);
}

.content-card {
  background: #fff;
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
}

.card-header {
  background: linear-gradient(135deg, #2f9580 0%, #4fb3a1 100%);
  padding: 16px 20px;
}

.header-title {
  color: #fff;
  font-size: 16px;
  font-weight: 600;
}

.card-body {
  padding: 20px;
}

.content-text {
  font-size: 16px;
  line-height: 1.8;
  color: #374151;
  word-wrap: break-word;
  
  // 处理内嵌HTML样式
  :deep(h1), :deep(h2), :deep(h3) {
    color: #2f9580;
    margin: 20px 0 15px 0;
    font-weight: 600;
  }
  
  :deep(h1) {
    font-size: 24px;
  }
  
  :deep(h2) {
    font-size: 20px;
  }
  
  :deep(h3) {
    font-size: 18px;
  }
  
  :deep(p) {
    margin: 12px 0;
    text-align: justify;
  }
  
  :deep(ul), :deep(ol) {
    padding-left: 20px;
    margin: 12px 0;
  }
  
  :deep(li) {
    margin: 8px 0;
  }
  
  :deep(img) {
    max-width: 100%;
    height: auto;
    border-radius: 8px;
    margin: 15px 0;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  }
  
  :deep(a) {
    color: #2f9580;
    text-decoration: none;
    border-bottom: 1px solid transparent;
    transition: all 0.3s ease;
  }
  
  :deep(a:hover) {
    border-bottom-color: #2f9580;
  }
  
  :deep(blockquote) {
    border-left: 4px solid #2f9580;
    padding-left: 16px;
    margin: 16px 0;
    background: #f8f9fa;
    padding: 16px;
    border-radius: 0 8px 8px 0;
    font-style: italic;
  }
  
  :deep(table) {
    width: 100%;
    border-collapse: collapse;
    margin: 16px 0;
    background: #fff;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  }
  
  :deep(th), :deep(td) {
    padding: 12px;
    text-align: left;
    border-bottom: 1px solid #e5e7eb;
  }
  
  :deep(th) {
    background: #2f9580;
    color: #fff;
    font-weight: 600;
  }
  
  :deep(code) {
    background: #f3f4f6;
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Courier New', monospace;
    color: #2f9580;
  }
}

.content-iframe {
  width: 100%;
  height: calc(100vh - 140px);
  border: none;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

/* 移动端适配 */
@media (max-width: 768px) {
  .nav-bar {
    height: 50px;
    padding: 0 12px;
  }
  
  .back-btn {
    width: 36px;
    height: 36px;
  }
  
  .title {
    font-size: 16px;
  }
  
  .content {
    padding: 16px;
  }
  
  .card-header {
    padding: 12px 16px;
  }
  
  .header-title {
    font-size: 15px;
  }
  
  .card-body {
    padding: 16px;
  }
  
  .content-text {
    font-size: 15px;
    line-height: 1.7;
    
    :deep(h1) {
      font-size: 20px;
    }
    
    :deep(h2) {
      font-size: 18px;
    }
    
    :deep(h3) {
      font-size: 16px;
    }
    
    :deep(th), :deep(td) {
      padding: 8px;
      font-size: 14px;
    }
  }
  
  .content-iframe {
    height: calc(100vh - 120px);
  }
}
</style> 