管理端 文件分享管理 前端

This commit is contained in:
Chenx221 2024-04-07 14:34:57 +08:00
parent 37638ad38f
commit e0d2fb1bc4
Signed by: chenx221
GPG Key ID: D7A9EC07024C3021
2 changed files with 145 additions and 0 deletions

View File

@ -0,0 +1,76 @@
<?php
use app\models\Share;
use yii\helpers\Html;
use yii\helpers\Url;
use yii\grid\ActionColumn;
use yii\grid\GridView;
/** @var yii\web\View $this */
/** @var app\models\ShareSearch $searchModel */
/** @var yii\data\ActiveDataProvider $dataProvider */
$this->title = '文件分享管理';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="share-index">
<h1><?= Html::encode($this->title) ?></h1>
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
[
'attribute' => 'share_id',
'headerOptions' => ['style' => 'width:6%;'],
],
[
'attribute' => 'sharer_id',
'label' => '分享者',
'value' => function ($model) {
return $model->getSharerUsername() . ' (ID:' . $model->sharer_id . ')';
},
],
[
'attribute' => 'file_relative_path',
],
[
'attribute' => 'access_code',
'enableSorting' => false,
'headerOptions' => ['style' => 'width:7%;'],
],
[
'attribute' => 'creation_date',
'headerOptions' => ['style' => 'width:15%;'],
],
[
'attribute' => 'status',
'label' => '分享状态',
'value' => function ($model) {
return $model->status == 1 ? '有效' : '失效';
},
'filter' => [1 => '有效', 0 => '失效'],
],
[
'attribute' => 'dl_count',
'label' => '下载次数',
],
[
'class' => ActionColumn::class,
'template' => '{view} {delete}', // 只显示查看和删除按钮
'urlCreator' => function ($action, Share $model, $key, $index, $column) {
if ($action === 'view') {
// 返回查看按钮的链接
return $model->status != 0 ? Url::toRoute(['share-manage-view', 'share_id' => $model->share_id]): null;
} elseif ($action === 'delete') {
// 如果 status 为 0禁用删除按钮
return $model->status != 0 ? Url::toRoute(['share-manage-delete', 'share_id' => $model->share_id]) : null;
}
}
],
],
]); ?>
</div>

View File

@ -0,0 +1,69 @@
<?php
use yii\helpers\Html;
use yii\web\JqueryAsset;
use yii\web\View;
use yii\web\YiiAsset;
use yii\widgets\DetailView;
/** @var yii\web\View $this */
/** @var app\models\Share $model */
$this->title = '分享ID ' . $model->share_id;
$this->params['breadcrumbs'][] = ['label' => '文件分享管理', 'url' => ['share-manage']];
$this->params['breadcrumbs'][] = $this->title;
YiiAsset::register($this);
JqueryAsset::register($this);
?>
<div class="share-view">
<h1><?= Html::encode($this->title) ?></h1>
<p>
<?php if ($model->status != 0): ?>
<?= Html::a('复制分享链接', null, ['class' => 'btn btn-primary', 'id' => 'copy-link-button']) ?>
<?= Html::a('访问分享链接', ['share/access', 'share_id' => $model->share_id, 'access_code' => $model->access_code], ['class' => 'btn btn-primary', 'target' => '_blank']) ?>
<?= Html::a('取消分享', ['share-manage-delete', 'share_id' => $model->share_id], [
'class' => 'btn btn-danger',
'data' => [
'confirm' => '确定要取消分享?',
'method' => 'post',
],
]) ?>
<?php else: ?>
<?= Html::a('复制分享链接', null, ['class' => 'btn btn-primary disabled', 'id' => 'copy-link-button', 'aria-disabled' => 'true']) ?>
<?= Html::a('访问分享链接', null, ['class' => 'btn btn-primary disabled', 'target' => '_blank', 'aria-disabled' => 'true']) ?>
<?= Html::a('取消分享', null, [
'class' => 'btn btn-danger disabled',
'aria-disabled' => 'true'
]) ?>
<?php endif; ?>
</p>
<?= DetailView::widget([
'model' => $model,
'attributes' => [
'share_id',
'sharer_id',
'file_relative_path',
'access_code',
'creation_date',
[
'attribute' => 'status',
'label' => '分享状态',
'value' => function ($model) {
return $model->status == 1 ? '有效' : '失效';
},
],
[
'attribute' => 'dl_count',
],
],
]) ?>
</div>
<?php
$this->registerJsFile('@web/js/share_view.js', ['depends' => [JqueryAsset::class], 'position' => View::POS_END]);
?>