Skip to content

Commit

Permalink
feat(后台): 增加微博配置管理面板
Browse files Browse the repository at this point in the history
  • Loading branch information
medz committed Nov 15, 2018
1 parent 750785f commit 1de1d00
Show file tree
Hide file tree
Showing 10 changed files with 205 additions and 7 deletions.
8 changes: 4 additions & 4 deletions app/Admin/Controllers/Setting/WeChat.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
use function Zhiyi\Plus\setting;
use Illuminate\Http\JsonResponse;
use Zhiyi\Plus\Admin\Controllers\Controller;
use Zhiyi\Plus\Admin\Requests\SeWeChatConfigure as SeWeChatConfigureRequest;
use Zhiyi\Plus\Admin\Requests\SetWeChatConfigure as SetWeChatConfigureRequest;

class WeChat extends Controller
{
Expand All @@ -44,12 +44,12 @@ public function getConfigure(): JsonResponse

/**
* set configure.
* @param \Zhiyi\Plus\Admin\Requests\SeWeChatConfigureRequest $request
* @param \Zhiyi\Plus\Admin\Requests\SetWeChatConfigureRequest $request
* @return \Illuminate\Http\Response
*/
public function setConfigure(SeWeChatConfigureRequest $request)
public function setConfigure(SetWeChatConfigureRequest $request)
{
setting('user')->set('vendor:qq', [
setting('user')->set('vendor:wechat', [
'appSecret' => $request->input('appSecret'),
'appKey' => $request->input('appKey'),
]);
Expand Down
59 changes: 59 additions & 0 deletions app/Admin/Controllers/Setting/Weibo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

declare(strict_types=1);

/*
* +----------------------------------------------------------------------+
* | ThinkSNS Plus |
* +----------------------------------------------------------------------+
* | Copyright (c) 2018 Chengdu ZhiYiChuangXiang Technology Co., Ltd. |
* +----------------------------------------------------------------------+
* | This source file is subject to version 2.0 of the Apache license, |
* | that is bundled with this package in the file LICENSE, and is |
* | available through the world-wide-web at the following url: |
* | http://www.apache.org/licenses/LICENSE-2.0.html |
* +----------------------------------------------------------------------+
* | Author: Slim Kit Group <[email protected]> |
* | Homepage: www.thinksns.com |
* +----------------------------------------------------------------------+
*/

namespace Zhiyi\Plus\Admin\Controllers\Setting;

use Illuminate\Http\Response;
use function Zhiyi\Plus\setting;
use Illuminate\Http\JsonResponse;
use Zhiyi\Plus\Admin\Controllers\Controller;
use Zhiyi\Plus\Admin\Requests\SetWeiboConfigure as SetWeiboConfigureRequest;

class Weibo extends Controller
{
/**
* Get configure.
* @return \Illuminate\Http\JsonResponse
*/
public function getConfigure(): JsonResponse
{
$settings = setting('user', 'vendor:weibo', [
'secret' => '',
'appId' => '',
]);

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

/**
* set configure.
* @param \Zhiyi\Plus\Admin\Requests\SetWeiboConfigureRequest $request
* @return \Illuminate\Http\Response
*/
public function setConfigure(SetWeiboConfigureRequest $request)
{
setting('user')->set('vendor:weibo', [
'secret' => $request->input('secret'),
'appId' => $request->input('appId'),
]);

return new Response('', Response::HTTP_NO_CONTENT);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

use Illuminate\Foundation\Http\FormRequest;

class SeWeChatConfigure extends FormRequest
class SetWeChatConfigure extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
Expand Down
51 changes: 51 additions & 0 deletions app/Admin/Requests/SetWeiboConfigure.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

declare(strict_types=1);

/*
* +----------------------------------------------------------------------+
* | ThinkSNS Plus |
* +----------------------------------------------------------------------+
* | Copyright (c) 2018 Chengdu ZhiYiChuangXiang Technology Co., Ltd. |
* +----------------------------------------------------------------------+
* | This source file is subject to version 2.0 of the Apache license, |
* | that is bundled with this package in the file LICENSE, and is |
* | available through the world-wide-web at the following url: |
* | http://www.apache.org/licenses/LICENSE-2.0.html |
* +----------------------------------------------------------------------+
* | Author: Slim Kit Group <[email protected]> |
* | Homepage: www.thinksns.com |
* +----------------------------------------------------------------------+
*/

namespace Zhiyi\Plus\Admin\Requests;

use Illuminate\Foundation\Http\FormRequest;

class SetWeiboConfigure extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
* @author Seven Du <[email protected]>
*/
public function authorize(): bool
{
return true;
}

/**
* Get the validation rules that apply to the request.
*
* @return array
* @author Seven Du <[email protected]>
*/
public function rules(): array
{
return [
'appId' => 'required|string',
'secret' => 'required|string',
];
}
}
1 change: 1 addition & 0 deletions resources/assets/admin/api/vendor.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ class VendorRequestGenerator {
export const easemob = new VendorRequestGenerator('setting/vendor/easemob');
export const qq = new VendorRequestGenerator('setting/vendor/qq');
export const wechat = new VendorRequestGenerator('setting/vendor/wechat');
export const weibo = new VendorRequestGenerator('setting/vendor/weibo');

4 changes: 3 additions & 1 deletion resources/assets/admin/component/User.vue
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@
<router-link tag="li" active-class="active" :to="{ name: 'user:vendor/wechat' }">
<a href="#">微信登录</a>
</router-link>
<li><a href="#">微博登录</a></li>
<router-link tag="li" active-class="active" :to="{ name: 'user:vendor/weibo' }">
<a href="#">微博登录</a>
</router-link>
<li class="divider"></li>
<router-link tag="li" active-class="active" :to="{ name: 'user:vendor/easemob' }">
<a href="#">环信即时聊天</a>
Expand Down
3 changes: 2 additions & 1 deletion resources/assets/admin/pages/user-vendor/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export { default as Easemob } from './easemob';
export { default as QQ } from './qq';
export { default as WeChat } from './wechat';
export { default as WeChat } from './wechat';
export { default as Weibo } from './weibo';
79 changes: 79 additions & 0 deletions resources/assets/admin/pages/user-vendor/weibo.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<template>
<div class="container-fluid">
<div class="row">
<div class="col-md-7">
<div class="panel panel-default">
<div class="panel-heading">微博登录</div>
<div class="panel-body">
<sb-ui-loading v-if="loading" />
<form class="form-horizontal" v-else>

<!-- App id -->
<div class="form-group">
<label class="col-sm-3 control-label">App ID</label>
<div class="col-sm-9">
<input type="text" class="form-control" v-model="form.appId">
</div>
</div>

<!-- Secret -->
<div class="form-group">
<label class="col-sm-3 control-label">Secret</label>
<div class="col-sm-9">
<input type="text" class="form-control" v-model="form.secret">
</div>
</div>

<!-- 提交按钮 -->
<div class="form-group">
<div class="col-sm-9 col-sm-offset-3">
<ui-button type="button" class="btn btn-primary" @click="onSubmit" />
</div>
</div>

</form>
</div>
</div>
</div>
<div class="col-md-5">
<div class="panel panel-default">
<div class="panel-heading">帮助</div>
<div class="panel-body">
新浪微博登录登录需要配置的数据,请前往「<a target="_blank" href="http://open.weibo.com/">微博·开放平台</a>」进行申请。
</div>
</div>
</div>
</div>
</div>
</template>

<script>
import { weibo } from '../../api/vendor';
export default {
data: () => ({
form: {
appId: '',
secret: '',
},
loading: true,
}),
methods: {
onSubmit(event) {
weibo.update(this.form).then(() => {
this.$store.dispatch("alert-open", { type: "success", message: '提交成功' });
}).catch(({ response: { data: message = "提交失败,请刷新页面重试!" } }) => {
this.$store.dispatch("alert-open", { type: "danger", message });
}).finally(event.stopProcessing);
}
},
created() {
weibo.get().then(({ data }) => {
this.loading = false;
this.form = data;
}).catch(({ response: { data: message = "获取失败,请刷新页面重试!" } }) => {
this.$store.dispatch("alert-open", { type: "danger", message });
});
}
}
</script>

1 change: 1 addition & 0 deletions resources/assets/admin/router/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const routers = {
{ path: 'vendor-easemob', component: vendorPages.Easemob, name: 'user:vendor/easemob' },
{ path: 'vendor-qq', component: vendorPages.QQ, name: 'user:vendor/qq' },
{ path: 'vendor-wechat', component: vendorPages.WeChat, name: 'user:vendor/wechat' },
{ path: 'vendor-weibo', component: vendorPages.Weibo, name: 'user:vendor/weibo' },
]
};

Expand Down
4 changes: 4 additions & 0 deletions routes/new-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,8 @@
// 微信配置
$route->get('setting/vendor/wechat', AdminControllers\Setting\WeChat::class.'@getConfigure');
$route->put('setting/vendor/wechat', AdminControllers\Setting\WeChat::class.'@setConfigure');

// 微博配置
$route->get('setting/vendor/weibo', AdminControllers\Setting\Weibo::class.'@getConfigure');
$route->put('setting/vendor/weibo', AdminControllers\Setting\Weibo::class.'@setConfigure');
});

0 comments on commit 1de1d00

Please sign in to comment.