UNPKG

joywok-material-components

Version:

<h1 align="center"> Joywok Material Components </h1>

807 lines (791 loc) 30.5 kB
/** * 自定义范围的对象选择器,本地数据,或请求一个接口拿回范围 * 搭配 CustomShareModal 使用 */ import React, { Component } from 'react'; import ReactDOM from 'react-dom'; import request from './../utils/request'; import { COMPONENT_DICT } from '../constants'; // import { Input, Modal, Select, Steps, Spin, Checkbox, Button, message, Popover } from 'antd'; import Input from '@material-ui/core/Input'; import Modal from 'joywok-material-components/lib/modal/modal' import Checkbox from 'joywok-material-components/lib/checkbox/index' import Button from 'joywok-material-components/lib/button/index' import Popover from 'joywok-material-components/lib/popper/custom' import Loading from 'joywok-material-components/lib/loading/index' import Dialog from '@material-ui/core/Dialog'; import AloneTip from 'joywok-material-components/lib/tips/aloneTip'; import RadioButtonCheckedIcon from '@material-ui/icons/RadioButtonChecked'; import RadioButtonUncheckedIcon from '@material-ui/icons/RadioButtonUnchecked'; const curLang = (window.language || window.cur_lang) || 'zh'; window.shareAloneTip = null; require('./style/shareobj.css'); class LocalShareObjContainer extends Component { constructor(props) { super(props); let selectD = _.filter(props.data.select, i => !i.selected_flag || (i.selected_flag && i.selected_flag == 1 && i.default_flag != 1)); let self = this; this.appIcons = { 'domain': jwimgsrc + '/images/jw-img/share/objselect_comp.png', 'dept': jwimgsrc + '/images/jw-img/share/team.png', 'personnel_category': jwimgsrc + '/images/jw-img/share/position.png', 'post': jwimgsrc + '/images/jw-img/share/position.png', 'role': jwimgsrc + '/images/jw-img/share/roles.png' , 'apps': jwimgsrc + '/images/jw-img/share/roles.png', 'extuser': jwimgsrc + '/images/jw-img/share/position.png', 'category': 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADwAAAA8CAYAAAA6/NlyAAAAAXNSR0IArs4c6QAABSpJREFUaAXtW2tsFFUU/mahy6stiG2xJA3avxUJirWBCk2qaDCCJCZAogmJ4osEoyb6Q43GV6IxGiWgVYk/NNGUUNRoFCmGNIWAaLBI9Yc0KhCssBDtFkq70PU7e3eyszu7szNz12z3cZLdmXvuOffeb777OPfujoG4RKMwsBX3I4r7qGritdLMK8irgWG2u5+otuERfGAYREQx5CvagXpE8BFV7ZIuOjGwh0jvMTZiMBBjtpjBCntCZBQfC1YjugUbMI73io7VdIACeCBA5DJmS0OINUCkTaWBNoaySRgu7NnYC1vEKgyXlJQBFzvdZYbLDBfZEyh36SIj1Aan5BiebHsEOoppc4ApM+0ljA0BFwbtepuGz3/BJga7G4DKBiD0E3DgGeBUj83Sr8KIbmZwqSuNq4HWN4HqeZlLCp8A9j0BHNue3iZQAdzeCTTelZzPPR32PsytfEey3mdKv0s3LAdWdDmDlcZVkTEBNO8Oe1OtYC+eAz6/DeioJrvP8oiCZxRt75D1B+1+PjT6gJuf81Zt8/PJ9qlgP7sFOPEtEAkDP7wE9DyaAH3tQ8m+PlL6Y7h2obdqa66jvTzncV6kG7OLN64ChFkBGzqcXN6Rt1V66VvAsq3q/ui7yTYeUvoMT57moTqaTgoS6CTl0/KKM1izZAHds0kxLaDnLjVzPF/1AXuuMu4wtQZY+DhweYxjlvNAKrOp5R7ZrGZsGdMtL6fmuk7nD/CV88kYq/9rH3DmR3cN7ot375oF7uzTWOUPcPi4as5snjAFZ6ZpWhpV/WKlNH3TmGRT5Q/w0ABw8jtgeh1w51dARZVzW2uvB5Z/omx+ed/Z1iFXH/BIyKH4NFmj/3KCjqiM7vWAsFW/BFj5dWbQAnZVNzD1CmCgC+jjePYp+oC9hn1W+2FGX11twNCfcdDf2EEngd0J7FpLqFzSfIo+4F6Gi7KGupHRf4BezsxWCf8O7GyLg+YYXUnQwVnKou5GC7MCdk2id1jL8HCfm1h6xlxgEcPAq25KPwHJ5uHv74FDLwLnT6ZvXtXVwOq9KkQdOQOc+5Xltah1eyA3YKXi3ACWknIhskNq/xBoaFeljV8GDr8OHOTDNMe9Zj0TC7AJpuoatdk4exQYdTlcTN8sV/1YOrUCIx42WvVRmWSiVk3me/Ef5swtHxFJe/FXXhm/cwO49gZgyWtAXTPHcKW9ssh5juFDwP6ngNMcy6kijN78BmPkZWrpSc2X8DPUxzngBeCPL1NzPaX1u7QsG3cf4OTCnU82Gb8E7Ggl+IMJS5nw1v1MoLMTOqe7XeuA3z51snDM01+WFr/qDqw0I8AOJfZWWfS0e7Di18qeoCH6gOdwKfIisraqf1ooL6/+M+rVeZeXOi22+oCDWWJgS2Wx24rpimlTH6w279xf/fjES9cH7L6ZE8KyDHhC0PA/NqLMsOeHKxsDLxK5wLiY67EpXv3FT/bUPkWf4UFLEOGmEbJrsoaZgwxavMjwqcw7Lhfl6AOWcFFCPzcizO5/MtlSDttHzibrnFK9jznlZs3TByzHq9u5bz2+G8jUPcfC/DWhW9mdZkxtFfmRrZOx+LEdBB6y5iTuL10EpCd8sYJ2nQm9jzv9WNpHpfl00Wc4n633UXcZsI+HVlAuZYYLii4fjS0z7OOhFZRLgIcP8vZHaQixSpfuLw20MZT9wvC2kgFMrEbsNZ4t2M0NTPz3jSKFL+8ubcStgdgbWxW4l0zvKVKockiqXtTi22n8h4iSGNMl8Cref+zuVmHr6M+NAAAAAElFTkSuQmCC', 'exregiontuser': jwimgsrc + '/images/jw-img/share/region.png', 'instance': jwimgsrc + '/images/jw-img/share/region.png', 'area': jwimgsrc + '/images/jw-img/share/area.png', // 用户组 'usergroup': jwimgsrc + '/images/jw-img/share/usergroup.png', // 自定义用户组 'customusergroup': jwimgsrc + '/images/jw-img/share/customusergroup.png', // 用户 'user': jwimgsrc + '/images/jw-img/share/usericon.png', // 群组 'groups': jwimgsrc + '/images/jw-img/share/groups.png', // 文件 'files': jwimgsrc + '/images/jw-img/share/files.png', // 问卷 'survey': jwimgsrc + '/images/jw-img/share/survey.png', // h5 'h5': jwimgsrc + '/images/jw-img/share/h5.png', // 考试 'examination': jwimgsrc + '/images/jw-img/share/examination.png', // 课程 'course': jwimgsrc + '/images/jw-img/share/course.png' } this.typeinfo = { 'usergroup': {id:'usergroup',type: 'jw_n_usergroup', name:i18n('label.usergroup.title')}, 'customusergroup': {id:'customusergroup', type: 'jw_n_customusergroup', name:i18n('label-s-groupsend-confirm-cgroup') }, 'dept': {id:'dept', type: 'jw_n_dept', name:i18n('app.team') }, 'role': {id:'role', type: 'jw_n_role', name:i18n('label.stat.role') }, 'post': {id:'post', type: 'jw_n_post', name:i18n('label.position-title') }, 'user': {id:'user', type: 'jw_n_user', name:i18n('label.app-fent-scope-user') } }; this.state = Underscore.extend({ sk: '', nav: [], allScope: {}, nowNav:'', showSelect: false, enterSub: 0, sidbarList: [], select: props.select || [], defaultSelAPI: [], data: [], loading: true, searchList: [] }, props.data, { select: selectD }, { selectAllStatus: false,//全选的初始的状态,用于选用户,当前页面没用户信息 } ) this.backupData = JSON.parse(JSON.stringify(this.state.select)); this.searchTime = null; this.fetchIng = false; this.nowData = {}; this.nav=[]; } // 左侧菜单 _init_nav(nowNav, i) { let self = this; let logo = this.appIcons[i.id] ? this.appIcons[i.id] : ''; return <div className={"share-object-cat-material-i " + (i['customClass'] || '') + ' ' + (nowNav && nowNav["id"] == i["id"] ? ' actives ' : '')} onClick={(e) => self.fetchData(e, i)}> {logo ? <img src={ logo } /> : '' } <span className="ellipsis">{i['name']}</span> { i['help'] ? <i className="icon-share-help"></i> : '' } <i className="icon-share-angle-right"></i> </div> // <img src={i['icon'] || jwimgsrc + '/images/jw-img/share/'+i['id']+'.png'} /> } _init_normal() { let self = this; let data = this.state; let nowNav = data['nowNav'][data['nowNav'].length - 1]; // return (<div className={"sahre-object-l-i " + (this.state.sk && this.state.sk.length != 0 ? 'hide' : '')}> return (<div className={"sahre-object-l-i "}> { _.map(data['nav'], function (i) { return self._init_nav(nowNav, i); }) } </div>) } changeNav(data, index) { let self = this; let navLenght = this.state.nowNav; // self.setState({ // data: fetchList, // // page: resp["data"]["JMObjs"]["page"], // nowNav: [data] // }) } _init_title() { let self = this; let navLenght = this.state.nowNav; let html = []; _.each(this.state.nowNav, function (i, index) { html.push(<span id={i.id} className={'ellipsis ' + (index != navLenght.length - 1 ? 'active' : '')} onClick={(e) => (index != navLenght.length - 1 ? self.changeNav(i, index) : function () { })}>{i["name"]}</span>) if (index != self.state.nowNav.length - 1) { html.push(<span className="active share-object-path-sep">{'>'}</span>) } }) setTimeout(function () { let left = $('.share-object-path-c').width() - $('.share-object-path').width(); if (left > 0) { left = '-' + left } else { left = 0; } $('.share-object-path-c').stop().animate({ marginLeft: left + 'px' }) }, 100) return <div className="share-object-path"><div className={"share-object-path-c "}>{html}</div></div> } _init_item(data,isSearch) { let self = this; let nowNav = this.state['nowNav'][0]; let checked = _.find(self.state.select, { id: data['id'] }) ? true : false; return <div className={"share-object-i specail " + (data['disabled'] ? 'share-object-i-disabled' : '')}> <Checkbox icon={<RadioButtonUncheckedIcon/>} checkedIcon={<RadioButtonCheckedIcon/>} disabled={data['disabled']} checked={checked} onChange={(e) => self.select(e, data)}></Checkbox> <div className={"share-objec-i-c " + (this.state.sk&&this.state.sk!=""&&data.type=='jw_n_user' ? 'share-object-depts-w' : '')} > {data['logo']?<img src={data['logo']} />:''} <span className="ellipsis">{ curLang && curLang == 'en' && data['en_name'] ? data['en_name'] : data['name'] }</span> { this.state.sk&&this.state.sk!=""&&data.type=='jw_n_user' ? <p className="share-object-depts">{data.depts&&data.depts[0]['title']+(data.depts&&data.depts[0]['title']!='' ? ',' : '')+(data.depts&&data.depts[0]['name'])}</p> : '' } </div> </div> } specailSelect(checked, data) { let datas = this.state; let selectList = this.state.select; if (data['disabled'] || data['default_flag'] == 1) { return } //代码有点复杂,稍后整理下; if (datas['maxSelect']) { //优化 if (datas['maxSelect'] == '1') { if (checked) { selectList = [data]; } else { selectList = []; } } else { if (selectList.length >= datas['maxSelect']) { if (checked) { selectList.shift(); selectList.push(data); } else { let nowSelectList = []; _.each(selectList, function (i) { if (i['id'] != data['id']) { nowSelectList.push(i) } }) selectList = nowSelectList; } } else { if (checked) { selectList.push(data); } else { let nowSelectList = []; _.each(selectList, function (i) { if (i['id'] != data['id']) { nowSelectList.push(i) } }) selectList = nowSelectList; } } } } else { if (checked) { selectList.push(data); } else { let nowSelectList = []; _.each(selectList, function (i) { if (i['id'] != data['id']) { nowSelectList.push(i) } }) selectList = nowSelectList; } } this.setState({ select: selectList }) } select(e, data) { let datas = this.state; let checked = e.target.checked; if (!checked) { if (this.state.cantRemoveData && this.state.cantRemoveData.length != 0) { if (_.findWhere(this.state.cantRemoveData, { id: data['id'] })) { return } } } let selectList = this.state.select; //代码有点复杂,稍后整理下; if (datas['maxSelect']) { //优化 if (datas['maxSelect'] == '1') { if (checked) { selectList = [data]; } else { selectList = []; } } else { if (selectList.length >= datas['maxSelect']) { if (checked) { selectList.shift(); selectList.push(data); } else { let nowSelectList = []; _.each(selectList, function (i) { if (i['id'] != data['id']) { nowSelectList.push(i) } }) selectList = nowSelectList; } } else { if (checked) { selectList.push(data); } else { let nowSelectList = []; _.each(selectList, function (i) { if (i['id'] != data['id']) { nowSelectList.push(i) } }) selectList = nowSelectList; } } } } else { if (checked) { selectList.push(data); } else { let nowSelectList = []; _.each(selectList, function (i) { if (i['id'] != data['id']) { nowSelectList.push(i) } }) selectList = nowSelectList; } } this.setState({ select: selectList }) } selectAll(e) { let self = this; let checked = e.target.checked; let selectList = this.state.select; let filterList; if (this.props.isJssdk) { filterList = _.filter(this.state.data, i => i.default_flag == 0); } else { filterList = this.state.data; } let nowData = this.state.nowNav[0]; let newfilterList = []; if (nowData['id'] == 'dept' || nowData['id'] == 'mydept' || (nowData['type']&&nowData['type'].indexOf('dept')!=-1)) { if (nowData['flag']) { if (nowData.flag == 'onlyuser') { filterList = _.filter(filterList, function (i) { return (i['type'] == 'jw_n_user') }) } else if (nowData.flag == 'onydept') { filterList = _.filter(filterList, function (i) { return (i['type'] == 'jw_n_dept' || i['type'] == 'jw_n_group') }) } } } if (checked) { selectList = selectList.concat(filterList) } else { let nowList = []; _.each(selectList, function (i) { if (_.find(filterList, { id: i['id'] })) { } else { nowList.push(i) } }) selectList = nowList; } selectList = Underscore.uniq(selectList, function (i) { return i['id'] }) selectList = _.filter(selectList, function (i) { return typeof (i['disabled']) == 'undefined' || !i['disabled'] }) this.setState({ select: selectList, selectAllStatus: !this.state.selectAllStatus }) } unSelectAll(e) { let list = []; if (this.state.cantRemoveData && this.state.cantRemoveData.length != 0) { list = this.state.cantRemoveData } this.setState({ select: list }) } inputSearch(e) { console.log("eeeeeeeeee:::::",e.target.value) let self = this; const text = e.target.value.trim(); // console.log('inputSearch text:',text) let searchList = []; clearTimeout(this.searchTime); this.searchTime = setTimeout(function () { searchList = _.filter(self.state.data,(item)=>{ // console.log(item,item.name.indexOf(text)!=-1) if(item.name.indexOf(text)!=-1||(item.employee_id&&item.employee_id.indexOf(text)!=-1)||(item.other_account&&item.other_account.indexOf(text)!=-1)){ return item; } }) self.setState({ sk: text, searchList: searchList }) }, 200) } fetchData(e, data, page) { let self = this; // let datas = this.state['page']; // if (this.fetchIng) { // return // } e.stopPropagation() self.setState({ data: this.state.allScope[data.id], nowNav: [data], sk: '', searchList: [] }) this.nowData = data; } showSelect(data) { this.setState({ showSelect: data }) } countSelectAll() { let self = this; let data = this.state; let selectAllNum = 0; let filterData = []; let parentNav = this.state['nowNav'][0]; if (parentNav && parentNav['id'] == 'dept') { if (parentNav['flag']) { if (parentNav['flag'] == 'onlyuser') { filterData = Underscore.filter(data['data'], function (i) { return i['type'] == 'jw_n_user' }) } else if (this.nowData['flag'] == 'onlydept') { filterData = Underscore.filter(data['data'], function (i) { return i['type'] == 'jw_n_dept' || i['type'] == 'jw_n_group' }) } else { filterData = data['data'] } }else{ filterData = data['data'] } } else { filterData = data['data'] } _.each(filterData, function (i) { if (Underscore.findWhere(data['select'], { id: i['id'] })) { selectAllNum++; } }) let jsDeData = _.filter(filterData, i => i.default_flag == 0); if (filterData.length == selectAllNum && selectAllNum != 0) { return true } else { return false } } combineSearch(){ let self = this; return ( <div className="share-object-normal"> <div className={"search-list " + (this.state.s && this.state.s.length != 0 ? 'hide' : '')} > { this.state.searchInput ? <div className="share-object-search"> <i className="icon-search-s"></i> <Input className="has-border" placeholder={COMPONENT_DICT('label.business.shareobj.search')} onChange={(e) => this.inputSearch(e)} /> </div> : '' } </div> <div className={"share-object-list search-list " + (this.state.sk && this.state.sk.length != 0 ? '' : 'hide')}> { _.map(this.state.searchList, function (i) { return self._init_item(i,true) }) } {this.state.searchList&&this.state.searchList.length ? '' : <div className="serach-empty"> <div className="search-content"> <div className="search-content-empty"></div> <div>{COMPONENT_DICT('label.business.shareobj.no.result')}</div> </div> </div>} </div> </div> ) } render() { let self = this; let data = this.state; let selectAllActive = this.countSelectAll(); let cusStyle = ''; if(this.props.data.customClass=='thapp-folder'){ cusStyle = 'thapp-folder'; } return ( <div className={'share-object-c local-share-obj-c' + cusStyle}> <div className="share-object-close"></div> { data['title'] ? <div className="share-object-title">{data['title']}</div> : '' } { this.state.loading==true ? <div className="share-object-main "> <Loading show={true}/> </div> : ( this.state.emptyScope==true ? <div className="share-object-main "> <div className="share-object-scope-error">{i18n('tip.sharescope.invalid')}</div> </div> : <div className="share-object-main "> <div className="share-object-l"> <div className={"sahre-object-l-i" } > { this._init_normal() } </div> </div> <div className="share-object-r"> { this.combineSearch() } {/* {console.log("(this.state.showSelect||this.state.sk!='') :",(this.state.showSelect||this.state.sk!='') )} */} <div className={"share-object-normal " + ((this.state.showSelect||this.state.sk!='') ? 'hide' : '')}> {this._init_title()} { data['maxSelect']? '' : (this.state.data.length!=0?<div className={"share-object-select-all " + (data['nav'][0].id=='dictParent'||data['nav'][0].id=='apps'||data['data'][0].type=='jw_n_usergroup_class' ? 'hide' : '')}> <Checkbox icon={<RadioButtonUncheckedIcon/>} checkedIcon={<RadioButtonCheckedIcon/>} checked={selectAllActive} onChange={(e) => this.selectAll(e)}></Checkbox> <span>{COMPONENT_DICT('label.business.shareobj.selected.all')}</span> </div>:"") } <div className={"share-object-list " + (this.state.data.length!=0&&data['data'][0].type=='jw_n_usergroup_class' ? 'share-object-list-usergroup' : '')}> { _.map(this.state.data, function (i) { return self._init_item(i,false) }) } {this.state.data.length ? '' : <div className="serach-empty"> <div className="search-content"> <div className="search-content-empty"></div> <div>{COMPONENT_DICT('label.business.shareobj.no.data')}</div> </div> </div>} </div> </div> <div className={"share-object-selectlist " + ((this.state.showSelect) ? '' : 'hide')}> <div className="share-object-path"><span>{COMPONENT_DICT('label.business.shareobj.selected.obj1')}</span><i className="icon-share-close" onClick={(e) => this.showSelect(false)}></i></div> <div className="share-object-list"> { _.map(this.state.select, function (i) { return self._init_item(i,true) }) } </div> </div> </div> </div> ) } <div className="share-object-footer"> { data['maxSelect'] && data['maxSelect'] == '1' ? (data['select'].length != 0 && JSON.stringify(data['select'][0])!="{}"? <div className="share-object-num"> <span onClick={(e) => this.showSelect(true)}> {COMPONENT_DICT('label.business.shareobj.selected')} </span> <span className="share-object-num-name">{this.state.select[0]['name']}</span> </div> : <div className="share-object-no-num">{i18n('tip.no.object.selected')}</div>) : <div className="share-object-num"><span onClick={(e) => this.showSelect(true)}>{COMPONENT_DICT('label.business.shareobj.selected.obj').replace('{num}',this.state.select.length)}</span>{this.state.select.length != 0 ? <span onClick={(e) => this.unSelectAll(e)}>{i18n('label.objselect-unselect-all')}</span> : ''}</div> } { data['button'] ? <div className="share-object-btn"> {data['button']} </div> : <div className="share-object-btn"> { this.state.loading==true ? <Button className="share-object-btn-submit" disabled >{COMPONENT_DICT('label.business.shareobj.save')}</Button> : <Button className="share-object-btn-submit" onClick={(e) => this.save()}>{COMPONENT_DICT('label.business.shareobj.save')}</Button> } <Button className="share-object-btn-cancel" onClick={(e) => this.cancel()}>{COMPONENT_DICT('label.business.shareobj.cancel')}</Button> </div> } </div> </div> ) } save() { let select = this.state.select; let backupData = this.backupData let add = []; let remove = []; // let bodyNewStyle = $("body").attr('style').replace('overflow: hidden;','').replace('overflow:hidden;',''); // $("body").attr('style',bodyNewStyle) _.each(select,function(i){ if(_.findWhere(backupData,{id:i['id']})){ }else{ add.push(i); } }) _.each(backupData,function(i){ if(_.findWhere(select,{id:i['id']})){ }else{ remove.push(i); } }) this.props.events.emit('save',select,{ add:add, remove:remove }); this.props.events.emit('cancel'); typeof(this.props.closeDialog)=='function' && this.props.closeDialog(); } cancel() { let select = this.state.select; let backupData = this.backupData let add = []; let remove = []; _.each(select,function(i){ if(_.findWhere(backupData,{id:i['id']})){ }else{ add.push(i); } }) _.each(backupData,function(i){ if(_.findWhere(select,{id:i['id']})){ }else{ remove.push(i); } }) this.props.events.emit('cancel', select,{ add:add, remove:remove }); typeof(this.props.closeDialog)=='function' && this.props.closeDialog(); } combineData(scope){ let self = this; let simpleshareData = {}; let usergrouplist = [], deptlist = [], rolelist = [], postlist = [], userlist = [], customusergrouplist=[]; let share_scope = scope; // 说明没有数据 if(!share_scope) return simpleshareData; // 数组,需要前端聚合分组 if(Array.isArray(share_scope)){ if(share_scope.length==0) return simpleshareData; // 新版分享范围数据结构中提取出所有的对象 let objs = []; let objIDs=[]; _.each(share_scope, function(item){ if(item.objs&&item.objs.length>0){ objIDs = _.pluck(objs,'id'); _.each(item.objs,function(obj){ if(_.indexOf(objIDs,obj.id)==-1) objs.push(obj); }) } }) share_scope = objs; _.each(share_scope, function(item){ // console.log('item,',item) if(item.type=='jobtype') item.type = 'jw_n_post'; switch(item.type){ case 'jw_n_user': userlist.push(item); break; case 'jw_n_dept': deptlist.push(item); break; case 'jw_n_usergroup': usergrouplist.push(item); break; case 'jw_n_role': rolelist.push(item); break; case 'jw_n_post': postlist.push(item); break; case 'jw_n_customusergroup': customusergrouplist.push(item); break; default: break; } }) // 对象,后台聚合过一遍了 }else{ var scopelenth = 0; _.each(share_scope,(item,key)=>{ scopelenth = scopelenth+(item&&item.length?item.length:0); switch(key){ case 'jw_n_user': userlist=_.union(userlist,item); break; case 'jw_n_dept': deptlist=_.union(deptlist,item); break; case 'jw_n_usergroup': usergrouplist=_.union(usergrouplist,item); break; case 'jw_n_role': rolelist=_.union(rolelist,item); break; case 'jw_n_post': postlist=_.union(postlist,item); break; case 'jw_n_customusergroup': customusergrouplist=_.union(customusergrouplist,item); break; default: break; } }) if(scopelenth==0) return simpleshareData; } // 把可见的对象按照simpleshare组件的数据重组 this.nav = []; if(usergrouplist.length>0){ simpleshareData.usergroup = usergrouplist; this.nav.push({id:'usergroup'}); } if(deptlist.length>0){ simpleshareData.dept = deptlist; this.nav.push({id:'dept'}); } if(rolelist.length>0){ simpleshareData.role = rolelist; this.nav.push({id:'role'}); } if(postlist.length>0){ simpleshareData.post = postlist; this.nav.push({id:'post'}); } if(userlist.length>0){ simpleshareData.user = userlist; this.nav.push({id:'user'}); } if(customusergrouplist.length>0){ simpleshareData.customusergroup = customusergrouplist; this.nav.push({id:'customusergroup'}); } let newNav = []; _.each(this.nav,function(item){ self.typeinfo[item.id] = _.extend(self.typeinfo[item.id],item); newNav.push(self.typeinfo[item.id]); }) this.focusNav = _.findWhere(this.nav,{focus:true}) if(this.focusNav==undefined) this.focusNav = this.nav[0]; this.nav = newNav; return simpleshareData; } componentDidMount() { let self = this; let nowNav = this.props.data.nav.length && this.props.data.nav[0]; let showType = this.props.data.showType; // 取数据 request(this.props.data.sharescopeUrl, { method: 'GET' }) .then(function (resp) { // self.fetchIng = false; let user_scope = resp["data"]["JMSubscription"]; let params = { loading: false } // 对数据重组 if(user_scope.scope_type=='custom'){ // params.data params.allScope = self.combineData(user_scope.scope); params.nav = self.nav; if(self.nav.length>0){ params.nowNav = [self.nav[0]]; params.data = params.allScope[self.nav[0].id]; }else{ params.emptyScope = true; } } self.setState(params) }) } } class LocalShareObj extends Component { constructor(props) { super(props); this.state = { open: true }; } countTop() { let clientHeight = document.documentElement.clientHeight || document.body.clientHeight; if (this.container.height() < clientHeight) { $('#' + this.props.containerId).css({ top: (clientHeight - this.container.height()) / 2 + 'px' }) } else { } } closeDialog(){ this.setState({open:false}); } render() { let modalData = this.props.modal || {}; let modal = _.extend({}, { destroyOnClose: true, getContainer: () => document.getElementById(this.props.containerId), title: null, visible: true, footer: null, onCancel: (e) => this.props.close(e), }, modalData); return (<div className={"dialog-c "} id={this.props.containerId}> <Dialog onClose={this.handleClose} aria-labelledby="simple-dialog-title" open={this.state.open} className={'simple-dialog dialog-child-'+this.props.containerId} maxWidth={false} PaperProps={{ style:{ width:modalData && modalData.style && modalData.style.width ? modalData.style.width : '700px', maxHeight:"none", height:"560px", display:"block", margin:"0" } }} > <LocalShareObjContainer {...this.props} bodyHeight={{}} events={this.props.events} closeDialog={ this.closeDialog.bind(this) }></LocalShareObjContainer> </Dialog> </div>) } componentDidMount() { let self = this; let datas = this.props.modal || {}; let container = ($('#' + this.props.containerId)); this.container = container; } } export default LocalShareObj