mirror of
				https://gitee.com/dromara/mayfly-go
				synced 2025-11-04 08:20:25 +08:00 
			
		
		
		
	feat: 数据操作按钮改为选择文本后显示
This commit is contained in:
		@@ -7,6 +7,7 @@
 | 
				
			|||||||
    "lint-fix": "eslint --fix --ext .js --ext .jsx --ext .vue src/"
 | 
					    "lint-fix": "eslint --fix --ext .js --ext .jsx --ext .vue src/"
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
  "dependencies": {
 | 
					  "dependencies": {
 | 
				
			||||||
 | 
					    "@types/lodash": "^4.14.178",
 | 
				
			||||||
    "axios": "^0.21.1",
 | 
					    "axios": "^0.21.1",
 | 
				
			||||||
    "codemirror": "^5.61.0",
 | 
					    "codemirror": "^5.61.0",
 | 
				
			||||||
    "core-js": "^3.6.5",
 | 
					    "core-js": "^3.6.5",
 | 
				
			||||||
@@ -16,6 +17,7 @@
 | 
				
			|||||||
    "echarts-wordcloud": "^2.0.0",
 | 
					    "echarts-wordcloud": "^2.0.0",
 | 
				
			||||||
    "element-plus": "^1.0.2-beta.44",
 | 
					    "element-plus": "^1.0.2-beta.44",
 | 
				
			||||||
    "jsonlint": "^1.6.3",
 | 
					    "jsonlint": "^1.6.3",
 | 
				
			||||||
 | 
					    "lodash": "^4.17.21",
 | 
				
			||||||
    "mitt": "^2.1.0",
 | 
					    "mitt": "^2.1.0",
 | 
				
			||||||
    "nprogress": "^0.2.0",
 | 
					    "nprogress": "^0.2.0",
 | 
				
			||||||
    "screenfull": "^5.1.0",
 | 
					    "screenfull": "^5.1.0",
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -25,9 +25,9 @@
 | 
				
			|||||||
            <el-aside id="sqlcontent" width="65%" style="background-color: rgb(238, 241, 246)">
 | 
					            <el-aside id="sqlcontent" width="65%" style="background-color: rgb(238, 241, 246)">
 | 
				
			||||||
                <div class="toolbar">
 | 
					                <div class="toolbar">
 | 
				
			||||||
                    <div class="fl">
 | 
					                    <div class="fl">
 | 
				
			||||||
                        <el-button v-waves @click="runSql" type="success" icon="el-icon-video-play" size="mini" plain>执行</el-button>
 | 
					                        <!-- <el-button v-waves @click="runSql" type="success" icon="el-icon-video-play" size="mini" plain>执行</el-button>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                        <el-button v-waves @click="formatSql" type="primary" icon="el-icon-magic-stick" size="mini" plain>格式化</el-button>
 | 
					                        <el-button v-waves @click="formatSql" type="primary" icon="el-icon-magic-stick" size="mini" plain>格式化</el-button> -->
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                        <el-button v-waves @click="saveSql" type="primary" icon="el-icon-document-add" size="mini" plain>保存</el-button>
 | 
					                        <el-button v-waves @click="saveSql" type="primary" icon="el-icon-document-add" size="mini" plain>保存</el-button>
 | 
				
			||||||
                    </div>
 | 
					                    </div>
 | 
				
			||||||
@@ -50,7 +50,19 @@
 | 
				
			|||||||
                        </el-upload>
 | 
					                        </el-upload>
 | 
				
			||||||
                    </div>
 | 
					                    </div>
 | 
				
			||||||
                </div>
 | 
					                </div>
 | 
				
			||||||
                <codemirror @beforeChange="onBeforeChange" class="codesql" ref="cmEditor" language="sql" v-model="sql" :options="cmOptions" />
 | 
					                <codemirror
 | 
				
			||||||
 | 
					                    @mousemove="listenMouse"
 | 
				
			||||||
 | 
					                    @beforeChange="onBeforeChange"
 | 
				
			||||||
 | 
					                    class="codesql"
 | 
				
			||||||
 | 
					                    ref="cmEditor"
 | 
				
			||||||
 | 
					                    language="sql"
 | 
				
			||||||
 | 
					                    v-model="sql"
 | 
				
			||||||
 | 
					                    :options="cmOptions"
 | 
				
			||||||
 | 
					                />
 | 
				
			||||||
 | 
					                <el-button-group :style="btnStyle">
 | 
				
			||||||
 | 
					                    <el-button v-waves @click="runSql" type="success" icon="el-icon-video-play" size="small" plain>执行</el-button>
 | 
				
			||||||
 | 
					                    <el-button v-waves @click="formatSql" type="primary" icon="el-icon-magic-stick" size="small" plain>格式化</el-button>
 | 
				
			||||||
 | 
					                </el-button-group>
 | 
				
			||||||
            </el-aside>
 | 
					            </el-aside>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            <el-container style="margin-left: 2px">
 | 
					            <el-container style="margin-left: 2px">
 | 
				
			||||||
@@ -95,6 +107,7 @@
 | 
				
			|||||||
<script lang="ts">
 | 
					<script lang="ts">
 | 
				
			||||||
import { toRefs, reactive, computed, defineComponent, ref } from 'vue';
 | 
					import { toRefs, reactive, computed, defineComponent, ref } from 'vue';
 | 
				
			||||||
import { dbApi } from './api';
 | 
					import { dbApi } from './api';
 | 
				
			||||||
 | 
					import _ from 'lodash';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import 'codemirror/addon/hint/show-hint.css';
 | 
					import 'codemirror/addon/hint/show-hint.css';
 | 
				
			||||||
// import base style
 | 
					// import base style
 | 
				
			||||||
@@ -149,6 +162,13 @@ export default defineComponent({
 | 
				
			|||||||
                pageSize: 10,
 | 
					                pageSize: 10,
 | 
				
			||||||
                envId: null,
 | 
					                envId: null,
 | 
				
			||||||
            },
 | 
					            },
 | 
				
			||||||
 | 
					            btnStyle: {
 | 
				
			||||||
 | 
					                position: 'absolute',
 | 
				
			||||||
 | 
					                zIndex: 1000,
 | 
				
			||||||
 | 
					                display: 'none',
 | 
				
			||||||
 | 
					                left: '',
 | 
				
			||||||
 | 
					                top: '',
 | 
				
			||||||
 | 
					            },
 | 
				
			||||||
            cmOptions: {
 | 
					            cmOptions: {
 | 
				
			||||||
                tabSize: 4,
 | 
					                tabSize: 4,
 | 
				
			||||||
                mode: 'text/x-sql',
 | 
					                mode: 'text/x-sql',
 | 
				
			||||||
@@ -415,7 +435,26 @@ export default defineComponent({
 | 
				
			|||||||
            const res = await dbApi.dbs.request(state.params);
 | 
					            const res = await dbApi.dbs.request(state.params);
 | 
				
			||||||
            state.dbs = res.list;
 | 
					            state.dbs = res.list;
 | 
				
			||||||
        };
 | 
					        };
 | 
				
			||||||
 | 
					        /**
 | 
				
			||||||
 | 
					         * 获取选择文字,显示隐藏按钮,防抖
 | 
				
			||||||
 | 
					         */
 | 
				
			||||||
 | 
					        const getSelection = _.debounce((e) => {
 | 
				
			||||||
 | 
					            let temp = codemirror.value.getSelection();
 | 
				
			||||||
 | 
					            if (temp) {
 | 
				
			||||||
 | 
					                state.btnStyle.display = 'block';
 | 
				
			||||||
 | 
					                if (!state.btnStyle.left) {
 | 
				
			||||||
 | 
					                    state.btnStyle.left = e.target.getBoundingClientRect().left - 100 + 'px';
 | 
				
			||||||
 | 
					                    state.btnStyle.top = e.target.getBoundingClientRect().top - 20 + 'px';
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            } else {
 | 
				
			||||||
 | 
					                state.btnStyle.display = 'none';
 | 
				
			||||||
 | 
					                state.btnStyle.left = '';
 | 
				
			||||||
 | 
					                state.btnStyle.top = '';
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }, 100);
 | 
				
			||||||
 | 
					        const listenMouse = (e: any) => {
 | 
				
			||||||
 | 
					            getSelection(e);
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
        return {
 | 
					        return {
 | 
				
			||||||
            ...toRefs(state),
 | 
					            ...toRefs(state),
 | 
				
			||||||
            cmEditor,
 | 
					            cmEditor,
 | 
				
			||||||
@@ -432,6 +471,7 @@ export default defineComponent({
 | 
				
			|||||||
            clearDb,
 | 
					            clearDb,
 | 
				
			||||||
            formatSql,
 | 
					            formatSql,
 | 
				
			||||||
            onBeforeChange,
 | 
					            onBeforeChange,
 | 
				
			||||||
 | 
					            listenMouse,
 | 
				
			||||||
        };
 | 
					        };
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
});
 | 
					});
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -107,6 +107,11 @@
 | 
				
			|||||||
  resolved "https://registry.npmmirror.com/@types/json-schema/download/@types/json-schema-7.0.9.tgz?cache=0&sync_timestamp=1637266073261&other_urls=https%3A%2F%2Fregistry.npmmirror.com%2F%40types%2Fjson-schema%2Fdownload%2F%40types%2Fjson-schema-7.0.9.tgz#97edc9037ea0c38585320b28964dde3b39e4660d"
 | 
					  resolved "https://registry.npmmirror.com/@types/json-schema/download/@types/json-schema-7.0.9.tgz?cache=0&sync_timestamp=1637266073261&other_urls=https%3A%2F%2Fregistry.npmmirror.com%2F%40types%2Fjson-schema%2Fdownload%2F%40types%2Fjson-schema-7.0.9.tgz#97edc9037ea0c38585320b28964dde3b39e4660d"
 | 
				
			||||||
  integrity sha1-l+3JA36gw4WFMgsolk3eOznkZg0=
 | 
					  integrity sha1-l+3JA36gw4WFMgsolk3eOznkZg0=
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					"@types/lodash@^4.14.178":
 | 
				
			||||||
 | 
					  version "4.14.178"
 | 
				
			||||||
 | 
					  resolved "https://registry.npmmirror.com/@types/lodash/download/@types/lodash-4.14.178.tgz#341f6d2247db528d4a13ddbb374bcdc80406f4f8"
 | 
				
			||||||
 | 
					  integrity sha512-0d5Wd09ItQWH1qFbEyQ7oTQ3GZrMfth5JkbN3EvTKLXcHLRDSXeLnlvlOn0wvxVIwK5o2M8JzP/OWz7T3NRsbw==
 | 
				
			||||||
 | 
					
 | 
				
			||||||
"@types/node@^15.6.0":
 | 
					"@types/node@^15.6.0":
 | 
				
			||||||
  version "15.14.9"
 | 
					  version "15.14.9"
 | 
				
			||||||
  resolved "https://registry.npmmirror.com/@types/node/download/@types/node-15.14.9.tgz#bc43c990c3c9be7281868bbc7b8fdd6e2b57adfa"
 | 
					  resolved "https://registry.npmmirror.com/@types/node/download/@types/node-15.14.9.tgz#bc43c990c3c9be7281868bbc7b8fdd6e2b57adfa"
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user