♻️ 通过 import.meta 获取当前环境

This commit is contained in:
BTMuli
2023-10-08 23:51:34 +08:00
parent 6e79c0a7e0
commit 66ecd9a91e
5 changed files with 13 additions and 14 deletions

View File

@@ -96,7 +96,7 @@ async function createDataDir(): Promise<void> {
// 初始化数据库
async function initData(): Promise<void> {
if (appStore.devEnv) {
if (!import.meta?.env?.PROD) {
console.info("开发环境,跳过数据库初始化!");
return;
}

View File

@@ -57,12 +57,12 @@
</template>
</v-list-item>
<v-divider />
<v-list-item v-show="appStore.devEnv" title="测试" value="test" :link="true" href="/test">
<v-list-item v-show="isDevEnv" title="测试" value="test" :link="true" href="/test">
<template #prepend>
<v-icon>mdi-test-tube</v-icon>
</template>
</v-list-item>
<v-divider v-show="appStore.devEnv" />
<v-divider v-show="isDevEnv" />
<v-list-group value="wiki" :fluid="true">
<template #activator="{ props }">
<v-list-item title="图鉴" v-bind="props">
@@ -132,6 +132,8 @@ import { useUserStore } from "../../store/modules/user";
const appStore = useAppStore();
const userStore = useUserStore();
const isDevEnv = ref<boolean>(!import.meta?.env?.PROD);
const userInfo = computed(() => {
const info = userStore.getBriefInfo();
return {

View File

@@ -107,7 +107,7 @@
<v-list-subheader :inset="true" class="config-header" title="调试" />
<v-divider :inset="true" class="border-opacity-75" />
<v-list-item
v-if="appStore.devEnv"
v-if="isDevEnv"
title="调试模式"
subtitle="开启后将显示调试信息"
prepend-icon="mdi-bug-play"
@@ -176,6 +176,8 @@ const userStore = useUserStore();
const homeStore = useHomeStore();
const achievementsStore = useAchievementsStore();
const isDevEnv = ref<boolean>(!import.meta?.env?.PROD);
// About App
const versionApp = ref<string>("");
const versionTauri = ref<string>("");

View File

@@ -49,10 +49,9 @@ function readLoading(): void {
onMounted(async () => {
loadingTitle.value = "正在加载首页";
loading.value = true;
const isProdEnv = import.meta?.env?.PROD;
// 获取当前环境
const timeGet = getBuildTime();
appStore.devEnv = timeGet.startsWith("dev");
if (!appStore.devEnv && appStore.devMode) {
if (isProdEnv && appStore.devMode) {
appStore.devMode = false;
}
const showItems = homeStore.getShowValue();
@@ -71,7 +70,7 @@ onMounted(async () => {
}),
);
timer.value = setInterval(readLoading, 100);
if (appStore.buildTime !== getBuildTime() && !appStore.devEnv) {
if (appStore.buildTime !== getBuildTime() && isProdEnv) {
const confirm = await showConfirm({
title: "检测到版本更新",
text: "请到设置页手动更新版本,即将弹出更新说明子页面",

View File

@@ -2,7 +2,7 @@
* @file store modules app.ts
* @description App store module
* @author BTMuli <bt-muli@outlook.com>
* @since Beta v0.3.1
* @since Beta v0.3.3
*/
// vue
@@ -36,8 +36,6 @@ export const useAppStore = defineStore(
});
// 开发者模式
const devMode = ref(false);
// 环境检测
const devEnv = ref(false);
// 应用主题
const theme = ref("default");
@@ -54,7 +52,6 @@ export const useAppStore = defineStore(
function init(): void {
loading.value = false;
devMode.value = false;
devEnv.value = false;
sidebar.submenu = {
wiki: false,
};
@@ -78,7 +75,6 @@ export const useAppStore = defineStore(
buildTime,
sidebar,
devMode,
devEnv,
dataPath,
userPath,
init,
@@ -96,7 +92,7 @@ export const useAppStore = defineStore(
{
key: "app",
storage: window.localStorage,
paths: ["devMode", "loading", "buildTime", "devEnv"],
paths: ["devMode", "loading", "buildTime"],
},
{
key: "sidebar",