From 6afdec0062dacbded57e166230eb22cc55ced0c1 Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期六, 08 五月 2021 14:30:21 +0800 Subject: [PATCH] 2021-05-08 --- src/tabviews/custom/components/card/cardcellList/index.jsx | 549 ++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 files changed, 504 insertions(+), 45 deletions(-) diff --git a/src/tabviews/custom/components/card/cardcellList/index.jsx b/src/tabviews/custom/components/card/cardcellList/index.jsx index 23ed5e1..01b98b4 100644 --- a/src/tabviews/custom/components/card/cardcellList/index.jsx +++ b/src/tabviews/custom/components/card/cardcellList/index.jsx @@ -1,12 +1,31 @@ import React, {Component} from 'react' import PropTypes from 'prop-types' import { is, fromJS } from 'immutable' -import { Button, Icon, Col, Tooltip } from 'antd' +import { Icon, Col, Tooltip, notification } from 'antd' +import moment from 'moment' -import zhCN from '@/locales/zh-CN/model.js' -import enUS from '@/locales/en-US/model.js' +import asyncComponent from './asyncButtonComponent' +import asyncElementComponent from '@/utils/asyncComponent' +import LostPng from '@/assets/img/lost.png' import './index.scss' + +const NormalButton = asyncComponent(() => import('@/tabviews/zshare/actionList/normalbutton')) +const ExcelInButton = asyncComponent(() => import('@/tabviews/zshare/actionList/excelInbutton')) +const ExcelOutButton = asyncComponent(() => import('@/tabviews/zshare/actionList/exceloutbutton')) +const PopupButton = asyncComponent(() => import('@/tabviews/zshare/actionList/popupbutton')) +const TabButton = asyncComponent(() => import('@/tabviews/zshare/actionList/tabbutton')) +const NewPageButton = asyncComponent(() => import('@/tabviews/zshare/actionList/newpagebutton')) +const ChangeUserButton = asyncComponent(() => import('@/tabviews/zshare/actionList/changeuserbutton')) +const PrintButton = asyncComponent(() => import('@/tabviews/zshare/actionList/printbutton')) +const BarCode = asyncElementComponent(() => import('@/components/barcode')) +const QrCode = asyncElementComponent(() => import('@/components/qrcode')) +const Video = asyncComponent(() => import('@/components/video')) +const PicRadio = { + '4:3': '75%', '3:2': '66.67%', '16:9': '56.25%', '2:1': '50%', '3:1': '33.33%', '4:1': '25%', + '5:1': '20%', '6:1': '16.67%', '7:1': '14.29%', '8:1': '12.5%', '9:1': '11.11%', + '10:1': '10%', '3:4': '133.33%', '2:3': '150%', '9:16': '177.78%' +} class CardCellComponent extends Component { static propTpyes = { @@ -17,7 +36,6 @@ } state = { - dict: localStorage.getItem('lang') !== 'en-US' ? zhCN : enUS, card: null, // 缂栬緫涓厓绱� elements: null, // 鎸夐挳缁� } @@ -34,7 +52,7 @@ } shouldComponentUpdate (nextProps, nextState) { - return !is(fromJS(this.state), fromJS(nextState)) + return !is(fromJS(this.state), fromJS(nextState)) || !is(fromJS(this.props), fromJS(nextProps)) } /** @@ -46,11 +64,260 @@ } } - getContent = (card) => { + openNewView = (e, card) => { + const { cardCell, data, cards } = this.props + + if (!card.link) return + e.stopPropagation() + + let url = '' + + if (card.link === 'static') { + url = card.linkurl + } else { + url = data[card.linkurl] + } + + if (!url) { + notification.warning({ + top: 92, + message: '閾炬帴鍦板潃涓嶅瓨鍦紒', + duration: 5 + }) + return + } + + if (/^sso$/ig.test(url)) { + if (!data.LinkUrl1) { + notification.warning({ + top: 92, + message: '閾炬帴鍦板潃涓嶅瓨鍦紒', + duration: 5 + }) + return + } + + let _url = data.LinkUrl1 + if (/index\.html/ig.test(_url)) { + _url = _url.replace(/index\.html.*/ig, '') + } else if (!/\/$/ig.test(_url)) { + _url = _url + '/' + } + + url = _url + 'index.html#/ssologin/' + window.btoa(window.encodeURIComponent(JSON.stringify({ + UserID: sessionStorage.getItem('UserID'), + LoginUID: sessionStorage.getItem('LoginUID'), + User_Name: sessionStorage.getItem('User_Name'), + Full_Name: sessionStorage.getItem('Full_Name'), + avatar: sessionStorage.getItem('avatar'), + dataM: data.dataM ? 'true' : '', + debug: data.debug || '', + role_id: data.role_id || '' + }))) + } else { + let Id = '' + let con = '?' + + if (/\?/ig.test(url)) { + con = '&' + } + + if (cards.subtype === 'propcard' && cardCell) { + Id = cardCell.setting.primaryId || '' + } else { + Id = data[cards.setting.primaryKey] || '' + } + + if (card.joint === 'true') { + url = url + `${con}id=${Id}&appkey=${window.GLOB.appkey}&userid=${sessionStorage.getItem('UserID')}&LoginUID=${sessionStorage.getItem('LoginUID') || ''}` + } + } + + window.open(url) + } + + getMark = (marks, style, content) => { const { data } = this.props - if (card.eleType === 'text' || card.eleType === 'number') { + marks.some(mark => { + let originVal = data[mark.field[0]] + '' + let contrastVal = '' + let result = false + + if (mark.field[1] === 'static') { + contrastVal = mark.contrastValue + '' + } else { + contrastVal = data[mark.field[2]] + '' + } + + if (mark.match === '=') { + result = originVal === contrastVal + } else if (mark.match === '!=') { + result = originVal !== contrastVal + } else if (mark.match === 'like') { + result = originVal.indexOf(contrastVal) > -1 + } else if (mark.match === '>') { + try { + originVal = parseFloat(originVal) + contrastVal = parseFloat(contrastVal) + } catch { + originVal = NaN + } + + if (!isNaN(originVal) && !isNaN(contrastVal) && originVal > contrastVal) { + result = true + } + } else if (mark.match === '<') { + try { + originVal = parseFloat(originVal) + contrastVal = parseFloat(contrastVal) + } catch { + originVal = NaN + } + + if (!isNaN(originVal) && !isNaN(contrastVal) && originVal < contrastVal) { + result = true + } + } + + if (result && mark.signType) { + if (mark.signType[0] === 'font') { + style.color = mark.color + } else if (mark.signType[0] === 'background') { + style.background = mark.color + if (mark.fontColor) { + style.color = mark.fontColor + } + } else if (mark.signType[0] === 'underline') { + style.textDecoration = 'underline' + style.color = mark.color + } else if (mark.signType[0] === 'line-through') { + style.textDecoration = 'line-through' + style.color = mark.color + } else if (mark.signType[0] === 'icon') { + let icon = (<Icon style={{color: mark.color}} type={mark.signType[3]} />) + if (mark.signType[1] === 'front') { + content = <span>{icon} {content}</span> + } else { + content = <span>{content} {icon}</span> + } + } + } + return result + }) + + return content + } + + getColor = (marks) => { + const { data } = this.props + let color = '' + + marks.some(mark => { + let originVal = data[mark.field[0]] + '' + let contrastVal = '' + let result = false + + if (mark.field[1] === 'static') { + contrastVal = mark.contrastValue + '' + } else { + contrastVal = data[mark.field[2]] + '' + } + + if (mark.match === '=') { + result = originVal === contrastVal + } else if (mark.match === '!=') { + result = originVal !== contrastVal + } else if (mark.match === 'like') { + result = originVal.indexOf(contrastVal) > -1 + } else if (mark.match === '>') { + try { + originVal = parseFloat(originVal) + contrastVal = parseFloat(contrastVal) + } catch { + originVal = NaN + } + + if (!isNaN(originVal) && !isNaN(contrastVal) && originVal > contrastVal) { + result = true + } + } else if (mark.match === '<') { + try { + originVal = parseFloat(originVal) + contrastVal = parseFloat(contrastVal) + } catch { + originVal = NaN + } + + if (!isNaN(originVal) && !isNaN(contrastVal) && originVal < contrastVal) { + result = true + } + } + + if (result) { + color = mark.color + } + return result + }) + + return color + } + + getContent = (card) => { + const { data, cards } = this.props + + if (card.eleType === 'sequence') { + return ( + <Col key={card.uuid} span={card.width}> + <div style={card.style}> + <div className={'ant-mk-text'}>{data.$Index || ''}</div> + </div> + </Col> + ) + } else if (card.eleType === 'text') { let val = '' + let _style = card.style ? {...card.style} : {} + + if (card.datatype === 'static') { + val = card.value || '' + if (/@username@|@fullName@|@login_city@/ig.test(val)) { + let userName = sessionStorage.getItem('User_Name') || '' + let fullName = sessionStorage.getItem('Full_Name') || '' + let city = sessionStorage.getItem('city') || '' + val = val.replace(/@username@/ig, userName).replace(/@fullName@/ig, fullName).replace(/@login_city@/ig, city) + } + } else if (data.hasOwnProperty(card.field)) { + val = data[card.field] + } + + if (val !== '' && card.format) { + if (card.format === 'YYYY-MM-DD' && /^[1-9]\d{3}(-|\/)(0[1-9]|1[0-2])(-|\/)(0[1-9]|[1-2][0-9]|3[0-1])/.test(val)) { + val = `${val.substr(0, 4)}-${val.substr(5, 2)}-${val.substr(8, 2)}` + } + } + + if (val !== '') { + val = `${card.prefix || ''}${val}${card.postfix || ''}` + } + + if (card.marks) { + val = this.getMark(card.marks, _style, val) + } + + if (card.link) { + _style.cursor = 'pointer' + } + + return ( + <Col key={card.uuid} span={card.width}> + <div style={_style} onClick={(e) => {this.openNewView(e, card)}}> + <div className={'ant-mk-text line' + (card.height || '')} style={{height: card.innerHeight || 'auto'}}>{val}</div> + </div> + </Col> + ) + } else if (card.eleType === 'number') { + let val = '' + let _style = card.style ? {...card.style} : {} if (card.datatype === 'static') { val = card.value @@ -58,13 +325,46 @@ val = data[card.field] } + if (val !== '' && typeof(val) === 'number') { + if (card.format === 'percent') { + val = val * 100 + } + + if (card.col && card.col.type === 'number') { + let decimal = card.col.decimal || 0 + + if (card.format === 'percent') { + decimal = decimal - 2 + } + if (decimal < 0) { + decimal = 0 + } + + val = val.toFixed(decimal) + } else { + val = '' + val + } + + if (card.format === 'percent' && (!card.postfix || card.postfix.indexOf('%') === -1)) { + val = val + '%' + } else if (card.format === 'thdSeparator') { + val = val.replace(/\d{1,3}(?=(\d{3})+(\.\d*)?$)/g, '$&,') + } + } + if (val !== '') { val = `${card.prefix || ''}${val}${card.postfix || ''}` + } + + if (card.marks) { + val = this.getMark(card.marks, _style, val) } return ( <Col key={card.uuid} span={card.width}> - <div style={card.style}>{val}</div> + <div style={_style}> + <div className={'ant-mk-text line' + (card.height || '')} style={{height: card.innerHeight || 'auto'}}>{val}</div> + </div> </Col> ) } else if (card.eleType === 'icon') { @@ -87,6 +387,7 @@ ) } else if (card.eleType === 'slider') { let val = 0 + let color = card.color if (card.datatype === 'static') { val = card.value @@ -107,14 +408,19 @@ _val = `${val}%` } + if (card.marks) { + let _color = this.getColor(card.marks) + color = _color ? _color : color + } + return ( <Col key={card.uuid} span={card.width}> <div style={card.style}> <div className="ant-mk-slider"> <div className="ant-mk-slider-rail"></div> - <div className="ant-mk-slider-track" style={{width: _val, backgroundColor: card.color}}></div> - <Tooltip title={val}> - <div className="ant-mk-slider-handle" style={{left: _val, borderColor: card.color}}></div> + <div className="ant-mk-slider-track" style={{width: _val, backgroundColor: color}}></div> + <Tooltip title={`${val}%`}> + <div className="ant-mk-slider-handle" style={{left: _val, borderColor: color}}></div> </Tooltip> </div> </div> @@ -122,75 +428,228 @@ ) } else if (card.eleType === 'picture') { let _imagestyle = {} + let _style = card.style ? {...card.style} : {} + let url = '' - if (card.url) { - _imagestyle = {backgroundImage: `url('${card.url}')`} + if (card.datatype === 'static') { + url = card.url } else { - _imagestyle = {backgroundImage: `url('')`} + url = data[card.field] + } + + if (url) { + _imagestyle = {backgroundImage: `url('${url}')`} + } else { + _imagestyle = {backgroundImage: `url(${LostPng})`, backgroundSize: 'contain'} } - if (card.radius === 'true') { - _imagestyle.borderRadius = '50%' + if (_style.borderRadius) { + _imagestyle.borderRadius = _style.borderRadius } - if (card.lenWidRadio === '16:9') { - _imagestyle.paddingTop = '56.25%' - } else if (card.lenWidRadio === '3:2') { - _imagestyle.paddingTop = '66.67%' - } else if (card.lenWidRadio === '4:3') { - _imagestyle.paddingTop = '75%' + if (PicRadio[card.lenWidRadio]) { + _imagestyle.paddingTop = PicRadio[card.lenWidRadio] } else { _imagestyle.paddingTop = '100%' } + if (card.link) { + _style.cursor = 'pointer' + } + return ( <Col key={card.uuid} span={card.width}> - <div style={card.style}> + <div style={_style} onClick={(e) => {this.openNewView(e, card)}}> <div className="ant-mk-picture" style={_imagestyle}></div> </div> </Col> ) } else if (card.eleType === 'splitline') { + let _borderWidth = card.borderWidth === undefined ? 1 : card.borderWidth return ( <Col key={card.uuid} span={card.width}> <div style={card.style}> - <div className="ant-mk-splitline" style={{backgroundColor: card.color}}></div> + <div className="ant-mk-splitline" style={{borderColor: card.color, borderWidth: _borderWidth}}></div> + </div> + </Col> + ) + } else if (card.eleType === 'barcode') { + let val = '' + + if (card.datatype === 'static') { + val = card.value + } else if (data.hasOwnProperty(card.field)) { + val = data[card.field] + } + + return ( + <Col key={card.uuid} span={card.width}> + <div style={card.style}> + <div style={{height: card.innerHeight || 25}}> + {val ? <BarCode card={card} value={val}/> : null} + </div> + </div> + </Col> + ) + } else if (card.eleType === 'video') { + let url = '' + + if (card.datatype === 'static') { + url = card.url + } else { + url = data[card.field] || '' + } + + return ( + <Col key={card.uuid} span={card.width}> + <div style={card.style}> + <Video card={card} value={url}/> + </div> + </Col> + ) + } else if (card.eleType === 'qrcode') { + let val = '' + + if (card.datatype === 'static') { + val = card.value + } else if (data.hasOwnProperty(card.field)) { + val = data[card.field] + } + + return ( + <Col key={card.uuid} span={card.width}> + <div style={card.style}> + <div style={{minHeight: card.qrWidth || 50}}> + {val ? <QrCode card={card} value={val}/> : null} + </div> + </div> + </Col> + ) + } else if (card.eleType === 'currentDate') { + return ( + <Col key={card.uuid} span={card.width}> + <div className="ant-mk-date" style={card.style}> + {card.dateFormat ? `${card.prefix || ''}${moment().format(card.dateFormat)}${card.postfix || ''}` : null} </div> </Col> ) } else if (card.eleType === 'button') { - if (card.show === 'icon') { + if (card.$type === 'tableButton' && card.controlField) { // 琛ㄦ牸涓寜閽殣钘忔帶鍒� + if (data[card.controlField] === card.controlVal) { + return null + } else if (card.controlVal && card.controlVal.split(',').includes(data[card.controlField])) { + return null + } + } + + if (['exec', 'prompt', 'pop'].includes(card.OpenType)) { return ( - <Col key={card.uuid} span={card.width}> - <div style={card.style}> - <Button className={'mk-link mk-' + card.class} style={card.btnstyle} type="link"><Icon type={card.icon}/></Button> - </div> + <Col key={card.uuid} className="mk-cell-btn" span={card.width}> + <NormalButton + BID={data.$$BID} + btn={card} + show={card.show} + style={card.style} + setting={cards.setting} + columns={cards.columns} + selectedData={[data]} + /> </Col> ) - } else if (card.show === 'link') { + } else if (card.OpenType === 'excelIn') { return ( - <Col key={card.uuid} span={card.width}> - <div style={card.style}> - <Button className={'mk-link mk-' + card.class} style={card.btnstyle} type="link">{card.label}{card.icon ? <Icon type={card.icon}/> : null}</Button> - </div> + <Col key={card.uuid} className="mk-cell-btn" span={card.width}> + <ExcelInButton + BID={data.$$BID} + btn={card} + show={card.show} + style={card.style} + setting={cards.setting} + selectedData={[data]} + /> </Col> ) - } else { + } else if (card.OpenType === 'excelOut') { return ( - <Col key={card.uuid} span={card.width}> - <div style={card.style}> - <Button - className={'mk-btn mk-' + card.class} - icon={card.icon} - style={card.btnstyle} - > - {card.label} - </Button> - </div> + <Col key={card.uuid} className="mk-cell-btn" span={card.width}> + <ExcelOutButton + BID={data.$$BID} + btn={card} + show={card.show} + style={card.style} + setting={cards.setting} + /> </Col> ) + } else if (card.OpenType === 'popview') { + return ( + <Col key={card.uuid} className="mk-cell-btn" span={card.width}> + <PopupButton + BID={data.$$BID} + btn={card} + show={card.show} + style={card.style} + setting={cards.setting} + selectedData={[data]} + /> + </Col> + ) + } else if (card.OpenType === 'tab') { + return ( + <Col key={card.uuid} className="mk-cell-btn" span={card.width}> + <TabButton + btn={card} + show={card.show} + style={card.style} + setting={cards.setting} + selectedData={[data]} + /> + </Col> + ) + } else if (card.OpenType === 'innerpage') { + return ( + <Col key={card.uuid} className="mk-cell-btn" span={card.width}> + <NewPageButton + btn={card} + show={card.show} + style={card.style} + setting={cards.setting} + selectedData={[data]} + /> + </Col> + ) + } else if (card.OpenType === 'funcbutton') { + if (card.funcType === 'changeuser') { + return ( + <Col key={card.uuid} className="mk-cell-btn" span={card.width}> + <ChangeUserButton + BID={data.$$BID} + btn={card} + show={card.show} + style={card.style} + setting={cards.setting} + selectedData={[data]} + /> + </Col> + ) + } else if (card.funcType === 'print') { + return ( + <Col key={card.uuid} className="mk-cell-btn" span={card.width}> + <PrintButton + BID={data.$$BID} + btn={card} + show={card.show} + style={card.style} + setting={cards.setting} + selectedData={[data]} + /> + </Col> + ) + } } } + + return null } render() { -- Gitblit v1.8.0