文件收集功能强化,支持上传文件时添加备注

This commit is contained in:
Chenx221 2024-04-30 15:02:56 +08:00
parent 6ec1ae8f8c
commit 365edd4452
Signed by: chenx221
GPG Key ID: D7A9EC07024C3021
6 changed files with 15 additions and 5 deletions

View File

@ -226,7 +226,7 @@ class CollectionController extends Controller
// 获取POST请求中的参数
$taskId = $request->post('CollectionTasks')['id'];
$subfolderName = $request->post('CollectionUploaded')['subfolder_name'];
$note = $request->post('CollectionUploaded')['note'];
// 获取发送POST请求的用户的IP地址
$uploaderIp = $request->userIP;
@ -245,6 +245,7 @@ class CollectionController extends Controller
$model->uploaded_at = date('Y-m-d H:i:s'); // 设置上传时间为当前时间
$model->subfolder_name = $subfolderName;
$model->user_agent = $request->userAgent;
$model->note = $note;
if ($model->validate()) {
// 进行文件上传
$targetDirectory = Yii::getAlias(Yii::$app->params['dataDirectory']) . '/' . $userId . '/' . $folderPath . '/' . $subfolderName;

View File

@ -15,6 +15,7 @@ use yii\db\ActiveRecord;
* @property string $uploaded_at 上传时间
* @property string $subfolder_name 对应的子文件夹名
* @property string $user_agent 浏览器UA信息
* @property string|null $note 用户设置的备注
*
* @property CollectionTasks $task
* @property User $user
@ -39,7 +40,8 @@ class CollectionUploaded extends ActiveRecord
[['user_id', 'task_id'], 'integer'],
[['uploaded_at'], 'safe'],
[['uploader_ip'], 'string', 'max' => 45],
[['subfolder_name'], 'string', 'max' => 255],
[['subfolder_name', 'user_agent'], 'string', 'max' => 255],
[['note'], 'string', 'max' => 100],
[['task_id'], 'exist', 'skipOnError' => true, 'targetClass' => CollectionTasks::class, 'targetAttribute' => ['task_id' => 'id']],
[['user_id'], 'exist', 'skipOnError' => true, 'targetClass' => User::class, 'targetAttribute' => ['user_id' => 'id']],
];
@ -58,6 +60,7 @@ class CollectionUploaded extends ActiveRecord
'uploaded_at' => '上传时间',
'subfolder_name' => '所在位置',
'user_agent' => '浏览器UA信息',
'note' => '用户设置的备注',
];
}

View File

@ -16,8 +16,8 @@ class CollectionUploadedSearch extends CollectionUploaded
public function rules(): array
{
return [
[['id', 'task_id'], 'integer'],
[['uploader_ip', 'uploaded_at', 'subfolder_name'], 'safe'],
[['id', 'user_id', 'task_id'], 'integer'],
[['uploader_ip', 'uploaded_at', 'subfolder_name', 'user_agent', 'note'], 'safe'],
];
}
@ -58,12 +58,15 @@ class CollectionUploadedSearch extends CollectionUploaded
// grid filtering conditions
$query->andFilterWhere([
'id' => $this->id,
'user_id' => $this->user_id,
'task_id' => $this->task_id,
'uploaded_at' => $this->uploaded_at,
]);
$query->andFilterWhere(['like', 'uploader_ip', $this->uploader_ip])
->andFilterWhere(['like', 'subfolder_name', $this->subfolder_name]);
->andFilterWhere(['like', 'subfolder_name', $this->subfolder_name])
->andFilterWhere(['like', 'user_agent', $this->user_agent])
->andFilterWhere(['like', 'note', $this->note]);
return $dataProvider;
}

View File

@ -52,6 +52,7 @@ $this->params['breadcrumbs'][] = $this->title;
'attribute' => 'user_agent',
'label' => 'User Agent',
],
'note'
],
'pager' => [
'class' => LinkPager::class,

View File

@ -30,6 +30,7 @@ $this->params['breadcrumbs'][] = $this->title;
<label for="uploader">要上传的文件:</label>
<input type="file" multiple name="files[]" id="uploader">
<?= $form->field($model2, 'note')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'id')->hiddenInput()->label(false) ?>

View File

@ -55,6 +55,7 @@ $dataProvider->query->andWhere(['task_id' => $model->id]);
'id',
'uploader_ip',
'uploaded_at',
'note',
[
'attribute' => 'subfolder_name',
'format' => 'raw',