From cb9ade2afd2a367ad767bc605ab7086c695dd010 Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期五, 09 十二月 2022 15:53:32 +0800 Subject: [PATCH] 2022-12-09 --- src/menu/components/carousel/prop-card/index.jsx | 289 ++++++++++++++++++++++++++------------------------------- 1 files changed, 133 insertions(+), 156 deletions(-) diff --git a/src/menu/components/carousel/prop-card/index.jsx b/src/menu/components/carousel/prop-card/index.jsx index 1795efc..8efdbe0 100644 --- a/src/menu/components/carousel/prop-card/index.jsx +++ b/src/menu/components/carousel/prop-card/index.jsx @@ -1,12 +1,12 @@ import React, {Component} from 'react' import PropTypes from 'prop-types' import { is, fromJS } from 'immutable' -import { Popover, Modal, notification, Carousel } from 'antd' -import { PlusOutlined, SettingOutlined, EditOutlined, ToolOutlined, DeleteOutlined, FontColorsOutlined } from '@ant-design/icons' +import { Popover, Modal, Carousel } from 'antd' +import { PlusOutlined, SettingOutlined, EditOutlined, ToolOutlined, DeleteOutlined, FontColorsOutlined, ClockCircleOutlined } from '@ant-design/icons' import asyncComponent from '@/utils/asyncComponent' import asyncIconComponent from '@/utils/asyncIconComponent' -import { resetStyle } from '@/utils/utils-custom.js' +import { resetStyle, getTables } from '@/utils/utils-custom.js' import MKEmitter from '@/utils/events.js' import Utils from '@/utils/utils.js' import getWrapForm from '../data-card/options' @@ -14,10 +14,11 @@ const SettingComponent = asyncIconComponent(() => import('@/menu/datasource')) const NormalForm = asyncIconComponent(() => import('@/components/normalform')) +const NormalHeader = asyncComponent(() => import('@/menu/components/share/normalheader')) const CardSimpleComponent = asyncComponent(() => import('@/menu/components/card/cardsimplecomponent')) const CopyComponent = asyncIconComponent(() => import('@/menu/components/share/copycomponent')) const PasteComponent = asyncIconComponent(() => import('@/menu/components/share/pastecomponent')) -const LogComponent = asyncIconComponent(() => import('@/menu/components/share/logcomponent')) +const ClockComponent = asyncIconComponent(() => import('@/menu/components/share/clockcomponent')) const UserComponent = asyncIconComponent(() => import('@/menu/components/share/usercomponent')) const { confirm } = Modal @@ -30,7 +31,6 @@ } state = { - appType: sessionStorage.getItem('appType'), card: null, back: false } @@ -42,18 +42,15 @@ let _card = { uuid: card.uuid, type: card.type, - tabId: card.tabId || '', - parentId: card.parentId || '', format: 'object', // 缁勪欢灞炴�� - 鏁版嵁鏍煎紡 pageable: false, // 缁勪欢灞炴�� - 鏄惁鍙垎椤� switchable: false, // 缁勪欢灞炴�� - 鏁版嵁鏄惁鍙垏鎹� - dataName: card.dataName || '', width: card.width || 24, name: card.name, subtype: card.subtype, setting: { }, - wrap: { name: card.name, width: card.width || 24, datatype: 'static', autoplay: 'false', dots: 'true' }, - style: { borderWidth: '1px', borderColor: '#e8e8e8', marginLeft: '0px', marginRight: '0px', marginTop: '8px', marginBottom: '8px', height: '300px' }, + wrap: { name: card.name, width: card.width || 24, datatype: 'static', autoplay: 'false', dots: 'true', height: '300px' }, + style: { borderWidth: '1px', borderColor: '#e8e8e8', marginLeft: '0px', marginRight: '0px', marginTop: '8px', marginBottom: '8px' }, columns: [], scripts: [], subcards: [{ @@ -61,8 +58,7 @@ setting: {}, style: {}, elements: [], - }], - btnlog: [], + }] } if (card.config) { @@ -85,21 +81,20 @@ return scard }) } + + this.updateComponent(_card) + } else { + let _card = fromJS(card).toJS() + + if (!_card.wrap.height && _card.style.height) { // 鍏煎 + _card.wrap.height = _card.style.height + } + delete _card.style.height + this.setState({ card: _card }) - this.props.updateConfig(_card) - } else { - this.setState({ - card: fromJS(card).toJS() - }) } - } - - componentDidMount () { - MKEmitter.addListener('submitStyle', this.getStyle) - MKEmitter.addListener('logButton', this.logButton) - MKEmitter.addListener('submitComponentStyle', this.updateComponentStyle) } shouldComponentUpdate (nextProps, nextState) { @@ -113,54 +108,84 @@ this.setState = () => { return } - MKEmitter.removeListener('submitStyle', this.getStyle) - MKEmitter.removeListener('logButton', this.logButton) - MKEmitter.removeListener('submitComponentStyle', this.updateComponentStyle) - } - - updateComponentStyle = (parentId, keys, style) => { - const { card } = this.state - - if (card.uuid !== parentId) return - - let subcards = card.subcards.map(item => { - if (keys.includes(item.uuid)) { - item.style = {...item.style, ...style} - } - return item - }) - - this.setState({card: {...card, subcards: []}}, () => { - this.updateComponent({...card, subcards: subcards}) - }) - } - - logButton = (id, item) => { - const { card } = this.state - - if (id !== card.uuid) return - - let btnlog = card.btnlog || [] - btnlog.push(item) - - this.setState({ - card: {...card, btnlog} - }) - this.props.updateConfig({...card, btnlog}) } /** * @description 鍗$墖琛屽灞備俊鎭洿鏂帮紙鏁版嵁婧愶紝鏍峰紡绛夛級 */ - updateComponent = (component) => { + updateComponent = (card) => { + card.width = card.wrap.width + card.name = card.wrap.name + + if (window.GLOB.styling && card.errors) { // 鏍峰紡淇敼鏃朵笉鍋氱瓫鏌� + this.setState({ + card: card + }) + + this.props.updateConfig(card) + return + } + + card.errors = [] + + if (card.subcards.length === 0) { + card.errors.push({ level: 0, detail: '鍗$墖涓嶅彲涓虹┖锛�'}) + } + + if (card.wrap.datatype === 'static') { + card.$tables = getTables(card) + card.subcards.forEach(item => { + item.elements.forEach(cell => { + if (cell.eleType === 'button') { + if (cell.OpenType === 'pop' || (cell.OpenType === 'funcbutton' && cell.execMode === 'pop')) { + if (!cell.modal || cell.modal.fields.length === 0) { + card.errors.push({ level: 1, detail: `鎸夐挳鈥�${cell.label}鈥濅腑琛ㄥ崟灏氭湭娣诲姞`}) + } + } + } else if (cell.datatype === 'dynamic' && cell.field) { + card.errors.push({ level: 1, detail: `鍗$墖涓姩鎬佸瓧娈碘��${cell.field}鈥濇棤鏁坄}) + } + }) + }) + } else { + let columns = card.columns.map(c => c.field) + + if (card.setting.interType === 'system' && card.setting.execute !== 'false' && !card.setting.dataresource) { + card.errors.push({ level: 0, detail: '鏈缃暟鎹簮锛�'}) + } else if (card.setting.interType === 'system' && card.setting.execute === 'false' && card.scripts.filter(script => script.status !== 'false').length === 0) { + card.errors.push({ level: 0, detail: '鏁版嵁婧愪腑鏃犲彲鐢ㄨ剼鏈紒'}) + } else if (!card.setting.primaryKey) { + card.errors.push({ level: 0, detail: '鏈缃富閿紒'}) + } else if (!columns.includes(card.setting.primaryKey)) { + card.errors.push({ level: 0, detail: '涓婚敭宸插け鏁堬紒'}) + } else if (!card.setting.supModule) { + card.errors.push({ level: 0, detail: '鏈缃笂绾х粍浠讹紒'}) + } + + if (card.errors.length === 0) { + card.$tables = getTables(card) + } + + card.subcards.forEach((item, i) => { + item.elements.forEach(cell => { + if (cell.eleType === 'button') { + if (cell.OpenType === 'pop' || (cell.OpenType === 'funcbutton' && cell.execMode === 'pop')) { + if (!cell.modal || cell.modal.fields.length === 0) { + card.errors.push({ level: 1, detail: `鎸夐挳鈥�${cell.label}鈥濅腑琛ㄥ崟灏氭湭娣诲姞`}) + } + } + } else if (cell.datatype === 'dynamic' && cell.field && !columns.includes(cell.field)) { + card.errors.push({ level: 1, detail: `鍗$墖涓姩鎬佸瓧娈碘��${cell.field}鈥濇棤鏁坄}) + } + }) + }) + } + this.setState({ - card: component + card: card }) - component.width = component.wrap.width - component.name = component.wrap.name - - this.props.updateConfig(component) + this.props.updateConfig(card) } /** @@ -174,16 +199,13 @@ return item }) - this.setState({card}) - - this.props.updateConfig(card) + this.updateComponent(card) } /** * @description 鍗曚釜鍗$墖淇℃伅鏇存柊 */ deleteCard = (cell) => { - const { appType } = this.state let card = fromJS(this.state.card).toJS() let _this = this @@ -192,26 +214,7 @@ onOk() { card.subcards = card.subcards.filter(item => item.uuid !== cell.uuid) - if (card.btnlog) { - card.btnlog = card.btnlog.filter(c => c.$parentId !== cell.uuid) - } - - _this.setState({card}) - _this.props.updateConfig(card) - - if (appType === 'mob') return - - let uuids = [] - - cell.elements && cell.elements.forEach(c => { - if (c.eleType !== 'button' || (appType === 'pc' && c.OpenType !== 'popview')) return - - uuids.push(c.uuid) - }) - - if (uuids.length === 0) return - - MKEmitter.emit('delButtons', uuids) + _this.updateComponent(card) }, onCancel() {} }) @@ -220,21 +223,13 @@ changeStyle = () => { const { card } = this.state - MKEmitter.emit('changeStyle', [card.uuid], ['height', 'background', 'border', 'padding', 'margin', 'shadow'], card.style) + MKEmitter.emit('changeStyle', ['background', 'border', 'padding', 'margin', 'shadow', 'clear'], card.style, this.getStyle) } - getStyle = (comIds, style) => { - const { card } = this.state - - if (comIds.length !== 1 || comIds[0] !== card.uuid) return - - let _card = {...card, style} - - this.setState({ - card: _card - }) + getStyle = (style) => { + let _card = {...this.state.card, style} - this.props.updateConfig(_card) + this.updateComponent(_card) } addCard = () => { @@ -257,54 +252,8 @@ } card.subcards.push(newcard) - - this.setState({card}) - this.props.updateConfig(card) - } - handleLog = (type, logs, item) => { - let card = fromJS(this.state.card).toJS() - - if (type === 'revert') { - let done = false - if (item.$parentId) { - card.subcards.forEach(col => { - if (item.$parentId === col.uuid) { - col.elements = [...col.elements, item] - done = true - } - }) - } - - card.btnlog = logs - - this.setState({ card: {...card, subcards: []} }, () => { - this.setState({ card }) - this.props.updateConfig(card) - }) - if (!done) { - notification.warning({ - top: 92, - message: '闄勫睘鍗$墖宸插垹闄わ紒', - duration: 2 - }) - } else { - notification.success({ - top: 92, - message: '鎭㈠鎴愬姛锛�', - duration: 2 - }) - } - } else { - card.btnlog = logs - this.setState({ card }) - this.props.updateConfig(card) - notification.success({ - top: 92, - message: '娓呴櫎鎴愬姛锛�', - duration: 2 - }) - } + this.updateComponent(card) } move = (item, direction) => { @@ -324,9 +273,8 @@ card.subcards.splice(hoverIndex, 0, ...card.subcards.splice(dragIndex, 1)) this.setState({card: {...card, subcards: []}}, () => { - this.setState({card}) + this.updateComponent(card) }) - this.props.updateConfig(card) } getWrapForms = () => { @@ -336,13 +284,25 @@ } updateWrap = (res) => { - this.updateComponent({...this.state.card, wrap: res}) + let _card = {...this.state.card, wrap: res} + + if (res.title && !_card.headerStyle) { + _card.headerStyle = { fontSize: '16px', borderBottomWidth: '1px', borderBottomColor: '#e8e8e8' } + } + + this.updateComponent(_card) } clickComponent = (e) => { if (sessionStorage.getItem('style-control') === 'true' || sessionStorage.getItem('style-control') === 'component') { e.stopPropagation() - MKEmitter.emit('clickComponent', this.state.card) + MKEmitter.emit('clickComponent', this.state.card.uuid, null, (style) => { + let _card = {...this.state.card} + _card.style = {..._card.style, ...style} + + this.setState({ card: _card }) + this.props.updateConfig(_card) + }) } } @@ -352,6 +312,7 @@ return ( <div className="menu-prop-carousel-edit-box" style={_style} onClick={this.clickComponent} id={card.uuid}> + <NormalHeader hideSearch="true" config={card} updateComponent={this.updateComponent}/> <Popover overlayClassName="mk-popover-control-wrap" mouseLeaveDelay={0.2} mouseEnterDelay={0.2} content={ <div className="mk-popover-control"> <PlusOutlined className="plus" title="娣诲姞鍗$墖" onClick={this.addCard}/> @@ -361,18 +322,34 @@ <CopyComponent type="propcard" card={card}/> <PasteComponent config={card} options={['cardcell']} updateConfig={this.updateComponent} /> <FontColorsOutlined className="style" title="璋冩暣鏍峰紡" onClick={this.changeStyle}/> - <LogComponent btnlog={card.btnlog || []} handlelog={this.handleLog} /> + <ClockComponent config={card} updateConfig={this.updateComponent}/> + {card.wrap.datatype === 'dynamic' ? <ClockComponent config={card} updateConfig={this.updateComponent}/> : <ClockCircleOutlined style={{color: '#eeeeee', cursor: 'not-allowed'}}/>} <UserComponent config={card}/> <DeleteOutlined className="close" title="鍒犻櫎缁勪欢" onClick={() => this.props.deletecomponent(card.uuid)} /> - {card.wrap.datatype !== 'static' ? <SettingComponent config={card} updateConfig={this.updateComponent} /> : null} - {card.wrap.datatype === 'static' ? <SettingOutlined style={{color: '#eeeeee', cursor: 'not-allowed'}}/> : null} + {card.wrap.datatype === 'dynamic' ? <SettingComponent config={card} updateConfig={this.updateComponent} /> : <SettingOutlined style={{color: '#eeeeee', cursor: 'not-allowed'}}/>} </div> } trigger="hover"> <ToolOutlined/> </Popover> - {card.subcards.length > 0 ? <Carousel dotPosition={card.wrap.dotPosition || 'bottom'} effect={card.wrap.effect || 'scrollx'}> - {card.subcards.map((subcard) => (<CardSimpleComponent key={subcard.uuid} cards={card} card={subcard} move={this.move} updateElement={this.updateCard} deleteElement={this.deleteCard}/>))} - </Carousel> : null} + <div style={{height: card.wrap.height}}> + {card.subcards.length > 0 ? <Carousel dotPosition={card.wrap.dotPosition || 'bottom'} effect={card.wrap.effect || 'scrollx'}> + {card.subcards.map((subcard) => (<CardSimpleComponent key={subcard.uuid} cards={card} card={subcard} move={this.move} updateElement={this.updateCard} deleteElement={this.deleteCard}/>))} + </Carousel> : null} + </div> + <div className="component-name"> + <div className="center"> + <div className="title">{card.name}</div> + <div className="content"> + {card.errors && card.errors.map((err, index) => { + if (err.level === 0) { + return <span key={index} className="error">{err.detail}</span> + } else { + return <span key={index} className="waring">{err.detail}锛�</span> + } + })} + </div> + </div> + </div> </div> ) } -- Gitblit v1.8.0