From f0566d78ec8af2286d0f202e7d84a33336c203f6 Mon Sep 17 00:00:00 2001 From: chenlong Date: Sun, 8 Oct 2023 19:07:37 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=A8=A1=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Enums/NotebookEnumMode.php | 23 +++++------- Enums/NotebookUserEnumMode.php | 48 +++++++++++++++++++++++++ Enums/NotebookUserEnumStatus.php | 48 +++++++++++++++++++++++++ Model/Notebook.php | 12 ++++--- Model/NotebookUser.php | 54 +++++++++++++++++++++++++++++ Service/Admin/NotebookService.php | 3 +- View/Admin/Notebook/lists.blade.php | 39 +++++++++++---------- 7 files changed, 187 insertions(+), 40 deletions(-) create mode 100644 Enums/NotebookUserEnumMode.php create mode 100644 Enums/NotebookUserEnumStatus.php create mode 100644 Model/NotebookUser.php diff --git a/Enums/NotebookEnumMode.php b/Enums/NotebookEnumMode.php index fdebcf4..af80b9b 100644 --- a/Enums/NotebookEnumMode.php +++ b/Enums/NotebookEnumMode.php @@ -13,19 +13,14 @@ enum NotebookEnumMode :int use EnumStatusTrait; /** - * 读写 + * 公开 */ - case ReadingAndWriting = 1; + case Public = 1; /** - * 只读 + * 私有 */ - case ReadOnly = 2; - - /** - * 私有写 - */ - case PrivateWrite = 3; + case Private = 2; /** * 获取描述 @@ -35,9 +30,8 @@ enum NotebookEnumMode :int public function getDes(): string { return match ($this) { - self::ReadingAndWriting => '读写', - self::ReadOnly => '只读', - self::PrivateWrite => '私有写', + self::Public => '公开', + self::Private => '私有', }; } @@ -47,9 +41,8 @@ enum NotebookEnumMode :int public function toTag():AbstractHtmlElement { return match ($this){ - self::ReadingAndWriting => $this->getTag('success', 'light'), - self::ReadOnly => $this->getTag('warning', 'light'), - self::PrivateWrite => $this->getTag('danger', 'light'), + self::Public => $this->getTag('success', 'light'), + self::Private => $this->getTag('warning', 'light'), }; } } diff --git a/Enums/NotebookUserEnumMode.php b/Enums/NotebookUserEnumMode.php new file mode 100644 index 0000000..a27fcc4 --- /dev/null +++ b/Enums/NotebookUserEnumMode.php @@ -0,0 +1,48 @@ + '只读', + self::ReadingAndWriting => '读写', + }; + } + + /** + * 转标签 + */ + public function toTag():AbstractHtmlElement + { + return match ($this){ + self::ReadOnly => $this->getTag('success', 'light'), + self::ReadingAndWriting => $this->getTag('warning', 'light'), + }; + } +} diff --git a/Enums/NotebookUserEnumStatus.php b/Enums/NotebookUserEnumStatus.php new file mode 100644 index 0000000..de4a4ee --- /dev/null +++ b/Enums/NotebookUserEnumStatus.php @@ -0,0 +1,48 @@ + '正常', + self::Eliminate => '剔除', + }; + } + + /** + * 转标签 + */ + public function toTag():AbstractHtmlElement + { + return match ($this){ + self::Normal => $this->getTag('success', 'light'), + self::Eliminate => $this->getTag('warning', 'light'), + }; + } +} diff --git a/Model/Notebook.php b/Model/Notebook.php index d702331..9d4ba67 100644 --- a/Model/Notebook.php +++ b/Model/Notebook.php @@ -11,7 +11,6 @@ use App\Model\Model; * @property int $id ID * @property string $title 标题 * @property string $content 内容 - * @property string $allow_see 允许查看的人 * @property int $administrators_id 创建人 * @property int $mode 模式 * @property string $share_key 分享密钥 @@ -25,9 +24,8 @@ CREATE TABLE `sd_notebook` ( `id` int NOT NULL AUTO_INCREMENT COMMENT 'ID', `title` varchar(127) COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT '标题', `content` text COLLATE utf8mb4_general_ci COMMENT '内容', - `allow_see` varchar(255) COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT '允许查看的人', `administrators_id` int NOT NULL COMMENT '创建人', - `mode` tinyint(1) NOT NULL DEFAULT '1' COMMENT '模式:1=读写,2=只读,3=私有写', + `mode` tinyint(1) NOT NULL DEFAULT '1' COMMENT '模式:1=公开,2=私有', `share_key` varchar(10) COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT '分享密钥', `latest_administrators_id` int NOT NULL COMMENT '最后修改人', `create_time` datetime NOT NULL COMMENT '创建时间', @@ -46,7 +44,7 @@ class Notebook extends Model // 更多casts ]; - protected array $fillable = ["title", "content", "allow_see", "administrators_id", "mode", "share_key", "latest_administrators_id"]; + protected array $fillable = ["title", "content", "administrators_id", "mode", "share_key", "latest_administrators_id"]; public function setAdministratorsIdAttribute($value): int { @@ -58,7 +56,6 @@ class Notebook extends Model return $this->attributes['latest_administrators_id'] = (int)$value; } - public function createAdmin() { return $this->belongsTo(Administrators::class, 'administrators_id'); @@ -68,5 +65,10 @@ class Notebook extends Model { return $this->belongsTo(Administrators::class, 'latest_administrators_id'); } + + public function user() + { + return $this->hasMany(NotebookUser::class); + } } diff --git a/Model/NotebookUser.php b/Model/NotebookUser.php new file mode 100644 index 0000000..c596513 --- /dev/null +++ b/Model/NotebookUser.php @@ -0,0 +1,54 @@ +attributes['notebook_id'] = (int)$value; + } + + public function setAdministratorsIdAttribute($value): int + { + return $this->attributes['administrators_id'] = (int)$value; + } +} + diff --git a/Service/Admin/NotebookService.php b/Service/Admin/NotebookService.php index 394d2dc..46b5eb8 100644 --- a/Service/Admin/NotebookService.php +++ b/Service/Admin/NotebookService.php @@ -33,7 +33,8 @@ class NotebookService extends AbstractAdminService $query = $this->model ->leftJoin('administrators as a1', 'a1.id', '=', 'notebook.administrators_id') ->leftJoin('administrators as a2', 'a2.id', '=', 'notebook.latest_administrators_id') - ->select(["notebook.id","notebook.title","notebook.content","notebook.mode","notebook.allow_see","notebook.share_key","a1.name as create_name","a2.name as latest_name","notebook.create_time","notebook.update_time"]); + ->with(['user']) + ->select(["notebook.id","notebook.title","notebook.content","notebook.mode","notebook.share_key","a1.name as create_name","a2.name as latest_name","notebook.create_time","notebook.update_time"]); return EasySearch::create($query)->getData(); } diff --git a/View/Admin/Notebook/lists.blade.php b/View/Admin/Notebook/lists.blade.php index a1426a0..ffd197a 100644 --- a/View/Admin/Notebook/lists.blade.php +++ b/View/Admin/Notebook/lists.blade.php @@ -214,29 +214,24 @@ /> - 添加用户 + 添加用户 -
+
- - @{{ tag }} - +
- @endsection @@ -285,20 +280,26 @@ if (item.allow_see) { this.allowUserData = item.allow_see.split(','); } - console.log(this.allowUserData); }; VueInit.methods.addAllowUser = function () { if (this.waitAddAllowUser.length > 0) { - console.log(this.waitAddAllowUser); - this.allowUserData.push(...this.waitAddAllowUser); - this.waitAddAllowUser = [] + let isPure = true; + this.waitAddAllowUser.map(v =>{ + if (!this.allowUserData.includes(v)) { + this.allowUserData.push(v); + isPure = false; + } + }) + this.waitAddAllowUser = []; + if (!isPure) { + this.updateNotebook.allow_see = this.allowUserData.join(','); + this.update(this.updateNotebook); + } } - console.log(this.allowUserData, this.waitAddAllowUser, 111) }; VueInit.methods.delAllowUser = function (index) { this.allowUserData.splice(index, 1); - console.log(this.allowUserData) }; VueInit.methods.titleChange = function (){