king
2021-08-04 abe961768cb069e84ed958f4c768c512cc3db598
src/menu/components/card/cardcomponent/index.jsx
@@ -1,18 +1,17 @@
import React, {Component} from 'react'
import PropTypes from 'prop-types'
import { is, fromJS } from 'immutable'
import { Modal, Popover, Icon, Switch, Col } from 'antd'
import { Popover, Icon, Switch, Col } from 'antd'
import asyncComponent from '@/utils/asyncComponent'
import asyncIconComponent from '@/utils/asyncIconComponent'
import zhCN from '@/locales/zh-CN/model.js'
import enUS from '@/locales/en-US/model.js'
import SettingForm from './settingform'
import { resetStyle } from '@/utils/utils-custom.js'
import getSettingForm from './options'
import Utils from '@/utils/utils.js'
import MKEmitter from '@/utils/events.js'
import './index.scss'
const NormalForm = asyncIconComponent(() => import('@/components/normalform'))
const CardCellComponent = asyncComponent(() => import('../cardcellcomponent'))
const CopyComponent = asyncIconComponent(() => import('@/menu/components/share/copycomponent'))
const PasteComponent = asyncIconComponent(() => import('./pastecomponent'))
@@ -28,12 +27,9 @@
  }
  state = {
    dict: sessionStorage.getItem('lang') !== 'en-US' ? zhCN : enUS,
    card: null,            // 卡片信息,包括正反面
    formlist: null,        // 设置表单信息
    elements: null,        // 编辑组
    visible: false,        // 模态框控制
    settingVisible: false,
    side: 'front'
  }
@@ -194,24 +190,33 @@
    MKEmitter.emit('changeStyle', [cards.uuid, card.uuid], options, _style)
  }
  settingSubmit = () => {
  getSettingForms = () => {
    const { cards } = this.props
    const { setting } = this.state.card
    return getSettingForm(setting, cards.subtype === 'propcard')
  }
  updateSetting = (res) => {
    const { card, side } = this.state
    this.settingRef.handleConfirm().then(res => {
      this.setState({
        settingVisible: false,
        card: {...card, setting: res}
      })
    if (res.appmenu) {
      res.menu = res.appmenu
      delete res.appmenu
    }
      if (side === 'back' && res.type === 'simple') {
        this.setState({
          side: 'front',
          elements: fromJS(card.elements).toJS()
        })
      }
      this.props.updateElement({...card, setting: res})
    this.setState({
      card: {...card, setting: res}
    })
    if (side === 'back' && res.type === 'simple') {
      this.setState({
        side: 'front',
        elements: fromJS(card.elements).toJS()
      })
    }
    this.props.updateElement({...card, setting: res})
  }
  clickComponent = (e) => {
@@ -231,7 +236,7 @@
  render() {
    const { cards, offset } = this.props
    const { card, elements, side, settingVisible, dict } = this.state
    const { card, elements, side } = this.state
    let _style = {...card.style}
@@ -256,7 +261,9 @@
              <div className="mk-popover-control">
                <Icon className="plus" title="添加元素" onClick={this.addElement} type="plus" />
                <Icon className="plus" title="添加按钮" onClick={this.addButton} type="plus-square" />
                <Icon className="edit" title="编辑" type="edit" onClick={() => this.setState({settingVisible: true})} />
                <NormalForm title="卡片设置" width={800} update={this.updateSetting} getForms={this.getSettingForms}>
                  <Icon type="edit" className="edit" title="编辑"/>
                </NormalForm>
                <CopyComponent type="cardcell" card={card}/>
                <PasteComponent elements={elements} options={['action', 'customCardElement']} updateConfig={(list) => this.updateCard(list, 'paste')} />
                <Icon className="style" title="调整样式" onClick={this.changeStyle} type="font-colors" />
@@ -276,25 +283,6 @@
            </Popover>
          </div>
        </div>
        <Modal
          wrapClassName="popview-modal"
          title={'卡片设置'}
          visible={settingVisible}
          width={800}
          maskClosable={false}
          okText={dict['model.submit']}
          onOk={this.settingSubmit}
          onCancel={() => { this.setState({ settingVisible: false }) }}
          destroyOnClose
        >
          <SettingForm
            dict={dict}
            cards={cards}
            setting={card.setting}
            inputSubmit={this.settingSubmit}
            wrappedComponentRef={(inst) => this.settingRef = inst}
          />
        </Modal>
      </Col>
    )
  }