Pārlūkot izejas kodu

构建全局变量

huangyan 1 gadu atpakaļ
vecāks
revīzija
74d73934f4
2 mainītis faili ar 13 papildinājumiem un 7 dzēšanām
  1. 6 6
      app/src/App.vue
  2. 7 1
      app/vite.config.js

+ 6 - 6
app/src/App.vue

@@ -548,7 +548,7 @@ const importFromJson = () => {
 //从服务器获取模板
 const importFromJsonServer = async (itemId) => {
   try {
-    const url = new URL('http://localhost:8080/api/template');
+    const url = new URL(process.env.TEMPLATE_API_URL+'template');
     url.searchParams.append('name', itemId);
     const response = await fetch(url, {
       headers: {
@@ -577,7 +577,7 @@ const importFromJsonServer = async (itemId) => {
 let search = ref('')
 const searchTemplate = async () => {
   try {
-    const url = new URL('http://localhost:8080/api/search');
+    const url = new URL(process.env.TEMPLATE_API_URL+'search');
     url.searchParams.append('name', search.value);
     const response = await fetch(url, {
       headers: {
@@ -609,7 +609,7 @@ const DeleteeFromJsonServer = async (itemId) => {
     type: 'warning',
   }).then(async () => {
     try {
-      const url = new URL('http://localhost:8080/api/template');
+      const url = new URL(process.env.TEMPLATE_API_URL+'template');
       url.searchParams.append('name', itemId);
       const response = await fetch(url, {
         method: 'DELETE',
@@ -689,7 +689,7 @@ const savetemplate = async (types) => {
     onlySelected: exportOnlySelected.value
   })
   try {
-    const response = await fetch('http://localhost:8080/api/saveTemplate', {
+    const response = await fetch(process.env.TEMPLATE_API_URL+'saveTemplate', {
       method: 'POST',
       headers: {
         'Content-Type': 'application/json'
@@ -722,7 +722,7 @@ async function getTemplats() {
   const fileName = getQueryParams(url);
   if (fileName.fileName != undefined) {
     try {
-      const url = new URL('http://localhost:8080/api/template');
+      const url = new URL(process.env.TEMPLATE_API_URL+'template');
       url.searchParams.append('name', fileName.fileName);
       const response = await fetch(url, {
         headers: {
@@ -747,7 +747,7 @@ const templateItems = async () => {
   };
   names.clear() //清空map 重新渲染
   try {
-    const response = await fetch('http://localhost:8080/api/template', {
+    const response = await fetch(process.env.TEMPLATE_API_URL+'template', {
       method: 'POST',
       headers: {
         'Content-Type': 'application/json',

+ 7 - 1
app/vite.config.js

@@ -4,9 +4,15 @@ import AutoImport from 'unplugin-auto-import/vite'
 import Components from 'unplugin-vue-components/vite'
 import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
 
+
+
+const TEMPLATE_API_URL = 'http://localhost:8080/api/';
 // https://vitejs.dev/config/
 export default defineConfig({
-  base: '/tiny_whiteboard_demo/',
+  base: '/',
+  define: {
+    'process.env.TEMPLATE_API_URL': JSON.stringify(TEMPLATE_API_URL),
+  },
   plugins: [
     vue(),
     AutoImport({