mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2024-11-27 20:49:03 +08:00
feat: 增加重命名功能
This commit is contained in:
parent
89b95e0d45
commit
04db6a8cf3
@ -154,3 +154,16 @@ func (b *BaseApi) UploadFiles(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
helper.SuccessWithMsg(c, fmt.Sprintf("%d files upload success", success))
|
helper.SuccessWithMsg(c, fmt.Sprintf("%d files upload success", success))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (b *BaseApi) ChangeName(c *gin.Context) {
|
||||||
|
var req dto.FileRename
|
||||||
|
if err := c.ShouldBindJSON(&req); err != nil {
|
||||||
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err := fileService.ChangeName(req); err != nil {
|
||||||
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
helper.SuccessWithData(c, nil)
|
||||||
|
}
|
||||||
|
@ -52,3 +52,8 @@ type FileEdit struct {
|
|||||||
Path string
|
Path string
|
||||||
Content string
|
Content string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type FileRename struct {
|
||||||
|
OldName string
|
||||||
|
NewName string
|
||||||
|
}
|
||||||
|
@ -115,6 +115,11 @@ func (f FileService) SaveContent(c dto.FileEdit) error {
|
|||||||
return fo.WriteFile(c.Path, strings.NewReader(c.Content), info.FileMode)
|
return fo.WriteFile(c.Path, strings.NewReader(c.Content), info.FileMode)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (f FileService) ChangeName(c dto.FileRename) error {
|
||||||
|
fo := files.NewFileOp()
|
||||||
|
return fo.Rename(c.OldName, c.NewName)
|
||||||
|
}
|
||||||
|
|
||||||
func getUuid() string {
|
func getUuid() string {
|
||||||
b := make([]byte, 16)
|
b := make([]byte, 16)
|
||||||
io.ReadFull(rand.Reader, b)
|
io.ReadFull(rand.Reader, b)
|
||||||
|
@ -25,6 +25,7 @@ func (f *FileRouter) InitFileRouter(Router *gin.RouterGroup) {
|
|||||||
fileRouter.POST("/content", baseApi.GetContent)
|
fileRouter.POST("/content", baseApi.GetContent)
|
||||||
fileRouter.POST("/save", baseApi.SaveContent)
|
fileRouter.POST("/save", baseApi.SaveContent)
|
||||||
fileRouter.POST("/upload", baseApi.UploadFiles)
|
fileRouter.POST("/upload", baseApi.UploadFiles)
|
||||||
|
fileRouter.POST("/rename", baseApi.ChangeName)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -77,6 +77,10 @@ func (f FileOp) Chmod(dst string, mode fs.FileMode) error {
|
|||||||
return f.Fs.Chmod(dst, mode)
|
return f.Fs.Chmod(dst, mode)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (f FileOp) Rename(oldName string, newName string) error {
|
||||||
|
return f.Fs.Rename(oldName, newName)
|
||||||
|
}
|
||||||
|
|
||||||
type CompressType string
|
type CompressType string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -64,4 +64,9 @@ export namespace File {
|
|||||||
path: string;
|
path: string;
|
||||||
content: string;
|
content: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface FileRename {
|
||||||
|
oldName: string;
|
||||||
|
newName: string;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -40,3 +40,7 @@ export const SaveFileContent = (params: File.FileEdit) => {
|
|||||||
export const UploadFileData = (params: FormData) => {
|
export const UploadFileData = (params: FormData) => {
|
||||||
return http.post<File.File>('files/upload', params);
|
return http.post<File.File>('files/upload', params);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const RenameRile = (params: File.FileRename) => {
|
||||||
|
return http.post<File.File>('files/rename', params);
|
||||||
|
};
|
||||||
|
@ -152,11 +152,6 @@ const changeMode = (val: String) => {
|
|||||||
getRoleNum(val[3], form.value.public);
|
getRoleNum(val[3], form.value.public);
|
||||||
};
|
};
|
||||||
|
|
||||||
// onMounted(() => {
|
|
||||||
// form.value.mode = mode.value;
|
|
||||||
// changeMode(form.value.mode);
|
|
||||||
// });
|
|
||||||
|
|
||||||
onUpdated(() => {
|
onUpdated(() => {
|
||||||
form.value.mode = mode.value;
|
form.value.mode = mode.value;
|
||||||
changeMode(form.value.mode);
|
changeMode(form.value.mode);
|
||||||
|
@ -32,6 +32,7 @@ export default {
|
|||||||
sureLogOut: 'Are you sure you want to log out?',
|
sureLogOut: 'Are you sure you want to log out?',
|
||||||
createSuccess: 'Create Success',
|
createSuccess: 'Create Success',
|
||||||
updateSuccess: 'Update Success',
|
updateSuccess: 'Update Success',
|
||||||
|
uploadSuccess: 'Update Success',
|
||||||
},
|
},
|
||||||
login: {
|
login: {
|
||||||
captchaHelper: 'Please enter the verification code',
|
captchaHelper: 'Please enter the verification code',
|
||||||
|
@ -32,6 +32,7 @@ export default {
|
|||||||
sureLogOut: '您是否确认退出登录?',
|
sureLogOut: '您是否确认退出登录?',
|
||||||
createSuccess: '新建成功',
|
createSuccess: '新建成功',
|
||||||
updateSuccess: '更新成功',
|
updateSuccess: '更新成功',
|
||||||
|
uploadSuccess: '上传成功',
|
||||||
},
|
},
|
||||||
login: {
|
login: {
|
||||||
captchaHelper: '请输入验证码',
|
captchaHelper: '请输入验证码',
|
||||||
|
95
frontend/src/views/file-management/file-rename/index.vue
Normal file
95
frontend/src/views/file-management/file-rename/index.vue
Normal file
@ -0,0 +1,95 @@
|
|||||||
|
<template>
|
||||||
|
<el-dialog
|
||||||
|
v-model="open"
|
||||||
|
:before-close="handleClose"
|
||||||
|
:title="$t('file.setRole')"
|
||||||
|
width="30%"
|
||||||
|
@open="onOpen"
|
||||||
|
v-loading="loading"
|
||||||
|
>
|
||||||
|
<el-form ref="fileForm" label-position="left" :model="addForm" label-width="100px" :rules="rules">
|
||||||
|
<el-form-item :label="$t('file.path')" prop="path">
|
||||||
|
<el-input v-model="props.path" disabled
|
||||||
|
/></el-form-item>
|
||||||
|
<el-form-item :label="$t('file.name')" prop="newName"> <el-input v-model="addForm.newName" /></el-form-item
|
||||||
|
></el-form>
|
||||||
|
<template #footer>
|
||||||
|
<span class="dialog-footer">
|
||||||
|
<el-button @click="handleClose">{{ $t('commons.button.cancel') }}</el-button>
|
||||||
|
<el-button type="primary" @click="submit(fileForm)">{{ $t('commons.button.confirm') }}</el-button>
|
||||||
|
</span>
|
||||||
|
</template>
|
||||||
|
</el-dialog>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script lang="ts" setup>
|
||||||
|
import { RenameRile } from '@/api/modules/files';
|
||||||
|
import { Rules } from '@/global/form-rues';
|
||||||
|
import { ElMessage, FormInstance, FormRules } from 'element-plus';
|
||||||
|
import { reactive, ref, toRefs } from 'vue';
|
||||||
|
import { File } from '@/api/interface/file';
|
||||||
|
import i18n from '@/lang';
|
||||||
|
|
||||||
|
const props = defineProps({
|
||||||
|
open: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false,
|
||||||
|
},
|
||||||
|
oldName: {
|
||||||
|
type: String,
|
||||||
|
default: '',
|
||||||
|
},
|
||||||
|
path: {
|
||||||
|
type: String,
|
||||||
|
default: '',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const { open } = toRefs(props);
|
||||||
|
const fileForm = ref<FormInstance>();
|
||||||
|
const loading = ref(false);
|
||||||
|
|
||||||
|
const addForm = reactive({
|
||||||
|
newName: '',
|
||||||
|
path: '',
|
||||||
|
});
|
||||||
|
|
||||||
|
const rules = reactive<FormRules>({
|
||||||
|
newName: [Rules.requiredInput],
|
||||||
|
});
|
||||||
|
|
||||||
|
const em = defineEmits(['close']);
|
||||||
|
const handleClose = () => {
|
||||||
|
em('close', false);
|
||||||
|
};
|
||||||
|
|
||||||
|
const getPath = (path: string, name: string) => {
|
||||||
|
return path + '/' + name;
|
||||||
|
};
|
||||||
|
const submit = async (formEl: FormInstance | undefined) => {
|
||||||
|
if (!formEl) return;
|
||||||
|
await formEl.validate((valid) => {
|
||||||
|
if (!valid) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let addItem = {};
|
||||||
|
Object.assign(addItem, addForm);
|
||||||
|
addItem['oldName'] = getPath(props.path, props.oldName);
|
||||||
|
addItem['newName'] = getPath(props.path, addForm.newName);
|
||||||
|
loading.value = true;
|
||||||
|
RenameRile(addItem as File.FileRename)
|
||||||
|
.then(() => {
|
||||||
|
ElMessage.success(i18n.global.t('commons.msg.updateSuccess'));
|
||||||
|
handleClose();
|
||||||
|
})
|
||||||
|
.finally(() => {
|
||||||
|
loading.value = false;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const onOpen = () => {
|
||||||
|
addForm.newName = props.oldName;
|
||||||
|
};
|
||||||
|
</script>
|
@ -124,6 +124,12 @@
|
|||||||
@qsave="quickSave"
|
@qsave="quickSave"
|
||||||
@save="saveContent"
|
@save="saveContent"
|
||||||
></CodeEditor>
|
></CodeEditor>
|
||||||
|
<FileRename
|
||||||
|
:open="renamePage.open"
|
||||||
|
:path="renamePage.path"
|
||||||
|
:oldName="renamePage.oldName"
|
||||||
|
@close="closeRename"
|
||||||
|
></FileRename>
|
||||||
<Upload :open="uploadPage.open" :path="uploadPage.path" @close="closeUpload"></Upload>
|
<Upload :open="uploadPage.open" :path="uploadPage.path" @close="closeUpload"></Upload>
|
||||||
</el-row>
|
</el-row>
|
||||||
</LayoutContent>
|
</LayoutContent>
|
||||||
@ -144,6 +150,7 @@ import ChangeRole from './change-role/index.vue';
|
|||||||
import Compress from './compress/index.vue';
|
import Compress from './compress/index.vue';
|
||||||
import Decompress from './decompress/index.vue';
|
import Decompress from './decompress/index.vue';
|
||||||
import Upload from './upload/index.vue';
|
import Upload from './upload/index.vue';
|
||||||
|
import FileRename from './file-rename/index.vue';
|
||||||
import { useDeleteData } from '@/hooks/use-delete-data';
|
import { useDeleteData } from '@/hooks/use-delete-data';
|
||||||
import CodeEditor from './code-editor/index.vue';
|
import CodeEditor from './code-editor/index.vue';
|
||||||
import { ElMessage } from 'element-plus';
|
import { ElMessage } from 'element-plus';
|
||||||
@ -157,13 +164,14 @@ let paths = ref<string[]>([]);
|
|||||||
let fileTree = ref<File.FileTree[]>([]);
|
let fileTree = ref<File.FileTree[]>([]);
|
||||||
let expandKeys = ref<string[]>([]);
|
let expandKeys = ref<string[]>([]);
|
||||||
|
|
||||||
let filePage = reactive({ open: false, createForm: { path: '/', isDir: false, mode: 0o755 } });
|
const filePage = reactive({ open: false, createForm: { path: '/', isDir: false, mode: 0o755 } });
|
||||||
let modePage = reactive({ open: false, modeForm: { path: '/', isDir: false, mode: 0o755 } });
|
const modePage = reactive({ open: false, modeForm: { path: '/', isDir: false, mode: 0o755 } });
|
||||||
let compressPage = reactive({ open: false, files: [''], name: '', dst: '' });
|
const compressPage = reactive({ open: false, files: [''], name: '', dst: '' });
|
||||||
let deCompressPage = reactive({ open: false, path: '', name: '', dst: '', mimeType: '' });
|
const deCompressPage = reactive({ open: false, path: '', name: '', dst: '', mimeType: '' });
|
||||||
let editorPage = reactive({ open: false, content: '', loading: false });
|
const editorPage = reactive({ open: false, content: '', loading: false });
|
||||||
let codeReq = reactive({ path: '', expand: false });
|
const codeReq = reactive({ path: '', expand: false });
|
||||||
const uploadPage = reactive({ open: false, path: '' });
|
const uploadPage = reactive({ open: false, path: '' });
|
||||||
|
const renamePage = reactive({ open: false, path: '', oldName: '' });
|
||||||
|
|
||||||
const defaultProps = {
|
const defaultProps = {
|
||||||
children: 'children',
|
children: 'children',
|
||||||
@ -338,6 +346,17 @@ const closeUpload = () => {
|
|||||||
search(req);
|
search(req);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const openRename = (item: File.File) => {
|
||||||
|
renamePage.open = true;
|
||||||
|
renamePage.path = req.path;
|
||||||
|
renamePage.oldName = item.name;
|
||||||
|
};
|
||||||
|
|
||||||
|
const closeRename = () => {
|
||||||
|
renamePage.open = false;
|
||||||
|
search(req);
|
||||||
|
};
|
||||||
|
|
||||||
const saveContent = (content: string) => {
|
const saveContent = (content: string) => {
|
||||||
editorPage.loading = true;
|
editorPage.loading = true;
|
||||||
SaveFileContent({ path: codeReq.path, content: content }).finally(() => {
|
SaveFileContent({ path: codeReq.path, content: content }).finally(() => {
|
||||||
@ -380,6 +399,7 @@ const buttons = [
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: i18n.global.t('file.rename'),
|
label: i18n.global.t('file.rename'),
|
||||||
|
click: openRename,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: i18n.global.t('commons.button.delete'),
|
label: i18n.global.t('commons.button.delete'),
|
||||||
|
Loading…
Reference in New Issue
Block a user