feat: 文件支持批量移动
This commit is contained in:
parent
d0438390cc
commit
305af935a7
@ -317,11 +317,11 @@ class FileController extends AbstractController
|
|||||||
* @apiSuccess {String} msg 返回信息(错误描述)
|
* @apiSuccess {String} msg 返回信息(错误描述)
|
||||||
* @apiSuccess {Object} data 返回数据
|
* @apiSuccess {Object} data 返回数据
|
||||||
*/
|
*/
|
||||||
public function move()
|
public function move($id = 0)
|
||||||
{
|
{
|
||||||
$user = User::auth();
|
$user = User::auth();
|
||||||
//
|
//
|
||||||
$id = intval(Request::input('id'));
|
$id = empty($id) ? intval(Request::input('id')) : $id;
|
||||||
$pid = intval(Request::input('pid'));
|
$pid = intval(Request::input('pid'));
|
||||||
//
|
//
|
||||||
$file = File::permissionFind($id, 1000);
|
$file = File::permissionFind($id, 1000);
|
||||||
@ -347,6 +347,44 @@ class FileController extends AbstractController
|
|||||||
return Base::retSuccess('操作成功', $file);
|
return Base::retSuccess('操作成功', $file);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @api {get} api/file/batch/move 批量移动文件
|
||||||
|
*
|
||||||
|
* @apiDescription 需要token身份
|
||||||
|
* @apiVersion 1.0.0
|
||||||
|
* @apiGroup file
|
||||||
|
* @apiName batch__move
|
||||||
|
*
|
||||||
|
* @apiParam {Array} ids 文件ID
|
||||||
|
*
|
||||||
|
* @apiSuccess {Number} ret 返回状态码(1正确、0错误)
|
||||||
|
* @apiSuccess {String} msg 返回信息(错误描述)
|
||||||
|
* @apiSuccess {Object} data 返回数据
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function batch__move(): array
|
||||||
|
{
|
||||||
|
$ids = Request::input('ids');
|
||||||
|
if ( empty($ids) || !is_array($ids) ) {
|
||||||
|
return Base::retError("请选择要移动的文件");
|
||||||
|
}
|
||||||
|
// 去重
|
||||||
|
$ids = array_unique($ids);
|
||||||
|
$data = [];
|
||||||
|
// 暂时不考虑异步
|
||||||
|
AbstractModel::transaction( function () use ($ids, &$data) {
|
||||||
|
foreach ($ids as $id) {
|
||||||
|
$res = $this->move($id);
|
||||||
|
if ( Base::isError($res) )
|
||||||
|
throw new ApiException($res["msg"]);
|
||||||
|
|
||||||
|
$data[] = $res["data"];
|
||||||
|
}
|
||||||
|
} );
|
||||||
|
return Base::retSuccess('操作成功', $data);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @api {get} api/file/remove 07. 删除文件(夹)
|
* @api {get} api/file/remove 07. 删除文件(夹)
|
||||||
*
|
*
|
||||||
@ -397,7 +435,7 @@ class FileController extends AbstractController
|
|||||||
}
|
}
|
||||||
$task = new BatchRemoveFileTask($ids, User::userid());
|
$task = new BatchRemoveFileTask($ids, User::userid());
|
||||||
Task::deliver($task);
|
Task::deliver($task);
|
||||||
return Base::retSuccess('success');
|
return Base::retSuccess('操作成功');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -37,7 +37,25 @@
|
|||||||
"<em>{{shearFile.name}}</em>"
|
"<em>{{shearFile.name}}</em>"
|
||||||
</div>
|
</div>
|
||||||
</Button>
|
</Button>
|
||||||
<Button v-if="selectFile.length > 0" size="small" type="error" @click="deleteSelectFile">删除</Button>
|
<Button v-if="shearFiles.length > 0" :disabled="shearFiles[0].pid == pid" size="small" type="primary" @click="batchShearTo">
|
||||||
|
<div class="file-shear">
|
||||||
|
<span>{{$L('粘贴')}}</span>
|
||||||
|
"<em>{{shearFiles[0].name}}</em>"
|
||||||
|
<span v-if="shearFiles.length > 1">{{$L('等')}}{{shearFiles.length}}{{$L('个文件')}}</span>
|
||||||
|
</div>
|
||||||
|
</Button>
|
||||||
|
<template v-if="selectFile.length > 0 && shearFiles.length <= 0">
|
||||||
|
<Tooltip :content="$L('仅支持移动文件')">
|
||||||
|
<Button
|
||||||
|
size="small" type="info"
|
||||||
|
@click="handleContextClick('batchShear')">{{$L('剪切')}}
|
||||||
|
</Button>
|
||||||
|
</Tooltip>
|
||||||
|
<Button
|
||||||
|
size="small" type="error"
|
||||||
|
@click="deleteSelectFile">{{$L('删除')}}
|
||||||
|
</Button>
|
||||||
|
</template>
|
||||||
<div v-if="loadIng > 0" class="nav-load"><Loading/></div>
|
<div v-if="loadIng > 0" class="nav-load"><Loading/></div>
|
||||||
<div class="flex-full"></div>
|
<div class="flex-full"></div>
|
||||||
<div :class="['switch-button', tableMode ? 'table' : '']" @click="tableMode=!tableMode">
|
<div :class="['switch-button', tableMode ? 'table' : '']" @click="tableMode=!tableMode">
|
||||||
@ -439,6 +457,7 @@ export default {
|
|||||||
|
|
||||||
selectFile: [],
|
selectFile: [],
|
||||||
fileChecked: [],
|
fileChecked: [],
|
||||||
|
shearFiles: [],
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -906,6 +925,14 @@ export default {
|
|||||||
this.shearId = item.id;
|
this.shearId = item.id;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'batchShear':
|
||||||
|
// 排除目录
|
||||||
|
for (const item of this.selectFile) {
|
||||||
|
if (item.type !== 'folder')
|
||||||
|
this.shearFiles.push(item);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
case 'share':
|
case 'share':
|
||||||
this.shareInfo = {
|
this.shareInfo = {
|
||||||
id: item.id,
|
id: item.id,
|
||||||
@ -1279,6 +1306,8 @@ export default {
|
|||||||
|
|
||||||
handleTableSelect(selection, row) {
|
handleTableSelect(selection, row) {
|
||||||
this.selectFile = selection;
|
this.selectFile = selection;
|
||||||
|
// 需要清空剪切的文件
|
||||||
|
this.shearFiles = [];
|
||||||
},
|
},
|
||||||
|
|
||||||
deleteSelectFile() {
|
deleteSelectFile() {
|
||||||
@ -1302,6 +1331,7 @@ export default {
|
|||||||
}).then(() => {
|
}).then(() => {
|
||||||
this.$Modal.remove();
|
this.$Modal.remove();
|
||||||
this.selectFile = [];
|
this.selectFile = [];
|
||||||
|
this.fileChecked = [];
|
||||||
$A.messageSuccess("已提交至后台处理,请稍后再回来查看结果吧");
|
$A.messageSuccess("已提交至后台处理,请稍后再回来查看结果吧");
|
||||||
}).catch(({msg}) => {
|
}).catch(({msg}) => {
|
||||||
$A.modalError(msg, 301);
|
$A.modalError(msg, 301);
|
||||||
@ -1326,7 +1356,33 @@ export default {
|
|||||||
if (index >= 0)
|
if (index >= 0)
|
||||||
this.selectFile.splice(index, 1);
|
this.selectFile.splice(index, 1);
|
||||||
}
|
}
|
||||||
}
|
// 需要清空剪切的文件
|
||||||
|
this.shearFiles = [];
|
||||||
|
},
|
||||||
|
batchShearTo() {
|
||||||
|
if (!this.shearFiles) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.$store.dispatch("call", {
|
||||||
|
url: 'file/batch/move',
|
||||||
|
data: {
|
||||||
|
ids: this.shearFiles.map( (item,index) => item.id ),
|
||||||
|
pid: this.pid,
|
||||||
|
},
|
||||||
|
}).then(({data, msg}) => {
|
||||||
|
$A.messageSuccess(msg);
|
||||||
|
// 清空数据
|
||||||
|
this.shearId = 0;
|
||||||
|
this.shearFiles = [];
|
||||||
|
this.selectFile = [];
|
||||||
|
this.fileChecked = [];
|
||||||
|
for (const item of data) {
|
||||||
|
this.$store.dispatch("saveFile", item);
|
||||||
|
}
|
||||||
|
}).catch(({msg}) => {
|
||||||
|
$A.modalError(msg);
|
||||||
|
});
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user