|
|
@@ -6,11 +6,16 @@
|
|
|
:label-align="labelPosition"
|
|
|
:input-align="inputAlign"
|
|
|
>
|
|
|
- <template v-for="(field,index) in formDef.fields">
|
|
|
+ <template v-for="(field, index) in formDef.fields">
|
|
|
<!--栅格布局-->
|
|
|
<ibps-dynamic-form-grid
|
|
|
- v-if="field.field_type === 'grid' || field.field_type === 'tabs' ||field.field_type === 'steps' || field.field_type === 'collapse'"
|
|
|
- :key="field.name+index"
|
|
|
+ v-if="
|
|
|
+ field.field_type === 'grid' ||
|
|
|
+ field.field_type === 'tabs' ||
|
|
|
+ field.field_type === 'steps' ||
|
|
|
+ field.field_type === 'collapse'
|
|
|
+ "
|
|
|
+ :key="field.name + index"
|
|
|
ref="formItem"
|
|
|
:models.sync="models"
|
|
|
:rights.sync="rights"
|
|
|
@@ -18,7 +23,6 @@
|
|
|
:code="code"
|
|
|
:form-opinion="responseFormOpinionData[field.name]"
|
|
|
:desc-position="formDef.attrs.descPosition"
|
|
|
-
|
|
|
:params="formParams"
|
|
|
:readonly-rights="readonlyRights"
|
|
|
@change-form-opinion="handleFormOpinion"
|
|
|
@@ -26,14 +30,13 @@
|
|
|
<ibps-dynamic-form-item
|
|
|
v-else
|
|
|
ref="formItem"
|
|
|
- :key="field.name+index"
|
|
|
+ :key="field.name + index"
|
|
|
:models.sync="models"
|
|
|
:rights.sync="rights"
|
|
|
:field="field"
|
|
|
:code="code"
|
|
|
:form-opinion="responseFormOpinionData[field.name]"
|
|
|
:desc-position="formDef.attrs.descPosition"
|
|
|
-
|
|
|
:params="formParams"
|
|
|
:readonly-rights="readonlyRights"
|
|
|
@change-form-opinion="handleFormOpinion"
|
|
|
@@ -43,7 +46,6 @@
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
-
|
|
|
import FormOptions from '../constants/formOptions'
|
|
|
import FormUtils from '../utils/formUtil'
|
|
|
|
|
|
@@ -71,7 +73,8 @@ export default {
|
|
|
columnMinWidth: {
|
|
|
type: String
|
|
|
},
|
|
|
- validateImmediately: { // 是否初始验证
|
|
|
+ validateImmediately: {
|
|
|
+ // 是否初始验证
|
|
|
type: Boolean,
|
|
|
default: true
|
|
|
},
|
|
|
@@ -108,20 +111,29 @@ export default {
|
|
|
return !!(this.formAttrs && this.formAttrs.colon)
|
|
|
},
|
|
|
labelWidth() {
|
|
|
- if (this.$utils.isNotEmpty(this.formAttrs.labelWidth) && this.$utils.isNotEmpty(this.formAttrs.labelWidthUnit)) {
|
|
|
+ if (
|
|
|
+ this.$utils.isNotEmpty(this.formAttrs.labelWidth) &&
|
|
|
+ this.$utils.isNotEmpty(this.formAttrs.labelWidthUnit)
|
|
|
+ ) {
|
|
|
return this.formAttrs.labelWidth + this.formAttrs.labelWidthUnit
|
|
|
} else {
|
|
|
return '100px'
|
|
|
}
|
|
|
},
|
|
|
labelPosition() {
|
|
|
- return this.$utils.isNotEmpty(this.formAttrs.mobileLabelPosition) ? this.formAttrs.mobileLabelPosition : 'right'
|
|
|
+ return this.$utils.isNotEmpty(this.formAttrs.mobileLabelPosition)
|
|
|
+ ? this.formAttrs.mobileLabelPosition
|
|
|
+ : 'right'
|
|
|
},
|
|
|
inputAlign() {
|
|
|
- return this.$utils.isNotEmpty(this.formAttrs.mobileInputAlign) ? this.formAttrs.mobileInputAlign : 'left'
|
|
|
+ return this.$utils.isNotEmpty(this.formAttrs.mobileInputAlign)
|
|
|
+ ? this.formAttrs.mobileInputAlign
|
|
|
+ : 'left'
|
|
|
},
|
|
|
customClass() {
|
|
|
- return this.$utils.isNotEmpty(this.formAttrs.customClass) ? this.formAttrs.customClass : null
|
|
|
+ return this.$utils.isNotEmpty(this.formAttrs.customClass)
|
|
|
+ ? this.formAttrs.customClass
|
|
|
+ : null
|
|
|
},
|
|
|
code() {
|
|
|
return this.formDef.code
|
|
|
@@ -130,12 +142,19 @@ export default {
|
|
|
return this.readonly
|
|
|
},
|
|
|
readonlyStyle() {
|
|
|
- return this.formAttrs && this.formAttrs.read_style ? this.formAttrs.read_style : 'text'
|
|
|
+ return this.formAttrs && this.formAttrs.read_style
|
|
|
+ ? this.formAttrs.read_style
|
|
|
+ : 'text'
|
|
|
},
|
|
|
hasScript() {
|
|
|
- return this.formAttrs ? this.$utils.isNotEmpty(this.formAttrs.mobile_script) : false
|
|
|
- },
|
|
|
- formParams() { // 扩展参数
|
|
|
+ return this.formAttrs
|
|
|
+ ? this.$utils.isNotEmpty(this.formAttrs.mobile_script)
|
|
|
+ ? this.$utils.isNotEmpty(this.formAttrs.mobile_script)
|
|
|
+ : this.$utils.isNotEmpty(this.formAttrs.script)
|
|
|
+ : false
|
|
|
+ },
|
|
|
+ formParams() {
|
|
|
+ // 扩展参数
|
|
|
const params = {
|
|
|
code: this.code,
|
|
|
responseFormula: this.responseFormula,
|
|
|
@@ -161,12 +180,13 @@ export default {
|
|
|
handler(val) {
|
|
|
// 延迟验证
|
|
|
this.$nextTick(() => {
|
|
|
- this.getFormValidator().then(() => { }).catch(() => {})
|
|
|
+ this.getFormValidator()
|
|
|
+ .then(() => {})
|
|
|
+ .catch(() => {})
|
|
|
})
|
|
|
},
|
|
|
deep: true,
|
|
|
immediate: true
|
|
|
-
|
|
|
},
|
|
|
initialization(val) {
|
|
|
if (val && this.hasScript) {
|
|
|
@@ -178,7 +198,9 @@ export default {
|
|
|
// 初始化脚本
|
|
|
this.$nextTick(() => {
|
|
|
if (this.validateImmediately) {
|
|
|
- this.getFormValidator().then(() => { }).catch(() => {})
|
|
|
+ this.getFormValidator()
|
|
|
+ .then(() => {})
|
|
|
+ .catch(() => {})
|
|
|
}
|
|
|
})
|
|
|
},
|
|
|
@@ -188,7 +210,9 @@ export default {
|
|
|
*/
|
|
|
async initResponseFields() {
|
|
|
const fields = this.formDef.fields
|
|
|
- if (!fields) { return }
|
|
|
+ if (!fields) {
|
|
|
+ return
|
|
|
+ }
|
|
|
await this.generateModles(fields)
|
|
|
// 初始化运行公式计算
|
|
|
await this.initRunCalFormula()
|
|
|
@@ -205,20 +229,27 @@ export default {
|
|
|
const fieldType = field.field_type
|
|
|
const fieldOptions = field.field_options
|
|
|
|
|
|
- if (FormOptions.t.NESTED_FIELD_TYPES.includes(fieldType)) { // 嵌套布局
|
|
|
- if (this.$utils.isNotEmpty(fieldOptions) && this.$utils.isNotEmpty(fieldOptions.columns)) {
|
|
|
+ if (FormOptions.t.NESTED_FIELD_TYPES.includes(fieldType)) {
|
|
|
+ // 嵌套布局
|
|
|
+ if (
|
|
|
+ this.$utils.isNotEmpty(fieldOptions) &&
|
|
|
+ this.$utils.isNotEmpty(fieldOptions.columns)
|
|
|
+ ) {
|
|
|
// 循环遍历所有字段
|
|
|
fieldOptions.columns.forEach(item => {
|
|
|
this.generateModles(item.fields)
|
|
|
})
|
|
|
}
|
|
|
- } else if (fieldType === 'table') { // 子表单
|
|
|
+ } else if (fieldType === 'table') {
|
|
|
+ // 子表单
|
|
|
const data = this.value ? this.value[fieldName] : []
|
|
|
if (fieldOptions.mode === 'block') {
|
|
|
if (this.$utils.isEmpty(data)) {
|
|
|
this.$set(this.models, fieldName, [])
|
|
|
const defaultValue = await FormUtils.getTableDefaultData(field)
|
|
|
- this.models[fieldName].push(JSON.parse(JSON.stringify(defaultValue)))
|
|
|
+ this.models[fieldName].push(
|
|
|
+ JSON.parse(JSON.stringify(defaultValue))
|
|
|
+ )
|
|
|
} else {
|
|
|
this.models[fieldName] = data || []
|
|
|
}
|
|
|
@@ -227,30 +258,41 @@ export default {
|
|
|
}
|
|
|
// 初始化表单扩展参数
|
|
|
this.initFormFieldParameter(field)
|
|
|
- } else if (fieldType === 'approval_opinion') { // 审批意见
|
|
|
+ } else if (fieldType === 'approval_opinion') {
|
|
|
+ // 审批意见
|
|
|
this.models[fieldName] = ''
|
|
|
this.responseOpinionFields[fieldName] = field
|
|
|
// ====== 初始化表单权限
|
|
|
this.initFormApprovalOpinionRights(field)
|
|
|
} else {
|
|
|
- if (fieldType === 'label') { // 文本字段
|
|
|
+ if (fieldType === 'label') {
|
|
|
+ // 文本字段
|
|
|
this.responseLabelFields[fieldName] = field
|
|
|
}
|
|
|
// 不是只读字段
|
|
|
if (!FormOptions.t.NON_MODEL_FIELD_TYPES.includes(fieldType)) {
|
|
|
// 空值默认
|
|
|
- const defaultValueEmpty = this.$utils.toBoolean(fieldOptions.default_value_empty, true)
|
|
|
- if (this.value && Object.keys(this.value).indexOf(fieldName) >= 0) { // 有值
|
|
|
+ const defaultValueEmpty = this.$utils.toBoolean(
|
|
|
+ fieldOptions.default_value_empty,
|
|
|
+ true
|
|
|
+ )
|
|
|
+ if (this.value && Object.keys(this.value).indexOf(fieldName) >= 0) {
|
|
|
+ // 有值
|
|
|
const data = this.value[fieldName]
|
|
|
if (this.$utils.isEmpty(data)) {
|
|
|
if (defaultValueEmpty) {
|
|
|
- this.models[fieldName] = await FormUtils.getFieldDefaultValue(field)
|
|
|
+ this.models[fieldName] = await FormUtils.getFieldDefaultValue(
|
|
|
+ field
|
|
|
+ )
|
|
|
}
|
|
|
} else {
|
|
|
this.models[fieldName] = await this.getInitData(field, data)
|
|
|
}
|
|
|
- } else { // 默认值
|
|
|
- this.models[fieldName] = await FormUtils.getFieldDefaultValue(field)
|
|
|
+ } else {
|
|
|
+ // 默认值
|
|
|
+ this.models[fieldName] = await FormUtils.getFieldDefaultValue(
|
|
|
+ field
|
|
|
+ )
|
|
|
}
|
|
|
}
|
|
|
// 初始化表单扩展参数
|
|
|
@@ -260,8 +302,12 @@ export default {
|
|
|
},
|
|
|
async getInitData(field, data) {
|
|
|
const fieldType = field.field_type
|
|
|
- const copyFlow = this.$utils.toBoolean(this.formParams ? this.formParams.copyFlow : false, false)
|
|
|
- if (fieldType === 'autoNumber' && copyFlow) { // 复制流程初始化数据
|
|
|
+ const copyFlow = this.$utils.toBoolean(
|
|
|
+ this.formParams ? this.formParams.copyFlow : false,
|
|
|
+ false
|
|
|
+ )
|
|
|
+ if (fieldType === 'autoNumber' && copyFlow) {
|
|
|
+ // 复制流程初始化数据
|
|
|
return await FormUtils.getFieldDefaultValue(field)
|
|
|
}
|
|
|
return data
|
|
|
@@ -278,38 +324,57 @@ export default {
|
|
|
this.initResponseLinkages(field)
|
|
|
},
|
|
|
initFormApprovalOpinionRights(field) {
|
|
|
- this.rights[field.name] = FormUtils.getDefaultApprovalOpinionRigths(field, this.params) || this.getPermissions(this.permissions, field) || FormUtils.getDefaultRigths(field)
|
|
|
+ this.rights[field.name] =
|
|
|
+ FormUtils.getDefaultApprovalOpinionRigths(field, this.params) ||
|
|
|
+ this.getPermissions(this.permissions, field) ||
|
|
|
+ FormUtils.getDefaultRigths(field)
|
|
|
},
|
|
|
/**
|
|
|
* 初始化表单权限
|
|
|
*/
|
|
|
initFormRights(field) {
|
|
|
- this.rights[field.name] = this.getPermissions(this.permissions, field) || FormUtils.getDefaultRigths(field)
|
|
|
+ this.rights[field.name] =
|
|
|
+ this.getPermissions(this.permissions, field) ||
|
|
|
+ FormUtils.getDefaultRigths(field)
|
|
|
},
|
|
|
// 获取权限
|
|
|
getPermissions(permissions, field) {
|
|
|
- if (this.$utils.isEmpty(permissions)) { return }
|
|
|
+ if (this.$utils.isEmpty(permissions)) {
|
|
|
+ return
|
|
|
+ }
|
|
|
const fieldType = field.field_type
|
|
|
const name = field.name
|
|
|
let rightsValue = null
|
|
|
- const isNonInputField = FormOptions.t.NON_INPUT_FIELD_TYPES.includes(fieldType)
|
|
|
+ const isNonInputField = FormOptions.t.NON_INPUT_FIELD_TYPES.includes(
|
|
|
+ fieldType
|
|
|
+ )
|
|
|
let isSpecial = false
|
|
|
- if (isNonInputField && permissions.fields) { // 非输入字段
|
|
|
+ if (isNonInputField && permissions.fields) {
|
|
|
+ // 非输入字段
|
|
|
rightsValue = permissions.fields[name] ? permissions.fields[name] : null
|
|
|
- } else if (fieldType === 'approval_opinion' && permissions.opinions) { // 意见 特殊处理
|
|
|
- rightsValue = permissions.opinions[name] ? permissions.opinions[name] : null
|
|
|
- } else if (fieldType === 'table' && permissions.tables) { // 子表
|
|
|
+ } else if (fieldType === 'approval_opinion' && permissions.opinions) {
|
|
|
+ // 意见 特殊处理
|
|
|
+ rightsValue = permissions.opinions[name]
|
|
|
+ ? permissions.opinions[name]
|
|
|
+ : null
|
|
|
+ } else if (fieldType === 'table' && permissions.tables) {
|
|
|
+ // 子表
|
|
|
isSpecial = true
|
|
|
rightsValue = permissions.tables[name] ? permissions.tables[name] : null
|
|
|
- } else { // 字段
|
|
|
+ } else {
|
|
|
+ // 字段
|
|
|
rightsValue = permissions.fields[name] ? permissions.fields[name] : null
|
|
|
}
|
|
|
- if (this.readonly && !isNonInputField && !isSpecial) { // 只读权限
|
|
|
+ if (this.readonly && !isNonInputField && !isSpecial) {
|
|
|
+ // 只读权限
|
|
|
// 修复空权限默认值的bug
|
|
|
if (this.$utils.isEmpty(rightsValue)) {
|
|
|
rightsValue = FormUtils.getDefaultRigths(field)
|
|
|
}
|
|
|
- rightsValue = rightsValue !== FormOptions.t.PERMISSIONS.HIDE ? FormOptions.t.PERMISSIONS.READ : rightsValue
|
|
|
+ rightsValue =
|
|
|
+ rightsValue !== FormOptions.t.PERMISSIONS.HIDE
|
|
|
+ ? FormOptions.t.PERMISSIONS.READ
|
|
|
+ : rightsValue
|
|
|
}
|
|
|
return rightsValue
|
|
|
},
|
|
|
@@ -320,7 +385,11 @@ export default {
|
|
|
// 初始化运行公式计算
|
|
|
initRunCalFormula() {
|
|
|
// 不需要字段的进行公式计算 比如获取但其当前时间
|
|
|
- FormUtils.runCalFormula(this, this.responseFormula[FormUtils.NOT_NEED_FIELD], this.formDef.code)
|
|
|
+ FormUtils.runCalFormula(
|
|
|
+ this,
|
|
|
+ this.responseFormula[FormUtils.NOT_NEED_FIELD],
|
|
|
+ this.formDef.code
|
|
|
+ )
|
|
|
},
|
|
|
// 初始化联动数据
|
|
|
initResponseLinkages(item) {
|
|
|
@@ -335,7 +404,8 @@ export default {
|
|
|
}
|
|
|
const hasBindNode = opinionData.hasBindNode
|
|
|
const formOpinionConfig = opinionData.formOpinionConfig
|
|
|
- if (hasBindNode) { // 1、有流程节点绑定的流程意见
|
|
|
+ if (hasBindNode) {
|
|
|
+ // 1、有流程节点绑定的流程意见
|
|
|
const nodeData = opinionData.formOpinionNodeData
|
|
|
for (const key in this.responseOpinionFields) {
|
|
|
if (this.responseOpinionFields.hasOwnProperty(key)) {
|
|
|
@@ -381,7 +451,13 @@ export default {
|
|
|
const formData = this.getFormData()
|
|
|
for (let i = 0; i < verifys.length; i++) {
|
|
|
const verify = verifys[i]
|
|
|
- if (!FormUtils.runFormSubmitVerify(verify.formula, formData, this.formDef.code)) {
|
|
|
+ if (
|
|
|
+ !FormUtils.runFormSubmitVerify(
|
|
|
+ verify.formula,
|
|
|
+ formData,
|
|
|
+ this.formDef.code
|
|
|
+ )
|
|
|
+ ) {
|
|
|
flag = false
|
|
|
callback(flag, verify.msg)
|
|
|
return
|
|
|
@@ -397,7 +473,10 @@ export default {
|
|
|
const data = {}
|
|
|
// 去除文本字段,表单意见字段
|
|
|
for (var key in this.models) {
|
|
|
- if (!this.responseOpinionFields[key] && !this.responseLabelFields[key]) {
|
|
|
+ if (
|
|
|
+ !this.responseOpinionFields[key] &&
|
|
|
+ !this.responseLabelFields[key]
|
|
|
+ ) {
|
|
|
data[key] = this.models[key]
|
|
|
}
|
|
|
}
|
|
|
@@ -427,8 +506,12 @@ export default {
|
|
|
getFormOpinionData() {
|
|
|
const data = {}
|
|
|
for (var key in this.models) {
|
|
|
- if (this.responseOpinionFields[key] &&
|
|
|
- (this.$utils.isEmpty(this.rights[key]) || this.rights[key] === (FormOptions.t.PERMISSIONS.EDIT || FormOptions.t.PERMISSIONS.REQUIRED))
|
|
|
+ if (
|
|
|
+ this.responseOpinionFields[key] &&
|
|
|
+ (this.$utils.isEmpty(this.rights[key]) ||
|
|
|
+ this.rights[key] ===
|
|
|
+ (FormOptions.t.PERMISSIONS.EDIT ||
|
|
|
+ FormOptions.t.PERMISSIONS.REQUIRED))
|
|
|
) {
|
|
|
data[key] = this.models[key]
|
|
|
}
|
|
|
@@ -446,16 +529,21 @@ export default {
|
|
|
let i = 0
|
|
|
if (flag) {
|
|
|
for (const key in this.responseOpinionFields) {
|
|
|
- if (this.$utils.isEmpty(this.models[key]) && (
|
|
|
- this.$utils.isEmpty(this.rights[key]) ||
|
|
|
- this.rights[key] === FormOptions.t.PERMISSIONS.EDIT ||
|
|
|
- this.rights[key] === FormOptions.t.PERMISSIONS.REQUIRED)) {
|
|
|
+ if (
|
|
|
+ this.$utils.isEmpty(this.models[key]) &&
|
|
|
+ (this.$utils.isEmpty(this.rights[key]) ||
|
|
|
+ this.rights[key] === FormOptions.t.PERMISSIONS.EDIT ||
|
|
|
+ this.rights[key] === FormOptions.t.PERMISSIONS.REQUIRED)
|
|
|
+ ) {
|
|
|
i++
|
|
|
}
|
|
|
}
|
|
|
} else {
|
|
|
for (const key in this.responseOpinionFields) {
|
|
|
- if (this.$utils.isEmpty(this.models[key]) && this.rights[key] === FormOptions.t.PERMISSIONS.REQUIRED) {
|
|
|
+ if (
|
|
|
+ this.$utils.isEmpty(this.models[key]) &&
|
|
|
+ this.rights[key] === FormOptions.t.PERMISSIONS.REQUIRED
|
|
|
+ ) {
|
|
|
i++
|
|
|
}
|
|
|
}
|
|
|
@@ -483,4 +571,3 @@ export default {
|
|
|
}
|
|
|
}
|
|
|
</script>
|
|
|
-
|