Ver Fonte

样式调整

caoziwu há 4 dias atrás
pai
commit
e4da6a8da1

+ 0 - 1
package.json

@@ -42,7 +42,6 @@
     "@vitejs/plugin-vue": "^6.0.2",
     "@vitejs/plugin-vue-jsx": "^5.1.6",
     "cross-env": "^10.1.0",
-    "echarts": "^6.1.0",
     "electron": "^14.0.0",
     "electron-builder": "^24.13.3",
     "electron-vite": "^4.0.0",

+ 2 - 0
src/renderer/src/App.vue

@@ -6,6 +6,7 @@ import { useI18n } from 'vue-i18n'
 import SpeakerSimulator from './components/simulator/SpeakerSimulator.vue'
 import { isDark } from './theme/index.js'
 import type { LocaleType } from './types/i18n.js'
+import { themeOverrides } from './theme/theme'
 
 const { locale } = useI18n()
 
@@ -28,6 +29,7 @@ const naiveTheme = computed(() => (isDark.value ? darkTheme : null))
     :theme="naiveTheme"
     :locale="naiveLocale"
     :date-locale="naiveDateLocale"
+    :theme-overrides="themeOverrides"
   >
     <SpeakerSimulator />
   </NConfigProvider>

+ 2 - 2
src/renderer/src/assets/simulator.less

@@ -144,7 +144,7 @@
 }
 
 .field-label .sym {
-  color: var(--n-primary-color, #18a058);
+  color: var(--n-primary-color, #05aef5);
   font-weight: 700;
   font-family: 'Courier New', monospace;
   font-size: 13px;
@@ -166,7 +166,7 @@
 
 @keyframes field-flash {
   0% {
-    box-shadow: 0 0 0 2px var(--n-primary-color-suppl, rgba(24, 160, 88, 0.35));
+    box-shadow: 0 0 0 2px var(--n-primary-color-suppl, rgba(24, 103, 160, 0.35));
   }
   100% {
     box-shadow: 0 0 0 0 transparent;

+ 237 - 0
src/renderer/src/components/simulator/CustomImagePreview.vue

@@ -0,0 +1,237 @@
+<script setup lang="ts">
+import { ref, watch, onMounted, onUnmounted } from 'vue'
+
+const props = defineProps<{
+  show: boolean
+  src: string
+}>()
+
+const emit = defineEmits<{
+  (e: 'update:show', value: boolean): void
+}>()
+
+const scale = ref(1)
+const translateX = ref(0)
+const translateY = ref(0)
+const isDragging = ref(false)
+const startX = ref(0)
+const startY = ref(0)
+
+// 重置状态
+const resetTransform = () => {
+  scale.value = 1
+  translateX.value = 0
+  translateY.value = 0
+}
+
+// 监听打开时重置状态
+watch(
+  () => props.show,
+  (newVal) => {
+    if (newVal) {
+      resetTransform()
+    }
+  }
+)
+
+const close = () => {
+  emit('update:show', false)
+}
+
+const zoomIn = () => {
+  scale.value = Math.min(scale.value + 0.25, 5) // 最大放大 5 倍
+}
+
+const zoomOut = () => {
+  scale.value = Math.max(scale.value - 0.25, 0.5) // 最小缩小到 0.5 倍
+}
+
+// 滚轮缩放
+const handleWheel = (e: WheelEvent) => {
+  if (e.deltaY < 0) zoomIn()
+  else zoomOut()
+}
+
+// 拖拽平移
+const handleMouseDown = (e: MouseEvent) => {
+  if (scale.value <= 1) return // 没放大时不支持拖拽
+  isDragging.value = true
+  startX.value = e.clientX - translateX.value
+  startY.value = e.clientY - translateY.value
+}
+
+const handleMouseMove = (e: MouseEvent) => {
+  if (!isDragging.value) return
+  translateX.value = e.clientX - startX.value
+  translateY.value = e.clientY - startY.value
+}
+
+const handleMouseUp = () => {
+  isDragging.value = false
+}
+
+// 键盘 Esc 关闭
+const handleKeyDown = (e: KeyboardEvent) => {
+  if (e.key === 'Escape' && props.show) close()
+}
+
+onMounted(() => window.addEventListener('keydown', handleKeyDown))
+onUnmounted(() => window.removeEventListener('keydown', handleKeyDown))
+</script>
+
+<template>
+  <Teleport to="body">
+    <div
+      v-if="show"
+      class="custom-lightbox"
+      @wheel.prevent="handleWheel"
+      @mousedown="handleMouseDown"
+      @mousemove="handleMouseMove"
+      @mouseup="handleMouseUp"
+      @mouseleave="handleMouseUp"
+    >
+      <!-- 遮罩层 -->
+      <div class="lightbox-backdrop" @click="close"></div>
+
+      <!-- 图片容器 -->
+      <div
+        class="lightbox-img-wrapper"
+        :style="{
+          transform: `translate(${translateX}px, ${translateY}px) scale(${scale})`,
+          cursor: scale > 1 ? (isDragging ? 'grabbing' : 'grab') : 'default'
+        }"
+      >
+        <img :src="src" alt="preview" @mousedown.stop @click.stop />
+      </div>
+
+      <!-- 自定义工具栏 -->
+      <div class="custom-toolbar" @mousedown.stop @click.stop>
+        <!-- 缩小 -->
+        <button class="tool-btn" title="缩小" @click="zoomOut">
+          <svg
+            viewBox="0 0 24 24"
+            width="20"
+            height="20"
+            stroke="currentColor"
+            stroke-width="2"
+            fill="none"
+            stroke-linecap="round"
+            stroke-linejoin="round"
+          >
+            <circle cx="11" cy="11" r="8"></circle>
+            <line x1="21" y1="21" x2="16.65" y2="16.65"></line>
+            <line x1="8" y1="11" x2="14" y2="11"></line>
+          </svg>
+        </button>
+
+        <!-- 放大 -->
+        <button class="tool-btn" title="放大" @click="zoomIn">
+          <svg
+            viewBox="0 0 24 24"
+            width="20"
+            height="20"
+            stroke="currentColor"
+            stroke-width="2"
+            fill="none"
+            stroke-linecap="round"
+            stroke-linejoin="round"
+          >
+            <circle cx="11" cy="11" r="8"></circle>
+            <line x1="21" y1="21" x2="16.65" y2="16.65"></line>
+            <line x1="11" y1="8" x2="11" y2="14"></line>
+            <line x1="8" y1="11" x2="14" y2="11"></line>
+          </svg>
+        </button>
+
+        <!-- 关闭 -->
+        <button class="tool-btn" title="关闭" @click="close">
+          <svg
+            viewBox="0 0 24 24"
+            width="20"
+            height="20"
+            stroke="currentColor"
+            stroke-width="2"
+            fill="none"
+            stroke-linecap="round"
+            stroke-linejoin="round"
+          >
+            <line x1="18" y1="6" x2="6" y2="18"></line>
+            <line x1="6" y1="6" x2="18" y2="18"></line>
+          </svg>
+        </button>
+      </div>
+    </div>
+  </Teleport>
+</template>
+
+<style scoped>
+.custom-lightbox {
+  position: fixed;
+  inset: 0;
+  z-index: 9999;
+  display: flex;
+  align-items: center;
+  justify-content: center;
+  overflow: hidden;
+  user-select: none;
+}
+
+.lightbox-backdrop {
+  position: absolute;
+  inset: 0;
+  background: rgba(0, 0, 0, 0.85);
+  backdrop-filter: blur(4px);
+}
+
+.lightbox-img-wrapper {
+  position: relative;
+  z-index: 1;
+  transition: transform 0.1s ease-out;
+  display: flex;
+  align-items: center;
+  justify-content: center;
+}
+
+.lightbox-img-wrapper img {
+  max-width: 90vw;
+  max-height: 90vh;
+  object-fit: contain;
+  pointer-events: none; /* 防止图片自带的拖拽影响 */
+}
+
+.custom-toolbar {
+  position: absolute;
+  bottom: 40px;
+  z-index: 2;
+  display: flex;
+  gap: 12px;
+  background: rgba(30, 30, 30, 0.7);
+  border: 1px solid rgba(255, 255, 255, 0.1);
+  border-radius: 40px;
+  backdrop-filter: blur(8px);
+  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
+}
+
+.tool-btn {
+  display: flex;
+  align-items: center;
+  justify-content: center;
+  width: 36px;
+  height: 36px;
+  border-radius: 50%;
+  background: transparent;
+  border: none;
+  color: #e5e5e5;
+  cursor: pointer;
+  transition: all 0.2s;
+}
+
+.tool-btn:hover {
+  color: #ffffff;
+  transform: scale(1.1);
+}
+
+.tool-btn:active {
+  transform: scale(0.95);
+}
+</style>

+ 17 - 2
src/renderer/src/components/simulator/SpeakerSimulator.vue

@@ -21,7 +21,20 @@ import SPLChartPanel from './SPLChartPanel.vue'
 import logo from '../../assets/logo.png'
 import BaseModel from '../BaseModel.vue'
 import { useI18n } from 'vue-i18n'
+import CustomImagePreview from './CustomImagePreview.vue'
 
+// 新增预览状态控制
+const showPreview = ref(false)
+const previewSrc = ref('')
+
+// 触发预览的方法
+const openPreview = () => {
+  const src = computedImage()
+  if (src) {
+    previewSrc.value = src
+    showPreview.value = true
+  }
+}
 const { t } = useI18n()
 
 const defaultParams: SpeakerParams = {
@@ -218,8 +231,9 @@ runCalc()
               <SPLChartPanel :params="params" :result="result" />
             </NTabPane>
             <NTabPane name="Polar Plot" :tab="$t('chart.polarPlot')" v-if="deviceState.polarPlot">
-              <div class="img-box">
-                <n-image :src="computedImage()" width="90%" :show-toolbar="false"></n-image>
+              <div class="img-box cursor-pointer" @click="openPreview" title="点击放大预览">
+                <!-- 关掉 n-image 的预览,仅作为展示 -->
+                <n-image :src="computedImage()" width="90%" :preview-disabled="true"></n-image>
               </div>
             </NTabPane>
           </NTabs>
@@ -246,4 +260,5 @@ runCalc()
       />
     </BaseModel>
   </div>
+  <CustomImagePreview v-model:show="showPreview" :src="previewSrc" />
 </template>

+ 72 - 0
src/renderer/src/theme/theme.ts

@@ -0,0 +1,72 @@
+import { GlobalThemeOverrides } from 'naive-ui'
+
+function addLight(color: string, amount: number): string {
+  const cc = parseInt(color, 16) + amount
+  const c = cc > 255 ? 255 : cc
+  return c.toString(16).length > 1 ? c.toString(16) : `0${c.toString(16)}`
+}
+function subLight(color: string, amount: number): string {
+  const cc = parseInt(color, 16) - amount
+  const c = cc < 0 ? 0 : cc
+  return c.toString(16).length > 1 ? c.toString(16) : `0${c.toString(16)}`
+}
+export function lighten(color: string, amount: number): string {
+  color = color.indexOf('#') >= 0 ? color.substring(1, color.length) : color
+  amount = Math.trunc((255 * amount) / 100)
+  return `#${addLight(color.substring(0, 2), amount)}${addLight(
+    color.substring(2, 4),
+    amount
+  )}${addLight(color.substring(4, 6), amount)}`
+}
+
+/**
+ * Darkens a 6 char HEX color according to the passed percentage
+ * @param {string} color The color to change (e.g. "#1190ff")
+ * @param {number} amount The percentage (0–100) to darken the color
+ * @returns {string} The processed color represented as HEX
+ */
+export function darken(color: string, amount: number): string {
+  color = color.indexOf('#') >= 0 ? color.substring(1, color.length) : color
+  amount = Math.trunc((255 * amount) / 100)
+  return `#${subLight(color.substring(0, 2), amount)}${subLight(
+    color.substring(2, 4),
+    amount
+  )}${subLight(color.substring(4, 6), amount)}`
+}
+const primaryColor = '#05AEF5'
+
+const primaryColorHover: string = lighten(primaryColor, 6)
+const primaryColorPressed: string = darken(primaryColor, 6)
+const infoColor = '#05AEF5'
+const infoColorHover: string = lighten(infoColor, 6)
+const successColor = '#5CC458'
+const successColorHover: string = lighten(successColor, 6)
+const warningColor = '#FFCA44'
+const warningColorHover: string = lighten(warningColor, 6)
+const errorColor = '#EB212C'
+const errorColorHover: string = lighten(errorColor, 6)
+const textColorBase = '#333333'
+
+export const themeOverrides: GlobalThemeOverrides = {
+  common: {
+    primaryColor,
+    primaryColorHover,
+    primaryColorPressed,
+    infoColor,
+    infoColorHover,
+    successColor,
+    successColorHover,
+    warningColor,
+    warningColorHover,
+    errorColor,
+    errorColorHover,
+    textColorBase
+  },
+  Scrollbar: {
+    color: 'rgba(0, 0, 0, 0.2)',
+    colorHover: 'rgba(0, 0, 0, 0.35)',
+    width: '9px',
+    height: '9px',
+    borderRadius: '4px'
+  }
+}