mirror of
https://github.com/kuaifan/dootask.git
synced 2026-01-01 00:38:14 +00:00
fix: 添加任务时不设置时间无须提示任务冲突
This commit is contained in:
parent
d54c86cec9
commit
81957c9396
@ -1111,7 +1111,7 @@ class ProjectController extends AbstractController
|
||||
/**
|
||||
* @api {get} api/project/task/easylists 20. 任务列表-简单的
|
||||
*
|
||||
* @apiDescription 需要token身份
|
||||
* @apiDescription 需要token身份,主要用于判断是否有时间冲突的任务
|
||||
* @apiVersion 1.0.0
|
||||
* @apiGroup project
|
||||
* @apiName task__easylists
|
||||
@ -1130,23 +1130,24 @@ class ProjectController extends AbstractController
|
||||
//
|
||||
$taskid = trim(Request::input('taskid'));
|
||||
$userid = Request::input('userid');
|
||||
$timerange = Request::input('timerange');
|
||||
$timerange = TimeRange::parse(Request::input('timerange'));
|
||||
//
|
||||
$list = ProjectTask::with(['taskUser'])
|
||||
->select('projects.name as project_name', 'project_tasks.id', 'project_tasks.name', 'project_tasks.start_at', 'project_tasks.end_at')
|
||||
->select([
|
||||
'projects.name as project_name',
|
||||
'project_tasks.id',
|
||||
'project_tasks.name',
|
||||
'project_tasks.start_at',
|
||||
'project_tasks.end_at'
|
||||
])
|
||||
->join('projects','project_tasks.project_id','=','projects.id')
|
||||
->leftJoin('project_task_users', function ($query) {
|
||||
$query->on('project_tasks.id', '=', 'project_task_users.task_id')->where('project_task_users.owner', '=', 1);
|
||||
})
|
||||
->whereIn('project_task_users.userid', is_array($userid) ? $userid : explode(',', $userid) )
|
||||
->when(!empty($timerange), function ($query) use ($timerange) {
|
||||
if (!is_array($timerange)) {
|
||||
$timerange = explode(',', $timerange);
|
||||
}
|
||||
if (Base::isDateOrTime($timerange[0]) && Base::isDateOrTime($timerange[1])) {
|
||||
$query->where('project_tasks.start_at', '<=', Carbon::parse($timerange[1])->endOfDay());
|
||||
$query->where('project_tasks.end_at', '>=', Carbon::parse($timerange[0])->startOfDay());
|
||||
}
|
||||
->when($timerange->isExist(), function ($query) use ($timerange) {
|
||||
$query->where('project_tasks.start_at', '<=', $timerange->lastTime()->endOfDay());
|
||||
$query->where('project_tasks.end_at', '>=', $timerange->firstTime()->startOfDay());
|
||||
})
|
||||
->when(!empty($taskid), function ($query) use ($taskid) {
|
||||
$query->where('project_tasks.id', "!=", $taskid);
|
||||
|
||||
@ -15,12 +15,17 @@ class TimeRange
|
||||
public function __construct($data)
|
||||
{
|
||||
if (is_array($data)) {
|
||||
$range = $this->format($data['timerange']);
|
||||
if ($data['updated_at'] || $data['at_after']) {
|
||||
$range[0] = $data['updated_at'] ?: $data['at_after'];
|
||||
}
|
||||
if ($data['deleted_at']) {
|
||||
$range[1] = $data['deleted_at'];
|
||||
$keys = array_keys($data);
|
||||
if (count($keys) === 2 && $keys[0] === 0 && $keys[1] === 1) {
|
||||
$range = $data;
|
||||
} else {
|
||||
$range = $this->format($data['timerange']);
|
||||
if ($data['updated_at'] || $data['at_after']) {
|
||||
$range[0] = $data['updated_at'] ?: $data['at_after'];
|
||||
}
|
||||
if ($data['deleted_at']) {
|
||||
$range[1] = $data['deleted_at'];
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$range = $this->format($data);
|
||||
@ -34,6 +39,30 @@ class TimeRange
|
||||
$this->deleted = $deleted ? Carbon::parse($deleted)->setTimezone($timezone) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Carbon|null
|
||||
*/
|
||||
public function firstTime(): ?Carbon
|
||||
{
|
||||
return $this->updated;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Carbon|null
|
||||
*/
|
||||
public function lastTime(): ?Carbon
|
||||
{
|
||||
return $this->deleted;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isExist(): bool
|
||||
{
|
||||
return $this->updated && $this->deleted;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $timerange
|
||||
* - 格式1:2021-01-01 00:00:00,2021-01-01 23:59:59
|
||||
|
||||
@ -502,7 +502,7 @@ export default {
|
||||
this.addData = Object.assign({}, this.addData, data);
|
||||
},
|
||||
|
||||
async onAdd(again,affirm=false) {
|
||||
async onAdd(again, affirm = false) {
|
||||
if (!this.addData.name) {
|
||||
$A.messageError("任务描述不能为空");
|
||||
return;
|
||||
@ -512,7 +512,7 @@ export default {
|
||||
|
||||
// 存在任务提示
|
||||
if (!affirm && this.addData.owner.length > 0) {
|
||||
this.$refs['taskExistTipsRef'].isExistTask({
|
||||
this.$refs.taskExistTipsRef.isExistTask({
|
||||
userids: this.addData.owner,
|
||||
timerange: this.addData.times
|
||||
}).then(res => {
|
||||
|
||||
@ -1048,7 +1048,7 @@ export default {
|
||||
if (!desc) {
|
||||
return `请输入修改备注`
|
||||
}
|
||||
this.updateParams = Object.assign(params, { desc })
|
||||
this.updateParams = Object.assign(params, {desc})
|
||||
if (params.start_at && params.end_at && this.$refs.taskExistTipsRef) {
|
||||
this.$refs.taskExistTipsRef.isExistTask({
|
||||
taskid: this.taskDetail.id,
|
||||
|
||||
@ -69,9 +69,13 @@ export default {
|
||||
return string
|
||||
},
|
||||
|
||||
isExistTask({ userids, timerange, taskid }) {
|
||||
isExistTask({userids, timerange, taskid}) {
|
||||
this.isExist = false;
|
||||
return new Promise(async resolve => {
|
||||
if ($A.isArray(timerange) && (!timerange[0] || !timerange[1])) {
|
||||
resolve(this.isExist)
|
||||
return false;
|
||||
}
|
||||
this.$store.dispatch("call", {
|
||||
url: 'project/task/easylists',
|
||||
data: {
|
||||
@ -80,7 +84,7 @@ export default {
|
||||
taskid: taskid
|
||||
},
|
||||
method: 'get',
|
||||
}).then(({ data }) => {
|
||||
}).then(({data}) => {
|
||||
if (data.data.length > 0) {
|
||||
this.show = true;
|
||||
let taskObj = {}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user