| | |
| | | import moment from 'moment' |
| | | |
| | | import Api from '@/api' |
| | | import { formRule } from '@/utils/option.js' |
| | | import Utils from '@/utils/utils.js' |
| | | import asyncComponent from '@/utils/asyncComponent' |
| | | import MKEmitter from '@/utils/events.js' |
| | |
| | | timestamp: '', |
| | | n_id: '', |
| | | focusId: '', |
| | | reFocusId: '' |
| | | reFocusId: '', |
| | | dict: window.GLOB.dict |
| | | } |
| | | |
| | | record = {} |
| | |
| | | |
| | | componentDidMount () { |
| | | const { action, unload } = this.props |
| | | const { dict } = this.state |
| | | |
| | | let data = {} |
| | | let BData = {} |
| | |
| | | let fieldMap = new Map() |
| | | let check = action.setting.formType === 'check' |
| | | |
| | | if (this.props.data) { |
| | | if (this.props.data && !this.props.data.$$empty) { |
| | | Object.keys(this.props.data).forEach(key => { |
| | | data[key.toLowerCase()] = this.props.data[key] |
| | | }) |
| | | } else if (action.uuid && sessionStorage.getItem('local_' + action.uuid)) { |
| | | let _data = JSON.parse(sessionStorage.getItem('local_' + action.uuid)) |
| | | |
| | | Object.keys(_data).forEach(key => { |
| | | data[key.toLowerCase()] = _data[key] |
| | | }) |
| | | } |
| | | |
| | | if (this.props.BData) { |
| | | Object.keys(this.props.BData).forEach(key => { |
| | | BData[key.toLowerCase()] = this.props.BData[key] |
| | |
| | | |
| | | // 数据自动填充 |
| | | let readin = item.readin !== 'false' |
| | | item.local = item.readin === 'local' |
| | | item.readin = item.readin !== 'false' && item.readin !== 'top' |
| | | item.readonly = check || item.readonly === 'true' |
| | | item.writein = item.writein !== 'false' |
| | |
| | | if (item.required === 'true') { |
| | | item.rules.push({ |
| | | required: true, |
| | | message: item.label + '不可为空!' |
| | | message: item.label + (dict['not_empty'] || '不可为空!') |
| | | }) |
| | | } |
| | | |
| | | item.rules.push({ |
| | | validator: (rule, value, callback) => { |
| | | if (/'/.test(value)) { |
| | | callback('不可使用英文状态的单引号!') |
| | | callback(dict['single_quot'] || '不可使用英文状态的单引号!') |
| | | // } else if (/--/.test(value)) { |
| | | // callback('不可使用 -- !') |
| | | } else { |
| | |
| | | if (!item.lenControl || item.lenControl === 'limit') { |
| | | item.rules.push({ |
| | | max: item.fieldlength, |
| | | message: formRule.input.formMessage.replace('@max', item.fieldlength) |
| | | message: (dict['max_char'] || '最多@max个字符').replace('@max', item.fieldlength) |
| | | }) |
| | | } |
| | | |
| | |
| | | } |
| | | item.rules.push({ |
| | | pattern: reg, |
| | | message: item.regularText || formRule.input.numbermsg |
| | | message: item.regularText || dict['enter_num'] || '请输入数字!' |
| | | }) |
| | | } else if (item.regular === 'letter') { |
| | | let reg = /^[a-zA-Z]*$/ |
| | |
| | | } |
| | | item.rules.push({ |
| | | pattern: reg, |
| | | message: item.regularText || formRule.input.lettermsg |
| | | message: item.regularText || dict['enter_letter'] || '请输入字母!' |
| | | }) |
| | | } else if (item.regular === 'letter_number') { |
| | | let reg = /^[a-zA-Z0-9]*$/ |
| | |
| | | } |
| | | item.rules.push({ |
| | | pattern: reg, |
| | | message: item.regularText || '请输入数字或字母' |
| | | message: item.regularText || dict['enter_num_letter'] || '请输入数字或字母' |
| | | }) |
| | | } else if (item.regular === 'letter&number') { |
| | | let reg = /^[a-zA-Z0-9@_.]*$/ |
| | |
| | | } |
| | | item.rules.push({ |
| | | pattern: reg, |
| | | message: item.regularText || '请输入数字、字母以及@_.' |
| | | message: item.regularText || dict['enter_num_letter_char'] || '请输入数字、字母以及@_.' |
| | | }) |
| | | } else if (item.regular === 'phone') { |
| | | item.rules.push({ |
| | | pattern: /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/, |
| | | message: item.regularText || '请正确输入手机号' |
| | | message: item.regularText || dict['phone_error'] || '请正确输入手机号' |
| | | }) |
| | | } else if (item.regular === 'email') { |
| | | item.rules.push({ |
| | | pattern: /^([a-zA-Z0-9._-])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])+/, |
| | | message: item.regularText || '请正确输入邮箱地址' |
| | | message: item.regularText || dict['email_error'] || '请正确输入邮箱地址' |
| | | }) |
| | | } |
| | | } |
| | | } else if (item.type === 'number') { |
| | | item.rules = [{ |
| | | required: true, |
| | | message: item.label + '不可为空!' |
| | | message: item.label + (dict['not_empty'] || '不可为空!') |
| | | }] |
| | | |
| | | if (typeof(item.min) === 'number' || typeof(item.max) === 'number' || item.notZero === 'true') { |
| | |
| | | if (isNaN(value)) { |
| | | callback() |
| | | } else if (item.notZero === 'true' && value === 0) { |
| | | callback(item.label + '不可为0') |
| | | callback(item.label + (dict['not_zero'] || '不可为0')) |
| | | } else if (typeof(item.min) === 'number' && value < item.min) { |
| | | if (item.min < 1e-6) { |
| | | if (item.min > 0 && item.min < 1e-6) { |
| | | if (item.min === 1e-6) { |
| | | callback(item.label + '最小值为 0.000001') |
| | | } else if (item.min === 1e-7) { |
| | |
| | | } else if (item.min === 1e-11) { |
| | | callback(item.label + '最小值为 0.00000000001') |
| | | } else { |
| | | callback(item.label + '最小值为 ' + item.min) |
| | | callback(item.label + (dict['less_limit'] || '最小值为 ') + item.min) |
| | | } |
| | | } else { |
| | | callback(item.label + '最小值为 ' + item.min) |
| | | callback(item.label + (dict['less_limit'] || '最小值为 ') + item.min) |
| | | } |
| | | } else if (typeof(item.max) === 'number' && value > item.max) { |
| | | callback(item.label + '最大值为 ' + item.max) |
| | | callback(item.label + (dict['max_limit'] || '最大值为 ') + item.max) |
| | | } else { |
| | | callback() |
| | | } |
| | |
| | | if (item.required === 'true') { |
| | | item.rules.push({ |
| | | required: true, |
| | | message: item.label + '不可为空!' |
| | | message: item.label + (dict['not_empty'] || '不可为空!') |
| | | }) |
| | | } |
| | | |
| | | item.rules.push({ |
| | | validator: (rule, value, callback) => { |
| | | if (/'/.test(value)) { |
| | | callback('不可使用英文状态的单引号!') |
| | | callback(dict['single_quot'] || '不可使用英文状态的单引号!') |
| | | // } else if (/--/.test(value)) { |
| | | // callback('不可使用 -- !') |
| | | } else { |
| | |
| | | } |
| | | }, { |
| | | max: item.fieldlength, |
| | | message: formRule.input.formMessage.replace('@max', item.fieldlength) |
| | | message: (dict['max_char'] || '最多@max个字符').replace('@max', item.fieldlength) |
| | | }) |
| | | } else if (item.type === 'brafteditor') { |
| | | if (item.required === 'true') { |
| | | item.rules.push({ |
| | | required: true, |
| | | message: item.label + '不可为空!' |
| | | message: item.label + (dict['not_empty'] || '不可为空!') |
| | | }) |
| | | } |
| | | |
| | | item.rules.push({ |
| | | max: item.fieldlength, |
| | | message: formRule.input.formMessage.replace('@max', item.fieldlength) |
| | | message: (dict['max_char'] || '最多@max个字符').replace('@max', item.fieldlength) |
| | | }) |
| | | } else if (item.type === 'linkMain' || item.type === 'vercode') { |
| | | if (item.required === 'true') { |
| | | item.rules.push({ |
| | | required: true, |
| | | message: item.label + '不可为空!' |
| | | message: item.label + (dict['not_empty'] || '不可为空!') |
| | | }) |
| | | } |
| | | } else { |
| | | if (item.required === 'true') { |
| | | item.rules.push({ |
| | | required: true, |
| | | message: '请选择' + item.label + '!' |
| | | message: (dict['select_tip'] || '请选择') + item.label + '!' |
| | | }) |
| | | } |
| | | if (['cascader', 'checkbox', 'checkcard', 'fileupload', 'multiselect'].includes(item.type) && item.fieldlength) { |
| | | item.rules.push({ |
| | | max: item.fieldlength, |
| | | message: formRule.input.formMessage.replace('@max', item.fieldlength) |
| | | message: (dict['max_char'] || '最多@max个字符').replace('@max', item.fieldlength) |
| | | }) |
| | | } |
| | | } |
| | |
| | | } |
| | | |
| | | getFormData = (deForms) => { |
| | | if (deForms.length === 1) { |
| | | if (window.backend && window.GLOB.CacheData.has('sql_' + deForms[0].uuid)) { |
| | | this.improveBackActionForm(deForms) |
| | | } else if (deForms.length === 1) { |
| | | this.improveSimpleActionForm(deForms) |
| | | } else if (!window.GLOB.mkHS && window.GLOB.sysType === 'local' && window.GLOB.systemType !== 'production') { |
| | | this.improveSimpleActionForm(deForms) |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * @description 获取下拉表单选项信息 |
| | | */ |
| | | improveBackActionForm = (deForms) => { |
| | | const { BID, action } = this.props |
| | | |
| | | let sysvals = { |
| | | mk_departmentcode: sessionStorage.getItem('departmentcode') || '', |
| | | mk_organization: sessionStorage.getItem('organization') || '', |
| | | mk_user_type: sessionStorage.getItem('mk_user_type') || '', |
| | | id: this.state.ID || '', |
| | | bid: BID || '', |
| | | datam: sessionStorage.getItem('dataM') === 'true' ? 'Y' : '', |
| | | datam_begin: sessionStorage.getItem('dataM') === 'true' ? 'Y' : '', |
| | | datam_end: sessionStorage.getItem('dataM') === 'true' ? 'Y' : '' |
| | | } |
| | | if (window.GLOB.externalDatabase !== null) { |
| | | sysvals.db = window.GLOB.externalDatabase |
| | | } |
| | | |
| | | let deffers = [] |
| | | let mainItems = [] // 云端或单点数据 |
| | | let localItems = [] // 本地数据 |
| | | let cache = action.setting.cache !== 'false' && !action.$cache |
| | | let skip = false |
| | | |
| | | deForms.forEach(item => { |
| | | let ex = window.GLOB.CacheData.get('sql_' + item.uuid) |
| | | |
| | | if (!ex) return |
| | | |
| | | let exps = [] |
| | | ex.reps.forEach(n => { |
| | | let key = n.toLowerCase() |
| | | if (sysvals.hasOwnProperty(key)) { |
| | | exps.push({ |
| | | key: n, |
| | | value: sysvals[key] |
| | | }) |
| | | } |
| | | }) |
| | | |
| | | let cell = { |
| | | id: ex.id, |
| | | menuname: item.label + '(表单)', |
| | | exps: exps, |
| | | md5_id: '' |
| | | } |
| | | |
| | | if (item.database === 'sso' && window.GLOB.mainSystemApi) { |
| | | mainItems.push(cell) |
| | | } else { |
| | | localItems.push(cell) |
| | | } |
| | | }) |
| | | |
| | | if (localItems.length) { |
| | | deffers.push({ |
| | | $backend: true, |
| | | $type: 's_Get_SelectedList', |
| | | data: localItems |
| | | }) |
| | | } |
| | | |
| | | if (mainItems.length) { |
| | | deffers.push({ |
| | | $backend: true, |
| | | $type: 's_Get_SelectedList', |
| | | data: mainItems, |
| | | rduri: window.GLOB.mainSystemApi |
| | | }) |
| | | } |
| | | |
| | | if (!deffers.length) return |
| | | |
| | | deffers = deffers.map(item => { |
| | | return new Promise(resolve => { |
| | | Api.getSystemCacheConfig(item, cache).then(res => { |
| | | if (!res.status) { |
| | | notification.warning({ |
| | | top: 92, |
| | | message: res.message, |
| | | duration: 5 |
| | | }) |
| | | skip = true |
| | | } |
| | | resolve(res) |
| | | }) |
| | | }) |
| | | }) |
| | | |
| | | Promise.all(deffers).then(response => { |
| | | let result = {...response[0], ...(response[1] || {})} |
| | | |
| | | delete result.ErrCode |
| | | delete result.ErrMesg |
| | | delete result.message |
| | | delete result.status |
| | | |
| | | this.resetFormList(result, skip) |
| | | }) |
| | | } |
| | | /** |
| | | * @description 获取下拉表单选项信息 |
| | | */ |
| | |
| | | sql = sql.replace(/@BID@/ig, `'${BID}'`) |
| | | |
| | | if (window.GLOB.debugger === true) { |
| | | console.info(sql) |
| | | window.mkInfo(sql) |
| | | } |
| | | |
| | | sql = sql.replace(/%/ig, ' mpercent ') |
| | |
| | | sql = sql.replace(/@BID@/ig, `'${BID}'`) |
| | | |
| | | if (window.GLOB.debugger === true) { |
| | | console.info(sql) |
| | | window.mkInfo(sql) |
| | | } |
| | | |
| | | sql = sql.replace(/%/ig, ' mpercent ') |
| | |
| | | param.LText = param.LText.replace(/@BID@/ig, `'${this.props.BID || ''}'`) |
| | | |
| | | if (window.GLOB.debugger) { |
| | | console.info(param.LText) |
| | | window.mkInfo(param.LText) |
| | | } |
| | | |
| | | if (window.GLOB.execType === 'x') { |
| | |
| | | } |
| | | |
| | | handleConfirm = (formId) => { |
| | | const { action } = this.props |
| | | const { formlist, send_type, timestamp, n_id } = this.state |
| | | |
| | | // 表单提交时检查输入值是否正确 |
| | |
| | | } |
| | | let forms = [] |
| | | let record = {...this.record, ...values} |
| | | let locals = null |
| | | |
| | | formlist.forEach(item => { |
| | | if (!item.field || ['hint', 'split', 'formula'].includes(item.type)) return |
| | |
| | | value: n_id || '' |
| | | }) |
| | | } |
| | | |
| | | if (item.local) { |
| | | locals = locals || {} |
| | | locals[item.field] = _item.value |
| | | } |
| | | |
| | | forms.push(_item) |
| | | }) |
| | | |
| | | this.submitId = formId || '' |
| | | |
| | | if (locals) { |
| | | sessionStorage.setItem('local_' + action.uuid, JSON.stringify(locals)) |
| | | } |
| | | |
| | | resolve(forms) |
| | | }) |
| | | }) |