Skip to content

Commit

Permalink
feat: 支持添加群聊配置
Browse files Browse the repository at this point in the history
  • Loading branch information
rehiy committed Feb 28, 2024
1 parent 8fd5e1b commit 4b7948f
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 7 deletions.
73 changes: 73 additions & 0 deletions webview/src/apps/chatroom/create.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<layout-header></layout-header>

<nav class="container-lg mb-3">
<ol class="breadcrumb">
<li class="breadcrumb-item"><a routerLink="/welcome">首页</a></li>
<li class="breadcrumb-item"><a routerLink="/keyword/list">群聊配置</a></li>
<li class="breadcrumb-item active">添加</li>
</ol>
</nav>

<div class="container-lg mb-3">
<form class="row gy-3" (ngSubmit)="createChatroom()" #myform="ngForm">
<div class="col-12">
<label class="form-label">群聊 *</label>
<select name="roomid" class="form-select" [(ngModel)]="formdata.roomid" required>
@for (item of chatrooms; track item.wxid) {
<option value="{{item.wxid}}">{{item.name}}</option>
}
</select>
<div class="form-text">
选择一个需要关联的群聊
</div>
</div>
<div class="col-12">
<label class="form-label">名称 *</label>
<input type="text" name="phrase" class="form-control" [(ngModel)]="formdata.name" required />
<div class="form-text">
用于生成加群指令中的描述
</div>
</div>
<div class="col-12">
<label class="form-label">加群指令 *</label>
<input type="text" name="phrase" class="form-control" [(ngModel)]="formdata.join_argot" required />
<div class="form-text">
用于生成加群指令
</div>
</div>
<div class="col-12">
<label class="form-label">欢迎信息 *</label>
<input type="text" name="phrase" class="form-control" [(ngModel)]="formdata.welcome_msg" required />
<div class="form-text">
用户入群时的欢迎信息,-” 表示不欢迎
</div>
</div>
<div class="col-12">
<label class="form-label">撤回提醒 *</label>
<input type="text" name="phrase" class="form-control" [(ngModel)]="formdata.revoke_msg" required />
<div class="form-text">
检测到撤回消息时的提醒,“-” 表示不提醒
</div>
</div>
<div class="col-12">
<label class="form-label">级别 *</label>
<select name="roomid" class="form-select" [(ngModel)]="formdata.level" required>
<option value="1">拉黑</option>
<option value="2">加白</option>
</select>
<div class="form-text">
机器人使用权限
</div>
</div>
<div class="col-12">
<label class="form-label">备注 *</label>
<input type="text" name="phrase" class="form-control" [(ngModel)]="formdata.remark" required />
<div class="form-text">
备注信息
</div>
</div>
<div class="col-12">
<button type="submit" class="btn btn-primary" [disabled]="myform.invalid">确认</button>
</div>
</form>
</div>
Empty file.
35 changes: 35 additions & 0 deletions webview/src/apps/chatroom/create.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { Component } from '@angular/core';
import { Router } from '@angular/router';

import { RobotApi, ChatroomCreateParam } from '../../openapi/wrobot';
import { WrestApi, WcfrestContactPayload } from '../../openapi/wcfrest';


@Component({
selector: 'page-chatroom-create',
templateUrl: 'create.html',
styleUrls: ['create.scss']
})
export class ChatroomCreateComponent {

public chatrooms: Array<WcfrestContactPayload> = [];

public formdata = { level: 1 } as ChatroomCreateParam;

constructor(private router: Router) {
this.getChatrooms();
}

public createChatroom() {
RobotApi.chatroomCreate(this.formdata).then(() => {
this.router.navigate(['chatroom/list']);
});
}

public getChatrooms() {
WrestApi.chatrooms().then((data) => {
this.chatrooms = data || [];
});
}

}
4 changes: 4 additions & 0 deletions webview/src/apps/chatroom/list.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
</nav>

<div class="container-lg mb-3">
<div class="text-end mb-3">
<button class="btn btn-sm btn-primary" [routerLink]="['/chatroom/create']">添加</button>
</div>

<table class="table table-hover align-middle">
<thead class="table-light">
<tr>
Expand Down
14 changes: 7 additions & 7 deletions webview/src/apps/chatroom/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,8 @@ export class ChatroomListComponent {
public chatrooms: Array<TablesChatroom> = [];

constructor() {
this.getContacts();
this.getChatrooms();
}

public getContacts() {
WrestApi.contacts().then((data) => {
data.forEach((item) => this.contacts[item.wxid] = item);
});
this.getContacts();
}

public getChatrooms() {
Expand All @@ -43,6 +37,12 @@ export class ChatroomListComponent {
});
}

public getContacts() {
WrestApi.contacts().then((data) => {
data.forEach((item) => this.contacts[item.wxid] = item);
});
}

public getAvatars(ids: string[]) {
WrestApi.avatars({ wxids: [...new Set(ids)] }).then((data) => {
data && data.forEach((item) => {
Expand Down

0 comments on commit 4b7948f

Please sign in to comment.