Explorar o código

perf(views): 优化“首页”文件名与多语言

wangshun hai 3 días
pai
achega
9e6b074aa5
Modificáronse 1 ficheiros con 166 adicións e 0 borrados
  1. 166 0
      src/views/HomePage.vue

+ 166 - 0
src/views/HomePage.vue

@@ -0,0 +1,166 @@
+<script setup lang="ts">
+import { onMounted, onUnmounted, ref } from 'vue';
+import { useRouter } from 'vue-router';
+import { PAGInit } from 'libpag';
+
+import { t } from '@/i18n';
+
+import type { PAGView } from 'libpag/types/pag-view';
+
+const pagCanvas = ref<HTMLCanvasElement | null>(null);
+let pagView: PAGView | undefined = undefined;
+const router = useRouter();
+
+const addLog = () => {
+  router.push('/login');
+};
+
+onMounted(async () => {
+  if (!pagCanvas.value) {
+    console.error('Canvas element not found');
+    return;
+  }
+
+  // 初始化 libpag
+  const PAG = await PAGInit();
+
+  // 加载 PAG 文件
+  const pagUrl = '/portal.pag';
+  try {
+    const response = await fetch(pagUrl);
+    const buffer = await response.arrayBuffer();
+    const pagFile = await PAG.PAGFile.load(buffer);
+
+    // 创建 PAG 视图并初始化
+    pagView = await PAG.PAGView.init(pagFile, pagCanvas.value);
+    if (pagView) {
+      pagView.setRepeatCount(0); // 设置循环播放
+
+      // 修复:使用直接属性访问或数值常量
+      // 方法1: 检查 PAGScaleMode 是否直接作为 PAG 的属性
+      if (PAG.PAGScaleMode) {
+        pagView.setScaleMode(PAG.PAGScaleMode.Stretch);
+      } else if (PAG.ScaleMode) {
+        // 有些版本可能使用 PAG.ScaleMode
+        pagView.setScaleMode(PAG.ScaleMode.Stretch);
+      } else {
+        // 方法2: 使用数值常量
+        pagView.setScaleMode(1);
+      }
+      await pagView.play(); // 播放动画
+    }
+  } catch (error) {
+    console.error('Failed to load or play PAG file:', error);
+  }
+});
+
+onUnmounted(() => {
+  // 销毁实例,释放资源
+  if (pagView) {
+    pagView.destroy();
+  }
+});
+</script>
+
+<template>
+  <div class="fullscreen-container">
+    <div class="header-bar">
+      <AFlex justify="space-between" class="header-top" align="center">
+        <div>
+          <img class="aside-header-logo" src="@/assets/img/logo.png" />
+        </div>
+        <AFlex class="text-top">
+          <div class="text-color">{{ t('homePage.homePage') }}</div>
+          <div>{{ t('homePage.productIntroduction') }}</div>
+          <div>{{ t('homePage.aboutUs') }}</div>
+        </AFlex>
+        <div>
+          <AButton type="primary" class="button-style" @click="addLog">{{ t('homePage.tryNow') }}</AButton>
+        </div>
+      </AFlex>
+      <AFlex justify="center">
+        <div class="portal-text">
+          <div>{{ t('homePage.energyConsumptionCommander') }}</div>
+          <div>{{ t('homePage.thermalBalance') }}</div>
+          <AButton type="primary" @click="addLog" class="lord-button-style">{{ t('homePage.tryNow') }}</AButton>
+        </div>
+      </AFlex>
+    </div>
+    <canvas ref="pagCanvas" class="fullscreen-canvas"></canvas>
+  </div>
+</template>
+
+<style lang="scss" scoped>
+.text-top .text-color {
+  color: var(--antd-color-primary-hover);
+}
+
+.text-top > div {
+  margin-left: 56px;
+  font-size: 14px;
+  font-style: normal;
+  font-weight: 500;
+  line-height: 20px;
+  color: #333;
+  text-align: justify;
+  cursor: pointer;
+}
+
+.lord-button-style {
+  width: 172px;
+  height: 56px;
+  margin-top: 32px;
+  border-radius: 28px;
+}
+
+.portal-text {
+  margin-top: 85px;
+  font-size: 40px;
+  font-style: normal;
+  font-weight: 500;
+  line-height: 56px;
+  color: #333;
+  text-align: center;
+}
+
+.button-style {
+  width: 112px;
+  height: 48px;
+  border-radius: 24px;
+}
+
+.header-top {
+  width: 100%;
+  height: 80px;
+  padding: 0 80px;
+}
+
+.aside-header-logo {
+  width: 48px;
+  height: 48px;
+}
+
+.header-bar {
+  position: fixed;
+  top: 0;
+  left: 0;
+  width: 100vw;
+  height: 269px;
+  background: linear-gradient(180deg, #fff 0%, rgb(230 229 228 / 0%) 100%);
+}
+
+.fullscreen-container {
+  position: fixed;
+  top: 0;
+  left: 0;
+  width: 100vw;
+  height: 100vh;
+  overflow: hidden;
+}
+
+.fullscreen-canvas {
+  display: block;
+  width: 100vw;
+  height: 100vh;
+}
+</style>