diff --git a/build/vite/plugin/index.ts b/build/vite/plugin/index.ts index c3da978..71bf858 100644 --- a/build/vite/plugin/index.ts +++ b/build/vite/plugin/index.ts @@ -20,6 +20,8 @@ export function createVitePlugins(viteEnv: ViteEnv, isBuild: boolean) { vue(), // 按需引入VantUi且自动创建组件声明 Components({ + // 共享组件目录(移动端使用;PC 端独立,不扫描此处) + dirs: ['src/shared/components'], dts: true, resolvers: [VantResolver()], types: [], diff --git a/build/vite/plugin/svgSprite.ts b/build/vite/plugin/svgSprite.ts index 3e2680a..7598be4 100644 --- a/build/vite/plugin/svgSprite.ts +++ b/build/vite/plugin/svgSprite.ts @@ -9,7 +9,7 @@ import { createSvgIconsPlugin } from 'vite-plugin-svg-icons' export function configSvgIconsPlugin(isBuild: boolean) { // 指定需要缓存的图标文件夹 const svgIconsPlugin = createSvgIconsPlugin({ - iconDirs: [path.resolve(process.cwd(), 'src/assets/icons')], + iconDirs: [path.resolve(process.cwd(), 'src/shared/assets/icons')], // 是否压缩 svgoOptions: isBuild, // 指定symbolId格式 diff --git a/index.html b/index.html index df28d73..c9ed537 100644 --- a/index.html +++ b/index.html @@ -10,6 +10,22 @@
diff --git a/postcss.config.js b/postcss.config.js index 1fbbd19..6e5cc47 100644 --- a/postcss.config.js +++ b/postcss.config.js @@ -45,8 +45,9 @@ export default { autoprefixer(), viewport({ ...baseViewportOpts, - // 只将 vant 转为 375 设计稿的 viewport,其它样式的视图宽度为 750 - // viewportWidth: file => (file.includes('node_modules/vant/') ? 375 : 750), + // PC 端源码不转 vw:PC 页面用 scoped 原生 px + 媒体查询写样式 + // 见 AGENTS.md「PC/移动端双端支持」约束 + exclude: [/src\/pc\//], }), ], } diff --git a/src/main.ts b/src/main.ts index f8cd5d0..f90d027 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,40 +1,23 @@ -import { createApp } from 'vue' -import { setupStore } from '@/store' -import { useDesignSettingWithOut } from '@/store/modules/designSetting' -import App from './App.vue' -import router, { setupRouter } from './router' +import { createMobileApp } from '@/mobile/app' +import { createPCApp } from '@/pc/app' +// UnoCSS 全局样式与重置在入口统一导入一次,PC/移动端共用 import 'virtual:uno.css' - -import 'vant/es/toast/style' - -import 'vant/es/dialog/style' -import 'vant/es/notify/style' -import 'vant/es/image-preview/style' // https://unocss.dev/guide/style-reset#tailwind-compat -// 此重置基于 Tailwind 重置,减去按钮的背景颜色覆盖,以避免与 UI 框架发生冲突。请参阅链接的问题。 +// 此重置基于 Tailwind 重置,减去按钮的背景颜色覆盖,以避免与 UI 框架发生冲突。 import '@unocss/reset/tailwind-compat.css' -// Register icon sprite -import 'virtual:svg-icons-register' - -// 开发环境启用 vconsole 移动端调试面板(由 VITE_V_CONSOLE 控制,默认开启) -if (import.meta.env.DEV && import.meta.env.VITE_V_CONSOLE !== 'false') { - import('vconsole').then(({ default: VConsole }) => { - // eslint-disable-next-line no-new -- vconsole 以副作用方式实例化以挂载调试面板 - new VConsole() - }) -} +/** + * 应用入口分发器 + * + * 由 index.html 内联脚本在 Vue 挂载前写入 window.__DEVICE__('pc' | 'mobile'), + * 此处据此挂载对应应用,首屏即为正确设备 UI,无重定向、无布局闪烁。 + * - mobile → 挂载到 #app(受 postcss-mobile-forever 限宽 600px 居中) + * - pc → 挂载到 #pc-app(全宽,px 不被转 vw) + */ async function bootstrap() { - const app = createApp(App) - // 挂载状态管理 - setupStore(app) - // 初始化全局主题:跟随系统 prefers-color-scheme(不支持手动修改) - useDesignSettingWithOut().initSystemListener() - // 挂载路由 - setupRouter(app) - await router.isReady() - // 路由准备就绪后挂载APP实例 - app.mount('#app', true) + const isPC = window.__DEVICE__ === 'pc' + const app = isPC ? await createPCApp() : await createMobileApp() + app.mount(isPC ? '#pc-app' : '#app', true) } void bootstrap() diff --git a/src/App.vue b/src/mobile/App.vue similarity index 91% rename from src/App.vue rename to src/mobile/App.vue index 445958a..e4c478a 100644 --- a/src/App.vue +++ b/src/mobile/App.vue @@ -1,7 +1,7 @@ + + diff --git a/src/pc/app.ts b/src/pc/app.ts new file mode 100644 index 0000000..cf618be --- /dev/null +++ b/src/pc/app.ts @@ -0,0 +1,32 @@ +import type { App } from 'vue' +import { createPinia } from 'pinia' +import piniaPluginPersistedstate from 'pinia-plugin-persistedstate' +import { createApp } from 'vue' +import PcApp from '@/pc/App.vue' +import { pcRouter, setupPCRouter } from '@/pc/router' + +// PC 端独立的 pinia 实例(与移动端状态隔离,同一时刻仅一套应用运行) +const pcStore = createPinia() +pcStore.use(piniaPluginPersistedstate) + +function setupPCStore(app: App) { + app.use(pcStore) +} + +/** + * 创建 PC 端应用实例 + * + * 挂载点:#pc-app(独立于 #app,不受 postcss-mobile-forever 的 appSelector 限宽影响) + * + * 样式约束:PC 页面所有尺寸用 scoped diff --git a/src/pc/router/index.ts b/src/pc/router/index.ts new file mode 100644 index 0000000..4743538 --- /dev/null +++ b/src/pc/router/index.ts @@ -0,0 +1,32 @@ +import type { App } from 'vue' +import type { RouteRecordRaw } from 'vue-router' +import { createRouter, createWebHistory } from 'vue-router' + +// PC 端路由树(独立于移动端,按需在此扩展业务路由,例如收银台 PC 版) +// 内页(收银台等)建议套 PcLayout;首页为全屏独立页,贴合移动端首页视觉 +const routes: RouteRecordRaw[] = [ + { + path: '/', + name: 'PcHome', + component: () => import('@/pc/views/Home.vue'), + }, + // 兜底:移动端专属路径(如 /home/index)或任何未匹配路径,渲染 PC 404 页 + // 用 component 而非 redirect——vue-router 5 下 catch-all + redirect 在初始导航不触发 + { + path: '/:pathMatch(.*)*', + name: 'PcNotFound', + component: () => import('@/pc/views/NotFound.vue'), + }, +] + +const pcRouter = createRouter({ + history: createWebHistory(import.meta.env.BASE_URL), + routes, + scrollBehavior: () => ({ left: 0, top: 0 }), +}) + +export function setupPCRouter(app: App) { + app.use(pcRouter) +} + +export { pcRouter } diff --git a/src/pc/views/Home.vue b/src/pc/views/Home.vue new file mode 100644 index 0000000..acc565f --- /dev/null +++ b/src/pc/views/Home.vue @@ -0,0 +1,89 @@ + + + + + diff --git a/src/pc/views/NotFound.vue b/src/pc/views/NotFound.vue new file mode 100644 index 0000000..d1ebad2 --- /dev/null +++ b/src/pc/views/NotFound.vue @@ -0,0 +1,80 @@ + + + + + diff --git a/src/assets/icons/exception/403.svg b/src/shared/assets/icons/exception/403.svg similarity index 100% rename from src/assets/icons/exception/403.svg rename to src/shared/assets/icons/exception/403.svg diff --git a/src/assets/icons/exception/404.svg b/src/shared/assets/icons/exception/404.svg similarity index 100% rename from src/assets/icons/exception/404.svg rename to src/shared/assets/icons/exception/404.svg diff --git a/src/assets/icons/exception/500.svg b/src/shared/assets/icons/exception/500.svg similarity index 100% rename from src/assets/icons/exception/500.svg rename to src/shared/assets/icons/exception/500.svg diff --git a/src/assets/icons/logo.svg b/src/shared/assets/icons/logo.svg similarity index 100% rename from src/assets/icons/logo.svg rename to src/shared/assets/icons/logo.svg diff --git a/src/components/Logo.vue b/src/shared/components/Logo.vue similarity index 94% rename from src/components/Logo.vue rename to src/shared/components/Logo.vue index 6e379ee..4dc5fbd 100644 --- a/src/components/Logo.vue +++ b/src/shared/components/Logo.vue @@ -1,7 +1,7 @@