feature: 任务复制

This commit is contained in:
zhuyu 2025-06-05 15:16:09 +08:00
parent 6b2ef44d68
commit 69ebde0732
3 changed files with 110 additions and 0 deletions

View File

@ -244,6 +244,53 @@ class Task extends Backend
$this->success();
}
public function copy($ids = null)
{
$row = $this->model->get($ids);
if (!$row) {
$this->error(__('No Results were found'));
}
$adminIds = $this->getDataLimitAdminIds();
if (is_array($adminIds) && !in_array($row[$this->dataLimitField], $adminIds)) {
$this->error(__('You have no permission'));
}
if (false === $this->request->isPost()) {
$this->view->assign('row', $row);
return $this->view->fetch();
}
$params = $this->request->post('row/a');
if (empty($params)) {
$this->error(__('Parameter %s can not be empty', ''));
}
$params = $this->preExcludeFields($params);
$result = false;
Db::startTrans();
try {
//是否采用模型验证
if ($this->modelValidate) {
$name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
$validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : $name) : $this->modelValidate;
$this->model->validateFailException()->validate($validate);
}
$params['create_time'] = date('Y-m-d H:i:s');
$params['update_time'] = date('Y-m-d H:i:s');
$params['admin_id'] = $this->auth->id;
$result = $this->model->allowField(true)->save($params);
Db::commit();
} catch (ValidateException|PDOException|Exception $e) {
Db::rollback();
$this->error($e->getMessage());
}
if (false === $result) {
$this->error(__('No rows were updated'));
}
$this->success();
}
public function notice($ids = null)
{

View File

@ -0,0 +1,52 @@
<form id="copy-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Type')}:</label>
<div class="col-xs-12 col-sm-8">
<select id="c-type" data-rule="required" class="form-control selectpicker" name="row[type]">
{foreach name="typeList" item="vo"}
<option value="{$key}" {in name="key" value="$row.type"}selected{/in}>{$vo}</option>
{/foreach}
</select>
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Title')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-title" class="form-control" name="row[title]" type="text" value="{$row.title|htmlentities}">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Desc')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-desc" class="form-control" name="row[desc]" type="text" value="{$row.desc|htmlentities}">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Exec_admin_id')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-exec_admin_id" data-rule="required" data-source="auth/admin/selectpage" data-field="nickname" class="form-control selectpage" name="row[exec_admin_id]" type="text" value="{$row.exec_admin_id|htmlentities}">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Expire_start_time')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-expire_start_time" data-rule="required" class="form-control datetimepicker" data-date-format="YYYY-MM-DD HH:mm:ss" data-use-current="true" name="row[expire_start_time]" type="text" value="{$row.expire_start_time}">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Expire_end_time')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-expire_end_time" data-rule="required" class="form-control datetimepicker" data-date-format="YYYY-MM-DD HH:mm:ss" data-use-current="true" name="row[expire_end_time]" type="text" value="{$row.expire_end_time}">
</div>
</div>
<div class="form-group layer-footer">
<label class="control-label col-xs-12 col-sm-2"></label>
<div class="col-xs-12 col-sm-8">
<button type="submit" class="btn btn-primary btn-embossed disabled">{:__('OK')}</button>
</div>
</div>
</form>

View File

@ -88,6 +88,14 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
extend: 'data-toggle="tooltip" data-container="body"',
classname: 'btn btn-xs btn-info btn-editone',
},
{
name: 'copy',
text: "复制",
title: "复制",
classname: 'btn btn-xs btn-warning btn-dialog',
icon: 'fa fa-copy',
url: 'oa/task/copy',
},
{
name: 'del',
text: "删除",
@ -110,6 +118,9 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
edit: function () {
Controller.api.bindevent();
},
copy: function () {
Controller.api.bindevent();
},
review: function () {
$(document).on('click', '.btn-preview', function (e) {