Răsfoiți Sursa

fix: 优化

shuisheng 1 an în urmă
părinte
comite
ac00f4794c
2 a modificat fișierele cu 55 adăugiri și 10 ștergeri
  1. 30 6
      src/App.vue
  2. 25 4
      src/components/HomeModal/index.vue

+ 30 - 6
src/App.vue

@@ -2,6 +2,10 @@
   <n-config-provider :theme-overrides="themeOverrides">
     <n-dialog-provider>
       <router-view></router-view>
+      <HomeModal
+        :show="showModal"
+        :content="modalContent"
+      ></HomeModal>
     </n-dialog-provider>
   </n-config-provider>
 </template>
@@ -15,8 +19,9 @@ export default {
 <script lang="ts" setup>
 import { isMobile } from 'billd-utils';
 import { GlobalThemeOverrides, NConfigProvider } from 'naive-ui';
-import { onMounted } from 'vue';
+import { onMounted, ref } from 'vue';
 
+import { fetchSettingsList } from '@/api/settings';
 import { THEME_COLOR, appBuildInfo } from '@/constant';
 import { useCheckUpdate } from '@/hooks/use-common';
 import { loginMessage } from '@/hooks/use-login';
@@ -25,12 +30,15 @@ import { useUserStore } from '@/store/user';
 import { getHostnameUrl } from '@/utils';
 import { getLastBuildDate, setLastBuildDate } from '@/utils/localStorage/app';
 import { getToken } from '@/utils/localStorage/user';
-
-import { fetchSettingsList } from './api/settings';
+import { useRoute } from 'vue-router';
 
 const { checkUpdate } = useCheckUpdate();
 const cacheStore = usePiniaCacheStore();
 const userStore = useUserStore();
+const route = useRoute();
+
+const showModal = ref(false);
+const modalContent = ref('');
 
 const themeOverrides: GlobalThemeOverrides = {
   common: {
@@ -69,9 +77,25 @@ onMounted(() => {
   }
 });
 
-async function initSettings() {
-  const res = await fetchSettingsList({});
-  console.log(res);
+function initSettings() {
+  setTimeout(async () => {
+    if (route.path !== '/') {
+      return;
+    }
+    const res = await fetchSettingsList({});
+    if (res.code === 200) {
+      const allowHomeModal = res.data.rows.find(
+        (v) => v.key === 'allow_home_modal'
+      );
+      const homeModalContent = res.data.rows.find(
+        (v) => v.key === 'home_modal_content'
+      );
+      if (allowHomeModal?.value === '1' && homeModalContent?.value) {
+        showModal.value = true;
+        modalContent.value = homeModalContent.value;
+      }
+    }
+  }, 500);
 }
 
 function handleUpdate() {

+ 25 - 4
src/layout/pc/modal/index.vue → src/components/HomeModal/index.vue

@@ -5,16 +5,37 @@
     preset="dialog"
     positive-text="OK"
   >
-    <p></p>
+    <p>{{ content }}</p>
   </n-modal>
 </template>
 
 <script lang="ts" setup>
-import { ref } from 'vue';
+import { onMounted, ref, watch } from 'vue';
 
+const props = withDefaults(
+  defineProps<{
+    show?: boolean;
+    content: string;
+  }>(),
+  {
+    show: () => {
+      return false;
+    },
+    content: '',
+  }
+);
 const showModal = ref(false);
-// const showModal = ref(true);
-// const showModal = ref(router.currentRoute.value.name === routerName.home);
+
+watch(
+  () => props.show,
+  () => {
+    showModal.value = props.show;
+  }
+);
+
+onMounted(() => {
+  showModal.value = props.show;
+});
 </script>
 
 <style lang="scss" scoped>