From 4962f62279679e18bdb54adff2c764ac4a7f5831 Mon Sep 17 00:00:00 2001 From: GallopYD <18859669020@163.com> Date: Tue, 18 May 2021 15:09:41 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E7=89=B9=E6=80=A7=EF=BC=9A=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=E4=BB=A4=E7=89=8C=E7=8A=B6=E6=80=81=E5=90=8C=E6=AD=A5?= =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Controllers/ConfigTokenController.php | 8 +++++++- app/Services/GitHubService.php | 2 +- resources/views/configToken/index.blade.php | 8 ++++++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/ConfigTokenController.php b/app/Http/Controllers/ConfigTokenController.php index 1c05897..721d299 100644 --- a/app/Http/Controllers/ConfigTokenController.php +++ b/app/Http/Controllers/ConfigTokenController.php @@ -3,6 +3,7 @@ namespace App\Http\Controllers; use App\Models\ConfigToken; +use App\Services\GitHubService; use Illuminate\Http\Request; class ConfigTokenController extends Controller @@ -37,7 +38,12 @@ public function store(Request $request) ['token' => $request->input('token')], ['description' => $request->input('description') ?? ''] ); - if (!$data->wasRecentlyCreated) { + if ($data->wasRecentlyCreated) { + $gitHubService = new GitHubService(); + $client['token'] = $data->token; + $client['client'] = $gitHubService->createClient($client['token']); + $gitHubService->updateClient($client); + } else { throw new \Exception('操作失败,可能已存在此令牌!'); } return ['success' => true, 'data' => ConfigToken::find($data->id)]; diff --git a/app/Services/GitHubService.php b/app/Services/GitHubService.php index a2dce33..db387fa 100644 --- a/app/Services/GitHubService.php +++ b/app/Services/GitHubService.php @@ -116,7 +116,7 @@ public function getClient() * @param $client * @return bool */ - private function updateClient(&$client) + public function updateClient(&$client) { $code = $resource = null; try { diff --git a/resources/views/configToken/index.blade.php b/resources/views/configToken/index.blade.php index 67f7448..56986b0 100644 --- a/resources/views/configToken/index.blade.php +++ b/resources/views/configToken/index.blade.php @@ -260,6 +260,13 @@ function winForm(data) { text: '提交', formBind: true, handler: function () { + Ext.MessageBox.show({ + msg: '令牌状态同步中...', + progressText: '', + width: 300, + wait: {interval: 200}, + }); + var params = this.up('form').getValues(); var method = data.id ? 'PUT' : 'POST'; var url = data.id ? '/api/configToken/' + data.id : '/api/configToken'; @@ -272,6 +279,7 @@ function winForm(data) { } else { tool.toast(rsp.message, 'warning'); } + Ext.MessageBox.hide(); }); } } From 2dd79f5b174b80539f464d43815b5f125e55e996 Mon Sep 17 00:00:00 2001 From: YoonPer Date: Mon, 31 May 2021 17:22:24 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E5=85=B6=E4=BB=96=EF=BC=9A=E7=BB=86?= =?UTF-8?q?=E8=8A=82=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Controllers/ConfigTokenController.php | 6 +++--- public/css/configToken.css | 2 +- resources/views/configToken/index.blade.php | 18 +++++++++--------- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/app/Http/Controllers/ConfigTokenController.php b/app/Http/Controllers/ConfigTokenController.php index 721d299..1f60faf 100644 --- a/app/Http/Controllers/ConfigTokenController.php +++ b/app/Http/Controllers/ConfigTokenController.php @@ -39,10 +39,10 @@ public function store(Request $request) ['description' => $request->input('description') ?? ''] ); if ($data->wasRecentlyCreated) { - $gitHubService = new GitHubService(); + $service = new GitHubService(); $client['token'] = $data->token; - $client['client'] = $gitHubService->createClient($client['token']); - $gitHubService->updateClient($client); + $client['client'] = $service->createClient($client['token']); + $service->updateClient($client); } else { throw new \Exception('操作失败,可能已存在此令牌!'); } diff --git a/public/css/configToken.css b/public/css/configToken.css index f5f6f16..36ad7bd 100644 --- a/public/css/configToken.css +++ b/public/css/configToken.css @@ -19,7 +19,7 @@ } .progress > div { - background: #FFE082; + background: #C2DDF2; line-height: 20px; } diff --git a/resources/views/configToken/index.blade.php b/resources/views/configToken/index.blade.php index 56986b0..6dc4281 100644 --- a/resources/views/configToken/index.blade.php +++ b/resources/views/configToken/index.blade.php @@ -39,14 +39,14 @@ }, } - var urlGenToken = 'https://github.com/settings/tokens/new'; + var urlNewToken = 'https://github.com/settings/tokens/new'; var content = ''; content += '

1. 令牌是什么?

'; content += '

用来请求 GitHub API 的 Token(即 GitHub personal access token)


'; content += '

2. 如何申请令牌?

'; content += '

GitHub - Settings - Developer settings - Personal access tokens - Generate new token'; - content += '(直达

'; + content += '(直达

'; content += '

提示:填写 Note 信息后直接点击 Generate token 按钮生成,无需设置其他选项。


'; content += '

3. 为何需要配置多个令牌?

'; content += '

GitHub 限制了 API 的请求速率'; @@ -120,13 +120,14 @@ text: 'GitHub接口请求配额', columns: [ { - text: '接口请求量/上限', + text: '已用配额/上限', width: 200, renderer: function (value, cellmeta, record) { var item = [], data = record.data; item.limit = data.api_limit; item.used = Math.max(0, item.limit - data.api_remaining); - item.percent = parseFloat(item.used / item.limit * 100); + item.percent = parseFloat((1 - item.used / item.limit) * 100); + item.percent = item.limit > 0 ? item.percent : 0; return new Ext.XTemplate( '

', '
', @@ -230,13 +231,13 @@ function winForm(data) { fieldLabel: '令牌', allowBlank: false, value: data.token, - emptyText: '点击右边图标申请..', + emptyText: '点击右侧图标申请..', triggers: { search: { - cls: 'icon-page-get', + cls: 'icon-page-key', tooltip: '前往 GitHub 申请令牌', handler: function () { - tool.winOpen(urlGenToken); + tool.winOpen(urlNewToken); } } } @@ -261,8 +262,7 @@ function winForm(data) { formBind: true, handler: function () { Ext.MessageBox.show({ - msg: '令牌状态同步中...', - progressText: '', + msg: '令牌状态同步中..', width: 300, wait: {interval: 200}, });