king
2024-05-16 b69b5f6329ca5f87932436b7a6c1ddfc3377e10f
src/menu/components/card/cardcellcomponent/formconfig.jsx
@@ -1,37 +1,120 @@
import zhCN from '@/locales/zh-CN/model.js'
import enUS from '@/locales/en-US/model.js'
const Formdict = sessionStorage.getItem('lang') !== 'en-US' ? zhCN : enUS
import React from 'react'
import MenuUtils from '@/utils/utils-custom.js'
/**
 * @description 获取元素配置信息
 * @param {*} card
 * @param {*} type
 */
export function getCardCellForm (card, type, subtype, cardCell) {
export function getCardCellForm (card, cards, cardCell) {
  let appType = sessionStorage.getItem('appType')
  let _options = [
    { value: 'text', text: '文本'},
    { value: 'number', text: '数值'},
    { value: 'picture', text: '图片'},
    { value: 'video', text: '视频'},
    { value: 'icon', text: '图标'},
    { value: 'icon', text: '提示(图标)'},
    { value: 'slider', text: '进度条'},
    { value: 'splitline', text: '分割线'},
    { value: 'barcode', text: '条形码'},
    { value: 'qrcode', text: '二维码'},
    { value: 'currentDate', text: '当前时间'},
    { value: 'formula', text: '公式'},
    { value: 'tag', text: '标签'},
    { value: 'color', text: '颜色'},
  ]
  if (type === 'table' || (type === 'card' && subtype === 'datacard')) {
    _options.push({value: 'sequence', text: '序号'})
  let anchors = []
  if (window.GLOB.customMenu.Template === 'BaseTable') {
    anchors = null
  } else {
    anchors = MenuUtils.getAnchors(window.GLOB.customMenu.components, cards.uuid) || []
  }
  let appMenus = []
  const isApp = sessionStorage.getItem('appType') === 'pc'
  if (cards.type === 'table' || (cards.type === 'card' && cards.subtype !== 'propcard')) {
    _options.push({value: 'sequence', text: '序号'})
  } else if (card.eleType === 'sequence') { // 拖拽添加类型转换
    card.eleType = 'text'
  }
  if (card.eleType === 'icon' && card.datatype === 'dynamic' && !card.field) { // 拖拽添加类型转换
    card.datatype = 'static'
  }
  if (isApp) {
    appMenus = sessionStorage.getItem('appMenus')
  let tooltip = ''
  if (cardCell.$cardType === 'extendCard') {
    tooltip = '在扩展卡片中,动态数据显示值为获取到的第一行数据。'
  }
  let isHeader = false
  if (cardCell.$cardType === 'extendCard' && cardCell.setting.cardRole === 'header') {
    isHeader = true
    anchors = null
    card.link = ''
    _options = [{ value: 'text', text: '文本'}]
  }
  let width = card.width === undefined ? 12 : card.width
  if (/x/.test(card.width)) {
    width = +width.replace(/x/, '.5')
  }
  let linkTypes = [
    { value: 'tel', text: '电话' },
    { value: 'email', text: '邮箱' },
    { value: 'linkmenu', text: '关联菜单' },
    { value: 'download', text: '下载' },
    { value: 'other', text: '其他' }
  ]
  if (appType === 'mob') {
    linkTypes = [
      { value: 'tel', text: '电话' },
      { value: 'email', text: '邮箱' },
      { value: 'qywx', text: '企业微信' },
      { value: 'linkmenu', text: '关联菜单' },
      { value: 'download', text: '下载' },
      { value: 'other', text: '其他' }
    ]
  } else if (appType === 'pc') {
    linkTypes = [
      { value: 'tel', text: '电话' },
      { value: 'email', text: '邮箱' },
      { value: 'linkmenu', text: '关联菜单' },
      { value: 'download', text: '下载' },
      { value: 'other', text: '其他' }
    ]
  }
  if (card.linkType === 'qywx') {
    if (appType !== 'mob') {
      card.link = ''
      card.linkType = ''
      card.linkurl = ''
    }
  // } else if (card.linkType === 'linkmenu') {
  //   if (appType !== 'mob' && appType !== 'pc') {
  //     card.link = ''
  //     card.linkType = ''
  //     card.linkurl = ''
  //     card.linkmenu = ''
  //   }
  }
  let menulist = sessionStorage.getItem('fstMenuList')
  if (appType === '' && menulist) {
    try {
      menulist = JSON.parse(menulist)
    } catch (e) {
      menulist = []
    }
  } else {
    menulist = []
  }
  let appMenus = sessionStorage.getItem('appMenus')
  if (['pc', 'mob'].includes(appType)) {
    if (appMenus) {
      try {
        appMenus = JSON.parse(appMenus)
@@ -41,17 +124,18 @@
    } else {
      appMenus = []
    }
    appMenus.push({value: 'goback', text: '返回(上一页)'})
  }
  let dataTypes = [
    { value: 'dynamic', text: '动态' },
    { value: 'static', text: '静态' }
  ]
  if (cardCell.$cardType === 'extendCard') {
    card.datatype = 'static'
    dataTypes = [
      { value: 'static', text: '静态' }
    ]
  let fields = []
  let isStatic = (cards.subtype === 'propcard' || cards.type === 'balcony') && cards.wrap.datatype === 'static'
  if (isStatic) {
    if (cards.wrap.supModule && cards.wrap.supModule.length) {
      let cell = MenuUtils.getComponent(cards.wrap.supModule[cards.wrap.supModule.length - 1])
      if (cell && cell.columns) {
        fields = cell.columns.map(col => ({ value: col.field }))
      }
    }
  }
  let forms = [
@@ -64,6 +148,42 @@
      options: _options
    },
    {
      type: 'radio',
      key: 'datatype',
      label: '数据类型',
      initVal: card.datatype || 'static',
      tooltip,
      required: true,
      options: [
        { value: 'dynamic', text: '动态' },
        { value: 'static', text: '静态' }
      ]
    },
    {
      type: 'radio',
      key: 'tipType',
      label: '提示内容',
      initVal: card.tipType || 'icon',
      required: false,
      options: [
        { value: 'icon', text: '图标' },
        { value: 'text', text: '文本' }
      ]
    },
    {
      type: isStatic ? 'text' : 'select',
      key: 'field',
      label: '字段',
      initVal: card.field || '',
      tooltip: isStatic ? '可绑定上级组件字段,不存在上级组件时可绑定url参数字段。' : '',
      required: true,
      options: fields,
      rules: [{
        pattern: /^[\u4E00-\u9FA50-9a-zA-Z_-]*$/ig,
        message: '字段名只允许包含数字、字母、汉字以及_-'
      }]
    },
    {
      type: 'icon',
      key: 'icon',
      label: '图标',
@@ -71,34 +191,19 @@
      required: true
    },
    {
      type: 'radio',
      key: 'datatype',
      label: '数据类型',
      initVal: card.datatype || 'static',
      required: true,
      options: dataTypes
    },
    {
      type: 'select',
      key: 'field',
      label: '字段',
      initVal: card.field || '',
      required: true,
      options: []
    },
    {
      type: 'text',
      key: 'value',
      min: 0,
      label: '内容',
      initVal: card.value || '',
      tooltip: '文本类型,会替换内容中的@username@、@fullName@、@login_city@。',
      // tooltip: '文本类型,会替换内容中的@username@、@fullName@、@mk_city@、@appname@、@bid@、@month@、@week@、@day@',
      required: true
    },
    {
      type: 'file',
      key: 'url',
      label: '图片/文件',
      tooltip: '使用静态图片时,@icon@代表头像。',
      initVal: card.url || '',
      maxfile: 1,
      required: true
@@ -126,6 +231,71 @@
      ]
    },
    {
      type: 'number',
      key: 'startTime',
      precision: 0,
      label: '开始时间',
      initVal: card.startTime || 0,
      tooltip: '视频开始播放的时间,用于调整视频初始化展示的界面。',
      required: false
    },
    {
      type: 'radio',
      key: 'posterType',
      label: '预览图',
      initVal: card.posterType || '',
      required: false,
      options: [
        { value: '', text: '无' },
        { value: 'dynamic', text: '动态' },
        { value: 'static', text: '静态' }
      ]
    },
    {
      type: 'file',
      key: 'posterUrl',
      label: '预览地址',
      initVal: card.posterUrl || '',
      maxfile: 1,
      required: true
    },
    {
      type: isStatic ? 'text' : 'select',
      key: 'posterField',
      label: '预览地址',
      initVal: card.posterField || '',
      required: true,
      options: fields
    },
    {
      type: 'radio',
      key: 'eval',
      label: '解析方式',
      initVal: card.eval || 'false',
      tooltip: '当公式内容涉及计算时请选择“计算”,当公式内容为字段拼接时请选择“字段替换”,使用函数时入参为data(数组)。',
      required: false,
      options: [{
        value: 'false',
        text: '字段替换'
      }, {
        value: 'true',
        text: '计算'
      }, {
        value: 'func',
        text: '函数'
      }]
    },
    {
      type: 'number',
      key: 'decimal',
      min: 0,
      max: 18,
      decimal: 0,
      label: '小数位',
      initVal: card.decimal === undefined ? '' : card.decimal,
      required: false
    },
    {
      type: 'select',
      key: 'format',
      label: '格式化',
@@ -137,7 +307,10 @@
        { value: 'percent', text: '百分数' },
        { value: 'thdSeparator', text: '千分位' },
        { value: 'abs', text: '绝对值' },
        { value: 'encryption', text: '加密'},
        { value: 'YYYY-MM-DD', text: 'YYYY-MM-DD' },
        { value: 'YYYY-MM-DD HH:mm', text: 'YYYY-MM-DD HH:mm' },
        { value: 'YYYY-MM-DD HH:mm:ss', text: 'YYYY-MM-DD HH:mm:ss' },
        { value: 'MM月DD日', text: 'MM月DD日' },
        { value: 'YYYY年MM月DD日', text: 'YYYY年MM月DD日' },
        { value: 'HH:mm', text: '时分(例:16:57)' },
@@ -145,7 +318,8 @@
        { value: 'MM月DD日 ahh:mm', text: '自定义2(例:12月17日 上午10:57)' },
        { value: 'calendar1', text: '自定义3(例:今天 上午10:57)' },
        { value: 'calendar2', text: '自定义4(例:刚刚、昨天、5天前)' },
      ]
      ],
      forbid: isHeader
    },
    {
      type: 'select',
@@ -159,17 +333,8 @@
        { value: 'YYYY-MM', text: 'YYYY-MM' },
        { value: 'YYYY-MM-DD HH:mm', text: 'YYYY-MM-DD HH:mm' },
        { value: 'YYYY-MM-DD HH:mm:ss', text: 'YYYY-MM-DD HH:mm:ss' },
        { value: 'YYYY年MM月DD日', text: 'YYYY年MM月DD日' },
      ]
    },
    {
      type: 'number',
      key: 'decimal',
      min: 0,
      max: 18,
      decimal: 0,
      label: '小数位',
      initVal: card.decimal === undefined ? '' : card.decimal,
      required: false
    },
    {
      type: 'text',
@@ -190,7 +355,8 @@
      key: 'tooltip',
      label: '提示信息',
      initVal: card.tooltip || '',
      tooltip: '鼠标悬浮时显示。',
      tooltip: '鼠标悬浮时显示。注:如使用动态信息,请在此处填写相应的字段名。',
      forbid: appType === 'mob',
      required: false
    },
    {
@@ -294,12 +460,12 @@
    {
      type: 'number',
      key: 'width',
      min: 1,
      min: 0,
      max: 24,
      precision: 0,
      precision: 1,
      label: '元素宽度',
      initVal: card.width || 12,
      tooltip: '栅格布局,每行等分为24列。',
      initVal: width,
      tooltip: '栅格布局,每行等分为24列,可设置半列即.5。注:为0时宽度依据内容自适应(文本、数值、提示(图标)、当前时间、公式)。',
      required: true
    },
    {
@@ -308,19 +474,30 @@
      min: 1,
      max: 10,
      label: '高度(行)',
      initVal: card.height,
      tooltip: '内容显示行数,值为空时高度自适应,注:自适应高度仅在设置卡片高度后有效。',
      initVal: card.height !== undefined ? card.height : 1,
      tooltip: '内容显示行数,值为空时高度自适应。',
      required: false
    },
    {
      type: 'select',
      type: isStatic ? 'text' : 'select',
      key: 'bgImage',
      label: '动态背景',
      initVal: card.bgImage || '',
      tooltip: '绑定数据源字段,可根据返回值改变背景图。',
      required: false,
      allowClear: true,
      options: []
      options: fields,
      forbid: isHeader
    },
    {
      type: 'cascader',
      key: 'anchors',
      label: '跳转锚点',
      initVal: card.anchors || [],
      tooltip: sessionStorage.getItem('appType') === 'mob' ? '注:小程序中无效' : '',
      required: false,
      options: anchors,
      forbid: !anchors
    },
    {
      type: 'number',
@@ -367,7 +544,8 @@
      min: 0,
      max: 50,
      label: '线宽',
      initVal: card.borderWidth || 1,
      initVal: card.borderWidth === undefined ? 1 : card.borderWidth,
      tooltip: '线宽为0时,为方便在开发时选中默认高度为10px,请注意调整内外边距。',
      required: true
    },
    {
@@ -395,6 +573,18 @@
        { value: '9:16', text: '9:16' },
      ]
    },
    // {
    //   type: 'radio',
    //   key: 'backgroundSize',
    //   label: '图像大小',
    //   initVal: card.backgroundSize || 'cover',
    //   required: false,
    //   options: [
    //     { value: 'cover', text: '覆盖' },
    //     { value: 'contain', text: '包含' },
    //     { value: 'auto', text: '自适应' },
    //   ]
    // },
    {
      type: 'number',
      key: 'maxWidth',
@@ -403,6 +593,7 @@
      label: '最大宽度',
      initVal: card.maxWidth || '',
      tooltip: '图片宽度的最大值。',
      help: '注:此值存在时,左右外边距为0居中显示。',
      required: false,
    },
    {
@@ -421,27 +612,22 @@
      key: 'link',
      label: '链接',
      initVal: card.link || '',
      tooltip: '动态地址为绑定字段值。',
      tooltip: '动态地址为绑定字段值。使用 动态-关联菜单 时,请在“链接地址”字段返回菜单ID。',
      required: false,
      // forbid: isApp,
      options: [
        { value: '', text: '无' },
        { value: 'dynamic', text: '动态' },
        { value: 'static', text: '静态' }
      ]
      ],
      forbid: isHeader
    },
    {
      type: 'radio',
      type: 'select',
      key: 'linkType',
      label: '链接类型',
      initVal: card.linkType || 'other',
      required: false,
      // forbid: isApp,
      options: [
        { value: 'tel', text: '电话' },
        { value: 'email', text: '邮箱' },
        { value: 'other', text: '其他' }
      ]
      options: linkTypes
    },
    {
      type: 'radio',
@@ -459,65 +645,52 @@
      key: 'linkmenu',
      label: '关联菜单',
      initVal: card.linkmenu || '',
      tooltip: '行信息(字段集中前40个长度不超过256的字段)将传递至此菜单,可在url变量、表单(关联主表)、静态属性卡、浮动卡中使用。',
      required: true,
      forbid: !isApp,
      options: appMenus
      options: appMenus || [],
      forbid: !['pc', 'mob'].includes(appType)
    },
    // {
    //   type: 'radio',
    //   key: 'open',
    //   label: '打开方式',
    //   initVal: card.open || 'blank',
    //   required: false,
    //   forbid: !isApp,
    //   options: [
    //     { value: 'blank', text: '新页面' },
    //     { value: 'self', text: '当前页面' }
    //   ]
    // },
    {
      type: 'select',
      type: 'cascader',
      key: 'linkmenu',
      label: '关联菜单',
      initVal: card.linkmenu || [],
      tooltip: '行信息将传递至此菜单,可在url变量、表单(关联主表)、静态属性卡、浮动卡中使用。',
      required: true,
      options: menulist,
      forbid: ['pc', 'mob'].includes(appType)
    },
    {
      type: isStatic ? 'text' : 'select',
      defType: isStatic ? 'text' : 'select',
      key: 'linkurl',
      label: '链接地址',
      initVal: card.linkurl || '',
      tooltip: '在链接中以@***@形式拼接的字段(字段来源于字段集中,此外 id、appkey、userid、LoginUID 为系统字段),跳转时将替换为对应值,例如:http://sso.mk9h.cn/doc/index.html?appkey=@appkey@&LoginUID=@LoginUID@,其中appkey与LoginUID将被替换。' + (['pc', 'mob'].includes(appType) ? '当链接类型为“其他”,且链接地址以@menuid@开头时,其后内容将被视为菜单ID。' : ''),
      toolWidth: 350,
      required: true,
      options: []
      options: fields
    },
    {
      type: 'radio',
      key: 'joint',
      label: Formdict['model.form.paramJoint'],
      initVal: card.joint || 'true',
      required: false,
      options: [{
        value: 'true',
        text: Formdict['model.true']
      }, {
        value: 'false',
        text: Formdict['model.false']
      }]
      key: 'open',
      label: '打开方式',
      initVal: card.open || 'blank',
      tooltip: '菜单打开方式,链接无效。',
      required: true,
      forbid: !['pc', 'mob'].includes(appType),
      options: [
        {value: 'blank', text: appType !== 'mob' ? '新窗口' : '新页面'},
        {value: 'self', text: appType !== 'mob' ? '当前窗口' : '当前页面'},
      ]
    },
    {
      type: 'radio',
      key: 'eval',
      label: '解析',
      initVal: card.eval || 'true',
      tooltip: '当公式内容涉及计算时请选择“是”,当公式内容为字段拼接时请选择“否”。',
      required: false,
      options: [{
        value: 'true',
        text: Formdict['model.true']
      }, {
        value: 'false',
        text: Formdict['model.false']
      }]
    },
    {
      type: 'textarea',
      type: 'codemirror',
      key: 'formula',
      label: '公式',
      initVal: card.formula || '',
      tooltip: '执行时会使用查询到的数据替换相应的字段,展示获得的结果,在不使用解析时换行符或空格会替换为页面元素。可使用JS的一些语法,如:三元表达式 @field1@ > @field2@ ? 0 : 1;Math对象,取绝对值 Math.abs(@field@)、四舍五入 Math.round(@field@)等',
      tooltip: '执行时会使用查询到的数据替换相应的字段,展示获得的结果,在不使用解析时换行符或空格会替换为页面元素。可使用JS的一些语法,如:三元表达式 @field1@ > @field2@ ? 0 : 1;Math对象,取绝对值 Math.abs(@field@)、四舍五入 Math.round(@field@)等。注:会替换公式中的@username@、@fullName@、@bid@。',
      toolWidth: 450,
      placeholder: '例如:@price@ * @number@',
      required: true
    },
@@ -526,13 +699,163 @@
      key: 'noValue',
      label: '空值',
      initVal: card.noValue || 'show',
      tooltip: '当元素内容为空时,是否显示当前元素。',
      tooltip: '当元素内容为空时,是否显示当前元素。注:数值类型元素包括数字0(非文本)。',
      required: false,
      options: [
        { value: 'show', text: '显示' },
        { value: 'hide', text: '隐藏' }
      ]
    },
    {
      type: 'radio',
      key: 'lostTip',
      label: '图片缺失',
      initVal: card.lostTip || 'true',
      tooltip: '图片地址不存在时,是否提示图片丢失。',
      required: false,
      options: [
        { value: 'true', text: '提示' },
        { value: 'false', text: '不提示' }
      ]
    },
    {
      type: 'radio',
      key: 'alignItems',
      label: '垂直对齐',
      initVal: card.alignItems || '',
      tooltip: '垂直方向的对齐方式。注:高度(行)大于1时有效。',
      required: false,
      options: [
        { value: '', text: '居上' },
        { value: 'center', text: '居中' },
        { value: 'end', text: '居下' }
      ],
      forbid: isHeader
    },
    {
      type: 'radio',
      key: 'fixStyle',
      label: '前后缀',
      initVal: card.fixStyle || '',
      tooltip: '前缀与后缀,使用与内容统一的样式还是独立样式。',
      required: false,
      options: [
        { value: '', text: '统一样式' },
        { value: 'alone', text: '独立样式' }
      ],
      forbid: isHeader
    },
    {
      type: 'radio',
      key: 'copyable',
      label: '可复制',
      initVal: card.copyable || 'false',
      tooltip: '元素是否可复制,复制内容不包括前缀与后缀。',
      required: false,
      options: [
        { value: 'true', text: '是' },
        { value: 'false', text: '否' }
      ],
      forbid: isHeader
    },
    {
      type: 'number',
      key: 'fixSize',
      min: 10,
      max: 300,
      label: '字体大小',
      initVal: card.fixSize || 14,
      tooltip: '前缀、后缀的字体大小。',
      required: true
    },
    {
      type: 'color',
      key: 'fixColor',
      label: '字体颜色',
      initVal: card.fixColor || 'rgba(0, 0, 0, 0.65)',
      tooltip: '前缀、后缀的字体颜色。',
      required: true
    },
    {
      type: 'number',
      key: 'fixLeft',
      min: 0,
      max: 1000,
      label: '左边距',
      initVal: card.fixLeft || 0,
      tooltip: '前缀、后缀的左边距。',
      required: false
    },
    {
      type: 'number',
      key: 'fixRight',
      min: 0,
      max: 1000,
      label: '右边距',
      initVal: card.fixRight || 0,
      tooltip: '前缀、后缀的右边距。',
      required: false
    },
    {
      type: 'select',
      key: 'sortField',
      label: '排序字段',
      initVal: card.sortField || '',
      required: false,
      allowClear: true,
      options: [],
      forbid: !isHeader
    },
    {
      type: 'table',
      key: 'signs',
      label: '标记',
      initVal: card.signs || [],
      tooltip: '可依据标签内容设置不同样式。',
      required: false,
      actions: ['edit', 'del', 'add', 'move'],
      columns: [
        {
          title: '值',
          dataIndex: 'value',
          inputType: 'text',
          editable: true,
          required: true,
          unique: true,
          width: '20%'
        },
        {
          title: '背景',
          dataIndex: 'background',
          inputType: 'color',
          className: 'mini-color',
          editable: true,
          required: true,
          width: '20%',
          render: (text) => <span className="mk-color-value" style={{background: text}}></span>,
        },
        {
          title: '文字',
          dataIndex: 'color',
          inputType: 'color',
          className: 'mini-color',
          editable: true,
          required: true,
          width: '20%',
          render: (text) => <span className="mk-color-value" style={{background: text}}></span>,
        },
        {
          title: '边框',
          dataIndex: 'border',
          inputType: 'color',
          className: 'mini-color',
          editable: true,
          required: true,
          width: '20%',
          render: (text) => <span className="mk-color-value" style={{background: text}}></span>,
        },
      ]
    },
  ]
  return forms