mirror of
https://gitee.com/dromara/mayfly-go
synced 2025-12-28 10:26:35 +08:00
feat: 新增机器与项目关联及相关资源列表查询以项目关联成员为准
This commit is contained in:
@@ -173,14 +173,15 @@ func GetPageBySql(sql string, param *PageParam, toModel interface{}, args ...int
|
||||
countSql := strings.Replace(sql, selectCol, "COUNT(*) AS total ", 1)
|
||||
// 查询count
|
||||
var count int
|
||||
db.Raw(countSql, args...).Scan(&count)
|
||||
err := db.Raw(countSql, args...).Scan(&count).Error
|
||||
biz.ErrIsNilAppendErr(err, "查询失败: %s")
|
||||
if count == 0 {
|
||||
return &PageResult{Total: 0, List: []string{}}
|
||||
}
|
||||
// 分页查询
|
||||
limitSql := sql + " LIMIT " + strconv.Itoa(param.PageNum-1) + ", " + strconv.Itoa(param.PageSize)
|
||||
err := db.Raw(limitSql).Scan(toModel).Error
|
||||
biz.ErrIsNil(err, "查询失败")
|
||||
err = db.Raw(limitSql).Scan(toModel).Error
|
||||
biz.ErrIsNil(err, "查询失败: %s")
|
||||
return &PageResult{Total: int64(count), List: toModel}
|
||||
}
|
||||
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
{"/Users/hml/Desktop/project/go/mayfly-go/controllers":1610075329396211594}
|
||||
@@ -2,17 +2,11 @@
|
||||
<div>
|
||||
<el-dialog :title="title" v-model="dialogVisible" :show-close="false" :before-close="cancel" width="35%">
|
||||
<el-form :model="form" ref="machineForm" :rules="rules" label-width="85px" size="small">
|
||||
<!-- <el-form-item prop="projectId" label="项目:" required>
|
||||
<el-form-item prop="projectId" label="项目:" required>
|
||||
<el-select style="width: 100%" v-model="form.projectId" placeholder="请选择项目" @change="changeProject" filterable>
|
||||
<el-option v-for="item in projects" :key="item.id" :label="`${item.name} [${item.remark}]`" :value="item.id"> </el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item prop="envId" label="环境:" required>
|
||||
<el-select @change="changeEnv" style="width: 100%" v-model="form.envId" placeholder="请选择环境">
|
||||
<el-option v-for="item in envs" :key="item.id" :label="`${item.name} [${item.remark}]`" :value="item.id"> </el-option>
|
||||
</el-select>
|
||||
</el-form-item> -->
|
||||
<el-form-item prop="name" label="名称:" required>
|
||||
<el-input v-model.trim="form.name" placeholder="请输入机器别名" auto-complete="off"></el-input>
|
||||
</el-form-item>
|
||||
@@ -57,6 +51,9 @@ export default defineComponent({
|
||||
visible: {
|
||||
type: Boolean,
|
||||
},
|
||||
projects: {
|
||||
type: Array,
|
||||
},
|
||||
machine: {
|
||||
type: [Boolean, Object],
|
||||
},
|
||||
@@ -68,8 +65,11 @@ export default defineComponent({
|
||||
const machineForm: any = ref(null);
|
||||
const state = reactive({
|
||||
dialogVisible: false,
|
||||
projects: [],
|
||||
form: {
|
||||
id: null,
|
||||
projectId: null,
|
||||
projectName: null,
|
||||
name: null,
|
||||
port: 22,
|
||||
username: null,
|
||||
@@ -131,6 +131,7 @@ export default defineComponent({
|
||||
|
||||
watch(props, async (newValue) => {
|
||||
state.dialogVisible = newValue.visible;
|
||||
state.projects = newValue.projects;
|
||||
if (newValue.machine) {
|
||||
state.form = { ...newValue.machine };
|
||||
} else {
|
||||
@@ -138,6 +139,14 @@ export default defineComponent({
|
||||
}
|
||||
});
|
||||
|
||||
const changeProject = (projectId: number) => {
|
||||
for (let p of state.projects as any) {
|
||||
if (p.id == projectId) {
|
||||
state.form.projectName = p.name;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const btnOk = async () => {
|
||||
machineForm.value.validate((valid: boolean) => {
|
||||
if (valid) {
|
||||
@@ -171,6 +180,7 @@ export default defineComponent({
|
||||
return {
|
||||
...toRefs(state),
|
||||
machineForm,
|
||||
changeProject,
|
||||
btnOk,
|
||||
cancel,
|
||||
};
|
||||
|
||||
@@ -35,8 +35,20 @@
|
||||
</div>
|
||||
|
||||
<div style="float: right">
|
||||
<el-input placeholder="host" size="mini" style="width: 140px" v-model="params.host" @clear="search" plain clearable></el-input>
|
||||
<el-button @click="search" type="success" icon="el-icon-search" size="mini"></el-button>
|
||||
<el-select size="mini" v-model="params.projectId" placeholder="请选择项目" @clear="search" filterable clearable>
|
||||
<el-option v-for="item in projects" :key="item.id" :label="`${item.name} [${item.remark}]`" :value="item.id"> </el-option>
|
||||
</el-select>
|
||||
<el-input
|
||||
class="ml5"
|
||||
placeholder="ip"
|
||||
size="mini"
|
||||
style="width: 140px"
|
||||
v-model="params.ip"
|
||||
@clear="search"
|
||||
plain
|
||||
clearable
|
||||
></el-input>
|
||||
<el-button class="ml5" @click="search" type="success" icon="el-icon-search" size="mini"></el-button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -54,12 +66,13 @@
|
||||
{{ `${scope.row.ip}:${scope.row.port}` }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="username" label="用户名" min-width="75"></el-table-column>
|
||||
<el-table-column prop="projectName" label="项目" min-width="120"></el-table-column>
|
||||
<el-table-column prop="ip" label="hasCli" width="70">
|
||||
<template #default="scope">
|
||||
{{ `${scope.row.hasCli ? '是' : '否'}` }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="username" label="用户名" min-width="75"></el-table-column>
|
||||
<el-table-column prop="createTime" label="创建时间" width="160">
|
||||
<template #default="scope">
|
||||
{{ $filters.dateFormat(scope.row.createTime) }}
|
||||
@@ -92,6 +105,7 @@
|
||||
|
||||
<machine-edit
|
||||
:title="machineEditDialog.title"
|
||||
:projects="projects"
|
||||
v-model:visible="machineEditDialog.visible"
|
||||
v-model:machine="machineEditDialog.data"
|
||||
@valChange="submitSuccess"
|
||||
@@ -113,6 +127,7 @@ import { useRouter } from 'vue-router';
|
||||
import { ElMessage, ElMessageBox } from 'element-plus';
|
||||
// import Monitor from './Monitor.vue';
|
||||
import { machineApi } from './api';
|
||||
import { projectApi } from '../project/api.ts';
|
||||
import ServiceManage from './ServiceManage.vue';
|
||||
import FileManage from './FileManage.vue';
|
||||
import MachineEdit from './MachineEdit.vue';
|
||||
@@ -127,6 +142,7 @@ export default defineComponent({
|
||||
setup() {
|
||||
const router = useRouter();
|
||||
const state = reactive({
|
||||
projects: [],
|
||||
params: {
|
||||
pageNum: 1,
|
||||
pageSize: 10,
|
||||
@@ -166,8 +182,9 @@ export default defineComponent({
|
||||
},
|
||||
});
|
||||
|
||||
onMounted(() => {
|
||||
onMounted(async () => {
|
||||
search();
|
||||
state.projects = (await projectApi.projects.request({ pageNum: 1, pageSize: 100 })).list;
|
||||
});
|
||||
|
||||
const choose = (item: any) => {
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
<template>
|
||||
<el-dialog :title="keyValue.key" v-model="dialogVisible" :before-close="cancel" :show-close="false" width="800px">
|
||||
<el-dialog :title="keyValue.key" v-model="dialogVisible" :before-close="cancel" :show-close="false" width="900px">
|
||||
<el-form>
|
||||
<el-form-item>
|
||||
<!-- <el-input v-model="keyValue.value" type="textarea" :autosize="{ minRows: 10, maxRows: 20 }" autocomplete="off"></el-input> -->
|
||||
|
||||
|
||||
<el-input class="json-text" v-model="keyValue2.jsonValue" type="textarea" :autosize="{ minRows: 10, maxRows: 20 }"></el-input>
|
||||
</el-form-item>
|
||||
<vue3-json-editor v-model="keyValue2.jsonValue" @json-change="valueChange" :show-btns="false" :expandedOnStart="true" />
|
||||
<!-- <vue3-json-editor v-model="keyValue2.jsonValue" @json-change="valueChange" :show-btns="false" :expandedOnStart="true" /> -->
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<div class="dialog-footer">
|
||||
@@ -21,13 +19,11 @@ import { defineComponent, reactive, watch, toRefs } from 'vue';
|
||||
import { redisApi } from './api';
|
||||
import { ElMessage } from 'element-plus';
|
||||
import { isTrue } from '@/common/assert';
|
||||
import { Vue3JsonEditor } from 'vue3-json-editor';
|
||||
|
||||
|
||||
export default defineComponent({
|
||||
name: 'ValueDialog',
|
||||
components: {
|
||||
Vue3JsonEditor,
|
||||
},
|
||||
components: {},
|
||||
props: {
|
||||
visible: {
|
||||
type: Boolean,
|
||||
@@ -61,9 +57,9 @@ export default defineComponent({
|
||||
(val) => {
|
||||
state.keyValue2 = val;
|
||||
if (typeof val.value == 'string') {
|
||||
state.keyValue2.jsonValue = JSON.parse(val.value)
|
||||
state.keyValue2.jsonValue = JSON.stringify(JSON.parse(val.value), null, 2);
|
||||
} else {
|
||||
state.keyValue2.jsonValue = val.value;
|
||||
state.keyValue2.jsonValue = JSON.stringify(val.value, null, 2);
|
||||
}
|
||||
}
|
||||
);
|
||||
@@ -71,6 +67,7 @@ export default defineComponent({
|
||||
const saveValue = async () => {
|
||||
isTrue(state.keyValue2.type == 'string', '暂不支持除string外其他类型修改');
|
||||
|
||||
state.keyValue2.value = state.keyValue2.jsonValue;
|
||||
await redisApi.saveStringValue.request(state.keyValue2);
|
||||
ElMessage.success('保存成功');
|
||||
cancel();
|
||||
|
||||
@@ -32,7 +32,7 @@ func (d *Db) Dbs(rc *ctx.ReqCtx) {
|
||||
ProjectId: uint64(ginx.QueryInt(g, "projectId", 0)),
|
||||
Database: g.Query("database"),
|
||||
}
|
||||
ginx.BindQuery(g, m)
|
||||
m.CreatorId = rc.LoginAccount.Id
|
||||
rc.ResData = d.DbApp.GetPageList(m, ginx.GetPageParam(rc.GinCtx), new([]vo.SelectDataDbVO))
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,8 @@ package form
|
||||
|
||||
type MachineForm struct {
|
||||
Id uint64 `json:"id"`
|
||||
ProjectId uint64 `json:"projectId"`
|
||||
ProjectName string `json:"projectName"`
|
||||
Name string `json:"name" binding:"required"`
|
||||
// IP地址
|
||||
Ip string `json:"ip" binding:"required"`
|
||||
|
||||
@@ -23,7 +23,18 @@ type Machine struct {
|
||||
}
|
||||
|
||||
func (m *Machine) Machines(rc *ctx.ReqCtx) {
|
||||
res := m.MachineApp.GetMachineList(new(entity.Machine), ginx.GetPageParam(rc.GinCtx), new([]*vo.MachineVO))
|
||||
condition := new(entity.Machine)
|
||||
// 使用创建者id模拟账号成员id
|
||||
condition.CreatorId = rc.LoginAccount.Id
|
||||
condition.Ip = rc.GinCtx.Query("ip")
|
||||
condition.ProjectId = uint64(ginx.QueryInt(rc.GinCtx, "projectId", 0))
|
||||
|
||||
res := m.MachineApp.GetMachineList(condition, ginx.GetPageParam(rc.GinCtx), new([]*vo.MachineVO))
|
||||
if res.Total == 0 {
|
||||
rc.ResData = res
|
||||
return
|
||||
}
|
||||
|
||||
list := res.List.(*[]*vo.MachineVO)
|
||||
for _, mv := range *list {
|
||||
mv.HasCli = machine.HasCli(*mv.Id)
|
||||
|
||||
@@ -23,7 +23,7 @@ func (r *Redis) RedisList(rc *ctx.ReqCtx) {
|
||||
m := &entity.Redis{EnvId: uint64(ginx.QueryInt(g, "envId", 0)),
|
||||
ProjectId: uint64(ginx.QueryInt(g, "projectId", 0)),
|
||||
}
|
||||
ginx.BindQuery(g, m)
|
||||
m.CreatorId = rc.LoginAccount.Id
|
||||
rc.ResData = r.RedisApp.GetPageList(m, ginx.GetPageParam(rc.GinCtx), new([]vo.Redis))
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,8 @@ type AccountVO struct {
|
||||
type MachineVO struct {
|
||||
//models.BaseModel
|
||||
Id *uint64 `json:"id"`
|
||||
ProjectId uint64 `json:"projectId"`
|
||||
ProjectName string `json:"projectName"`
|
||||
Name *string `json:"name"`
|
||||
Username *string `json:"username"`
|
||||
Ip *string `json:"ip"`
|
||||
|
||||
@@ -6,6 +6,8 @@ import (
|
||||
|
||||
type Machine struct {
|
||||
model.Model
|
||||
ProjectId uint64 `json:"projectId"`
|
||||
ProjectName string `json:"projectName"`
|
||||
Name string `json:"name"`
|
||||
// IP地址
|
||||
Ip string `json:"ip"`
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package persistence
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"mayfly-go/base/biz"
|
||||
"mayfly-go/base/model"
|
||||
"mayfly-go/server/devops/domain/entity"
|
||||
@@ -13,7 +14,19 @@ var DbDao repository.Db = &dbRepo{}
|
||||
|
||||
// 分页获取数据库信息列表
|
||||
func (d *dbRepo) GetDbList(condition *entity.Db, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult {
|
||||
return model.GetPage(pageParam, condition, toEntity, orderBy...)
|
||||
sql := "SELECT d.* FROM t_db d JOIN t_project_member pm ON d.project_id = pm.project_id WHERE 1 = 1 "
|
||||
if condition.CreatorId != 0 {
|
||||
// 使用创建者id模拟项目成员id
|
||||
sql = fmt.Sprintf("%s AND pm.account_id = %d", sql, condition.CreatorId)
|
||||
}
|
||||
if condition.ProjectId != 0 {
|
||||
sql = fmt.Sprintf("%s AND d.project_id = %d", sql, condition.ProjectId)
|
||||
}
|
||||
if condition.Host != "" {
|
||||
sql = sql + " AND d.host LIKE '%" + condition.Host + "%'"
|
||||
}
|
||||
sql = sql + " ORDER BY d.create_time DESC"
|
||||
return model.GetPageBySql(sql, pageParam, toEntity)
|
||||
}
|
||||
|
||||
func (d *dbRepo) Count(condition *entity.Db) int64 {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package persistence
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"mayfly-go/base/model"
|
||||
"mayfly-go/server/devops/domain/entity"
|
||||
"mayfly-go/server/devops/domain/repository"
|
||||
@@ -12,7 +13,19 @@ var MachineDao repository.Machine = &machineRepo{}
|
||||
|
||||
// 分页获取机器信息列表
|
||||
func (m *machineRepo) GetMachineList(condition *entity.Machine, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult {
|
||||
return model.GetPage(pageParam, condition, toEntity, orderBy...)
|
||||
sql := "SELECT m.* FROM t_machine m JOIN t_project_member pm ON m.project_id = pm.project_id WHERE 1 = 1 "
|
||||
if condition.CreatorId != 0 {
|
||||
// 使用创建者id模拟项目成员id
|
||||
sql = fmt.Sprintf("%s AND pm.account_id = %d", sql, condition.CreatorId)
|
||||
}
|
||||
if condition.ProjectId != 0 {
|
||||
sql = fmt.Sprintf("%s AND m.project_id = %d", sql, condition.ProjectId)
|
||||
}
|
||||
if condition.Ip != "" {
|
||||
sql = sql + " AND m.ip LIKE '%" + condition.Ip + "%'"
|
||||
}
|
||||
sql = sql + " ORDER BY m.create_time DESC"
|
||||
return model.GetPageBySql(sql, pageParam, toEntity)
|
||||
}
|
||||
|
||||
func (m *machineRepo) Count(condition *entity.Machine) int64 {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package persistence
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"mayfly-go/base/biz"
|
||||
"mayfly-go/base/model"
|
||||
"mayfly-go/server/devops/domain/entity"
|
||||
@@ -13,7 +14,19 @@ var RedisDao repository.Redis = &redisRepo{}
|
||||
|
||||
// 分页获取机器信息列表
|
||||
func (r *redisRepo) GetRedisList(condition *entity.Redis, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult {
|
||||
return model.GetPage(pageParam, condition, toEntity, orderBy...)
|
||||
sql := "SELECT d.* FROM t_redis d JOIN t_project_member pm ON d.project_id = pm.project_id WHERE 1 = 1 "
|
||||
if condition.CreatorId != 0 {
|
||||
// 使用创建者id模拟项目成员id
|
||||
sql = fmt.Sprintf("%s AND pm.account_id = %d", sql, condition.CreatorId)
|
||||
}
|
||||
if condition.ProjectId != 0 {
|
||||
sql = fmt.Sprintf("%s AND d.project_id = %d", sql, condition.ProjectId)
|
||||
}
|
||||
if condition.Host != "" {
|
||||
sql = sql + " AND d.host LIKE '%" + condition.Host + "%'"
|
||||
}
|
||||
sql = sql + " ORDER BY d.create_time DESC"
|
||||
return model.GetPageBySql(sql, pageParam, toEntity)
|
||||
}
|
||||
|
||||
func (r *redisRepo) Count(condition *entity.Redis) int64 {
|
||||
|
||||
Reference in New Issue
Block a user