feat: 修改文件选择组件

This commit is contained in:
zhengkunwang223 2023-02-09 14:31:05 +08:00 committed by zhengkunwang223
parent 405db20980
commit b002614759
23 changed files with 77 additions and 58 deletions

View File

@ -4,6 +4,8 @@ import (
"fmt"
"github.com/1Panel-dev/1Panel/backend/app/dto/request"
"github.com/1Panel-dev/1Panel/backend/app/dto/response"
"github.com/1Panel-dev/1Panel/backend/buserr"
"github.com/1Panel-dev/1Panel/backend/constant"
"io/fs"
"os"
"path/filepath"
@ -57,7 +59,6 @@ func (f FileService) GetFileTree(op request.FileOption) ([]response.FileTree, er
}
func (f FileService) Create(op request.FileCreate) error {
fo := files.NewFileOp()
if fo.Stat(op.Path) {
return errors.New("file is exist")
@ -154,6 +155,10 @@ func (f FileService) Wget(w request.FileWget) (string, error) {
func (f FileService) MvFile(m request.FileMove) error {
fo := files.NewFileOp()
if !fo.Stat(m.NewPath) {
return buserr.New(constant.ErrPathNotFound)
}
if m.Type == "cut" {
return fo.Cut(m.OldPaths, m.NewPath)
}

View File

@ -70,3 +70,8 @@ var (
ErrAccountCannotDelete = "ErrAccountCannotDelete"
ErrSSLApply = "ErrSSLApply"
)
//file
var (
ErrPathNotFound = "ErrPathNotFound"
)

View File

@ -23,10 +23,10 @@ ErrAppRequired: "{{ .detail }} app is required"
ErrNotInstall: "App not installed"
ErrPortInOtherApp: "{{ .port }} port already in use by {{ .apps }}"
#file
ErrFileCanNotRead: "File can not read"
ErrFileToLarge: "file is too large"
ErrPathNotFound: "Path is not found"
#website
ErrDomainIsExist: "Domain is already exist"

View File

@ -26,6 +26,7 @@ ErrPortInOtherApp: "{{ .port }} 端口已被 {{ .apps }}占用!"
#file
ErrFileCanNotRead: "此文件不支持预览"
ErrFileToLarge: "文件超过10M,无法打开"
ErrPathNotFound: "目录不存在"
#website
ErrDomainIsExist: "域名已存在"

View File

@ -59,6 +59,7 @@ declare module 'vue' {
ElRow: typeof import('element-plus/es')['ElRow']
ElScrollbar: typeof import('element-plus/es')['ElScrollbar']
ElSelect: typeof import('element-plus/es')['ElSelect']
ElSpan: typeof import('element-plus/es')['ElSpan']
ElSubMenu: typeof import('element-plus/es')['ElSubMenu']
ElSwitch: typeof import('element-plus/es')['ElSwitch']
ElTable: typeof import('element-plus/es')['ElTable']

View File

@ -1,5 +1,5 @@
<template>
<el-drawer :close-on-click-modal="false" v-model="open" size="30%">
<el-drawer :close-on-click-modal="false" v-model="open" size="40%">
<template #header>
<Header :header="$t('commons.msg.operate')" :resource="resourceName" :back="handleClose"></Header>
</template>

View File

@ -19,11 +19,10 @@
</el-form-item>
<el-form-item v-if="form.from === 'path'" prop="path">
<el-input
disabled
:placeholder="$t('commons.example') + '/tmp/docker-compose.yml'"
v-model="form.path"
>
<template #append>
<template #prepend>
<FileList @choose="loadDir" :dir="false"></FileList>
</template>
</el-input>

View File

@ -1,5 +1,5 @@
<template>
<el-drawer v-model="newNameVisiable" :destroy-on-close="true" :close-on-click-modal="false" size="30%">
<el-drawer v-model="newNameVisiable" :destroy-on-close="true" :close-on-click-modal="false" size="40%">
<template #header>
<DrawerHeader :header="$t('container.rename')" :back="handleClose" />
</template>

View File

@ -39,7 +39,7 @@
</el-form-item>
<el-form-item v-else :rules="Rules.requiredSelect" prop="dockerfile">
<el-input clearable v-model="form.dockerfile">
<template #append>
<template #prepend>
<FileList @choose="loadBuildDir" :dir="true"></FileList>
</template>
</el-input>

View File

@ -1,12 +1,12 @@
<template>
<el-drawer v-model="loadVisiable" :destroy-on-close="true" :close-on-click-modal="false" size="30%">
<el-drawer v-model="loadVisiable" :destroy-on-close="true" :close-on-click-modal="false" size="40%">
<template #header>
<DrawerHeader :header="$t('container.importImage')" :back="handleClose" />
</template>
<el-form v-loading="loading" ref="formRef" :model="form" label-position="top">
<el-form-item :label="$t('container.path')" :rules="Rules.requiredSelect" prop="path">
<el-input disabled v-model="form.path">
<template #append>
<el-input v-model="form.path">
<template #prepend>
<FileList @choose="loadLoadDir" :dir="false"></FileList>
</template>
</el-input>

View File

@ -18,8 +18,8 @@
</el-select>
</el-form-item>
<el-form-item :label="$t('container.path')" :rules="Rules.requiredSelect" prop="path">
<el-input disabled v-model="form.path">
<template #append>
<el-input v-model="form.path">
<template #prepend>
<FileList @choose="loadSaveDir" :dir="true"></FileList>
</template>
</el-input>

View File

@ -93,8 +93,8 @@
:label="$t('cronjob.sourceDir')"
prop="sourceDir"
>
<el-input style="width: 100%" disabled v-model="dialogData.rowData!.sourceDir">
<template #append>
<el-input style="width: 100%" v-model="dialogData.rowData!.sourceDir">
<template #prepend>
<FileList @choose="loadDir" :dir="true"></FileList>
</template>
</el-input>

View File

@ -1,5 +1,5 @@
<template>
<el-drawer v-model="dialogVisiable" :destroy-on-close="true" :close-on-click-modal="false" size="30%">
<el-drawer v-model="dialogVisiable" :destroy-on-close="true" :close-on-click-modal="false" size="40%">
<template #header>
<DrawerHeader :header="$t('database.remoteAccess')" :back="handleClose" />
</template>

View File

@ -1,5 +1,5 @@
<template>
<el-drawer v-model="dialogVisiable" :destroy-on-close="true" :close-on-click-modal="false" size="30%">
<el-drawer v-model="dialogVisiable" :destroy-on-close="true" :close-on-click-modal="false" size="40%">
<template #header>
<DrawerHeader :header="$t('database.rootPassword')" :back="handleClose" />
</template>

View File

@ -30,8 +30,8 @@
</el-input>
</el-form-item>
<el-form-item :label="$t('file.compressDst')" prop="dst">
<el-input v-model="form.dst" disabled>
<template #append><FileList :path="form.dst" @choose="getLinkPath"></FileList></template>
<el-input v-model="form.dst">
<template #prepend><FileList :path="form.dst" @choose="getLinkPath"></FileList></template>
</el-input>
</el-form-item>
<el-form-item>

View File

@ -37,7 +37,7 @@
</el-form-item>
<el-form-item v-if="addForm.isLink" :label="$t('file.linkPath')" prop="linkPath">
<el-input v-model="addForm.linkPath">
<template #append>
<template #prepend>
<FileList @choose="getLinkPath"></FileList>
</template>
</el-input>

View File

@ -4,28 +4,32 @@
:destroy-on-close="true"
:close-on-click-modal="false"
:before-close="handleClose"
size="30%"
size="40%"
>
<template #header>
<DrawerHeader :header="$t('file.deCompress')" :back="handleClose" />
</template>
<el-form
ref="fileForm"
label-position="left"
:model="form"
label-width="100px"
:rules="rules"
v-loading="loading"
>
<el-form-item :label="$t('file.name')">
<el-input v-model="name" disabled></el-input>
</el-form-item>
<el-form-item :label="$t('file.deCompressDst')" prop="dst">
<el-input v-model="form.dst" disabled>
<template #append><FileList :path="form.dst" @choose="getLinkPath"></FileList></template>
</el-input>
</el-form-item>
</el-form>
<el-row>
<el-col :span="22" :offset="1">
<el-form
ref="fileForm"
label-position="top"
:model="form"
label-width="100px"
:rules="rules"
v-loading="loading"
>
<el-form-item :label="$t('file.name')">
<el-input v-model="name" disabled></el-input>
</el-form-item>
<el-form-item :label="$t('file.deCompressDst')" prop="dst">
<el-input v-model="form.dst">
<template #prepend><FileList :path="form.dst" @choose="getLinkPath"></FileList></template>
</el-input>
</el-form-item>
</el-form>
</el-col>
</el-row>
<template #footer>
<span class="dialog-footer">
<el-button @click="handleClose">{{ $t('commons.button.cancel') }}</el-button>

View File

@ -5,7 +5,7 @@
:destroy-on-close="true"
:close-on-click-modal="false"
:before-close="handleClose"
size="30%"
size="40%"
>
<template #header>
<DrawerHeader :header="$t('file.download')" :back="handleClose" />

View File

@ -4,25 +4,29 @@
:destroy-on-close="true"
:close-on-click-modal="false"
:before-close="handleClose"
size="30%"
size="40%"
>
<template #header>
<DrawerHeader :header="title" :back="handleClose" />
</template>
<el-form
ref="fileForm"
label-position="left"
:model="addForm"
label-width="100px"
:rules="rules"
v-loading="loading"
>
<el-form-item :label="$t('file.path')" prop="newPath">
<el-input v-model="addForm.newPath" disabled>
<template #append><FileList @choose="getPath" :dir="true"></FileList></template>
</el-input>
</el-form-item>
</el-form>
<el-row>
<el-col :span="22" :offset="1">
<el-form
ref="fileForm"
label-position="top"
:model="addForm"
label-width="100px"
:rules="rules"
v-loading="loading"
>
<el-form-item :label="$t('file.path')" prop="newPath">
<el-input v-model="addForm.newPath">
<template #prepend><FileList @choose="getPath" :dir="true"></FileList></template>
</el-input>
</el-form-item>
</el-form>
</el-col>
</el-row>
<template #footer>
<span class="dialog-footer">
<el-button @click="handleClose" :disabled="loading">{{ $t('commons.button.cancel') }}</el-button>

View File

@ -1,5 +1,5 @@
<template>
<el-drawer v-model="open" :before-close="handleClose" :title="$t('file.rename')" size="30%">
<el-drawer v-model="open" :before-close="handleClose" :title="$t('file.rename')" size="40%">
<el-row>
<el-col :span="22" :offset="1">
<el-form

View File

@ -17,8 +17,8 @@
<el-input v-model="addForm.url" @input="getFileName" />
</el-form-item>
<el-form-item :label="$t('file.path')" prop="path">
<el-input v-model="addForm.path" disabled>
<template #append><FileList :path="addForm.path" @choose="getPath"></FileList></template>
<el-input v-model="addForm.path">
<template #prepend><FileList :path="addForm.path" @choose="getPath"></FileList></template>
</el-input>
</el-form-item>
<el-form-item :label="$t('file.name')" prop="name">

View File

@ -17,7 +17,7 @@
prop="varsJson['dir']"
:rules="Rules.requiredInput"
>
<el-input disabled v-model="dialogData.rowData!.varsJson['dir']">
<el-input v-model="dialogData.rowData!.varsJson['dir']">
<template #append>
<FileList @choose="loadDir" :dir="true"></FileList>
</template>

View File

@ -1,5 +1,5 @@
<template>
<el-drawer :close-on-click-modal="false" v-model="open" size="30%">
<el-drawer :close-on-click-modal="false" v-model="open" size="40%">
<template #header>
<DrawerHeader :header="$t('website.defaulServer')" :back="handleClose"></DrawerHeader>
</template>