Skip to content

Commit

Permalink
fix: 字段类型引发的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
rehiy committed Feb 29, 2024
1 parent 125e718 commit 2434bd0
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 16 deletions.
2 changes: 1 addition & 1 deletion webview/src/apps/chatroom/create.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<label class="form-label">群聊 *</label>
<select name="roomid" class="form-select" [(ngModel)]="formdata.roomid" required>
@for (item of wcfChatrooms; track item.wxid) {
<option value="{{item.wxid}}">{{item.name}}</option>
<option [value]="item.wxid">{{item.name}}</option>
}
</select>
<div class="form-text">
Expand Down
12 changes: 8 additions & 4 deletions webview/src/apps/keyword/create.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
<label class="form-label">类别 *</label>
<select name="roomid" class="form-select" [(ngModel)]="formdata.roomid" required>
<option value="-">全局</option>
@for (item of chatrooms; track item.wxid) {
<option value="{{item.wxid}}">{{item.name}}</option>
@for (item of wcfChatrooms; track item.wxid) {
<option [value]="item.wxid">{{item.name}}</option>
}
</select>
<div class="form-text">
Expand All @@ -31,9 +31,13 @@
</div>
<div class="col-12">
<label class="form-label">级别 *</label>
<input type="range" name="level" class="form-range" [(ngModel)]="formdata.level" min="0" max="6" required />
<select name="level" class="form-select" [(ngModel)]="formdata.level" required>
@for (item of keywordLevels | keyvalue; track item.key) {
<option [value]="item.key">{{item.value.name}}</option>
}
</select>
<div class="form-text">
用于违规积分计算,0 为不生效,当前值:{{formdata.level}}
用于违规积分累计,当前选项计 {{formdata.level}}
</div>
</div>
<div class="col-12">
Expand Down
14 changes: 10 additions & 4 deletions webview/src/apps/keyword/create.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Component } from '@angular/core';
import { Router } from '@angular/router';

import { KeywordLevels } from 'src/openapi/const';
import { RobotApi, KeywordCreateParam } from '../../openapi/wrobot';
import { WrestApi, WcfrestContactPayload } from '../../openapi/wcfrest';

Expand All @@ -12,23 +13,28 @@ import { WrestApi, WcfrestContactPayload } from '../../openapi/wcfrest';
})
export class KeywordCreateComponent {

public chatrooms: Array<WcfrestContactPayload> = [];
public keywordLevels = KeywordLevels;

public wcfChatrooms: Array<WcfrestContactPayload> = [];

public formdata: KeywordCreateParam = { roomid: '-', level: 1 };

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

public createKeyword() {
if (this.formdata.level) {
this.formdata.level = +this.formdata.level;
}
RobotApi.keywordCreate(this.formdata).then(() => {
this.router.navigate(['keyword/list']);
});
}

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

Expand Down
6 changes: 3 additions & 3 deletions webview/src/apps/keyword/list.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@
<th scope="row">{{item.rd}}</th>
<td>{{item.phrase}}</td>
<td>
@if (chatrooms[item.roomid]) {
{{chatrooms[item.roomid].name}}
@if (wcfChatrooms[item.roomid]) {
{{wcfChatrooms[item.roomid].name}}
} @else {
{{item.roomid != '-' ? item.roomid : '全局'}}
}
</td>
<td>{{item.level}}</td>
<td>{{ keywordLevels[item.level] && keywordLevels[item.level].name || item.level}}</td>
<td>
<button class="btn btn-sm btn-danger" (click)="deleteKeyword(item)">删除</button>
</td>
Expand Down
11 changes: 7 additions & 4 deletions webview/src/apps/keyword/list.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Component } from '@angular/core';

import { KeywordLevels } from 'src/openapi/const';
import { RobotApi, TablesKeyword } from '../../openapi/wrobot';
import { WrestApi, WcfrestContactPayload } from '../../openapi/wcfrest';

Expand All @@ -11,13 +12,15 @@ import { WrestApi, WcfrestContactPayload } from '../../openapi/wcfrest';
})
export class KeywordListComponent {

public chatrooms: Record<string, WcfrestContactPayload> = {};
public keywordLevels = KeywordLevels;

public wcfChatrooms: Record<string, WcfrestContactPayload> = {};

public keywords: Array<TablesKeyword> = [];

constructor() {
this.getKeywords();
this.getChatrooms();
this.getWcfChatrooms();
}

public getKeywords() {
Expand All @@ -33,9 +36,9 @@ export class KeywordListComponent {
});
}

public getChatrooms() {
public getWcfChatrooms() {
WrestApi.chatrooms().then((data) => {
data.forEach((item) => this.chatrooms[item.wxid] = item);
data.forEach((item) => this.wcfChatrooms[item.wxid] = item);
});
}

Expand Down
6 changes: 6 additions & 0 deletions webview/src/openapi/const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,10 @@ export const UserLevels: Record<number, LevelData> = {
2: { name: '已注册' },
7: { name: '管理员' },
9: { name: '创始人' }
};

export const KeywordLevels: Record<number, LevelData> = {
1: { name: '一般违规' },
2: { name: '较为严重' },
3: { name: '非常严重' },
};

0 comments on commit 2434bd0

Please sign in to comment.