diff --git a/controllers/CollectionController.php b/controllers/CollectionController.php index 9177941..6e97792 100644 --- a/controllers/CollectionController.php +++ b/controllers/CollectionController.php @@ -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. diff --git a/models/CollectionTasks.php b/models/CollectionTasks.php index 5ed1949..9996a46 100644 --- a/models/CollectionTasks.php +++ b/models/CollectionTasks.php @@ -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]]. * diff --git a/views/collection/_form.php b/views/collection/_form.php deleted file mode 100644 index e7497f1..0000000 --- a/views/collection/_form.php +++ /dev/null @@ -1,29 +0,0 @@ - - -
- - - - field($model, 'user_id')->textInput() ?> - - field($model, 'folder_path')->textInput(['maxlength' => true]) ?> - - field($model, 'created_at')->textInput() ?> - - field($model, 'secret')->textInput(['maxlength' => true]) ?> - -
- 'btn btn-success']) ?> -
- - - -
diff --git a/views/collection/create.php b/views/collection/create.php index 3588dff..8316be5 100644 --- a/views/collection/create.php +++ b/views/collection/create.php @@ -1,20 +1,27 @@ title = 'new 文件收集'; -$this->params['breadcrumbs'][] = ['label' => 'Collection Tasks', 'url' => ['index']]; -$this->params['breadcrumbs'][] = $this->title; +/** @var yii\widgets\ActiveForm $form */ ?> -
-

title) ?>

+
- render('_form', [ - 'model' => $model, - ]) ?> + ['collection/create'], // 指定表单提交的URL + ]); ?> + + field($model, 'folder_path')->textInput(['maxlength' => true, 'readonly' => true]) ?> + + field($model, 'secret')->textInput(['maxlength' => true]) ?> + +
+ 'btn btn-success']) ?> +
+ +
diff --git a/views/collection/index.php b/views/collection/index.php index f9cb466..e920bb5 100644 --- a/views/collection/index.php +++ b/views/collection/index.php @@ -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]); } diff --git a/views/collection/view.php b/views/collection/view.php index 2c32fbb..5c29a93 100644 --- a/views/collection/view.php +++ b/views/collection/view.php @@ -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]);

title) ?>

- $model->id], ['class' => 'btn btn-primary']) ?> - $model->id], [ + 'btn btn-primary', 'id' => 'copy-link-button']) ?> + $model->id, '$secret' => $model->secret], ['class' => 'btn btn-primary', 'target' => '_blank']) ?> + $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', ], ]) ?> -

收集情况:

+

文件收集情况:

$dataProvider, 'filterModel' => $searchModel, @@ -58,3 +60,6 @@ $dataProvider->query->andWhere(['task_id' => $model->id]); ], ]); ?>
+registerJsFile('@web/js/collection_view.js', ['depends' => [JqueryAsset::class], 'position' => View::POS_END]); +?> diff --git a/web/js/collection_view.js b/web/js/collection_view.js new file mode 100644 index 0000000..744b5a7 --- /dev/null +++ b/web/js/collection_view.js @@ -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); + }); + }); +}); \ No newline at end of file