Jelajahi Sumber

haha-admin&haha-admin-web前后端一体化部署

skyline 2 bulan lalu
induk
melakukan
2738b87b9b

+ 1 - 1
haha-admin-web/.env.production

@@ -1,5 +1,5 @@
 # 线上环境平台打包路径
-VITE_PUBLIC_PATH = /
+VITE_PUBLIC_PATH = /admin/
 
 # 线上环境路由历史模式(Hash模式传"hash"、HTML5模式传"h5"、Hash模式带base参数传"hash,base参数"、HTML5模式带base参数传"h5,base参数")
 VITE_ROUTER_HISTORY = "hash"

+ 1 - 1
haha-admin-web/src/assets/iconfont/iconfont.js

@@ -20,7 +20,7 @@
             "<style>.svgfont {display: inline-block;width: 1em;height: 1em;fill: currentColor;vertical-align: -0.1em;font-size:16px;}</style>"
           );
         } catch (t) {
-          console && console.log(t);
+          console.log(t);
         }
       }
       ((n = function () {

+ 104 - 0
haha-admin-web/src/components/ReAnimateSelector/index.tsx

@@ -0,0 +1,104 @@
+import { defineComponent, ref, watch } from "vue";
+
+const animateList = [
+  { label: "无", value: "" },
+  { label: "fadeIn", value: "fadeIn" },
+  { label: "fadeInDown", value: "fadeInDown" },
+  { label: "fadeInLeft", value: "fadeInLeft" },
+  { label: "fadeInRight", value: "fadeInRight" },
+  { label: "fadeInUp", value: "fadeInUp" },
+  { label: "fadeOut", value: "fadeOut" },
+  { label: "fadeOutDown", value: "fadeOutDown" },
+  { label: "fadeOutLeft", value: "fadeOutLeft" },
+  { label: "fadeOutRight", value: "fadeOutRight" },
+  { label: "fadeOutUp", value: "fadeOutUp" },
+  { label: "slideInDown", value: "slideInDown" },
+  { label: "slideInLeft", value: "slideInLeft" },
+  { label: "slideInRight", value: "slideInRight" },
+  { label: "slideInUp", value: "slideInUp" },
+  { label: "slideOutDown", value: "slideOutDown" },
+  { label: "slideOutLeft", value: "slideOutLeft" },
+  { label: "slideOutRight", value: "slideOutRight" },
+  { label: "slideOutUp", value: "slideOutUp" },
+  { label: "zoomIn", value: "zoomIn" },
+  { label: "zoomInDown", value: "zoomInDown" },
+  { label: "zoomInLeft", value: "zoomInLeft" },
+  { label: "zoomInRight", value: "zoomInRight" },
+  { label: "zoomInUp", value: "zoomInUp" },
+  { label: "zoomOut", value: "zoomOut" },
+  { label: "zoomOutDown", value: "zoomOutDown" },
+  { label: "zoomOutLeft", value: "zoomOutLeft" },
+  { label: "zoomOutRight", value: "zoomOutRight" },
+  { label: "zoomOutUp", value: "zoomOutUp" },
+  { label: "bounceIn", value: "bounceIn" },
+  { label: "bounceInDown", value: "bounceInDown" },
+  { label: "bounceInLeft", value: "bounceInLeft" },
+  { label: "bounceInRight", value: "bounceInRight" },
+  { label: "bounceInUp", value: "bounceInUp" },
+  { label: "bounceOut", value: "bounceOut" },
+  { label: "bounceOutDown", value: "bounceOutDown" },
+  { label: "bounceOutLeft", value: "bounceOutLeft" },
+  { label: "bounceOutRight", value: "bounceOutRight" },
+  { label: "bounceOutUp", value: "bounceOutUp" },
+  { label: "flipInX", value: "flipInX" },
+  { label: "flipInY", value: "flipInY" },
+  { label: "flipOutX", value: "flipOutX" },
+  { label: "flipOutY", value: "flipOutY" },
+  { label: "lightSpeedIn", value: "lightSpeedIn" },
+  { label: "lightSpeedOut", value: "lightSpeedOut" },
+  { label: "rotateIn", value: "rotateIn" },
+  { label: "rotateInDownLeft", value: "rotateInDownLeft" },
+  { label: "rotateInDownRight", value: "rotateInDownRight" },
+  { label: "rotateInUpLeft", value: "rotateInUpLeft" },
+  { label: "rotateInUpRight", value: "rotateInUpRight" },
+  { label: "rotateOut", value: "rotateOut" },
+  { label: "rotateOutDownLeft", value: "rotateOutDownLeft" },
+  { label: "rotateOutDownRight", value: "rotateOutDownRight" },
+  { label: "rotateOutUpLeft", value: "rotateOutUpLeft" },
+  { label: "rotateOutUpRight", value: "rotateOutUpRight" },
+  { label: "rollIn", value: "rollIn" },
+  { label: "rollOut", value: "rollOut" }
+];
+
+export default defineComponent({
+  name: "ReAnimateSelector",
+  props: {
+    modelValue: {
+      type: String,
+      default: ""
+    },
+    placeholder: {
+      type: String,
+      default: "请选择动画"
+    }
+  },
+  emits: ["update:modelValue"],
+  setup(props, { emit }) {
+    const currentValue = ref(props.modelValue);
+
+    watch(
+      () => props.modelValue,
+      val => {
+        currentValue.value = val;
+      }
+    );
+
+    watch(currentValue, val => {
+      emit("update:modelValue", val);
+    });
+
+    return () => (
+      <el-select
+        v-model={currentValue.value}
+        placeholder={props.placeholder}
+        clearable
+        filterable
+        class="w-full"
+      >
+        {animateList.map(item => (
+          <el-option key={item.value} label={item.label} value={item.value} />
+        ))}
+      </el-select>
+    );
+  }
+});

+ 1 - 0
haha-admin-web/src/utils/http/index.ts

@@ -17,6 +17,7 @@ import { useUserStoreHook } from "@/store/modules/user";
 const defaultConfig: AxiosRequestConfig = {
   // 请求超时时间
   timeout: 10000,
+  baseURL: import.meta.env.VITE_PUBLIC_PATH,
   headers: {
     Accept: "application/json, text/plain, */*",
     "Content-Type": "application/json",

+ 38 - 97
haha-admin-web/vite.config.ts

@@ -12,6 +12,43 @@ import {
 export default ({ mode }: ConfigEnv): UserConfigExport => {
   const { VITE_CDN, VITE_PORT, VITE_COMPRESSION, VITE_PUBLIC_PATH } =
     wrapperEnv(loadEnv(mode, root));
+  
+  // 统一的后端服务地址
+  const API_BASE_URL = "http://localhost:7070/admin";
+  
+  // 需要代理的 API 路径列表
+  const apiPaths = [
+    "/login",
+    "/user",
+    "/role",
+    "/permission",
+    "/users",
+    "/shops",
+    "/devices",
+    "/order",
+    "/products",
+    "/inventory",
+    "/marketing",
+    "/checkin",
+    "/announcement",
+    "/operation-log",
+    "/sync",
+    "/new-product-apply",
+    "/dashboard",
+    "/dict",
+    "/timed-discount"
+  ];
+  
+  // 动态生成代理配置
+  const proxyConfig: Record<string, any> = {};
+  apiPaths.forEach(path => {
+    proxyConfig[path] = {
+      target: API_BASE_URL,
+      changeOrigin: true,
+      rewrite: (p: string) => p.replace(new RegExp(`^${path}`), path)
+    };
+  });
+  
   return {
     base: VITE_PUBLIC_PATH,
     root,
@@ -22,103 +59,7 @@ export default ({ mode }: ConfigEnv): UserConfigExport => {
     server: {
       port: 8888,
       host: "0.0.0.0",
-      proxy: {
-        "/login": {
-          target: "http://localhost:7070/admin",
-          changeOrigin: true,
-          rewrite: path => path.replace(/^\/login/, "/login")
-        },
-        "/user": {
-          target: "http://localhost:7070/admin",
-          changeOrigin: true,
-          rewrite: path => path.replace(/^\/user/, "/user")
-        },
-        "/role": {
-          target: "http://localhost:7070/admin",
-          changeOrigin: true,
-          rewrite: path => path.replace(/^\/role/, "/role")
-        },
-        "/permission": {
-          target: "http://localhost:7070/admin",
-          changeOrigin: true,
-          rewrite: path => path.replace(/^\/permission/, "/permission")
-        },
-        "/users": {
-          target: "http://localhost:7070/admin",
-          changeOrigin: true,
-          rewrite: path => path.replace(/^\/users/, "/users")
-        },
-        "/shops": {
-          target: "http://localhost:7070/admin",
-          changeOrigin: true,
-          rewrite: path => path.replace(/^\/shops/, "/shops")
-        },
-        "/devices": {
-          target: "http://localhost:7070/admin",
-          changeOrigin: true,
-          rewrite: path => path.replace(/^\/devices/, "/devices")
-        },
-        "/order": {
-          target: "http://localhost:7070/admin",
-          changeOrigin: true,
-          rewrite: path => path.replace(/^\/order/, "/order")
-        },
-        "/products": {
-          target: "http://localhost:7070/admin",
-          changeOrigin: true,
-          rewrite: path => path.replace(/^\/products/, "/products")
-        },
-        "/inventory": {
-          target: "http://localhost:7070/admin",
-          changeOrigin: true,
-          rewrite: path => path.replace(/^\/inventory/, "/inventory")
-        },
-        "/marketing": {
-          target: "http://localhost:7070/admin",
-          changeOrigin: true,
-          rewrite: path => path.replace(/^\/marketing/, "/marketing")
-        },
-        "/checkin": {
-          target: "http://localhost:7070/admin",
-          changeOrigin: true,
-          rewrite: path => path.replace(/^\/checkin/, "/checkin")
-        },
-        "/announcement": {
-          target: "http://localhost:7070/admin",
-          changeOrigin: true,
-          rewrite: path => path.replace(/^\/announcement/, "/announcement")
-        },
-        "/operation-log": {
-          target: "http://localhost:7070/admin",
-          changeOrigin: true,
-          rewrite: path => path.replace(/^\/operation-log/, "/operation-log")
-        },
-        "/sync": {
-          target: "http://localhost:7070/admin",
-          changeOrigin: true,
-          rewrite: path => path.replace(/^\/sync/, "/sync")
-        },
-        "/new-product-apply": {
-          target: "http://localhost:7070/admin",
-          changeOrigin: true,
-          rewrite: path => path.replace(/^\/new-product-apply/, "/new-product-apply")
-        },
-        "/dashboard": {
-          target: "http://localhost:7070/admin",
-          changeOrigin: true,
-          rewrite: path => path.replace(/^\/dashboard/, "/dashboard")
-        },
-        "/dict": {
-          target: "http://localhost:7070/admin",
-          changeOrigin: true,
-          rewrite: path => path.replace(/^\/dict/, "/dict")
-        },
-        "/timed-discount": {
-          target: "http://localhost:7070/admin",
-          changeOrigin: true,
-          rewrite: path => path.replace(/^\/timed-discount/, "/timed-discount")
-        }
-      },
+      proxy: proxyConfig,
       // 预热文件以提前转换和缓存结果,降低启动期间的初始页面加载时长并防止转换瀑布
       warmup: {
         clientFiles: ["./index.html", "./src/{views,components}/*"]

+ 65 - 0
haha-admin/pom.xml

@@ -102,6 +102,71 @@
                     </execution>
                 </executions>
             </plugin>
+            <plugin>
+                <groupId>com.github.eirslett</groupId>
+                <artifactId>frontend-maven-plugin</artifactId>
+                <version>1.15.0</version>
+                <configuration>
+                    <workingDirectory>${project.basedir}/../haha-admin-web</workingDirectory>
+                    <installDirectory>${project.build.directory}</installDirectory>
+                </configuration>
+                <executions>
+                    <execution>
+                        <id>install node and pnpm</id>
+                        <goals>
+                            <goal>install-node-and-pnpm</goal>
+                        </goals>
+                        <configuration>
+                            <nodeVersion>v20.19.0</nodeVersion>
+                            <pnpmVersion>v9.0.0</pnpmVersion>
+                        </configuration>
+                    </execution>
+                    <execution>
+                        <id>pnpm install</id>
+                        <goals>
+                            <goal>pnpm</goal>
+                        </goals>
+                        <configuration>
+                            <arguments>install</arguments>
+                        </configuration>
+                    </execution>
+                    <execution>
+                        <id>pnpm build</id>
+                        <goals>
+                            <goal>pnpm</goal>
+                        </goals>
+                        <phase>prepare-package</phase>
+                        <configuration>
+                            <arguments>run build</arguments>
+                        </configuration>
+                    </execution>
+                </executions>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-resources-plugin</artifactId>
+                <version>3.3.1</version>
+                <executions>
+                    <execution>
+                        <id>copy-frontend-build</id>
+                        <phase>prepare-package</phase>
+                        <goals>
+                            <goal>copy-resources</goal>
+                        </goals>
+                        <configuration>
+                            <outputDirectory>${project.build.outputDirectory}/static</outputDirectory>
+                            <resources>
+                                <resource>
+                                    <directory>${project.basedir}/../haha-admin-web/dist</directory>
+                                    <includes>
+                                        <include>**/*</include>
+                                    </includes>
+                                </resource>
+                            </resources>
+                        </configuration>
+                    </execution>
+                </executions>
+            </plugin>
         </plugins>
     </build>
 

+ 31 - 0
haha-admin/src/main/java/com/haha/admin/config/SpaConfig.java

@@ -0,0 +1,31 @@
+package com.haha.admin.config;
+
+import org.springframework.context.annotation.Configuration;
+import org.springframework.core.io.ClassPathResource;
+import org.springframework.core.io.Resource;
+import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
+import org.springframework.web.servlet.resource.PathResourceResolver;
+
+import java.io.IOException;
+
+@Configuration
+public class SpaConfig implements WebMvcConfigurer {
+
+    @Override
+    public void addResourceHandlers(ResourceHandlerRegistry registry) {
+        registry.addResourceHandler("/**")
+            .addResourceLocations("classpath:/static/")
+            .resourceChain(true)
+            .addResolver(new PathResourceResolver() {
+                @Override
+                protected Resource getResource(String resourcePath, Resource location) throws IOException {
+                    Resource requestedResource = location.createRelative(resourcePath);
+                    if (requestedResource.exists() && requestedResource.isReadable()) {
+                        return requestedResource;
+                    }
+                    return new ClassPathResource("/static/index.html");
+                }
+            });
+    }
+}