文件收集功能(4/10)
实现基本创建文件收集功能 具体收集功能后续增加
This commit is contained in:
parent
c22b132070
commit
84886de324
@ -4,6 +4,7 @@ namespace app\controllers;
|
||||
|
||||
use app\models\CollectionTasks;
|
||||
use app\models\CollectionSearch;
|
||||
use Yii;
|
||||
use yii\web\Controller;
|
||||
use yii\web\NotFoundHttpException;
|
||||
use yii\filters\VerbFilter;
|
||||
@ -68,10 +69,14 @@ class CollectionController extends Controller
|
||||
public function actionCreate()
|
||||
{
|
||||
$model = new CollectionTasks();
|
||||
$model->scenario = 'create'; // 设置场景
|
||||
|
||||
if ($this->request->isPost) {
|
||||
if ($model->load($this->request->post()) && $model->save()) {
|
||||
return $this->redirect(['view', 'id' => $model->id]);
|
||||
if ($model->load($this->request->post())) {
|
||||
$model->user_id = Yii::$app->user->id; // 手动设置user_id字段的值
|
||||
if ($model->save()) {
|
||||
return $this->redirect(['view', 'id' => $model->id]);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$model->loadDefaultValues();
|
||||
@ -82,26 +87,6 @@ class CollectionController extends Controller
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates an existing CollectionTasks model.
|
||||
* If update is successful, the browser will be redirected to the 'view' page.
|
||||
* @param int $id ID
|
||||
* @return string|\yii\web\Response
|
||||
* @throws NotFoundHttpException if the model cannot be found
|
||||
*/
|
||||
public function actionUpdate($id)
|
||||
{
|
||||
$model = $this->findModel($id);
|
||||
|
||||
if ($this->request->isPost && $model->load($this->request->post()) && $model->save()) {
|
||||
return $this->redirect(['view', 'id' => $model->id]);
|
||||
}
|
||||
|
||||
return $this->render('update', [
|
||||
'model' => $model,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes an existing CollectionTasks model.
|
||||
* If deletion is successful, the browser will be redirected to the 'index' page.
|
||||
|
@ -3,6 +3,7 @@
|
||||
namespace app\models;
|
||||
|
||||
use Yii;
|
||||
use yii\db\ActiveRecord;
|
||||
|
||||
/**
|
||||
* This is the model class for table "collection_tasks".
|
||||
@ -16,8 +17,10 @@ use Yii;
|
||||
* @property CollectionUploaded[] $collectionUploadeds
|
||||
* @property User $user
|
||||
*/
|
||||
class CollectionTasks extends \yii\db\ActiveRecord
|
||||
class CollectionTasks extends ActiveRecord
|
||||
{
|
||||
const SCENARIO_CREATE = 'create';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
@ -33,6 +36,7 @@ class CollectionTasks extends \yii\db\ActiveRecord
|
||||
{
|
||||
return [
|
||||
[['user_id', 'folder_path', 'secret'], 'required'],
|
||||
[['folder_path', 'secret'], 'required', 'on' => self::SCENARIO_CREATE],
|
||||
[['user_id'], 'integer'],
|
||||
[['created_at'], 'safe'],
|
||||
[['folder_path', 'secret'], 'string', 'max' => 255],
|
||||
@ -54,6 +58,16 @@ class CollectionTasks extends \yii\db\ActiveRecord
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function scenarios()
|
||||
{
|
||||
$scenarios = parent::scenarios();
|
||||
$scenarios[self::SCENARIO_CREATE] = ['folder_path', 'secret']; // 在这里列出你想在创建收集任务时验证的属性
|
||||
return $scenarios;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets query for [[CollectionUploadeds]].
|
||||
*
|
||||
|
@ -1,29 +0,0 @@
|
||||
<?php
|
||||
|
||||
use yii\helpers\Html;
|
||||
use yii\widgets\ActiveForm;
|
||||
|
||||
/** @var yii\web\View $this */
|
||||
/** @var app\models\CollectionTasks $model */
|
||||
/** @var yii\widgets\ActiveForm $form */
|
||||
?>
|
||||
|
||||
<div class="collection-tasks-form">
|
||||
|
||||
<?php $form = ActiveForm::begin(); ?>
|
||||
|
||||
<?= $form->field($model, 'user_id')->textInput() ?>
|
||||
|
||||
<?= $form->field($model, 'folder_path')->textInput(['maxlength' => true]) ?>
|
||||
|
||||
<?= $form->field($model, 'created_at')->textInput() ?>
|
||||
|
||||
<?= $form->field($model, 'secret')->textInput(['maxlength' => true]) ?>
|
||||
|
||||
<div class="form-group">
|
||||
<?= Html::submitButton('Save', ['class' => 'btn btn-success']) ?>
|
||||
</div>
|
||||
|
||||
<?php ActiveForm::end(); ?>
|
||||
|
||||
</div>
|
@ -1,20 +1,27 @@
|
||||
<?php
|
||||
|
||||
use yii\helpers\Html;
|
||||
use yii\widgets\ActiveForm;
|
||||
|
||||
/** @var yii\web\View $this */
|
||||
/** @var app\models\CollectionTasks $model */
|
||||
|
||||
$this->title = 'new 文件收集';
|
||||
$this->params['breadcrumbs'][] = ['label' => 'Collection Tasks', 'url' => ['index']];
|
||||
$this->params['breadcrumbs'][] = $this->title;
|
||||
/** @var yii\widgets\ActiveForm $form */
|
||||
?>
|
||||
<div class="collection-tasks-create">
|
||||
|
||||
<h1><?= Html::encode($this->title) ?></h1>
|
||||
<div class="collection-tasks-form">
|
||||
|
||||
<?= $this->render('_form', [
|
||||
'model' => $model,
|
||||
]) ?>
|
||||
<?php $form = ActiveForm::begin([
|
||||
'action' => ['collection/create'], // 指定表单提交的URL
|
||||
]); ?>
|
||||
|
||||
<?= $form->field($model, 'folder_path')->textInput(['maxlength' => true, 'readonly' => true]) ?>
|
||||
|
||||
<?= $form->field($model, 'secret')->textInput(['maxlength' => true]) ?>
|
||||
|
||||
<div class="form-group">
|
||||
<?= Html::submitButton('创建', ['class' => 'btn btn-success']) ?>
|
||||
</div>
|
||||
|
||||
<?php ActiveForm::end(); ?>
|
||||
|
||||
</div>
|
||||
|
@ -36,6 +36,7 @@ $this->params['breadcrumbs'][] = $this->title;
|
||||
'secret',
|
||||
[
|
||||
'class' => ActionColumn::className(),
|
||||
'template' => '{view} {delete}',
|
||||
'urlCreator' => function ($action, CollectionTasks $model, $key, $index, $column) {
|
||||
return Url::toRoute([$action, 'id' => $model->id]);
|
||||
}
|
||||
|
@ -2,6 +2,8 @@
|
||||
|
||||
use yii\grid\GridView;
|
||||
use yii\helpers\Html;
|
||||
use yii\web\JqueryAsset;
|
||||
use yii\web\View;
|
||||
use yii\web\YiiAsset;
|
||||
use yii\widgets\DetailView;
|
||||
use app\models\CollectionUploadedSearch;
|
||||
@ -9,8 +11,8 @@ use app\models\CollectionUploadedSearch;
|
||||
/** @var yii\web\View $this */
|
||||
/** @var app\models\CollectionTasks $model */
|
||||
|
||||
$this->title = $model->id;
|
||||
$this->params['breadcrumbs'][] = ['label' => 'Collection Tasks', 'url' => ['index']];
|
||||
$this->title = '文件收集ID ' . $model->id;
|
||||
$this->params['breadcrumbs'][] = ['label' => '文件收集', 'url' => ['index']];
|
||||
$this->params['breadcrumbs'][] = $this->title;
|
||||
YiiAsset::register($this);
|
||||
|
||||
@ -23,11 +25,12 @@ $dataProvider->query->andWhere(['task_id' => $model->id]);
|
||||
<h1><?= Html::encode($this->title) ?></h1>
|
||||
|
||||
<p>
|
||||
<?= Html::a('Update', ['update', 'id' => $model->id], ['class' => 'btn btn-primary']) ?>
|
||||
<?= Html::a('Delete', ['delete', 'id' => $model->id], [
|
||||
<?= Html::a('复制收集链接', null, ['class' => 'btn btn-primary', 'id' => 'copy-link-button']) ?>
|
||||
<?= Html::a('访问收集链接', ['collection/access', 'id' => $model->id, '$secret' => $model->secret], ['class' => 'btn btn-primary', 'target' => '_blank']) ?>
|
||||
<?= Html::a('取消收集', ['delete', 'id' => $model->id], [
|
||||
'class' => 'btn btn-danger',
|
||||
'data' => [
|
||||
'confirm' => 'Are you sure you want to delete this item?',
|
||||
'confirm' => '你确定要取消这个收集任务吗?已收集的文件不会被删除',
|
||||
'method' => 'post',
|
||||
],
|
||||
]) ?>
|
||||
@ -37,14 +40,13 @@ $dataProvider->query->andWhere(['task_id' => $model->id]);
|
||||
'model' => $model,
|
||||
'attributes' => [
|
||||
'id',
|
||||
'user_id',
|
||||
'folder_path',
|
||||
'created_at',
|
||||
'secret',
|
||||
],
|
||||
]) ?>
|
||||
|
||||
<h2>收集情况:</h2>
|
||||
<h2>文件收集情况:</h2>
|
||||
<?= GridView::widget([
|
||||
'dataProvider' => $dataProvider,
|
||||
'filterModel' => $searchModel,
|
||||
@ -58,3 +60,6 @@ $dataProvider->query->andWhere(['task_id' => $model->id]);
|
||||
],
|
||||
]); ?>
|
||||
</div>
|
||||
<?php
|
||||
$this->registerJsFile('@web/js/collection_view.js', ['depends' => [JqueryAsset::class], 'position' => View::POS_END]);
|
||||
?>
|
||||
|
12
web/js/collection_view.js
Normal file
12
web/js/collection_view.js
Normal file
@ -0,0 +1,12 @@
|
||||
$(document).ready(function() {
|
||||
$('#copy-link-button').click(function() {
|
||||
var id = $('table.detail-view tbody tr:first-child td').text();
|
||||
var secret = $('table.detail-view tbody tr:nth-child(4) td').text(); // 获取访问密码
|
||||
var shareLink = window.location.origin + '/index.php?r=collection%2Faccess&id=' + id + '&secret=' + secret; // 将访问密码添加到分享链接中
|
||||
navigator.clipboard.writeText(shareLink).then(function() {
|
||||
alert('分享链接已复制到剪贴板');
|
||||
}).catch(function(error) {
|
||||
console.error('复制失败: ', error);
|
||||
});
|
||||
});
|
||||
});
|
Loading…
x
Reference in New Issue
Block a user