Skip to content

Commit

Permalink
feat(admin): 完成公开频道设置面板
Browse files Browse the repository at this point in the history
  • Loading branch information
medz committed Sep 5, 2018
1 parent f06b755 commit 70ad60e
Show file tree
Hide file tree
Showing 10 changed files with 185 additions and 3 deletions.
48 changes: 48 additions & 0 deletions app/Admin/Controllers/FileStorage/PublicChannel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?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 PublicChannel
{
/**
* Get public channel settings.
* @return \Illuminate\Http\JsonResponse
*/
public function show(): JsonResponse
{
$configure = setting('file-storage', 'channels.public', []);
$result = [
'filesystem' => $configure['filesystem'] ?? '',
];

return new JsonResponse($result, Response::HTTP_OK);
}

/**
* Update public channel settings.
* @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('channels.public', [
'filesystem' => $filesystem,
]);

return new Response('', Response::HTTP_NO_CONTENT);
}
}
2 changes: 1 addition & 1 deletion app/FileStorage/ChannelManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function getDefaultDriver()
protected function createPublicDriver(): ChannelInterface
{
$filesystem = $this->filesystemManager->driver(
setting('file-storage', 'channels.public')['filesystem']
setting('file-storage', 'channels.public')['filesystem'] ?? null
);

$channel = $this->app->make(Channels\PublicChannel::class);
Expand Down
2 changes: 1 addition & 1 deletion resources/assets/admin/component/Home.vue
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ $lefyNavWidth: 240px;
<div class="left-nav pull-left">

<!-- User avatar. -->
<img v-if="user.avatar" class="img-responsive img-circle center-block user-avatar" :src="user.avatar">
<img v-if="user.avatar" class="img-responsive img-circle center-block user-avatar" :src="user.avatar.url">
<default-avatar v-else class="img-responsive img-circle center-block user-avatar" />
<!-- End user avatar. -->

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from './wrap';
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
<template>
<div class="panel panel-default">
<div class="panel-heading">公开频道</div>
<div class="panel-body">

<div class="alert alert-warning">
公开频道关键词为 <code>public</code>,公开频道中
所存储的文件均为公开免费文件!主要适用场景为<code>用户头像</code>、<code>背景图片</code>以及<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-3">
<select class="form-control" v-model="filesystem">
<option value="" disabled>-- 请选择文件系统 --</option>
<option
v-for="filesystem in filesystems"
:key="filesystem.value"
:value="filesystem.value"
>
{{ filesystem.name }}
</option>
</select>
</div>
<div class="col-sm-7 help-block">
请选择频道中所使用的文件系统。如果没有选择,将使用<code>默认文件系统</code>。
</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 {
props: {
filesystems: {
required: true,
type: Array
}
},
data: () => ({
filesystem: '',
loading: true
}),
created() {
this.loading = true;
request.get(
createRequestURI('file-storage/channels/public'),
{
validateStatus: status => status === 200
}
)
.then(({ data: { filesystem } }) => {
this.filesystem = filesystem;
this.loading = false;
})
.catch(({ response: { data: message = "获取默认公开频道设置失败,请检查网络或者刷新页面重试" } }) => {
this.$store.dispatch("alert-open", { type: "danger", message });
});
},
methods: {
submitHandler({ stopProcessing }) {
request.patch(
createRequestURI('file-storage/channels/public'),
{
filesystem: this.filesystem
},
{
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>

Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<template>
<div class="container-fluid">
<public-channel-panel :filesystems="filesystems" />
</div>
</template>

<script>
import PublicChannelPanel from './public';
export default {
components: {
PublicChannelPanel,
},
data: () => ({
filesystems: [
{ value: 'local', name: '本地存储' },
{ value: 'AliyunOSS', name: '阿里云 OSS' },
]
})
}
</script>

1 change: 1 addition & 0 deletions resources/assets/admin/pages/file-storage/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export { default as WrapComponent } from './wrap-component';
export { default as HomeComponent } from './home-component';
export { default as FilesystemsComponent } from './filesystems-component';
export { default as ChannelsComponent } from './channels-component';
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<router-link tag="li" active-class="active" :to="{ name: 'file-storage:filesystems' }">
<a>文件系统</a>
</router-link>
<router-link tag="li" active-class="active" to="/file-storage/filesystem">
<router-link tag="li" active-class="active" :to="{ name: 'file-storage:channels' }">
<a>频道设置</a>
</router-link>
</ul>
Expand Down
6 changes: 6 additions & 0 deletions resources/assets/admin/router/file-storage-routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
WrapComponent,
HomeComponent,
FilesystemsComponent,
ChannelsComponent,
} from '../pages/file-storage';

export default {
Expand All @@ -17,6 +18,11 @@ export default {
name: "file-storage:filesystems",
path: "filesystems",
component: FilesystemsComponent
},
{
name: "file-storage:channels",
path: 'channels',
component: ChannelsComponent
}
]
};
3 changes: 3 additions & 0 deletions routes/new-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,7 @@

$route->get('file-storage/filesystems/aliyun-oss', AdminControllers\FileStorage\AliyunOSSFilesystem::class.'@show');
$route->patch('file-storage/filesystems/aliyun-oss', AdminControllers\FileStorage\AliyunOSSFilesystem::class.'@update');

$route->get('file-storage/channels/public', AdminControllers\FileStorage\PublicChannel::class.'@show');
$route->patch('file-storage/channels/public', AdminControllers\FileStorage\PublicChannel::class.'@update');
});

0 comments on commit 70ad60e

Please sign in to comment.