diff --git a/app/Http/Controllers/Api/UsersController.php b/app/Http/Controllers/Api/UsersController.php index 63031664b..34c64d9e8 100755 --- a/app/Http/Controllers/Api/UsersController.php +++ b/app/Http/Controllers/Api/UsersController.php @@ -3188,6 +3188,58 @@ class UsersController extends AbstractController return Base::retSuccess($message, $result); } + /** + * @api {post} api/users/favorite/remark 47-1. 修改收藏备注 + * + * @apiDescription 需要token身份 + * @apiVersion 1.0.0 + * @apiGroup users + * @apiName favorite__remark + * + * @apiParam {String} type 收藏类型 (task/project/file/message) + * @apiParam {Number} id 收藏对象ID + * @apiParam {String} remark 收藏备注(<=255个字符) + * + * @apiSuccess {Number} ret 返回状态码(1正确、0错误) + * @apiSuccess {String} msg 返回信息(错误描述) + * @apiSuccess {Object} data 返回数据 + */ + public function favorite__remark() + { + $user = User::auth(); + // + $type = trim(Request::input('type')); + $id = intval(Request::input('id')); + $remark = trim(Request::input('remark', '')); + + if (!$type || $id <= 0) { + return Base::retError('参数错误'); + } + + $allowedTypes = [UserFavorite::TYPE_TASK, UserFavorite::TYPE_PROJECT, UserFavorite::TYPE_FILE, UserFavorite::TYPE_MESSAGE]; + if (!in_array($type, $allowedTypes)) { + return Base::retError('无效的收藏类型'); + } + + if ($remark === '') { + return Base::retError('请输入修改备注'); + } + + if (mb_strlen($remark) > 255) { + return Base::retError('备注最多支持255个字符'); + } + + $favorite = UserFavorite::updateRemark($user->userid, $type, $id, $remark); + + if (!$favorite) { + return Base::retError('收藏记录不存在'); + } + + return Base::retSuccess('修改备注成功', [ + 'remark' => $favorite->remark, + ]); + } + /** * @api {post} api/users/favorites/clean 48. 清理用户收藏 * diff --git a/app/Models/UserFavorite.php b/app/Models/UserFavorite.php index 49af29132..ff19943dd 100644 --- a/app/Models/UserFavorite.php +++ b/app/Models/UserFavorite.php @@ -44,6 +44,7 @@ class UserFavorite extends AbstractModel 'userid', 'favoritable_type', 'favoritable_id', + 'remark', ]; /** @@ -79,16 +80,42 @@ class UserFavorite extends AbstractModel if ($favorite) { // 取消收藏 $favorite->delete(); - return ['favorited' => false, 'action' => 'removed']; - } else { - // 添加收藏 - self::create([ - 'userid' => $userid, - 'favoritable_type' => $type, - 'favoritable_id' => $id, - ]); - return ['favorited' => true, 'action' => 'added']; + return ['favorited' => false, 'action' => 'removed', 'remark' => '']; } + + // 添加收藏 + $favorite = self::create([ + 'userid' => $userid, + 'favoritable_type' => $type, + 'favoritable_id' => $id, + ]); + + return ['favorited' => true, 'action' => 'added', 'remark' => $favorite->remark ?? '']; + } + + /** + * 更新收藏备注 + * @param int $userid + * @param string $type + * @param int $id + * @param string $remark + * @return static|null + */ + public static function updateRemark($userid, $type, $id, $remark) + { + $favorite = self::whereUserid($userid) + ->whereFavoritableType($type) + ->whereFavoritableId($id) + ->first(); + + if (!$favorite) { + return null; + } + + $favorite->remark = $remark; + $favorite->save(); + + return $favorite; } /** @@ -192,6 +219,7 @@ class UserFavorite extends AbstractModel 'flow_item_status' => $flowItemStatus, 'flow_item_color' => $flowItemColor, 'favorited_at' => Carbon::parse($favorite->created_at)->format('Y-m-d H:i:s'), + 'remark' => $favorite->remark, ]; } } @@ -211,6 +239,7 @@ class UserFavorite extends AbstractModel 'desc' => $project->desc, 'archived_at' => $project->archived_at, 'favorited_at' => Carbon::parse($favorite->created_at)->format('Y-m-d H:i:s'), + 'remark' => $favorite->remark, ]; } } @@ -231,6 +260,7 @@ class UserFavorite extends AbstractModel 'size' => $file->size, 'pid' => $file->pid, 'favorited_at' => Carbon::parse($favorite->created_at)->format('Y-m-d H:i:s'), + 'remark' => $favorite->remark, ]; } } @@ -263,6 +293,7 @@ class UserFavorite extends AbstractModel 'userid' => $message->userid, 'type' => $message->type, 'favorited_at' => Carbon::parse($favorite->created_at)->format('Y-m-d H:i:s'), + 'remark' => $favorite->remark, ]; } } diff --git a/database/migrations/2025_09_22_102100_add_remark_to_user_favorites_table.php b/database/migrations/2025_09_22_102100_add_remark_to_user_favorites_table.php new file mode 100644 index 000000000..4e65cd2ff --- /dev/null +++ b/database/migrations/2025_09_22_102100_add_remark_to_user_favorites_table.php @@ -0,0 +1,36 @@ +string('remark', 255)->default('')->after('favoritable_id')->comment('收藏备注'); + } + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('user_favorites', function (Blueprint $table) { + if (Schema::hasColumn('user_favorites', 'remark')) { + $table->dropColumn('remark'); + } + }); + } +} diff --git a/resources/assets/js/app.js b/resources/assets/js/app.js index 034ee5361..1b124b78c 100644 --- a/resources/assets/js/app.js +++ b/resources/assets/js/app.js @@ -108,6 +108,11 @@ router.afterEach(() => { store.commit('route/loading', false); }); +// 消息配置 +ViewUI.Message.config({ + duration: 2.5 +}); + // 加载路由 Vue.prototype.goForward = function(route, isReplace, autoBroadcast = true) { if ($A.Ready && $A.isSubElectron && autoBroadcast) { diff --git a/resources/assets/js/pages/manage/components/DialogWrapper.vue b/resources/assets/js/pages/manage/components/DialogWrapper.vue index f3549b123..9ed4ef8a1 100644 --- a/resources/assets/js/pages/manage/components/DialogWrapper.vue +++ b/resources/assets/js/pages/manage/components/DialogWrapper.vue @@ -4079,25 +4079,22 @@ export default { if (this.operateVisible) { return } - + this.$store.dispatch("toggleFavorite", { type: 'message', id: this.operateItem.id - }).then(({data, msg}) => { + }).then(({data}) => { this.$set(this.operateItem, 'favorited', data.favorited); const message = this.dialogMsgs.find(msg => msg.id === this.operateItem.id); if (message) { this.$set(message, 'favorited', data.favorited); } - this.$Message.success(msg); - }).catch(({msg}) => { - $A.messageError(msg); }); }, checkMessageFavoriteStatus(message) { if (!message.id) return; - + this.$store.dispatch("checkFavoriteStatus", { type: 'message', id: message.id diff --git a/resources/assets/js/pages/manage/components/FavoriteManagement.vue b/resources/assets/js/pages/manage/components/FavoriteManagement.vue index 66db01f6b..eb3746679 100644 --- a/resources/assets/js/pages/manage/components/FavoriteManagement.vue +++ b/resources/assets/js/pages/manage/components/FavoriteManagement.vue @@ -66,10 +66,11 @@