-
Notifications
You must be signed in to change notification settings - Fork 472
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
165 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Zhiyi\Plus\Admin\Controllers\FileStorage; | ||
|
||
use Illuminate\Http\Request; | ||
use Illuminate\Http\Response; | ||
use function Zhiyi\Plus\setting; | ||
use Illuminate\Http\JsonResponse; | ||
use Symfony\Component\HttpKernel\Exception\UnprocessableEntityHttpException; | ||
|
||
class DefaultFilesystem | ||
{ | ||
/** | ||
* Get default filesystem. | ||
* @return \Illuminate\Http\JsonResponse | ||
*/ | ||
public function show(): JsonResponse | ||
{ | ||
$defaultFilesystem = setting('file-storage', 'default-filesystem', 'local'); | ||
|
||
return new JsonResponse(['filesystem' => $defaultFilesystem], Response::HTTP_OK); | ||
} | ||
|
||
/** | ||
* Update default filesystem. | ||
* @param \Illuminate\Http\Request $request | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function update(Request $request): Response | ||
{ | ||
$filesystem = $request->input('filesystem'); | ||
if (! in_array($filesystem, ['local', 'AliyunOSS'])) { | ||
throw new UnprocessableEntityHttpException('设置的文件系统不合法'); | ||
} | ||
|
||
$setting = setting('file-storage'); | ||
$setting->set('default-filesystem', $filesystem); | ||
|
||
return new Response('', Response::HTTP_NO_CONTENT); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
resources/assets/admin/pages/file-storage/filesystems-component/default.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
<template> | ||
<div class="panel panel-default"> | ||
<div class="panel-heading">默认文件系统</div> | ||
<div class="panel-body"> | ||
<div class="alert alert-warning"> | ||
默认文件系统是用于在<code>频道</code>没有指定文件系统时候使用的默认文件系统。 | ||
</div> | ||
|
||
<sb-ui-loading v-if="loading" /> | ||
|
||
<div class="form-horizontal" v-else> | ||
<div class="form-group"> | ||
<label class="col-sm-2 control-label">文件系统</label> | ||
<div class="col-sm-10"> | ||
<select class="form-control" v-model="selected"> | ||
<option | ||
v-for="filesystem in filesystems" | ||
:key="filesystem.value" | ||
:value="filesystem.value" | ||
> | ||
{{ filesystem.name }} | ||
</option> | ||
</select> | ||
</div> | ||
</div> | ||
|
||
<!-- 提交按钮 --> | ||
<div class="form-group"> | ||
<div class="col-sm-10 col-sm-offset-2"> | ||
<ui-button type="button" class="btn btn-primary" @click="submitHandler" /> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
</div> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
import request, { createRequestURI } from '../../../util/request'; | ||
export default { | ||
data: () => ({ | ||
selected: 'local', | ||
loading: true, | ||
filesystems: [ | ||
{ value: 'local', name: '本地存储' }, | ||
{ value: 'AliyunOSS', name: '阿里云 OSS' }, | ||
] | ||
}), | ||
created() { | ||
this.loading = true; | ||
request.get( | ||
createRequestURI('file-storage/default-filesystem'), | ||
{ | ||
validateStatus: status => status === 200 | ||
} | ||
) | ||
.then(({ data: { filesystem } }) => { | ||
this.selected = filesystem; | ||
this.loading = false; | ||
}) | ||
.catch(({ response: { data: message = "获取默认文件系统设置失败,请检查网络或者刷新页面重试" } }) => { | ||
this.$store.dispatch("alert-open", { type: "danger", message }); | ||
}); | ||
}, | ||
methods: { | ||
submitHandler({ stopProcessing }) { | ||
request.patch( | ||
createRequestURI('file-storage/default-filesystem'), | ||
{ | ||
filesystem: this.selected | ||
}, | ||
{ | ||
validateStatus: status => status === 204, | ||
} | ||
) | ||
.then(() => { | ||
this.$store.dispatch("alert-open", { | ||
type: "success", | ||
message: "更新成功!" | ||
}); | ||
}) | ||
.catch(({ response: { data: message = "提交失败!" } }) => { | ||
this.$store.dispatch("alert-open", { type: "danger", message }); | ||
}) | ||
.finally(stopProcessing); | ||
} | ||
} | ||
} | ||
</script> | ||
|
1 change: 1 addition & 0 deletions
1
resources/assets/admin/pages/file-storage/filesystems-component/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from './wrap'; |
15 changes: 15 additions & 0 deletions
15
resources/assets/admin/pages/file-storage/filesystems-component/wrap.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<template> | ||
<div class="container-fluid"> | ||
<default-filesystem-panel /> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
import DefaultFilesystemPanel from './default'; | ||
export default { | ||
components: { | ||
DefaultFilesystemPanel | ||
} | ||
} | ||
</script> | ||
|
2 changes: 1 addition & 1 deletion
2
resources/assets/admin/pages/file-storage/home-component/file-size.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export { default as WrapComponent } from './wrap-component'; | ||
export { default as HomeComponent } from './home-component'; | ||
export { default as FilesystemsComponent } from './filesystems-component'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters