mirror of
https://gitee.com/dromara/mayfly-go
synced 2025-11-02 15:30:25 +08:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b88923a128 | ||
|
|
fe8cd93c78 | ||
|
|
64b49dae2e | ||
|
|
edbbbca5f9 |
@@ -7,25 +7,25 @@
|
||||
"lint-fix": "eslint --fix --ext .js --ext .jsx --ext .vue src/"
|
||||
},
|
||||
"dependencies": {
|
||||
"@element-plus/icons-vue": "^2.0.4",
|
||||
"@element-plus/icons-vue": "^2.0.6",
|
||||
"axios": "^0.27.2",
|
||||
"codemirror": "^5.65.5",
|
||||
"countup.js": "^2.0.7",
|
||||
"cropperjs": "^1.5.11",
|
||||
"echarts": "^5.3.2",
|
||||
"element-plus": "^2.2.4",
|
||||
"jsoneditor": "^9.8.0",
|
||||
"echarts": "^5.3.3",
|
||||
"element-plus": "^2.2.8",
|
||||
"jsoneditor": "^9.9.0",
|
||||
"lodash": "^4.17.21",
|
||||
"mitt": "^3.0.0",
|
||||
"nprogress": "^0.2.0",
|
||||
"screenfull": "^5.1.0",
|
||||
"sortablejs": "^1.13.0",
|
||||
"sql-formatter": "^6.1.2",
|
||||
"sql-formatter": "^7.0.3",
|
||||
"vue": "^3.2.37",
|
||||
"vue-clipboard3": "^1.0.1",
|
||||
"vue-router": "^4.0.15",
|
||||
"vue-router": "^4.0.16",
|
||||
"vuex": "^4.0.2",
|
||||
"xterm": "^4.18.0",
|
||||
"xterm": "^4.19.0",
|
||||
"xterm-addon-fit": "^0.5.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
@@ -43,8 +43,8 @@
|
||||
"prettier": "^2.3.0",
|
||||
"sass": "^1.45.1",
|
||||
"sass-loader": "^12.4.0",
|
||||
"typescript": "^4.2.4",
|
||||
"vite": "^2.9.10",
|
||||
"typescript": "^4.7.4",
|
||||
"vite": "^2.9.13",
|
||||
"vue-eslint-parser": "^8.0.1"
|
||||
},
|
||||
"browserslist": [
|
||||
|
||||
@@ -239,16 +239,6 @@
|
||||
color: set-color(primary);
|
||||
}
|
||||
|
||||
/* Switch 开关
|
||||
------------------------------- */
|
||||
.el-switch.is-checked .el-switch__core {
|
||||
border-color: set-color(primary);
|
||||
background-color: set-color(primary);
|
||||
}
|
||||
.el-switch__label.is-active {
|
||||
color: set-color(primary);
|
||||
}
|
||||
|
||||
/* Slider 滑块
|
||||
------------------------------- */
|
||||
.el-slider__bar {
|
||||
|
||||
@@ -30,7 +30,7 @@ import { useStore } from '@/store/index.ts';
|
||||
export default defineComponent({
|
||||
name: 'layoutBreadcrumbSearch',
|
||||
setup() {
|
||||
const layoutMenuAutocompleteRef = ref();
|
||||
const layoutMenuAutocompleteRef: any = ref(null);
|
||||
const store = useStore();
|
||||
const router = useRouter();
|
||||
const state: any = reactive({
|
||||
@@ -68,7 +68,6 @@ export default defineComponent({
|
||||
// 初始化菜单数据
|
||||
const initTageView = () => {
|
||||
if (state.tagsViewList.length > 0) return false;
|
||||
console.log(getRoutes(store.state.routesList.routesList));
|
||||
getRoutes(store.state.routesList.routesList).map((v: any) => {
|
||||
if (!v.meta.isHide) {
|
||||
state.tagsViewList.push({ ...v });
|
||||
|
||||
@@ -72,9 +72,35 @@
|
||||
|
||||
<el-dialog width="75%" :title="`${db} 表信息`" :before-close="closeTableInfo" v-model="tableInfoDialog.visible">
|
||||
<el-row class="mb10">
|
||||
<el-popover v-model:visible="showDumpInfo" :width="470" placement="right">
|
||||
<template #reference>
|
||||
<el-button class="ml5" type="success" size="small" @click="showDumpInfo = !showDumpInfo">导出</el-button>
|
||||
</template>
|
||||
<el-form-item label="导出内容: ">
|
||||
<el-radio-group v-model="dumpInfo.type">
|
||||
<el-radio :label="1" size="small">结构</el-radio>
|
||||
<el-radio :label="2" size="small">数据</el-radio>
|
||||
<el-radio :label="3" size="small">结构+数据</el-radio>
|
||||
</el-radio-group>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="导出表: ">
|
||||
<el-table @selection-change="handleDumpTableSelectionChange" max-height="300" size="small" :data="tableInfoDialog.infos">
|
||||
<el-table-column type="selection" width="45" />
|
||||
<el-table-column property="tableName" label="表名" min-width="150" show-overflow-tooltip> </el-table-column>
|
||||
<el-table-column property="tableComment" label="备注" min-width="150" show-overflow-tooltip></el-table-column>
|
||||
</el-table>
|
||||
</el-form-item>
|
||||
|
||||
<div style="text-align: right">
|
||||
<el-button @click="showDumpInfo = false" size="small">取消</el-button>
|
||||
<el-button @click="dump(db)" type="success" size="small">确定</el-button>
|
||||
</div>
|
||||
</el-popover>
|
||||
|
||||
<el-button type="primary" size="small" @click="tableCreateDialog.visible = true">创建表</el-button>
|
||||
</el-row>
|
||||
<el-table border stripe :data="tableInfoDialog.infos" size="small">
|
||||
<el-table v-loading="tableInfoDialog.loading" border stripe :data="tableInfoDialog.infos" size="small">
|
||||
<el-table-column property="tableName" label="表名" min-width="150" show-overflow-tooltip></el-table-column>
|
||||
<el-table-column property="tableComment" label="备注" min-width="150" show-overflow-tooltip></el-table-column>
|
||||
<el-table-column
|
||||
@@ -226,6 +252,10 @@ import { dbApi } from './api';
|
||||
import enums from './enums';
|
||||
import { projectApi } from '../project/api.ts';
|
||||
import SqlExecBox from './component/SqlExecBox.ts';
|
||||
import config from '@/common/config';
|
||||
import { getSession } from '@/common/utils/storage';
|
||||
import { isTrue } from '@/common/assert';
|
||||
|
||||
export default defineComponent({
|
||||
name: 'DbList',
|
||||
components: {
|
||||
@@ -255,6 +285,13 @@ export default defineComponent({
|
||||
},
|
||||
datas: [],
|
||||
total: 0,
|
||||
showDumpInfo: false,
|
||||
dumpInfo: {
|
||||
id: 0,
|
||||
db: '',
|
||||
type: 3,
|
||||
tables: [],
|
||||
},
|
||||
// sql执行记录弹框
|
||||
sqlExecLogDialog: {
|
||||
title: '',
|
||||
@@ -276,6 +313,7 @@ export default defineComponent({
|
||||
},
|
||||
chooseTableName: '',
|
||||
tableInfoDialog: {
|
||||
loading: false,
|
||||
visible: false,
|
||||
infos: [],
|
||||
},
|
||||
@@ -391,6 +429,29 @@ export default defineComponent({
|
||||
searchSqlExecLog();
|
||||
};
|
||||
|
||||
/**
|
||||
* 选择导出数据库表
|
||||
*/
|
||||
const handleDumpTableSelectionChange = (vals: any) => {
|
||||
state.dumpInfo.tables = vals.map((x: any) => x.tableName);
|
||||
};
|
||||
|
||||
/**
|
||||
* 数据库信息导出
|
||||
*/
|
||||
const dump = (db: string) => {
|
||||
isTrue(state.dumpInfo.tables.length > 0, '请选择要导出的表');
|
||||
const a = document.createElement('a');
|
||||
a.setAttribute(
|
||||
'href',
|
||||
`${config.baseApiUrl}/dbs/${state.dbId}/dump?db=${db}&type=${state.dumpInfo.type}&tables=${state.dumpInfo.tables.join(
|
||||
','
|
||||
)}&token=${getSession('token')}`
|
||||
);
|
||||
a.click();
|
||||
state.showDumpInfo = false;
|
||||
};
|
||||
|
||||
const onShowRollbackSql = async (sqlExecLog: any) => {
|
||||
const columns = await dbApi.columnMetadata.request({ id: sqlExecLog.dbId, db: sqlExecLog.db, tableName: sqlExecLog.table });
|
||||
const primaryKey = columns[0].columnName;
|
||||
@@ -434,13 +495,19 @@ export default defineComponent({
|
||||
};
|
||||
|
||||
const showTableInfo = async (row: any, db: string) => {
|
||||
state.tableInfoDialog.infos = await dbApi.tableInfos.request({ id: row.id, db });
|
||||
state.dbId = row.id;
|
||||
state.db = db;
|
||||
state.tableInfoDialog.loading = true;
|
||||
state.tableInfoDialog.visible = true;
|
||||
try {
|
||||
state.tableInfoDialog.infos = await dbApi.tableInfos.request({ id: row.id, db });
|
||||
state.dbId = row.id;
|
||||
state.db = db;
|
||||
} finally {
|
||||
state.tableInfoDialog.loading = false;
|
||||
}
|
||||
};
|
||||
|
||||
const closeTableInfo = () => {
|
||||
state.showDumpInfo = false;
|
||||
state.tableInfoDialog.visible = false;
|
||||
state.tableInfoDialog.infos = [];
|
||||
};
|
||||
@@ -510,6 +577,8 @@ export default defineComponent({
|
||||
valChange,
|
||||
deleteDb,
|
||||
onShowSqlExec,
|
||||
handleDumpTableSelectionChange,
|
||||
dump,
|
||||
onBeforeCloseSqlExecDialog,
|
||||
handleSqlExecPageChange,
|
||||
searchSqlExecLog,
|
||||
|
||||
@@ -190,7 +190,7 @@
|
||||
@cell-dblclick="cellClick"
|
||||
@sort-change="onTableSortChange"
|
||||
@selection-change="onDataSelectionChange"
|
||||
:data="dt.execRes.data"
|
||||
:data="dt.datas"
|
||||
size="small"
|
||||
:max-height="dataTabsTableHeight"
|
||||
v-loading="dt.loading"
|
||||
@@ -200,12 +200,12 @@
|
||||
border
|
||||
class="mt5"
|
||||
>
|
||||
<el-table-column v-if="dt.execRes.tableColumn.length > 0" type="selection" width="35" />
|
||||
<el-table-column v-if="dt.datas.length > 0" type="selection" width="35" />
|
||||
<el-table-column
|
||||
min-width="100"
|
||||
:width="flexColumnWidth(item, dt.execRes.data)"
|
||||
:width="flexColumnWidth(item, dt.datas)"
|
||||
align="center"
|
||||
v-for="item in dt.execRes.tableColumn"
|
||||
v-for="item in dt.columnNames"
|
||||
:key="item"
|
||||
:prop="item"
|
||||
:label="item"
|
||||
@@ -215,12 +215,21 @@
|
||||
<template #header>
|
||||
<el-tooltip raw-content placement="top" effect="customized">
|
||||
<template #content> {{ getColumnTip(dt.name, item) }} </template>
|
||||
<!-- <el-icon><question-filled /></el-icon> -->
|
||||
{{ item }}
|
||||
</el-tooltip>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
<el-row type="flex" class="mt5" justify="center">
|
||||
<el-pagination
|
||||
small
|
||||
:total="dt.count"
|
||||
@current-change="handlePageChange(dt)"
|
||||
layout="prev, pager, next, total, jumper"
|
||||
v-model:current-page="dt.pageNum"
|
||||
:page-size="defalutLimit"
|
||||
></el-pagination>
|
||||
</el-row>
|
||||
</el-tab-pane>
|
||||
</el-tabs>
|
||||
</el-container>
|
||||
@@ -263,7 +272,7 @@ export default defineComponent({
|
||||
|
||||
const state = reactive({
|
||||
token: token,
|
||||
defalutLimit: 25, // 默认查询数量
|
||||
defalutLimit: 20, // 默认查询数量
|
||||
dbs: [], // 数据库实例列表
|
||||
databaseList: [], // 数据库实例拥有的数据库列表,1数据库实例 -> 多数据库
|
||||
db: '', // 当前操作的数据库
|
||||
@@ -271,7 +280,6 @@ export default defineComponent({
|
||||
dbId: null, // 当前选中操作的数据库实例
|
||||
tableName: '',
|
||||
tableMetadata: [],
|
||||
columnMetadata: [],
|
||||
sqlName: '', // 当前sql模板名
|
||||
sqlNames: [], // 所有sql模板名
|
||||
activeName: 'Query',
|
||||
@@ -356,7 +364,7 @@ export default defineComponent({
|
||||
const setHeight = () => {
|
||||
// 默认300px
|
||||
codemirror.setSize('auto', `${window.innerHeight - 538}px`);
|
||||
state.dataTabsTableHeight = window.innerHeight - 258;
|
||||
state.dataTabsTableHeight = window.innerHeight - 258 - 33;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -457,33 +465,6 @@ export default defineComponent({
|
||||
sql: sql.trim(),
|
||||
remark,
|
||||
});
|
||||
// const sqlTrim = sql.trim();
|
||||
// let remark = '';
|
||||
// let canRun = true;
|
||||
// const needRemark = ['update', 'UPDATE', 'delete', 'DELETE', 'INSERT', 'insert'].indexOf(sqlTrim.split(' ')[0]);
|
||||
// if (needRemark) {
|
||||
// const res: any = await ElMessageBox.prompt('请输入备注', 'Tip', {
|
||||
// confirmButtonText: '确定',
|
||||
// cancelButtonText: '取消',
|
||||
// });
|
||||
// remark = res.value;
|
||||
// if (!remark) {
|
||||
// canRun = false;
|
||||
// }
|
||||
// }
|
||||
|
||||
// if (!canRun) {
|
||||
// return;
|
||||
// }
|
||||
// try {
|
||||
// state.queryTab.loading = true;
|
||||
// return await dbApi.sqlExec.request({
|
||||
// id: state.dbId,
|
||||
// db: state.db,
|
||||
// sql: sqlTrim,
|
||||
// remark,
|
||||
// });
|
||||
// } catch (e: any) {}
|
||||
};
|
||||
|
||||
const removeDataTab = (targetName: string) => {
|
||||
@@ -533,7 +514,7 @@ export default defineComponent({
|
||||
|
||||
// 获取sql文件上传执行url
|
||||
const getUploadSqlFileUrl = () => {
|
||||
return `${config.baseApiUrl}/dbs/${state.dbId}/exec-sql-file`;
|
||||
return `${config.baseApiUrl}/dbs/${state.dbId}/exec-sql-file?db=${state.db}`;
|
||||
};
|
||||
|
||||
const flexColumnWidth = (str: any, tableData: any, flag = 'equal') => {
|
||||
@@ -673,8 +654,6 @@ export default defineComponent({
|
||||
if (tableName == '') {
|
||||
return;
|
||||
}
|
||||
state.columnMetadata = (await getColumns(tableName)) as any;
|
||||
|
||||
if (!execSelectSql) {
|
||||
return;
|
||||
}
|
||||
@@ -691,40 +670,17 @@ export default defineComponent({
|
||||
tab = {
|
||||
label: tableName,
|
||||
name: tableName,
|
||||
execRes: {
|
||||
tableColumn: [],
|
||||
data: [],
|
||||
},
|
||||
querySql: getDefaultSelectSql(tableName),
|
||||
datas: [],
|
||||
columnNames: [],
|
||||
pageNum: 1,
|
||||
count: 0,
|
||||
};
|
||||
tab.columnNames = await getColumnNames(tableName);
|
||||
state.dataTabs[tableName] = tab;
|
||||
|
||||
state.dataTabs[tableName].execRes.tableColumn = [];
|
||||
state.dataTabs[tableName].execRes.data = [];
|
||||
|
||||
onRefresh(tableName);
|
||||
};
|
||||
|
||||
/**
|
||||
* 获取默认查询语句
|
||||
*/
|
||||
const getDefaultSelectSql = (tableName: string, where: string = '', orderBy: string = '') => {
|
||||
return `SELECT * FROM \`${tableName}\` ${where ? 'WHERE ' + where : ''} ${orderBy ? orderBy : ''} LIMIT ${state.defalutLimit}`;
|
||||
};
|
||||
|
||||
const selectByCondition = async (tableName: string, condition: string) => {
|
||||
notEmpty(condition, '条件不能为空');
|
||||
state.dataTabs[tableName].loading = true;
|
||||
try {
|
||||
const colAndData: any = await runSql(getDefaultSelectSql(tableName, condition));
|
||||
state.dataTabs[tableName].execRes.tableColumn = colAndData.colNames;
|
||||
state.dataTabs[tableName].execRes.data = colAndData.res;
|
||||
state.dataTabs[tableName].loading = false;
|
||||
} catch (err) {
|
||||
state.dataTabs[tableName].loading = false;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 获取表的所有列信息
|
||||
*/
|
||||
@@ -748,6 +704,11 @@ export default defineComponent({
|
||||
return tableMap.get(tableName);
|
||||
};
|
||||
|
||||
const getColumnNames = async (tableName: string) => {
|
||||
const columns = await getColumns(tableName);
|
||||
return columns.map((t: any) => t.columnName);
|
||||
};
|
||||
|
||||
/**
|
||||
* 条件查询,点击列信息后显示输入对应的值
|
||||
*/
|
||||
@@ -773,13 +734,70 @@ export default defineComponent({
|
||||
};
|
||||
|
||||
const onRefresh = async (tableName: string) => {
|
||||
const dataTab = state.dataTabs[tableName];
|
||||
// 查询条件置空
|
||||
state.dataTabs[tableName].condition = '';
|
||||
state.dataTabs[tableName].loading = true;
|
||||
const colAndData: any = await runSql(state.dataTabs[tableName].querySql);
|
||||
state.dataTabs[tableName].execRes.tableColumn = colAndData.colNames;
|
||||
state.dataTabs[tableName].execRes.data = colAndData.res;
|
||||
state.dataTabs[tableName].loading = false;
|
||||
dataTab.condition = '';
|
||||
dataTab.pageNum = 1;
|
||||
setDataTabDatas(dataTab);
|
||||
};
|
||||
|
||||
/**
|
||||
* 数据tab修改页数
|
||||
*/
|
||||
const handlePageChange = async (dataTab: any) => {
|
||||
setDataTabDatas(dataTab);
|
||||
};
|
||||
|
||||
/**
|
||||
* 根据条件查询数据
|
||||
*/
|
||||
const selectByCondition = async (tableName: string, condition: string) => {
|
||||
notEmpty(condition, '条件不能为空');
|
||||
const dataTab = state.dataTabs[tableName];
|
||||
dataTab.pageNum = 1;
|
||||
setDataTabDatas(dataTab);
|
||||
};
|
||||
|
||||
/**
|
||||
* 设置data tab的表数据
|
||||
*/
|
||||
const setDataTabDatas = async (dataTab: any) => {
|
||||
dataTab.loading = true;
|
||||
try {
|
||||
dataTab.count = await getTableCount(dataTab.name, dataTab.condition);
|
||||
if (dataTab.count > 0) {
|
||||
const colAndData: any = await runSql(getDefaultSelectSql(dataTab.name, dataTab.condition, dataTab.orderBy, dataTab.pageNum));
|
||||
dataTab.datas = colAndData.res;
|
||||
} else {
|
||||
dataTab.datas = [];
|
||||
}
|
||||
} finally {
|
||||
dataTab.loading = false;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 获取表的统计数量
|
||||
*/
|
||||
const getTableCount = async (tableName: string, condition: string = '') => {
|
||||
const countRes = await runSql(getDefaultCountSql(tableName, condition));
|
||||
return countRes.res[0].count;
|
||||
};
|
||||
|
||||
/**
|
||||
* 获取默认查询语句
|
||||
*/
|
||||
const getDefaultSelectSql = (tableName: string, where: string = '', orderBy: string = '', pageNum: number = 1) => {
|
||||
return `SELECT * FROM \`${tableName}\` ${where ? 'WHERE ' + where : ''} ${orderBy ? orderBy : ''} LIMIT ${
|
||||
(pageNum - 1) * state.defalutLimit
|
||||
}, ${state.defalutLimit}`;
|
||||
};
|
||||
|
||||
/**
|
||||
* 获取默认查询统计语句
|
||||
*/
|
||||
const getDefaultCountSql = (tableName: string, where: string = '') => {
|
||||
return `SELECT COUNT(*) count FROM \`${tableName}\` ${where ? 'WHERE ' + where : ''}`;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -801,7 +819,8 @@ export default defineComponent({
|
||||
const tableName = state.activeName;
|
||||
const sortType = sort.order == 'descending' ? 'DESC' : 'ASC';
|
||||
|
||||
state.dataTabs[state.activeName].querySql = getDefaultSelectSql(tableName, '', `ORDER BY \`${sort.prop}\` ${sortType}`);
|
||||
const orderBy = `ORDER BY \`${sort.prop}\` ${sortType}`;
|
||||
state.dataTabs[state.activeName].orderBy = orderBy;
|
||||
|
||||
onRefresh(tableName);
|
||||
};
|
||||
@@ -892,7 +911,6 @@ export default defineComponent({
|
||||
state.tableName = '';
|
||||
state.nowTableName = '';
|
||||
state.tableMetadata = [];
|
||||
state.columnMetadata = [];
|
||||
state.dataTabs = {};
|
||||
setCodermirrorValue('');
|
||||
state.sqlNames = [];
|
||||
@@ -927,10 +945,7 @@ export default defineComponent({
|
||||
|
||||
promptExeSql(sql, null, () => {
|
||||
if (!queryTab) {
|
||||
state.dataTabs[state.activeName].execRes.data = state.dataTabs[state.activeName].execRes.data.filter(
|
||||
(d: any) => !(deleteDatas.findIndex((x: any) => x[primaryKeyColumnName] == d[primaryKeyColumnName]) != -1)
|
||||
);
|
||||
state.dataTabs[state.activeName].selectionDatas = [];
|
||||
onRefresh(state.activeName);
|
||||
} else {
|
||||
state.queryTab.execRes.data = state.queryTab.execRes.data.filter(
|
||||
(d: any) => !(deleteDatas.findIndex((x: any) => x[primaryKeyColumnName] == d[primaryKeyColumnName]) != -1)
|
||||
@@ -955,7 +970,7 @@ export default defineComponent({
|
||||
return;
|
||||
}
|
||||
// 转为字符串比较,可能存在数字等
|
||||
let text = row[property] + '';
|
||||
let text = (row[property] ? row[property] : '') + '';
|
||||
let div = cell.children[0];
|
||||
if (div) {
|
||||
let input = document.createElement('input');
|
||||
@@ -1107,6 +1122,7 @@ export default defineComponent({
|
||||
formatSql,
|
||||
onBeforeChange,
|
||||
onRefresh,
|
||||
handlePageChange,
|
||||
selectByCondition,
|
||||
onCommit,
|
||||
addRow,
|
||||
|
||||
@@ -5,6 +5,7 @@ export const dbApi = {
|
||||
dbs: Api.create("/dbs", 'get'),
|
||||
saveDb: Api.create("/dbs", 'post'),
|
||||
deleteDb: Api.create("/dbs/{id}", 'delete'),
|
||||
dumpDb: Api.create("/dbs/{id}/dump", 'post'),
|
||||
tableInfos: Api.create("/dbs/{id}/t-infos", 'get'),
|
||||
tableIndex: Api.create("/dbs/{id}/t-index", 'get'),
|
||||
tableDdl: Api.create("/dbs/{id}/t-create-ddl", 'get'),
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<div>
|
||||
<el-dialog title="待执行SQL" v-model="dialogVisible" :show-close="false" width="600px">
|
||||
<codemirror height="350px" class="codesql" ref="cmEditor" language="sql" v-model="sqlValue" :options="cmOptions" />
|
||||
<el-input v-model="remark" placeholder="请输入执行备注" class="mt5" />
|
||||
<el-input ref="remarkInputRef" v-model="remark" placeholder="请输入执行备注" class="mt5" />
|
||||
<template #footer>
|
||||
<span class="dialog-footer">
|
||||
<el-button @click="cancel">取 消</el-button>
|
||||
@@ -14,9 +14,9 @@
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { toRefs, reactive, defineComponent } from 'vue';
|
||||
import { toRefs, ref, nextTick, reactive, defineComponent } from 'vue';
|
||||
import { dbApi } from '../api';
|
||||
import { ElDialog, ElButton, ElInput, ElMessage } from 'element-plus';
|
||||
import { ElDialog, ElButton, ElInput, ElMessage, InputInstance } from 'element-plus';
|
||||
// import base style
|
||||
import 'codemirror/lib/codemirror.css';
|
||||
// 引入主题后还需要在 options 中指定主题才会生效
|
||||
@@ -50,6 +50,7 @@ export default defineComponent({
|
||||
},
|
||||
},
|
||||
setup(props: any) {
|
||||
const remarkInputRef = ref<InputInstance>();
|
||||
const state = reactive({
|
||||
dialogVisible: false,
|
||||
sqlValue: '',
|
||||
@@ -84,16 +85,22 @@ export default defineComponent({
|
||||
ElMessage.error('请输入执行的备注信息');
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
state.btnLoading = true;
|
||||
await dbApi.sqlExec.request({
|
||||
const res = await dbApi.sqlExec.request({
|
||||
id: state.dbId,
|
||||
db: state.db,
|
||||
remark: state.remark,
|
||||
sql: state.sqlValue.trim(),
|
||||
});
|
||||
runSuccess = true;
|
||||
if (parseInt(res.res[0].影响条数) >= 1) {
|
||||
ElMessage.success('执行成功');
|
||||
runSuccess = true;
|
||||
} else {
|
||||
ElMessage.error('执行失败');
|
||||
runSuccess = false;
|
||||
}
|
||||
} catch (e) {
|
||||
runSuccess = false;
|
||||
}
|
||||
@@ -127,10 +134,14 @@ export default defineComponent({
|
||||
state.dbId = props.dbId;
|
||||
state.db = props.db;
|
||||
state.dialogVisible = true;
|
||||
nextTick(() => {
|
||||
remarkInputRef.value?.focus();
|
||||
});
|
||||
};
|
||||
|
||||
return {
|
||||
...toRefs(state),
|
||||
remarkInputRef,
|
||||
open,
|
||||
runSql,
|
||||
cancel,
|
||||
|
||||
@@ -89,15 +89,11 @@
|
||||
|
||||
<template #dropdown>
|
||||
<el-dropdown-menu>
|
||||
<el-dropdown-item v-if="data.type == '-' && data.size < 1 * 1024 * 1024">
|
||||
<el-link
|
||||
@click.prevent="getFileContent(tree.folder.id, data.path)"
|
||||
type="info"
|
||||
icon="view"
|
||||
:underline="false"
|
||||
>
|
||||
查看
|
||||
</el-link>
|
||||
<el-dropdown-item
|
||||
@click="getFileContent(tree.folder.id, data.path)"
|
||||
v-if="data.type == '-' && data.size < 1 * 1024 * 1024"
|
||||
>
|
||||
<el-link type="info" icon="view" :underline="false">查看</el-link>
|
||||
</el-dropdown-item>
|
||||
|
||||
<span v-auth="'machine:file:upload'">
|
||||
@@ -112,34 +108,20 @@
|
||||
name="file"
|
||||
style="display: inline-block; margin-left: 2px"
|
||||
>
|
||||
<el-link icon="upload" :underline="false"> 上传 </el-link>
|
||||
<el-link icon="upload" :underline="false">上传</el-link>
|
||||
</el-upload>
|
||||
</el-dropdown-item>
|
||||
</span>
|
||||
|
||||
<span v-auth="'machine:file:write'">
|
||||
<el-dropdown-item v-if="data.type == '-'">
|
||||
<el-link
|
||||
@click.prevent="downloadFile(node, data)"
|
||||
type="primary"
|
||||
icon="download"
|
||||
:underline="false"
|
||||
style="margin-left: 2px"
|
||||
>下载</el-link
|
||||
>
|
||||
<el-dropdown-item @click="downloadFile(node, data)" v-if="data.type == '-'">
|
||||
<el-link type="primary" icon="download" :underline="false" style="margin-left: 2px">下载</el-link>
|
||||
</el-dropdown-item>
|
||||
</span>
|
||||
|
||||
<span v-auth="'machine:file:rm'">
|
||||
<el-dropdown-item v-if="!dontOperate(data)">
|
||||
<el-link
|
||||
@click.prevent="deleteFile(node, data)"
|
||||
type="danger"
|
||||
icon="delete"
|
||||
:underline="false"
|
||||
style="margin-left: 2px"
|
||||
>删除
|
||||
</el-link>
|
||||
<el-dropdown-item @click="deleteFile(node, data)" v-if="!dontOperate(data)">
|
||||
<el-link type="danger" icon="delete" :underline="false" style="margin-left: 2px">删除</el-link>
|
||||
</el-dropdown-item>
|
||||
</span>
|
||||
</el-dropdown-menu>
|
||||
|
||||
@@ -57,11 +57,10 @@
|
||||
v-model="scope.row.status"
|
||||
:active-value="1"
|
||||
:inactive-value="-1"
|
||||
active-color="#13ce66"
|
||||
inactive-color="#ff4949"
|
||||
inline-prompt
|
||||
active-text="启用"
|
||||
inactive-text="停用"
|
||||
style="--el-switch-on-color: #13ce66; --el-switch-off-color: #ff4949"
|
||||
@change="changeStatus(scope.row)"
|
||||
></el-switch>
|
||||
</template>
|
||||
|
||||
@@ -12,15 +12,10 @@
|
||||
resolved "https://registry.npmmirror.com/@ctrl/tinycolor/-/tinycolor-3.4.1.tgz#75b4c27948c81e88ccd3a8902047bcd797f38d32"
|
||||
integrity sha512-ej5oVy6lykXsvieQtqZxCOaLT+xD4+QNarq78cIYISHmZXshCvROLudpQN3lfL8G0NL7plMSSK+zlyvCaIJ4Iw==
|
||||
|
||||
"@element-plus/icons-vue@^2.0.4":
|
||||
version "2.0.4"
|
||||
resolved "https://registry.npmmirror.com/@element-plus/icons-vue/-/icons-vue-2.0.4.tgz#98fb9680c814a2a4f231b8bdabc8cd59b1b79d86"
|
||||
integrity sha512-UeBVBU3fuBsYa9mzM7DgkRztQ1Aftw3sMTI/1gZsqXq2NWiCOi16ZYXXGIc0jFDIu+k6SojzdlxOjv+rN/Y6FQ==
|
||||
|
||||
"@element-plus/icons-vue@^2.0.5":
|
||||
version "2.0.5"
|
||||
resolved "https://registry.npmmirror.com/@element-plus/icons-vue/-/icons-vue-2.0.5.tgz#8eb4143a7b5e4d8468d2e72af99eefee446f5ea0"
|
||||
integrity sha512-jvNWyKcdvPvMDLTWjghrPY+bYHKqh7hbAFIPe+HWR073zilzt33csREzmKx3VwhdlJUW5u0nCqN+0rwI8jlH+w==
|
||||
"@element-plus/icons-vue@^2.0.6":
|
||||
version "2.0.6"
|
||||
resolved "https://registry.npmmirror.com/@element-plus/icons-vue/-/icons-vue-2.0.6.tgz#8490e7a3193c17515d10c3be0544d800afe6a228"
|
||||
integrity sha512-lPpG8hYkjL/Z97DH5Ei6w6o22Z4YdNglWCNYOPcB33JCF2A4wye6HFgSI7hEt9zdLyxlSpiqtgf9XcYU+m5mew==
|
||||
|
||||
"@eslint/eslintrc@^1.0.5":
|
||||
version "1.0.5"
|
||||
@@ -37,17 +32,17 @@
|
||||
minimatch "^3.0.4"
|
||||
strip-json-comments "^3.1.1"
|
||||
|
||||
"@floating-ui/core@^0.7.2":
|
||||
version "0.7.2"
|
||||
resolved "https://registry.npmmirror.com/@floating-ui/core/-/core-0.7.2.tgz#f7af9613d080dc29360e77c970965b79b524d45a"
|
||||
integrity sha512-FRVAkSNU/vGXLIsgbggcs70GkXKEOXgBBbNpYPNHSaKsCAMMd00NrjbtKTesxkdv9xm9N3+XiDlcFGY6WnatBg==
|
||||
"@floating-ui/core@^0.7.3":
|
||||
version "0.7.3"
|
||||
resolved "https://registry.npmmirror.com/@floating-ui/core/-/core-0.7.3.tgz#d274116678ffae87f6b60e90f88cc4083eefab86"
|
||||
integrity sha512-buc8BXHmG9l82+OQXOFU3Kr2XQx9ys01U/Q9HMIrZ300iLc8HLMgh7dcCqgYzAzf4BkoQvDcXf5Y+CuEZ5JBYg==
|
||||
|
||||
"@floating-ui/dom@^0.5.0":
|
||||
version "0.5.2"
|
||||
resolved "https://registry.npmmirror.com/@floating-ui/dom/-/dom-0.5.2.tgz#908f3febbfc0d6696d70921616ec194fe07af183"
|
||||
integrity sha512-z1DnEa7F3d8Fm/eXSbii8UEGpcjZGkQaYYUI0WpEVgD3vBfebDW8j/3ysusxonuMexoigA+A3b/fYH7sEqiwyg==
|
||||
"@floating-ui/dom@^0.5.4":
|
||||
version "0.5.4"
|
||||
resolved "https://registry.npmmirror.com/@floating-ui/dom/-/dom-0.5.4.tgz#4eae73f78bcd4bd553ae2ade30e6f1f9c73fe3f1"
|
||||
integrity sha512-419BMceRLq0RrmTSDxn8hf9R3VCJv2K9PUfugh5JyEFmdjzDo+e8U5EdR8nzKq8Yj1htzLm3b6eQEEam3/rrtg==
|
||||
dependencies:
|
||||
"@floating-ui/core" "^0.7.2"
|
||||
"@floating-ui/core" "^0.7.3"
|
||||
|
||||
"@humanwhocodes/config-array@^0.9.2":
|
||||
version "0.9.2"
|
||||
@@ -131,6 +126,11 @@
|
||||
resolved "https://registry.npmmirror.com/@types/sortablejs/download/@types/sortablejs-1.10.7.tgz#ab9039c85429f0516955ec6dbc0bb20139417b15"
|
||||
integrity sha1-q5A5yFQp8FFpVextvAuyATlBexU=
|
||||
|
||||
"@types/web-bluetooth@^0.0.14":
|
||||
version "0.0.14"
|
||||
resolved "https://registry.npmmirror.com/@types/web-bluetooth/-/web-bluetooth-0.0.14.tgz#94e175b53623384bff1f354cdb3197a8d63cdbe5"
|
||||
integrity sha512-5d2RhCard1nQUC3aHcq/gHzWYO6K0WJmAbjO7mQJgCQKtZpgXxv1rOM6O/dBDhDYYVutk1sciOgNSe+5YyfM8A==
|
||||
|
||||
"@typescript-eslint/eslint-plugin@^4.23.0":
|
||||
version "4.33.0"
|
||||
resolved "https://registry.npmmirror.com/@typescript-eslint/eslint-plugin/download/@typescript-eslint/eslint-plugin-4.33.0.tgz#c24dc7c8069c7706bc40d99f6fa87edcb2005276"
|
||||
@@ -364,31 +364,32 @@
|
||||
resolved "https://registry.npmmirror.com/@vue/shared/-/shared-3.2.37.tgz#8e6adc3f2759af52f0e85863dfb0b711ecc5c702"
|
||||
integrity sha512-4rSJemR2NQIo9Klm1vabqWjD8rs/ZaJSzMxkMNeJS6lHiUjjUeYFbooN19NgFjztubEKh3WlZUeOLVdbbUWHsw==
|
||||
|
||||
"@vueuse/core@^8.5.0":
|
||||
version "8.6.0"
|
||||
resolved "https://registry.npmmirror.com/@vueuse/core/-/core-8.6.0.tgz#a8f80363cc63d17382423f16beae57696f376e67"
|
||||
integrity sha512-VirzExCm/N+QdrEWT7J4uSrvJ5hquKIAU9alQ37kUvIJk9XxCLxmfRnmekYc1kz2+6BnoyuKYXVmrMV351CB4w==
|
||||
"@vueuse/core@^8.7.5":
|
||||
version "8.7.5"
|
||||
resolved "https://registry.npmmirror.com/@vueuse/core/-/core-8.7.5.tgz#e74a888251ea11a9d432068ce18cbdfc4f810251"
|
||||
integrity sha512-tqgzeZGoZcXzoit4kOGLWJibDMLp0vdm6ZO41SSUQhkhtrPhAg6dbIEPiahhUu6sZAmSYvVrZgEr5aKD51nrLA==
|
||||
dependencies:
|
||||
"@vueuse/metadata" "8.6.0"
|
||||
"@vueuse/shared" "8.6.0"
|
||||
"@types/web-bluetooth" "^0.0.14"
|
||||
"@vueuse/metadata" "8.7.5"
|
||||
"@vueuse/shared" "8.7.5"
|
||||
vue-demi "*"
|
||||
|
||||
"@vueuse/metadata@8.6.0":
|
||||
version "8.6.0"
|
||||
resolved "https://registry.npmmirror.com/@vueuse/metadata/-/metadata-8.6.0.tgz#34771443a72ee891ae001a70aa05dd9a1d799372"
|
||||
integrity sha512-F+CKPvaExsm7QgRr8y+ZNJFwXasn89rs5wth/HeX9lJ1q8XEt+HJ16Q5Sxh4rfG5YSKXrStveVge8TKvPjMjFA==
|
||||
"@vueuse/metadata@8.7.5":
|
||||
version "8.7.5"
|
||||
resolved "https://registry.npmmirror.com/@vueuse/metadata/-/metadata-8.7.5.tgz#c7f2b21d873d1604a8860ed9c5728d8f3295f00a"
|
||||
integrity sha512-emJZKRQSaEnVqmlu39NpNp8iaW+bPC2kWykWoWOZMSlO/0QVEmO/rt8A5VhOEJTKLX3vwTevqbiRy9WJRwVOQg==
|
||||
|
||||
"@vueuse/shared@8.6.0":
|
||||
version "8.6.0"
|
||||
resolved "https://registry.npmmirror.com/@vueuse/shared/-/shared-8.6.0.tgz#63dad9fc4b73a7fccbe5d6b97adeacf73d4fec41"
|
||||
integrity sha512-Y/IVywZo7IfEoSSEtCYpkVEmPV7pU35mEIxV7PbD/D3ly18B3mEsBaPbtDkNM/QP3zAZ5mn4nEkOfddX4uwuIA==
|
||||
"@vueuse/shared@8.7.5":
|
||||
version "8.7.5"
|
||||
resolved "https://registry.npmmirror.com/@vueuse/shared/-/shared-8.7.5.tgz#06fb08f6f8fc9e90be9d1e033fa443de927172b0"
|
||||
integrity sha512-THXPvMBFmg6Gf6AwRn/EdTh2mhqwjGsB2Yfp374LNQSQVKRHtnJ0I42bsZTn7nuEliBxqUrGQm/lN6qUHmhJLw==
|
||||
dependencies:
|
||||
vue-demi "*"
|
||||
|
||||
ace-builds@^1.5.3:
|
||||
version "1.5.3"
|
||||
resolved "https://registry.npmmirror.com/ace-builds/-/ace-builds-1.5.3.tgz#05f81d3464a9ea19696e5e6fd0f924d37dab442f"
|
||||
integrity sha512-WN5BKR2aTSuBmisO8jo3Fytk6sOmJGki82v/Boeic81IgYN8pFHNkXq2anDF0XkmfDWMqLbRoW9sjc/GtKzQbQ==
|
||||
ace-builds@^1.6.0:
|
||||
version "1.7.1"
|
||||
resolved "https://registry.npmmirror.com/ace-builds/-/ace-builds-1.7.1.tgz#be796fbd98610dda5e138aed98d309cac2ab0872"
|
||||
integrity sha512-1mcbP5kXvr729sJ9dA/8tul0pjuvKbma0LF/ZMRwPEwjoNWNpe/x0OXpaPJo36aRpZCjRZMl5zsME3hAKTiaNw==
|
||||
|
||||
acorn-jsx@^5.3.1:
|
||||
version "5.3.2"
|
||||
@@ -445,10 +446,10 @@ array-union@^2.1.0:
|
||||
resolved "https://registry.npm.taobao.org/array-union/download/array-union-2.1.0.tgz?cache=0&sync_timestamp=1614624262896&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Farray-union%2Fdownload%2Farray-union-2.1.0.tgz#b798420adbeb1de828d84acd8a2e23d3efe85e8d"
|
||||
integrity sha1-t5hCCtvrHego2ErNii4j0+/oXo0=
|
||||
|
||||
async-validator@^4.1.1:
|
||||
version "4.1.1"
|
||||
resolved "https://registry.npmmirror.com/async-validator/-/async-validator-4.1.1.tgz#3cd1437faa2de64743f7d56649dd904c946a18fe"
|
||||
integrity sha512-p4DO/JXwjs8klJyJL8Q2oM4ks5fUTze/h5k10oPPKMiLe1fj3G1QMzPHNmN1Py4ycOk7WlO2DcGXv1qiESJCZA==
|
||||
async-validator@^4.2.5:
|
||||
version "4.2.5"
|
||||
resolved "https://registry.npmmirror.com/async-validator/-/async-validator-4.2.5.tgz#c96ea3332a521699d0afaaceed510a54656c6339"
|
||||
integrity sha512-7HhHjtERjqlNbZtqNqy2rckN/SpOOlmDliet+lP7k+eKZEjPk3DgyeU9lIXLdeLz0uBbbVp+9Qdow9wJWgwwfg==
|
||||
|
||||
asynckit@^0.4.0:
|
||||
version "0.4.0"
|
||||
@@ -578,10 +579,10 @@ csstype@^2.6.8:
|
||||
resolved "https://registry.npmmirror.com/csstype/download/csstype-2.6.19.tgz?cache=0&sync_timestamp=1637224514674&other_urls=https%3A%2F%2Fregistry.npmmirror.com%2Fcsstype%2Fdownload%2Fcsstype-2.6.19.tgz#feeb5aae89020bb389e1f63669a5ed490e391caa"
|
||||
integrity sha512-ZVxXaNy28/k3kJg0Fou5MiYpp88j7H9hLZp8PDC3jV0WFjfH5E9xHb56L0W59cPbKbcHXeP4qyT8PrHp8t6LcQ==
|
||||
|
||||
dayjs@^1.11.2:
|
||||
version "1.11.2"
|
||||
resolved "https://registry.npmmirror.com/dayjs/-/dayjs-1.11.2.tgz#fa0f5223ef0d6724b3d8327134890cfe3d72fbe5"
|
||||
integrity sha512-F4LXf1OeU9hrSYRPTTj/6FbO4HTjPKXvEIC1P2kcnFurViINCVk3ZV0xAS3XVx9MkMsXbbqlK6hjseaYbgKEHw==
|
||||
dayjs@^1.11.3:
|
||||
version "1.11.3"
|
||||
resolved "https://registry.npmmirror.com/dayjs/-/dayjs-1.11.3.tgz#4754eb694a624057b9ad2224b67b15d552589258"
|
||||
integrity sha512-xxwlswWOlGhzgQ4TKzASQkUhqERI3egRNqgV4ScR8wlANA/A9tZ7miXa44vTTKEq5l7vWoL5G57bG3zA+Kow0A==
|
||||
|
||||
debug@^4.1.1, debug@^4.3.1, debug@^4.3.2:
|
||||
version "4.3.3"
|
||||
@@ -624,28 +625,28 @@ dotenv@^10.0.0:
|
||||
resolved "https://registry.nlark.com/dotenv/download/dotenv-10.0.0.tgz#3d4227b8fb95f81096cdd2b66653fb2c7085ba81"
|
||||
integrity sha1-PUInuPuV+BCWzdK2ZlP7LHCFuoE=
|
||||
|
||||
echarts@^5.3.2:
|
||||
version "5.3.2"
|
||||
resolved "https://registry.npmmirror.com/echarts/-/echarts-5.3.2.tgz#0a7b3be8c48a48b2e7cb1b82121df0c208d42d2c"
|
||||
integrity sha512-LWCt7ohOKdJqyiBJ0OGBmE9szLdfA9sGcsMEi+GGoc6+Xo75C+BkcT/6NNGRHAWtnQl2fNow05AQjznpap28TQ==
|
||||
echarts@^5.3.3:
|
||||
version "5.3.3"
|
||||
resolved "https://registry.npmmirror.com/echarts/-/echarts-5.3.3.tgz#df97b09c4c0e2ffcdfb44acf518d50c50e0b838e"
|
||||
integrity sha512-BRw2serInRwO5SIwRviZ6Xgm5Lb7irgz+sLiFMmy/HOaf4SQ+7oYqxKzRHAKp4xHQ05AuHw1xvoQWJjDQq/FGw==
|
||||
dependencies:
|
||||
tslib "2.3.0"
|
||||
zrender "5.3.1"
|
||||
zrender "5.3.2"
|
||||
|
||||
element-plus@^2.2.4:
|
||||
version "2.2.4"
|
||||
resolved "https://registry.npmmirror.com/element-plus/-/element-plus-2.2.4.tgz#f07f400222a5b0ae93ee9a139155342604746813"
|
||||
integrity sha512-jktZr0o3ARDxWNWPEaJZQm2BN7thTpQl0aIfCUo5eB5m+zEap2DEcojyGKMHSQsCULcPM32NFfu2sHlhbhOiGA==
|
||||
element-plus@^2.2.8:
|
||||
version "2.2.8"
|
||||
resolved "https://registry.npmmirror.com/element-plus/-/element-plus-2.2.8.tgz#6bba6285c20d8bea42247977d8f605611fc2da93"
|
||||
integrity sha512-+cubFh1rgeGcc2LeBm7hv/1BKFJre/LIIdRntm9OLaIhysCxigjEwcxk9gbVT4KsbcjmoqZUr4/mwhIhQV6mvw==
|
||||
dependencies:
|
||||
"@ctrl/tinycolor" "^3.4.1"
|
||||
"@element-plus/icons-vue" "^2.0.5"
|
||||
"@floating-ui/dom" "^0.5.0"
|
||||
"@element-plus/icons-vue" "^2.0.6"
|
||||
"@floating-ui/dom" "^0.5.4"
|
||||
"@popperjs/core" "npm:@sxzz/popperjs-es@^2.11.7"
|
||||
"@types/lodash" "^4.14.182"
|
||||
"@types/lodash-es" "^4.17.6"
|
||||
"@vueuse/core" "^8.5.0"
|
||||
async-validator "^4.1.1"
|
||||
dayjs "^1.11.2"
|
||||
"@vueuse/core" "^8.7.5"
|
||||
async-validator "^4.2.5"
|
||||
dayjs "^1.11.3"
|
||||
escape-html "^1.0.3"
|
||||
lodash "^4.17.21"
|
||||
lodash-es "^4.17.21"
|
||||
@@ -1201,12 +1202,12 @@ json-stable-stringify-without-jsonify@^1.0.1:
|
||||
resolved "https://registry.nlark.com/json-stable-stringify-without-jsonify/download/json-stable-stringify-without-jsonify-1.0.1.tgz#9db7b59496ad3f3cfef30a75142d2d930ad72651"
|
||||
integrity sha1-nbe1lJatPzz+8wp1FC0tkwrXJlE=
|
||||
|
||||
jsoneditor@^9.8.0:
|
||||
version "9.8.0"
|
||||
resolved "https://registry.npmmirror.com/jsoneditor/-/jsoneditor-9.8.0.tgz#08db81ccf6f6e9fdff8691e42c4fb62d3efdd6ad"
|
||||
integrity sha512-q1ekwYizbSAny0/UAEOzLviVCyBS5XFGwM/EUNf9KnfB1MRSDmJDWjt4lAqMVz1TUV5O/l3J4/WzUSLQh2tZjw==
|
||||
jsoneditor@^9.9.0:
|
||||
version "9.9.0"
|
||||
resolved "https://registry.npmmirror.com/jsoneditor/-/jsoneditor-9.9.0.tgz#671e1231e23c43ebc6e1eb43fe97b2f97b156faf"
|
||||
integrity sha512-NHJhyaqcc5U33ah6dEcd0S9b14Auocpe9nydvC9ui7Uq/vjEFnsd7ot6O9Jqwv53B7DmHFUWq5cT4qeWh4MEoA==
|
||||
dependencies:
|
||||
ace-builds "^1.5.3"
|
||||
ace-builds "^1.6.0"
|
||||
ajv "^6.12.6"
|
||||
javascript-natural-sort "^0.7.1"
|
||||
jmespath "^0.16.0"
|
||||
@@ -1587,10 +1588,10 @@ sourcemap-codec@^1.4.4:
|
||||
resolved "https://registry.npm.taobao.org/sourcemap-codec/download/sourcemap-codec-1.4.8.tgz#ea804bd94857402e6992d05a38ef1ae35a9ab4c4"
|
||||
integrity sha1-6oBL2UhXQC5pktBaOO8a41qatMQ=
|
||||
|
||||
sql-formatter@^6.1.2:
|
||||
version "6.1.2"
|
||||
resolved "https://registry.npmmirror.com/sql-formatter/-/sql-formatter-6.1.2.tgz#78b05021c641020312a5f144ec313b38e7663258"
|
||||
integrity sha512-09AiPmA6zDq82IBXOj5kN33VeAqaV92enkoonlhJge0fmfTESiYs3pwsntGKxa1C89xj/9MoHlNeqMmCr23BJw==
|
||||
sql-formatter@^7.0.3:
|
||||
version "7.0.3"
|
||||
resolved "https://registry.npmmirror.com/sql-formatter/-/sql-formatter-7.0.3.tgz#6c78f1e550cfa8419fa6f50c2c6140178484c3a7"
|
||||
integrity sha512-E9zotLB0dy9ZZhs1sY4ZqzSzJGF2uC4Vzj0mEzXJC9rlE+Jjmz6t64qT2dzm/IPQosYvZknDbBOrWkygIJz67A==
|
||||
dependencies:
|
||||
argparse "^2.0.1"
|
||||
|
||||
@@ -1664,10 +1665,10 @@ type-fest@^0.20.2:
|
||||
resolved "https://registry.npmmirror.com/type-fest/download/type-fest-0.20.2.tgz#1bf207f4b28f91583666cb5fbd327887301cd5f4"
|
||||
integrity sha1-G/IH9LKPkVg2ZstfvTJ4hzAc1fQ=
|
||||
|
||||
typescript@^4.2.4:
|
||||
version "4.5.4"
|
||||
resolved "https://registry.npmmirror.com/typescript/download/typescript-4.5.4.tgz#a17d3a0263bf5c8723b9c52f43c5084edf13c2e8"
|
||||
integrity sha512-VgYs2A2QIRuGphtzFV7aQJduJ2gyfTljngLzjpfW9FoYZF6xuw1W0vW9ghCKLfcWrCFxK81CSGRAvS1pn4fIUg==
|
||||
typescript@^4.7.4:
|
||||
version "4.7.4"
|
||||
resolved "https://registry.npmmirror.com/typescript/-/typescript-4.7.4.tgz#1a88596d1cf47d59507a1bcdfb5b9dfe4d488235"
|
||||
integrity sha512-C0WQT0gezHuw6AdY1M2jxUO83Rjf0HP7Sk1DtXj6j1EwkQNZrHAg2XPWlq62oqEhYvONq5pkC2Y9oPljWToLmQ==
|
||||
|
||||
uri-js@^4.2.2:
|
||||
version "4.4.1"
|
||||
@@ -1688,10 +1689,10 @@ vanilla-picker@^2.12.1:
|
||||
dependencies:
|
||||
"@sphinxxxx/color-conversion" "^2.2.2"
|
||||
|
||||
vite@^2.9.10:
|
||||
version "2.9.10"
|
||||
resolved "https://registry.npmmirror.com/vite/-/vite-2.9.10.tgz#f574d96655622c2e0fbc662edd0ed199c60fe91a"
|
||||
integrity sha512-TwZRuSMYjpTurLqXspct+HZE7ONiW9d+wSWgvADGxhDPPyoIcNywY+RX4ng+QpK30DCa1l/oZgi2PLZDibhzbQ==
|
||||
vite@^2.9.13:
|
||||
version "2.9.13"
|
||||
resolved "https://registry.npmmirror.com/vite/-/vite-2.9.13.tgz#859cb5d4c316c0d8c6ec9866045c0f7858ca6abc"
|
||||
integrity sha512-AsOBAaT0AD7Mhe8DuK+/kE4aWYFMx/i0ZNi98hJclxb4e0OhQcZYUrvLjIaQ8e59Ui7txcvKMiJC1yftqpQoDw==
|
||||
dependencies:
|
||||
esbuild "^0.14.27"
|
||||
postcss "^8.4.13"
|
||||
@@ -1725,10 +1726,10 @@ vue-eslint-parser@^8.0.1:
|
||||
lodash "^4.17.21"
|
||||
semver "^7.3.5"
|
||||
|
||||
vue-router@^4.0.15:
|
||||
version "4.0.15"
|
||||
resolved "https://registry.npmmirror.com/vue-router/-/vue-router-4.0.15.tgz#b4a0661efe197f8c724e0f233308f8776e2c3667"
|
||||
integrity sha512-xa+pIN9ZqORdIW1MkN2+d9Ui2pCM1b/UMgwYUCZOiFYHAvz/slKKBDha8DLrh5aCG/RibtrpyhKjKOZ85tYyWg==
|
||||
vue-router@^4.0.16:
|
||||
version "4.0.16"
|
||||
resolved "https://registry.npmmirror.com/vue-router/-/vue-router-4.0.16.tgz#9477beeeef36e80e04d041a1738801a55e6e862e"
|
||||
integrity sha512-JcO7cb8QJLBWE+DfxGUL3xUDOae/8nhM1KVdnudadTAORbuxIC/xAydC5Zr/VLHUDQi1ppuTF5/rjBGzgzrJNA==
|
||||
dependencies:
|
||||
"@vue/devtools-api" "^6.0.0"
|
||||
|
||||
@@ -1772,19 +1773,19 @@ xterm-addon-fit@^0.5.0:
|
||||
resolved "https://registry.npmmirror.com/xterm-addon-fit/download/xterm-addon-fit-0.5.0.tgz#2d51b983b786a97dcd6cde805e700c7f913bc596"
|
||||
integrity sha1-LVG5g7eGqX3NbN6AXnAMf5E7xZY=
|
||||
|
||||
xterm@^4.18.0:
|
||||
version "4.18.0"
|
||||
resolved "https://registry.npmmirror.com/xterm/-/xterm-4.18.0.tgz#a1f6ab2c330c3918fb094ae5f4c2562987398ea1"
|
||||
integrity sha512-JQoc1S0dti6SQfI0bK1AZvGnAxH4MVw45ZPFSO6FHTInAiau3Ix77fSxNx3mX4eh9OL4AYa8+4C8f5UvnSfppQ==
|
||||
xterm@^4.19.0:
|
||||
version "4.19.0"
|
||||
resolved "https://registry.npmmirror.com/xterm/-/xterm-4.19.0.tgz#c0f9d09cd61de1d658f43ca75f992197add9ef6d"
|
||||
integrity sha512-c3Cp4eOVsYY5Q839dR5IejghRPpxciGmLWWaP9g+ppfMeBChMeLa1DCA+pmX/jyDZ+zxFOmlJL/82qVdayVoGQ==
|
||||
|
||||
yallist@^4.0.0:
|
||||
version "4.0.0"
|
||||
resolved "https://registry.nlark.com/yallist/download/yallist-4.0.0.tgz#9bb92790d9c0effec63be73519e11a35019a3a72"
|
||||
integrity sha1-m7knkNnA7/7GO+c1GeEaNQGaOnI=
|
||||
|
||||
zrender@5.3.1:
|
||||
version "5.3.1"
|
||||
resolved "https://registry.npmmirror.com/zrender/-/zrender-5.3.1.tgz#fa8e63ac7e719cfd563831fe8c42a9756c5af384"
|
||||
integrity sha512-7olqIjy0gWfznKr6vgfnGBk7y4UtdMvdwFmK92vVQsQeDPyzkHW1OlrLEKg6GHz1W5ePf0FeN1q2vkl/HFqhXw==
|
||||
zrender@5.3.2:
|
||||
version "5.3.2"
|
||||
resolved "https://registry.npmmirror.com/zrender/-/zrender-5.3.2.tgz#f67b11d36d3d020d62411d3bb123eb1c93cccd69"
|
||||
integrity sha512-8IiYdfwHj2rx0UeIGZGGU4WEVSDEdeVCaIg/fomejg1Xu6OifAL1GVzIPHg2D+MyUkbNgPWji90t0a8IDk+39w==
|
||||
dependencies:
|
||||
tslib "2.3.0"
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
module mayfly-go
|
||||
|
||||
go 1.17
|
||||
go 1.18
|
||||
|
||||
require (
|
||||
github.com/dgrijalva/jwt-go v3.2.0+incompatible // jwt
|
||||
github.com/gin-gonic/gin v1.7.7
|
||||
github.com/gin-gonic/gin v1.8.1
|
||||
github.com/go-redis/redis v6.15.9+incompatible
|
||||
github.com/gorilla/websocket v1.5.0
|
||||
github.com/mojocn/base64Captcha v1.3.5 // 验证码
|
||||
@@ -27,8 +27,8 @@ require (
|
||||
github.com/go-playground/validator/v10 v10.10.1 // indirect
|
||||
github.com/go-sql-driver/mysql v1.6.0 // indirect
|
||||
github.com/go-stack/stack v1.8.0 // indirect
|
||||
github.com/goccy/go-json v0.9.7 // indirect
|
||||
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 // indirect
|
||||
github.com/golang/protobuf v1.5.2 // indirect
|
||||
github.com/golang/snappy v0.0.1 // indirect
|
||||
github.com/jinzhu/inflection v1.0.0 // indirect
|
||||
github.com/jinzhu/now v1.1.4 // indirect
|
||||
@@ -41,6 +41,7 @@ require (
|
||||
github.com/modern-go/reflect2 v1.0.2 // indirect
|
||||
github.com/onsi/ginkgo v1.16.5 // indirect
|
||||
github.com/onsi/gomega v1.18.1 // indirect
|
||||
github.com/pelletier/go-toml/v2 v2.0.1 // indirect
|
||||
github.com/pkg/errors v0.9.1 // indirect
|
||||
github.com/ugorji/go/codec v1.2.7 // indirect
|
||||
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
|
||||
@@ -48,9 +49,10 @@ require (
|
||||
github.com/xdg-go/stringprep v1.0.2 // indirect
|
||||
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d // indirect
|
||||
golang.org/x/image v0.0.0-20220302094943-723b81ca9867 // indirect
|
||||
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2 // indirect
|
||||
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9 // indirect
|
||||
golang.org/x/sys v0.0.0-20220310020820-b874c991c1a5 // indirect
|
||||
golang.org/x/text v0.3.7 // indirect
|
||||
google.golang.org/protobuf v1.27.1 // indirect
|
||||
google.golang.org/protobuf v1.28.0 // indirect
|
||||
gopkg.in/yaml.v2 v2.4.0 // indirect
|
||||
)
|
||||
|
||||
@@ -2,7 +2,7 @@ package api
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"mayfly-go/internal/devops/api/form"
|
||||
"mayfly-go/internal/devops/api/vo"
|
||||
"mayfly-go/internal/devops/application"
|
||||
@@ -16,8 +16,10 @@ import (
|
||||
"mayfly-go/pkg/ws"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/xwb1989/sqlparser"
|
||||
)
|
||||
|
||||
type Db struct {
|
||||
@@ -27,6 +29,8 @@ type Db struct {
|
||||
ProjectApp application.Project
|
||||
}
|
||||
|
||||
const DEFAULT_COLUMN_SIZE = 500
|
||||
|
||||
// @router /api/dbs [get]
|
||||
func (d *Db) Dbs(rc *ctx.ReqCtx) {
|
||||
g := rc.GinCtx
|
||||
@@ -91,7 +95,7 @@ func (d *Db) ExecSql(rc *ctx.ReqCtx) {
|
||||
rc.ReqParam = fmt.Sprintf("db: %d:%s | sql: %s", id, db, sql)
|
||||
|
||||
biz.NotEmpty(sql, "sql不能为空")
|
||||
if strings.HasPrefix(sql, "SELECT") || strings.HasPrefix(sql, "select") || strings.HasPrefix(sql, "show") {
|
||||
if strings.HasPrefix(sql, "SELECT") || strings.HasPrefix(sql, "select") || strings.HasPrefix(sql, "show") || strings.HasPrefix(sql, "explain") {
|
||||
colNames, res, err := dbInstance.SelectData(sql)
|
||||
biz.ErrIsNilAppendErr(err, "查询失败: %s")
|
||||
colAndRes := make(map[string]interface{})
|
||||
@@ -128,12 +132,8 @@ func (d *Db) ExecSqlFile(rc *ctx.ReqCtx) {
|
||||
fileheader, err := g.FormFile("file")
|
||||
biz.ErrIsNilAppendErr(err, "读取sql文件失败: %s")
|
||||
|
||||
// 读取sql文件并根据;切割sql语句
|
||||
file, _ := fileheader.Open()
|
||||
filename := fileheader.Filename
|
||||
bytes, _ := ioutil.ReadAll(file)
|
||||
sqlContent := string(bytes)
|
||||
sqls := strings.Split(sqlContent, ";")
|
||||
dbId, db := GetIdAndDb(g)
|
||||
|
||||
go func() {
|
||||
@@ -153,12 +153,14 @@ func (d *Db) ExecSqlFile(rc *ctx.ReqCtx) {
|
||||
|
||||
biz.ErrIsNilAppendErr(d.ProjectApp.CanAccess(rc.LoginAccount.Id, db.ProjectId), "%s")
|
||||
|
||||
for _, sql := range sqls {
|
||||
sql = strings.Trim(sql, " ")
|
||||
if sql == "" || sql == "\n" {
|
||||
continue
|
||||
tokens := sqlparser.NewTokenizer(file)
|
||||
for {
|
||||
stmt, err := sqlparser.ParseNext(tokens)
|
||||
if err == io.EOF {
|
||||
break
|
||||
}
|
||||
_, err := db.Exec(sql)
|
||||
sql := sqlparser.String(stmt)
|
||||
_, err = db.Exec(sql)
|
||||
if err != nil {
|
||||
d.MsgApp.CreateAndSend(rc.LoginAccount, ws.ErrMsg("sql脚本执行失败", fmt.Sprintf("[%s]%s执行失败: [%s]", filename, dbInfo, err.Error())))
|
||||
return
|
||||
@@ -168,6 +170,88 @@ func (d *Db) ExecSqlFile(rc *ctx.ReqCtx) {
|
||||
}()
|
||||
}
|
||||
|
||||
// 数据库dump
|
||||
func (d *Db) DumpSql(rc *ctx.ReqCtx) {
|
||||
g := rc.GinCtx
|
||||
dbId, db := GetIdAndDb(g)
|
||||
dumpType := g.Query("type")
|
||||
tablesStr := g.Query("tables")
|
||||
biz.NotEmpty(tablesStr, "请选择要导出的表")
|
||||
tables := strings.Split(tablesStr, ",")
|
||||
|
||||
// 是否需要导出表结构
|
||||
needStruct := dumpType == "1" || dumpType == "3"
|
||||
// 是否需要导出数据
|
||||
needData := dumpType == "2" || dumpType == "3"
|
||||
|
||||
now := time.Now()
|
||||
filename := fmt.Sprintf("%s.%s.sql", db, now.Format("200601021504"))
|
||||
g.Header("Content-Type", "application/octet-stream")
|
||||
g.Header("Content-Disposition", "attachment; filename="+filename)
|
||||
|
||||
rc.ReqParam = fmt.Sprintf("数据库id: %d -- %s", dbId, db)
|
||||
dbInstance := d.DbApp.GetDbInstance(dbId, db)
|
||||
writer := g.Writer
|
||||
writer.WriteString("-- ----------------------------")
|
||||
writer.WriteString("\n-- 导出平台: mayfly-go")
|
||||
writer.WriteString(fmt.Sprintf("\n-- 导出时间: %s ", now.Format("2006-01-02 15:04:05")))
|
||||
writer.WriteString(fmt.Sprintf("\n-- 导出数据库: %s ", db))
|
||||
writer.WriteString("\n-- ----------------------------\n")
|
||||
|
||||
for _, table := range tables {
|
||||
if needStruct {
|
||||
writer.WriteString(fmt.Sprintf("\n-- ----------------------------\n-- 表结构: %s \n-- ----------------------------\n", table))
|
||||
writer.WriteString(fmt.Sprintf("DROP TABLE IF EXISTS `%s`;\n", table))
|
||||
writer.WriteString(dbInstance.GetCreateTableDdl(table)[0]["Create Table"].(string) + ";\n")
|
||||
}
|
||||
|
||||
if !needData {
|
||||
continue
|
||||
}
|
||||
|
||||
writer.WriteString(fmt.Sprintf("\n-- ----------------------------\n-- 表记录: %s \n-- ----------------------------\n", table))
|
||||
writer.WriteString("BEGIN;\n")
|
||||
|
||||
countSql := fmt.Sprintf("SELECT COUNT(*) count FROM %s", table)
|
||||
_, countRes, _ := dbInstance.SelectData(countSql)
|
||||
// 查询出所有列信息总数,手动分页获取所有数据
|
||||
maCount := int(countRes[0]["count"].(int64))
|
||||
// 计算需要查询的页数
|
||||
pageNum := maCount / DEFAULT_COLUMN_SIZE
|
||||
if maCount%DEFAULT_COLUMN_SIZE > 0 {
|
||||
pageNum++
|
||||
}
|
||||
|
||||
sqlTmp := "SELECT * FROM %s LIMIT %d, %d"
|
||||
for index := 0; index < pageNum; index++ {
|
||||
sql := fmt.Sprintf(sqlTmp, table, index*DEFAULT_COLUMN_SIZE, DEFAULT_COLUMN_SIZE)
|
||||
columns, result, _ := dbInstance.SelectData(sql)
|
||||
|
||||
insertSql := "INSERT INTO `%s` VALUES (%s);\n"
|
||||
for _, res := range result {
|
||||
var values []string
|
||||
for _, column := range columns {
|
||||
value := res[column]
|
||||
if value == nil {
|
||||
values = append(values, "NULL")
|
||||
continue
|
||||
}
|
||||
strValue, ok := value.(string)
|
||||
if ok {
|
||||
values = append(values, fmt.Sprintf("%#v", strValue))
|
||||
} else {
|
||||
values = append(values, utils.ToString(value))
|
||||
}
|
||||
}
|
||||
writer.WriteString(fmt.Sprintf(insertSql, table, strings.Join(values, ", ")))
|
||||
}
|
||||
}
|
||||
|
||||
writer.WriteString("COMMIT;\n")
|
||||
}
|
||||
rc.NoRes = true
|
||||
}
|
||||
|
||||
// @router /api/db/:dbId/t-metadata [get]
|
||||
func (d *Db) TableMA(rc *ctx.ReqCtx) {
|
||||
dbi := d.DbApp.GetDbInstance(GetIdAndDb(rc.GinCtx))
|
||||
|
||||
@@ -223,8 +223,9 @@ func (d *DbInstance) SelectData(execSql string) ([]string, []map[string]interfac
|
||||
execSql = strings.Trim(execSql, " ")
|
||||
isSelect := strings.HasPrefix(execSql, "SELECT") || strings.HasPrefix(execSql, "select")
|
||||
isShow := strings.HasPrefix(execSql, "show")
|
||||
isExplain := strings.HasPrefix(execSql, "explain")
|
||||
|
||||
if !isSelect && !isShow {
|
||||
if !isSelect && !isShow && !isExplain {
|
||||
return nil, nil, errors.New("该sql非查询语句")
|
||||
}
|
||||
// 没加limit,则默认限制50条
|
||||
@@ -272,14 +273,13 @@ func (d *DbInstance) SelectData(execSql string) ([]string, []map[string]interfac
|
||||
colName := colType.Name()
|
||||
// 字段类型名
|
||||
colScanType := colType.ScanType().Name()
|
||||
|
||||
// 如果是密码字段,则脱敏显示
|
||||
if colName == "password" {
|
||||
v = []byte("******")
|
||||
}
|
||||
if isFirst {
|
||||
colNames = append(colNames, colName)
|
||||
}
|
||||
if v == nil {
|
||||
rowData[colName] = nil
|
||||
continue
|
||||
}
|
||||
// 这里把[]byte数据转成string
|
||||
stringV := string(v)
|
||||
if stringV == "" {
|
||||
@@ -352,19 +352,19 @@ const (
|
||||
// mysql 表信息元数据
|
||||
MYSQL_TABLE_MA = `SELECT table_name tableName, engine, table_comment tableComment,
|
||||
create_time createTime from information_schema.tables
|
||||
WHERE table_schema = (SELECT database())`
|
||||
WHERE table_schema = (SELECT database()) LIMIT 2000`
|
||||
|
||||
// mysql 表信息
|
||||
MYSQL_TABLE_INFO = `SELECT table_name tableName, table_comment tableComment, table_rows tableRows,
|
||||
data_length dataLength, index_length indexLength, create_time createTime
|
||||
FROM information_schema.tables
|
||||
WHERE table_schema = (SELECT database())`
|
||||
WHERE table_schema = (SELECT database()) LIMIT 2000`
|
||||
|
||||
// mysql 索引信息
|
||||
MYSQL_INDEX_INFO = `SELECT index_name indexName, column_name columnName, index_type indexType,
|
||||
SEQ_IN_INDEX seqInIndex, INDEX_COMMENT indexComment
|
||||
FROM information_schema.STATISTICS
|
||||
WHERE table_schema = (SELECT database()) AND table_name = '%s'`
|
||||
WHERE table_schema = (SELECT database()) AND table_name = '%s' LIMIT 500`
|
||||
|
||||
// 默认每次查询列元信息数量
|
||||
DEFAULT_COLUMN_SIZE = 2000
|
||||
@@ -372,7 +372,7 @@ const (
|
||||
// mysql 列信息元数据
|
||||
MYSQL_COLOUMN_MA = `SELECT table_name tableName, column_name columnName, column_type columnType,
|
||||
column_comment columnComment, column_key columnKey, extra, is_nullable nullable from information_schema.columns
|
||||
WHERE table_name in (%s) AND table_schema = (SELECT database()) ORDER BY tableName, ordinal_position limit %d, %d`
|
||||
WHERE table_name in (%s) AND table_schema = (SELECT database()) ORDER BY tableName, ordinal_position LIMIT %d, %d`
|
||||
|
||||
// mysql 列信息元数据总数
|
||||
MYSQL_COLOUMN_MA_COUNT = `SELECT COUNT(*) maNum from information_schema.columns
|
||||
|
||||
@@ -61,6 +61,12 @@ func InitDbRouter(router *gin.RouterGroup) {
|
||||
rc.Handle(d.ExecSqlFile)
|
||||
})
|
||||
|
||||
db.GET(":dbId/dump", func(g *gin.Context) {
|
||||
ctx.NewReqCtxWithGin(g).
|
||||
WithLog(ctx.NewLogInfo("Sql文件dump")).
|
||||
Handle(d.DumpSql)
|
||||
})
|
||||
|
||||
db.GET(":dbId/t-metadata", func(c *gin.Context) {
|
||||
ctx.NewReqCtxWithGin(c).Handle(d.TableMA)
|
||||
})
|
||||
|
||||
@@ -16,7 +16,6 @@ type HandlerFunc func(*ReqCtx)
|
||||
type ReqCtx struct {
|
||||
GinCtx *gin.Context // gin context
|
||||
|
||||
// NeedToken bool // 是否需要token
|
||||
RequiredPermission *Permission // 需要的权限信息,默认为nil,需要校验token
|
||||
LoginAccount *model.LoginAccount // 登录账号信息,只有校验token后才会有值
|
||||
|
||||
@@ -26,7 +25,7 @@ type ReqCtx struct {
|
||||
Err interface{} // 请求错误
|
||||
|
||||
timed int64 // 执行时间
|
||||
noRes bool // 无需返回结果,即文件下载等
|
||||
NoRes bool // 无需返回结果,即文件下载等
|
||||
}
|
||||
|
||||
func (rc *ReqCtx) Handle(handler HandlerFunc) {
|
||||
@@ -55,13 +54,13 @@ func (rc *ReqCtx) Handle(handler HandlerFunc) {
|
||||
begin := time.Now()
|
||||
handler(rc)
|
||||
rc.timed = time.Now().Sub(begin).Milliseconds()
|
||||
if !rc.noRes {
|
||||
if !rc.NoRes {
|
||||
ginx.SuccessRes(ginCtx, rc.ResData)
|
||||
}
|
||||
}
|
||||
|
||||
func (rc *ReqCtx) Download(reader io.Reader, filename string) {
|
||||
rc.noRes = true
|
||||
rc.NoRes = true
|
||||
ginx.Download(rc.GinCtx, reader, filename)
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,8 @@ package utils
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"strconv"
|
||||
"strings"
|
||||
"text/template"
|
||||
)
|
||||
@@ -107,3 +109,45 @@ func ReverStrTemplate(temp, str string, res map[string]interface{}) {
|
||||
ReverStrTemplate(next, StrTrim(SubString(str, UnicodeIndex(str, value)+StrLen(value), StrLen(str))), res)
|
||||
}
|
||||
}
|
||||
|
||||
func ToString(value interface{}) string {
|
||||
// interface 转 string
|
||||
var key string
|
||||
if value == nil {
|
||||
return key
|
||||
}
|
||||
|
||||
switch it := value.(type) {
|
||||
case float64:
|
||||
return strconv.FormatFloat(it, 'f', -1, 64)
|
||||
case float32:
|
||||
return strconv.FormatFloat(float64(it), 'f', -1, 64)
|
||||
case int:
|
||||
return strconv.Itoa(it)
|
||||
case uint:
|
||||
return strconv.Itoa(int(it))
|
||||
case int8:
|
||||
return strconv.Itoa(int(it))
|
||||
case uint8:
|
||||
return strconv.Itoa(int(it))
|
||||
case int16:
|
||||
return strconv.Itoa(int(it))
|
||||
case uint16:
|
||||
return strconv.Itoa(int(it))
|
||||
case int32:
|
||||
return strconv.Itoa(int(it))
|
||||
case uint32:
|
||||
return strconv.Itoa(int(it))
|
||||
case int64:
|
||||
return strconv.FormatInt(it, 10)
|
||||
case uint64:
|
||||
return strconv.FormatUint(it, 10)
|
||||
case string:
|
||||
return it
|
||||
case []byte:
|
||||
return string(value.([]byte))
|
||||
default:
|
||||
newValue, _ := json.Marshal(value)
|
||||
return string(newValue)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user