Skip to content

Commit

Permalink
完善后台管理
Browse files Browse the repository at this point in the history
  • Loading branch information
WangNingkai committed Jul 19, 2020
1 parent ea0a4d3 commit c4a6015
Show file tree
Hide file tree
Showing 12 changed files with 94 additions and 45 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
/.idea
.env
.env.backup
.env.bak
.phpunit.result.cache
Homestead.json
Homestead.yaml
Expand Down
4 changes: 2 additions & 2 deletions app/Console/Commands/InstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function handle(): void
copy($sqlSampleFile, $sqlFile);
} else {
$this->warn('Already have database file,Re-creating...');
rename($sqlFile, $sqlFile . '.' . date('YmdHis') . '.bak');
rename($sqlFile, date('YmdHis') . '.' . $sqlFile . '.bak');
copy($sqlSampleFile, $sqlFile);
}
chmod($sqlFile, 0777);
Expand All @@ -81,7 +81,7 @@ public function handle(): void
$env = str_replace($_search, $_replace, $envExample);
if (file_exists($envFile)) {
if ($this->confirm('Already have [.env] ,overwrite?', true)) {
rename($envFile, $envFile . '.' . date('YmdHis') . '.bak');
rename($envFile, date('YmdHis') . '.' . $envFile . '.bak');
file_put_contents($envFile, $env);
}
} else {
Expand Down
32 changes: 10 additions & 22 deletions app/Http/Controllers/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
namespace App\Http\Controllers;

use App\Helpers\Tool;
use App\Http\Traits\ApiResponseTrait;
use App\Models\Account;
use App\Models\Setting;
use App\Models\User;
Expand All @@ -18,6 +19,7 @@

class AdminController extends BaseController
{
use ApiResponseTrait;
/**
* 缓存清理
* @return \Illuminate\Http\RedirectResponse
Expand Down Expand Up @@ -134,14 +136,10 @@ public function accountSet(Request $request)
$id = $request->post('id', 0);
$account = Account::find($id);
if (!$account) {
return response()->json([
'error' => '账号不存在!'
]);
return $this->fail('账号不存在');
}
setting_set('primary_account', $id);
return response()->json([
'error' => ''
]);
return $this->success();
}

/**
Expand All @@ -154,19 +152,15 @@ public function accountRemark($id, Request $request)
{
$account = Account::find($id);
if (!$account) {
return response()->json([
'error' => '账号不存在!'
]);
return $this->fail('账号不存在');
}
$remark = $request->get('remark');
$account->remark = $remark;
if ($account->save()) {
Cache::forget('ac:list');
return response()->json();
return $this->success();
}
return response()->json([
'error' => ''
]);
return $this->success();
}

/**
Expand All @@ -181,19 +175,13 @@ public function accountDelete(Request $request)
$id = $request->post('id', 0);
$account = Account::find($id);
if (!$account) {
return response()->json([
'error' => '账号不存在!'
]);
return $this->fail('账号不存在');
}
if ($account->delete()) {
Cache::forget('ac:list');
return response()->json([
'error' => ''
]);
return $this->success();
}
return response()->json([
'error' => '删除失败'
]);
return $this->fail('删除失败');
}

/**
Expand Down
1 change: 1 addition & 0 deletions app/Http/Controllers/Auth/LoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,6 @@ public function redirectPath()
Cache::forget('ac:list');
return '/admin/install';
}
return request()->get('redirect');
}
}
26 changes: 18 additions & 8 deletions app/Http/Controllers/ManageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@

use App\Helpers\HashidsHelper;
use App\Helpers\Tool;
use App\Http\Traits\ApiResponseTrait;
use Illuminate\Http\Request;
use Cache;
use OneDrive;

class ManageController extends BaseController
{
use ApiResponseTrait;

public function query(Request $request, $hash, $query = '')
{
// 账号处理
Expand Down Expand Up @@ -84,6 +87,7 @@ public function query(Request $request, $hash, $query = '')
$perPage = array_get($config, 'list_limit', 10);

$list = $this->paginate($list, $perPage, false);

return view(config('olaindex.theme') . 'admin.file-manage', compact('accounts', 'hash', 'path', 'item', 'list', 'doc'));
}

Expand Down Expand Up @@ -151,8 +155,7 @@ public function edit(Request $request, $hash, $query = '')
$content = '';
}

$file['content'] = $content;
;
$file['content'] = $content;;
return view(config('olaindex.theme') . 'editor', compact('accounts', 'hash', 'path', 'file'));
}

Expand Down Expand Up @@ -185,24 +188,31 @@ public function create(Request $request, $hash, $query = '')
return redirect()->route('home');
}

public function delete(Request $request, $hash, $query = '')
public function delete(Request $request)
{
$eTag = $request->get('eTag');
$hash = $request->get('hash');
$query = $request->get('id');
if (!$eTag || !$hash || !$query) {
return $this->fail('参数错误!');
}
$accounts = Tool::fetchAccounts();
if (blank($accounts)) {
Cache::forget('ac:list');
abort(404, '请先绑定账号');
return $this->fail('请先绑定账号!');
}
$account_id = HashidsHelper::decode($hash);
if (!$account_id) {
abort(404, '账号不存在');
return $this->fail('账号不存在');

}
$service = OneDrive::account($account_id);
$eTag = $request->get('eTag');

$resp = $service->delete($query, $eTag);
if (array_key_exists('code', $resp)) {
$this->showMessage(array_get($resp, 'message', '404NotFound'), true);
return $this->fail(array_get($resp, 'message', '404NotFound'));
}
return redirect()->back();
return $this->success();
}

/**
Expand Down
6 changes: 3 additions & 3 deletions app/Http/Middleware/Authenticate.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ class Authenticate extends Middleware
/**
* Get the path the user should be redirected to when they are not authenticated.
*
* @param \Illuminate\Http\Request $request
* @param \Illuminate\Http\Request $request
* @return string|null
*/
protected function redirectTo($request)
{
if (! $request->expectsJson()) {
return route('login');
if (!$request->expectsJson()) {
return route('login', ['redirect' => $request->getRequestUri()]);
}
}
}
3 changes: 2 additions & 1 deletion app/Http/Traits/ApiResponseTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ public function buildResponse($data = [], $code = 0, $msg = 'ok')
$data = [
'data' => $data,
'msg' => $msg,
'code' => $code
'code' => $code,
'error' => $code ? $msg : '',
];
return response()->json($data);
}
Expand Down
55 changes: 49 additions & 6 deletions resources/views/default/admin/file-manage.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,9 @@ class="btn btn-primary btn-sm dropdown-toggle list-item-dropdown"
data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">更多
</button>
<div class="dropdown-menu" aria-labelledby="actionItem"
data-id="{{ $item['id'] }}">
<a class="dropdown-item" href="javascript:void(0)">todo</a>
data-id="{{ $data['id'] }}" data-hash="{{ $hash }}"
data-etag="{{ $data['eTag'] ?? '' }}">
<a class="dropdown-item delete-item" href="javascript:void(0)">删除</a>
</div>
</div>
</td>
Expand Down Expand Up @@ -104,17 +105,59 @@ class="btn btn-primary btn-sm dropdown-toggle list-item-dropdown"
@stop
@push('scripts')
<script>
$(function() {
$('.list-item').on('click', function(e) {
window.location.href = $(this).attr('data-route')
$(function () {
$('.list-item').on('click', function (e) {
if ($(this).attr('data-route')) {
window.location.href = $(this).attr('data-route')
}
e.stopPropagation()
})
$('.list-item-dropdown').on('mouseover', function(e) {
$('.list-item-dropdown').on('mouseover', function (e) {
$(this).dropdown({
boundary: 'window',
})
e.stopPropagation()
})
$('.delete-item').on('click', function (e) {
Swal.fire({
title: '确定删除吗?',
text: '删除后无法恢复!',
icon: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: '确定',
cancelButtonText: '取消',
}).then((result) => {
if (result.value) {
let source_id = $('.delete-item').parent().attr('data-id')
let hash = $('.delete-item').parent().attr('data-hash')
let eTag = $('.delete-item').parent().attr('data-etag')
axios.post("{{ route('admin.file.delete') }}", {
id: source_id,
hash: hash,
eTag: eTag
})
.then(function (response) {
let data = response.data
console.log(data)
if (data.error === '') {
Swal.fire('删除成功!')
window.location.reload()
}else {
Swal.fire('删除失败!')
}
})
.catch(function (error) {
console.log(error)
})
.then(function () {
// always executed
})
}
})
e.stopPropagation()
})
})
</script>
@endpush
4 changes: 3 additions & 1 deletion resources/views/default/one-id.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,9 @@
<script>
$(function() {
$('.list-item').on('click', function(e) {
window.location.href = $(this).attr('data-route')
if ($(this).attr('data-route')) {
window.location.href = $(this).attr('data-route')
}
e.stopPropagation()
})
})
Expand Down
4 changes: 3 additions & 1 deletion resources/views/default/one.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,9 @@
<script>
$(function() {
$('.list-item').on('click', function(e) {
window.location.href = $(this).attr('data-route')
if ($(this).attr('data-route')) {
window.location.href = $(this).attr('data-route')
}
e.stopPropagation()
})
})
Expand Down
2 changes: 1 addition & 1 deletion routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
Route::any('manage/{hash}/q/{query?}', 'ManageController@query')->name('admin.file.manage')->where('query', '.*');
Route::any('manage/{hash}/edit/{query?}', 'ManageController@edit')->name('admin.file.edit');
Route::any('manage/{hash}/create/{query?}', 'ManageController@create')->name('admin.file.create');
Route::any('manage/{hash}/delete/{query?}', 'ManageController@delete')->name('admin.file.delete');
Route::any('manage/delete', 'ManageController@delete')->name('admin.file.delete');
});
// 短网址
Route::get('t/{code}', 'IndexController')->name('short');
Expand Down
1 change: 1 addition & 0 deletions storage/install/data/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
*.sqlite
*.sqlite.bak
*.bak
!*.sample.sqlite

0 comments on commit c4a6015

Please sign in to comment.