Skip to content

Commit

Permalink
♻️ 通过 import.meta 获取当前环境
Browse files Browse the repository at this point in the history
  • Loading branch information
BTMuli committed Oct 8, 2023
1 parent 6e79c0a commit 66ecd9a
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
6 changes: 4 additions & 2 deletions src/components/app/t-sidebar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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">
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 3 additions & 1 deletion src/pages/common/Config.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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>("");
Expand Down
7 changes: 3 additions & 4 deletions src/pages/common/Home.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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: "请到设置页手动更新版本,即将弹出更新说明子页面",
Expand Down
8 changes: 2 additions & 6 deletions src/store/modules/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -36,8 +36,6 @@ export const useAppStore = defineStore(
});
// 开发者模式
const devMode = ref(false);
// 环境检测
const devEnv = ref(false);
// 应用主题
const theme = ref("default");

Expand All @@ -54,7 +52,6 @@ export const useAppStore = defineStore(
function init(): void {
loading.value = false;
devMode.value = false;
devEnv.value = false;
sidebar.submenu = {
wiki: false,
};
Expand All @@ -78,7 +75,6 @@ export const useAppStore = defineStore(
buildTime,
sidebar,
devMode,
devEnv,
dataPath,
userPath,
init,
Expand All @@ -96,7 +92,7 @@ export const useAppStore = defineStore(
{
key: "app",
storage: window.localStorage,
paths: ["devMode", "loading", "buildTime", "devEnv"],
paths: ["devMode", "loading", "buildTime"],
},
{
key: "sidebar",
Expand Down

0 comments on commit 66ecd9a

Please sign in to comment.