diff --git a/app/Http/Controllers/Api/ProjectController.php b/app/Http/Controllers/Api/ProjectController.php index b33228a3..4c654207 100755 --- a/app/Http/Controllers/Api/ProjectController.php +++ b/app/Http/Controllers/Api/ProjectController.php @@ -946,12 +946,11 @@ class ProjectController extends AbstractController // $task_id = intval(Request::input('task_id')); // - $task = ProjectTask::userTask($task_id, ['taskUser', 'taskTag'], true, $project); + $task = ProjectTask::userTask($task_id, true, false, ['taskUser', 'taskTag']); // $data = $task->toArray(); - $data['project_name'] = $project?->name; - $data['column_name'] = ProjectColumn::whereId($task->column_id)->value('name'); - // + $data['project_name'] = $task->project?->name; + $data['column_name'] = $task->projectColumn?->name; return Base::retSuccess('success', $data); } @@ -1030,10 +1029,7 @@ class ProjectController extends AbstractController return Base::retError('文件不存在或已被删除'); } // - $task = ProjectTask::userTask($file->task_id, [], true, $project); - if (!$task->isOwner() && !$project->owner) { - return Base::retError('仅限项目或任务负责人操作'); - } + $task = ProjectTask::userTask($file->task_id, true, true); // $task->pushMsg('filedelete', $file); $file->delete(); @@ -1133,10 +1129,7 @@ class ProjectController extends AbstractController $task_id = intval(Request::input('task_id')); $name = Request::input('name'); // - $task = ProjectTask::userTask($task_id, [], true, $project); - if (!$task->isOwner() && !$project->owner) { - return Base::retError('仅限项目或任务负责人添加'); - } + $task = ProjectTask::userTask($task_id, true, true); // $task = ProjectTask::addTask([ 'name' => $name, @@ -1187,14 +1180,7 @@ class ProjectController extends AbstractController parse_str(Request::getContent(), $data); $task_id = intval($data['task_id']); // - $task = ProjectTask::userTask($task_id, [], true, $project); - // - if ($task->hasOwner()) { - // 任务有负责人后仅限项目或任务负责人修改 - if (!$task->isOwner() && !$project->owner) { - return Base::retError('仅限项目或任务负责人修改'); - } - } + $task = ProjectTask::userTask($task_id, true, 2); // 更新任务 $updateProject = false; $updateContent = false; @@ -1233,10 +1219,7 @@ class ProjectController extends AbstractController // $task_id = Base::getPostInt('task_id'); // - $task = ProjectTask::userTask($task_id, [], true, $project); - if (!$task->isOwner() && !$project->owner) { - return Base::retError('仅限项目或任务负责人上传'); - } + $task = ProjectTask::userTask($task_id, true, true); // $path = "uploads/task/" . $task->id . "/"; $image64 = Base::getPostValue('image64'); @@ -1350,10 +1333,7 @@ class ProjectController extends AbstractController $task_id = intval(Request::input('task_id')); $type = Request::input('type', 'add'); // - $task = ProjectTask::userTask($task_id, [], false, $project); - if (!$task->isOwner() && !$project->owner) { - return Base::retError('仅限项目或任务负责人操作'); - } + $task = ProjectTask::userTask($task_id, false, true); // if ($task->parent_id > 0) { return Base::retError('子任务不支持此功能'); @@ -1387,10 +1367,7 @@ class ProjectController extends AbstractController // $task_id = intval(Request::input('task_id')); // - $task = ProjectTask::userTask($task_id, [], true, $project); - if (!$task->isOwner() && !$project->owner) { - return Base::retError('仅限项目或任务负责人删除'); - } + $task = ProjectTask::userTask($task_id, true, true); // $task->deleteTask(); return Base::retSuccess('删除成功', ['id' => $task->id]); diff --git a/app/Models/FileContent.php b/app/Models/FileContent.php index 65c0b12b..e40d4e7d 100644 --- a/app/Models/FileContent.php +++ b/app/Models/FileContent.php @@ -8,9 +8,8 @@ use Illuminate\Database\Eloquent\SoftDeletes; use Response; /** - * Class FileContent + * App\Models\FileContent * - * @package App\Models * @property int $id * @property int|null $fid 文件ID * @property string|null $content 内容 diff --git a/app/Models/Project.php b/app/Models/Project.php index b793d6e1..f4cafb56 100644 --- a/app/Models/Project.php +++ b/app/Models/Project.php @@ -11,26 +11,19 @@ use Illuminate\Database\Eloquent\SoftDeletes; use Request; /** - * Class Project + * App\Models\Project * - * @package App\Models * @property int $id * @property string|null $name 名称 * @property string|null $desc 描述、备注 * @property int|null $userid 创建人 - * @property int|mixed $dialog_id 聊天会话ID + * @property int|null $dialog_id 聊天会话ID * @property string|null $archived_at 归档时间 * @property int|null $archived_userid 归档会员 * @property \Illuminate\Support\Carbon|null $created_at * @property \Illuminate\Support\Carbon|null $updated_at * @property \Illuminate\Support\Carbon|null $deleted_at * @property-read int $owner_userid - * @property-read int $task_complete - * @property-read int $task_my_complete - * @property-read int $task_my_num - * @property-read int $task_my_percent - * @property-read int $task_num - * @property-read int $task_percent * @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\ProjectColumn[] $projectColumn * @property-read int|null $project_column_count * @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\ProjectLog[] $projectLog @@ -337,20 +330,20 @@ class Project extends AbstractModel /** * 根据用户获取项目信息(用于判断会员是否存在项目内) * @param int $project_id - * @param null|bool $ignoreArchived 排除已归档 - * @param null|bool $mustOwner 是否仅限项目负责人 + * @param null|bool $archived true:仅限未归档, false:仅限已归档, null:不限制 + * @param null|bool $mustOwner true:仅限项目负责人, false:仅限非项目负责人, null:不限制 * @return self */ - public static function userProject($project_id, $ignoreArchived = true, $mustOwner = null) + public static function userProject($project_id, $archived = true, $mustOwner = null) { $project = self::authData()->where('projects.id', intval($project_id))->first(); if (empty($project)) { throw new ApiException('项目不存在或不在成员列表内', [ 'project_id' => $project_id ], -4001); } - if ($ignoreArchived === true && $project->archived_at != null) { + if ($archived === true && $project->archived_at != null) { throw new ApiException('项目已归档', [ 'project_id' => $project_id ], -4001); } - if ($ignoreArchived === false && $project->archived_at == null) { + if ($archived === false && $project->archived_at == null) { throw new ApiException('项目未归档', [ 'project_id' => $project_id ]); } if ($mustOwner === true && !$project->owner) { diff --git a/app/Models/ProjectColumn.php b/app/Models/ProjectColumn.php index 3e17d2b0..f446fdf9 100644 --- a/app/Models/ProjectColumn.php +++ b/app/Models/ProjectColumn.php @@ -9,9 +9,8 @@ use Illuminate\Database\Eloquent\SoftDeletes; use Request; /** - * Class ProjectColumn + * App\Models\ProjectColumn * - * @package App\Models * @property int $id * @property int|null $project_id 项目ID * @property string|null $name 列表名称 diff --git a/app/Models/ProjectLog.php b/app/Models/ProjectLog.php index d0047f67..cebc2319 100644 --- a/app/Models/ProjectLog.php +++ b/app/Models/ProjectLog.php @@ -3,9 +3,8 @@ namespace App\Models; /** - * Class ProjectLog + * App\Models\ProjectLog * - * @package App\Models * @property int $id * @property int|null $project_id 项目ID * @property int|null $column_id 列表ID diff --git a/app/Models/ProjectTask.php b/app/Models/ProjectTask.php index dae53c3d..09ebe035 100644 --- a/app/Models/ProjectTask.php +++ b/app/Models/ProjectTask.php @@ -42,12 +42,12 @@ use Request; * @property-read int $file_num * @property-read int $msg_num * @property-read bool $overdue - * @property-read bool $owner * @property-read int $percent * @property-read int $sub_complete * @property-read int $sub_num * @property-read bool $today * @property-read \App\Models\Project|null $project + * @property-read \App\Models\ProjectColumn|null $projectColumn * @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\ProjectTaskFile[] $taskFile * @property-read int|null $task_file_count * @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\ProjectTaskTag[] $taskTag @@ -91,11 +91,6 @@ class ProjectTask extends AbstractModel { use SoftDeletes; - const taskSelect = [ - 'project_tasks.*', - 'project_task_users.owner', - ]; - protected $appends = [ 'file_num', 'msg_num', @@ -223,6 +218,14 @@ class ProjectTask extends AbstractModel return $this->hasOne(Project::class, 'id', 'project_id'); } + /** + * @return \Illuminate\Database\Eloquent\Relations\HasOne + */ + public function projectColumn(): \Illuminate\Database\Eloquent\Relations\HasOne + { + return $this->hasOne(ProjectColumn::class, 'id', 'column_id'); + } + /** * @return \Illuminate\Database\Eloquent\Relations\HasOne */ @@ -869,32 +872,39 @@ class ProjectTask extends AbstractModel /** * 根据会员ID获取任务、项目信息(会员有任务权限 或 会员存在项目内) * @param int $task_id + * @param bool $archived true:仅限未归档, false:不限制 + * @param int|bool $mustOwner 0|false:不限制, 1|true:限制任务或项目负责人, 2:已有负责人才限制任务或项目负责人 * @param array $with - * @param bool $ignoreArchived 排除已归档 - * @param null $project * @return self */ - public static function userTask($task_id, $with = [], $ignoreArchived = true, &$project = null) + public static function userTask($task_id, $archived = true, $mustOwner = 0, $with = []) { - $task = self::with($with)->whereId(intval($task_id))->first(); + $task = self::with($with)->allData()->where("project_tasks.id", intval($task_id))->first(); + // if (empty($task)) { throw new ApiException('任务不存在', [ 'task_id' => $task_id ], -4002); } - if ($ignoreArchived && $task->archived_at != null) { + if ($archived === true && $task->archived_at != null) { throw new ApiException('任务已归档', [ 'task_id' => $task_id ], -4002); } // try { - $project = Project::userProject($task->project_id, $ignoreArchived); + $project = Project::userProject($task->project_id, $archived); } catch (Exception $e) { - if (ProjectTaskUser::whereUserid(User::userid())->whereTaskPid($task->id)->exists()) { - $project = Project::find($task->project_id); - if (empty($project)) { - throw new ApiException('项目不存在或已被删除', [ 'task_id' => $task_id ], -4002); - } - } else { + if ($task->owner === null) { throw new ApiException($e->getMessage(), [ 'task_id' => $task_id ], -4002); } + $project = Project::find($task->project_id); + if (empty($project)) { + throw new ApiException('项目不存在或已被删除', [ 'task_id' => $task_id ], -4002); + } + } + // + if ($mustOwner === 2) { + $mustOwner = $task->hasOwner() ? 1 : 0; + } + if (($mustOwner === 1 || $mustOwner === true) && !$task->owner && !$project->owner) { + throw new ApiException('仅限项目或任务负责人操作'); } // return $task; diff --git a/app/Models/ProjectTaskContent.php b/app/Models/ProjectTaskContent.php index cbf13629..3b6bdb1c 100644 --- a/app/Models/ProjectTaskContent.php +++ b/app/Models/ProjectTaskContent.php @@ -3,9 +3,8 @@ namespace App\Models; /** - * Class ProjectTaskContent + * App\Models\ProjectTaskContent * - * @package App\Models * @property int $id * @property int|null $project_id 项目ID * @property int|null $task_id 任务ID diff --git a/app/Models/ProjectTaskFile.php b/app/Models/ProjectTaskFile.php index 7b3307b3..aaec82f2 100644 --- a/app/Models/ProjectTaskFile.php +++ b/app/Models/ProjectTaskFile.php @@ -5,17 +5,16 @@ namespace App\Models; use App\Module\Base; /** - * Class ProjectTaskFile + * App\Models\ProjectTaskFile * - * @package App\Models * @property int $id * @property int|null $project_id 项目ID * @property int|null $task_id 任务ID * @property string|null $name 文件名称 * @property int|null $size 文件大小(B) * @property string|null $ext 文件格式 - * @property string|null $path 文件地址 - * @property string|null $thumb 缩略图 + * @property string $path 文件地址 + * @property string $thumb 缩略图 * @property int|null $userid 上传用户ID * @property int|null $download 下载次数 * @property \Illuminate\Support\Carbon|null $created_at diff --git a/app/Models/ProjectTaskTag.php b/app/Models/ProjectTaskTag.php index 893f5f18..f464c9d9 100644 --- a/app/Models/ProjectTaskTag.php +++ b/app/Models/ProjectTaskTag.php @@ -3,9 +3,8 @@ namespace App\Models; /** - * Class ProjectTaskTag + * App\Models\ProjectTaskTag * - * @package App\Models * @property int $id * @property int|null $project_id 项目ID * @property int|null $task_id 任务ID diff --git a/app/Models/ProjectTaskUser.php b/app/Models/ProjectTaskUser.php index 70aea076..d3c642a7 100644 --- a/app/Models/ProjectTaskUser.php +++ b/app/Models/ProjectTaskUser.php @@ -3,9 +3,8 @@ namespace App\Models; /** - * Class ProjectTaskUser + * App\Models\ProjectTaskUser * - * @package App\Models * @property int $id * @property int|null $project_id 项目ID * @property int|null $task_id 任务ID diff --git a/app/Models/ProjectUser.php b/app/Models/ProjectUser.php index eeada72c..fad1568f 100644 --- a/app/Models/ProjectUser.php +++ b/app/Models/ProjectUser.php @@ -5,9 +5,8 @@ namespace App\Models; use App\Module\Base; /** - * Class ProjectUser + * App\Models\ProjectUser * - * @package App\Models * @property int $id * @property int|null $project_id 项目ID * @property int|null $userid 成员ID diff --git a/app/Models/Setting.php b/app/Models/Setting.php index 8c439c82..a337cfc3 100644 --- a/app/Models/Setting.php +++ b/app/Models/Setting.php @@ -3,9 +3,8 @@ namespace App\Models; /** - * Class Setting + * App\Models\Setting * - * @package App\Models * @property int $id * @property string|null $name * @property string|null $desc 参数描述、备注 diff --git a/app/Models/Tmp.php b/app/Models/Tmp.php index dac12b88..6be31d31 100644 --- a/app/Models/Tmp.php +++ b/app/Models/Tmp.php @@ -3,9 +3,8 @@ namespace App\Models; /** - * Class Tmp + * App\Models\Tmp * - * @package App\Models * @property int $id * @property string|null $name * @property string|null $value diff --git a/app/Models/User.php b/app/Models/User.php index 4b666287..29cab32c 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -9,9 +9,8 @@ use Cache; use Carbon\Carbon; /** - * Class User + * App\Models\User * - * @package App\Models * @property int $userid * @property array $identity 身份 * @property string|null $az A-Z diff --git a/app/Models/WebSocket.php b/app/Models/WebSocket.php index 963f4f4d..f6b563c1 100644 --- a/app/Models/WebSocket.php +++ b/app/Models/WebSocket.php @@ -4,14 +4,13 @@ namespace App\Models; /** - * Class WebSocket + * App\Models\WebSocket * - * @package App\Models * @property int $id * @property string $key * @property string|null $fd - * @property int|null $userid * @property string|null $path + * @property int|null $userid * @property \Illuminate\Support\Carbon|null $created_at * @property \Illuminate\Support\Carbon|null $updated_at * @method static \Illuminate\Database\Eloquent\Builder|WebSocket newModelQuery() diff --git a/app/Models/WebSocketDialog.php b/app/Models/WebSocketDialog.php index cf982425..feddefa9 100644 --- a/app/Models/WebSocketDialog.php +++ b/app/Models/WebSocketDialog.php @@ -7,9 +7,8 @@ use Carbon\Carbon; use Illuminate\Database\Eloquent\SoftDeletes; /** - * Class WebSocketDialog + * App\Models\WebSocketDialog * - * @package App\Models * @property int $id * @property string|null $type 对话类型 * @property string|null $group_type 聊天室类型 diff --git a/app/Models/WebSocketDialogMsg.php b/app/Models/WebSocketDialogMsg.php index 8697095d..cdb4f821 100644 --- a/app/Models/WebSocketDialogMsg.php +++ b/app/Models/WebSocketDialogMsg.php @@ -10,9 +10,8 @@ use Carbon\Carbon; use Hhxsv5\LaravelS\Swoole\Task\Task; /** - * Class WebSocketDialogMsg + * App\Models\WebSocketDialogMsg * - * @package App\Models * @property int $id * @property int|null $dialog_id 对话ID * @property int|null $userid 发送会员ID diff --git a/app/Models/WebSocketDialogMsgRead.php b/app/Models/WebSocketDialogMsgRead.php index f474393c..c2a6be17 100644 --- a/app/Models/WebSocketDialogMsgRead.php +++ b/app/Models/WebSocketDialogMsgRead.php @@ -3,9 +3,8 @@ namespace App\Models; /** - * Class WebSocketDialogMsgRead + * App\Models\WebSocketDialogMsgRead * - * @package App\Models * @property int $id * @property int|null $dialog_id 对话ID * @property int|null $msg_id 消息ID diff --git a/app/Models/WebSocketDialogUser.php b/app/Models/WebSocketDialogUser.php index ba6091d4..b06d770d 100644 --- a/app/Models/WebSocketDialogUser.php +++ b/app/Models/WebSocketDialogUser.php @@ -3,9 +3,8 @@ namespace App\Models; /** - * Class WebSocketDialogUser + * App\Models\WebSocketDialogUser * - * @package App\Models * @property int $id * @property int|null $dialog_id 对话ID * @property int|null $userid 会员ID diff --git a/app/Models/WebSocketTmpMsg.php b/app/Models/WebSocketTmpMsg.php index 73671881..884e2f5e 100644 --- a/app/Models/WebSocketTmpMsg.php +++ b/app/Models/WebSocketTmpMsg.php @@ -3,9 +3,8 @@ namespace App\Models; /** - * Class WebSocketTmpMsg + * App\Models\WebSocketTmpMsg * - * @package App\Models * @property int $id * @property string|null $md5 MD5(会员ID-消息) * @property string|null $msg 详细消息 diff --git a/resources/assets/js/functions/common.js b/resources/assets/js/functions/common.js index 43c999f3..0a5e0990 100755 --- a/resources/assets/js/functions/common.js +++ b/resources/assets/js/functions/common.js @@ -142,10 +142,10 @@ */ getMiddle(string, start, end) { string = string.toString(); - if (this.ishave(start) && this.strExists(string, start)) { + if (this.isHave(start) && this.strExists(string, start)) { string = string.substring(string.indexOf(start) + start.length); } - if (this.ishave(end) && this.strExists(string, end)) { + if (this.isHave(end) && this.strExists(string, end)) { string = string.substring(0, string.indexOf(end)); } return string; @@ -160,7 +160,7 @@ */ subString(string, start, end) { string += ""; - if (!this.ishave(end)) { + if (!this.isHave(end)) { end = string.length; } return string.substring(start, end); @@ -187,7 +187,7 @@ * @param set * @returns {boolean} */ - ishave(set) { + isHave(set) { return !!(set !== null && set !== "null" && set !== undefined && set !== "undefined" && set); }, @@ -197,12 +197,12 @@ * @param fixed * @returns {number} */ - runNum(str, fixed) { + runNum(str, fixed = null) { let _s = Number(str); if (_s + "" === "NaN") { _s = 0; } - if (/^[0-9]*[1-9][0-9]*$/.test(fixed)) { + if (fixed && /^[0-9]*[1-9][0-9]*$/.test(fixed)) { _s = _s.toFixed(fixed); let rs = _s.indexOf('.'); if (rs < 0) { @@ -349,15 +349,6 @@ return /^1([3456789])\d{9}$/.test(str); }, - /** - * 是否手机号码 - * @param phone - * @returns {boolean} - */ - isPhone(phone) { - return this.isMobile(phone); - }, - /** * 根据两点间的经纬度计算距离 * @param lng1 @@ -416,24 +407,6 @@ } }, - /** - * 克隆对象 - * @param myObj - * @returns {*} - */ - cloneData(myObj) { - if(typeof(myObj) !== 'object') return myObj; - if(myObj === null) return myObj; - // - if (typeof myObj.length === 'number') { - let [ ...myNewObj ] = myObj; - return myNewObj; - }else{ - let { ...myNewObj } = myObj; - return myNewObj; - } - }, - /** * 克隆对象 * @param myObj @@ -452,7 +425,7 @@ * @param defaultVal * @returns {*} */ - jsonParse(str, defaultVal) { + jsonParse(str, defaultVal = undefined) { if (str === null) { return defaultVal ? defaultVal : {}; } @@ -472,7 +445,7 @@ * @param defaultVal * @returns {string} */ - jsonStringify(json, defaultVal) { + jsonStringify(json, defaultVal = undefined) { if (typeof json !== 'object') { return json; } @@ -544,10 +517,10 @@ if (this.count(obj) === 0 || this.count(keys) === 0) { return ""; } - let arr = keys.replace(/,/g, "|").replace(/\./g, "|").split("|"); - $A.each(arr, (index, key) => { + let array = keys.replace(/,/g, "|").replace(/\./g, "|").split("|"); + array.some(key => { object = typeof object[key] === "undefined" ? "" : object[key]; - }); + }) return object; }, @@ -736,7 +709,7 @@ * @param object * @param content */ - insert2Input (object, content) { + insert2Input(object, content) { if (object === null || typeof object !== "object") return; if (typeof object.length === 'number' && object.length > 0) object = object[0]; @@ -1045,7 +1018,7 @@ * ============================================================================= */ $.extend({ - serializeObject (obj, parents) { + serializeObject(obj, parents) { if (typeof obj === 'string') return obj; let resultArray = []; let separator = '&'; diff --git a/resources/assets/js/pages/manage/components/Calendar.vue b/resources/assets/js/pages/manage/components/Calendar.vue index 827fb564..76e1f974 100644 --- a/resources/assets/js/pages/manage/components/Calendar.vue +++ b/resources/assets/js/pages/manage/components/Calendar.vue @@ -119,21 +119,21 @@ export default { }, theme: { handler(newValue) { - this.calendarInstance.setTheme(this.cloneData(newValue)); + this.calendarInstance.setTheme($A.cloneJSON(newValue)); }, deep: true }, week: { handler(newValue) { const silent = this.view !== 'week' && this.view !== 'day'; - this.calendarInstance.setOptions({week: this.cloneData(newValue)}, silent); + this.calendarInstance.setOptions({week: $A.cloneJSON(newValue)}, silent); }, deep: true }, month: { handler(newValue) { const silent = this.view !== 'month'; - this.calendarInstance.setOptions({month: this.cloneData(newValue)}, silent); + this.calendarInstance.setOptions({month: $A.cloneJSON(newValue)}, silent); }, deep: true }, @@ -176,9 +176,6 @@ export default { this.calendarInstance.destroy(); }, methods: { - cloneData(data) { - return JSON.parse(JSON.stringify(data)); - }, addEventListeners() { for (const eventName of Object.keys(this.$listeners)) { this.calendarInstance.on(eventName, (...args) => this.$emit(eventName, ...args));