Skip to content

Commit 208790e

Browse files
authored
Merge pull request #23 from leezng/dev
release 1.6.0
2 parents 53f502d + 9112c91 commit 208790e

21 files changed

+6673
-11753
lines changed

.travis.yml

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
language: node_js
22
node_js:
3-
- "7"
3+
- "10"
44

55
cache:
66
directories:
77
- "node_modules"
88

99
install:
1010
- npm i
11-
- npm install vue@2
1211

1312
stages:
1413
- lint
@@ -24,15 +23,15 @@ jobs:
2423
- stage: gh_pages
2524
script: npm run build
2625
after_script:
27-
- cd ./example-dist
28-
- git init
29-
- git remote add origin "https://${GH_TOKEN}@${GH_REF}"
30-
- git checkout -b gh-pages
26+
- git clone -b gh-pages "https://${GH_TOKEN}@${GH_REF}" gh-pages
27+
- rm -r gh-pages/*
28+
- cp -r example-dist/. gh-pages
29+
- cd ./gh-pages
3130
- git config user.name "leezng"
3231
- git config user.email "im.leezng@gmail.com"
3332
- git add .
34-
- git commit -m "update example page"
35-
- git push --force --quiet "https://${GH_TOKEN}@${GH_REF}" gh-pages:gh-pages
33+
- git commit -m "update gh-pages"
34+
- git push --quiet "https://${GH_TOKEN}@${GH_REF}" gh-pages:gh-pages
3635
- stage: github_release
3736
script: echo "Deploying to GitHub releases ..."
3837
deploy:

README.md

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ A vue 2.x component for rendering JSON data as a tree structure.
1313

1414
- [Demo](https://leezng.github.io/vue-json-pretty)
1515
- [Github](https://github.com/leezng/vue-json-pretty)
16+
- [NPM](https://www.npmjs.com/package/vue-json-pretty)
1617
- [中文文档](./README.zh-CN.md)
1718

1819
## Install
@@ -49,23 +50,28 @@ export default {
4950
## Props
5051

5152
- If you are using only the basic features (JSON pretty), just focus on the `base` properties.
52-
- If you are using advanced features (get item data), you need to focus on the `base` and `advanced` attributes.
53+
- If you are using advanced features (selected), you can use `base` and `advanced` attributes.
5354

5455
| Attribute | Level | Description | Type | Default |
5556
|-------- |-------- |-------- |-------- | -------- |
5657
| data | basic | json data | JSON object | - |
5758
| deep | basic | data depth, data larger than this depth will not be expanded | number | Infinity |
5859
| showLength | basic | whether to show the length when closed | boolean | false |
60+
| showLine | basic | whether to show the line | boolean | true |
61+
| showDoubleQuotes | basic | whether to show doublequotes on key | boolean | true |
62+
| highlightMouseoverNode | basic | highlight current node when mouseover | boolean | false |
63+
| v-model | advanced | defines value when the tree can be selected | string, array | -, [] |
5964
| path | advanced | root data path | string | root |
6065
| pathChecked | advanced | defines the selected data path | array | [] |
6166
| pathSelectable | advanced | defines whether a data path supports selection | Function(itemPath, itemData) | - |
62-
| selectableType | advanced | defines the selected type, this feature is not supported by default | enum: both, checkbox, tree | - |
67+
| selectableType | advanced | defines the selected type, this feature is not supported by default | enum: -, multiple, single | - |
68+
| showSelectController | advanced | whether to show the select controller at left | boolean | false |
69+
| selectOnClickNode | advanced | whether to change selected value when click node | boolean | true |
70+
| highlightSelectedNode | advanced | highlight current node when selected | boolean | true |
6371

6472
## Events
6573

66-
- The following events are base on advanced features.
67-
6874
| Event Name | Description | Callback Parameters |
6975
|---------- |-------- |---------- |
7076
| click | triggered when a data item is clicked | (path, data) |
71-
77+
| change | triggered when the selected value changed (only the selectableType not null) | (newVal, oldVal) |

README.zh-CN.md

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
- [Demo](https://leezng.github.io/vue-json-pretty)
1515
- [Github](https://github.com/leezng/vue-json-pretty)
16+
- [NPM](https://www.npmjs.com/package/vue-json-pretty)
1617
- [English Document](./README.md)
1718

1819
## 安装
@@ -37,6 +38,7 @@ npm install vue-json-pretty -save
3738
```
3839

3940
```js
41+
// 更多用法请见demo页面
4042
import VueJsonPretty from 'vue-json-pretty'
4143

4244
export default {
@@ -49,23 +51,28 @@ export default {
4951
## Props
5052

5153
- 若仅使用基础功能(JSON美化),只需关注功能级别为 `基础` 的属性。
52-
- 若使用高级功能(数据层级的获取),需关注 `基础``高级` 的属性。
54+
- 若使用高级功能(选择数据),你可以同时使用 `基础``高级` 的属性。
5355

5456
| 属性 | 级别 | 说明 | 类型 | 默认值 |
5557
|-------- |-------- |-------- |-------- | -------- |
5658
| data | 基础 | 待美化的源数据,注意不是 `JSON` 字符串 | `JSON` 对象 | - |
5759
| deep | 基础 | 数据深度, 大于该深度的数据将不被展开 | number | Infinity |
5860
| showLength | 基础 | 是否在数据线闭合的时候展示长度 | boolean | false |
61+
| showLine | 基础 | 是否显示缩紧标识线 | boolean | true |
62+
| showDoubleQuotes | 基础 | 是否展示key名的双引号 | boolean | true |
63+
| highlightMouseoverNode | 基础 | 是否在mouseover的时候高亮 | boolean | false |
64+
| v-model | 高级 | 双向绑定选中的数据层级 | string, array | -, [] |
5965
| path | 高级 | 定义最顶层数据层级 | string | root |
6066
| pathChecked | 高级 | 定义哪些数据层级是已被选中的 | array | [] |
6167
| pathSelectable | 高级 | 定义哪些数据层级是可以被选中的 | Function(itemPath, itemData) | - |
62-
| selectableType | 高级 | 定义组件支持的选中方式,默认无选中功能 | enum: both, checkbox, tree | - |
68+
| selectableType | 高级 | 定义组件支持的选中方式,默认无选中功能 | enum: -, multiple, single | - |
69+
| showSelectController | 高级 | 是否展示选择控制器 | boolean | false |
70+
| selectOnClickNode | 高级 | 是否在点击节点的时候触发v-model双向绑定 | boolean | true |
71+
| highlightSelectedNode | 高级 | 是否高亮已选项 | boolean | true |
6372

6473
## Events
6574

66-
- 若使用高级功能,下列事件才是有效的。
67-
6875
| 事件名 | 说明 | 回调参数 |
6976
|---------- |-------- |---------- |
7077
| click | 点击某一个数据层级时触发的事件 | (path, data) |
71-
78+
| change | v-model改变的事件(仅在选择模式下可用) | (newVal, oldVal) |

example/App.vue

Lines changed: 111 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,36 +3,75 @@
33
<div class="example-box">
44
<h2 class="title">EXAMPLE 1</h2>
55
<div class="block">
6-
<h3>JSON Input:</h3>
6+
<h3>JSON:</h3>
77
<textarea v-model="val"></textarea>
8+
9+
<h3>Options:</h3>
10+
<div class="options">
11+
<div>
12+
<label>showLength</label>
13+
<input type="checkbox" v-model="showLength">
14+
</div>
15+
<div>
16+
<label>showLine</label>
17+
<input type="checkbox" v-model="showLine">
18+
</div>
19+
<div>
20+
<label>showDoubleQuotes</label>
21+
<input type="checkbox" v-model="showDoubleQuotes">
22+
</div>
23+
<div>
24+
<label>highlightMouseoverNode</label>
25+
<input type="checkbox" v-model="highlightMouseoverNode">
26+
</div>
27+
<div>
28+
<label>deep</label>
29+
<select v-model="deep">
30+
<option :value="2">2</option>
31+
<option :value="3">3</option>
32+
<option :value="4">4</option>
33+
</select>
34+
</div>
35+
</div>
836
</div>
937
<div class="block">
10-
<h3>JSON Tree:</h3>
38+
<h3>vue-json-pretty:</h3>
1139
<vue-json-pretty
12-
:deep="deep"
1340
:data="json"
14-
:path="'res'">
41+
:deep="deep"
42+
:show-double-quotes="showDoubleQuotes"
43+
:show-length="showLength"
44+
:show-line="showLine"
45+
:highlight-mouseover-node="highlightMouseoverNode"
46+
@click="handleClick">
1547
</vue-json-pretty>
1648
</div>
1749
</div>
1850

1951
<div class="example-box">
2052
<h2 class="title">EXAMPLE 2</h2>
2153
<div class="block">
22-
<h3>JSON Input:</h3>
54+
<h3>JSON:</h3>
2355
<textarea v-model="val"></textarea>
2456

25-
<h3>Options</h3>
57+
<h3>Options:</h3>
2658
<div class="options">
2759
<div>
28-
<label>selectable-type</label>
60+
<label>selectableType</label>
2961
<select v-model="selectableType">
30-
<option>-</option>
31-
<option>both</option>
32-
<option>checkbox</option>
33-
<option>tree</option>
62+
<option label="-"></option>
63+
<option>single</option>
64+
<option>multiple</option>
3465
</select>
3566
</div>
67+
<div>
68+
<label>showSelectController</label>
69+
<input type="checkbox" v-model="showSelectController">
70+
</div>
71+
<div>
72+
<label>selectOnClickNode</label>
73+
<input type="checkbox" v-model="selectOnClickNode">
74+
</div>
3675
<div>
3776
<label>path</label>
3877
<input type="text" v-model="path">
@@ -41,6 +80,22 @@
4180
<label>showLength</label>
4281
<input type="checkbox" v-model="showLength">
4382
</div>
83+
<div>
84+
<label>showLine</label>
85+
<input type="checkbox" v-model="showLine">
86+
</div>
87+
<div>
88+
<label>showDoubleQuotes</label>
89+
<input type="checkbox" v-model="showDoubleQuotes">
90+
</div>
91+
<div>
92+
<label>highlightMouseoverNode</label>
93+
<input type="checkbox" v-model="highlightMouseoverNode">
94+
</div>
95+
<div>
96+
<label>highlightSelectedNode</label>
97+
<input type="checkbox" v-model="highlightSelectedNode">
98+
</div>
4499
<div>
45100
<label>deep</label>
46101
<select v-model="deep">
@@ -50,22 +105,31 @@
50105
</select>
51106
</div>
52107
</div>
53-
54-
<h3>Latest Click Result:</h3>
108+
<h3>v-model:</h3>
109+
<div>{{value}}</div>
110+
<h3>Current Click:</h3>
55111
<div>path: {{itemPath}}</div>
56112
<div>data: <pre>{{itemData}}</pre></div>
57113
</div>
58114
<div class="block">
59-
<h3>JSON Tree:</h3>
115+
<h3>vue-json-pretty:</h3>
60116
<vue-json-pretty
117+
v-if="renderOK"
61118
:data="json"
62119
:path="path"
63120
:deep="deep"
121+
:show-double-quotes="showDoubleQuotes"
122+
:highlight-mouseover-node="highlightMouseoverNode"
123+
:highlight-selected-node="highlightSelectedNode"
64124
:show-length="showLength"
65-
:path-checked="['res', 'res.c']"
125+
:show-line="showLine"
126+
:select-on-click-node="selectOnClickNode"
127+
v-model="value"
66128
:path-selectable="((path, data) => typeof data !== 'number')"
67129
:selectable-type="selectableType"
68-
@click="handleClick">
130+
:show-select-controller="showSelectController"
131+
@click="handleClick(...arguments, 'complexTree')"
132+
@change="handleChange">
69133
</vue-json-pretty>
70134
</div>
71135
</div>
@@ -83,6 +147,7 @@ export default {
83147
},
84148
data () {
85149
return {
150+
renderOK: true,
86151
val: '',
87152
data: {
88153
status: 200,
@@ -99,20 +164,41 @@ export default {
99164
news_id: 51182,
100165
title: 'Teslamask\'s American Business Relations: The government does not pay billions to build factories',
101166
source: 'AI Finance',
102-
members: ['Daniel, Mike, John']
167+
members: ['Daniel', 'Mike', 'John']
103168
}]
104169
},
105-
selectableType: 'both',
106-
showLength: true,
170+
value: 'res.error',
171+
selectableType: 'single',
172+
showSelectController: true,
173+
showLength: false,
174+
showLine: true,
175+
showDoubleQuotes: true,
176+
highlightMouseoverNode: true,
177+
highlightSelectedNode: true,
178+
selectOnClickNode: true,
107179
path: 'res',
108-
deep: 4,
180+
deep: 3,
109181
itemData: {},
110182
itemPath: ''
111183
}
112184
},
113185
created () {
114186
this.val = JSON.stringify(this.data)
115187
},
188+
watch: {
189+
selectableType (newVal) {
190+
this.renderOK = false
191+
if (newVal === 'single') {
192+
this.value = 'res.error'
193+
} else if (newVal === 'multiple') {
194+
this.value = ['res.error', 'res.data[0].title']
195+
}
196+
// 重新渲染, 因为2中情况的v-model格式不同
197+
this.$nextTick(() => {
198+
this.renderOK = true
199+
})
200+
}
201+
},
116202
computed: {
117203
json () {
118204
try {
@@ -124,10 +210,13 @@ export default {
124210
}
125211
},
126212
methods: {
127-
handleClick (path, data, checked) {
128-
console.log('click', path, data, checked)
213+
handleClick (path, data, treeName = '') {
214+
console.log('click: ', path, data, treeName)
129215
this.itemPath = path
130216
this.itemData = !data ? data + '' : data // 处理 data = null 的情况
217+
},
218+
handleChange (newVal, oldVal) {
219+
console.log('newVal: ', newVal, ' oldVal: ', oldVal)
131220
}
132221
}
133222
}

0 commit comments

Comments
 (0)