diff --git a/.env b/.env index 2969d73..6b96cba 100644 --- a/.env +++ b/.env @@ -1,2 +1,4 @@ -VITE_BASE_URL='' #接口地址 -VITE_ASSETSURL='https://cdn.vrupup.com/s/1598/assets/' #资源地址 \ No newline at end of file +VITE_BASE_URL= #接口地址 +VITE_ASSETSURL=https://cdn.vrupup.com/s/1598/assets/ #资源地址 +VITE_APPID=wx9cb717d8151d8486 #小程序APPID +VITE_UNI_APPID=_UNI_8842336 #UNI-APPID \ No newline at end of file diff --git a/IFLOW.md b/IFLOW.md index 8c6c87c..87fb84d 100644 --- a/IFLOW.md +++ b/IFLOW.md @@ -8,6 +8,7 @@ * **Vue3**: 渐进式 JavaScript 框架,用于构建用户界面。 * **uView-Plus**: 基于 UniApp 的 UI 组件库。 * **z-paging**: 一个用于处理分页加载的组件库。 +* **Vuex**: 状态管理库。 ## 目录结构 @@ -21,13 +22,17 @@ │ │ ├── common.css # codefun原子类样式 │ │ └── base.scss # 全局样式变量 │ └── utils/ # 工具函数 +│ └── tool.ts # 常用工具函数 ├── components/ # 公共组件 ├── uni_modules/ # uni-app 组件 +│ └── z-paging/ # 分页组件库 ├── lib/ # 第三方库 │ └── luch-request/ # luch-request 网络请求库 ├── uview-plus/ # uView-Plus 组件库 ├── mixins/ # Vue 混入 +│ └── global.ts # 全局混入 ├── store/ # 状态管理 +│ └── index.ts # Vuex store ├── pages/ # 主包页面 ├── subPages/ # 分包页面 ├── App.vue # 应用入口 @@ -36,6 +41,7 @@ ├── manifest.json # 应用配置 ├── uni.scss # 全局样式变量 ├── vite.config.js # Vite 编译配置 +├── .nvmdrc # Node.js 版本要求 └── .env # 环境变量 ``` @@ -43,7 +49,7 @@ ## 环境要求 -* Node.js (版本信息在 `.nvmdrc` 文件中指定) +* Node.js (版本信息在 `.nvmdrc` 文件中指定,当前为 20.0.0) * npm 或 yarn ## 安装依赖 @@ -64,8 +70,9 @@ npm install ## 样式 -* 全局样式文件位于 `common/styles/` 目录下,包括 `common.css` 和 `normal.scss`。 -* 样式优先使用codefun原子类样式。 +* 全局样式文件位于 `common/styles/` 目录下,包括 `common.css` 和 `base.scss`。 +* `common.css` 提供了codefun原子类样式,用于快速布局。 +* `base.scss` 提供了SCSS变量和mixins,以及常用的样式类生成器。 * 样式规范应遵循项目中已有的风格。 ## JavaScript @@ -97,7 +104,7 @@ npm install * **提示与加载**: `alert`, `loading`, `hideLoading` * **页面跳转**: `navigateTo`, `redirectTo`, `reLaunch`, `switchTab`, `navigateBack` * **本地存储**: `storage`, `removeStorage`, `getStorageInfo` -* **其他功能**: `copy` (复制文本), `saveImageToPhotos` (保存图片), `requestPayment` (微信支付), `upload` (文件上传) +* **其他功能**: `copy` (复制文本), `saveImageToPhotos` (保存图片), `requestPayment` (微信支付), `upload` (文件上传), `loadFont` (加载字体) ## 网络请求 @@ -109,7 +116,7 @@ npm install ## 组件 * 项目集成了 `uView-Plus` 和 `z-paging` 两个组件库,组件均已全局导入,可以直接使用。 -* `uView-Plus` 组件的使用方式是 `u-icon`、`u-input`、`u-textarea`。 +* `uView-Plus` 组件已通过 `easycom` 自动导入,可以直接使用,如:``、``。 * 全局组件放在 `components/` 目录下。 * 页面独立组件放在页面根目录下的 `components/`。 * 每个组件应该附带 `README.MD` 文档。 @@ -119,4 +126,5 @@ npm install * 页面配置在 `pages.json` 中管理。 * 主包页面放在 `pages/` 目录下,分包页面放在 `subPages/` 目录下。 +* 页面使用 Composition API (setup语法糖) 编写。 * 注释、结构规范应遵循项目中已有的风格。 \ No newline at end of file diff --git a/manifest.json b/manifest.json index 6da07ea..03fbc66 100644 --- a/manifest.json +++ b/manifest.json @@ -1,5 +1,5 @@ { - "name" : "", + "name" : "template", "appid" : "", "description" : "", "versionName" : "1.0.0", diff --git a/vite.config.js b/vite.config.js index 9081083..9fb8f66 100644 --- a/vite.config.js +++ b/vite.config.js @@ -1,9 +1,47 @@ import { defineConfig } from 'vite' import uni from '@dcloudio/vite-plugin-uni' -import { configDotenv } from 'dotenv' +import { resolve } from 'path' +import { readFileSync, writeFileSync } from 'fs' +import dotenv from 'dotenv' + +// 自定义插件:替换 manifest.json 中的 appid +function replaceManifestAppid() { + return { + name: 'replace-manifest-appid', + buildStart() { + // 获取环境变量,明确指定路径为项目根目录 + dotenv.config({ path: resolve(__dirname, '.env') }) + const appid = process.env.VITE_APPID + const uni_appId = process.env.VITE_UNI_APPID + + if (appid && uni_appId) { + // 读取 manifest.json 文件 + const manifestPath = resolve(__dirname, 'manifest.json') + let manifestContent = readFileSync(manifestPath, 'utf-8') + + // 解析 JSON + const manifest = JSON.parse(manifestContent) + + // 替换 + manifest.appid = uni_appId + if (manifest['mp-weixin']) { + manifest['mp-weixin'].appid = appid + } + + // 写回文件 + writeFileSync(manifestPath, JSON.stringify(manifest, null, 4)) + + console.log(`Manifest appid 已更新为: ${uni_appId}`) + console.log(`Manifest mp-weixin appid 已更新为: ${appid}`) + } else { + console.warn('未找到 VITE_APPID 和 VITE_UNI_APPID 环境变量,使用默认值') + } + }, + } +} export default defineConfig({ - plugins: [uni(), configDotenv()], + plugins: [replaceManifestAppid(), uni()], build: { minify: 'terser', terserOptions: {