king
2022-08-06 cbeffcc0902631909c0373f274752a97ddaf2d4e
src/menu/components/share/actioncomponent/formconfig.jsx
@@ -1,5 +1,6 @@
import zhCN from '@/locales/zh-CN/model.js'
import enUS from '@/locales/en-US/model.js'
import { btnCustomClasses } from '@/utils/option.js'
const Formdict = sessionStorage.getItem('lang') !== 'en-US' ? zhCN : enUS
@@ -11,8 +12,11 @@
 * @param {*} usefulFields   存储过程可用的开始字段
 * @param {*} type           按钮类型,用于区分可选的打开方式
 */
export function getActionForm (card, functip, config, usefulFields, type, menulist = [], modules = []) {
export function getActionForm (card, functip, config, usefulFields, type, menulist = [], modules = [], anchors = []) {
  let appType = sessionStorage.getItem('appType')
  let viewType = sessionStorage.getItem('editMenuType') // 弹窗 popview
  let printTemps = sessionStorage.getItem('printTemps')
  printTemps = printTemps ? JSON.parse(printTemps) : []
  let setting = config.setting || {}
  let columns = config.columns || []
  let appMenus = []
@@ -47,6 +51,32 @@
    }
  ]
  let getTabs = (list) => {
    return list.filter(item => {
      if (item.type !== 'tabs') return false
      item.children = item.children.map(cell => {
        cell.children = getTabs(cell.children)
        return cell
      })
      return item
    })
  }
  // if (type === 'editable') {
  //   opentypes = [
  //     {
  //       value: 'excelIn',
  //       text: Formdict['model.form.excelIn']
  //     }, {
  //       value: 'excelOut',
  //       text: Formdict['model.form.excelOut']
  //     }
  //   ]
  // }
  let tabs = getTabs(JSON.parse(JSON.stringify(modules)))
  let pageTemps = [
    { value: 'billprint', text: '单据打印' },
    { value: 'pay', text: Formdict['model.pay'] },
@@ -55,22 +85,14 @@
  const isApp = ['pc', 'mob'].includes(appType)
  let funTypes = [
    { value: 'changeuser', text: Formdict['header.form.func.changeuser'] },
    { value: 'changeuser', text: '切换用户' },
    { value: 'print', text: '标签打印' },
    { value: 'closetab', text: '标签关闭' },
    { value: 'megvii', text: '旷视面板机' },
    { value: 'filezip', text: '文件压缩包' },
  ]
  
  if (isApp) {
    pageTemps = [
      // { value: 'page', text: '菜单' },
      { value: 'linkpage', text: '关联菜单' },
      { value: 'billprint', text: '单据打印' },
      { value: 'pay', text: Formdict['model.pay'] },
      { value: 'custom', text: '链接' }
    ]
    funTypes = [
      { value: 'changeuser', text: Formdict['header.form.func.changeuser'] },
    ]
    appMenus = sessionStorage.getItem('appMenus')
    if (appMenus) {
      try {
@@ -81,18 +103,36 @@
    } else {
      appMenus = []
    }
    if (appType === 'mob') {
      opentypes = opentypes.filter(item => ['pop', 'prompt', 'exec', 'innerpage', 'funcbutton'].includes(item.value))
      funTypes = [
        { value: 'mkBinding', text: '开通扫码登录' },
        { value: 'mkUnBinding', text: '用户解绑' },
        { value: 'scan', text: '扫一扫' },
        { value: 'reAuth', text: '重新授权' },
      ]
    } else {
      opentypes = opentypes.filter(item => item.value !== 'tab')
    }
  }
  if (appType === 'mob') {
    opentypes = opentypes.filter(item => ['pop', 'prompt', 'exec', 'innerpage', 'funcbutton'].includes(item.value))
    funTypes = [
      { value: 'scan', text: '扫码' },
      { value: 'pay', text: '支付' },
      { value: 'resetPwd', text: '修改密码'},
      { value: 'mkBinding', text: '开通扫码登录' },
      { value: 'mkUnBinding', text: '用户解绑' },
      { value: 'mkUnsubscribe', text: '注销账户' },
      { value: 'reAuth', text: '切换系统(清空缓存-小程序)' },
      { value: 'copyurl', text: '复制链接地址' },
      { value: 'logout', text: '退出' },
      { value: 'goBack', text: '返回' },
    ]
    pageTemps = [
      { value: 'linkpage', text: '关联菜单' },
      { value: 'custom', text: '链接' }
    ]
  } else if (appType === 'pc') {
    opentypes = opentypes.filter(item => item.value !== 'tab')
    funTypes = [
      { value: 'changeuser', text: '切换用户' },
    ]
    pageTemps = [
      { value: 'linkpage', text: '关联菜单' },
      { value: 'billprint', text: '单据打印' },
      { value: 'pay', text: Formdict['model.pay'] },
      { value: 'custom', text: '链接' }
    ]
  }
  
  if (type === 'chart' && appType !== 'mob') {
@@ -100,12 +140,43 @@
  }
  let refresh = []
  if (sessionStorage.getItem('editMenuType') === 'popview') { // 弹窗标签
  if (viewType === 'popview') { // 弹窗标签
    opentypes = opentypes.filter(item => item.value !== 'popview' && item.value !== 'funcbutton')
    refresh.push({
      value: 'popclose',
      text: '标签刷新'
      value: 'closepoptab', // 关闭弹窗标签
      text: '关闭弹窗'
    })
    refresh.push({
      value: 'popclose',  // 执行弹窗关闭时的刷新
      text: '刷新源组件'
    })
  }
  if (type === 'card') {
    opentypes.push({
      value: 'form',
      text: '表单(开关或勾选框)'
    })
  }
  if (!card.control && card.controlField) {
    card.control = 'disabled'
  }
  if (appType === 'mob' && card.control === 'parent') {
    card.control = ''
  }
  if (card.execSuccess === 'goback') {
    card.openmenu = 'goback'
    card.execSuccess = 'never'
  }
  let closetab = []
  if (!appType) {
    closetab = [{
      value: 'closetab',
      text: '关闭标签'
    }]
  }
  let forms = [
@@ -118,12 +189,43 @@
      options: opentypes
    },
    {
      type: 'text',
      key: 'label',
      label: '按钮名称',
      initVal: card.label,
      required: true,
    },
    {
      type: 'select',
      key: 'funcType',
      label: Formdict['header.form.funcType'],
      label: '功能类型',
      initVal: card.funcType || '',
      required: true,
      options: funTypes
    },
    {
      type: 'radio',
      key: 'subFunc',
      label: '接口名称',
      initVal: card.subFunc || 'addUser',
      required: true,
      options: [
        { value: 'addUser', text: '添加用户' },
      ]
    },
    {
      type: 'radio',
      key: 'formType',
      label: '表单类型',
      initVal: card.formType || 'switch',
      required: true,
      options: [{
        value: 'switch',
        text: '开关'
      }, {
        value: 'radio',
        text: '勾选框'
      }]
    },
    {
      type: 'select',
@@ -151,12 +253,18 @@
      options: []
    },
    {
      type: 'text',
      key: 'label',
      label: '按钮名称',
      initVal: card.label,
      type: 'checkbox',
      key: 'payType',
      label: '支付方式',
      initVal: card.payType || [],
      required: true,
      readonly: false
      options: [{
        value: 'wxpay',
        text: '微信'
      }, {
        value: 'alipay',
        text: '支付宝'
      }]
    },
    {
      type: 'radio',
@@ -170,6 +278,9 @@
      }, {
        value: 'inner',
        text: '内部函数'
      }, {
        value: 'none',
        text: '无'
      }]
    },
    {
@@ -194,7 +305,14 @@
      initVal: card.innerFunc || '',
      tooltip: functip,
      fields: usefulFields,
      tooltipClass: 'middle',
      required: false,
    },
    {
      type: 'text',
      key: 'urlkey',
      label: '地址字段',
      initVal: card.urlkey || '',
      tooltip: '图片(文件)链接的字段名。',
      required: false,
      readonly: false
    },
@@ -208,12 +326,20 @@
    },
    {
      type: 'select',
      key: 'printTemp',
      label: '打印模板',
      initVal: card.printTemp || '',
      required: true,
      options: printTemps
    },
    {
      type: isApp ? 'select' : 'cascader',
      key: 'linkmenu',
      label: '关联菜单',
      initVal: card.linkmenu || '',
      initVal: card.linkmenu || (isApp ? '' : []),
      required: true,
      forbid: !isApp,
      options: appMenus
      extendName: 'MenuNo',
      options: isApp ? appMenus : menulist
    },
    {
      type: 'textarea',
@@ -242,7 +368,6 @@
      label: Formdict['header.form.outerFunc'],
      initVal: card.outerFunc || '',
      required: false,
      readonly: false
    },
    {
      type: 'textarea',
@@ -302,6 +427,12 @@
      }, {
        value: 'default',
        text: '后台脚本'
      }, {
        value: 'func',
        text: '回调函数'
      }, {
        value: 'none',
        text: '无'
      }]
    },
    {
@@ -316,53 +447,37 @@
      key: 'callbackFunc',
      label: Formdict['header.form.callbackFunc'],
      initVal: card.callbackFunc || '',
      required: false,
      readonly: false
      required: true
    },
    {
      type: 'select',
      key: 'Ot',
      label: Formdict['header.form.isRequired'],
      initVal: card.Ot || 'requiredSgl',
      initVal: card.Ot || (card.sqlType === 'insert' ? 'notRequired' : 'requiredSgl'),
      required: true,
      forbid: card.$type === 'tableButton',
      options: []
    },
    {
      type: 'cascader',
      key: 'linkmenu',
      label: Formdict['model.form.linkmenu'],
      initVal: card.linkmenu || [],
      required: true,
      forbid: isApp,
      options: menulist
    },
    {
      type: 'cascader',
      key: 'refreshTab',
      label: '刷新标签',
      initVal: card.refreshTab || [],
      required: false,
      forbid: isApp,
      options: menulist
    },
    {
      type: 'select',
      key: 'execSuccess',
      label: Formdict['model.form.afterSuccess'],
      initVal: card.execSuccess || 'never',
      tooltip: refresh.length ? '执行标签刷新时,会同步刷新当前组件和上级组件-行。' : '刷新上级组件-行时,会同步刷新当前组件,注:上级组件在数据源中添加。',
      initVal: card.execSuccess || 'grid',
      tooltip: refresh.length ? '执行刷新源组件时,请在源按钮中设置关闭后刷新那一项,注:此时会同步刷新当前组件和上级组件-行。' : '选择刷新行时,如果选择多条数据会刷新表格。注:上级组件在数据源中添加。',
      required: true,
      options: [{
        value: 'never',
        text: Formdict['header.form.refresh.never']
      }, {
        value: 'line',
        text: '刷新行'
      }, {
        value: 'grid',
        text: '刷新当前组件'
      }, {
        value: 'mainline',
        text: '刷新上级组件 - 行'
      },
      },
      ...closetab,
      ...refresh]
    },
    {
@@ -370,11 +485,14 @@
      key: 'execError',
      label: Formdict['model.form.afterError'],
      initVal: card.execError || 'never',
      tooltip: refresh.length ? '执行标签关闭刷新时,会同步刷新当前组件和上级组件-行。' : '刷新上级组件-行时,会同步刷新当前组件,注:上级组件在数据源中添加。',
      tooltip: refresh.length ? '执行刷新源组件时,请在源按钮中设置关闭后刷新那一项,注:此时会同步刷新当前组件和上级组件-行。' : '选择刷新行时,如果选择多条数据会刷新表格,注:上级组件在数据源中添加。',
      required: true,
      options: [{
        value: 'never',
        text: Formdict['header.form.refresh.never']
      }, {
        value: 'line',
        text: '刷新行'
      }, {
        value: 'grid',
        text: '刷新当前组件'
@@ -433,6 +551,7 @@
      label: '显示为',
      initVal: card.show || 'button',
      required: true,
      forbid: type === 'datacard' && appType === 'mob', // 移动端,滑动显示的按钮只显示文字
      options: [{
        value: 'icon',
        text: '图标'
@@ -448,13 +567,13 @@
      type: 'radio',
      key: 'swipe',
      label: "滑动显示",
      initVal: card.swipe || 'false',
      initVal: card.swipe === 'false' ? 'left' : (card.swipe || 'left'), // 移动端仅保留滑动显示按钮
      required: false,
      forbid: (type !== 'datacard' || appType !== 'mob'),
      options: [{
        value: 'false',
        text: '否'
      }, {
      //   value: 'false',
      //   text: '否'
      // }, {
        value: 'left',
        text: '左滑'
      }, {
@@ -468,6 +587,7 @@
      label: Formdict['model.icon'],
      initVal: card.icon,
      required: false,
      forbid: type === 'datacard' && appType === 'mob', // 移动端,滑动显示的按钮只显示文字
      options: []
    },
    {
@@ -477,7 +597,32 @@
      initVal: card.class,
      tooltip: '此颜色为按钮初始化颜色,可在样式调整中修改。',
      required: false,
      options: []
      forbid: type === 'datacard' && appType === 'mob', // 移动端,滑动显示的按钮不设置通用颜色
      options: btnCustomClasses
    },
    {
      type: 'radio',
      key: 'color',
      label: Formdict['model.form.color'],
      initVal: card.color || 'primary',
      required: false,
      forbid: (type !== 'datacard' || appType !== 'mob'), // 移动端,滑动显示的按钮只可设置固定颜色
      options: [{
        value: 'primary',
        text: '蓝'
      }, {
        value: 'danger',
        text: '红'
      }, {
        value: 'warning',
        text: '橙'
      }, {
        value: 'success',
        text: '绿'
      }, {
        value: 'light',
        text: '灰'
      }]
    },
    {
      type: 'radio',
@@ -503,7 +648,7 @@
    {
      type: 'radio',
      key: 'pagination',
      label: Formdict['header.form.pagination'],
      label: '分页',
      initVal: card.pagination || 'false',
      required: false,
      options: [{
@@ -529,49 +674,69 @@
      }]
    },
    {
      type: 'mcascader',
      type: 'cascader',
      key: 'syncComponent',
      label: '同步刷新',
      label: '刷新组件',
      initVal: card.syncComponent || [],
      tooltip: '执行成功后(或弹窗标签关闭时),需要同步刷新的组件。注:选择当前组件的上级组件无效。',
      required: false,
      options: modules
    },
    {
      type: 'select',
      key: 'controlField',
      label: '控制字段',
      tooltip: '禁用控制字段,可根据数据控制按钮是否禁用。',
      initVal: card.controlField || '',
      type: 'cascader',
      key: 'switchTab',
      label: '切换标签',
      initVal: card.switchTab || [],
      tooltip: '执行成功后,需要切换的标签页。' + (appType === 'mob' ? '注:小程序中无效' : ''),
      required: false,
      allowClear: true,
      options: columns
      options: tabs
    },
    {
      type: 'text',
      key: 'controlVal',
      label: '控制值',
      tooltip: '当选择控制字段,且字段值与控制值相等时,按钮会禁用,多个值用逗号分隔。',
      initVal: card.controlVal || '',
      required: false
      type: 'cascader',
      key: 'anchors',
      label: '跳转锚点',
      initVal: card.anchors || [],
      tooltip: '执行成功后,需要跳转的锚点。' + (appType === 'mob' ? '注:小程序中无效' : ''),
      required: false,
      options: anchors
    },
    {
      type: 'select',
      type: 'cascader',
      key: 'refreshTab',
      label: '刷新菜单',
      initVal: card.refreshTab || [],
      tooltip: '执行成功后(或功能按钮中标签关闭类型),需要同步刷新的菜单',
      required: false,
      forbid: isApp || viewType === 'popview',
      options: menulist
    },
    {
      type: !appType ? 'cascader' : 'select',
      key: 'openmenu',
      label: '打开菜单',
      tooltip: '执行成功后需要打开的菜单。',
      initVal: card.openmenu || '',
      forbid: appType !== 'pc' && appType !== 'mob',
      initVal: card.openmenu || (!appType ? [] : ''),
      help: appType === 'mob' || appType === 'pc' ? '可返回上一页。' : null,
      required: false,
      allowClear: true,
      options: appType !== 'mob' ? appMenus : [...appMenus, {value: 'goback', text: '返回'}]
      options: appType === 'mob' || appType === 'pc' ? [...appMenus, {value: 'goback', text: '返回(上一页)'}] : menulist,
      forbid: viewType === 'popview'
    },
    {
      type: 'text',
      key: 'output',
      label: '返回值',
      tooltip: '执行成功后的返回值。',
      tooltip: '执行成功后的返回值。系统函数可指定返回的变量(以@符开头,如@id);自定义函数可指定返回字段(如id)。',
      initVal: card.output || '',
      forbid: appType !== 'pc' && appType !== 'mob',
      required: false,
      forbid: viewType === 'popview'
    },
    {
      type: 'text',
      key: 'tipTitle',
      label: '确认提示',
      initVal: card.tipTitle || '',
      tooltip: '注:弹窗(表单)在显示为是否框时有效。',
      required: false
    },
    {
@@ -579,15 +744,13 @@
      key: 'open',
      label: '打开方式',
      initVal: card.open || 'blank',
      tooltip: '菜单打开方式。',
      required: true,
      forbid: appType !== 'pc',
      options: [{
        value: 'blank',
        text: '新窗口'
      }, {
        value: 'self',
        text: '当前窗口'
      }]
      forbid: appType !== 'pc' && appType !== 'mob',
      options: [
        {value: 'blank', text: appType !== 'mob' ? '新窗口' : '新页面'},
        {value: 'self', text: appType !== 'mob' ? '当前窗口' : '当前页面'},
      ]
    },
    {
      type: 'radio',
@@ -607,11 +770,11 @@
      type: 'number',
      key: 'ratio',
      min: 1,
      max: 24,
      max: 3000,
      precision: 0,
      label: '比例',
      initVal: card.ratio || 85,
      tooltip: '小于100为宽度(或高度)百分比,大于100为像素值。',
      tooltip: '模态框或抽屉的宽度,小于100为窗口宽度(或高度)百分比,大于100为像素值。',
      required: true
    },
    {
@@ -619,7 +782,6 @@
      key: 'placement',
      label: '抽屉方向',
      initVal: card.placement || 'right',
      tooltip: '使用抽屉时有效。',
      required: false,
      options: [{
        value: 'right',
@@ -635,6 +797,185 @@
        text: '下侧'
      }]
    },
    {
      type: 'radio',
      key: 'clickouter',
      label: '点击蒙层',
      initVal: card.clickouter || 'unclose',
      required: false,
      options: [{
        value: 'unclose',
        text: '不关闭'
      }, {
        value: 'close',
        text: '关闭'
      }]
    },
    {
      type: 'radio',
      key: 'reload',
      label: '上一页',
      initVal: card.reload || 'false',
      tooltip: '成功后是否刷新上页的数据。注:在明科云APP或小程序中有效。',
      forbid: appType !== 'mob',
      options: [{
        value: 'false',
        text: '不刷新'
      }, {
        value: 'true',
        text: '刷新'
      }]
    },
    {
      type: 'radio',
      key: 'position',
      label: '显示位置',
      initVal: card.position || 'middle',
      tooltip: '注:弹窗(表单)在显示为是否框时有效。',
      required: false,
      forbid: appType !== 'mob',
      options: [{
        value: 'middle',
        text: '中部'
      }, {
        value: 'bottom',
        text: '底部'
      }]
    },
    {
      type: 'radio',
      key: 'control',
      label: '按钮控制',
      initVal: card.control || (card.controlField ? 'disabled' : ''),
      tooltip: '当选择禁用或隐藏,且字段值与控制值相等时,按钮会隐藏或禁用。当选择上级,主表字段值与控制值相等或主表字段值不存在时,按钮会隐藏。注:多个值用逗号分隔',
      required: false,
      options: [{
        value: '',
        text: '无'
      }, {
        value: 'disabled',
        text: '禁用'
      }, {
        value: 'hidden',
        text: '隐藏'
      }, {
        value: 'parent',
        text: '上级'
      }]
    },
    {
      type: 'select',
      key: 'controlField',
      label: '控制字段',
      initVal: card.controlField || '',
      required: true,
      allowClear: true,
      options: columns
    },
    {
      type: 'text',
      key: 'controlVal',
      label: '控制值',
      initVal: card.controlVal || '',
      required: false
    },
    {
      type: 'text',
      key: 'reason',
      label: '禁用原因',
      initVal: card.reason || '',
      required: false
    },
    {
      type: 'splitLine',
      key: 'title',
      label: '表单',
      initVal: ''
    },
    {
      type: 'text',
      key: 'field',
      label: Formdict['model.form.field'],
      initVal: card.field || '',
      required: true,
      readonly: false
    },
    {
      type: 'radio',
      key: 'size',
      label: '开关尺寸',
      initVal: card.size || 'default',
      options: [{
        value: 'large',
        text: '大'
      }, {
        value: 'default',
        text: '中'
      }, {
        value: 'small',
        text: '小'
      }]
    },
    {
      type: 'text',
      key: 'openVal',
      label: '开启值',
      initVal: card.openVal === undefined ? '' : card.openVal + '',
      tooltip: '当开启与关闭值均为正整数时,默认转换为INT类型。',
      required: false
    },
    {
      type: 'text',
      key: 'closeVal',
      label: '关闭值',
      initVal: card.closeVal === undefined ? '' : card.closeVal + '',
      tooltip: '当开启与关闭值均为正整数时,默认转换为INT类型。',
      required: false
    },
    {
      type: 'text',
      key: 'openText',
      label: '开启提示',
      initVal: card.openText || '',
      required: false,
    },
    {
      type: 'text',
      key: 'closeText',
      label: '关闭提示',
      initVal: card.closeText || '',
      required: false,
    },
    {
      type: 'radio',
      key: 'hidden',
      label: '隐藏',
      initVal: card.hidden || 'false',
      tooltip: '隐藏后按钮在页面中不显示,且不参与权限分配。',
      required: false,
      options: [{
        value: 'false',
        text: '否'
      }, {
        value: 'true',
        text: '是'
      }]
    },
    {
      type: 'radio',
      key: 'progress',
      label: '进度提示',
      initVal: card.progress || 'number',
      required: false,
      forbid: appType === 'mob',
      options: [{
        value: 'number',
        text: '剩余数'
      }, {
        value: 'progressbar',
        text: '进度条'
      }]
    }
  ]
  return forms