Skip to content

Commit 750785f

Browse files
committed
feat(后台): 增加微信登录设置面板
1 parent 03bd6c8 commit 750785f

File tree

8 files changed

+200
-2
lines changed

8 files changed

+200
-2
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/*
6+
* +----------------------------------------------------------------------+
7+
* | ThinkSNS Plus |
8+
* +----------------------------------------------------------------------+
9+
* | Copyright (c) 2018 Chengdu ZhiYiChuangXiang Technology Co., Ltd. |
10+
* +----------------------------------------------------------------------+
11+
* | This source file is subject to version 2.0 of the Apache license, |
12+
* | that is bundled with this package in the file LICENSE, and is |
13+
* | available through the world-wide-web at the following url: |
14+
* | http://www.apache.org/licenses/LICENSE-2.0.html |
15+
* +----------------------------------------------------------------------+
16+
* | Author: Slim Kit Group <master@zhiyicx.com> |
17+
* | Homepage: www.thinksns.com |
18+
* +----------------------------------------------------------------------+
19+
*/
20+
21+
namespace Zhiyi\Plus\Admin\Controllers\Setting;
22+
23+
use Illuminate\Http\Response;
24+
use function Zhiyi\Plus\setting;
25+
use Illuminate\Http\JsonResponse;
26+
use Zhiyi\Plus\Admin\Controllers\Controller;
27+
use Zhiyi\Plus\Admin\Requests\SeWeChatConfigure as SeWeChatConfigureRequest;
28+
29+
class WeChat extends Controller
30+
{
31+
/**
32+
* Get configure.
33+
* @return \Illuminate\Http\JsonResponse
34+
*/
35+
public function getConfigure(): JsonResponse
36+
{
37+
$settings = setting('user', 'vendor:wechat', [
38+
'appSecret' => '',
39+
'appKey' => '',
40+
]);
41+
42+
return new JsonResponse($settings, Response::HTTP_OK);
43+
}
44+
45+
/**
46+
* set configure.
47+
* @param \Zhiyi\Plus\Admin\Requests\SeWeChatConfigureRequest $request
48+
* @return \Illuminate\Http\Response
49+
*/
50+
public function setConfigure(SeWeChatConfigureRequest $request)
51+
{
52+
setting('user')->set('vendor:qq', [
53+
'appSecret' => $request->input('appSecret'),
54+
'appKey' => $request->input('appKey'),
55+
]);
56+
57+
return new Response('', Response::HTTP_NO_CONTENT);
58+
}
59+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/*
6+
* +----------------------------------------------------------------------+
7+
* | ThinkSNS Plus |
8+
* +----------------------------------------------------------------------+
9+
* | Copyright (c) 2018 Chengdu ZhiYiChuangXiang Technology Co., Ltd. |
10+
* +----------------------------------------------------------------------+
11+
* | This source file is subject to version 2.0 of the Apache license, |
12+
* | that is bundled with this package in the file LICENSE, and is |
13+
* | available through the world-wide-web at the following url: |
14+
* | http://www.apache.org/licenses/LICENSE-2.0.html |
15+
* +----------------------------------------------------------------------+
16+
* | Author: Slim Kit Group <master@zhiyicx.com> |
17+
* | Homepage: www.thinksns.com |
18+
* +----------------------------------------------------------------------+
19+
*/
20+
21+
namespace Zhiyi\Plus\Admin\Requests;
22+
23+
use Illuminate\Foundation\Http\FormRequest;
24+
25+
class SeWeChatConfigure extends FormRequest
26+
{
27+
/**
28+
* Determine if the user is authorized to make this request.
29+
*
30+
* @return bool
31+
* @author Seven Du <shiweidu@outlook.com>
32+
*/
33+
public function authorize(): bool
34+
{
35+
return true;
36+
}
37+
38+
/**
39+
* Get the validation rules that apply to the request.
40+
*
41+
* @return array
42+
* @author Seven Du <shiweidu@outlook.com>
43+
*/
44+
public function rules(): array
45+
{
46+
return [
47+
'appSecret' => 'required|string',
48+
'appKey' => 'required|string',
49+
];
50+
}
51+
}

resources/assets/admin/api/vendor.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,5 @@ class VendorRequestGenerator {
2323

2424
export const easemob = new VendorRequestGenerator('setting/vendor/easemob');
2525
export const qq = new VendorRequestGenerator('setting/vendor/qq');
26+
export const wechat = new VendorRequestGenerator('setting/vendor/wechat');
2627

resources/assets/admin/component/User.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@
4141
<router-link tag="li" active-class="active" :to="{ name: 'user:vendor/qq' }">
4242
<a href="#">QQ&nbsp;登录</a>
4343
</router-link>
44-
<li><a href="#">微信登录</a></li>
44+
<router-link tag="li" active-class="active" :to="{ name: 'user:vendor/wechat' }">
45+
<a href="#">微信登录</a>
46+
</router-link>
4547
<li><a href="#">微博登录</a></li>
4648
<li class="divider"></li>
4749
<router-link tag="li" active-class="active" :to="{ name: 'user:vendor/easemob' }">
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
export { default as Easemob } from './easemob';
2-
export { default as QQ } from './qq';
2+
export { default as QQ } from './qq';
3+
export { default as WeChat } from './wechat';
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
<template>
2+
<div class="container-fluid">
3+
<div class="row">
4+
<div class="col-md-7">
5+
<div class="panel panel-default">
6+
<div class="panel-heading">微信登录</div>
7+
<div class="panel-body">
8+
<sb-ui-loading v-if="loading" />
9+
<form class="form-horizontal" v-else>
10+
11+
<!-- App Key -->
12+
<div class="form-group">
13+
<label class="col-sm-3 control-label">App Key</label>
14+
<div class="col-sm-9">
15+
<input type="text" class="form-control" v-model="form.appKey">
16+
</div>
17+
</div>
18+
19+
<!-- App Secret -->
20+
<div class="form-group">
21+
<label class="col-sm-3 control-label">App Secret</label>
22+
<div class="col-sm-9">
23+
<input type="text" class="form-control" v-model="form.appSecret">
24+
</div>
25+
</div>
26+
27+
<!-- 提交按钮 -->
28+
<div class="form-group">
29+
<div class="col-sm-9 col-sm-offset-3">
30+
<ui-button type="button" class="btn btn-primary" @click="onSubmit" />
31+
</div>
32+
</div>
33+
34+
</form>
35+
</div>
36+
</div>
37+
</div>
38+
<div class="col-md-5">
39+
<div class="panel panel-default">
40+
<div class="panel-heading">帮助</div>
41+
<div class="panel-body">
42+
微信登录登录需要配置的数据,请前往「<a target="_blank" href="https://open.weixin.qq.com/">微信开发平台</a>」进行申请。
43+
</div>
44+
</div>
45+
</div>
46+
</div>
47+
</div>
48+
</template>
49+
50+
<script>
51+
import { wechat } from '../../api/vendor';
52+
export default {
53+
data: () => ({
54+
form: {
55+
appKey: '',
56+
appSecret: '',
57+
},
58+
loading: true,
59+
}),
60+
methods: {
61+
onSubmit(event) {
62+
wechat.update(this.form).then(() => {
63+
this.$store.dispatch("alert-open", { type: "success", message: '提交成功' });
64+
}).catch(({ response: { data: message = "提交失败,请刷新页面重试!" } }) => {
65+
this.$store.dispatch("alert-open", { type: "danger", message });
66+
}).finally(event.stopProcessing);
67+
}
68+
},
69+
created() {
70+
wechat.get().then(({ data }) => {
71+
this.loading = false;
72+
this.form = data;
73+
}).catch(({ response: { data: message = "获取失败,请刷新页面重试!" } }) => {
74+
this.$store.dispatch("alert-open", { type: "danger", message });
75+
});
76+
}
77+
}
78+
</script>
79+

resources/assets/admin/router/user.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ const routers = {
3333
{ path: 'trashed', component: UserTrashed },
3434
{ path: 'vendor-easemob', component: vendorPages.Easemob, name: 'user:vendor/easemob' },
3535
{ path: 'vendor-qq', component: vendorPages.QQ, name: 'user:vendor/qq' },
36+
{ path: 'vendor-wechat', component: vendorPages.WeChat, name: 'user:vendor/wechat' },
3637
]
3738
};
3839

routes/new-admin.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,8 @@
6161
// QQ 配置
6262
$route->get('setting/vendor/qq', AdminControllers\Setting\QQ::class.'@getConfigure');
6363
$route->put('setting/vendor/qq', AdminControllers\Setting\QQ::class.'@setConfigure');
64+
65+
// 微信配置
66+
$route->get('setting/vendor/wechat', AdminControllers\Setting\WeChat::class.'@getConfigure');
67+
$route->put('setting/vendor/wechat', AdminControllers\Setting\WeChat::class.'@setConfigure');
6468
});

0 commit comments

Comments
 (0)