修改说明文件

merge-requests/1/head
ch 3 years ago
parent 38c2d3a412
commit f9aa2852ee

@ -1,69 +1,81 @@
<!--
* @Author: ch
* @Date: 2022-05-05 15:39:29
* @LastEditors: ch
* @LastEditTime: 2022-05-06 15:04:35
* @Description: file content
-->
# shop-pc # shop-pc
## Build Setup
```bash ## 环境变量配置
# install dependencies - 环境变量配置文件env.config;
$ npm install - 输出的环境变量文件plugins/config/env.js
- 修改环境变量配置后需要执行 “ node env.config " 输出的环境变量才会更新
``` js
// 直接引入输出的配置文件即可
import ENV from '@/plugins/config/env.js';
// 直接访问你在配置文件中定义的属性
console.log(ENV.baseUrl);
# serve with hot reload at localhost:3000
$ npm run dev
# build for production and launch server
$ npm run build
$ npm run start
# generate static project
$ npm run generate
``` ```
For detailed explanation on how things work, check out the [documentation](https://nuxtjs.org). ## 公共方法utils
- 公共方法统一放置utils文件夹内可以按分类建方法文件 如验证类verify.js 请求类request.js
## Special Directories - 所有公共方法采用大驼峰命名法
- 所有的方法都从index.js输出引入时统一引入index不允许直接引入方法文件
You can create the following extra directories, some of which have special behaviors. Only `pages` is required; you can delete them if you don't want to use their functionality. - 所有方法文件如果导出的是多个方法,不允许在定义方法时导出,必须在文件底部一一导出,并附上方法简单的注释
``` js
### `assets` // 正确
import {Req, IsPhone} from '@/common/utils';
The assets directory contains your uncompiled assets such as Stylus or Sass files, images, or fonts.
// 错误
More information about the usage of this directory in [the documentation](https://nuxtjs.org/docs/2.x/directory-structure/assets). import {Req} from '@/common/utils/request';
import {IsPhone} from '@/common/utils/utils';
### `components`
// 正确
The components directory contains your Vue.js components. Components make up the different parts of your page and can be reused and imported into your pages, layouts and even other components. const IsPhone = (str) => {....}
const IsEmail = (str) => {....}
More information about the usage of this directory in [the documentation](https://nuxtjs.org/docs/2.x/directory-structure/components). export {
// 判断手机号
### `layouts` IsPhone,
// 判断邮箱
Layouts are a great help when you want to change the look and feel of your Nuxt app, whether you want to include a sidebar or have distinct layouts for mobile and desktop. IsEmail
}
More information about the usage of this directory in [the documentation](https://nuxtjs.org/docs/2.x/directory-structure/layouts). ```
## 组件
- 根目录的components 只放置真正的组件某个页面的业务模块应该在pages的相应目录下新建module目录放置
### `pages` - 所有的自定义组件文件名以大驼峰命名且在templet中使用也用大驼峰形式使用(包括页面内的模块组件)
This directory contains your application views and routes. Nuxt will read all the `*.vue` files inside this directory and setup Vue Router automatically. ## storage的使用
- 不要在页面内直接使用loaclStorage全都放置到vuex中做一次管理
More information about the usage of this directory in [the documentation](https://nuxtjs.org/docs/2.x/get-started/routing).
### `plugins` ## 请求
- 所有请求方法命名以Api+请求类型+具体方) 法命名
The plugins directory contains JavaScript plugins that you want to run before instantiating the root Vue.js Application. This is the place to add Vue plugins and to inject functions or constants. Every time you need to use `Vue.use()`, you should create a file in `plugins/` and add its path to plugins in `nuxt.config.js`. - 所有请求使用ToAsyncAwait 包裹
- 不允许使用try catch 和 then 处理返回结果
More information about the usage of this directory in [the documentation](https://nuxtjs.org/docs/2.x/directory-structure/plugins). ``` js
// 使用示例
### `static` // xxapi.js
import {ToAsyncAwait, ReqestTk} from '@/common/utils'
This directory contains your static files. Each file inside this directory is mapped to `/`. const ApiGetUserInfo = (parapms) => ToAsyncAwait(ReqestTk.get('xxxxUrl',{params}));
exprot {
Example: `/static/robots.txt` is mapped as `/robots.txt`. // 获取用户信息
ApiGetUserInfo
More information about the usage of this directory in [the documentation](https://nuxtjs.org/docs/2.x/directory-structure/static). }
// user.vue
### `store` improt {ApiGetUserInfo} from '@/common/api/xxapi.js';
This directory contains your Vuex store files. Creating a file in this directory automatically activates Vuex. const getUserInfo = async () =>{
const {error, result} = await ApiGetUserInfo();
if(error){
alert(error);
return false;
}
app.userInfo = result;
}
More information about the usage of this directory in [the documentation](https://nuxtjs.org/docs/2.x/directory-structure/store). ```
## css
- 采用BEM命名法

@ -2,8 +2,9 @@
* @Author: ch * @Author: ch
* @Date: 2022-05-05 14:40:00 * @Date: 2022-05-05 14:40:00
* @LastEditors: ch * @LastEditors: ch
* @LastEditTime: 2022-05-05 15:40:42 * @LastEditTime: 2022-05-05 17:53:47
* @Description: 根据git分支生成对应环境的环境变量 * @Description: 根据git分支生成对应环境的环境变量
* 开发时如果环境变量换了可以不用重启服务直接运行node env.config.js即可
*/ */
const fs = require('fs'); const fs = require('fs');
const path = require('path'); const path = require('path');
@ -11,7 +12,6 @@ const getRepoInfo = require('git-repo-info');
const envConfig = { const envConfig = {
dev : { dev : {
base_url: 'dev' base_url: 'dev'
}, },
test : { test : {
@ -19,14 +19,12 @@ const envConfig = {
}, },
reslese : { reslese : {
base_url: 'xxx' base_url: 'xxx'
}, },
prod : { prod : {
base_url: 'xxx'
} }
} }
const branch = getRepoInfo().branch; // 调用获取git信息 const branch = getRepoInfo().branch; // 调用获取git信息
const argv = global.process.argv;
let curEnvConfig = {}; let curEnvConfig = {};
switch (branch){ switch (branch){
case 'msb_test': case 'msb_test':
@ -43,5 +41,5 @@ switch (branch){
break; break;
} }
let codeStr = `const ENV = ${JSON.stringify(curEnvConfig)}; export default ENV;`; fs.writeFileSync(`${path.resolve(__dirname, './plugins/config')}/env.js`,
fs.writeFileSync(`${path.resolve(__dirname, './plugins')}/env.js`, codeStr); `const ENV = ${JSON.stringify(curEnvConfig)}; export default ENV;`);

@ -1,9 +0,0 @@
/*
* @Author: ch
* @Date: 2022-05-04 21:02:38
* @LastEditors: ch
* @LastEditTime: 2022-05-04 21:03:14
* @Description: file content
*/
const LOCAL_BASE = 'msbPc:';
export const TOKEN = `${LOCAL_BASE}tk`;

@ -0,0 +1,9 @@
/*
* @Author: ch
* @Date: 2022-05-04 21:02:38
* @LastEditors: ch
* @LastEditTime: 2022-05-05 15:53:40
* @Description: file content
*/
const STORAGE_BASE = 'msbPc:';
export const TOKEN = `${STORAGE_BASE}tk`;
Loading…
Cancel
Save