1
0
Fork 0

chartOption

master
panliang 2023-12-11 13:20:44 +08:00
parent 93b3e69806
commit 0713fc5614
12 changed files with 60 additions and 9 deletions

View File

@ -51,8 +51,8 @@ class ArticleController extends AdminController
amisMake()->TextControl()->name('title')->label(__('article.title'))->required(true),
amisMake()->SelectControl()->name('category_id')->label(__('article.category_id'))->options($this->getCategoryOptions())->required(),
amisMake()->SelectControl()->name('party_cate_id')->label(__('article.party_cate_id'))->options($this->getPartyCateOptions())->searchable(),
amisMake()->ImageControl()->name('cover')->label(__('article.cover'))->autoUpload(true),
Components::make()->sortControl('sort', __('article.sort')),
// amisMake()->ImageControl()->name('cover')->label(__('article.cover'))->autoUpload(true),
// Components::make()->sortControl('sort', __('article.sort')),
amisMake()->DateTimeControl()->name('published_at')->label(__('article.published_at'))->value(now())->format('YYYY-MM-DD HH:mm:ss')->description('*不填写则默认为创建时间'),
Components::make()->switchControl('form')->name('is_enable')->label(__('article.is_enable'))->value(true),
Components::make()->fuEditorControl('content', __('article.content')),

View File

@ -3,7 +3,7 @@
namespace App\Admin\Controllers;
use App\Admin\Services\{PartyUserService, PartyCateService};
use App\Models\PartyCate;
use App\Models\{PartyCate, PartyUser, Keyword};
use Slowlyo\OwlAdmin\Controllers\AdminController;
use Slowlyo\OwlAdmin\Renderers\Form;
use Slowlyo\OwlAdmin\Renderers\Page;
@ -87,12 +87,21 @@ class PartyUserController extends AdminController
amisMake()->TextControl()->name('avatar')->label(__('party_user.avatar'))->static()->staticSchema(amisMake()->Image()),
amisMake()->TextControl()->name('current_score')->label(__('party_cate.current_score'))->static(),
amisMake()->TextControl()->name('score')->label(__('party_cate.score'))->static(),
amisMake()->TextControl()->name('scores')->label(__('party_cate.scores'))->static()->staticSchema(amisMake()->Json()),
amisMake()->TextControl()->name('scores')->label(__('party_cate.scores'))->static()->staticSchema(
amisMake()->Chart()->width('400px')->height('300px')->initFetch(false)->api(admin_url('/party-user/${id}/chart-option'))
),
amisMake()->TextControl()->name('remarks')->label(__('party_cate.remarks'))->static(),
amisMake()->TextControl()->name('created_at')->label(__('party_user.created_at'))->static(),
]);
}
public function chartOption($id)
{
$user = PartyUser::findOrFail($id);
$option = $this->service->getChartOption($user);
return $this->response()->success($option);
}
public function getCateOptions()
{
if (!$this->cateOptions) {

View File

@ -38,7 +38,7 @@ class ArticleService extends BaseService
if ($cid && $category = Keyword::find($cid)) {
$data['category_path'] = $category->path.$category->id.'-';
}
if (! data_get($data, 'published_at')) {
if (! data_get($data, 'published_at') && !$model) {
$data['published_at'] = now();
}

View File

@ -87,4 +87,35 @@ class PartyUserService extends BaseService
PartyCateService::make()->incrementScore($user->cate, $type, $score);
}
}
/**
* 五星维度配置
* Echarts 雷达图 echarts.apache.org
*
* @param PartyUser $user 党员
*
* @return array
*/
public function getChartOption(PartyUser $user)
{
$typeList = Keyword::filter(['key' => 'score_cate_'])->sort()->get();
$scores = $user->scores ?: [];
$values = $typeList->map(fn($item) => data_get($scores, $item->key, 0))->all();
$max = max($values);
$options = [
'radar' => [
'indicator' => $typeList->map(fn($item) => ['name' => $item->name, 'max' => $max])->all(),
],
'series' => [
[
'type' => 'radar',
'data' => [
['value' => $values]
],
'label' => ['show' => true]
]
]
];
return $options;
}
}

View File

@ -50,6 +50,7 @@ Route::group([
$router->get('party-cate/{id}/rank', [\App\Admin\Controllers\PartyCateController::class, 'rankList']);
// 党员
$router->resource('party-user', \App\Admin\Controllers\PartyUserController::class)->names('admin.party_user');
$router->get('party-user/{id}/chart-option', [\App\Admin\Controllers\PartyUserController::class, 'chartOption']);
// 评议审核
$router->post('user-score/{id}/check', [\App\Admin\Controllers\UserScoreController::class, 'check']);
$router->resource('user-score', \App\Admin\Controllers\UserScoreController::class)->names('admin.user_score');

View File

@ -24,6 +24,14 @@ class AccountController extends Controller
]);
}
public function chartOption()
{
$user = auth('api')->user();
$option = PartyUserService::make()->getChartOption($user);
return $this->response()->success($option);
}
public function update(Request $request)
{
$user = auth('api')->user();

View File

@ -7,6 +7,7 @@ use Laravel\Sanctum\HasApiTokens;
use Illuminate\Foundation\Auth\User as Authenticatable;
use EloquentFilter\Filterable;
use App\Casts\StorageFile;
use Illuminate\Database\Eloquent\Casts\Attribute;
/**
* 党员
@ -24,7 +25,7 @@ class PartyUser extends Authenticatable
'avatar' => StorageFile::class,
'scores' => 'array',
];
public function cate()
{
return $this->belongsTo(PartyCate::class, 'cate_id');

View File

@ -1,2 +1,2 @@
<!doctype html><html lang="zh-CN"><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><title>五星党建</title><script>var coverSupport = 'CSS' in window && typeof CSS.supports === 'function' && (CSS.supports('top: env(a)') || CSS.supports('top: constant(a)'))
document.write('<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0' + (coverSupport ? ', viewport-fit=cover' : '') + '" />')</script><link rel="stylesheet" href="/h5/static/index.5841170f.css"/><script defer="defer" src="/h5/static/js/chunk-vendors.49434503.js"></script><script defer="defer" src="/h5/static/js/index.2d1c93b2.js"></script></head><body><noscript><strong>Please enable JavaScript to continue.</strong></noscript><div id="app"></div></body></html>
document.write('<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0' + (coverSupport ? ', viewport-fit=cover' : '') + '" />')</script><link rel="stylesheet" href="/h5/static/index.5841170f.css"/><script defer="defer" src="/h5/static/js/chunk-vendors.49434503.js"></script><script defer="defer" src="/h5/static/js/index.19712fcf.js"></script></head><body><noscript><strong>Please enable JavaScript to continue.</strong></noscript><div id="app"></div></body></html>

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -38,6 +38,7 @@ Route::post('feedback', [\App\Http\Controllers\Api\FeedbackController::class, 's
Route::group(['middleware' => 'auth:api'], function () {
Route::get('logout', [\App\Http\Controllers\Api\AccountController::class, 'logout']);
Route::get('user/profile', [\App\Http\Controllers\Api\AccountController::class, 'profile']);
Route::get('user/chart-option', [\App\Http\Controllers\Api\AccountController::class, 'chartOption']);
Route::post('user/profile', [\App\Http\Controllers\Api\AccountController::class, 'update']);
Route::get('article/cate', [\App\Http\Controllers\Api\ArticleController::class, 'cate']);