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 4b7948f commit c52d99a
Show file tree
Hide file tree
Showing 6 changed files with 133 additions and 6 deletions.
6 changes: 6 additions & 0 deletions webview/src/apps/pages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { WelcomeComponent } from './welcome';
import { Alert404Component } from './alert/404';

import { ChatroomListComponent } from './chatroom/list';
import { ChatroomCreateComponent } from './chatroom/create';

import { LLModelCreateComponent } from './llmodel/create';
import { LLModelListComponent } from './llmodel/list';
Expand All @@ -12,6 +13,7 @@ import { KeywordListComponent } from './keyword/list';
import { KeywordCreateComponent } from './keyword/create';

import { ProfileListComponent } from './profile/list';
import { ProfileCreateComponent } from './profile/create';

import { WcferryChatroomComponent } from './wcferry/chatroom';
import { WcferryContactComponent } from './wcferry/contact';
Expand All @@ -23,6 +25,7 @@ export const AppComponents = [
Alert404Component,

ChatroomListComponent,
ChatroomCreateComponent,

LLModelCreateComponent,
LLModelListComponent,
Expand All @@ -31,6 +34,7 @@ export const AppComponents = [
KeywordCreateComponent,

ProfileListComponent,
ProfileCreateComponent,

WcferryChatroomComponent,
WcferryContactComponent,
Expand All @@ -45,6 +49,7 @@ export const AppRoutes: Routes = [
{ path: 'welcome', component: WelcomeComponent },

{ path: 'chatroom/list', component: ChatroomListComponent, canActivate: [LoginGuard] },
{ path: 'chatroom/create', component: ChatroomCreateComponent, canActivate: [LoginGuard] },

{ path: 'llmodel/create', component: LLModelCreateComponent, canActivate: [LoginGuard] },
{ path: 'llmodel/list', component: LLModelListComponent, canActivate: [LoginGuard] },
Expand All @@ -53,6 +58,7 @@ export const AppRoutes: Routes = [
{ path: 'keyword/create', component: KeywordCreateComponent, canActivate: [LoginGuard] },

{ path: 'profile/list', component: ProfileListComponent, canActivate: [LoginGuard] },
{ path: 'profile/create', component: ProfileCreateComponent, canActivate: [LoginGuard] },

{ path: 'wcferry/chatroom', component: WcferryChatroomComponent, canActivate: [LoginGuard] },
{ path: 'wcferry/contact', component: WcferryContactComponent, canActivate: [LoginGuard] },
Expand Down
59 changes: 59 additions & 0 deletions webview/src/apps/profile/create.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<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)="createProfile()" #myform="ngForm">
<div class="col-12">
<label class="form-label">类别 *</label>
<select name="roomid" class="form-select" [(ngModel)]="formdata.roomid" (change)="changeRoomid()" required>
<option value="-">私聊</option>
@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>
<select name="wxid" class="form-select" [(ngModel)]="formdata.wxid" required>
@for (item of conacts; track item.wxid) {
<option value="{{item.wxid}}">{{item.wxid}} - {{item.name}}</option>
}
</select>
<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>
<option value="7">群管理</option>
<option value="9">创始人</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.
58 changes: 58 additions & 0 deletions webview/src/apps/profile/create.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { Component } from '@angular/core';
import { Router } from '@angular/router';

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


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

public conacts: Array<WcfrestContactPayload> = [];
public friends: Array<WcfrestContactPayload> = [];
public chatrooms: Array<WcfrestContactPayload> = [];

public formdata = {} as ProfileCreateParam;

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

public createProfile() {
RobotApi.profileCreate(this.formdata).then(() => {
this.router.navigate(['profile/list']);
});
}

public changeRoomid() {
if (this.formdata.roomid == '-') {
this.conacts = this.friends;
} else {
this.getRoomMembers(this.formdata.roomid);
}
}

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

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

public getRoomMembers(id: string) {
WrestApi.chatroomMembers({ roomid: id }).then((data) => {
this.conacts = data || [];
});
}

}
4 changes: 4 additions & 0 deletions webview/src/apps/profile/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]="['/profile/create']">添加</button>
</div>

<table class="table table-hover align-middle">
<thead class="table-light">
<tr>
Expand Down
12 changes: 6 additions & 6 deletions webview/src/apps/profile/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,6 @@ export class ProfileListComponent {
this.timestamp = new Date().getTime();
}

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

public getProfiles() {
const rq = {} as ProfileFetchAllParam;
RobotApi.profileList(rq).then((data) => {
Expand All @@ -49,6 +43,12 @@ export class ProfileListComponent {
});
}

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

public getRoomMembers(ids: string[]) {
[...new Set(ids)].forEach((id) => {
if (id === '-' || this.roomMembers[id]) {
Expand Down

0 comments on commit c52d99a

Please sign in to comment.