1 | # AutoTree
|
2 |
|
3 | ## 项目运行
|
4 |
|
5 | 1. cnpm install 或 npm install cnpm使用教程
|
6 |
|
7 | 2. npm run serve:data //用于本地模拟数据服务
|
8 |
|
9 | 3. npm run dev (开发环境打包 port:8080)
|
10 |
|
11 | 4. npm run test (测试用例)
|
12 |
|
13 | 5. npm run build (生产环境打包)
|
14 |
|
15 |
|
16 | ## 参数
|
17 |
|
18 | ### props
|
19 | ```javascript
|
20 | const options = {
|
21 | required: true, //必填
|
22 | disabled: false,
|
23 | sync: false, //异步请求
|
24 | status: 'edit', //edit,search
|
25 | showDropDown: false, //渲染footer,带有确定按钮以及下拉弹层
|
26 | hiddenTip: false,
|
27 | sideTip: false, //tips是否左右显示 可选参数 true ,false 默认为false 可不设置,一般情况下均为false`
|
28 | single: true, //单选多选
|
29 | isFetching: this.state.isFetching, //loading状态
|
30 | isSearchAutoTreeEdit:true, //是否在高级筛选中的组件(beisencloud的参数)
|
31 | autoTreeData: [{
|
32 | id:'0',
|
33 | name:'100990'
|
34 | },
|
35 | {
|
36 | id:'1',
|
37 | name:'asdfasdf'
|
38 | }],
|
39 | treeData:[{
|
40 | "id": "32025",
|
41 | "name": "技术体系阿斯顿发送到发送到发送到发送到发送到发送到发送到发送的方式打发当时发生的发生的",
|
42 | "path": "32025.",
|
43 | "pid": "0",
|
44 | "level": "1",
|
45 | "has_child":false,
|
46 | "clickable":false
|
47 | }],
|
48 | componentId:"3", //唯一标示(cmp_id)
|
49 | errorStatus: false, //是否报错
|
50 | errorMsg:"出错了~~~!", //报错信息
|
51 | helpMsg:"dsadas", //帮助信息
|
52 | labelText: '选择部门11', //左侧 label 文字
|
53 | showText:'请输入正确信1息',
|
54 | placeholder: '输入部门2名称1', // input placeholder
|
55 | lablePos: true, //label位置,true时在左边,false在上边
|
56 | lableTxt: false, //label中文字对齐方式,true左对齐,false右对齐
|
57 | defaultStatus:false, //// 输入框样式控制,默认false
|
58 | hidden:false, //不显示,默认false
|
59 | defaultValue:false, //todo 用于控制state.hasClick
|
60 | defaultValueObj:{
|
61 | id:'',
|
62 | name:'',
|
63 | path:'',
|
64 | level:'',
|
65 | },
|
66 | getAutoTreeDataAPI,
|
67 |
|
68 |
|
69 | autoTreeSearchCallBack: (val) => console.log(val),
|
70 | keyUpCallBack: (event, value) => console.log(event, value), // input keyup输入回调
|
71 | itemCallBack: (data) => {
|
72 | console.log(data)
|
73 | // this.setState({_defaultValue:data[0].name})
|
74 | }, // 点击回调
|
75 | focusCallBack: (value) => {
|
76 | let self = this;
|
77 | console.log('2focusCallBack')
|
78 | setTimeout(function() {
|
79 | self.props.getAutoTreeData(self.props.getAutoTreeDataAPI,'','');
|
80 | },500)
|
81 | }, // input focusp输入回调
|
82 | blurCallBack: (event) => console.log(event), // input失去焦点回调
|
83 | changeCallBack: (event,value,inputValue) => {console.log(event, value,inputValue)}, // input keyup输入回调
|
84 | clearCallback: ()=>{console.log('clearCallback')},
|
85 | searchSubmitCallBack: (value) =>{console.log(value)}, //搜索态点击确定按钮回调
|
86 | setSessionCallBack:() => {},
|
87 | submitCallBack:(resultsData)=>{console.log(resultsData)},
|
88 | getAutoTreeData:(getAutoTreeDataAPI,inputValue,filters)=>{},
|
89 | findAllSearch:(value)=>{},
|
90 | clearAutoTreeData:()=>{},
|
91 | showPopCallback:()=>{},
|
92 | removeComponent:()=>{},
|
93 | unmountCallBack:()=>{},
|
94 | onCloseCallback:(event)=>{},
|
95 | itemCloseCallBack:(resultsData)=>{},
|
96 | }
|
97 | ```
|
98 |
|
99 |
|
100 |
|
101 | ## 使用方法
|
102 |
|
103 | 1.安装npm组件包
|
104 |
|
105 | ```
|
106 | npm install @beisen/auto-tree --save-dev
|
107 | ```
|
108 |
|
109 | 2.引用组件
|
110 |
|
111 | ```javascript
|
112 | import auto-tree from "@beisen/auto-tree"
|
113 | ```
|
114 |
|
115 | 3.传入参数
|
116 |
|
117 | 该参数为上述参数,传入方式使用: {...参数}
|
118 |
|
119 | ```javascript
|
120 |
|
121 | class Demo extends Component{
|
122 | constructor(props){
|
123 | super(props);
|
124 | this.state = {
|
125 | // hidden:false,
|
126 | popShow:true,
|
127 | target: "",
|
128 | defaultDropValue: '',
|
129 | defaultValue: '',
|
130 | treeMaxheight: '',
|
131 | isFetching: true
|
132 | }
|
133 | this.popClose = this.popClose.bind(this);
|
134 | this.removeComponent = this.removeComponent.bind(this);
|
135 | }
|
136 | popClose() {
|
137 | let self = this;
|
138 | this.setState({
|
139 | popShow: !this.state.popShow
|
140 | })
|
141 | }
|
142 | removeComponent() {
|
143 | this.setState({
|
144 | popShow: false
|
145 | })
|
146 | }
|
147 | componentDidMount() {
|
148 | if(this.refs.dirButton!=undefined){
|
149 | let target = this.refs.dirButton.getBoundingClientRect();
|
150 | this.state.target = target;
|
151 | this.setState(this.state);
|
152 | }
|
153 | let self = this;
|
154 | setTimeout(function() {
|
155 | // self.props.getAutoTreeData(self.props.getAutoTreeDataAPI,'','');
|
156 | self.setState({isFetching:false})
|
157 | },500)
|
158 | }
|
159 | clearAutoTreeData() {
|
160 | this.props.clearAutoTreeData();
|
161 | }
|
162 |
|
163 | render () {
|
164 | let self = this;
|
165 | const options = {
|
166 | required: true,
|
167 | disabled: false,
|
168 | sync: false, //true:同步,false:异步
|
169 | status: 'search', //edit,search
|
170 | single: true,
|
171 | isFetching: this.state.isFetching,
|
172 | isSearchAutoTreeEdit:true,
|
173 | hiddenTip: false,
|
174 | sideTip: false,
|
175 | showDropDown: true,
|
176 | totalCount: 100,
|
177 | helpMsg: 'aaaaaa',
|
178 | autoTreeData: [
|
179 | {
|
180 | id:'0',
|
181 | name:'100990ajksdhfoiqhwieofhsdhfajshdfjahsdjkfhaksdhfajsdhfquwehfkjasdhfkajshdfjasbdvasnbkjsdfbksjhdf',
|
182 | pname:'我是爸爸'
|
183 | },{
|
184 | id:'1',
|
185 | name:'100990',
|
186 | pname:'我是爸爸'
|
187 | },{
|
188 | id:'2',
|
189 | name:'123123123123'
|
190 | },{
|
191 | id:'3',
|
192 | name:'1qweqweqwe'
|
193 | },{
|
194 | id:'4',
|
195 | name:'1asdfasdf'
|
196 | },{
|
197 | id:'5',
|
198 | name:'23123123'
|
199 | },{
|
200 | id:'6',
|
201 | name:'1asdadssdasdasd'
|
202 | },{
|
203 | id:'7',
|
204 | name:'10dsfgergsdfgsdfg0'
|
205 | },{
|
206 | id:'8',
|
207 | name:'1435467867543'
|
208 | },{
|
209 | id:'9',
|
210 | name:'sdfgwer1fasdfasdf'
|
211 | },{
|
212 | id:'10',
|
213 | name:'23434534534511435345'
|
214 | },{
|
215 | id:'11',
|
216 | name:'sdfsdfgsdfgsdfg111'
|
217 | },{
|
218 | id:'12',
|
219 | name:'sdvsdfgsfgweger11222'
|
220 | },{
|
221 | id:'13',
|
222 | name:'dfgrgw2211'
|
223 | }
|
224 | ],
|
225 | defaultValue: '',
|
226 | defaultStatus: false,
|
227 | componentId:"1",
|
228 | errorStatus: false, //是否报错
|
229 | errorMsg:"出错了~~~!", //报错信息
|
230 | // showText:'请输入正确信息',
|
231 | labelText: '选择部门', //左侧 label 文字
|
232 | // placeholder: '', // input placeholder
|
233 | lablePos: true, //label位置,true时在左边,false在上边
|
234 | lableTxt: false, //label中文字对齐方式,true左对齐,false右对齐
|
235 | autoTreeSearchCallBack: (val,filters) => {this.setState({defaultDropValue:filters})},
|
236 | keyUpCallBack: (event, value) => {}, // input keyup输入回调
|
237 | itemCallBack: (data) => {
|
238 |
|
239 | }, // 点击回调
|
240 | focusCallBack: (value) => {
|
241 | // setTimeout(function() {
|
242 | // self.setState({isFetching:false})
|
243 | // },5500)
|
244 | console.log('点击了')
|
245 | let self = this;
|
246 | setTimeout(function() {
|
247 | // self.props.getAutoTreeData(self.props.getAutoTreeDataAPI,'','');
|
248 | },500)
|
249 | }, // input keyup输入回调
|
250 | blurCallBack: (event) => {}, // 点击回调
|
251 | changeCallBack: (event,value,inputValue) => {}, // input keyup输入回调
|
252 | clearCallback: () => {},
|
253 | showPopCallback: () =>{},
|
254 | unmountCallBack: () => {},
|
255 | searchSubmitCallBack: (value) =>{console.log(value)},
|
256 | submitCallBack: (data) =>{console.log(data)},
|
257 | onCloseCallback:(value)=>this.clearAutoTreeData(),
|
258 | setSessionCallBack:() => {},
|
259 | itemCloseCallBack: (data) => {console.log(data)}
|
260 | }
|
261 | const treeData = {
|
262 | toggle: true,
|
263 | treeData: this.props.treeData,
|
264 | async: 1, //1异步 0同步
|
265 | id:1, //异步请求的第一层数据pid,非必须
|
266 | sidebarScene:false, // false或该字段没有,则为非sidebar交互方式
|
267 | // scrollBar:true, //false则不使用
|
268 | initGetData:true, //默认为tree,是否组件在首次渲染时请求数据,树组件默认会在DidMount时执行getTreeData方法去请求数据
|
269 | postData:[],
|
270 | methodType:'GET',
|
271 | getTreeData:function(id,treeAsync,getUrl,postData,methodType) {
|
272 | console.log(id,treeAsync,getUrl,postData,methodType)
|
273 | self.props.getTreeData(getUrl,id);
|
274 | },
|
275 | getTreeDataAPI: '' || 'http://localhost:3001/getTreeData' //请求接口
|
276 | ,style:{
|
277 | "maxHeight":this.state.treeMaxheight
|
278 | }
|
279 | ,clearTreeData:function() {console.log('clearTreeData')}
|
280 | }
|
281 | const DropDownData = {
|
282 | "title":"" //input框前的文字标识,可为空
|
283 | ,"placeholder":"搜索" /**没有值的时候显示的内容(string)**/
|
284 | ,"defaultValue": this.state.defaultDropValue //默认值
|
285 | ,"openListView":false // 是否打开下拉框
|
286 | ,"errorStatus":true // 错误状态
|
287 | ,"errorMsg":"出错了~~~!" //错误信息
|
288 | ,multiple: false //下拉菜单为单选或者多选,true为多选,false为单选,默认为false
|
289 | ,"children":[
|
290 | {
|
291 | "value":0
|
292 | ,"text":"本级别及所有下级"
|
293 | ,"isActive":false //点击效果,默认为false
|
294 | ,"isChecked":false //是否被选中,默认为false
|
295 | }
|
296 | ,{
|
297 | "value":1
|
298 | ,"text":"本级别"
|
299 | ,"isActive":false
|
300 | ,"isChecked":false
|
301 | }
|
302 | ,{
|
303 | "value":2
|
304 | ,"text":"本本级别及直接下级"
|
305 | ,"isActive":false
|
306 | ,"isChecked":false
|
307 | }
|
308 | ,{
|
309 | "value":3
|
310 | ,"text":"直接下级"
|
311 | ,"isActive":false
|
312 | ,"isChecked":false
|
313 | }
|
314 | ,{
|
315 | "value":4
|
316 | ,"text":"全部下级"
|
317 | ,"isActive":false
|
318 | ,"isChecked":false
|
319 | }
|
320 | ] /** MenuItem **/
|
321 | ,"hidden":false //是否显示\
|
322 | ,"disabled":false //是否禁用
|
323 | ,"required":false //是否显示必选星号
|
324 | ,"iconName":"pc-sys-arrowdown-nomal-svg" //右侧下拉按钮的样式
|
325 | ,"onClick":function(event, target, val){} /**点击后事件回调;event:事件,target: 事件对象,val:抛出的值**/
|
326 | ,"onBlur":function(event, val){} /**失去焦点后事件回调event:val:input抛出的值**/ /**change后事件回调event:事件,target: 事件对象,val:input中值改变的值**/
|
327 | ,"onFocus":function(event, val){} /**获取焦点后事件回调event:事件,val:抛出的input中的值**/
|
328 | }
|
329 | let popTree = this.state.popShow?<AutoTree {...options} {...this.props} {...this.state} popClose={this.popClose} DropDownData={DropDownData} treeData={treeData} removeComponent={this.removeComponent} />:"";
|
330 |
|
331 | return (
|
332 | <div style={{marginTop:'50px',height:"700px"}}>
|
333 | <div>
|
334 | {popTree}
|
335 | </div>
|
336 | </div>
|
337 | )
|
338 | }
|
339 | }
|
340 | render(
|
341 | <Provider store={store}>
|
342 | <Demo />
|
343 | </Provider>,
|
344 | document.getElementById('content')
|
345 | );
|
346 |
|
347 |
|
348 | ``` |
\ | No newline at end of file |