king
2021-12-22 bd1dfc9e6c9b9f8076ca2783ce598e0936b4c664
src/templates/calendarconfig/index.jsx
@@ -4,19 +4,20 @@
import { is, fromJS } from 'immutable'
import { DndProvider } from 'react-dnd'
import HTML5Backend from 'react-dnd-html5-backend'
import { Button, Card, Modal, Collapse, notification, Spin, Icon, Switch } from 'antd'
import { Button, Card, Modal, Collapse, notification, Spin, Switch } from 'antd'
import { RedoOutlined } from '@ant-design/icons'
import moment from 'moment'
import Api from '@/api'
import zhCN from '@/locales/zh-CN/model.js'
import enUS from '@/locales/en-US/model.js'
import MKEmitter from '@/utils/events.js'
import Utils from '@/utils/utils.js'
import asyncComponent from '@/utils/asyncComponent'
import SearchComponent from '@/templates/sharecomponent/searchcomponent'
import MenuForm from '@/templates/comtableconfig/menuform'
import EditComponent from '@/templates/zshare/editcomponent'
import SourceElement from '@/templates/zshare/dragsource'
import Source from './source'
import './index.scss'
@@ -24,6 +25,8 @@
const { Panel } = Collapse
const { confirm } = Modal
const UrlFieldComponent = asyncComponent(() => import('@/menu/urlfieldcomponent'))
const EditComponent = asyncComponent(() => import('@/templates/zshare/editcomponent'))
const SettingComponent = asyncComponent(() => import('@/templates/sharecomponent/settingcalcomponent'))
const TabComponent = asyncComponent(() => import('./tabcomponent'))
const CalComponent = asyncComponent(() => import('./calcomponent'))
@@ -39,10 +42,9 @@
  }
  state = {
    dict: localStorage.getItem('lang') !== 'en-US' ? zhCN : enUS,        // 字典
    dict: sessionStorage.getItem('lang') !== 'en-US' ? zhCN : enUS,        // 字典
    config: null,            // 页面配置
    visible: false,          // 搜索条件、按钮、显示列,模态框显示控制
    tableFields: [],         // 已选表字段集
    fields: null,            // 搜索条件及显示列,可选字段
    formlist: null,          // 搜索条件、按钮、显示列表单字段
    menuloading: false,      // 菜单保存中
@@ -52,7 +54,6 @@
    originConfig: null,      // 原配置
    tabviews: [],            // 所有标签页
    activeKey: '0',          // 默认展开基本信息
    pasteContent: null,      // 粘贴内容
    openEdition: '',         // 编辑版本标记,防止多人操作
    mockdata: [],            // 测试数据
  }
@@ -231,19 +232,20 @@
  getFuncNames = (data, funcNames, tableNames) => {
    data.forEach(item => {
      if (item.subfuncs) {
        this.getFuncNames(item.subfuncs, funcNames, tableNames)
      } else {
        if (item.tableName) {
          tableNames.push(item.tableName)
        }
        if (item.innerFunc) {
          funcNames.push({func: item.innerFunc, label: item.label || ''})
        }
      // if (item.subfuncs) {
      //   this.getFuncNames(item.subfuncs, funcNames, tableNames)
      //   return
      // }
        if (item.callbackFunc) {
          funcNames.push({func: item.callbackFunc, label: item.label || ''})
        }
      if (item.tableName) {
        tableNames.push(item.tableName)
      }
      if (item.innerFunc) {
        funcNames.push({func: item.innerFunc, label: item.label || ''})
      }
      if (item.callbackFunc) {
        funcNames.push({func: item.callbackFunc, label: item.label || ''})
      }
    })
@@ -323,34 +325,37 @@
    }
    new Promise(resolve => {
      if (_config.tab) {
        Api.getSystemConfig({
          func: 'sPC_Get_LongParam',
          MenuID: _config.tab.linkTab
        }).then(result => {
          if (result.status && result.LongParam) {
            let _LongParam = ''
      // if (_config.tab) {
      //   Api.getSystemConfig({
      //     func: 'sPC_Get_LongParam',
      //     MenuID: _config.tab.linkTab
      //   }).then(result => {
      //     if (result.status && result.LongParam) {
      //       let _LongParam = ''
  
            if (result.LongParam) {
              try {
                _LongParam = JSON.parse(window.decodeURIComponent(window.atob(result.LongParam)))
              } catch (e) {
                console.warn('Parse Failure')
                _LongParam = ''
              }
            }
      //       if (result.LongParam) {
      //         try {
      //           _LongParam = JSON.parse(window.decodeURIComponent(window.atob(result.LongParam)))
      //         } catch (e) {
      //           console.warn('Parse Failure')
      //           _LongParam = ''
      //         }
      //       }
            if (_LongParam) {
              _config.funcs[1].menuNo = _LongParam.tabNo || ''
              _config.funcs[1].subfuncs = _LongParam.funcs || []
            }
          }
          resolve()
        })
      } else {
        resolve()
      }
      //       if (_LongParam) {
      //         _config.funcs[1].menuNo = _LongParam.tabNo || ''
      //         _config.funcs[1].subfuncs = _LongParam.funcs || []
      //       }
      //     }
      //     resolve()
      //   })
      // } else {
      //   resolve()
      // }
      resolve()
    }).then(() => {
      let reload = _config.isAdd
      // 保存时删除配置类型,system 、user
      delete _config.type
      delete _config.isAdd
@@ -429,6 +434,8 @@
            config: _config,
            openEdition: response.open_edition || '',
            originMenu: fromJS(_config).toJS()
          }, () => {
            reload && MKEmitter.emit('revert')
          })
          this.props.reloadmenu()
@@ -656,23 +663,20 @@
      }
    })
    let calvaild = true
    if (!cols.includes(config.calendar.startfield)) {
      calvaild = false
    } else if (!cols.includes(config.calendar.endfield)) {
      calvaild = false
    } else if (!cols.includes(config.calendar.colorfield)) {
      calvaild = false
    } else if (!cols.includes(config.calendar.remarkfield)) {
      calvaild = false
    }
    if (config.setting.interType === 'system' && config.setting.default !== 'false' && !config.setting.dataresource) {
      return '菜单尚未设置数据源,不可启用!'
    } else if (config.columns.length === 0) {
      return '菜单尚未设置数据字段,不可启用!'
    } else if (!calvaild) {
      return '菜单尚未设置字段集,不可启用!'
    } else if (!config.calendar.startfield) {
      return '日历关联字段未设置,不可启用!'
    } else if (!cols.includes(config.calendar.startfield)) {
      return '开始时间字段已删除,不可启用!'
    } else if (!cols.includes(config.calendar.endfield)) {
      return '结束时间字段已删除,不可启用!'
    } else if (config.calendar.colorfield && !cols.includes(config.calendar.colorfield)) {
      return '颜色字段已删除,不可启用!'
    } else if (!cols.includes(config.calendar.remarkfield)) {
      return '信息字段已删除,不可启用!'
    } else {
      return true
    }
@@ -687,13 +691,7 @@
        config: res.config
      })
    } else if (res.type === 'paste') {
      this.setState({
        pasteContent: res.content
      }, () => {
        this.setState({
          pasteContent: null
        })
      })
      this.setState({config: res.config})
    }
  }
@@ -713,18 +711,6 @@
  updateconfig = (config) => {
    this.setState({
      config: config
    })
  }
  /**
   * @description 更新常用表信息,快捷添加后更新配置信息
   */
  updatetable = (config, fields) => {
    const { tableFields } = this.state
    this.setState({
      config: config,
      tableFields: fields ? fields : tableFields
    })
  }
@@ -754,11 +740,15 @@
                  dict={this.state.dict}
                  updatemenu={this.updateconfig}
                />
                {config ? <UrlFieldComponent
                  config={config}
                  updateConfig={this.updateconfig}
                /> : null}
                {/* 表名添加 */}
                <TableComponent
                  config={config}
                  containerId="subtable-basedata"
                  updatetable={this.updatetable}
                  updatetable={this.updateconfig}
                />
              </Panel>
              {/* 搜索条件添加 */}
@@ -768,12 +758,7 @@
                    return (<SourceElement key={index} content={item}/>)
                  })}
                </div>
                <FieldsComponent
                  config={config}
                  type="search"
                  tableFields={this.state.tableFields}
                  updatefield={this.updateconfig}
                />
                <FieldsComponent config={config} type="search" />
              </Panel>
            </Collapse>
          </div>
@@ -781,11 +766,11 @@
            <Card title={
              <div>
                日历页面配置 
                <Icon type="redo" style={{marginLeft: '10px'}} title="刷新标签列表" onClick={() => this.reloadTab(true)} />
                <RedoOutlined style={{marginLeft: '10px'}} title="刷新标签列表" onClick={() => this.reloadTab(true)} />
              </div>
            } bordered={false} extra={
              <div>
                <EditComponent dict={this.state.dict} type="calendar" config={this.state.config} refresh={this.updateConfig}/>
                <EditComponent dict={this.state.dict} type="table" options={['search', 'form']} config={this.state.config}/>
                <Switch className="big" checkedChildren="启" unCheckedChildren="停" checked={this.state.config.enabled} onChange={this.onEnabledChange} />
                <Button type="primary" onClick={this.submitConfig} loading={this.state.menuloading}>{this.state.dict['model.save']}</Button>
                <Button onClick={this.cancelConfig}>{this.state.dict['model.back']}</Button>
@@ -794,15 +779,11 @@
              <SettingComponent
                config={config}
                MenuID={menu.MenuID}
                tableFields={this.state.tableFields}
                permFuncField={this.props.permFuncField}
                updateConfig={this.updateconfig}
              />
              <SearchComponent
                menu={{MenuID: menu.MenuID, MenuName: config.MenuName}}
                config={config}
                pasteContent={this.state.pasteContent}
                sysRoles={this.props.sysRoles}
                updatesearch={this.updatesearch}
              />
              <div className="calendar-wrap">
@@ -838,8 +819,6 @@
const mapStateToProps = (state) => {
  return {
    sysRoles: state.sysRoles,
    permFuncField: state.permFuncField,
    memberLevel: state.memberLevel
  }
}