This repository was archived by the owner on Aug 11, 2021. It is now read-only.
File tree 12 files changed +78
-50
lines changed
12 files changed +78
-50
lines changed Original file line number Diff line number Diff line change 1
1
<template >
2
2
<div >
3
- {{ #if isGlobal }}
4
- <!-- 全局组件:<{{ properCase name }} /> -->
5
- {{ else }}
6
- <!-- 组件:<{{ properCase name }} /> -->
7
- {{ /if }}
3
+ <!-- 组件内容区 -->
8
4
</div >
9
5
</template >
10
6
@@ -17,7 +13,6 @@ export default {
17
13
data () {
18
14
return {}
19
15
},
20
- created () {},
21
16
mounted () {},
22
17
methods: {}
23
18
}
Original file line number Diff line number Diff line change
1
+ const fs = require ( 'fs' )
2
+
3
+ function getFolder ( path ) {
4
+ let components = [ ]
5
+ const files = fs . readdirSync ( path )
6
+ files . forEach ( function ( item ) {
7
+ let stat = fs . lstatSync ( path + '/' + item )
8
+ if ( stat . isDirectory ( ) === true && item != 'components' ) {
9
+ components . push ( path + '/' + item )
10
+ components . push . apply ( components , getFolder ( path + '/' + item ) )
11
+ }
12
+ } )
13
+ return components
14
+ }
15
+
1
16
module . exports = {
2
17
description : '创建组件' ,
3
18
prompts : [
19
+ {
20
+ type : 'confirm' ,
21
+ name : 'isGlobal' ,
22
+ message : '是否为全局组件' ,
23
+ default : false
24
+ } ,
25
+ {
26
+ type : 'list' ,
27
+ name : 'path' ,
28
+ message : '请选择组件创建目录' ,
29
+ choices : getFolder ( 'src/views' ) ,
30
+ when : answers => {
31
+ return ! answers . isGlobal
32
+ }
33
+ } ,
4
34
{
5
35
type : 'input' ,
6
36
name : 'name' ,
@@ -12,25 +42,20 @@ module.exports = {
12
42
return true
13
43
}
14
44
}
15
- } ,
16
- {
17
- type : 'confirm' ,
18
- name : 'isGlobal' ,
19
- message : '是否为全局组件' ,
20
- default : false
21
45
}
22
46
] ,
23
47
actions : data => {
24
- const name = '{{properCase name}}'
48
+ let path = ''
49
+ if ( data . isGlobal ) {
50
+ path = 'src/components/{{properCase name}}/index.vue'
51
+ } else {
52
+ path = `${ data . path } /components/{{properCase name}}/index.vue`
53
+ }
25
54
const actions = [
26
55
{
27
56
type : 'add' ,
28
- path : `src/components/${ data . isGlobal ? 'global/' : '' } ${ name } /index.vue` ,
29
- templateFile : 'plop-templates/component/index.hbs' ,
30
- data : {
31
- name : data . name ,
32
- isGlobal : data . isGlobal
33
- }
57
+ path : path ,
58
+ templateFile : 'plop-templates/component/index.hbs'
34
59
}
35
60
]
36
61
return actions
Original file line number Diff line number Diff line change 1
1
<template >
2
2
<div >
3
- {{ #if isLayout }}
4
- <!-- 布局页面:{{ properCase name }} -->
5
- <RouterView />
6
- {{ else }}
7
- <!-- 页面:{{ properCase name }} -->
8
- {{ /if }}
3
+ <page-header title =" {{ cname }} " />
4
+ <page-main >
5
+ 页面内容区域
6
+ </page-main >
9
7
</div >
10
8
</template >
11
9
12
10
<script >
13
11
export default {
14
- props : {} ,
12
+ name : ' {{ properCase componentName }} ' ,
15
13
data () {
16
14
return {}
17
15
},
18
- created () {},
19
16
mounted () {},
20
17
methods: {}
21
18
}
Original file line number Diff line number Diff line change
1
+ const path = require ( 'path' )
2
+ const fs = require ( 'fs' )
3
+
4
+ function getFolder ( path ) {
5
+ let components = [ ]
6
+ const files = fs . readdirSync ( path )
7
+ files . forEach ( function ( item ) {
8
+ let stat = fs . lstatSync ( path + '/' + item )
9
+ if ( stat . isDirectory ( ) === true && item != 'components' ) {
10
+ components . push ( path + '/' + item )
11
+ components . push . apply ( components , getFolder ( path + '/' + item ) )
12
+ }
13
+ } )
14
+ return components
15
+ }
16
+
1
17
module . exports = {
2
18
description : '创建页面' ,
3
19
prompts : [
4
20
{
5
21
type : 'list' ,
6
- name : 'type' ,
7
- message : '请选择页面类型' ,
8
- choices : [ 'view' , 'layout' ] ,
9
- default : 'view'
10
- } ,
11
- {
12
- type : 'input' ,
13
- name : 'viewPath' ,
14
- message : '请输入页面存放路径(./views/???)' ,
15
- when : answers => {
16
- return answers . type == 'view'
17
- }
22
+ name : 'path' ,
23
+ message : '请选择页面创建目录' ,
24
+ choices : getFolder ( 'src/views' )
18
25
} ,
19
26
{
20
27
type : 'input' ,
21
28
name : 'name' ,
22
- message : '请输入页面名称' ,
23
- default : 'index' ,
29
+ message : '请输入文件名' ,
24
30
validate : v => {
25
31
if ( ! v || v . trim === '' ) {
26
- return '页面名称不能为空 '
32
+ return '文件名不能为空 '
27
33
} else {
28
34
return true
29
35
}
30
36
}
37
+ } ,
38
+ {
39
+ type : 'input' ,
40
+ name : 'cname' ,
41
+ message : '请输入页面中文名称' ,
42
+ default : '默认页面'
31
43
}
32
44
] ,
33
45
actions : data => {
34
- const path = data . type == 'view' ? `views/ ${ data . viewPath } ` : 'layout'
46
+ let relativePath = path . relative ( 'src/views' , data . path )
35
47
const actions = [
36
48
{
37
49
type : 'add' ,
38
- path : `src/ ${ path } /${ data . name } .vue` ,
50
+ path : `${ data . path } /{{dotCase name} }.vue` ,
39
51
templateFile : 'plop-templates/page/index.hbs' ,
40
52
data : {
41
- name : data . name ,
42
- isLayout : data . type == 'layout'
53
+ componentName : `${ relativePath } ${ data . name } `
43
54
}
44
55
}
45
56
]
Original file line number Diff line number Diff line change @@ -5,7 +5,6 @@ module.exports = {
5
5
type : 'input' ,
6
6
name : 'name' ,
7
7
message : '请输入模块名称' ,
8
- default : 'index' ,
9
8
validate : v => {
10
9
if ( ! v || v . trim === '' ) {
11
10
return '模块名称不能为空'
Original file line number Diff line number Diff line change 1
1
module . exports = function ( plop ) {
2
+ plop . setWelcomeMessage ( '请选择需要创建的模式:' )
2
3
plop . setGenerator ( 'page' , require ( './plop-templates/page/prompt' ) )
3
4
plop . setGenerator ( 'component' , require ( './plop-templates/component/prompt' ) )
4
5
plop . setGenerator ( 'store' , require ( './plop-templates/store/prompt' ) )
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change 1
1
/**
2
2
* 全局组件自动注册
3
3
*
4
- * 全局组件统一放在 ./global 目录下,需要注意各个组件按文件夹区分, 文件夹名称与组件名无关联
4
+ * 全局组件各个组件按文件夹区分, 文件夹名称与组件名无关联,但建议与组件名保持一致
5
5
* 文件夹内至少保留一个文件名为 index 的组件入口,例如 index.vue
6
6
* 普通组件必须设置 name 并保证其唯一,自动注册会将组件的 name 设为组件名,可参考 SvgIcon 组件写法
7
7
* 如果组件是通过 js 进行调用,则确保组件入口文件为 index.js,可参考 ExampleNotice 组件
8
8
*/
9
9
10
10
import Vue from 'vue'
11
11
12
- const componentsContext = require . context ( './global ' , true , / i n d e x .( v u e | j s ) $ / )
12
+ const componentsContext = require . context ( './' , true , / i n d e x .( v u e | j s ) $ / )
13
13
componentsContext . keys ( ) . forEach ( file_name => {
14
14
// 获取文件中的 default 模块
15
15
const componentConfig = componentsContext ( file_name ) . default
Original file line number Diff line number Diff line change 6
6
</template >
7
7
8
8
<script >
9
- import ExampleList from ' @ /components/ExampleList'
9
+ import ExampleList from ' . /components/ExampleList/index '
10
10
11
11
export default {
12
12
components: {
File renamed without changes.
You can’t perform that action at this time.
0 commit comments