mirror of
https://github.com/yangjian102621/geekai.git
synced 2025-09-17 08:46:38 +08:00
feat: Access environment variables using import.meta
This commit is contained in:
parent
8abae324a5
commit
4f15cec9ea
@ -68,7 +68,7 @@ watch(
|
|||||||
const handler = ref(0);
|
const handler = ref(0);
|
||||||
// 初始化 websocket 连接
|
// 初始化 websocket 连接
|
||||||
const connect = () => {
|
const connect = () => {
|
||||||
let host = process.env.VUE_APP_WS_HOST;
|
let host = import.meta.env.VITE_APP_WS_HOST;
|
||||||
if (host === "") {
|
if (host === "") {
|
||||||
if (location.protocol === "https:") {
|
if (location.protocol === "https:") {
|
||||||
host = "wss://" + location.host;
|
host = "wss://" + location.host;
|
||||||
|
@ -20,8 +20,8 @@ import { showMessageError } from "@/utils/dialog";
|
|||||||
import { getLicenseInfo, getSystemInfo } from "@/store/cache";
|
import { getLicenseInfo, getSystemInfo } from "@/store/cache";
|
||||||
|
|
||||||
const title = ref("");
|
const title = ref("");
|
||||||
const version = ref(process.env.VUE_APP_VERSION);
|
const version = ref(import.meta.env.VITE_APP_VERSION);
|
||||||
const gitURL = ref(process.env.VUE_APP_GIT_URL);
|
const gitURL = ref(import.meta.env.VITE_APP_GIT_URL);
|
||||||
const copyRight = ref("");
|
const copyRight = ref("");
|
||||||
const license = ref({});
|
const license = ref({});
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
@ -34,7 +34,7 @@ const props = defineProps({
|
|||||||
// 获取系统配置
|
// 获取系统配置
|
||||||
getSystemInfo()
|
getSystemInfo()
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
title.value = res.data.title ?? process.env.VUE_APP_TITLE;
|
title.value = res.data.title ?? import.meta.env.VITE_APP_TITLE;
|
||||||
copyRight.value =
|
copyRight.value =
|
||||||
res.data.copyright.length > 1
|
res.data.copyright.length > 1
|
||||||
? res.data.copyright
|
? res.data.copyright
|
||||||
|
@ -218,8 +218,8 @@ watch(
|
|||||||
|
|
||||||
const login = ref(true);
|
const login = ref(true);
|
||||||
const data = ref({
|
const data = ref({
|
||||||
username: process.env.VUE_APP_USER,
|
username: import.meta.env.VITE_APP_USER,
|
||||||
password: process.env.VUE_APP_PASS,
|
password: import.meta.env.VITE_APP_PASS,
|
||||||
mobile: "",
|
mobile: "",
|
||||||
email: "",
|
email: "",
|
||||||
repass: "",
|
repass: "",
|
||||||
|
@ -107,7 +107,7 @@ const animateVoice = () => {
|
|||||||
|
|
||||||
const wavRecorder = ref(new WavRecorder({ sampleRate: 24000 }));
|
const wavRecorder = ref(new WavRecorder({ sampleRate: 24000 }));
|
||||||
const wavStreamPlayer = ref(new WavStreamPlayer({ sampleRate: 24000 }));
|
const wavStreamPlayer = ref(new WavStreamPlayer({ sampleRate: 24000 }));
|
||||||
let host = process.env.VUE_APP_WS_HOST;
|
let host = import.meta.env.VITE_APP_WS_HOST;
|
||||||
if (host === "") {
|
if (host === "") {
|
||||||
if (location.protocol === "https:") {
|
if (location.protocol === "https:") {
|
||||||
host = "wss://" + location.host;
|
host = "wss://" + location.host;
|
||||||
|
@ -62,8 +62,8 @@ import { onMounted, ref } from "vue";
|
|||||||
import { ElMessage } from "element-plus";
|
import { ElMessage } from "element-plus";
|
||||||
import { getSystemInfo } from "@/store/cache";
|
import { getSystemInfo } from "@/store/cache";
|
||||||
|
|
||||||
const title = ref(process.env.VUE_APP_TITLE);
|
const title = ref(import.meta.env.VITE_APP_TITLE);
|
||||||
const version = ref(process.env.VUE_APP_VERSION);
|
const version = ref(import.meta.env.VITE_APP_VERSION);
|
||||||
|
|
||||||
const samples = ref([
|
const samples = ref([
|
||||||
"用小学生都能听懂的术语解释什么是量子纠缠",
|
"用小学生都能听懂的术语解释什么是量子纠缠",
|
||||||
|
@ -52,7 +52,7 @@ import {ElMessage} from "element-plus";
|
|||||||
import {removeAdminToken} from "@/store/session";
|
import {removeAdminToken} from "@/store/session";
|
||||||
import {useSharedStore} from "@/store/sharedata";
|
import {useSharedStore} from "@/store/sharedata";
|
||||||
|
|
||||||
const version = ref(process.env.VUE_APP_VERSION);
|
const version = ref(import.meta.env.VITE_APP_VERSION);
|
||||||
const avatar = ref("/images/user-info.jpg");
|
const avatar = ref("/images/user-info.jpg");
|
||||||
const sidebar = useSidebarStore();
|
const sidebar = useSidebarStore();
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
@ -6,8 +6,8 @@ import {removeAdminInfo} from "@/store/cache";
|
|||||||
* storage handler
|
* storage handler
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const UserTokenKey = process.env.VUE_APP_KEY_PREFIX + "Authorization";
|
const UserTokenKey = import.meta.env.VITE_APP_KEY_PREFIX + "Authorization";
|
||||||
const AdminTokenKey = process.env.VUE_APP_KEY_PREFIX + "Admin-Authorization"
|
const AdminTokenKey = import.meta.env.VITE_APP_KEY_PREFIX + "Admin-Authorization"
|
||||||
|
|
||||||
export function getSessionId() {
|
export function getSessionId() {
|
||||||
return randString(42)
|
return randString(42)
|
||||||
|
@ -46,9 +46,9 @@ export function FormatFileSize(bytes) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function setRoute(path) {
|
export function setRoute(path) {
|
||||||
Storage.set(process.env.VUE_APP_KEY_PREFIX + 'ROUTE_',path)
|
Storage.set(import.meta.env.VITE_APP_KEY_PREFIX + 'ROUTE_', path)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getRoute() {
|
export function getRoute() {
|
||||||
return Storage.get(process.env.VUE_APP_KEY_PREFIX + 'ROUTE_')
|
return Storage.get(import.meta.env.VITE_APP_KEY_PREFIX + 'ROUTE_')
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@ import axios from 'axios'
|
|||||||
import {getAdminToken, getUserToken, removeAdminToken, removeUserToken} from "@/store/session";
|
import {getAdminToken, getUserToken, removeAdminToken, removeUserToken} from "@/store/session";
|
||||||
|
|
||||||
axios.defaults.timeout = 180000
|
axios.defaults.timeout = 180000
|
||||||
axios.defaults.baseURL = process.env.VUE_APP_API_HOST
|
axios.defaults.baseURL = import.meta.env.VITE_APP_API_HOST
|
||||||
axios.defaults.withCredentials = true;
|
axios.defaults.withCredentials = true;
|
||||||
//axios.defaults.headers.post['Content-Type'] = 'application/json'
|
//axios.defaults.headers.post['Content-Type'] = 'application/json'
|
||||||
|
|
||||||
|
@ -228,7 +228,7 @@ export const replaceImg =(img) => {
|
|||||||
if (!img.startsWith("http")) {
|
if (!img.startsWith("http")) {
|
||||||
img = `${location.protocol}//${location.host}/${img}`
|
img = `${location.protocol}//${location.host}/${img}`
|
||||||
}
|
}
|
||||||
const devHost = process.env.VUE_APP_API_HOST
|
const devHost = import.meta.env.VITE_APP_API_HOST
|
||||||
const localhost = "http://localhost:5678"
|
const localhost = "http://localhost:5678"
|
||||||
if (img.includes(localhost)) {
|
if (img.includes(localhost)) {
|
||||||
return img?.replace(localhost, devHost)
|
return img?.replace(localhost, devHost)
|
||||||
|
@ -169,7 +169,7 @@ const loginUser = ref({});
|
|||||||
const routerViewKey = ref(0);
|
const routerViewKey = ref(0);
|
||||||
const showConfigDialog = ref(false);
|
const showConfigDialog = ref(false);
|
||||||
const license = ref({ de_copy: true });
|
const license = ref({ de_copy: true });
|
||||||
const gitURL = ref(process.env.VUE_APP_GIT_URL);
|
const gitURL = ref(import.meta.env.VITE_APP_GIT_URL);
|
||||||
const showLoginDialog = ref(false);
|
const showLoginDialog = ref(false);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -80,8 +80,8 @@ const slogan = ref("");
|
|||||||
const license = ref({ de_copy: true });
|
const license = ref({ de_copy: true });
|
||||||
|
|
||||||
const isLogin = ref(false);
|
const isLogin = ref(false);
|
||||||
const docsURL = ref(process.env.VUE_APP_DOCS_URL);
|
const docsURL = ref(import.meta.env.VITE_APP_DOCS_URL);
|
||||||
const gitURL = ref(process.env.VUE_APP_GIT_URL);
|
const gitURL = ref(import.meta.env.VITE_APP_GIT_URL);
|
||||||
const navs = ref([]);
|
const navs = ref([]);
|
||||||
|
|
||||||
const iconMap = ref({
|
const iconMap = ref({
|
||||||
|
@ -62,8 +62,8 @@ const enableVerify = ref(false);
|
|||||||
const captchaRef = ref(null);
|
const captchaRef = ref(null);
|
||||||
const ruleFormRef = ref(null);
|
const ruleFormRef = ref(null);
|
||||||
const ruleForm = reactive({
|
const ruleForm = reactive({
|
||||||
username: process.env.VUE_APP_USER,
|
username: import.meta.env.VITE_APP_USER,
|
||||||
password: process.env.VUE_APP_PASS,
|
password: import.meta.env.VITE_APP_PASS,
|
||||||
});
|
});
|
||||||
const rules = {
|
const rules = {
|
||||||
username: [{ required: true, trigger: "blur", message: "请输入账号" }],
|
username: [{ required: true, trigger: "blur", message: "请输入账号" }],
|
||||||
|
@ -171,7 +171,7 @@ onUnmounted(() => {
|
|||||||
|
|
||||||
const download = (item) => {
|
const download = (item) => {
|
||||||
const url = replaceImg(item.video_url);
|
const url = replaceImg(item.video_url);
|
||||||
const downloadURL = `${process.env.VUE_APP_API_HOST}/api/download?url=${url}`;
|
const downloadURL = `${import.meta.env.VITE_APP_API_HOST}/api/download?url=${url}`;
|
||||||
// parse filename
|
// parse filename
|
||||||
const urlObj = new URL(url);
|
const urlObj = new URL(url);
|
||||||
const fileName = urlObj.pathname.split("/").pop();
|
const fileName = urlObj.pathname.split("/").pop();
|
||||||
|
@ -209,11 +209,11 @@ const pay = (product, payWay) => {
|
|||||||
}
|
}
|
||||||
loading.value = true;
|
loading.value = true;
|
||||||
loadingText.value = "正在生成支付订单...";
|
loadingText.value = "正在生成支付订单...";
|
||||||
let host = process.env.VUE_APP_API_HOST;
|
let host = import.meta.env.VITE_APP_API_HOST;
|
||||||
if (host === "") {
|
if (host === "") {
|
||||||
host = `${location.protocol}//${location.host}`;
|
host = `${location.protocol}//${location.host}`;
|
||||||
}
|
}
|
||||||
httpPost(`${process.env.VUE_APP_API_HOST}/api/payment/doPay`, {
|
httpPost(`${import.meta.env.VITE_APP_API_HOST}/api/payment/doPay`, {
|
||||||
product_id: product.id,
|
product_id: product.id,
|
||||||
pay_way: payWay.pay_way,
|
pay_way: payWay.pay_way,
|
||||||
pay_type: payWay.pay_type,
|
pay_type: payWay.pay_type,
|
||||||
|
@ -447,7 +447,7 @@ const merge = (item) => {
|
|||||||
// 下载歌曲
|
// 下载歌曲
|
||||||
const download = (item) => {
|
const download = (item) => {
|
||||||
const url = replaceImg(item.audio_url);
|
const url = replaceImg(item.audio_url);
|
||||||
const downloadURL = `${process.env.VUE_APP_API_HOST}/api/download?url=${url}`;
|
const downloadURL = `${import.meta.env.VITE_APP_API_HOST}/api/download?url=${url}`;
|
||||||
// parse filename
|
// parse filename
|
||||||
const urlObj = new URL(url);
|
const urlObj = new URL(url);
|
||||||
const fileName = urlObj.pathname.split("/").pop();
|
const fileName = urlObj.pathname.split("/").pop();
|
||||||
|
@ -52,8 +52,8 @@ import Captcha from "@/components/Captcha.vue";
|
|||||||
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const title = ref("Geek-AI Console");
|
const title = ref("Geek-AI Console");
|
||||||
const username = ref(process.env.VUE_APP_ADMIN_USER);
|
const username = ref(import.meta.env.VITE_APP_ADMIN_USER);
|
||||||
const password = ref(process.env.VUE_APP_ADMIN_PASS);
|
const password = ref(import.meta.env.VITE_APP_ADMIN_PASS);
|
||||||
const logo = ref("");
|
const logo = ref("");
|
||||||
const enableVerify = ref(false);
|
const enableVerify = ref(false);
|
||||||
const captchaRef = ref(null);
|
const captchaRef = ref(null);
|
||||||
|
@ -382,7 +382,7 @@ watch(
|
|||||||
// const connect = function () {
|
// const connect = function () {
|
||||||
// // 初始化 WebSocket 对象
|
// // 初始化 WebSocket 对象
|
||||||
// const _sessionId = getSessionId();
|
// const _sessionId = getSessionId();
|
||||||
// let host = process.env.VUE_APP_WS_HOST
|
// let host = import.meta.env.VITE_APP_WS_HOST
|
||||||
// if (host === '') {
|
// if (host === '') {
|
||||||
// if (location.protocol === 'https:') {
|
// if (location.protocol === 'https:') {
|
||||||
// host = 'wss://' + location.host;
|
// host = 'wss://' + location.host;
|
||||||
|
@ -74,7 +74,7 @@ import { arrayContains, removeArrayItem, showLoginDialog, substr } from "@/utils
|
|||||||
import { showNotify } from "vant";
|
import { showNotify } from "vant";
|
||||||
import { ElMessage } from "element-plus";
|
import { ElMessage } from "element-plus";
|
||||||
|
|
||||||
const title = ref(process.env.VUE_APP_TITLE);
|
const title = ref(import.meta.env.VITE_APP_TITLE);
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const isLogin = ref(false);
|
const isLogin = ref(false);
|
||||||
const apps = ref([]);
|
const apps = ref([]);
|
||||||
|
@ -284,11 +284,11 @@ const pay = (product, payWay) => {
|
|||||||
message: "正在创建订单",
|
message: "正在创建订单",
|
||||||
forbidClick: true,
|
forbidClick: true,
|
||||||
});
|
});
|
||||||
let host = process.env.VUE_APP_API_HOST;
|
let host = import.meta.env.VITE_APP_API_HOST;
|
||||||
if (host === "") {
|
if (host === "") {
|
||||||
host = `${location.protocol}//${location.host}`;
|
host = `${location.protocol}//${location.host}`;
|
||||||
}
|
}
|
||||||
httpPost(`${process.env.VUE_APP_API_HOST}/api/payment/doPay`, {
|
httpPost(`${import.meta.env.VITE_APP_API_HOST}/api/payment/doPay`, {
|
||||||
product_id: product.id,
|
product_id: product.id,
|
||||||
pay_way: payWay.pay_way,
|
pay_way: payWay.pay_way,
|
||||||
pay_type: payWay.pay_type,
|
pay_type: payWay.pay_type,
|
||||||
|
53
web/vite.config.js
Normal file
53
web/vite.config.js
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
import { defineConfig, loadEnv } from 'vite';
|
||||||
|
import vue from '@vitejs/plugin-vue';
|
||||||
|
import path from 'path';
|
||||||
|
|
||||||
|
export default defineConfig(({ mode }) => {
|
||||||
|
const env = loadEnv(mode, process.cwd());
|
||||||
|
|
||||||
|
console.log('VITE_API_HOST from .env:', env);
|
||||||
|
|
||||||
|
return {
|
||||||
|
plugins: [vue()],
|
||||||
|
resolve: {
|
||||||
|
alias: {
|
||||||
|
'@': path.resolve(__dirname, 'src'),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
css: {
|
||||||
|
preprocessorOptions: {
|
||||||
|
stylus: {
|
||||||
|
paths: [path.resolve(__dirname, 'src')],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
build: {
|
||||||
|
sourcemap: false,
|
||||||
|
minify: 'terser',
|
||||||
|
rollupOptions: {
|
||||||
|
output: {
|
||||||
|
manualChunks: {
|
||||||
|
vendor: ['vue', 'vue-router', 'pinia'],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
server: {
|
||||||
|
port: 8888,
|
||||||
|
host: true,
|
||||||
|
proxy: {
|
||||||
|
'/api': {
|
||||||
|
target: env.VITE_APP_API_HOST,
|
||||||
|
changeOrigin: true,
|
||||||
|
},
|
||||||
|
'/static/upload/': {
|
||||||
|
target: env.VITE_APP_API_HOST,
|
||||||
|
changeOrigin: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
esbuild: {
|
||||||
|
// 模拟 transpileDependencies: true
|
||||||
|
},
|
||||||
|
};
|
||||||
|
});
|
Loading…
Reference in New Issue
Block a user