@ -16,6 +16,17 @@
* /
* /
< template >
< template >
< div class = "datax-model" >
< div class = "datax-model" >
< m -list -box >
< div slot = "text" > { { $t ( 'Custom template' ) } } < / div >
< div slot = "content" >
< label class = "label-box" >
< div style = "padding-top: 5px;" >
< x -switch v-model ="enable" @on-click="_onSwitch" :disabled ="isDetails" > < / x -switch >
< / div >
< / label >
< / div >
< / m - l i s t - b o x >
< div v-if ="!enable" >
< m -list -box >
< m -list -box >
< div slot = "text" > { { $t ( 'Datasource' ) } } < / div >
< div slot = "text" > { { $t ( 'Datasource' ) } } < / div >
< div slot = "content" >
< div slot = "content" >
@ -102,6 +113,32 @@
< / div >
< / div >
< / m - l i s t - b o x >
< / m - l i s t - b o x >
< / div >
< / div >
< div v-else >
< m -list -box >
< div slot = "text" > json < / div >
< div slot = "content" >
< div class = "from-mirror" >
< textarea
id = "code-json-mirror"
name = "code-json-mirror"
style = "opacity: 0;" >
< / textarea >
< / div >
< / div >
< / m - l i s t - b o x >
< m -list -box >
< div slot = "text" > { { $t ( 'Custom Parameters' ) } } < / div >
< div slot = "content" >
< m -local -params
ref = "refLocalParams"
@ on - local - params = "_onLocalParams"
: udp - list = "localParams"
: hide = "false" >
< / m - l o c a l - p a r a m s >
< / div >
< / m - l i s t - b o x >
< / div >
< / div >
< / template >
< / template >
< script >
< script >
import _ from 'lodash'
import _ from 'lodash'
@ -115,12 +152,15 @@
import codemirror from '@/conf/home/pages/resource/pages/file/pages/_source/codemirror'
import codemirror from '@/conf/home/pages/resource/pages/file/pages/_source/codemirror'
let editor
let editor
let jsonEditor
export default {
export default {
name : 'datax' ,
name : 'datax' ,
data ( ) {
data ( ) {
return {
return {
/ / D a t a C u s t o m t e m p l a t e
enable : false ,
/ / D a t a s o u r c e t y p e
/ / D a t a s o u r c e t y p e
dsType : '' ,
dsType : '' ,
/ / d a t a s o u r c e
/ / d a t a s o u r c e
@ -135,6 +175,7 @@
rtDatatarget : '' ,
rtDatatarget : '' ,
/ / S q l s t a t e m e n t
/ / S q l s t a t e m e n t
sql : '' ,
sql : '' ,
json : '' ,
/ / t a r g e t t a b l e
/ / t a r g e t t a b l e
targetTable : '' ,
targetTable : '' ,
/ / P r e s t a t e m e n t s
/ / P r e s t a t e m e n t s
@ -145,6 +186,9 @@
jobSpeedByte : 0 ,
jobSpeedByte : 0 ,
/ / s p e e d r e c o r d
/ / s p e e d r e c o r d
jobSpeedRecord : 1000 ,
jobSpeedRecord : 1000 ,
/ / C u s t o m p a r a m e t e r
localParams : [ ] ,
customConfig : 0 ,
}
}
} ,
} ,
mixins : [ disabledState ] ,
mixins : [ disabledState ] ,
@ -153,6 +197,19 @@
createNodeId : Number
createNodeId : Number
} ,
} ,
methods : {
methods : {
_onSwitch ( is ) {
if ( is ) {
this . customConfig = 1
setTimeout ( ( ) => {
this . _handlerJsonEditor ( )
} , 200 )
} else {
this . customConfig = 0
setTimeout ( ( ) => {
this . _handlerEditor ( )
} , 200 )
}
} ,
/ * *
/ * *
* return data source
* return data source
* /
* /
@ -183,6 +240,20 @@
* verification
* verification
* /
* /
_verification ( ) {
_verification ( ) {
if ( this . customConfig ) {
if ( ! jsonEditor . getValue ( ) ) {
this . $message . warning ( ` ${ i18n . $t ( 'Please enter a JSON Statement(required)' ) } ` )
return false
}
/ / s t o r a g e
this . $emit ( 'on-params' , {
customConfig : this . customConfig ,
json : jsonEditor . getValue ( ) ,
localParams : this . localParams
} )
return true
} else {
if ( ! editor . getValue ( ) ) {
if ( ! editor . getValue ( ) ) {
this . $message . warning ( ` ${ i18n . $t ( 'Please enter a SQL Statement(required)' ) } ` )
this . $message . warning ( ` ${ i18n . $t ( 'Please enter a SQL Statement(required)' ) } ` )
return false
return false
@ -215,6 +286,7 @@
/ / s t o r a g e
/ / s t o r a g e
this . $emit ( 'on-params' , {
this . $emit ( 'on-params' , {
customConfig : this . customConfig ,
dsType : this . dsType ,
dsType : this . dsType ,
dataSource : this . rtDatasource ,
dataSource : this . rtDatasource ,
dtType : this . dtType ,
dtType : this . dtType ,
@ -227,6 +299,7 @@
postStatements : this . postStatements
postStatements : this . postStatements
} )
} )
return true
return true
}
} ,
} ,
/ * *
/ * *
* Processing code highlighting
* Processing code highlighting
@ -259,6 +332,34 @@
return editor
return editor
} ,
} ,
_handlerJsonEditor ( ) {
this . _destroyJsonEditor ( )
/ / j s o n E d i t o r
jsonEditor = codemirror ( 'code-json-mirror' , {
mode : 'json' ,
readOnly : this . isDetails
} )
this . keypress = ( ) => {
if ( ! jsonEditor . getOption ( 'readOnly' ) ) {
jsonEditor . showHint ( {
completeSingle : false
} )
}
}
/ / M o n i t o r k e y b o a r d
jsonEditor . on ( 'keypress' , this . keypress )
jsonEditor . on ( 'changes' , ( ) => {
/ / t h i s . _ c a c h e P a r a m s ( )
} )
jsonEditor . setValue ( this . json )
return jsonEditor
} ,
_cacheParams ( ) {
_cacheParams ( ) {
this . $emit ( 'on-cache-params' , {
this . $emit ( 'on-cache-params' , {
dsType : this . dsType ,
dsType : this . dsType ,
@ -279,6 +380,13 @@
editor . off ( $ ( '.code-sql-mirror' ) , 'keypress' , this . keypress )
editor . off ( $ ( '.code-sql-mirror' ) , 'keypress' , this . keypress )
editor . off ( $ ( '.code-sql-mirror' ) , 'changes' , this . changes )
editor . off ( $ ( '.code-sql-mirror' ) , 'changes' , this . changes )
}
}
} ,
_destroyJsonEditor ( ) {
if ( jsonEditor ) {
jsonEditor . toTextArea ( ) / / U n i n s t a l l
jsonEditor . off ( $ ( '.code-json-mirror' ) , 'keypress' , this . keypress )
jsonEditor . off ( $ ( '.code-json-mirror' ) , 'changes' , this . changes )
}
}
}
} ,
} ,
created ( ) {
created ( ) {
@ -287,6 +395,9 @@
/ / N o n - n u l l o b j e c t s r e p r e s e n t b a c k f i l l
/ / N o n - n u l l o b j e c t s r e p r e s e n t b a c k f i l l
if ( ! _ . isEmpty ( o ) ) {
if ( ! _ . isEmpty ( o ) ) {
/ / b a c k f i l l
/ / b a c k f i l l
if ( o . params . customConfig == 0 ) {
this . customConfig = 0
this . enable = false
this . dsType = o . params . dsType || ''
this . dsType = o . params . dsType || ''
this . datasource = o . params . dataSource || ''
this . datasource = o . params . dataSource || ''
this . dtType = o . params . dtType || ''
this . dtType = o . params . dtType || ''
@ -297,12 +408,24 @@
this . jobSpeedRecord = o . params . jobSpeedRecord || 0
this . jobSpeedRecord = o . params . jobSpeedRecord || 0
this . preStatements = o . params . preStatements || [ ]
this . preStatements = o . params . preStatements || [ ]
this . postStatements = o . params . postStatements || [ ]
this . postStatements = o . params . postStatements || [ ]
} else {
this . customConfig = 1
this . enable = true
this . json = o . params . json || [ ]
this . localParams = o . params . localParams || ''
}
}
}
} ,
} ,
mounted ( ) {
mounted ( ) {
if ( this . customConfig ) {
setTimeout ( ( ) => {
this . _handlerJsonEditor ( )
} , 200 )
} else {
setTimeout ( ( ) => {
setTimeout ( ( ) => {
this . _handlerEditor ( )
this . _handlerEditor ( )
} , 200 )
} , 200 )
}
} ,
} ,
destroyed ( ) {
destroyed ( ) {
/ * *
/ * *
@ -312,6 +435,10 @@
editor . toTextArea ( ) / / U n i n s t a l l
editor . toTextArea ( ) / / U n i n s t a l l
editor . off ( $ ( '.code-sql-mirror' ) , 'keypress' , this . keypress )
editor . off ( $ ( '.code-sql-mirror' ) , 'keypress' , this . keypress )
}
}
if ( jsonEditor ) {
jsonEditor . toTextArea ( ) / / U n i n s t a l l
jsonEditor . off ( $ ( '.code-json-mirror' ) , 'keypress' , this . keypress )
}
} ,
} ,
watch : {
watch : {
/ / W a t c h t h e c a c h e P a r a m s
/ / W a t c h t h e c a c h e P a r a m s