ソースを参照

路径错误需要报错404

Jing 1 ヶ月 前
コミット
572f4d534e

+ 1 - 0
.nuxt/imports.d.ts

@@ -32,4 +32,5 @@ export { requestData, requestDataPromise, requestDataWebUrl, requestHome } from
 export { getTime, getTitleLength, getLinkPath, getLinkPathDetail, getLinkPathDetail1, getRoutePath, getLinkPath1 } from '../composables/publicFunction';
 export { seoSetup } from '../composables/useSeo';
 export { apiUse, asyncFetchData, fGET, fPOST, fPUT, fDELETE, GET, POST, PUT, DELETE } from '../utils/request';
+export { useNuxtDevTools } from '../node_modules/@nuxt/devtools/dist/runtime/use-nuxt-devtools';
 export { definePageMeta } from '../node_modules/nuxt/dist/pages/runtime/composables';

+ 1 - 1
.nuxt/manifest/latest.json

@@ -1 +1 @@
-{"id":"a6ca4f6e-5184-4b63-933c-904031213293","timestamp":1746781083438}
+{"id":"13263338-764a-4b14-909f-5a16a085010b","timestamp":1747041152672}

+ 1 - 0
.nuxt/manifest/meta/13263338-764a-4b14-909f-5a16a085010b.json

@@ -0,0 +1 @@
+{"id":"13263338-764a-4b14-909f-5a16a085010b","timestamp":1747041152672,"matcher":{"static":{},"wildcard":{},"dynamic":{}},"prerendered":[]}

+ 0 - 1
.nuxt/manifest/meta/a6ca4f6e-5184-4b63-933c-904031213293.json

@@ -1 +0,0 @@
-{"id":"a6ca4f6e-5184-4b63-933c-904031213293","timestamp":1746781083438,"matcher":{"static":{},"wildcard":{},"dynamic":{}},"prerendered":[]}

+ 1 - 1
.nuxt/nuxt.d.ts

@@ -1,6 +1,6 @@
 // Generated by nuxi
-/// <reference types="@nuxt/devtools" />
 /// <reference types="@nuxt/telemetry" />
+/// <reference types="@nuxt/devtools" />
 /// <reference path="types/builder-env.d.ts" />
 /// <reference types="nuxt" />
 /// <reference path="types/app-defaults.d.ts" />

+ 9 - 0
.nuxt/nuxt.json

@@ -0,0 +1,9 @@
+{
+  "_hash": "sJUFJxUAIm",
+  "project": {
+    "rootDir": "D:/01_AA_ssr_master/nongminwang"
+  },
+  "versions": {
+    "nuxt": "3.15.2"
+  }
+}

+ 1 - 1
.nuxt/tsconfig.json

@@ -102,7 +102,7 @@
         "./imports"
       ],
       "#app-manifest": [
-        "./manifest/meta/a6ca4f6e-5184-4b63-933c-904031213293.json"
+        "./manifest/meta/dev.json"
       ],
       "#components": [
         "./components"

+ 1 - 0
.nuxt/types/build.d.ts

@@ -11,6 +11,7 @@ declare module "#build/paths.mjs";
 declare module "#build/root-component.mjs";
 declare module "#build/plugins.server.mjs";
 declare module "#build/test-component-wrapper.mjs";
+declare module "#build/devtools/settings.mjs";
 declare module "#build/routes.mjs";
 declare module "#build/pages.mjs";
 declare module "#build/router.options.mjs";

+ 2 - 0
.nuxt/types/imports.d.ts

@@ -134,6 +134,7 @@ declare global {
   const useModel: typeof import('vue')['useModel']
   const useNuxtApp: typeof import('../../node_modules/nuxt/dist/app/nuxt')['useNuxtApp']
   const useNuxtData: typeof import('../../node_modules/nuxt/dist/app/composables/asyncData')['useNuxtData']
+  const useNuxtDevTools: typeof import('../../node_modules/@nuxt/devtools/dist/runtime/use-nuxt-devtools')['useNuxtDevTools']
   const usePreviewMode: typeof import('../../node_modules/nuxt/dist/app/composables/preview')['usePreviewMode']
   const useRequestEvent: typeof import('../../node_modules/nuxt/dist/app/composables/ssr')['useRequestEvent']
   const useRequestFetch: typeof import('../../node_modules/nuxt/dist/app/composables/ssr')['useRequestFetch']
@@ -333,6 +334,7 @@ declare module 'vue' {
     readonly useModel: UnwrapRef<typeof import('vue')['useModel']>
     readonly useNuxtApp: UnwrapRef<typeof import('../../node_modules/nuxt/dist/app/nuxt')['useNuxtApp']>
     readonly useNuxtData: UnwrapRef<typeof import('../../node_modules/nuxt/dist/app/composables/asyncData')['useNuxtData']>
+    readonly useNuxtDevTools: UnwrapRef<typeof import('../../node_modules/@nuxt/devtools/dist/runtime/use-nuxt-devtools')['useNuxtDevTools']>
     readonly usePreviewMode: UnwrapRef<typeof import('../../node_modules/nuxt/dist/app/composables/preview')['usePreviewMode']>
     readonly useRequestEvent: UnwrapRef<typeof import('../../node_modules/nuxt/dist/app/composables/ssr')['useRequestEvent']>
     readonly useRequestFetch: UnwrapRef<typeof import('../../node_modules/nuxt/dist/app/composables/ssr')['useRequestFetch']>

+ 7 - 2
.nuxt/types/plugins.d.ts

@@ -9,12 +9,17 @@ type NuxtAppInjections =
   InjectionType<typeof import("../../node_modules/nuxt/dist/app/plugins/revive-payload.client.js")> &
   InjectionType<typeof import("../../node_modules/nuxt/dist/head/runtime/plugins/unhead.js")> &
   InjectionType<typeof import("../../node_modules/nuxt/dist/pages/runtime/plugins/router.js")> &
-  InjectionType<typeof import("../../node_modules/nuxt/dist/app/plugins/payload.client.js")> &
+  InjectionType<typeof import("../../node_modules/nuxt/dist/app/plugins/browser-devtools-timing.client.js")> &
   InjectionType<typeof import("../../node_modules/nuxt/dist/app/plugins/navigation-repaint.client.js")> &
   InjectionType<typeof import("../../node_modules/nuxt/dist/app/plugins/check-outdated-build.client.js")> &
   InjectionType<typeof import("../../node_modules/nuxt/dist/app/plugins/revive-payload.server.js")> &
   InjectionType<typeof import("../../node_modules/nuxt/dist/app/plugins/chunk-reload.client.js")> &
   InjectionType<typeof import("../../node_modules/nuxt/dist/pages/runtime/plugins/prefetch.client.js")> &
+  InjectionType<typeof import("../../node_modules/nuxt/dist/pages/runtime/plugins/check-if-page-unused.js")> &
+  InjectionType<typeof import("../../node_modules/@nuxt/devtools/dist/runtime/plugins/devtools.server.js")> &
+  InjectionType<typeof import("../../node_modules/@nuxt/devtools/dist/runtime/plugins/devtools.client.js")> &
+  InjectionType<typeof import("../../node_modules/nuxt/dist/app/plugins/dev-server-logs.js")> &
+  InjectionType<typeof import("../../node_modules/nuxt/dist/app/plugins/check-if-layout-used.js")> &
   InjectionType<typeof import("../../plugins/element-plus.js")> &
   InjectionType<typeof import("../../plugins/request.js")> &
   InjectionType<typeof import("../../plugins/category")> &
@@ -25,7 +30,7 @@ declare module '#app' {
   interface NuxtApp extends NuxtAppInjections { }
 
   interface NuxtAppLiterals {
-    pluginName: 'nuxt:revive-payload:client' | 'nuxt:head' | 'nuxt:router' | 'nuxt:payload' | 'nuxt:revive-payload:server' | 'nuxt:chunk-reload' | 'nuxt:global-components' | 'nuxt:prefetch'
+    pluginName: 'nuxt:revive-payload:client' | 'nuxt:head' | 'nuxt:router' | 'nuxt:browser-devtools-timing' | 'nuxt:revive-payload:server' | 'nuxt:chunk-reload' | 'nuxt:global-components' | 'nuxt:prefetch' | 'nuxt:checkIfPageUnused' | 'nuxt:checkIfLayoutUsed'
   }
 }
 

+ 4 - 8
components/home/PageMessage.vue

@@ -4,8 +4,8 @@
         <div class="inner">
             <div class="toutiao" v-if="headlinelist">
                 <div class="xwtt">
-                    <NuxtLink :href="getLinkPathDetail(item)" :title="item.title"
-                        :target="item.islink == 1 ? '_blank' : '_self'" v-for="(item, index) in headlinelist"
+                    <NuxtLink v-for="(item, index) in headlinelist" :href="getLinkPathDetail(item)" :title="item.title"
+                        :target="item.islink == 1 ? '_blank' : '_self'" 
                         :key="index">
                         <h1 class="tttitle">{{ item.title }}</h1>
                     </NuxtLink>
@@ -108,12 +108,8 @@ async function getModelData1() {
                 }
             }
         }
-        //填充大标题
-        // headlinelist.value.push(mkdata.data[0])
-        // //剩余的两条放到大标题下面
-        // headlinelist1.value.push(mkdata.data[1])
-        // headlinelist1.value.push(mkdata.data[2])
-        // headlinelist1.value.push(mkdata.data[3])
+        console.log("首页大标题:", headlinelist.value)
+        console.log("首页大标题下面的二级内容:", headlinelist1.value)
     } else {
         console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
         console.log("错误位置:设置大标题")

+ 79 - 0
middleware/setup.global.js

@@ -0,0 +1,79 @@
+export default async function (to, from) {
+    //获得全局url
+    const { $webUrl, $CwebUrl } = useNuxtApp();
+    if(to.path == '/' || to.path == '/404'){
+        //如果目标路由是/,或者/404 无需验证
+    }else{
+        // to是目标路由对象,from是来源路由对象
+        console.log('进入路由中间件,目标路由:', to.path,"当前路由:",from.path);
+        //拆分目标路由
+        let parts = parseRoute(to.path)
+        console.log(parts)
+
+        const responseRoute = await $fetch($webUrl + '/web/checkWebsiteRoute', {
+            headers: {
+                'Content-Type': 'application/json',
+                'Userurl': $CwebUrl,
+                'Origin': $CwebUrl
+            },
+            query: parts
+        })
+        console.log(responseRoute)
+        if(responseRoute.code == 200){
+            //如果路由存在,不做任何操作
+        }else{
+            return navigateTo('/404')
+        }
+    }
+}
+
+//提取路由
+function parseRoute(url) {
+    const parts = url.split('/').filter(Boolean); // 分割并过滤空字符串
+    const lastPart = parts[parts.length - 1];
+    
+    // 提取 id(数字.html 的数字部分)
+    const idMatch = lastPart.match(/^(\d+)\.html$/);
+    const id = idMatch ? idMatch[1] : undefined;
+    
+    // 如果最后是数字.html、index.html 或 list-数字.html,则去掉它
+    const isSpecialRoute = idMatch || lastPart === "index.html" || lastPart.startsWith("list-");
+    if (isSpecialRoute) {
+        parts.pop();
+    }
+    
+    let all_route, last_route;
+    
+    // 如果路径以 xiangcunshangcheng 开头
+    if (parts[0] === "xiangcunshangcheng") {
+        if( parts.length > 1){
+            if(parts[parts.length - 1] != 'gongying' && parts[parts.length - 1] != 'qiugou'){
+                // 否则按原逻辑处理
+                all_route = parts.join('/');
+                last_route = parts.length > 0 ? parts[parts.length - 1] : null;
+            }else{
+                // all_route = 去掉最后一层
+                all_route = parts.slice(0, -1).join('/');
+                // last_route = 新的最后一层
+                last_route = parts.length > 1 ? parts[parts.length - 2] : null;
+            }
+        }else{
+            // 否则按原逻辑处理
+            all_route = parts.join('/');
+            last_route = parts.length > 0 ? parts[parts.length - 1] : null;
+        }
+    } else {
+        // 否则按原逻辑处理
+        all_route = parts.join('/');
+        last_route = parts.length > 0 ? parts[parts.length - 1] : null;
+    }
+    // 返回结果(只有数字.html 时才包含 id)
+    const result = {
+        all_route,
+        last_route
+    };
+    if (id !== undefined) {
+        result.id = id;
+    }
+    return result;
+}