From 44463a89e097e6f3920779ca396459e223417bf3 Mon Sep 17 00:00:00 2001 From: shenhan Date: Fri, 17 Jan 2025 17:28:08 +0800 Subject: [PATCH] update --- .gitignore | 8 + .npmrc | 4 + .stackblitzrc | 4 + .vscode/extensions.json | 10 + .vscode/settings.json | 45 + LICENSE | 21 + README.md | 80 + app/api/common.ts | 21 + app/api/index.ts | 4 + app/api/user.ts | 36 + app/app.vue | 47 + app/components/DarkToggle.vue | 21 + app/components/Footer.vue | 7 + app/components/GlobalConfig.vue | 18 + app/components/LoginModal.vue | 125 + app/composables/count.ts | 16 + app/config/pwa.ts | 79 + app/constants/index.ts | 2 + app/layouts/README.md | 15 + app/layouts/default.vue | 245 + app/layouts/header.vue | 232 + app/layouts/home.vue | 137 + app/middleware/auth.global.ts | 28 + app/pages/Independent-page/index.vue | 156 + app/pages/[...all].vue | 17 + app/pages/index.vue | 42 + app/pages/member-center/index.vue | 55 + app/pages/model-square.vue | 12 + app/pages/publishDetails/[id].vue | 48 + app/pages/web-ui/index.vue | 215 + app/plugins/naive-ui.ts | 40 + app/stores/menu.ts | 29 + app/stores/modal.ts | 38 + app/stores/user.ts | 39 + app/types/api.ts | 18 + app/types/request.ts | 19 + app/utils/error.ts | 36 + app/utils/request.ts | 149 + eslint.config.js | 12 + netlify.toml | 11 + nuxt.config.ts | 109 + package.json | 55 + pnpm-lock.yaml | 11683 ++++++++++++++++ public/apple-touch-icon.png | Bin 0 -> 3038 bytes public/favicon.ico | Bin 0 -> 15086 bytes public/maskable-icon.png | Bin 0 -> 4571 bytes public/nuxt.svg | 3 + public/pwa-192x192.png | Bin 0 -> 3243 bytes public/pwa-512x512.png | Bin 0 -> 7206 bytes public/robots.txt | 2 + public/vite.png | Bin 0 -> 3498 bytes server/api/pageview.ts | 7 + server/tsconfig.json | 3 + tailwind.config.js | 45 + tsconfig.json | 8 + ...1-fae2346e178ea50e0c92bca7744e68e6fe0b45d9 | 1 + 56 files changed, 14057 insertions(+) create mode 100644 .gitignore create mode 100644 .npmrc create mode 100644 .stackblitzrc create mode 100644 .vscode/extensions.json create mode 100644 .vscode/settings.json create mode 100644 LICENSE create mode 100644 README.md create mode 100644 app/api/common.ts create mode 100644 app/api/index.ts create mode 100644 app/api/user.ts create mode 100644 app/app.vue create mode 100644 app/components/DarkToggle.vue create mode 100644 app/components/Footer.vue create mode 100644 app/components/GlobalConfig.vue create mode 100644 app/components/LoginModal.vue create mode 100644 app/composables/count.ts create mode 100644 app/config/pwa.ts create mode 100644 app/constants/index.ts create mode 100644 app/layouts/README.md create mode 100644 app/layouts/default.vue create mode 100644 app/layouts/header.vue create mode 100644 app/layouts/home.vue create mode 100644 app/middleware/auth.global.ts create mode 100644 app/pages/Independent-page/index.vue create mode 100644 app/pages/[...all].vue create mode 100644 app/pages/index.vue create mode 100644 app/pages/member-center/index.vue create mode 100644 app/pages/model-square.vue create mode 100644 app/pages/publishDetails/[id].vue create mode 100644 app/pages/web-ui/index.vue create mode 100644 app/plugins/naive-ui.ts create mode 100644 app/stores/menu.ts create mode 100644 app/stores/modal.ts create mode 100644 app/stores/user.ts create mode 100644 app/types/api.ts create mode 100644 app/types/request.ts create mode 100644 app/utils/error.ts create mode 100644 app/utils/request.ts create mode 100644 eslint.config.js create mode 100755 netlify.toml create mode 100644 nuxt.config.ts create mode 100644 package.json create mode 100644 pnpm-lock.yaml create mode 100644 public/apple-touch-icon.png create mode 100644 public/favicon.ico create mode 100644 public/maskable-icon.png create mode 100644 public/nuxt.svg create mode 100644 public/pwa-192x192.png create mode 100644 public/pwa-512x512.png create mode 100644 public/robots.txt create mode 100644 public/vite.png create mode 100644 server/api/pageview.ts create mode 100644 server/tsconfig.json create mode 100644 tailwind.config.js create mode 100644 tsconfig.json create mode 100644 tsx-0/17371-fae2346e178ea50e0c92bca7744e68e6fe0b45d9 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..86a4f46 --- /dev/null +++ b/.gitignore @@ -0,0 +1,8 @@ +node_modules +*.log +dist +.output +.nuxt +.env +.idea/ +public/assets/fonts diff --git a/.npmrc b/.npmrc new file mode 100644 index 0000000..5eda00a --- /dev/null +++ b/.npmrc @@ -0,0 +1,4 @@ +shamefully-hoist=true +strict-peer-dependencies=false +shell-emulator=true +auto-install-peers=false diff --git a/.stackblitzrc b/.stackblitzrc new file mode 100644 index 0000000..d98146f --- /dev/null +++ b/.stackblitzrc @@ -0,0 +1,4 @@ +{ + "installDependencies": true, + "startCommand": "npm run dev" +} diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..4a2da08 --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,10 @@ +{ + "recommendations": [ + "antfu.iconify", + "antfu.unocss", + "antfu.goto-alias", + "csstools.postcss", + "dbaeumer.vscode-eslint", + "vue.volar" + ] +} diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..e099f81 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,45 @@ +{ + "files.associations": { + "*.css": "postcss" + }, + + // Disable the default formatter, use eslint instead + "prettier.enable": false, + "editor.formatOnSave": false, + + // Auto fix + "editor.codeActionsOnSave": { + "source.fixAll.eslint": "explicit", + "source.organizeImports": "never" + }, + + // Silent the stylistic rules in you IDE, but still auto fix them + "eslint.rules.customizations": [ + { "rule": "style/*", "severity": "off" }, + { "rule": "*-indent", "severity": "off" }, + { "rule": "*-spacing", "severity": "off" }, + { "rule": "*-spaces", "severity": "off" }, + { "rule": "*-order", "severity": "off" }, + { "rule": "*-dangle", "severity": "off" }, + { "rule": "*-newline", "severity": "off" }, + { "rule": "*quotes", "severity": "off" }, + { "rule": "*semi", "severity": "off" } + ], + + // Enable eslint for all supported languages + "eslint.validate": [ + "javascript", + "javascriptreact", + "typescript", + "typescriptreact", + "vue", + "html", + "markdown", + "json", + "jsonc", + "yaml" + ], + "interline-translate.knownPopularWordCount": 6000, + "iconify.annotations": true, + "iconify.inplace": true +} diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..6a0c70b --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2021-PRESENT Anthony Fu + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..459296c --- /dev/null +++ b/README.md @@ -0,0 +1,80 @@ +

+ +

+ +

+Vitesse for Nuxt 3 +


+ +

+
+🖥 Online Preview +

+ +

+ +## Features + +- 💚 [Nuxt 3](https://nuxt.com/) - SSR, ESR, File-based routing, components auto importing, modules, etc. + +- ⚡️ Vite - Instant HMR. + +- 🎨 [UnoCSS](https://github.com/unocss/unocss) - The instant on-demand atomic CSS engine. + +- 😃 Use icons from any icon sets in Pure CSS, powered by [UnoCSS](https://github.com/unocss/unocss). + +- 🔥 The ` + + + + \ No newline at end of file diff --git a/app/components/DarkToggle.vue b/app/components/DarkToggle.vue new file mode 100644 index 0000000..abcacc4 --- /dev/null +++ b/app/components/DarkToggle.vue @@ -0,0 +1,21 @@ + + + diff --git a/app/components/Footer.vue b/app/components/Footer.vue new file mode 100644 index 0000000..f7bb519 --- /dev/null +++ b/app/components/Footer.vue @@ -0,0 +1,7 @@ + diff --git a/app/components/GlobalConfig.vue b/app/components/GlobalConfig.vue new file mode 100644 index 0000000..244355f --- /dev/null +++ b/app/components/GlobalConfig.vue @@ -0,0 +1,18 @@ + + + \ No newline at end of file diff --git a/app/components/LoginModal.vue b/app/components/LoginModal.vue new file mode 100644 index 0000000..db31771 --- /dev/null +++ b/app/components/LoginModal.vue @@ -0,0 +1,125 @@ + + + + \ No newline at end of file diff --git a/app/composables/count.ts b/app/composables/count.ts new file mode 100644 index 0000000..6122453 --- /dev/null +++ b/app/composables/count.ts @@ -0,0 +1,16 @@ +export function useCount() { + const count = useState('count', () => Math.round(Math.random() * 20)) + + function inc() { + count.value += 1 + } + function dec() { + count.value -= 1 + } + + return { + count, + inc, + dec, + } +} diff --git a/app/config/pwa.ts b/app/config/pwa.ts new file mode 100644 index 0000000..5133b1e --- /dev/null +++ b/app/config/pwa.ts @@ -0,0 +1,79 @@ +import type { ModuleOptions } from '@vite-pwa/nuxt' +import process from 'node:process' +import { appDescription, appName } from '../constants/index' + +const scope = '/' + +export const pwa: ModuleOptions = { + registerType: 'autoUpdate', + scope, + base: scope, + manifest: { + id: scope, + scope, + name: appName, + short_name: appName, + description: appDescription, + theme_color: '#ffffff', + icons: [ + { + src: 'pwa-192x192.png', + sizes: '192x192', + type: 'image/png', + }, + { + src: 'pwa-512x512.png', + sizes: '512x512', + type: 'image/png', + }, + { + src: 'maskable-icon.png', + sizes: '512x512', + type: 'image/png', + purpose: 'any maskable', + }, + ], + }, + workbox: { + globPatterns: ['**/*.{js,css,html,txt,png,ico,svg}'], + navigateFallbackDenylist: [/^\/api\//], + navigateFallback: '/', + cleanupOutdatedCaches: true, + runtimeCaching: [ + { + urlPattern: /^https:\/\/fonts.googleapis.com\/.*/i, + handler: 'CacheFirst', + options: { + cacheName: 'google-fonts-cache', + expiration: { + maxEntries: 10, + maxAgeSeconds: 60 * 60 * 24 * 365, // <== 365 days + }, + cacheableResponse: { + statuses: [0, 200], + }, + }, + }, + { + urlPattern: /^https:\/\/fonts.gstatic.com\/.*/i, + handler: 'CacheFirst', + options: { + cacheName: 'gstatic-fonts-cache', + expiration: { + maxEntries: 10, + maxAgeSeconds: 60 * 60 * 24 * 365, // <== 365 days + }, + cacheableResponse: { + statuses: [0, 200], + }, + }, + }, + ], + }, + registerWebManifestInRouteRules: true, + writePlugin: true, + devOptions: { + enabled: process.env.VITE_PLUGIN_PWA === 'true', + navigateFallback: scope, + }, +} diff --git a/app/constants/index.ts b/app/constants/index.ts new file mode 100644 index 0000000..3fc9c84 --- /dev/null +++ b/app/constants/index.ts @@ -0,0 +1,2 @@ +export const appName = '魔创未来' +export const appDescription = '魔创未来' diff --git a/app/layouts/README.md b/app/layouts/README.md new file mode 100644 index 0000000..0adc860 --- /dev/null +++ b/app/layouts/README.md @@ -0,0 +1,15 @@ +## Layouts + +Vue components in this dir are used as layouts. + +By default, `default.vue` will be used unless an alternative is specified in the route meta. + +```vue + +``` + +Learn more on https://nuxt.com/docs/guide/directory-structure/layouts diff --git a/app/layouts/default.vue b/app/layouts/default.vue new file mode 100644 index 0000000..ab403b8 --- /dev/null +++ b/app/layouts/default.vue @@ -0,0 +1,245 @@ + + + + + \ No newline at end of file diff --git a/app/layouts/header.vue b/app/layouts/header.vue new file mode 100644 index 0000000..b699987 --- /dev/null +++ b/app/layouts/header.vue @@ -0,0 +1,232 @@ + + + + + \ No newline at end of file diff --git a/app/layouts/home.vue b/app/layouts/home.vue new file mode 100644 index 0000000..19f9ba0 --- /dev/null +++ b/app/layouts/home.vue @@ -0,0 +1,137 @@ + + + + + \ No newline at end of file diff --git a/app/middleware/auth.global.ts b/app/middleware/auth.global.ts new file mode 100644 index 0000000..f433a4f --- /dev/null +++ b/app/middleware/auth.global.ts @@ -0,0 +1,28 @@ +// middleware/auth.ts + +/** + * 全局认证中间件 + * 用于处理需要登录才能访问的路由 + * 如果用户未登录,将显示登录框并重定向到模型广场 + * + * @param to - 目标路由对象 + * @returns void | NavigationResult - 如果需要重定向则返回导航结果 + */ +export default defineNuxtRouteMiddleware((to) => { + const userStore = useUserStore() + const modalStore = useModalStore() + + // 需要登录权限的路由列表 + const authRoutes = [ + '/high-availability', + // 可以继续添加其他需要登录的路由 + ] + + // 如果是需要登录的路由,且用户未登录 + if (authRoutes.includes(to.path) && !userStore.isLoggedIn) { + // 显示登录模态框 + modalStore.showLoginModal() + // 重定向到模型广场页面 + return navigateTo('/model-square') + } +}) \ No newline at end of file diff --git a/app/pages/Independent-page/index.vue b/app/pages/Independent-page/index.vue new file mode 100644 index 0000000..0a13060 --- /dev/null +++ b/app/pages/Independent-page/index.vue @@ -0,0 +1,156 @@ + + + + + \ No newline at end of file diff --git a/app/pages/[...all].vue b/app/pages/[...all].vue new file mode 100644 index 0000000..bce9733 --- /dev/null +++ b/app/pages/[...all].vue @@ -0,0 +1,17 @@ + + + diff --git a/app/pages/index.vue b/app/pages/index.vue new file mode 100644 index 0000000..ac96f36 --- /dev/null +++ b/app/pages/index.vue @@ -0,0 +1,42 @@ + + + diff --git a/app/pages/member-center/index.vue b/app/pages/member-center/index.vue new file mode 100644 index 0000000..62337ba --- /dev/null +++ b/app/pages/member-center/index.vue @@ -0,0 +1,55 @@ + + + + + \ No newline at end of file diff --git a/app/pages/model-square.vue b/app/pages/model-square.vue new file mode 100644 index 0000000..1146f9e --- /dev/null +++ b/app/pages/model-square.vue @@ -0,0 +1,12 @@ + + + \ No newline at end of file diff --git a/app/pages/publishDetails/[id].vue b/app/pages/publishDetails/[id].vue new file mode 100644 index 0000000..2cdcc64 --- /dev/null +++ b/app/pages/publishDetails/[id].vue @@ -0,0 +1,48 @@ + + + diff --git a/app/pages/web-ui/index.vue b/app/pages/web-ui/index.vue new file mode 100644 index 0000000..ca3ed66 --- /dev/null +++ b/app/pages/web-ui/index.vue @@ -0,0 +1,215 @@ + + + + + \ No newline at end of file diff --git a/app/plugins/naive-ui.ts b/app/plugins/naive-ui.ts new file mode 100644 index 0000000..f116856 --- /dev/null +++ b/app/plugins/naive-ui.ts @@ -0,0 +1,40 @@ +import { setup } from '@css-render/vue3-ssr' +import { defineNuxtPlugin } from '#app' + +export default defineNuxtPlugin((nuxtApp) => { + if (process.server) { + const { collect } = setup(nuxtApp.vueApp) + const originalRenderMeta = nuxtApp.ssrContext?.renderMeta + nuxtApp.ssrContext!.renderMeta = () => { + if (!originalRenderMeta) { + return { + headTags: collect() + } + } + const originalMeta = originalRenderMeta() + if ('headTags' in originalMeta) { + originalMeta.headTags += collect() + } else { + originalMeta.headTags = collect() + } + return originalMeta + } + } + + const { collect } = setup(nuxtApp.vueApp) + useServerHead({ + style: () => { + const stylesString = collect() + const stylesArray = stylesString.split(/<\/style>/g).filter(style => style) + return stylesArray.map((styleString: string) => { + const match = styleString.match(/