-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
161 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<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="/profile/list">用户配置</a></li> | ||
<li class="breadcrumb-item active">更新</li> | ||
</ol> | ||
</nav> | ||
|
||
<div class="container-lg mb-3"> | ||
<form class="row gy-3" (ngSubmit)="updateProfile()" #myform="ngForm"> | ||
<div class="col-12"> | ||
<label class="form-label">场景 *</label> | ||
<select name="roomid" class="form-select" [(ngModel)]="formdata.roomid" (change)="changeConacts()" required> | ||
<option value="-">私聊</option> | ||
@for (item of wcfChatrooms; 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" [disabled]="conacts.length == 0" 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="level" class="form-select" [(ngModel)]="formdata.level"> | ||
@for (item of userLevels | keyvalue; track item.key) { | ||
<option [value]="item.key">{{item.value.name}}</option> | ||
} | ||
</select> | ||
<div class="form-text"> | ||
机器人使用权限 | ||
</div> | ||
</div> | ||
<div class="col-12"> | ||
<label class="form-label">AI 唤醒词</label> | ||
<input type="text" name="ai_argot" class="form-control" [(ngModel)]="formdata.ai_argot" /> | ||
<div class="form-text"> | ||
自定义唤醒词 | ||
</div> | ||
</div> | ||
<div class="col-12"> | ||
<label class="form-label">AI 模型</label> | ||
<input type="text" name="ai_model" class="form-control" [(ngModel)]="formdata.ai_model" /> | ||
<div class="form-text"> | ||
当前使用的模型 | ||
</div> | ||
</div> | ||
<div class="col-12"> | ||
<label class="form-label">备注</label> | ||
<input type="text" name="remark" class="form-control" [(ngModel)]="formdata.remark" /> | ||
<div class="form-text"> | ||
备注信息 | ||
</div> | ||
</div> | ||
<div class="col-12"> | ||
<button type="submit" class="btn btn-primary" [disabled]="myform.invalid">确认</button> | ||
</div> | ||
</form> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import { Component, OnInit } from '@angular/core'; | ||
import { Router, ActivatedRoute } from '@angular/router'; | ||
|
||
import { UserLevels } from 'src/openapi/const'; | ||
import { RobotApi, ProfileUpdateParam } from '../../openapi/wrobot'; | ||
import { WrestApi, WcfrestContactPayload } from '../../openapi/wcfrest'; | ||
|
||
|
||
@Component({ | ||
selector: 'page-profile-update', | ||
templateUrl: 'update.html' | ||
}) | ||
export class ProfileUpdateComponent implements OnInit { | ||
|
||
public userLevels = UserLevels; | ||
|
||
public wcfAvatars: Record<string, string> = {}; | ||
public wcfFriends: Array<WcfrestContactPayload> = []; | ||
public wcfContacts: Record<string, WcfrestContactPayload> = {}; | ||
public wcfChatrooms: Array<WcfrestContactPayload> = []; | ||
public wcfRoomMembers: Record<string, Array<WcfrestContactPayload>> = {}; | ||
|
||
public conacts: Array<WcfrestContactPayload> = []; | ||
public formdata = {} as ProfileUpdateParam; | ||
|
||
constructor( | ||
private router: Router, | ||
private route: ActivatedRoute | ||
) { | ||
this.getWcfFriends(); | ||
this.getWcfChatrooms(); | ||
} | ||
|
||
public ngOnInit() { | ||
const rd = this.route.snapshot.paramMap.get('rd'); | ||
rd && this.getProfile(+rd); | ||
} | ||
|
||
public getProfile(rd: number) { | ||
RobotApi.profileDetail({ rd }).then((data) => { | ||
data && Object.assign(this.formdata, data); | ||
}); | ||
} | ||
|
||
public updateProfile() { | ||
if (this.formdata.level) { | ||
this.formdata.level = +this.formdata.level; | ||
} | ||
RobotApi.profileUpdate(this.formdata).then(() => { | ||
this.router.navigate(['profile/list']); | ||
}); | ||
} | ||
|
||
public changeConacts() { | ||
const id = this.formdata.roomid || '-'; | ||
this.conacts = id == '-' ? this.wcfFriends : this.wcfRoomMembers[id] || []; | ||
} | ||
|
||
public getWcfFriends() { | ||
WrestApi.friends().then((data) => { | ||
this.wcfFriends = data || []; | ||
}); | ||
} | ||
|
||
public getWcfChatrooms() { | ||
WrestApi.chatrooms().then((data) => { | ||
this.wcfChatrooms = data || []; | ||
this.getWcfRoomMembers(this.wcfChatrooms.map((item) => item.wxid)); | ||
}); | ||
} | ||
|
||
public getWcfRoomMembers(ids: string[]) { | ||
[...new Set(ids)].forEach((id) => { | ||
WrestApi.chatroomMembers({ roomid: id }).then((data) => { | ||
this.wcfRoomMembers[id] = data || []; | ||
// 尝试更新当前人员列表 | ||
this.changeConacts(); | ||
}); | ||
}); | ||
} | ||
|
||
} |