Quellcode durchsuchen

📦 修改页面嵌入问题

快乐的梦鱼 vor 2 Wochen
Ursprung
Commit
100bc2c11d

+ 11 - 6
src/App.vue

@@ -8,8 +8,10 @@
     }"
     :componentSize="'large'"
   >
-    <NavBar />
-    <main>
+    <NavBar v-if="!authStore.loginFromEmbed" />
+    <main :class="{
+      'has-nav': !authStore.loginFromEmbed,
+    }">
       <RouterView />
       <!-- <RouterView v-slot="{ Component }">
         <KeepAlive>
@@ -18,7 +20,7 @@
         <component :is="Component" v-if="!route.meta.keepAlive" />
       </RouterView> -->
     </main>
-    <FooterSmall />
+    <FooterSmall v-if="!authStore.loginFromEmbed" />
   </a-config-provider>
 </template>
 
@@ -33,21 +35,24 @@ import FooterSmall from './components/FooterSmall.vue';
 import Colors from './assets/scss/vueexp.module.scss';
 
 const authStore = useAuthStore();
+const route = useRoute();
 const { checkAndRedirectLoginPage } = useRedirectLoginPage();
 
 onMounted(async () => {
-  await authStore.loadLoginState();
+  await authStore.loadLoginState(route);
   checkAndRedirectLoginPage();
 });
 
-const route = useRoute();
 
 watch(route, () => {
   window.scrollTo({
     top: 0,
     behavior: 'instant'
   });
-  checkAndRedirectLoginPage();
+  if (!authStore.isLogged)
+    authStore.loadLoginState(route).finally(() => {
+      checkAndRedirectLoginPage();
+    });
 });
 </script>
 

+ 1 - 1
src/api/auth/UserApi.ts

@@ -73,7 +73,7 @@ export class UserApi extends AppServerRequestModule<DataModel> {
     mobile: string,
     password: string,
   }) {
-    return (await this.post('/ich/inheritor/login', data, '登录', undefined, LoginResult)).data as LoginResult;
+    return (await this.post('/user/login', data, '登录', undefined, LoginResult)).data as LoginResult;
   }
   async loginAdmin(data: {
     account: string,

+ 7 - 4
src/components/NavBar.vue

@@ -109,10 +109,6 @@ onBeforeUnmount(() => {
 
 $nav-height: 70px;
 
-.nav-placeholder {
-  height: $nav-height; 
-  background-color: $primary-color;
-}
 nav.main {
   position: fixed;
   display: flex;
@@ -203,6 +199,13 @@ nav.main {
   }
 }
 
+.main.has-nav {
+  .nav-placeholder {
+    height: $nav-height; 
+    background-color: $primary-color;
+  }
+}
+
 .mobile-menu {
   //display: none;
   position: fixed;

+ 1 - 2
src/pages/admin.vue

@@ -8,8 +8,7 @@
       <div class="content">
         <div class="title">
           <h2>管理员管理</h2>
-        </div>
-       
+        </div>      
         <a-tabs v-model:activeKey="activeKey" centered>
           <a-tab-pane key="1" tab="志愿者列表">
             <CommonListBlock 

+ 3 - 1
src/pages/inheritor.vue

@@ -38,7 +38,7 @@
                 <div class="size-ss w-100">{{ item.villageName }}</div>
                 <div class="d-flex flex-row align-center">
                   <a-button type="primary" @click="goSubmitDigPage(item)">采编</a-button>
-                  <a-button class="ml-2" @click="goManagePage(item)">管理</a-button>
+                  <a-button v-if="authStore.isAdmin" class="ml-2" @click="goManagePage(item)">管理</a-button>
                 </div>
               </div>
             </div>
@@ -55,8 +55,10 @@ import { useRouter } from 'vue-router';
 import { useSimpleDataLoader, SimplePageContentLoader } from '@imengyu/imengyu-web-shared';
 import { useCollectStore } from '@/stores/collect';
 import VillageApi, { VillageListItem } from '@/api/inhert/VillageApi';
+import { useAuthStore } from '@/stores/auth';
 
 const router = useRouter();
+const authStore = useAuthStore();
 
 const collectStore = useCollectStore();
 const villageListLoader = useSimpleDataLoader(async () => await VillageApi.getClaimedVallageList(), true);

+ 20 - 1
src/pages/login.vue

@@ -24,6 +24,7 @@
 <script setup lang="ts">
 import { useAuthStore } from '@/stores/auth';
 import { waitTimeOut } from '@imengyu/imengyu-utils';
+import type { SimpleSelectFormItemProps } from '@imengyu/imengyu-web-shared';
 import { DynamicForm, type IDynamicFormOptions, type IDynamicFormRef } from '@imengyu/vue-dynamic-form';
 import { message, Modal, type FormInstance } from 'ant-design-vue';
 import { ref } from 'vue';
@@ -59,6 +60,24 @@ const formOptions = ref<IDynamicFormOptions>({
         placeholder: '请输入密码' 
       }
     },
+    {
+      label: '登录类型',
+      name: 'type',
+      type: 'radio-value',
+      additionalProps: {
+        placeholder: '请输入密码',
+        options: [
+          {
+            text: '志愿者',
+            value: 0,
+          },
+          {
+            text: '管理员',
+            value: 1,
+          },
+        ],
+      } as SimpleSelectFormItemProps
+    },
   ],
   formRules: {
     account: [
@@ -83,7 +102,7 @@ async function handleSubmit() {
     await authStore.login(
       formModel.value.account,
       formModel.value.password,
-      1,
+      formModel.value.type,
     );
     message.success('您已成功登录');
     await waitTimeOut(200);

+ 1 - 1
src/scripts/UpdateScript/postConfig.mjs

@@ -20,7 +20,7 @@ const localConfig = existsSync(localConfigPath) ? JSON.parse(readFileSync(localC
 export const config = {
   server: localConfig.updateServer || 'https://update-server1.imengyu.top/',
   submitKey: '',
-  appId: 2,
+  appId: 4,
   uploadWebConfig: {
     storageAction: 'override',
     storageProps: {

+ 14 - 6
src/stores/auth.ts

@@ -1,11 +1,11 @@
 import UserApi, { LoginResult, UserInfo } from "@/api/auth/UserApi";
-import { SettingsUtils } from "@imengyu/imengyu-utils";
+import { HtmlUtils, SettingsUtils } from "@imengyu/imengyu-utils";
 import { defineStore } from "pinia"
+import { useRoute, type RouteLocationNormalizedLoadedGeneric } from "vue-router";
 
 const STORAGE_KEY = 'authInfo';
 const canRefresh = false;
 
-
 export const useAuthStore = defineStore('auth', {
   state: () => ({
     token: '',
@@ -13,11 +13,19 @@ export const useAuthStore = defineStore('auth', {
     userId: 0,
     userInfo: null as null|UserInfo,
     loginType: 0,
+    loginFromEmbed: false,
   }),
   actions: {
-    async loadLoginState() {
+    async loadLoginState(route: RouteLocationNormalizedLoadedGeneric) {
       try {
-        const res = localStorage.getItem(STORAGE_KEY);
+        const query = route.query.internalAuth as string|undefined;
+        let res = localStorage.getItem(STORAGE_KEY);
+        this.loginFromEmbed = false;
+        if (!res && query) {
+          res = decodeURIComponent(query);
+          this.loginFromEmbed = true;
+          localStorage.setItem(STORAGE_KEY, res);
+        }
         if (!res)
           throw 'no storage';
         const authInfo = JSON.parse(res);
@@ -28,10 +36,10 @@ export const useAuthStore = defineStore('auth', {
         this.loginType = authInfo.loginType;
 
         // 检查token是否过期,如果快要过期,则刷新token
-        if (canRefresh && Date.now() > this.expireAt + 1000 * 3600 * 5) {
+        /*if (canRefresh && Date.now() > this.expireAt + 1000 * 3600 * 5) {
           const refreshResult = await UserApi.refresh();
           this.loginResultHandle(refreshResult, this.loginType);
-        }
+        }*/
       } catch (error) {
         this.token = '';
         this.userId = 0;

+ 5 - 3
vite.config.ts

@@ -1,9 +1,8 @@
-import { fileURLToPath, URL } from 'node:url'
-
 import { defineConfig } from 'vite'
 import vue from '@vitejs/plugin-vue'
 import vueJsx from '@vitejs/plugin-vue-jsx'
 import vueDevTools from 'vite-plugin-vue-devtools'
+import { fileURLToPath, URL } from 'node:url'
 
 // https://vite.dev/config/
 export default defineConfig({
@@ -13,9 +12,12 @@ export default defineConfig({
     vueDevTools(),
   ],
   base: './',
+  build: {
+    sourcemap: true
+  },
   resolve: {
     alias: {
       '@': fileURLToPath(new URL('./src', import.meta.url))
     },
   },
-})
+})