CN-296 feat: 左侧筛选和搜索框交互、样式完成;数据未对接完成
This commit is contained in:
@@ -79,13 +79,15 @@ export default {
|
||||
this.$refs.tagMode && this.$refs.tagMode.addParams(params)
|
||||
this.$refs.textMode && this.$refs.textMode.addParams(params)
|
||||
},
|
||||
// params: [{column, operator, value}, ...]
|
||||
removeParams (params) {
|
||||
this.$refs.tagMode && this.$refs.tagMode.removeParams(params)
|
||||
this.$refs.textMode && this.$refs.textMode.removeParams(params)
|
||||
},
|
||||
changeParams (n, o) {
|
||||
this.$refs.tagMode && this.$refs.tagMode.changeParams(n, o)
|
||||
this.$refs.textMode && this.$refs.textMode.changeParams(n, o)
|
||||
// params: [{ newParam: {column, operator, value }, oldParam: { column, operator, value }], ...]
|
||||
changeParams (params) {
|
||||
this.$refs.tagMode && this.$refs.tagMode.changeParams(params)
|
||||
this.$refs.textMode && this.$refs.textMode.changeParams(params)
|
||||
},
|
||||
setSql (sql) {
|
||||
if (this.searchMode === 'text') {
|
||||
|
||||
@@ -242,8 +242,8 @@ export default {
|
||||
this.$emit('changeMode', 'text', formatSql)
|
||||
},
|
||||
// 处理value,例如转换IN的值
|
||||
handleValue (value, column) {
|
||||
const isArray = ['IN', 'NOT IN'].indexOf(column.operator.value) > -1
|
||||
handleValue (value, column, operator) {
|
||||
const isArray = ['IN', 'NOT IN'].indexOf(operator) > -1
|
||||
if (isArray) {
|
||||
if (this.$_.isArray(value)) {
|
||||
value = value.map(v => column.type === columnType.string ? stringInQuot(v) : v)
|
||||
@@ -266,14 +266,39 @@ export default {
|
||||
meta.column.label = column ? column.label : param.column
|
||||
meta.operator.value = '='
|
||||
meta.operator.show = true
|
||||
meta.value.value = this.handleValue(param.value, column)
|
||||
meta.value.value = this.handleValue(param.value, column, column.operator)
|
||||
meta.value.show = true
|
||||
meta.value.label = meta.value.value
|
||||
this.addCondition(meta)
|
||||
})
|
||||
},
|
||||
changeParams (params) {
|
||||
|
||||
params.forEach(param => {
|
||||
const oldColumn = this.columnList.find(column => {
|
||||
return column.name === param.oldParam.column
|
||||
})
|
||||
const newColumn = this.columnList.find(column => {
|
||||
return column.name === param.newParam.column
|
||||
})
|
||||
const meta = this.metaList.find(m => m.column.name === oldColumn.name && m.operator.value === param.oldParam.operator && m.value.value === this.handleValue(param.oldParam.value, oldColumn, param.oldParam.operator))
|
||||
if (meta) {
|
||||
meta.column.name = newColumn.name
|
||||
meta.column.type = newColumn.type
|
||||
meta.column.label = newColumn.label ? newColumn.label : newColumn.name
|
||||
meta.operator.value = param.newParam.operator
|
||||
meta.value.value = this.handleValue(param.newParam.value, newColumn, param.newParam.operator)
|
||||
meta.value.label = meta.value.value
|
||||
}
|
||||
})
|
||||
},
|
||||
removeParams (params) {
|
||||
params.forEach(param => {
|
||||
const column = this.columnList.find(c => {
|
||||
return c.name === param.column
|
||||
})
|
||||
const metaIndex = this.metaList.findIndex(m => m.column.name === param.column && m.operator.value === param.operator && m.value.value === this.handleValue(param.value, column, param.operator))
|
||||
this.metaList.splice(metaIndex, 1)
|
||||
})
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
|
||||
@@ -104,21 +104,27 @@ export default {
|
||||
})
|
||||
toRaw(this.codeMirror).setValue(current)
|
||||
},
|
||||
removeParams () {
|
||||
|
||||
removeParams (params) {
|
||||
let current = this.codeMirror.getValue()
|
||||
params.forEach(param => {
|
||||
const column = this.columnList.find(c => c.name === param.column)
|
||||
// 将对应内容替换为空串
|
||||
const sqlPiece = `${param.column}${handleOperatorSpace(param.operator)}${this.handleValue(param.value, column, param.operator)}`.trim()
|
||||
current = current.replace(sqlPiece, '')
|
||||
})
|
||||
toRaw(this.codeMirror).setValue(current)
|
||||
},
|
||||
changeParams (params) {
|
||||
Object.keys(params).forEach(key => {
|
||||
const column = this.columnList.find(column => {
|
||||
return column.name === key
|
||||
})
|
||||
console.info(this.columnList, params)
|
||||
let current = this.codeMirror.getValue()
|
||||
let selected = column.value
|
||||
// if (selected && selected.length )
|
||||
current = `${current ? current + 'AND ' : ''}${key}=${(column.type === columnType.string ? stringInQuot(params[key]) : params[key])}`
|
||||
toRaw(this.codeMirror).setValue(current)
|
||||
let current = this.codeMirror.getValue()
|
||||
params.forEach(param => {
|
||||
const oldColumn = this.columnList.find(c => c.name === param.oldParam.column)
|
||||
const newColumn = this.columnList.find(c => c.name === param.newParam.column)
|
||||
// 将oldParam内容替换为newParam
|
||||
const oldSqlPiece = `${param.oldParam.column}${handleOperatorSpace(param.oldParam.operator)}${this.handleValue(param.oldParam.value, oldColumn, param.oldParam.operator)}`.trim()
|
||||
const newSqlPiece = `${param.newParam.column}${handleOperatorSpace(param.newParam.operator)}${this.handleValue(param.newParam.value, newColumn, param.newParam.operator)}`.trim()
|
||||
current = current.replace(oldSqlPiece, newSqlPiece)
|
||||
})
|
||||
toRaw(this.codeMirror).setValue(current)
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
|
||||
@@ -70,6 +70,8 @@ export default class SqlParser extends SqlParserVisitor {
|
||||
let tempArr = temp.split(',')
|
||||
tempArr = tempArr.map(t => meta.column.type === columnType.string ? stringInQuot(t.trim()) : t.trim())
|
||||
meta.value.value = `(${tempArr.join(',')})`
|
||||
} else {
|
||||
meta.value.value = meta.column.type === columnType.string ? stringInQuot(meta.value.value.trim()) : meta.value.value.trim()
|
||||
}
|
||||
meta.value.label = meta.value.value
|
||||
}
|
||||
@@ -156,7 +158,7 @@ export default class SqlParser extends SqlParserVisitor {
|
||||
tempArr = tempArr.map(t => this.tempMeta.column.type === columnType.string ? stringInQuot(t.trim()) : t.trim())
|
||||
this.tempMeta.value.value = `(${tempArr.join(',')})`
|
||||
} else {
|
||||
this.tempMeta.value.value = value
|
||||
this.tempMeta.value.value = this.tempMeta.column.type === columnType.string ? stringInQuot(value.trim()) : value.trim()
|
||||
}
|
||||
this.tempMeta.value.label = this.tempMeta.value.value
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user