Skip to content

Commit ff070de

Browse files
author
levy
committed
Merge branch 'dev'
2 parents e5e0b5c + af30075 commit ff070de

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+2127
-2562
lines changed

.stylelintrc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
{
22
"extends": "stylelint-config-standard",
33
"rules": {
4-
"no-empty-source": null
4+
"no-empty-source": null,
5+
"declaration-colon-newline-after": null,
6+
"value-list-comma-newline-after": null,
7+
"no-descending-specificity": null,
8+
"no-duplicate-selectors": null,
9+
"declaration-block-no-shorthand-property-overrides": null
510
}
611
}

.travis.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ addons:
2020
cache:
2121
- yarn
2222
- directories:
23-
- release/nuxt-element-dashboard/node_modules
24-
- release/nuxt-multiple-spa/node_modules
23+
- release/nuxt-admin/node_modules
2524
- release/nuxt-vant/node_modules
2625
deploy:
2726
#- provider: pages

bin/deploy/env.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"nuxt-element-dashboard": {
3-
"NO_LOGIN": 1
4-
},
5-
"nuxt-multiple-spa": {}
2+
"nuxt-admin": {
3+
"API_SERVER": "https://mockapi.eolinker.com/IeZWjzy87c204a1f7030b2a17b00f3776ce0a07a5030a1b",
4+
"APP_ID": "1204701543597604893"
5+
}
66
}

docs/api.md

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
# 在 nuxt 中优雅的管理 API
2+
3+
## 背景
4+
5+
在使用 nuxt 开发复杂系统时,往往伴随着海量的 API 接口。如果单纯的使用  [@nuxtjs/axios](#),那么 API 将与业务代码耦合在一次。最糟糕的状况是每个开发者都在页面中写下面的代码
6+
7+
```javascript
8+
// Page 1 获取一个用户的信息
9+
this.$axios.$get('/deepexi-cloud/users/1')
10+
11+
// Page 2 创建一个用户
12+
this.$axios.$post('/deepexi-cloud/users', body)
13+
```
14+
15+
对于 RESTful API 同一个资源,需要创建多个字符串来维护,即便可以通过抽离常量来维护,但对于调用者,还必须 import apiUrl,使用对应的 methods 来调用接口。
16+
17+
随着业务规模的扩张,需要一个能统一维护 API 的方案,来降低开发者的使用和维护成本。需要满足这几点:
18+
19+
- 可以直接调用方法,而不是写 this.$axios.$get('string')
20+
- 可以获取一个基本的 RESTful 资源链接,方便 data-table 等组件使用
21+
- 修改接口服务、版本、资源名称时,修改一处即可
22+
23+
## 使用
24+
25+
```javascript
26+
// 创建一个 API 资源,修改文件 src/api/index.js
27+
28+
// 创建了一个菜单资源的 CRUD 接口方法
29+
+ export const menus = new Repository(`${DEEPEXI_CLOUD_TENANT}/${VERSION}/menus`)
30+
31+
// 获取一个菜单,只要能访问到 nuxt 上下文的地方都可以调用,最常见是 this
32+
33+
// 在 page 中
34+
mounted() {
35+
// 获取资源的服务器路径
36+
this.$http.menus.uri()
37+
// 获取所有菜单资源,返回一个列表
38+
this.$http.menus.list()
39+
// 获取某个菜单资源的详情
40+
this.$http.menus.detail(MENUS_ID)
41+
// 创建一个菜单资源
42+
this.$http.menus.create(payload)
43+
// 更新一个菜单资源
44+
this.$http.menus.update(MENUS_ID, payload)
45+
// 删除一个菜单资源
46+
this.$http.menus.delete(MENUS_ID)
47+
}
48+
49+
// 在 store 中
50+
export const actions = {
51+
async getMenus(store, payload) {
52+
const data = await this.$http.menus.detail(payload)
53+
...
54+
}
55+
}
56+
```
57+
58+
## 进阶
59+
60+
有些时候,后端的接口并不是严格遵循 RESTful 的最佳实践,这个时候就需要自己重新实现默认的方法
61+
62+
```javascript
63+
// 在 src/api/repository.js 中增加一个类,继承 Repository
64+
export class ExampleRepository extends Repository {
65+
constructor(resource, id) {
66+
super(resource)
67+
this.id = id
68+
}
69+
70+
uri(appId) {
71+
return `${this.resource}/status/${this.id}?appId=${appId}`
72+
}
73+
74+
update($axios) {
75+
return (appId, payload, ...args) =>
76+
$axios.$post(`${this.uri(appId)}`, payload, ...args)
77+
}
78+
}
79+
80+
// 基于 ExampleRepository 创建一个 API
81+
export const example = new ExampleRepository('/example/api')
82+
83+
// 调用
84+
this.$http.example.uri(appId)
85+
this.$http.example.detail(id)
86+
this.$http.example.list()
87+
this.$http.example.create(payload)
88+
this.$http.example.update(appId, payload)
89+
this.$http.example.delete(id)
90+
```

docs/scroll.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# 实现统一的滚动条
2+
3+
本模板使用 element 中的 `el-scrollbar` 组件实现滚动条统一。由于这个组件 element 没有作为一个基础组件开放给大家使用。所以一些使用的细节只有 element 的维护者才知道。
4+
5+
| 属性名 | 类型 | 默认值 | 说明 |
6+
| --------- | ------- | ------ | ------------------------------------------------------- |
7+
| native | Boolean | false | 是否使用原生的滚动条 |
8+
| wrapStyle | - | - | 滚动容器的样式类 |
9+
| wrapClass | - | - | 滚动容器的样式 |
10+
| viewClass | - | - | 滚动视图的样式类 |
11+
| viewStyle | - | - | 滚动视图的样式 |
12+
| noresize | Boolean | false | 如果 container 尺寸不会发生变化,最好设置它可以优化性能 |
13+
| tag | String | div | 使用什么标签来渲染滚动视图 |
14+
15+
使用时,需要给 `el-scrollbar` 的根元素一个确定的宽高,如果不希望横向滚动条一直出现,需要将 `.el-scrollbar__wrap` 设置为 `overflow-x: auto;`
16+
17+
```html
18+
<el-scrollbar class="srollbar">
19+
...content
20+
</el-scrollbar>
21+
22+
<style>
23+
.scrollbar {
24+
height: 100%;
25+
}
26+
27+
.scrollbar .el-scrollbar__wrap {
28+
height: 100%;
29+
overflow-x: auto;
30+
}
31+
</style>
32+
```

lhci.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#!/bin/sh
22
yarn global add @lhci/cli
33

4-
lhci autorun --upload.target=temporary-public-storage --collect.staticDistDir=./dist --collect.url=http://localhost/nuxt-element-dashboard --collect.url=http://localhost/nuxt-multiple-spa --collect.url=http://localhost/nuxt-vant
4+
lhci autorun --upload.target=temporary-public-storage --collect.staticDistDir=./dist --collect.url=http://localhost/nuxt-admin --collect.url=http://localhost/nuxt-vant

template.config.js

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ const common = {
2828
'icon-font': 'icon-font',
2929
test: 'jest',
3030
utils: 'utils',
31+
service: 'service',
3132
}
3233

3334
const desktop = {
@@ -38,18 +39,11 @@ const desktop = {
3839
componentsDesktop: 'components-desktop',
3940
}
4041

41-
// nuxt-element-dashboard 框架配置
42-
const single = {
42+
// nuxt-admin 框架配置
43+
const admin = {
4344
...desktop,
44-
folder: 'nuxt-element-dashboard',
45-
template: 'single',
46-
}
47-
48-
// nuxt-multiple-spa 框架配置
49-
const multiple = {
50-
...desktop,
51-
folder: 'nuxt-multiple-spa',
52-
template: 'multiple',
45+
folder: 'nuxt-admin',
46+
template: 'admin',
5347
}
5448

5549
// nuxt-mobile 框架配置
@@ -59,4 +53,4 @@ const mobile = {
5953
template: 'mobile',
6054
}
6155

62-
module.exports = [single, multiple, mobile]
56+
module.exports = [mobile, admin]
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
{
2-
"name": "nuxt-multiple-spa",
2+
"name": "nuxt-admin",
33
"description": "Nuxt2 + element UI project",
44
"keywords": [
5+
"admin",
56
"dashboard",
67
"element-ui"
78
],
89
"dependencies": {
910
"@femessage/el-data-table": "latest",
1011
"@femessage/el-form-renderer": "latest",
1112
"@femessage/element-ui": "latest"
13+
},
14+
"devDependencies": {
15+
"svg-sprite-loader": "^4.1.6"
1216
}
1317
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
:export {
2+
INFO_COLOR: @--color-info;
3+
DANGER_COLOR: @--color-danger;
4+
PRIMARY_COLOR: @--color-primary;
5+
SUCCESS_COLOR: @--color-success;
6+
WARNING_COLOR: @--color-warning;
7+
TEXTPRIMARY_COLOR: @--color-text-primary;
8+
TEXTREGULAR_COLOR: @--color-text-regular;
9+
MENU_BG_COLOR: @menu-bg-color;
10+
MENU_TEXT_COLOR: @menu-text-color;
11+
MENU_ACTIVE_TEXT_COLOR: @menu-active-text-color;
12+
SUBMENU_BG_COLOR: @submenu-bg-color;
13+
SUBMENU_HOVER_COLOR: @submenu-hover-color;
14+
SUBMENU_ACTIVE_TEXT_COLOR: @submenu-active-text-color;
15+
HEADER_HEIGHT: @--header-height;
16+
FOOTER_HEIGHT: @--footer-height;
17+
BREADCRUMB_HEIGHT: @--breadcrumb-height;
18+
SIDEBAR_MIN_WIDTH: @sidebar-min-width;
19+
}
Lines changed: 20 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)