<template>
  <div class="simple-img-viewer">
    <!-- 缩略图 -->
    <img
      :src="currentSrc"
      :alt="alt"
      :width="width"
      :height="height"
      class="thumbnail"
      @click="openViewer"
      :title="title || '点击查看图片'"
      @error="handleImageError"
    >

    <!-- 全屏查看器 -->
    <div
      class="viewer-overlay"
      v-if="isOpen"
      @click="closeViewer"
    >
      <!-- 添加一个完全不透明的背景层 -->
      <div class="absolute-overlay"></div>

      <!-- 导航按钮 -->
      <div v-if="hasMultipleImages" class="nav-buttons">
        <div class="nav-button prev" @click.stop="prevImage">‹</div>
        <div class="nav-button next" @click.stop="nextImage">›</div>
      </div>

      <div
        class="img-wrapper"
        @click.stop
        ref="imgWrapper"
        @wheel.prevent="handleWheel($event)"
      >
        <div
          class="img-container"
          :style="transformStyle"
          ref="imgContainer"
        >
          <img
            :src="viewerCurrentSrc"
            :alt="alt"
            class="viewer-img"
            ref="viewerImg"
            @mousedown.prevent="startDrag($event)"
            @dblclick="resetImage"
            @error="handleViewerImageError"
          >
        </div>
      </div>
      <div class="ui-layer">
        <!-- 图片计数器 -->
        <div v-if="hasMultipleImages" class="image-counter">
          {{ currentIndex + 1 }} / {{ totalImages }}
        </div>

        <div class="zoom-info" v-show="showZoomInfo">{{ Math.round(scale * 100) }}%</div>
        <div class="controls">
          <div v-if="hasMultipleImages" class="control-btn" @click.stop="prevImage">‹</div>
          <div class="control-btn" @click.stop="zoomIn">+</div>
          <div class="control-btn" @click.stop="zoomOut">-</div>
          <div class="control-btn" @click.stop="rotateLeft">↺</div>
          <div class="control-btn" @click.stop="rotateRight">↻</div>
          <div class="control-btn" @click.stop="resetImage">⟲</div>
          <div v-if="hasMultipleImages" class="control-btn" @click.stop="nextImage">›</div>
        </div>
        <div class="close-btn" @click.stop="closeViewer">×</div>
      </div>
    </div>
  </div>
</template>

<script>
import {HttpResetClass} from "vue-client";
import Vue from 'vue'

export default {
  props: {
    src: {
      type: String,
      required: true
    },
    images: {
      type: Array,
      default: () => []
    },
    width: {
      default: 60
    },
    height: {
      default: 60
    },
    alt: {
      default: '图片'
    },
    title: {
      type: String,
      default: ''
    }
  },

  data() {
    return {
      isOpen: false,
      scale: 1,
      rotation: 0,
      posX: 0,
      urlRules:[],
      viewerCurrentSrc:'',
      posY: 0,
      isDragging: false,
      startX: 0,
      startY: 0,
      showZoomInfo: false,
      zoomInfoTimeout: null,
      boundMouseMove: null,
      boundMouseUp: null,
      boundKeyDown: null,
      overlayElement: null,
      useMinioUrl: false,
      viewerUseMinioUrl: false,
      currentIndex: 0,
      // 缩略图：当前尝试到 urlRules 的第几个规则（-1 表示还在前置阶段）
      thumbnailRuleIndex: -1,
      // 查看器：当前尝试到 urlRules 的第几个规则（-1 表示还在前置阶段）
      viewerRuleIndex: -1,
      // 缓存原始纯文件路径，避免多次失败时路径叠加
      thumbnailRawPath: '',
      viewerRawPath: ''
    }
  },

  computed: {
    // 判断是否有多张图片
    hasMultipleImages() {
      return this.images && this.images.length > 1
    },

    // 获取当前显示的图片路径
    currentImagePath() {
      if (this.hasMultipleImages) {
        // 如果 src 未定义，使用当前索引的图片
        if (!this.src) {
          return this.images[this.currentIndex]
        }

        // 找到当前图片在数组中的索引
        const currentSrcIndex = this.images.indexOf(this.src)

        if (currentSrcIndex !== -1) {
          // currentIndex 的更新由 watch.src 统一处理,避免在 computed 里改 state
          return this.src
        }

        // 如果找不到当前图片，使用当前索引的图片
        return this.images[this.currentIndex]
      }

      // 单张图片的情况
      return this.src || ''
    },

    // 处理缩略图的URL
    currentSrc() {
      const path = this.currentImagePath

      if (!path) return ''

      // 如果已经是完整的URL，直接返回
      if (path.startsWith('http://') || path.startsWith('https://')) {
        return path
      }

      // 如果path已经包含了基础路径，直接返回
      if (path.startsWith('/rs/image/file/')
          || path.startsWith('/minio/af-safecheck/jpg/')
          || path.startsWith('/minio/af-safecheck/png/')) {
        return path
      }

      // 根据useMinioUrl标记决定使用哪个基础URL
      const baseUrl = this.useMinioUrl ? this._minioPrefix(path) : '/rs/image/file/'

      // 确保path不以/开头
      const cleanPath = path.startsWith('/') ? path.slice(1) : path

      return baseUrl + cleanPath
    },

    // 处理查看器的URL（添加新的计算属性用于查看器图片源）
    // viewerCurrentSrc() {
    //   if (this.hasMultipleImages) {
    //     const path = this.images[this.currentIndex]
    //
    //     if (!path) return ''
    //
    //     // 如果已经是完整的URL，直接返回
    //     if (path.startsWith('http://') || path.startsWith('https://')) {
    //       return path
    //     }
    //
    //     // 如果path已经包含了基础路径，直接返回
    //     if (path.startsWith('/rs/image/file/') || path.startsWith('/minio/af-safecheck/jpg/')) {
    //       return path
    //     }
    //
    //     // 根据viewerUseMinioUrl标记决定使用哪个基础URL
    //     const baseUrl = this.viewerUseMinioUrl ? '/minio/af-safecheck/jpg/' : '/rs/image/file/'
    //
    //     // 确保path不以/开头
    //     const cleanPath = path.startsWith('/') ? path.slice(1) : path
    //
    //     return baseUrl + cleanPath
    //   }
    //
    //   return this.currentSrc
    // },

    // 获取总图片数量
    totalImages() {
      return this.hasMultipleImages ? this.images.length : 1
    },

    transformStyle() {
      return {
        transform: `translate(${this.posX}px, ${this.posY}px) scale(${this.scale}) rotate(${this.rotation}deg)`,
        transition: this.isDragging ? 'none' : 'transform 0.1s ease-out'
      }
    }
  },

  watch: {
    // 监听src的变化，更新currentIndex
    src: {
      immediate: true,
      handler(newSrc) {
        if (this.hasMultipleImages && newSrc) {
          const index = this.images.indexOf(newSrc)
          if (index !== -1) {
            this.currentIndex = index
          }
        }
      }
    }
  },
  ready(){
    if (Vue.changeMinioDate){
      this.urlRules = Vue.changeMinioDate
      return
    }
    // this.urlRules = ['aaaa/aaa','bbb/bbbb']
    new HttpResetClass().load('post','api/af-revenue/logic/openapi/getLiuliConfiguration',{ configName: 'changeMinioDate' }).then(resp=>{
      const rules = resp.data.storageSwitch.sort(
        (a, b) => new Date(a.changeDate) - new Date(b.changeDate)
      )
      rules.forEach(rule=>{
        this.urlRules.push(rule.prefix)
      })
      if (!Vue.changeMinioDate){
        Vue.changeMinioDate = this.urlRules
      }
    })
  },

  methods: {
    // 切换到上一张图片
    prevImage() {
      if (!this.hasMultipleImages) return
      this.currentIndex = (this.currentIndex - 1 + this.totalImages) % this.totalImages
      this.resetImage()

      // 新一张图重置 fallback 状态
      this.useMinioUrl = false
      this.thumbnailRuleIndex = -1
      this.thumbnailRawPath = ''
      this.viewerUseMinioUrl = false
      this.viewerRuleIndex = -1
      this.viewerRawPath = ''
      this._updateViewerSrc()
    },

    // 切换到下一张图片
    nextImage() {
      if (!this.hasMultipleImages) return
      this.currentIndex = (this.currentIndex + 1) % this.totalImages
      this.resetImage()

      // 新一张图重置 fallback 状态
      this.useMinioUrl = false
      this.thumbnailRuleIndex = -1
      this.thumbnailRawPath = ''
      this.viewerUseMinioUrl = false
      this.viewerRuleIndex = -1
      this.viewerRawPath = ''
      this._updateViewerSrc()
    },

    // 根据 currentIndex 更新查看器图片 src
    // 与缩略图共用 viewerUseMinioUrl / urlRules 的 fallback 逻辑,保证一致性
    _updateViewerSrc() {
      let path
      if (this.hasMultipleImages) {
        path = this.images[this.currentIndex]
      } else {
        path = this.src
      }
      if (!path) return

      if (path.startsWith('http://') || path.startsWith('https://')) {
        this.viewerCurrentSrc = path
        return
      }
      if (path.startsWith('/rs/image/file/')
          || path.startsWith('/minio/af-safecheck/jpg/')
          || path.startsWith('/minio/af-safecheck/png/')) {
        this.viewerCurrentSrc = path
        return
      }
      // 与缩略图同步:viewer 已切到 minio,走对应 minio 桶
      const baseUrl = this.viewerUseMinioUrl ? this._minioPrefix(path) : '/rs/image/file/'
      const cleanPath = path.startsWith('/') ? path.slice(1) : path
      this.viewerCurrentSrc = baseUrl + cleanPath
    },

    openViewer(e) {
      // 同步缩略图的 fallback 状态,避免查看器走另一条路径
      this.viewerUseMinioUrl = this.useMinioUrl
      this.viewerRuleIndex = this.thumbnailRuleIndex
      this.viewerRawPath = this.thumbnailRawPath

      // 基于 props 重新计算 viewer src,保证与缩略图走同一套规则
      this._updateViewerSrc()

      this.isOpen = true
      document.body.style.overflow = 'hidden'

      // 创建一个全屏遮罩元素并添加到body
      this.overlayElement = document.createElement('div');
      this.overlayElement.className = 'global-img-viewer-overlay';
      document.body.appendChild(this.overlayElement);

      // 重置图片状态
      this.scale = 1
      this.rotation = 0
      this.posX = 0
      this.posY = 0

      // 在下一个渲染周期添加事件监听
      this.$nextTick(() => {
        // 使用bind确保this绑定正确
        this.boundMouseMove = this.handleMouseMove.bind(this)
        this.boundMouseUp = this.handleMouseUp.bind(this)
        this.boundKeyDown = this.handleKeyDown.bind(this)

        document.addEventListener('mousemove', this.boundMouseMove)
        document.addEventListener('mouseup', this.boundMouseUp)
        document.addEventListener('keydown', this.boundKeyDown)

        if (this.$refs.viewerImg) {
          this.$refs.viewerImg.style.cursor = 'grab'
        }

        // 将查看器移动到body下，确保它在最顶层
        if (this.$el.querySelector('.viewer-overlay')) {
          const viewerOverlay = this.$el.querySelector('.viewer-overlay');
          document.body.appendChild(viewerOverlay);
        }
      })
    },

    closeViewer() {
      this.isOpen = false
      document.body.style.overflow = ''

      // 移除全局遮罩
      if (this.overlayElement && this.overlayElement.parentNode) {
        this.overlayElement.parentNode.removeChild(this.overlayElement);
      }

      // 移除事件监听
      if (this.boundMouseMove) {
        document.removeEventListener('mousemove', this.boundMouseMove)
      }
      if (this.boundMouseUp) {
        document.removeEventListener('mouseup', this.boundMouseUp)
      }
      if (this.boundKeyDown) {
        document.removeEventListener('keydown', this.boundKeyDown)
      }

      // 将查看器元素移回原位
      this.$nextTick(() => {
        const overlay = document.querySelector('.viewer-overlay');
        if (overlay && this.$el) {
          this.$el.appendChild(overlay);
        }
      });
    },

    // 滚轮缩放
    handleWheel(e) {
      // 阻止默认滚动行为
      e.preventDefault()

      // 计算缩放因子
      const delta = e.deltaY < 0 ? 1.1 : 0.9
      const newScale = this.scale * delta

      // 限制缩放范围
      if (newScale >= 0.1 && newScale <= 10) {
        // 获取视口尺寸
        const viewportWidth = window.innerWidth
        const viewportHeight = window.innerHeight

        // 视口中心点
        const centerX = viewportWidth / 2
        const centerY = viewportHeight / 2

        // 计算鼠标位置相对于视口中心的偏移
        const mouseOffsetX = e.clientX - centerX
        const mouseOffsetY = e.clientY - centerY

        // 计算当前图片中心点相对于视口中心的偏移
        const currentOffsetX = this.posX
        const currentOffsetY = this.posY

        // 计算新的位置
        // 当缩小时，让图片更倾向于回到中心位置
        // 当放大时，保持以鼠标位置为中心
        let newPosX, newPosY

        if (delta < 1) { // 缩小
          // 缩小时，逐渐将图片拉回中心
          const pullFactor = Math.max(0.2, newScale / 2) // 拉力因子，随着缩放比例减小而增大
          newPosX = currentOffsetX * delta + (mouseOffsetX * (1 - delta) * pullFactor)
          newPosY = currentOffsetY * delta + (mouseOffsetY * (1 - delta) * pullFactor)
        } else { // 放大
          // 放大时，以鼠标位置为中心
          newPosX = currentOffsetX * delta - mouseOffsetX * (delta - 1)
          newPosY = currentOffsetY * delta - mouseOffsetY * (delta - 1)
        }

        // 更新位置和缩放比例
        this.posX = newPosX
        this.posY = newPosY
        this.scale = newScale

        // 显示缩放信息
        this.showZoomInfo = true
        clearTimeout(this.zoomInfoTimeout)
        this.zoomInfoTimeout = setTimeout(() => {
          this.showZoomInfo = false
        }, 1000)
      }
    },

    // 开始拖动
    startDrag(e) {
      if (e.button !== 0) return // 只响应左键

      this.isDragging = true
      this.startX = e.clientX - this.posX
      this.startY = e.clientY - this.posY

      if (this.$refs.viewerImg) {
        this.$refs.viewerImg.style.cursor = 'grabbing'
      }

      // 阻止默认行为和冒泡
      e.stopPropagation()
    },

    // 拖动中
    handleMouseMove(e) {
      if (!this.isDragging) return

      this.posX = e.clientX - this.startX
      this.posY = e.clientY - this.startY
    },

    // 结束拖动
    handleMouseUp() {
      if (this.isDragging) {
        this.isDragging = false
        if (this.$refs.viewerImg) {
          this.$refs.viewerImg.style.cursor = 'grab'
        }
      }
    },

    // 缩放控制
    zoomIn() {
      this.scale = Math.min(this.scale * 1.2, 10)

      this.showZoomInfo = true
      clearTimeout(this.zoomInfoTimeout)
      this.zoomInfoTimeout = setTimeout(() => {
        this.showZoomInfo = false
      }, 1000)
    },

    zoomOut() {
      this.scale = Math.max(this.scale * 0.8, 0.1)

      this.showZoomInfo = true
      clearTimeout(this.zoomInfoTimeout)
      this.zoomInfoTimeout = setTimeout(() => {
        this.showZoomInfo = false
      }, 1000)
    },

    // 旋转控制
    rotateLeft() {
      this.rotation -= 90
    },

    rotateRight() {
      this.rotation += 90
    },

    // 重置图片
    resetImage() {
      this.scale = 1
      this.rotation = 0
      this.posX = 0
      this.posY = 0

      // 显示缩放信息
      this.showZoomInfo = true
      clearTimeout(this.zoomInfoTimeout)
      this.zoomInfoTimeout = setTimeout(() => {
        this.showZoomInfo = false
      }, 1000)
    },

    // 键盘事件处理
    handleKeyDown(e) {
      if (!this.isOpen) return

      switch (e.key) {
        case 'Escape':
          this.closeViewer()
          break
        case 'ArrowLeft':
          if (e.ctrlKey || e.metaKey) {
            this.rotateLeft()
          } else {
            this.prevImage()
          }
          break
        case 'ArrowRight':
          if (e.ctrlKey || e.metaKey) {
            this.rotateRight()
          } else {
            this.nextImage()
          }
          break
        case '+':
        case '=':
          this.zoomIn()
          break
        case '-':
          this.zoomOut()
          break
        case '0':
          this.resetImage()
          break
      }
    },

    // 从图片 URL 中提取纯文件路径（去掉已知前缀）
    _extractRawPath(url) {
      const knownPrefixes = ['/rs/image/file/', '/minio/af-safecheck/jpg/', '/minio/af-safecheck/png/']
      for (const prefix of knownPrefixes) {
        if (url.includes(prefix)) {
          const idx = url.indexOf(prefix)
          return url.slice(idx + prefix.length)
        }
      }
      // 没有匹配到已知前缀，尝试取路径部分
      try {
        const path = new URL(url).pathname
        return path.startsWith('/') ? path.slice(1) : path
      } catch (e) {
        return url.startsWith('/') ? url.slice(1) : url
      }
    },

    // 根据文件名后缀选择 minio 桶前缀
    _minioPrefix(rawPath) {
      if (rawPath && rawPath.toLowerCase().includes('.png')) {
        return '/minio/af-safecheck/png/'
      }
      return '/minio/af-safecheck/jpg/'
    },

    // 处理缩略图加载失败
    handleImageError(e) {
      if (!this.currentImagePath) return

      // 阶段一：第一次失败，记录原始路径，尝试 minio 前缀
      if (!this.useMinioUrl) {
        this.useMinioUrl = true
        this.thumbnailRuleIndex = -1
        // 第一次失败时从当前 src 提取纯路径并缓存
        this.thumbnailRawPath = this._extractRawPath(e.target.src)
        e.target.src = this._minioPrefix(this.thumbnailRawPath) + this.thumbnailRawPath
        return
      }

      // 阶段二：依次遍历 urlRules，始终使用缓存的原始路径
      const nextIndex = this.thumbnailRuleIndex + 1
      if (this.urlRules && nextIndex < this.urlRules.length) {
        this.thumbnailRuleIndex = nextIndex
        const rulePrefix = this.urlRules[nextIndex]
        const prefix = rulePrefix.endsWith('/') ? rulePrefix : rulePrefix + '/'
        e.target.src = prefix + this.thumbnailRawPath
      }
      // 全部规则都尝试完毕，不再重试
    },

    // 处理全屏查看器的图片加载失败
    handleViewerImageError(e) {
      // 阶段一：第一次失败，记录原始路径，尝试 minio 前缀
      if (!this.viewerUseMinioUrl) {
        this.viewerUseMinioUrl = true
        this.viewerRuleIndex = -1
        this.viewerRawPath = this._extractRawPath(e.target.src)
        e.target.src = this._minioPrefix(this.viewerRawPath) + this.viewerRawPath
        return
      }

      // 阶段二：依次遍历 urlRules，始终使用缓存的原始路径
      const nextIndex = this.viewerRuleIndex + 1
      if (this.urlRules && nextIndex < this.urlRules.length) {
        this.viewerRuleIndex = nextIndex
        const rulePrefix = this.urlRules[nextIndex]
        const prefix = rulePrefix.endsWith('/') ? rulePrefix : rulePrefix + '/'
        e.target.src = prefix + this.viewerRawPath
      }
      // 全部规则都尝试完毕，不再重试
    }
  },

  beforeDestroy() {
    // 确保清理事件监听
    if (this.boundMouseMove) {
      document.removeEventListener('mousemove', this.boundMouseMove)
    }
    if (this.boundMouseUp) {
      document.removeEventListener('mouseup', this.boundMouseUp)
    }
    if (this.boundKeyDown) {
      document.removeEventListener('keydown', this.boundKeyDown)
    }

    // 清除定时器
    if (this.zoomInfoTimeout) {
      clearTimeout(this.zoomInfoTimeout)
    }

    // 移除全局遮罩
    if (this.overlayElement && this.overlayElement.parentNode) {
      this.overlayElement.parentNode.removeChild(this.overlayElement);
    }
  }
}
</script>

<style scoped>
.simple-img-viewer {
  display: inline-block;
}

.thumbnail {
  cursor: pointer;
  transition: transform 0.2s;
}

.thumbnail:hover {
  transform: scale(1.05);
  box-shadow: 0 0 8px rgba(0, 0, 0, 0.2);
}

.viewer-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: transparent;
  z-index: 999999;
  display: flex;
  justify-content: center;
  align-items: center;
}

.absolute-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.7);
  z-index: 999998;
}

.img-wrapper {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
  z-index: 1000000;
}

.img-container {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  transform-origin: center;
  will-change: transform;
}

.viewer-img {
  max-width: 90vw;
  max-height: 90vh;
  user-select: none;
  -webkit-user-drag: none;
  cursor: grab;
}

/* 新增UI层，用于放置所有控制元素 */
.ui-layer {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none; /* 默认不接收鼠标事件，让事件穿透到下层 */
  z-index: 1000001;
}

.controls {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  background-color: rgba(0, 0, 0, 0.5);
  border-radius: 20px;
  padding: 5px;
  height: 50px;
  pointer-events: auto; /* 控制按钮需要接收鼠标事件 */
}

.control-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background-color: rgba(255, 255, 255, 0.2);
  color: white;
  font-size: 20px;
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: pointer;
  margin: 0 5px;
  transition: background-color 0.3s;
}

.control-btn:hover {
  background-color: rgba(255, 255, 255, 0.4);
}

.close-btn {
  position: absolute;
  top: 20px;
  right: 20px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background-color: rgba(255, 255, 255, 0.2);
  color: white;
  font-size: 30px;
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: pointer;
  transition: background-color 0.3s;
  pointer-events: auto;
  z-index: 1000003; /* 确保关闭按钮在最上层 */
}

.close-btn:hover {
  background-color: rgba(255, 255, 255, 0.4);
}

.zoom-info {
  position: absolute;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  background-color: rgba(0, 0, 0, 0.7);
  color: white;
  padding: 5px 10px;
  border-radius: 4px;
  font-size: 14px;
  pointer-events: none; /* 缩放信息不需要接收鼠标事件 */
  height: auto; /* 自适应内容高度 */
  line-height: 1.2; /* 合理的行高 */
  display: inline-block; /* 使元素宽度自适应内容 */
  white-space: nowrap; /* 防止文本换行 */
}

/* 导航按钮样式 */
.nav-buttons {
  position: fixed;
  top: 100%;
  transform: translateY(-50%);
  width: 100%;
  z-index: 1000002;
  pointer-events: none;
  display: flex;
  justify-content: space-between;
  padding: 0 20px;
  box-sizing: border-box;
  font-size: 25px;
}

.nav-button {
  position: relative;
  width: 50px;
  height: 80px;
  background-color: rgba(0, 0, 0, 0.3);
  color: white;
  font-size: 40px;
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: pointer;
  transition: background-color 0.3s;
  pointer-events: auto;
  border-radius: 5px;
}

.nav-button:hover {
  background-color: rgba(0, 0, 0, 0.5);
}

.nav-button.prev {
  border-radius: 0 5px 5px 0;
}

.nav-button.next {
  border-radius: 5px 0 0 5px;
}

/* 图片计数器样式 */
.image-counter {
  position: absolute;
  top: 20px;
  right: 80px;
  background-color: rgba(0, 0, 0, 0.7);
  color: white;
  padding: 5px 10px;
  border-radius: 4px;
  font-size: 14px;
  pointer-events: none;
}
</style>

<style>
/* 全局遮罩样式 */
.global-img-viewer-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: #000;
  opacity: 0.4; /* 降低不透明度，使其更透明 */
  z-index: 999997;
  pointer-events: auto;
}

/* 确保图片查看器始终在最顶层 */
.viewer-overlay {
  position: fixed !important;
  z-index: 999999 !important;
}

.ui-layer {
  z-index: 1000001 !important;
}
</style>
