crazy-treeselect 1.3.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.babelrc +5 -0
- package/App.vue +10 -0
- package/README.md +0 -0
- package/assets/logo.png +0 -0
- package/dist/vue-treeselect.js +2 -0
- package/dist/vue-treeselect.js.map +1 -0
- package/index.html +13 -0
- package/main.js +12 -0
- package/package.json +34 -0
- package/src/index.js +14 -0
- package/src/treeselect.vue +260 -0
- package/webpack.config.js +85 -0
package/index.html
ADDED
package/main.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "crazy-treeselect",
|
|
3
|
+
"description": "基于vue2的tree下拉",
|
|
4
|
+
"version": "1.3.9",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"vue2",
|
|
7
|
+
"tree",
|
|
8
|
+
"select"
|
|
9
|
+
],
|
|
10
|
+
"main": "dist/vue-treeselect.js",
|
|
11
|
+
"private": false,
|
|
12
|
+
"license": "MIT",
|
|
13
|
+
"scripts": {
|
|
14
|
+
"dev": "cross-env NODE_ENV=development webpack-dev-server --open --hot",
|
|
15
|
+
"build": "cross-env NODE_ENV=production webpack --progress --hide-modules"
|
|
16
|
+
},
|
|
17
|
+
"dependencies": {},
|
|
18
|
+
"devDependencies": {
|
|
19
|
+
"babel-core": "^6.0.0",
|
|
20
|
+
"babel-loader": "^6.0.0",
|
|
21
|
+
"babel-preset-env": "^1.5.1",
|
|
22
|
+
"cross-env": "^3.0.0",
|
|
23
|
+
"css-loader": "^0.25.0",
|
|
24
|
+
"file-loader": "^0.9.0",
|
|
25
|
+
"less": "^2.7.2",
|
|
26
|
+
"less-loader": "^4.0.5",
|
|
27
|
+
"vue": "^2.3.3",
|
|
28
|
+
"vue-jstree": "^2.1.6",
|
|
29
|
+
"vue-loader": "^12.1.0",
|
|
30
|
+
"vue-template-compiler": "^2.3.3",
|
|
31
|
+
"webpack": "^2.6.1",
|
|
32
|
+
"webpack-dev-server": "^2.4.5"
|
|
33
|
+
}
|
|
34
|
+
}
|
package/src/index.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Created by virus_zhh on 2017/9/30.
|
|
3
|
+
*/
|
|
4
|
+
import VTreeSelect from './treeselect.vue'
|
|
5
|
+
|
|
6
|
+
VTreeSelect.install = function(Vue){
|
|
7
|
+
Vue.component(VTreeSelect.name, VTreeSelect)
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
if (typeof window !== 'undefined' && window.Vue) {
|
|
11
|
+
window.Vue.use(VTreeSelect);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export default VTreeSelect
|
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div :class="classes" onselectstart="return false">
|
|
3
|
+
<button type="button" class="tree-select-single" @click="open = !open" v-if="selectedItems.length <= 1">
|
|
4
|
+
<span v-if="selectedItems.length === 0">{{placeholder}}</span>
|
|
5
|
+
<span v-if="selectedItems.length === 1">{{selectedItems[0].text}}</span>
|
|
6
|
+
</button>
|
|
7
|
+
<div class="tree-select-multiple" @click="open = !open" v-else>
|
|
8
|
+
<div class="tree-select-tag" v-for="item in selectedItems">
|
|
9
|
+
{{item.text}}
|
|
10
|
+
</div>
|
|
11
|
+
</div>
|
|
12
|
+
<i class="tree-selec-allow" @click="open = !open"></i>
|
|
13
|
+
<div class="tree-select-dropdown">
|
|
14
|
+
<v-jstree :data="data" ref="tree"
|
|
15
|
+
:size="size"
|
|
16
|
+
:showCheckbox="showCheckbox"
|
|
17
|
+
:allowTransition="allowTransition"
|
|
18
|
+
:wholeRow="wholeRow"
|
|
19
|
+
:noDots="noDots"
|
|
20
|
+
:multiple="multiple"
|
|
21
|
+
:allowBatch="allowBatch"
|
|
22
|
+
:textFieldName="textFieldName"
|
|
23
|
+
:valueFieldName="valueFieldName"
|
|
24
|
+
:childrenFieldName="childrenFieldName"
|
|
25
|
+
:async="async"
|
|
26
|
+
:loadingText="loadingText"
|
|
27
|
+
@item-click="itemClick"></v-jstree>
|
|
28
|
+
</div>
|
|
29
|
+
</div>
|
|
30
|
+
</template>
|
|
31
|
+
<script>
|
|
32
|
+
import VJstree from 'vue-jstree/src/tree.vue'
|
|
33
|
+
|
|
34
|
+
export default{
|
|
35
|
+
name: 'VTreeSelect',
|
|
36
|
+
data () {
|
|
37
|
+
return {
|
|
38
|
+
open: false,
|
|
39
|
+
selectedItems: []
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
props: {
|
|
43
|
+
value: null,
|
|
44
|
+
placeholder:{type: String, default: '请选择'},
|
|
45
|
+
data: {type: Array},
|
|
46
|
+
size: {type: String, validator: value => ['large', 'small'].indexOf(value) > -1},
|
|
47
|
+
showCheckbox: {type: Boolean, default: false},
|
|
48
|
+
allowTransition: {type: Boolean, default: true},
|
|
49
|
+
wholeRow: {type: Boolean, default: false},
|
|
50
|
+
noDots: {type: Boolean, default: false},
|
|
51
|
+
multiple: {type: Boolean, default: false},
|
|
52
|
+
allowBatch: {type: Boolean, default: false},
|
|
53
|
+
textFieldName: {type: String, default: 'text'},
|
|
54
|
+
valueFieldName: {type: String, default: 'value'},
|
|
55
|
+
childrenFieldName: {type: String, default: 'children'},
|
|
56
|
+
async: {type: Function},
|
|
57
|
+
loadingText: {type: String, default: 'Loading...'},
|
|
58
|
+
klass: String
|
|
59
|
+
},
|
|
60
|
+
model: {
|
|
61
|
+
prop: 'value',
|
|
62
|
+
event: 'update:value'
|
|
63
|
+
},
|
|
64
|
+
watch: {
|
|
65
|
+
value (val, oldVal) {
|
|
66
|
+
if (val !== oldVal) {
|
|
67
|
+
this.selectedItems = []
|
|
68
|
+
this.updateValue(val)
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
computed: {
|
|
73
|
+
classes () {
|
|
74
|
+
return [
|
|
75
|
+
{'tree-select': true},
|
|
76
|
+
{'tree-select-open': this.open},
|
|
77
|
+
{[this.klass]: !!this.klass}
|
|
78
|
+
]
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
methods: {
|
|
82
|
+
itemClick () {
|
|
83
|
+
var self = this
|
|
84
|
+
this.selectedItems = []
|
|
85
|
+
this.$refs.tree.handleRecursionNodeChilds(this.$refs.tree, node => {
|
|
86
|
+
if (node.model && node.model.selected) {
|
|
87
|
+
self.addSelectNode(node)
|
|
88
|
+
}
|
|
89
|
+
})
|
|
90
|
+
if (this.selectedItems.length === 1) {
|
|
91
|
+
this.$emit('update:value', this.selectedItems[0].value)
|
|
92
|
+
} else if (this.selectedItems.length > 1) {
|
|
93
|
+
this.$emit('update:value', this.selectedItems.map(item => {
|
|
94
|
+
return item.value
|
|
95
|
+
}))
|
|
96
|
+
} else {
|
|
97
|
+
this.$emit('update:value', null)
|
|
98
|
+
}
|
|
99
|
+
},
|
|
100
|
+
addSelectNode (node) {
|
|
101
|
+
this.selectedItems.push({
|
|
102
|
+
text: node.model[this.textFieldName],
|
|
103
|
+
value: node.model[this.valueFieldName]
|
|
104
|
+
})
|
|
105
|
+
},
|
|
106
|
+
updateValue (val) {
|
|
107
|
+
var self = this
|
|
108
|
+
var isBreak = false
|
|
109
|
+
this.$refs.tree.handleRecursionNodeChilds(this.$refs.tree, node => {
|
|
110
|
+
if (node.model) {
|
|
111
|
+
if (this.multiple) {
|
|
112
|
+
if (val.indexOf(node.model[self.valueFieldName]) !== -1) {
|
|
113
|
+
self.addSelectNode(node)
|
|
114
|
+
node.model.selected = true
|
|
115
|
+
} else {
|
|
116
|
+
node.model.selected = false
|
|
117
|
+
}
|
|
118
|
+
} else {
|
|
119
|
+
if (isBreak === false) {
|
|
120
|
+
if (node.model[self.valueFieldName] === val) {
|
|
121
|
+
isBreak = true
|
|
122
|
+
self.addSelectNode(node)
|
|
123
|
+
node.model.selected = true
|
|
124
|
+
} else {
|
|
125
|
+
node.model.selected = false
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
})
|
|
131
|
+
}
|
|
132
|
+
},
|
|
133
|
+
mounted () {
|
|
134
|
+
var el = this.$el
|
|
135
|
+
document.addEventListener('click', (e) => {
|
|
136
|
+
if (!el.contains(e.target) && el !== e.target) {
|
|
137
|
+
this.open = false
|
|
138
|
+
} else {
|
|
139
|
+
return false
|
|
140
|
+
}
|
|
141
|
+
}, true)
|
|
142
|
+
if (this.value) {
|
|
143
|
+
this.updateValue(this.value)
|
|
144
|
+
}
|
|
145
|
+
},
|
|
146
|
+
components: {
|
|
147
|
+
VJstree
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
</script>
|
|
151
|
+
<style lang="less">
|
|
152
|
+
.tree-select {
|
|
153
|
+
width: 100%;
|
|
154
|
+
height: auto;
|
|
155
|
+
line-height: 1.42857;
|
|
156
|
+
color: #555;
|
|
157
|
+
border: 1px solid #c2cad8;
|
|
158
|
+
background-color: #fff;
|
|
159
|
+
display: inline-block;
|
|
160
|
+
outline: 0!important;
|
|
161
|
+
box-shadow: none!important;
|
|
162
|
+
position: relative;
|
|
163
|
+
vertical-align: middle;
|
|
164
|
+
|
|
165
|
+
> .tree-select-single{
|
|
166
|
+
width: 100%;
|
|
167
|
+
line-height: 1.44;
|
|
168
|
+
padding-right: 25px;
|
|
169
|
+
text-align: left;
|
|
170
|
+
margin-bottom: 0;
|
|
171
|
+
vertical-align: middle;
|
|
172
|
+
touch-action: manipulation;
|
|
173
|
+
cursor: pointer;
|
|
174
|
+
border: none;
|
|
175
|
+
background-color: #fff;
|
|
176
|
+
white-space: nowrap;
|
|
177
|
+
padding: 6px 12px;
|
|
178
|
+
font-size: 14px;
|
|
179
|
+
outline: 0!important;
|
|
180
|
+
|
|
181
|
+
&:hover {
|
|
182
|
+
transition: all .3s;
|
|
183
|
+
background-color: #e1e5ec;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
> .tree-select-multiple{
|
|
188
|
+
max-width: 100%;
|
|
189
|
+
line-height: 24px;
|
|
190
|
+
padding: 4px 32px 2px 6px;
|
|
191
|
+
vertical-align: middle;
|
|
192
|
+
cursor: pointer;
|
|
193
|
+
|
|
194
|
+
> .tree-select-tag {
|
|
195
|
+
display: inline-block;
|
|
196
|
+
background-color: #36c6d3;
|
|
197
|
+
margin-right: 2px;
|
|
198
|
+
margin-bottom: 2px;
|
|
199
|
+
color: white;
|
|
200
|
+
text-shadow: none!important;
|
|
201
|
+
font-size: 14px;
|
|
202
|
+
font-weight: 300;
|
|
203
|
+
padding: 0px 6px;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
> .tree-select-dropdown{
|
|
208
|
+
cursor: pointer;
|
|
209
|
+
position: absolute;
|
|
210
|
+
width: 100%;
|
|
211
|
+
max-height: 0px;
|
|
212
|
+
overflow: auto;
|
|
213
|
+
min-height: 0px;
|
|
214
|
+
z-index: 1000!important;
|
|
215
|
+
background-color: #fff;
|
|
216
|
+
border: 1px solid #eee;
|
|
217
|
+
border-top: 0px;
|
|
218
|
+
border-bottom: 0px;
|
|
219
|
+
margin: 1px 0px 0px -1px;
|
|
220
|
+
transition: all .3s ease-in-out;
|
|
221
|
+
|
|
222
|
+
> .tree {
|
|
223
|
+
margin: 8px;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
> .tree-selec-allow{
|
|
228
|
+
|
|
229
|
+
cursor: pointer;
|
|
230
|
+
|
|
231
|
+
width:0px;
|
|
232
|
+
height:0px;
|
|
233
|
+
border-width:6px;
|
|
234
|
+
border-style:solid;
|
|
235
|
+
border-color:#555 transparent transparent;
|
|
236
|
+
font-size:0;
|
|
237
|
+
line-height:0;
|
|
238
|
+
|
|
239
|
+
position: absolute;
|
|
240
|
+
top:10px;
|
|
241
|
+
right:10px;
|
|
242
|
+
transition: all .3s;
|
|
243
|
+
transform:rotate(90deg);
|
|
244
|
+
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
&.tree-select-open{
|
|
248
|
+
> .tree-selec-allow{
|
|
249
|
+
transform:rotate(0deg);
|
|
250
|
+
top:12px;
|
|
251
|
+
right:8px;
|
|
252
|
+
}
|
|
253
|
+
> .tree-select-dropdown{
|
|
254
|
+
border-bottom: 1px solid #eee;
|
|
255
|
+
margin: 1px -1px 0px -1px;
|
|
256
|
+
max-height: 400px;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
</style>
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
var path = require('path')
|
|
2
|
+
var webpack = require('webpack')
|
|
3
|
+
|
|
4
|
+
module.exports = {
|
|
5
|
+
//entry: './main.js',
|
|
6
|
+
entry: './src/index.js',
|
|
7
|
+
output: {
|
|
8
|
+
path: path.resolve(__dirname, './dist'),
|
|
9
|
+
//publicPath: '/dist/',
|
|
10
|
+
publicPath: 'dist/',
|
|
11
|
+
filename: 'vue-treeselect.js',
|
|
12
|
+
library: 'vue-treeselect',
|
|
13
|
+
libraryTarget: 'umd',
|
|
14
|
+
umdNamedDefine: true
|
|
15
|
+
},
|
|
16
|
+
module: {
|
|
17
|
+
rules: [
|
|
18
|
+
{
|
|
19
|
+
test: /\.vue$/,
|
|
20
|
+
loader: 'vue-loader',
|
|
21
|
+
options: {
|
|
22
|
+
loaders: {
|
|
23
|
+
}
|
|
24
|
+
// other vue-loader options go here
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
test: /\.js$/,
|
|
29
|
+
loader: 'babel-loader',
|
|
30
|
+
exclude: /node_modules/
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
test: /\.(png|jpg|gif|svg)$/,
|
|
34
|
+
loader: 'file-loader',
|
|
35
|
+
options: {
|
|
36
|
+
name: '[name].[ext]'
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
test: /\.less$/,
|
|
41
|
+
use: [{
|
|
42
|
+
loader: "style-loader" // creates style nodes from JS strings
|
|
43
|
+
}, {
|
|
44
|
+
loader: "css-loader" // translates CSS into CommonJS
|
|
45
|
+
}, {
|
|
46
|
+
loader: "less-loader" // compiles Less to CSS
|
|
47
|
+
}]
|
|
48
|
+
}
|
|
49
|
+
]
|
|
50
|
+
},
|
|
51
|
+
resolve: {
|
|
52
|
+
alias: {
|
|
53
|
+
'vue$': 'vue/dist/vue.js'
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
devServer: {
|
|
57
|
+
historyApiFallback: true,
|
|
58
|
+
noInfo: true
|
|
59
|
+
},
|
|
60
|
+
performance: {
|
|
61
|
+
hints: false
|
|
62
|
+
},
|
|
63
|
+
devtool: '#eval-source-map'
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (process.env.NODE_ENV === 'production') {
|
|
67
|
+
module.exports.devtool = '#source-map'
|
|
68
|
+
// http://vue-loader.vuejs.org/en/workflow/production.html
|
|
69
|
+
module.exports.plugins = (module.exports.plugins || []).concat([
|
|
70
|
+
new webpack.DefinePlugin({
|
|
71
|
+
'process.env': {
|
|
72
|
+
NODE_ENV: '"production"'
|
|
73
|
+
}
|
|
74
|
+
}),
|
|
75
|
+
new webpack.optimize.UglifyJsPlugin({
|
|
76
|
+
sourceMap: true,
|
|
77
|
+
compress: {
|
|
78
|
+
warnings: false
|
|
79
|
+
}
|
|
80
|
+
}),
|
|
81
|
+
new webpack.LoaderOptionsPlugin({
|
|
82
|
+
minimize: true
|
|
83
|
+
})
|
|
84
|
+
])
|
|
85
|
+
}
|