From d38dc481492878c04ddf2d6bc2e9bf7d44c57fd7 Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期一, 23 十二月 2019 18:29:38 +0800 Subject: [PATCH] 2019-12-23 --- src/components/sidemenu/editthdmenu/index.jsx | 203 +++++++++++++++++++++++++++++++------------------- 1 files changed, 124 insertions(+), 79 deletions(-) diff --git a/src/components/sidemenu/editthdmenu/index.jsx b/src/components/sidemenu/editthdmenu/index.jsx index 5b14802..3c26b4e 100644 --- a/src/components/sidemenu/editthdmenu/index.jsx +++ b/src/components/sidemenu/editthdmenu/index.jsx @@ -10,6 +10,7 @@ import Utils from '@/utils/utils.js' import DragElement from '../menuelement' import asyncLoadComponent from '@/utils/asyncLoadComponent' +import { sysTemps } from '@/utils/option.js' import Api from '@/api' import zhCN from '@/locales/zh-CN/header.js' import enUS from '@/locales/en-US/header.js' @@ -23,56 +24,56 @@ const { confirm } = Modal const { TabPane } = Tabs const { Search } = Input -const illust = { + +const illust = { // 妯℃澘鍥剧墖锛岀敤浜庡凡浣跨敤妯℃澘 CommonTable: nortable } -let previewList = null + +let previewList = null // 鍒濆鑿滃崟鍒楄〃 class EditMenu extends Component { static propTpyes = { - menulist: PropTypes.any, - supMenuList: PropTypes.array, - supMenu: PropTypes.object, - reload: PropTypes.func, - exitEdit: PropTypes.func + reload: PropTypes.func, // 鑿滃崟淇敼鍚庡埛鏂� + menulist: PropTypes.any, // 涓夌骇鑿滃崟鍒楄〃 + exitEdit: PropTypes.func, // 閫�鍑虹紪杈戠姸鎬� + supMenu: PropTypes.object, // 瀵瑰簲鐨勪笂绾ц彍鍗� + supMenuList: PropTypes.array // 涓婄骇鑿滃崟鍒楄〃锛岀敤浜庝笁绾ц彍鍗曞垏鎹笂绾ц彍鍗� } state = { dict: (!localStorage.getItem('lang') || localStorage.getItem('lang') === 'zh-CN') ? zhCN : enUS, - show: true, - thawmenulist: null, // 宸插喕缁撶殑浜岀骇鑿滃崟 - visible: null, - title: '', - type: '', - tabview: '', // 閫夋嫨妯℃澘绐楀彛锛坱emplate锛夈�佸熀纭�琛ㄦ牸閰嶇疆锛圕ommonTable锛� - formlist: null, + show: true, // 鎺у埗鑿滃崟鍒锋柊 + thawmenulist: null, // 宸插喕缁撶殑浜岀骇鑿滃崟 + type: '', // 鎿嶄綔绫诲瀷锛屾柊寤烘垨缂栬緫鑿滃崟 + tabview: '', // 閫夋嫨妯℃澘绐楀彛锛坱emplate锛夈�佸熀纭�琛ㄦ牸閰嶇疆锛圕ommonTable锛夈�佽〃鍗曪紙Modal锛夈�佸瓙琛紙SubTable锛� editMenu: null, // 缂栬緫鑿滃崟 editAction: null, // 缂栬緫鎸夐挳 editTab: null, // 缂栬緫鏍囩 thawMvisible: false, // 瑙i櫎鍐荤粨妯℃�佹 confirmLoading: false, // 鎻愪氦涓�傘�傘�� selectTemp: '', // 閫夋嫨妯℃澘 - usedTemplates: null, - menuConfig: '', - tempSearchKey: '', - loading: false, - preview: null, - pretemplate: null, - baseTemplates: [{ - title: '鍩虹琛ㄦ牸', - type: 'CommonTable', - url: illust['CommonTable'], - baseconfig: '' - }] + usedTemplates: null, // 宸蹭娇鐢ㄦā鏉垮垪琛� + tempSearchKey: '', // 鑿滃崟鍚嶇О杩囨护鍊� + loading: false, // 缂栬緫鑿滃崟鎴栦娇鐢ㄥ凡浣跨敤妯℃澘鏃讹紝鑾峰彇閰嶇疆淇℃伅 + preview: null, // 鍥剧墖棰勮url + pretemplate: null, // 棰勮妯℃澘 + sysTemplates: sysTemps // 绯荤粺妯℃澘 } + /** + * @description 鑿滃崟椤哄簭鏀瑰彉鏃讹紝淇濆瓨涓棿鐘舵�� + */ handlePreviewList = (List) => { - // 鑿滃崟椤哄簭鏀瑰彉鏃讹紝淇濆瓨涓棿鐘舵�� previewList = List } + /** + * @description 鑿滃崟缂栬緫锛氫慨鏀广�佸垹闄� + * 1銆佽彍鍗曚慨鏀规垨鍒犻櫎鏃讹紝鍏堟煡鐪嬭彍鍗曢『搴忔槸鍚︽敼鍙� + * 2銆佽彍鍗曞垹闄� + * 3銆佽彍鍗曠紪杈戯紝鏌ヨ鑿滃崟閰嶇疆淇℃伅锛屼俊鎭纭紝杩涘叆瀵瑰簲缂栬緫椤甸潰 + */ handleMenu = (menu) => { - // 鑿滃崟缂栬緫锛氫慨鏀广�佸垹闄� const _this = this if (previewList && !is(fromJS(previewList), fromJS(this.state.subMenulist))) { notification.warning({ @@ -122,25 +123,23 @@ try { _LongParam = JSON.parse(_LongParam) } catch (e) { - _LongParam = { - type: 'system', - setting: {}, - search: [], - action: [], - columns: [] - } + _LongParam = '' } + _menu.LongParam = _LongParam _menu.ParentID = this.props.supMenu.MenuID // 妫�娴嬫ā鏉挎槸鍚﹀瓨鍦� - let _Template = this.state.baseTemplates.filter(temp => temp.type === _menu.PageParam.Template) + let _Template = this.state.sysTemplates.filter(temp => temp.type === _menu.PageParam.Template) + this.setState({ type: 'edit', editMenu: _menu, loading: false, tabview: _Template.length > 0 ? _menu.PageParam.Template : 'template' }) + + // 妯℃澘涓嶅瓨鍦ㄦ椂閿欒鎻愮ず if (_Template.length === 0) { notification.warning({ top: 92, @@ -320,57 +319,104 @@ }) } - useTemplate = (template) => { + useTemplate = (template, useType) => { const { type, editMenu } = this.state - // 閫夋嫨妯℃澘锛氭坊鍔犺彍鍗曟椂 - if (type === 'add') { - this.setState({ - tabview: template.type, - editMenu: { - MenuID: Utils.getuuid(), - MenuName: '', - MenuNo: '', - id: this.props.menulist.length, - src: '', - text: '', - type: template.type, - PageParam: {OpenType: 'newtab', Template: template.type}, - LongParam: template.baseconfig, - ParentID: this.props.supMenu.MenuID + new Promise(resolve => { + if (useType === 'sys') { + resolve(true) + } else { + let param = { + func: 'sPC_Get_LongParam', + MenuID: template.uuid } - }) - } else { - let _PageParam = {OpenType: editMenu.PageParam.OpenType || 'newtab', Template: template.type} + this.setState({ + loading: true + }) - this.setState({ - tabview: template.type, - editMenu: {...editMenu, LongParam: template.baseconfig, PageParam: _PageParam, type: template.type} - }) - } - document.getElementById('root').style.overflowY = 'hidden' + Api.getSystemConfig(param).then(result => { + if (!result.status) { + notification.warning({ + top: 92, + message: result.message, + duration: 10 + }) + resolve(false) + } else { + let _config = '' + if (result.LongParam) { + try { + _config = window.decodeURIComponent(window.atob(result.LongParam)) + _config = JSON.parse(_config) + _config.type = 'user' + } catch (e) { + _config = '' + } + } + + if (_config) { + template.baseconfig = _config + resolve(true) + } else { + notification.warning({ + top: 92, + message: '妯℃澘淇℃伅鑾峰彇澶辫触锛�', + duration: 10 + }) + resolve(false) + } + } + }) + } + }).then(res => { + if (!res) { + this.setState({ + loading: false + }) + return + } + + // 閫夋嫨妯℃澘锛氭坊鍔犺彍鍗曟椂 + if (type === 'add') { + this.setState({ + tabview: template.type, + loading: false, + editMenu: { + MenuID: Utils.getuuid(), + MenuName: '', + MenuNo: '', + id: this.props.menulist.length, + src: '', + text: '', + type: template.type, + PageParam: {OpenType: 'newtab', Template: template.type}, + LongParam: template.baseconfig, + ParentID: this.props.supMenu.MenuID + } + }) + } else { + let _PageParam = {OpenType: editMenu.PageParam.OpenType || 'newtab', Template: template.type} + + this.setState({ + loading: false, + tabview: template.type, + editMenu: {...editMenu, LongParam: template.baseconfig, PageParam: _PageParam, type: template.type} + }) + } + document.getElementById('root').style.overflowY = 'hidden' + }) } getUsedTemplate = () => { - Api.getSystemConfig({func: 'sPC_Get_UserTemp'}).then(res => { + Api.getSystemConfig({func: 'sPC_Get_UserTemp', TypeCharTwo: 'menu'}).then(res => { this.setState({ usedTemplates: res.UserTemp.map(temp => { - let _config = '' - if (temp.LongParam) { - _config = window.decodeURIComponent(window.atob(temp.LongParam)) - try { - _config = JSON.parse(_config) - _config.type = 'user' - } catch (e) { - _config = '' - } - } return { + uuid: temp.MenuID, title: temp.MenuName, type: temp.Template, - url: illust[temp.Template], - baseconfig: _config + url: illust[temp.Template] } }) }) @@ -401,7 +447,6 @@ }) } } else if (type === 'tab') { - console.log(item) if (item.type === 'SubTable') { this.setState({ editMenu: originMenu, @@ -478,14 +523,14 @@ {this.state.tabview === 'template' && <Tabs defaultActiveKey="1"> <TabPane tab="绯荤粺妯℃澘" key="1"> <Row> - {this.state.baseTemplates.map(template => { + {this.state.sysTemplates.map(template => { return ( <Col key={template.type} span={8}> <Card title={template.title}> <img onClick={() => {this.previewPicture(template)}} src={template.url} alt=""/> <div className="card-operation"> - <Button type="primary" onClick={() => {this.useTemplate(template)}}>浣跨敤妯℃澘</Button> + <Button type="primary" onClick={() => {this.useTemplate(template, 'sys')}}>浣跨敤妯℃澘</Button> </div> </Card> </Col> @@ -508,7 +553,7 @@ title={template.title}> <img onClick={() => {this.previewPicture(template)}} src={template.url} alt=""/> <div className="card-operation"> - <Button type="primary" onClick={() => {this.useTemplate(template)}}>浣跨敤妯℃澘</Button> + <Button type="primary" onClick={() => {this.useTemplate(template, 'user')}}>浣跨敤妯℃澘</Button> </div> </Card> </Col> @@ -561,7 +606,7 @@ {!this.state.thawmenulist && <Spin style={{marginLeft: 'calc(50% - 22px)', marginTop: '70px', marginBottom: '70px'}} size="large" />} {this.state.thawmenulist && <TransferForm ref="trawmenu" dict={this.state.dict} menulist={this.state.thawmenulist}/>} </Modal> - {this.state.loading && <Spin style={{position: 'fixed', left: 'calc(50vw - 22px)', top: 'calc(50vh - 70px)'}} size="large" />} + {this.state.loading && <Spin className="loading-thdmenu" size="large" />} </div> ) } -- Gitblit v1.8.0