From 10f1df2abb4f9d7de6e8031c2729684faad24734 Mon Sep 17 00:00:00 2001
From: yxh <172933527@qq.com>
Date: 星期三, 12 八月 2026 09:30:52 +0800
Subject: [PATCH] Merge branch 'srm-master' of http://116.62.18.175:6699/r/~yxh/opo-web into srm-master

---
 src/components/CustomImageViewer/index.vue |  293 ++++++++++++++++++++++++++++++----------------------------
 1 files changed, 152 insertions(+), 141 deletions(-)

diff --git a/src/components/CustomImageViewer/index.vue b/src/components/CustomImageViewer/index.vue
index 942cb20..f604700 100644
--- a/src/components/CustomImageViewer/index.vue
+++ b/src/components/CustomImageViewer/index.vue
@@ -1,14 +1,34 @@
 <template>
-  <div v-if="visible" class="custom-image-viewer">
+  <div v-if="visible" class="custom-image-viewer" @wheel.prevent="handleWheel">
     <!-- 閬僵灞� -->
     <div class="el-image-viewer__mask" @click.self="handleMaskClick"></div>
 
-    <!-- 鍥剧墖棰勮涓讳綋 -->
+    <!-- 鍏抽棴 -->
     <div class="el-image-viewer__btn el-image-viewer__close" @click="close">
       <i class="el-icon-close"></i>
     </div>
 
-    <!-- 涓婁竴寮犳寜閽� -->
+    <!-- 宸ュ叿鏍� -->
+    <div class="viewer-toolbar">
+      <div class="toolbar-btn" title="鏀惧ぇ" @click="zoomIn">
+        <i class="el-icon-zoom-in"></i>
+      </div>
+      <div class="toolbar-btn" title="缂╁皬" @click="zoomOut">
+        <i class="el-icon-zoom-out"></i>
+      </div>
+      <div class="toolbar-btn" title="椤烘椂閽堟棆杞�" @click="rotateRight">
+        <i class="el-icon-refresh-right"></i>
+      </div>
+      <div class="toolbar-btn" title="閫嗘椂閽堟棆杞�" @click="rotateLeft">
+        <i class="el-icon-refresh-left"></i>
+      </div>
+      <div class="toolbar-btn" title="杩樺師" @click="resetTransform">
+        <i class="el-icon-s-home"></i>
+      </div>
+      <span class="toolbar-info">{{ currentIndex + 1 }} / {{ urlList.length }}</span>
+    </div>
+
+    <!-- 涓婁竴寮� -->
     <div
       class="el-image-viewer__btn el-image-viewer__prev"
       :class="{ 'is-disabled': isFirst }"
@@ -17,7 +37,7 @@
       <i class="el-icon-arrow-left"></i>
     </div>
 
-    <!-- 涓嬩竴寮犳寜閽� -->
+    <!-- 涓嬩竴寮� -->
     <div
       class="el-image-viewer__btn el-image-viewer__next"
       :class="{ 'is-disabled': isLast }"
@@ -27,17 +47,25 @@
     </div>
 
     <!-- 鍥剧墖灞曠ず -->
-    <div class="el-image-viewer__canvas">
+    <div
+      class="el-image-viewer__canvas"
+      @mousedown="handleMouseDown"
+      @mousemove="handleMouseMove"
+      @mouseup="handleMouseUp"
+      @mouseleave="handleMouseUp"
+    >
       <img
         v-if="currentUrl"
         :src="currentUrl"
         :key="currentIndex"
         @error="handleError"
         class="el-image-viewer__img"
+        :style="imgStyle"
+        draggable="false"
       />
     </div>
 
-    <!-- 鑷畾涔夋彁绀轰俊鎭� -->
+    <!-- 鎻愮ず淇℃伅 -->
     <div v-if="showTip" class="custom-viewer-tip">
       {{ tipMessage }}
     </div>
@@ -48,24 +76,22 @@
 export default {
   name: 'CustomImageViewer',
   props: {
-    urlList: {
-      type: Array,
-      default: () => []
-    },
-    initialIndex: {
-      type: Number,
-      default: 0
-    },
-    visible: {
-      type: Boolean,
-      default: false
-    }
+    urlList: { type: Array, default: () => [] },
+    initialIndex: { type: Number, default: 0 },
+    visible: { type: Boolean, default: false }
   },
   data() {
     return {
       currentIndex: this.initialIndex,
       showTip: false,
-      tipMessage: ''
+      tipMessage: '',
+      scale: 1,
+      rotate: 0,
+      // 鎷栨嫿
+      dragging: false,
+      dragStart: { x: 0, y: 0 },
+      offsetX: 0,
+      offsetY: 0,
     };
   },
   computed: {
@@ -77,174 +103,159 @@
     },
     isLast() {
       return this.currentIndex === this.urlList.length - 1;
-    }
+    },
+    imgStyle() {
+      return {
+        transform: `translate(${this.offsetX}px, ${this.offsetY}px) scale(${this.scale}) rotate(${this.rotate}deg)`,
+        transition: this.dragging ? 'none' : 'transform 0.3s',
+        cursor: this.scale > 1 ? (this.dragging ? 'grabbing' : 'grab') : 'default',
+      };
+    },
   },
   watch: {
     initialIndex(newVal) {
       this.currentIndex = newVal;
+      this.resetTransform();
     },
     visible(newVal) {
       if (!newVal) {
         this.showTip = false;
-        this.tipMessage = '';
         this.removeKeyListener();
       } else {
-        this.$nextTick(() => {
-          this.addKeyListener();
-        });
+        this.$nextTick(() => { this.addKeyListener(); });
       }
-    }
+    },
   },
   methods: {
     close() {
       this.$emit('update:visible', false);
       this.$emit('close');
     },
-    handleMaskClick() {
-      this.close();
-    },
+    handleMaskClick() { this.close(); },
+
+    // 鍒囨崲鍥剧墖
     goPrev() {
-      if (this.isFirst) {
-        this.showTipMessage('杩欏凡缁忔槸绗竴寮犱簡');
-        return;
-      }
+      if (this.isFirst) { this.showTipMessage('宸叉槸绗竴寮�'); return; }
       this.currentIndex--;
-      this.hideTip();
+      this.resetTransform();
     },
     goNext() {
-      if (this.isLast) {
-        this.showTipMessage('杩欏凡缁忔槸鏈�鍚庝竴寮犱簡');
-        return;
-      }
+      if (this.isLast) { this.showTipMessage('宸叉槸鏈�鍚庝竴寮�'); return; }
       this.currentIndex++;
-      this.hideTip();
-    },
-    showTipMessage(message) {
-      this.tipMessage = message;
-      this.showTip = true;
-      setTimeout(() => {
-        this.hideTip();
-      }, 2000);
-    },
-    hideTip() {
-      this.showTip = false;
-      this.tipMessage = '';
-    },
-    handleError() {
-      console.error(`鍥剧墖鍔犺浇澶辫触: ${this.currentUrl}`);
+      this.resetTransform();
     },
 
-    // 閿洏浜嬩欢澶勭悊
-    handleKeydown(event) {
-      switch(event.key) {
-        case 'ArrowLeft':
-          event.preventDefault(); // 闃绘榛樿琛屼负
-          this.goPrev();
-          break;
-        case 'ArrowRight':
-          event.preventDefault();
-          this.goNext();
-          break;
-        case 'Escape':
-          event.preventDefault();
-          this.close();
-          break;
+    // 缂╂斁
+    zoomIn() {
+      this.scale = Math.min(this.scale + 0.25, 5);
+      if (this.scale <= 1) { this.offsetX = 0; this.offsetY = 0; }
+    },
+    zoomOut() {
+      this.scale = Math.max(this.scale - 0.25, 0.25);
+      if (this.scale <= 1) { this.offsetX = 0; this.offsetY = 0; }
+    },
+    handleWheel(e) {
+      if (e.deltaY < 0) this.zoomIn();
+      else this.zoomOut();
+    },
+
+    // 鏃嬭浆
+    rotateRight() { this.rotate = (this.rotate + 90) % 360; },
+    rotateLeft() { this.rotate = (this.rotate - 90) % 360; },
+
+    // 杩樺師
+    resetTransform() {
+      this.scale = 1;
+      this.rotate = 0;
+      this.offsetX = 0;
+      this.offsetY = 0;
+    },
+
+    // 鎷栨嫿锛堜粎鍦ㄦ斁澶ф椂鍚敤锛�
+    handleMouseDown(e) {
+      if (this.scale <= 1) return;
+      this.dragging = true;
+      this.dragStart = { x: e.clientX - this.offsetX, y: e.clientY - this.offsetY };
+    },
+    handleMouseMove(e) {
+      if (!this.dragging) return;
+      this.offsetX = e.clientX - this.dragStart.x;
+      this.offsetY = e.clientY - this.dragStart.y;
+    },
+    handleMouseUp() {
+      this.dragging = false;
+    },
+
+    showTipMessage(msg) {
+      this.tipMessage = msg;
+      this.showTip = true;
+      setTimeout(() => { this.hideTip(); }, 2000);
+    },
+    hideTip() { this.showTip = false; this.tipMessage = ''; },
+    handleError() { console.error('鍥剧墖鍔犺浇澶辫触:', this.currentUrl); },
+
+    // 閿洏
+    handleKeydown(e) {
+      switch(e.key) {
+        case 'ArrowLeft': e.preventDefault(); this.goPrev(); break;
+        case 'ArrowRight': e.preventDefault(); this.goNext(); break;
+        case 'Escape': e.preventDefault(); this.close(); break;
+        case '+': case '=': e.preventDefault(); this.zoomIn(); break;
+        case '-': e.preventDefault(); this.zoomOut(); break;
+        case '0': e.preventDefault(); this.resetTransform(); break;
       }
     },
-    addKeyListener() {
-      document.addEventListener('keydown', this.handleKeydown);
-    },
-    removeKeyListener() {
-      document.removeEventListener('keydown', this.handleKeydown);
-    }
+    addKeyListener() { document.addEventListener('keydown', this.handleKeydown); },
+    removeKeyListener() { document.removeEventListener('keydown', this.handleKeydown); },
   },
-  mounted() {
-    if (this.visible) {
-      this.addKeyListener();
-    }
-  },
-  beforeUnmount() {
-    this.removeKeyListener();
-  }
+  mounted() { if (this.visible) this.addKeyListener(); },
+  beforeUnmount() { this.removeKeyListener(); },
 };
 </script>
 
 <style scoped>
 .custom-image-viewer {
-  position: fixed;
-  top: 0;
-  right: 0;
-  bottom: 0;
-  left: 0;
-  z-index: 2000; /* 纭繚 z-index 瓒冲楂� */
+  position: fixed; top: 0; right: 0; bottom: 0; left: 0; z-index: 2000;
 }
-
 .el-image-viewer__mask {
-  position: absolute;
-  width: 100%;
-  height: 100%;
+  position: absolute; width: 100%; height: 100%;
   background-color: rgba(0, 0, 0, 0.5);
 }
-
 .el-image-viewer__btn {
-  position: absolute;
-  z-index: 1;
-  color: #fff;
-  background-color: rgba(0, 0, 0, 0.3);
-  border-radius: 50%;
-  width: 40px;
-  height: 40px;
-  display: flex;
-  align-items: center;
-  justify-content: center;
-  cursor: pointer;
-  user-select: none;
+  position: absolute; z-index: 1; color: #fff;
+  background-color: rgba(0, 0, 0, 0.3); border-radius: 50%;
+  width: 40px; height: 40px; display: flex;
+  align-items: center; justify-content: center; cursor: pointer; user-select: none;
 }
+.el-image-viewer__btn.is-disabled { cursor: not-allowed; opacity: 0.5; }
+.el-image-viewer__close { top: 20px; right: 20px; }
+.el-image-viewer__prev { left: 20px; top: 50%; transform: translateY(-50%); }
+.el-image-viewer__next { right: 20px; top: 50%; transform: translateY(-50%); }
 
-.el-image-viewer__btn.is-disabled {
-  cursor: not-allowed;
-  opacity: 0.5;
+.viewer-toolbar {
+  position: absolute; bottom: 30px; left: 50%; transform: translateX(-50%);
+  z-index: 1; display: flex; align-items: center; gap: 8px;
+  padding: 8px 16px; background: rgba(0, 0, 0, 0.6); border-radius: 24px;
 }
-
-.el-image-viewer__close {
-  top: 20px;
-  right: 20px;
+.toolbar-btn {
+  width: 36px; height: 36px; border-radius: 50%; display: flex;
+  align-items: center; justify-content: center; cursor: pointer;
+  color: #fff; font-size: 18px; transition: background 0.2s;
 }
-
-.el-image-viewer__prev {
-  left: 20px;
-  top: 50%;
-  transform: translateY(-50%);
-}
-
-.el-image-viewer__next {
-  right: 20px;
-  top: 50%;
-  transform: translateY(-50%);
-}
+.toolbar-btn:hover { background: rgba(255, 255, 255, 0.2); }
+.toolbar-info { color: rgba(255, 255, 255, 0.7); font-size: 13px; margin-left: 8px; white-space: nowrap; }
 
 .el-image-viewer__canvas {
-  display: flex;
-  justify-content: center;
-  align-items: center;
-  height: 100%;
+  display: flex; justify-content: center; align-items: center;
+  height: 100%; overflow: hidden;
 }
-
 .el-image-viewer__img {
-  max-width: 90%;
-  max-height: 90%;
-  object-fit: contain;
+  max-width: 90%; max-height: 90%;
+  object-fit: contain; user-select: none; -webkit-user-drag: none;
 }
-
 .custom-viewer-tip {
-  position: absolute;
-  bottom: 50px;
-  left: 50%;
-  transform: translateX(-50%);
-  background-color: rgba(0, 0, 0, 0.7);
-  color: #fff;
-  padding: 10px 20px;
-  border-radius: 4px;
-  z-index: 2001;
+  position: absolute; bottom: 100px; left: 50%; transform: translateX(-50%);
+  background-color: rgba(0, 0, 0, 0.7); color: #fff;
+  padding: 10px 20px; border-radius: 4px; z-index: 2001;
 }
 </style>

--
Gitblit v1.9.3