1
0
mirror of https://github.com/PanJiaChen/vue-element-admin.git synced 2025-08-14 07:41:57 +08:00

fix: #386 Value preference with session context. (#387)

* fix: Value preference with session context.

* fix set value in field isParentLink or isKey

* remove unused attribute.

* Add additional attributes fieldTemplate.
This commit is contained in:
Edwin Betancourt 2020-03-11 21:27:09 -04:00 committed by GitHub
parent f57a3bd11e
commit 876b51cce3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 78 additions and 100 deletions

View File

@ -93,8 +93,8 @@ const browser = {
// Get dependent fields // Get dependent fields
fieldsList fieldsList
.filter(field => field.parentFieldsList && field.isActive)
.forEach((field, index, list) => { .forEach((field, index, list) => {
if (field.isActive && field.parentFieldsList.length) {
field.parentFieldsList.forEach(parentColumnName => { field.parentFieldsList.forEach(parentColumnName => {
const parentField = list.find(parentField => { const parentField = list.find(parentField => {
return parentField.columnName === parentColumnName && parentColumnName !== field.columnName return parentField.columnName === parentColumnName && parentColumnName !== field.columnName
@ -103,6 +103,7 @@ const browser = {
parentField.dependentFieldsList.push(field.columnName) parentField.dependentFieldsList.push(field.columnName)
} }
}) })
}
}) })
// Convert from gRPC process list // Convert from gRPC process list

View File

@ -97,7 +97,7 @@ const panel = {
}) })
let orderBy = 'sequence' let orderBy = 'sequence'
if ((params.panelType === 'window' && !params.isParent) || params.panelType === 'browser') { if ((params.panelType === 'window' && !params.isParentTab) || params.panelType === 'browser') {
orderBy = 'seqNoGrid' orderBy = 'seqNoGrid'
} }
params.fieldList = assignedGroup({ params.fieldList = assignedGroup({

View File

@ -252,7 +252,7 @@ const window = {
isAdvancedQuery isAdvancedQuery
} }
let fieldUuidsequence = 0 let isWithUuidField = false // indicates it contains the uuid field
let fieldLinkColumnName let fieldLinkColumnName
// Convert from gRPC // Convert from gRPC
const fieldsList = tabResponse.fieldsList.map((fieldItem, index) => { const fieldsList = tabResponse.fieldsList.map((fieldItem, index) => {
@ -263,8 +263,9 @@ const window = {
fieldListIndex: index fieldListIndex: index
} }
}) })
if (fieldItem.sequence > fieldUuidsequence) {
fieldUuidsequence = fieldItem.sequence if (!isWithUuidField && fieldItem.columnName === 'UUID') {
isWithUuidField = true
} }
if (fieldItem.isParent) { if (fieldItem.isParent) {
@ -277,8 +278,8 @@ const window = {
if (!isAdvancedQuery) { if (!isAdvancedQuery) {
// Get dependent fields // Get dependent fields
fieldsList fieldsList
.filter(field => field.parentFieldsList && field.isActive)
.forEach((field, index, list) => { .forEach((field, index, list) => {
if (field.parentFieldsList.length && field.isActive) {
field.parentFieldsList.forEach(parentColumnName => { field.parentFieldsList.forEach(parentColumnName => {
const parentField = list.find(parentField => { const parentField = list.find(parentField => {
return parentField.columnName === parentColumnName && parentColumnName !== field.columnName return parentField.columnName === parentColumnName && parentColumnName !== field.columnName
@ -287,20 +288,19 @@ const window = {
parentField.dependentFieldsList.push(field.columnName) parentField.dependentFieldsList.push(field.columnName)
} }
}) })
}
}) })
} }
if (!fieldsList.find(field => field.columnName === 'UUID')) { if (!isWithUuidField) {
const attributesOverwrite = { const fieldUuid = getFieldTemplate({
panelType: panelType, ...additionalAttributes,
sequence: (fieldUuidsequence + 10), isShowedFromUser: false,
name: 'UUID', name: 'UUID',
columnName: 'UUID', columnName: 'UUID',
isAdvancedQuery,
componentPath: 'FieldText' componentPath: 'FieldText'
} })
const field = getFieldTemplate(attributesOverwrite) fieldsList.push(fieldUuid)
fieldsList.push(field)
} }
const window = getters.getWindow(parentUuid) const window = getters.getWindow(parentUuid)

View File

@ -23,38 +23,19 @@ export const getContext = ({
* @param {string} mandatoryLogic * @param {string} mandatoryLogic
* @param {string} readOnlyLogic * @param {string} readOnlyLogic
* @param {string} defaultValue * @param {string} defaultValue
* @returns {array} List column name of parent fields
*/ */
export function getParentFields({ displayLogic, mandatoryLogic, readOnlyLogic, defaultValue }) { export function getParentFields({ displayLogic, mandatoryLogic, readOnlyLogic, defaultValue }) {
let parentFields = [] return Array.from(new Set([
// For Display logic // For Display logic
if (displayLogic) { ...evaluator.parseDepends(displayLogic),
parentFields = Array.from(new Set([
...parentFields,
...evaluator.parseDepends(displayLogic)
]))
}
// For Mandatory Logic // For Mandatory Logic
if (mandatoryLogic) { ...evaluator.parseDepends(mandatoryLogic),
parentFields = Array.from(new Set([
...parentFields,
...evaluator.parseDepends(mandatoryLogic)
]))
}
// For Read Only Logic // For Read Only Logic
if (readOnlyLogic) { ...evaluator.parseDepends(readOnlyLogic),
parentFields = Array.from(new Set([
...parentFields,
...evaluator.parseDepends(readOnlyLogic)
]))
}
// For Default Value // For Default Value
if (defaultValue) {
parentFields = Array.from(new Set([
...parentFields,
...evaluator.parseDepends(defaultValue) ...evaluator.parseDepends(defaultValue)
])) ]))
}
return parentFields
} }
/** /**
@ -88,14 +69,14 @@ export function parseContext({
if (value.includes('@SQL=')) { if (value.includes('@SQL=')) {
value = value.replace('@SQL=', '') value = value.replace('@SQL=', '')
} }
// var instances = value.length - value.replace('@', '').length // const instances = value.length - value.replace('@', '').length
// if ((instances > 0) && (instances % 2) !== 0) { // could be an email address // if ((instances > 0) && (instances % 2) !== 0) { // could be an email address
// return value // return value
// } // }
var token let token, contextInfo
var inString = value let inString = value
var outString = '' let outString = ''
let firstIndexTag = inString.indexOf('@') let firstIndexTag = inString.indexOf('@')
@ -117,7 +98,7 @@ export function parseContext({
token = inString.substring(0, secondIndexTag) token = inString.substring(0, secondIndexTag)
columnName = token columnName = token
var contextInfo = getContext({ contextInfo = getContext({
parentUuid, parentUuid,
containerUuid, containerUuid,
columnName columnName

View File

@ -37,7 +37,8 @@ export function generateField({
operator = 'LIKE' operator = 'LIKE'
} }
} else { } else {
if (String(parsedDefaultValue).includes('@')) { if (String(parsedDefaultValue).includes('@') &&
String(parsedDefaultValue).trim() !== '-1') {
parsedDefaultValue = parseContext({ parsedDefaultValue = parseContext({
...moreAttributes, ...moreAttributes,
columnName: fieldToGenerate.columnName, columnName: fieldToGenerate.columnName,
@ -46,8 +47,8 @@ export function generateField({
}).value }).value
} }
if ((isEmptyValue(parsedDefaultValue) || if (isEmptyValue(parsedDefaultValue) &&
String(parsedDefaultValue).includes('@')) && !(fieldToGenerate.isKey || fieldToGenerate.isParent) &&
String(parsedDefaultValue).trim() !== '-1') { String(parsedDefaultValue).trim() !== '-1') {
parsedDefaultValue = getPreference({ parsedDefaultValue = getPreference({
parentUuid: fieldToGenerate.parentUuid, parentUuid: fieldToGenerate.parentUuid,
@ -57,9 +58,7 @@ export function generateField({
// search value preference with elementName // search value preference with elementName
if (!isEmptyValue(fieldToGenerate.elementName) && if (!isEmptyValue(fieldToGenerate.elementName) &&
(isEmptyValue(parsedDefaultValue) || isEmptyValue(parsedDefaultValue)) {
String(parsedDefaultValue).includes('@')) &&
String(parsedDefaultValue).trim() !== '-1') {
parsedDefaultValue = getPreference({ parsedDefaultValue = getPreference({
parentUuid: fieldToGenerate.parentUuid, parentUuid: fieldToGenerate.parentUuid,
containerUuid: fieldToGenerate.containerUuid, containerUuid: fieldToGenerate.containerUuid,
@ -76,9 +75,8 @@ export function generateField({
}) })
// VALUE TO // VALUE TO
// if (String(parsedDefaultValueTo).includes('@SQL=')) { if (String(parsedDefaultValueTo).includes('@') &&
// parsedDefaultValueTo.replace('@SQL=', '') String(parsedDefaultValueTo).trim() !== '-1') {
if (String(parsedDefaultValueTo).includes('@')) {
parsedDefaultValueTo = parseContext({ parsedDefaultValueTo = parseContext({
...moreAttributes, ...moreAttributes,
columnName: `${fieldToGenerate.columnName}_To`, columnName: `${fieldToGenerate.columnName}_To`,
@ -86,8 +84,8 @@ export function generateField({
}).value }).value
} }
if ((isEmptyValue(parsedDefaultValueTo) || if (isEmptyValue(parsedDefaultValueTo) &&
String(parsedDefaultValueTo).includes('@')) && !(fieldToGenerate.isKey || fieldToGenerate.isParent) &&
String(parsedDefaultValueTo).trim() !== '-1') { String(parsedDefaultValueTo).trim() !== '-1') {
parsedDefaultValueTo = getPreference({ parsedDefaultValueTo = getPreference({
parentUuid: fieldToGenerate.parentUuid, parentUuid: fieldToGenerate.parentUuid,
@ -97,9 +95,7 @@ export function generateField({
// search value preference with elementName // search value preference with elementName
if (!isEmptyValue(fieldToGenerate.elementName) && if (!isEmptyValue(fieldToGenerate.elementName) &&
(isEmptyValue(parsedDefaultValueTo) || isEmptyValue(parsedDefaultValueTo)) {
String(parsedDefaultValueTo).includes('@')) &&
String(parsedDefaultValueTo).trim() !== '-1') {
parsedDefaultValueTo = getPreference({ parsedDefaultValueTo = getPreference({
parentUuid: fieldToGenerate.parentUuid, parentUuid: fieldToGenerate.parentUuid,
containerUuid: fieldToGenerate.containerUuid, containerUuid: fieldToGenerate.containerUuid,
@ -260,8 +256,8 @@ export function generateProcess({ processToGenerate, containerUuidAssociated = u
// Get dependent fields // Get dependent fields
fieldDefinitionList fieldDefinitionList
.filter(field => field.parentFieldsList && field.isActive)
.forEach((field, index, list) => { .forEach((field, index, list) => {
if (field.isActive && field.parentFieldsList.length) {
field.parentFieldsList.forEach(parentColumnName => { field.parentFieldsList.forEach(parentColumnName => {
const parentField = list.find(itemParentField => { const parentField = list.find(itemParentField => {
return itemParentField.columnName === parentColumnName && parentColumnName !== field.columnName return itemParentField.columnName === parentColumnName && parentColumnName !== field.columnName
@ -270,6 +266,7 @@ export function generateProcess({ processToGenerate, containerUuidAssociated = u
parentField.dependentFieldsList.push(field.columnName) parentField.dependentFieldsList.push(field.columnName)
} }
}) })
}
}) })
} }
@ -392,18 +389,7 @@ export function evalutateTypeField(displayTypeId, isAllInfo = false) {
// Default template for injected fields // Default template for injected fields
export function getFieldTemplate(attributesOverwrite) { export function getFieldTemplate(attributesOverwrite) {
const referenceValue = { return {
tableName: '',
keyColumnName: '',
displayColumnName: '',
query: '',
parsedQuery: '',
directQuery: '',
parsedDirectQuery: '',
validationCode: '',
windowsList: []
}
const newField = {
id: 0, id: 0,
uuid: '', uuid: '',
name: '', name: '',
@ -452,16 +438,26 @@ export function getFieldTemplate(attributesOverwrite) {
readOnlyLogic: undefined, readOnlyLogic: undefined,
parentFieldsList: undefined, parentFieldsList: undefined,
dependentFieldsList: [], dependentFieldsList: [],
reference: referenceValue, reference: {
tableName: '',
keyColumnName: '',
displayColumnName: '',
query: '',
parsedQuery: '',
directQuery: '',
parsedDirectQuery: '',
validationCode: '',
windowsList: []
},
contextInfo: undefined, contextInfo: undefined,
isShowedFromUser: false, isShowedFromUser: false,
isFixedTableColumn: false, isFixedTableColumn: false,
sizeFieldFromType: { sizeFieldFromType: {
type: 'Button', type: 'Button',
size: DEFAULT_SIZE size: DEFAULT_SIZE
},
...attributesOverwrite
} }
}
return Object.assign(newField, attributesOverwrite)
} }
/** /**