2020-05-04 12:18:57 +08:00
< template >
2023-02-07 15:35:34 +08:00
< div class = "data-executor-vue" >
< div style = "padding: 0 10px 10px;height: 100%;box-sizing: border-box;" >
< el-card style = "margin-bottom: 10px;" >
2023-02-08 18:21:09 +08:00
< div v-show = "aceEditorShow" >
< el-alert
2023-05-24 16:44:29 +08:00
title = "筛选示例 (支持 and , or 等连接符)"
type = "info"
: description = "executorDesc"
show - icon >
2023-02-08 18:21:09 +08:00
< / el-alert >
2023-05-24 16:44:29 +08:00
< ace-editor v-model = "sqlExecutorContent" @init="sqlExecutorInit" lang="sql" theme="monokai"
width = "100%"
height = "60" : options = "sqlEditorConfig" : source = "executorSource"
style = "margin-bottom: 10px;" >
2023-02-08 18:21:09 +08:00
< / ace-editor >
< / div >
2023-02-07 15:35:34 +08:00
< div >
2023-02-08 18:21:09 +08:00
< el-button v -on :click = "doAceEditorShow" type = "primary" plain size = "small" icon = "el-icon-search" > 筛选
< / el-button >
2023-02-07 15:35:34 +08:00
< el-button v-if = "sqlExecuting" v-on:click="cancelExecutorSql" type="primary" plain size="small"
2023-05-24 16:44:29 +08:00
icon = "el-icon-video-pause" > 取消执行
2023-02-07 15:35:34 +08:00
< / el-button >
2023-02-08 18:21:09 +08:00
< el-tooltip v-show = "aceEditorShow" v-else effect="dark" content="Ctrl+R、Ctrl+Enter" placement="top" >
< el-button v -on :click = "doExecutorClick" type = "primary" plain size = "small"
2023-05-24 16:44:29 +08:00
icon = "el-icon-video-play" > 执行
2023-02-07 15:35:34 +08:00
< / el-button >
< / el-tooltip >
2023-02-08 18:21:09 +08:00
2023-02-07 15:35:34 +08:00
< el-button icon = "el-icon-refresh-left" size = "small" @click ="refreshData" > 重置 < / el -button >
< el-button @click ="downloadTableData" type = "success" size = "small" icon = "el-icon-download" plain
2023-06-09 14:13:36 +08:00
style = "margin-left: 10px;" > 导出
2023-02-07 15:35:34 +08:00
< / el-button >
< / div >
< / el-card >
< el-card >
< div v-if = "!!executeError" style="color: #f00;" > {{ executeError }} < / div >
< div v-else-if = "sqlExecuting" v-loading="sqlExecuting" style="padding: 20px 0;" > 数据加载中... < / div >
2023-05-24 16:44:29 +08:00
< div v-else-if = "executeResultList.length <= 0" v-loading="sqlExecuting" style="padding: 20px 0;" >
暂无数据
< / div >
2021-06-05 16:38:27 +08:00
< div v-else style = "position: relative;" >
2021-09-25 21:28:37 +08:00
< div style = "position: absolute;right: 0;z-index: 1;" v-show = "executeShowTable !== 'table0'" >
2023-05-24 16:44:29 +08:00
< span
v - show = "choiceResultObj[executeShowTable] && choiceResultObj[executeShowTable].length > 0" >
2023-02-07 15:35:34 +08:00
< el-button icon = "el-icon-delete" size = "small" @click ="deleteCheckLine" type = "danger" plain
2023-05-24 16:44:29 +08:00
style = "margin-right: 10px;" > 删除 < / el-button >
2021-09-25 21:28:37 +08:00
<!-- 复制选中行 -- >
< el-dropdown @command ="handleCopyCheckLineCommand" >
< el-button type = "primary" size = "small" icon = "el-icon-document-copy" >
复制选中行 < i class = "el-icon-arrow-down el-icon--right" > < / i >
< / el-button >
< el-dropdown-menu slot = "dropdown" >
< el-dropdown-item command = "insert" > SQL Inserts < / el-dropdown-item >
< el-dropdown-item command = "update" > SQL Updates < / el-dropdown-item >
< el-dropdown-item command = "json" > JSON < / el-dropdown-item >
< / el-dropdown-menu >
< / el-dropdown >
< / span >
< el-tooltip effect = "dark" content = "选择展示列" placement = "top" >
2023-02-07 15:35:34 +08:00
< el-button icon = "el-icon-setting" size = "small" style = "margin-left: 10px;"
2023-05-24 16:44:29 +08:00
@ click = "choiceShowColumnDrawerShow" > < / el-button >
2021-09-25 21:28:37 +08:00
< / el-tooltip >
2021-06-05 16:38:27 +08:00
< / div >
2021-10-04 09:30:08 +08:00
< el-tabs v-model = "executeShowTable" >
2023-02-07 15:35:34 +08:00
< el-tab-pane label = "信息" name = "table0" >
2023-05-12 15:08:48 +08:00
< pre class = "xxpre" > { { executeResultInfo } } < / pre >
2023-02-07 15:35:34 +08:00
< / el-tab-pane >
< el-tab-pane :label = "'结果'+resultItem.index" :name = "resultItem.name"
2023-05-24 16:44:29 +08:00
v - for = "(resultItem,index) in executeResultList" : key = "index"
2023-05-26 18:26:22 +08:00
v - if = "!!resultItem.index" lazy >
2023-02-07 15:35:34 +08:00
< div v-if = "!!resultItem.errMsg" style="color: #f00;" > {{ resultItem.errMsg }} < / div >
< div v-else-if = "resultItem.dataList.length <= 0"
2023-05-24 16:44:29 +08:00
style = "text-align: center; color: #aaa; padding: 20px 0;" > 暂无数据
2023-02-07 15:35:34 +08:00
< / div >
2021-06-20 00:41:28 +08:00
< template v-else >
2023-02-07 15:35:34 +08:00
< ux-grid
2023-05-24 16:44:29 +08:00
v - clickoutside = "handleClickOutside"
stripe
border
: height = "height"
style = "width: 100%; margin-bottom: 5px;" class = "execute-result-table"
: max - height = "tableMaxHeight"
@ selection - change = "handleSelectionChange"
@ cell - click = "mouseOnFocus"
@ sort - change = "tableSortChange"
2023-06-16 18:42:21 +08:00
keep - source
ref = "plxTable"
: edit - config = "{trigger:'click',mode:'cell',activeMethod:activeMethod}"
@ edit - closed = "editClosed"
2023-05-26 18:26:22 +08:00
: checkboxConfig = "{checkMethod: selectable, highlight: true}"
2023-05-24 16:44:29 +08:00
: default - sort = "tableSort" >
2023-05-26 18:26:22 +08:00
< ux-table-column type = "checkbox" width = "50" > < / ux-table-column >
2023-02-07 15:35:34 +08:00
< ux-table-column type = "index" width = "50" title = " " > < / ux-table-column >
2023-05-24 16:44:29 +08:00
< ux-table-column v-for = "(item,index) in resultItem.dataCols" :key="index"
2023-06-16 18:42:21 +08:00
: prop = "item.prop" : title = "item.prop" : field = "item.prop"
: resizable = "true" edit - render
2023-05-24 16:44:29 +08:00
: width = "item.width" sortable >
2023-06-16 18:42:21 +08:00
< template v -slot :header = "scope" >
2021-07-17 12:22:51 +08:00
< el-tooltip effect = "dark" :content = "item.desc" placement = "top" >
2023-02-07 15:35:34 +08:00
< span > { { item . prop } } < / span >
2021-07-17 12:22:51 +08:00
< / el-tooltip >
< / template >
2023-06-16 18:42:21 +08:00
< template v-slot = "scope" >
< input title = "" v-model = "scope.row[item.prop]" class="el-textarea__inner"
2023-06-09 14:13:36 +08:00
> < / input >
2021-06-20 00:41:28 +08:00
< / template >
2023-06-16 18:42:21 +08:00
< template v -slot :edit = "scope" >
< input title = "" v-model = "scope.row[item.prop]" class="el-textarea__inner"
> < / input >
< / template >
2023-02-07 15:35:34 +08:00
< / ux-table-column >
< / ux-grid >
2021-06-20 00:41:28 +08:00
< el-pagination
2023-05-24 16:44:29 +08:00
style = "margin-top: 10px;"
@ size - change = "handlePageSizeChange"
@ current - change = "handleCurrentChange"
: current - page = "currentPage"
: page - sizes = "[50, 100, 300, 500]"
: page - size = "pageSize"
layout = "total, sizes, prev, pager, next, jumper"
: total = "tableTotalCount" >
2021-06-20 00:41:28 +08:00
< / el-pagination >
< / template >
2023-02-07 15:35:34 +08:00
< / el-tab-pane >
< / el-tabs >
< / div >
< / el-card >
< / div >
2021-06-05 16:38:27 +08:00
<!-- 选择导出为update的条件列弹窗 -- >
< el-dialog :visible.sync = "exportConditionVisible" width = "500px" title = "选择更新语句条件" >
< div >
更新条件列 :
< el-select v-model = "conditionDataColsChoice" multiple placeholder="请选择" style="width: 370px;" >
2023-02-07 15:35:34 +08:00
< el-option v-for = "item in conditionDataCols" :key="item.prop" :label="item.prop"
2023-05-24 16:44:29 +08:00
: value = "item.prop" > < / el-option >
2021-06-05 16:38:27 +08:00
< / el-select >
< / div >
< span slot = "footer" class = "dialog-footer" >
< el-button @click ="exportConditionVisible = false" > 取 消 < / el -button >
< el-button type = "primary" @click ="doCopyCheckLineUpdate" > 确 定 < / el -button >
< / span >
< / el-dialog >
<!-- 导出选择弹窗 -- >
< el-dialog :visible.sync = "downloadDataVisible" width = "600px" title = "表数据导出" >
< el-form label -width = " 120px " >
< el-form-item label = "导出类型:" >
2023-02-07 15:35:34 +08:00
< el-select v-model = "downloadDataParam.downloadType" filterable placeholder="请选择导出类型"
2023-05-24 16:44:29 +08:00
style = "width: 370px;" >
2021-06-05 16:38:27 +08:00
< el-option label = "SQL Inserts" value = "insert" > < / el-option >
< el-option label = "SQL Updates" value = "update" > < / el-option >
< el-option label = "JSON" value = "json" > < / el-option >
2021-08-15 13:40:59 +08:00
< el-option label = "Excel" value = "excel" > < / el-option >
2021-06-05 16:38:27 +08:00
< / el-select >
< / el-form-item >
< el-form-item label = "数据表:" v-if = "downloadDataParam.downloadType === 'insert'" >
2023-02-07 15:35:34 +08:00
< el-checkbox :true-label = "1" :false-label = "0" v-model = "downloadDataParam.dropTableFlag"
2023-05-24 16:44:29 +08:00
@ change = "dropTableFlagChange" > 删除表 { {
downloadDataParam . dropTableFlag == 1 ? '!!' : ''
} }
2023-02-07 15:35:34 +08:00
< / el-checkbox >
< el-checkbox :true-label = "1" :false-label = "0" v-model = "downloadDataParam.createTableFlag"
2023-05-24 16:44:29 +08:00
@ change = "createTableFlagChange" > 创建表
2023-02-07 15:35:34 +08:00
< / el-checkbox >
2021-06-05 16:38:27 +08:00
< / el-form-item >
< el-form-item label = "更新条件列:" v-if = "downloadDataParam.downloadType === 'update'" >
2023-05-24 16:44:29 +08:00
< el-select v-model = "downloadDataParam.conditionColumnArr" multiple
placeholder = "不选则是没有条件的更新"
style = "width: 370px;" >
2023-02-07 15:35:34 +08:00
< el-option v-for = "item in conditionDataCols" :key="item.prop" :label="item.prop"
2023-05-24 16:44:29 +08:00
: value = "item.prop" > < / el-option >
2021-06-05 16:38:27 +08:00
< / el-select >
< / el-form-item >
< / el-form >
< span slot = "footer" class = "dialog-footer" >
2021-07-11 18:57:35 +08:00
< el-button @click ="downloadDataVisible = false" > 取 消 < / el -button >
2021-06-05 16:38:27 +08:00
< el-button type = "primary" @click ="doDownloadTableData" > 确 定 < / el -button >
< / span >
< / el-dialog >
2021-09-25 21:28:37 +08:00
< el-drawer
2023-05-24 16:44:29 +08:00
size = "350px"
: with - header = "false"
: visible . sync = "choiceShowColumnDrawer"
: before - close = "choiceShowColumnDrawerClose"
direction = "rtl" >
2021-09-25 21:28:37 +08:00
< div style = "padding: 10px;" >
< el-row >
< el-col :span = "12" > 选择展示列 < / el-col >
< el-col :span = "12" style = "text-align: right;" >
2023-05-24 16:44:29 +08:00
< el-checkbox v-model = "choiceShowColumnAll" @change="choiceShowColumnAllChange" > 全选
< / el-checkbox >
2023-02-07 15:35:34 +08:00
< el-button type = "primary" size = "mini" @click ="choiceShowColumnOk" style = "margin-left: 10px;" > 确定
< / el-button >
2021-09-25 21:28:37 +08:00
< / el-col >
< / el-row >
< / div >
2021-09-26 22:02:40 +08:00
< div style = "overflow: auto; height: calc(100vh - 50px);" >
2023-02-07 15:35:34 +08:00
< el-tree ref = "showColumnTree" node -key = " name " :props = "showColumnProps" :data = "tableDataColumns"
2023-05-24 16:44:29 +08:00
check - on - click - node show - checkbox
@ check - change = "tableDataColumnsCheckChange" >
2021-09-25 21:28:37 +08:00
< / el-tree >
< / div >
< / el-drawer >
2021-06-05 16:38:27 +08:00
< form method = "post" ref = "downloadForm" :action = "downloadFormParam.url" target = "_blank" >
< input type = "hidden" :name = "key" :value = "val" v-for = "(val,key) in downloadFormParam.param" >
< / form >
2023-02-07 15:35:34 +08:00
< span id = "widthCalculate" style = "visibility: hidden; white-space: nowrap;position: fixed;" > < / span >
< / div >
2020-05-04 12:18:57 +08:00
< / template >
< script >
2023-02-07 15:35:34 +08:00
import datasourceApi from '../../common/api/datasource'
import copyFormatter from './copy/index'
import sqlFormatter from "sql-formatter" ;
import aceEditor from "../../common/lib/ace-editor" ;
import storageUtil from "../../common/lib/zyplayer/storageUtil" ;
2023-05-17 23:48:26 +08:00
import Clickoutside from 'element-ui/src/utils/clickoutside'
2020-05-12 22:29:29 +08:00
2023-02-07 15:35:34 +08:00
export default {
name : 'dataPreview' ,
2023-05-24 16:44:29 +08:00
directives : { Clickoutside } ,
2023-02-07 15:35:34 +08:00
data ( ) {
return {
2023-02-08 18:21:09 +08:00
executorDesc : "" ,
aceEditorShow : false ,
2023-02-07 15:35:34 +08:00
height : 0 ,
sqlExecuting : false ,
executeResultList : [ ] ,
executeResultInfo : "" ,
executeShowTable : "table1" ,
sqlExecutorEditor : { } ,
nowExecutorId : 1 ,
executeError : "" ,
pageParam : { } ,
vueQueryParam : { } ,
pageSize : 50 ,
currentPage : 1 ,
tableTotalCount : 0 ,
tableSort : { } ,
tableMaxHeight : 600 ,
tableStatusInfo : { } ,
// 选择复制
choiceResultObj : { } ,
exportConditionVisible : false ,
tableDataColumns : [ ] ,
conditionDataCols : [ ] ,
conditionDataColsChoice : [ ] ,
// 导出
downloadDataVisible : false ,
downloadDataParam : {
downloadType : 'insert' ,
dropTableFlag : 0 ,
createTableFlag : 0 ,
conditionColumnArr : [ ] ,
retainColumnArr : [ ] ,
} ,
downloadFormParam : {
url : 'zyplayer-doc-db/data-view/downloadMultiple' ,
param : { }
} ,
// 选择展示列
choiceShowColumnDrawer : false ,
showColumnProps : { label : 'name' } ,
choiceShowColumnLast : [ ] ,
choiceShowColumnAll : true ,
// 编辑器
sqlExecutorContent : '' ,
sqlEditorConfig : {
wrap : true ,
autoScrollEditorIntoView : true ,
enableBasicAutocompletion : true ,
enableSnippets : true ,
enableLiveAutocompletion : true ,
minLines : 3 ,
maxLines : 3 ,
} ,
executorSource : { } ,
columnMap : { } ,
primaryKeyColumn : { } ,
storageKey : {
key : 'zyplayer-doc-table-show-columns' , subKey : ''
} ,
}
} ,
components : {
'ace-editor' : aceEditor
} ,
mounted : function ( ) {
2023-06-09 14:13:36 +08:00
this . height = document . body . clientHeight - 330 ;
2023-02-07 15:35:34 +08:00
let resizeWindow = ( ) => {
this . tableMaxHeight = document . body . clientHeight - 420 ;
} ;
resizeWindow ( ) ;
window . onresize = resizeWindow ;
} ,
methods : {
init ( param , columnList ) {
if ( this . pageParam . sourceId == param . sourceId ) {
return ;
}
this . pageParam = param ;
this . executorSource = { sourceId : param . sourceId , dbName : param . dbName , tableName : param . tableName } ;
this . columnMap = { } ;
columnList . forEach ( item => {
this . columnMap [ item . name ] = item ;
if ( item . primaryKey == 1 ) {
this . primaryKeyColumn = item ;
}
} ) ;
this . tableDataColumns = columnList ;
2023-02-08 18:21:09 +08:00
this . executorDesc = columnList [ 0 ] . name + " = ?" ;
2023-02-07 15:35:34 +08:00
// 设置选择展示的列
this . storageKey . subKey = param . sourceId + '-' + param . dbName + '-' + param . tableName ;
let storageShowColumns = storageUtil . set . get ( this . storageKey . key , this . storageKey . subKey ) ;
this . choiceShowColumnLast = columnList . map ( val => val . name ) ;
if ( storageShowColumns ) {
let showColumns = storageShowColumns . split ( ',' ) ;
showColumns = showColumns . filter ( item => this . choiceShowColumnLast . indexOf ( item ) >= 0 ) ;
if ( showColumns . length > 0 ) {
this . choiceShowColumnLast = showColumns ;
}
}
this . doExecutorSqlCommon ( ) ;
// this.vueQueryParam = to.query;
// let newName = {key: this.$route.fullPath, val: '数据-'+this.vueQueryParam.tableName};
// this.$store.commit('global/addTableName', newName);
// datasourceApi.tableStatus(this.pageParam).then(json => {
// this.tableStatusInfo = json.data || {};
// });
} ,
sqlExecutorInit ( editor ) {
this . sqlExecutorEditor = editor ;
this . sqlExecutorEditor . setFontSize ( 16 ) ;
let that = this ;
this . sqlExecutorEditor . commands . addCommand ( {
name : "execute-sql" ,
bindKey : { win : "Ctrl-R|Ctrl-Shift-R|Ctrl-Enter" , mac : "Command-R|Command-Shift-R|Command-Enter" } ,
exec : function ( editor ) {
that . doExecutorClick ( ) ;
}
} ) ;
} ,
handleCurrentChange ( to ) {
this . currentPage = to ;
this . doExecutorSqlCommon ( ) ;
} ,
handlePageSizeChange ( to ) {
this . pageSize = to ;
this . currentPage = 1 ;
this . doExecutorSqlCommon ( ) ;
2021-06-20 00:41:28 +08:00
} ,
2023-02-07 15:35:34 +08:00
tableSortChange ( sort ) {
2023-02-08 18:21:09 +08:00
if ( this . tableSort . prop === sort . column . title && this . tableSort . order === sort . order ) return ;
this . tableSort = { prop : sort . column . title , order : sort . order } ;
2023-02-07 15:35:34 +08:00
this . doExecutorSqlCommon ( ) ;
} ,
refreshData ( ) {
this . tableSort = { } ;
this . currentPage = 1 ;
this . sqlExecutorEditor . setValue ( '' , 1 ) ;
this . doExecutorSqlCommon ( ) ;
} ,
cancelExecutorSql ( ) {
datasourceApi . executeSqlCancel ( { executeId : this . nowExecutorId } ) . then ( ( ) => {
this . sqlExecuting = false ;
this . $message . success ( "取消成功" ) ;
} ) ;
} ,
doExecutorClick ( ) {
this . tableSort = { } ;
this . currentPage = 1 ;
this . doExecutorSqlCommon ( ) ;
} ,
2023-02-08 18:21:09 +08:00
doAceEditorShow ( ) {
this . aceEditorShow = ! this . aceEditorShow
2023-06-09 14:13:36 +08:00
this . aceEditorShow ? this . height = this . height - 125 : this . height = this . height + 125 ;
2023-02-08 18:21:09 +08:00
} ,
2023-02-07 15:35:34 +08:00
doExecutorSqlCommon ( ) {
if ( ! this . pageParam . sourceId ) {
this . $message . error ( "请先选择数据源" ) ;
return ;
}
if ( ! this . tableSort . prop ) {
2023-02-08 18:21:09 +08:00
this . tableSort = { prop : this . pageParam . orderColumn , order : 'asc' } ;
2023-02-07 15:35:34 +08:00
}
let conditionSql = this . sqlExecutorEditor . getSelectedText ( ) ;
conditionSql = conditionSql || this . sqlExecutorEditor . getValue ( ) ;
conditionSql = conditionSql || "" ;
this . executeError = "" ;
this . executeUseTime = "" ;
this . choiceResultObj = { } ;
this . executeResultList = [ ] ;
this . nowExecutorId = ( new Date ( ) ) . getTime ( ) + Math . ceil ( Math . random ( ) * 1000 ) ;
this . sqlExecuting = true ;
let param = {
sourceId : this . pageParam . sourceId ,
dbName : this . pageParam . dbName ,
tableName : this . pageParam . tableName ,
executeId : this . nowExecutorId ,
condition : conditionSql ,
retainColumn : this . choiceShowColumnLast . join ( ',' ) ,
pageNum : this . currentPage ,
pageSize : this . pageSize ,
orderColumn : this . tableSort . prop ,
2023-02-08 18:21:09 +08:00
orderType : this . tableSort . order ,
2023-02-07 15:35:34 +08:00
params : '' ,
2021-08-08 22:47:38 +08:00
} ;
2023-02-07 15:35:34 +08:00
datasourceApi . dataViewQuery ( param ) . then ( json => {
this . sqlExecuting = false ;
if ( json . errCode !== 200 ) {
this . executeError = json . errMsg ;
2021-06-06 22:43:16 +08:00
return ;
}
2023-02-07 15:35:34 +08:00
let resultList = json . data || [ ] ;
let executeResultList = [ ] ;
let executeResultInfo = "" , itemIndex = 1 ;
for ( let i = 0 ; i < resultList . length ; i ++ ) {
let objItem = JSON . parse ( resultList [ i ] ) ;
executeResultInfo += this . getExecuteInfoStr ( objItem ) ;
let resultItem = this . dealExecuteResult ( objItem ) ;
if ( resultItem . updateCount < 0 ) {
resultItem . index = itemIndex ;
resultItem . name = 'table' + itemIndex ;
itemIndex ++ ;
2021-10-04 09:30:08 +08:00
}
2023-02-07 15:35:34 +08:00
executeResultList . push ( resultItem ) ;
2021-10-04 09:30:08 +08:00
}
2023-02-07 15:35:34 +08:00
if ( ! ! json . total ) {
this . tableTotalCount = json . total || 0 ;
2021-06-05 16:38:27 +08:00
}
2023-02-07 15:35:34 +08:00
this . executeShowTable = ( itemIndex === 1 ) ? "table0" : "table1" ;
this . executeResultInfo = executeResultInfo ;
this . executeResultList = executeResultList ;
2023-06-16 18:42:21 +08:00
setTimeout ( ( ) => {
for ( let i = 0 ; i < executeResultList . length ; i ++ ) {
this . datas = executeResultList [ i ] . dataList ;
this . $refs . plxTable [ i ] . reloadData ( this . datas ) ;
}
} )
2023-05-26 18:26:22 +08:00
2023-02-07 15:35:34 +08:00
} ) . catch ( e => {
this . sqlExecuting = false ;
} ) ;
} ,
getExecuteInfoStr ( resultData ) {
var resultStr = resultData . sql ;
resultStr += "\n> 状态:" + ( ( ! ! resultData . errMsg ) ? "ERROR" : "OK" ) ;
if ( resultData . updateCount >= 0 ) {
resultStr += "\n> 影响行数:" + resultData . updateCount ;
}
resultStr += "\n> 耗时:" + ( resultData . useTime || 0 ) / 1000 + "s" ;
resultStr += "\n\n" ;
return resultStr ;
} ,
dealExecuteResult ( resultData ) {
var dataList = resultData . result || [ ] ;
var executeResultCols = [ ] ;
if ( dataList . length > 0 ) {
var propData = dataList [ 0 ] ;
for ( var key in propData ) {
// 动态计算宽度~自己想的一个方法, 666
document . getElementById ( "widthCalculate" ) . innerText = key ;
var width1 = document . getElementById ( "widthCalculate" ) . offsetWidth ;
document . getElementById ( "widthCalculate" ) . innerText = propData [ key ] ;
var width2 = document . getElementById ( "widthCalculate" ) . offsetWidth ;
var width = ( width1 > width2 ) ? width1 : width2 ;
width = ( width < 50 ) ? 50 : width ;
width = ( width > 200 ) ? 200 : width ;
let column = this . columnMap [ key ] || { } ;
2023-06-19 16:59:51 +08:00
if ( key === 'ZYPLAYDBROWID' ) {
2023-06-16 18:42:21 +08:00
continue ;
}
2023-02-07 15:35:34 +08:00
executeResultCols . push ( { prop : key , width : width + 50 , desc : ( column . description || key ) } ) ;
2021-05-24 22:42:01 +08:00
}
2023-02-07 15:35:34 +08:00
}
var resultObj = { } ;
resultObj . dataList = dataList ;
resultObj . dataCols = executeResultCols ;
resultObj . useTime = resultData . useTime || 0 ;
resultObj . errMsg = resultData . errMsg || "" ;
resultObj . updateCount = resultData . updateCount ;
return resultObj ;
} ,
handleSelectionChange ( val ) {
this . $set ( this . choiceResultObj , this . executeShowTable , val ) ;
} ,
2023-05-17 23:48:26 +08:00
//表格单元格鼠标焦点事件
2023-05-24 16:44:29 +08:00
mouseOnFocus ( row , column , cell , event ) {
if ( this . uxGridCell ) {
this . uxGridCell . style . border = 'none'
}
2023-06-16 18:42:21 +08:00
if ( column . type === 'index' || column . type === 'checkbox' ) {
return ;
}
2023-05-24 16:44:29 +08:00
cell . style . border = '2px solid #0078d7'
this . uxGridCell = cell ;
2023-05-17 23:48:26 +08:00
} ,
// 点击区域外
handleClickOutside ( ) {
2023-05-24 16:44:29 +08:00
if ( this . uxGridCell ) {
this . uxGridCell . style . border = 'none'
}
2023-05-17 23:48:26 +08:00
} ,
2023-06-16 18:42:21 +08:00
//根据返回值用来决定该单元格是否允许编辑
activeMethod ( row ) {
return true
} ,
//单元格编辑状态下被关闭时
editClosed ( row ) {
//判断是否发生改变
2023-06-19 16:59:51 +08:00
if ( this . $refs . plxTable [ 0 ] . isUpdateByRow ( row . row ) && row . row . ZYPLAYDBROWID ) {
this . $refs . plxTable [ 0 ] . reloadRow ( row . row , null , null )
2023-06-16 18:42:21 +08:00
let col = row . column . title ;
2023-06-19 16:59:51 +08:00
let sql = "update \"" + this . pageParam . dbName + "\".\"" + this . pageParam . tableName + "\" set \"" + col + "\" = \'" + row . row [ col ] + "\' where ROWID = \'" + row . row . ZYPLAYDBROWID + "\'" ;
2023-06-16 18:42:21 +08:00
datasourceApi . queryExecuteSql ( {
sourceId : this . pageParam . sourceId ,
dbName : this . pageParam . dbName ,
executeId : this . nowExecutorId ,
sql : sql ,
} ) . then ( response => {
2023-06-19 16:59:51 +08:00
if ( response . errCode !== 200 ) {
this . $message . error ( response . errMsg ) ;
return ;
}
2023-06-16 18:42:21 +08:00
if ( response . data [ 0 ] . errCode !== 0 ) {
2023-06-19 16:59:51 +08:00
this . $message . error ( response . data [ 0 ] . errMsg ) ;
return ;
2023-06-16 18:42:21 +08:00
}
2023-06-19 16:59:51 +08:00
this . $message . success ( "修改成功" ) ;
2023-06-16 18:42:21 +08:00
} )
}
} ,
2023-02-07 15:35:34 +08:00
doCopyCheckLineUpdate ( ) {
let choiceData = this . choiceResultObj [ this . executeShowTable ] || [ ] ;
if ( choiceData . length > 0 ) {
let dataCols = this . executeResultList . find ( item => item . name === this . executeShowTable ) . dataCols ;
let copyData = copyFormatter . format ( 'update' , this . pageParam . dbType , dataCols , choiceData , this . conditionDataColsChoice , this . pageParam . dbName , this . pageParam . tableName ) ;
this . conditionDataColsChoice = [ ] ;
this . exportConditionVisible = false ;
this . $copyText ( copyData ) . then (
2023-05-24 16:44:29 +08:00
res => this . $message . success ( "内容已复制到剪切板!" ) ,
err => this . $message . error ( "抱歉,复制失败!" )
2023-02-07 15:35:34 +08:00
) ;
}
} ,
deleteCheckLine ( ) {
let choiceData = this . choiceResultObj [ this . executeShowTable ] || [ ] ;
if ( choiceData . length > 0 ) {
let primaryKey = this . primaryKeyColumn . name ;
if ( ! primaryKey ) {
this . $message . error ( "删除失败,未找到数据表的主键列" ) ;
return ;
2021-06-05 16:38:27 +08:00
}
2023-02-07 15:35:34 +08:00
// 通过主键ID和值删除行的数据
let deleteParam = [ ] ;
choiceData . forEach ( item => {
let line = { } ;
line [ primaryKey ] = item [ primaryKey ] ;
deleteParam . push ( line ) ;
} ) ;
this . $confirm ( ` 确定要删除选中的 ${ choiceData . length } 行数据吗? ` , '提示' , {
confirmButtonText : '确定' ,
cancelButtonText : '取消' ,
type : 'warning'
} ) . then ( ( ) => {
let param = {
sourceId : this . pageParam . sourceId ,
dbName : this . pageParam . dbName ,
tableName : this . pageParam . tableName ,
lineJson : JSON . stringify ( deleteParam )
} ;
datasourceApi . deleteTableLineData ( param ) . then ( ( ) => {
this . $message . success ( "删除成功!" ) ;
this . refreshData ( ) ;
2021-08-14 12:53:36 +08:00
} ) ;
2023-02-07 15:35:34 +08:00
} ) . catch ( ( ) => {
} ) ;
}
} ,
handleCopyCheckLineCommand ( type ) {
let choiceData = this . choiceResultObj [ this . executeShowTable ] || [ ] ;
if ( choiceData . length > 0 ) {
this . conditionDataColsChoice = [ ] ;
let dataCols = this . executeResultList . find ( item => item . name === this . executeShowTable ) . dataCols ;
if ( type === 'update' ) {
if ( ! ! this . primaryKeyColumn . name ) {
this . conditionDataColsChoice = [ this . primaryKeyColumn . name ] ;
} else {
// 没有主键的时候,选择更新的条件列
this . conditionDataCols = dataCols ;
this . exportConditionVisible = true ;
return ;
2021-06-05 16:38:27 +08:00
}
2021-08-02 21:18:58 +08:00
}
2023-02-07 15:35:34 +08:00
let copyData = copyFormatter . format ( type , this . pageParam . dbType , dataCols , choiceData , this . conditionDataColsChoice , this . pageParam . dbName , this . pageParam . tableName ) ;
this . $copyText ( copyData ) . then (
2023-05-24 16:44:29 +08:00
res => this . $message . success ( "内容已复制到剪切板!" ) ,
err => this . $message . error ( "抱歉,复制失败!" )
2023-02-07 15:35:34 +08:00
) ;
}
} ,
doDownloadTableData ( ) {
let conditionSql = this . sqlExecutorEditor . getSelectedText ( ) ;
conditionSql = conditionSql || this . sqlExecutorEditor . getValue ( ) ;
conditionSql = conditionSql || "" ;
this . nowExecutorId = ( new Date ( ) ) . getTime ( ) + Math . ceil ( Math . random ( ) * 1000 ) ;
let condition = { } , conditionColumn = { } , retainColumn = { } ;
condition [ this . pageParam . tableName ] = conditionSql ;
conditionColumn [ this . pageParam . tableName ] = this . downloadDataParam . conditionColumnArr . join ( "," ) ;
retainColumn [ this . pageParam . tableName ] = this . choiceShowColumnLast . join ( "," ) ;
this . downloadFormParam . param = {
executeId : this . nowExecutorId ,
sourceId : this . pageParam . sourceId ,
dbName : this . pageParam . dbName ,
tableNames : this . pageParam . tableName ,
downloadType : this . downloadDataParam . downloadType ,
dropTableFlag : this . downloadDataParam . dropTableFlag ,
createTableFlag : this . downloadDataParam . createTableFlag ,
conditionJson : JSON . stringify ( condition ) ,
conditionColumnJson : JSON . stringify ( conditionColumn ) ,
retainColumnJson : JSON . stringify ( retainColumn ) ,
} ;
setTimeout ( ( ) => this . $refs . downloadForm . submit ( ) , 0 ) ;
this . downloadDataVisible = false ;
} ,
downloadTableData ( ) {
let dataRes = this . executeResultList . find ( item => item . name === this . executeShowTable ) ;
if ( ! dataRes || ! dataRes . dataList || dataRes . dataList . length <= 0 ) {
this . $message . warning ( "当前筛选条件下无数据,请重新筛选后再操作导出" ) ;
return ;
}
let primaryKey = this . primaryKeyColumn . name ;
if ( this . downloadDataParam . conditionColumnArr . length <= 0 && ! ! primaryKey ) {
this . downloadDataParam . conditionColumnArr = [ primaryKey ] ;
}
this . conditionDataCols = dataRes . dataCols ;
this . downloadDataVisible = true ;
2021-08-02 21:18:58 +08:00
2023-02-07 15:35:34 +08:00
} ,
dropTableFlagChange ( ) {
if ( this . downloadDataParam . dropTableFlag === 1 ) {
this . downloadDataParam . createTableFlag = 1 ;
}
} ,
createTableFlagChange ( ) {
if ( this . downloadDataParam . createTableFlag == 0 ) {
this . downloadDataParam . dropTableFlag = 0 ;
}
} ,
choiceShowColumnDrawerShow ( ) {
this . choiceShowColumnDrawer = true ;
setTimeout ( ( ) => {
this . $refs . showColumnTree . setCheckedKeys ( this . choiceShowColumnLast ) ;
this . choiceShowColumnAll = ( this . choiceShowColumnLast . length === this . tableDataColumns . length ) ;
} , 10 ) ;
} ,
choiceShowColumnDrawerClose ( ) {
this . choiceShowColumnDrawer = false ;
} ,
choiceShowColumnOk ( ) {
let checkedKeys = this . $refs . showColumnTree . getCheckedKeys ( ) ;
if ( checkedKeys . length <= 0 ) {
this . $message . warning ( "必须选择一列展示" ) ;
} else {
storageUtil . set . save ( this . storageKey . key , this . storageKey . subKey , checkedKeys . join ( ',' ) , 50 ) ;
this . choiceShowColumnLast = checkedKeys ;
2021-09-25 21:28:37 +08:00
this . choiceShowColumnDrawer = false ;
2023-02-07 15:35:34 +08:00
this . doExecutorClick ( ) ;
}
} ,
tableDataColumnsCheckChange ( ) {
let checkedKeys = this . $refs . showColumnTree . getCheckedKeys ( ) ;
this . choiceShowColumnAll = ( checkedKeys . length === this . tableDataColumns . length ) ;
} ,
choiceShowColumnAllChange ( ) {
let choiceAll = [ ] ;
if ( this . choiceShowColumnAll ) {
choiceAll = this . tableDataColumns . map ( val => val . name ) ;
}
this . $refs . showColumnTree . setCheckedKeys ( choiceAll ) ;
} ,
2023-05-26 18:26:22 +08:00
selectable ( { row } ) {
return row . id !== 2
} ,
2023-02-07 15:35:34 +08:00
}
}
2020-05-04 12:18:57 +08:00
< / script >
2023-02-09 22:27:39 +08:00
< style scoped >
2023-02-07 15:35:34 +08:00
. data - executor - vue . ace - monokai . ace _print - margin {
display : none ;
}
. data - executor - vue . el - card _ _body {
padding : 10 px ;
}
. data - executor - vue . el - table td , . el - table th {
padding : 6 px 0 ;
}
. data - executor - vue . execute - result - table . el - input _ _inner {
height : 25 px ;
line - height : 25 px ;
padding : 0 5 px ;
}
. data - executor - vue . execute - result - table . el - textarea _ _inner {
2023-05-17 23:48:26 +08:00
height : 26 px ;
min - height : 26 px ;
line - height : 26 px ;
padding : 0 ;
2023-02-07 15:35:34 +08:00
resize : none ;
2023-06-09 14:13:36 +08:00
font - size : 12 px ;
2023-02-07 15:35:34 +08:00
}
. data - executor - vue . execute - use - time {
font - size : 12 px ;
margin - right : 10 px ;
}
. data - executor - vue - out . el - tabs _ _nav - scroll {
padding - left : 20 px ;
}
. data - executor - vue - out . el - button + . el - button {
margin - left : 0 px ;
}
. data - executor - vue - out . el - table _ _body - wrapper {
height : calc ( 100 vh - 180 px ) ;
overflow - y : auto ;
}
2023-02-09 22:27:39 +08:00
/deep/ . elx - table . elx - body -- column . col -- ellipsis {
2023-05-17 23:48:26 +08:00
height : 30 px ;
2023-02-09 22:27:39 +08:00
}
/deep/ . elx - table . elx - header -- column . col -- ellipsis {
2023-05-17 23:48:26 +08:00
height : 30 px ;
2023-05-24 16:44:29 +08:00
//padding-left: 5px;
2023-02-09 22:27:39 +08:00
}
2023-05-12 15:08:48 +08:00
2023-05-24 16:44:29 +08:00
. xxpre {
overflow : auto ;
2023-05-12 15:08:48 +08:00
}
2023-05-24 16:44:29 +08:00
. el - textarea _ _inner {
border : none ;
background - color : # f0f8ff00 ;
2023-05-17 23:48:26 +08:00
}
2023-05-24 16:44:29 +08:00
2023-05-12 15:08:48 +08:00
. el - textarea _ _inner : : - webkit - scrollbar {
2023-05-24 16:44:29 +08:00
display : none ;
2023-05-12 15:08:48 +08:00
}
2020-05-04 12:18:57 +08:00
< / style >