mirror of
https://gitee.com/dromara/mayfly-go
synced 2025-11-03 16:00:25 +08:00
合并冲突
This commit is contained in:
@@ -25,7 +25,6 @@
|
|||||||
"sql-formatter": "^2.3.3",
|
"sql-formatter": "^2.3.3",
|
||||||
"vue": "^3.0.5",
|
"vue": "^3.0.5",
|
||||||
"vue-router": "^4.0.2",
|
"vue-router": "^4.0.2",
|
||||||
"vue3-json-editor": "^1.1.3",
|
|
||||||
"vuex": "^4.0.0-rc.2",
|
"vuex": "^4.0.0-rc.2",
|
||||||
"xterm": "^4.9.0",
|
"xterm": "^4.9.0",
|
||||||
"xterm-addon-fit": "^0.4.0"
|
"xterm-addon-fit": "^0.4.0"
|
||||||
|
|||||||
@@ -29,11 +29,8 @@
|
|||||||
|
|
||||||
<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>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div style="float: right" class="fl">
|
|
||||||
<el-upload
|
<el-upload
|
||||||
|
style="display: inline-block; margin-left: 10px"
|
||||||
:before-upload="beforeUpload"
|
:before-upload="beforeUpload"
|
||||||
:on-success="execSqlFileSuccess"
|
:on-success="execSqlFileSuccess"
|
||||||
:headers="{ Authorization: token }"
|
:headers="{ Authorization: token }"
|
||||||
@@ -46,9 +43,29 @@
|
|||||||
multiple
|
multiple
|
||||||
:limit="100"
|
:limit="100"
|
||||||
>
|
>
|
||||||
<el-button class="fr" v-waves type="success" icon="el-icon-video-play" size="mini" plain>sql脚本执行</el-button>
|
<el-button v-waves type="success" icon="el-icon-video-play" size="mini" plain>sql脚本执行</el-button>
|
||||||
</el-upload>
|
</el-upload>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div style="float: right" class="fl">
|
||||||
|
<el-select
|
||||||
|
v-model="sqlName"
|
||||||
|
placeholder="选择or输入SQL模板名"
|
||||||
|
@change="changeSqlTemplate"
|
||||||
|
filterable
|
||||||
|
allow-create
|
||||||
|
default-first-option
|
||||||
|
size="mini"
|
||||||
|
class="mr10"
|
||||||
|
>
|
||||||
|
<el-option v-for="item in sqlNames" :key="item" :label="item.database" :value="item">
|
||||||
|
{{ item }}
|
||||||
|
</el-option>
|
||||||
|
</el-select>
|
||||||
|
|
||||||
|
<el-button v-waves @click="saveSql" type="primary" icon="el-icon-document-add" size="mini" plain>保存</el-button>
|
||||||
|
<el-button v-waves @click="deleteSql" type="danger" icon="el-icon-delete" size="mini" plain>删除</el-button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<codemirror
|
<codemirror
|
||||||
@mousemove="listenMouse"
|
@mousemove="listenMouse"
|
||||||
@@ -123,7 +140,7 @@ import 'codemirror/addon/hint/sql-hint.js';
|
|||||||
|
|
||||||
import sqlFormatter from 'sql-formatter';
|
import sqlFormatter from 'sql-formatter';
|
||||||
import { notNull, notEmpty } from '@/common/assert';
|
import { notNull, notEmpty } from '@/common/assert';
|
||||||
import { ElMessage } from 'element-plus';
|
import { ElMessage, ElMessageBox } from 'element-plus';
|
||||||
import ProjectEnvSelect from '../component/ProjectEnvSelect.vue';
|
import ProjectEnvSelect from '../component/ProjectEnvSelect.vue';
|
||||||
import config from '@/common/config';
|
import config from '@/common/config';
|
||||||
import { getSession } from '@/common/utils/storage';
|
import { getSession } from '@/common/utils/storage';
|
||||||
@@ -146,6 +163,8 @@ export default defineComponent({
|
|||||||
tableName: '',
|
tableName: '',
|
||||||
tableMetadata: [],
|
tableMetadata: [],
|
||||||
columnMetadata: [],
|
columnMetadata: [],
|
||||||
|
sqlName: '',
|
||||||
|
sqlNames: [],
|
||||||
sql: '',
|
sql: '',
|
||||||
sqlTabs: {
|
sqlTabs: {
|
||||||
tabs: [] as any,
|
tabs: [] as any,
|
||||||
@@ -322,9 +341,9 @@ export default defineComponent({
|
|||||||
// 设置最小宽度
|
// 设置最小宽度
|
||||||
flexWidth = 80;
|
flexWidth = 80;
|
||||||
}
|
}
|
||||||
if (flexWidth > 350) {
|
if (flexWidth > 500) {
|
||||||
// 设置最大宽度
|
// 设置最大宽度
|
||||||
flexWidth = 350;
|
flexWidth = 500;
|
||||||
}
|
}
|
||||||
return flexWidth + 'px';
|
return flexWidth + 'px';
|
||||||
};
|
};
|
||||||
@@ -341,13 +360,6 @@ export default defineComponent({
|
|||||||
return selectSql;
|
return selectSql;
|
||||||
};
|
};
|
||||||
|
|
||||||
const saveSql = async () => {
|
|
||||||
notEmpty(state.sql, 'sql内容不能为空');
|
|
||||||
notNull(state.dbId, '请先选择数据库');
|
|
||||||
await dbApi.saveSql.request({ id: state.dbId, sql: state.sql, type: 1 });
|
|
||||||
ElMessage.success('保存成功');
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 更改数据库事件
|
* 更改数据库事件
|
||||||
*/
|
*/
|
||||||
@@ -373,13 +385,72 @@ export default defineComponent({
|
|||||||
state.cmOptions.hintOptions.tables = res;
|
state.cmOptions.hintOptions.tables = res;
|
||||||
});
|
});
|
||||||
|
|
||||||
dbApi.getSql.request({ id, type: 1 }).then((res) => {
|
getSqlNames();
|
||||||
|
};
|
||||||
|
|
||||||
|
const changeSqlTemplate = () => {
|
||||||
|
getUserSql();
|
||||||
|
};
|
||||||
|
|
||||||
|
const getUserSql = () => {
|
||||||
|
notNull(state.dbId, '请先选择数据库');
|
||||||
|
dbApi.getSql.request({ id: state.dbId, type: 1, name: state.sqlName }).then((res) => {
|
||||||
if (res) {
|
if (res) {
|
||||||
state.sql = res.sql;
|
state.sql = res.sql;
|
||||||
|
} else {
|
||||||
|
state.sql = '';
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const getSqlNames = () => {
|
||||||
|
dbApi.getSqlNames
|
||||||
|
.request({
|
||||||
|
id: state.dbId,
|
||||||
|
})
|
||||||
|
.then((res) => {
|
||||||
|
if (res && res.length > 0) {
|
||||||
|
state.sqlNames = res.map((r: any) => r.name);
|
||||||
|
state.sqlName = state.sqlNames[0];
|
||||||
|
} else {
|
||||||
|
state.sqlNames = ['default'] as any;
|
||||||
|
state.sqlName = 'default';
|
||||||
|
}
|
||||||
|
|
||||||
|
getUserSql();
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const saveSql = async () => {
|
||||||
|
notEmpty(state.sql, 'sql内容不能为空');
|
||||||
|
notNull(state.dbId, '请先选择数据库');
|
||||||
|
await dbApi.saveSql.request({ id: state.dbId, sql: state.sql, type: 1, name: state.sqlName });
|
||||||
|
ElMessage.success('保存成功');
|
||||||
|
|
||||||
|
dbApi.getSqlNames
|
||||||
|
.request({
|
||||||
|
id: state.dbId,
|
||||||
|
})
|
||||||
|
.then((res) => {
|
||||||
|
if (res) {
|
||||||
|
state.sqlNames = res.map((r: any) => r.name);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const deleteSql = async () => {
|
||||||
|
try {
|
||||||
|
await ElMessageBox.confirm(`确定删除【${state.sqlName}】该SQL模板?`, '提示', {
|
||||||
|
confirmButtonText: '确定',
|
||||||
|
cancelButtonText: '取消',
|
||||||
|
type: 'warning',
|
||||||
|
});
|
||||||
|
await dbApi.deleteDbSql.request({ id: state.dbId, name: state.sqlName });
|
||||||
|
ElMessage.success('删除成功');
|
||||||
|
getSqlNames();
|
||||||
|
} catch (err) {}
|
||||||
|
};
|
||||||
|
|
||||||
// 清空数据库事件
|
// 清空数据库事件
|
||||||
const clearDb = () => {
|
const clearDb = () => {
|
||||||
state.tableName = '';
|
state.tableName = '';
|
||||||
@@ -466,6 +537,8 @@ export default defineComponent({
|
|||||||
getUploadSqlFileUrl,
|
getUploadSqlFileUrl,
|
||||||
execSqlFileSuccess,
|
execSqlFileSuccess,
|
||||||
flexColumnWidth,
|
flexColumnWidth,
|
||||||
|
changeSqlTemplate,
|
||||||
|
deleteSql,
|
||||||
saveSql,
|
saveSql,
|
||||||
changeDb,
|
changeDb,
|
||||||
clearDb,
|
clearDb,
|
||||||
|
|||||||
@@ -17,14 +17,7 @@ export const dbApi = {
|
|||||||
saveSql: Api.create("/dbs/{id}/sql", 'post'),
|
saveSql: Api.create("/dbs/{id}/sql", 'post'),
|
||||||
// 获取保存的sql
|
// 获取保存的sql
|
||||||
getSql: Api.create("/dbs/{id}/sql", 'get'),
|
getSql: Api.create("/dbs/{id}/sql", 'get'),
|
||||||
lsFile: Api.create("/devops/machines/files/{fileId}/ls", 'get'),
|
// 获取保存的sql names
|
||||||
rmFile: Api.create("/devops/machines/files/{fileId}/rm", 'delete'),
|
getSqlNames: Api.create("/dbs/{id}/sql-names", 'get'),
|
||||||
uploadFile: Api.create("/devops/machines/files/upload", 'post'),
|
deleteDbSql: Api.create("/dbs/{id}/sql", 'delete'),
|
||||||
fileContent: Api.create("/devops/machines/files/{fileId}/cat", 'get'),
|
|
||||||
// 修改文件内容
|
|
||||||
updateFileContent: Api.create("/devops/machines/files/{id}", 'put'),
|
|
||||||
// 添加文件or目录
|
|
||||||
addConf: Api.create("/devops/machines/{machineId}/files", 'post'),
|
|
||||||
// 删除配置的文件or目录
|
|
||||||
delConf: Api.create("/devops/machines/files/{id}", 'delete'),
|
|
||||||
}
|
}
|
||||||
@@ -107,11 +107,14 @@
|
|||||||
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=
|
||||||
|
|
||||||
|
<<<<<<< HEAD
|
||||||
"@types/lodash@^4.14.178":
|
"@types/lodash@^4.14.178":
|
||||||
version "4.14.178"
|
version "4.14.178"
|
||||||
resolved "https://registry.npmmirror.com/@types/lodash/download/@types/lodash-4.14.178.tgz#341f6d2247db528d4a13ddbb374bcdc80406f4f8"
|
resolved "https://registry.npmmirror.com/@types/lodash/download/@types/lodash-4.14.178.tgz#341f6d2247db528d4a13ddbb374bcdc80406f4f8"
|
||||||
integrity sha512-0d5Wd09ItQWH1qFbEyQ7oTQ3GZrMfth5JkbN3EvTKLXcHLRDSXeLnlvlOn0wvxVIwK5o2M8JzP/OWz7T3NRsbw==
|
integrity sha512-0d5Wd09ItQWH1qFbEyQ7oTQ3GZrMfth5JkbN3EvTKLXcHLRDSXeLnlvlOn0wvxVIwK5o2M8JzP/OWz7T3NRsbw==
|
||||||
|
|
||||||
|
=======
|
||||||
|
>>>>>>> master
|
||||||
"@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"
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ func (d *Db) Save(rc *ctx.ReqCtx) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (d *Db) DeleteDb(rc *ctx.ReqCtx) {
|
func (d *Db) DeleteDb(rc *ctx.ReqCtx) {
|
||||||
d.DbApp.Delete(uint64(ginx.PathParamInt(rc.GinCtx, "id")))
|
d.DbApp.Delete(GetDbId(rc.GinCtx))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Db) TableInfos(rc *ctx.ReqCtx) {
|
func (d *Db) TableInfos(rc *ctx.ReqCtx) {
|
||||||
@@ -202,7 +202,7 @@ func (d *Db) SaveSql(rc *ctx.ReqCtx) {
|
|||||||
biz.ErrIsNil(err, "该数据库信息不存在")
|
biz.ErrIsNil(err, "该数据库信息不存在")
|
||||||
|
|
||||||
// 获取用于是否有该dbsql的保存记录,有则更改,否则新增
|
// 获取用于是否有该dbsql的保存记录,有则更改,否则新增
|
||||||
dbSql := &entity.DbSql{Type: dbSqlForm.Type, DbId: dbId}
|
dbSql := &entity.DbSql{Type: dbSqlForm.Type, DbId: dbId, Name: dbSqlForm.Name}
|
||||||
dbSql.CreatorId = account.Id
|
dbSql.CreatorId = account.Id
|
||||||
e := model.GetBy(dbSql)
|
e := model.GetBy(dbSql)
|
||||||
|
|
||||||
@@ -216,11 +216,34 @@ func (d *Db) SaveSql(rc *ctx.ReqCtx) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// @router /api/db/:dbId/sql [get]
|
// 获取所有保存的sql names
|
||||||
func (d *Db) GetSql(rc *ctx.ReqCtx) {
|
func (d *Db) GetSqlNames(rc *ctx.ReqCtx) {
|
||||||
// 获取用于是否有该dbsql的保存记录,有则更改,否则新增
|
// 获取用于是否有该dbsql的保存记录,有则更改,否则新增
|
||||||
dbSql := &entity.DbSql{Type: 1, DbId: GetDbId(rc.GinCtx)}
|
dbSql := &entity.DbSql{Type: 1, DbId: GetDbId(rc.GinCtx)}
|
||||||
dbSql.CreatorId = rc.LoginAccount.Id
|
dbSql.CreatorId = rc.LoginAccount.Id
|
||||||
|
var sqls []entity.DbSql
|
||||||
|
model.ListBy(dbSql, &sqls, "id", "name")
|
||||||
|
|
||||||
|
rc.ResData = sqls
|
||||||
|
}
|
||||||
|
|
||||||
|
// 删除保存的sql
|
||||||
|
func (d *Db) DeleteSql(rc *ctx.ReqCtx) {
|
||||||
|
dbSql := &entity.DbSql{Type: 1, DbId: GetDbId(rc.GinCtx)}
|
||||||
|
dbSql.CreatorId = rc.LoginAccount.Id
|
||||||
|
dbSql.Name = rc.GinCtx.Query("name")
|
||||||
|
|
||||||
|
model.DeleteByCondition(dbSql)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// @router /api/db/:dbId/sql [get]
|
||||||
|
func (d *Db) GetSql(rc *ctx.ReqCtx) {
|
||||||
|
// 根据创建者id, 数据库id,以及sql模板名称查询保存的sql信息
|
||||||
|
dbSql := &entity.DbSql{Type: 1, DbId: GetDbId(rc.GinCtx)}
|
||||||
|
dbSql.CreatorId = rc.LoginAccount.Id
|
||||||
|
dbSql.Name = rc.GinCtx.Query("name")
|
||||||
|
|
||||||
e := model.GetBy(dbSql)
|
e := model.GetBy(dbSql)
|
||||||
if e != nil {
|
if e != nil {
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ type MachineScriptForm struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type DbSqlSaveForm struct {
|
type DbSqlSaveForm struct {
|
||||||
|
Name string
|
||||||
Sql string `binding:"required"`
|
Sql string `binding:"required"`
|
||||||
Type int `binding:"required"`
|
Type int `binding:"required"`
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,8 @@ import (
|
|||||||
type DbSql struct {
|
type DbSql struct {
|
||||||
model.Model `orm:"-"`
|
model.Model `orm:"-"`
|
||||||
|
|
||||||
DbId uint64 `json:"db_id"`
|
DbId uint64 `json:"dbId"`
|
||||||
Type int `json:"type"` // 类型
|
Type int `json:"type"` // 类型
|
||||||
Sql string `json:"sql"`
|
Sql string `json:"sql"`
|
||||||
|
Name string `json:"name"`
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ func InitDbRouter(router *gin.RouterGroup) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
deleteDb := ctx.NewLogInfo("删除数据库信息")
|
deleteDb := ctx.NewLogInfo("删除数据库信息")
|
||||||
db.DELETE(":id", func(c *gin.Context) {
|
db.DELETE(":dbId", func(c *gin.Context) {
|
||||||
ctx.NewReqCtxWithGin(c).
|
ctx.NewReqCtxWithGin(c).
|
||||||
WithLog(deleteDb).
|
WithLog(deleteDb).
|
||||||
Handle(d.DeleteDb)
|
Handle(d.DeleteDb)
|
||||||
@@ -65,10 +65,13 @@ func InitDbRouter(router *gin.RouterGroup) {
|
|||||||
db.GET(":dbId/c-metadata", func(c *gin.Context) {
|
db.GET(":dbId/c-metadata", func(c *gin.Context) {
|
||||||
ctx.NewReqCtxWithGin(c).Handle(d.ColumnMA)
|
ctx.NewReqCtxWithGin(c).Handle(d.ColumnMA)
|
||||||
})
|
})
|
||||||
|
|
||||||
db.GET(":dbId/hint-tables", func(c *gin.Context) {
|
db.GET(":dbId/hint-tables", func(c *gin.Context) {
|
||||||
ctx.NewReqCtxWithGin(c).Handle(d.HintTables)
|
ctx.NewReqCtxWithGin(c).Handle(d.HintTables)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
/** db sql相关接口 */
|
||||||
|
|
||||||
db.POST(":dbId/sql", func(c *gin.Context) {
|
db.POST(":dbId/sql", func(c *gin.Context) {
|
||||||
rc := ctx.NewReqCtxWithGin(c)
|
rc := ctx.NewReqCtxWithGin(c)
|
||||||
rc.Handle(d.SaveSql)
|
rc.Handle(d.SaveSql)
|
||||||
@@ -77,5 +80,13 @@ func InitDbRouter(router *gin.RouterGroup) {
|
|||||||
db.GET(":dbId/sql", func(c *gin.Context) {
|
db.GET(":dbId/sql", func(c *gin.Context) {
|
||||||
ctx.NewReqCtxWithGin(c).Handle(d.GetSql)
|
ctx.NewReqCtxWithGin(c).Handle(d.GetSql)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
db.DELETE(":dbId/sql", func(c *gin.Context) {
|
||||||
|
ctx.NewReqCtxWithGin(c).Handle(d.DeleteSql)
|
||||||
|
})
|
||||||
|
|
||||||
|
db.GET(":dbId/sql-names", func(c *gin.Context) {
|
||||||
|
ctx.NewReqCtxWithGin(c).Handle(d.GetSqlNames)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -58,6 +58,7 @@ DROP TABLE IF EXISTS `t_db_sql`;
|
|||||||
CREATE TABLE `t_db_sql` (
|
CREATE TABLE `t_db_sql` (
|
||||||
`id` bigint(20) NOT NULL AUTO_INCREMENT,
|
`id` bigint(20) NOT NULL AUTO_INCREMENT,
|
||||||
`db_id` bigint(20) NOT NULL COMMENT '数据库id',
|
`db_id` bigint(20) NOT NULL COMMENT '数据库id',
|
||||||
|
`name` varchar(60) COLLATE utf8mb4_bin DEFAULT NULL COMMENT 'sql模板名',
|
||||||
`sql` text COLLATE utf8mb4_bin,
|
`sql` text COLLATE utf8mb4_bin,
|
||||||
`type` tinyint(8) NOT NULL,
|
`type` tinyint(8) NOT NULL,
|
||||||
`creator_id` bigint(20) NOT NULL,
|
`creator_id` bigint(20) NOT NULL,
|
||||||
|
|||||||
Reference in New Issue
Block a user