1- import { HttpUtils , removeHTML , randNumber } from "../utils/utils" ;
2- import { SystemConfig } from "@App/config" ;
3- import { Application } from "../application" ;
1+ import { HttpUtils , removeHTML , randNumber } from "../utils/utils" ;
2+ import { SystemConfig } from "@App/config" ;
3+ import { Application } from "../application" ;
44
55export interface Topic {
66 topic : string
@@ -21,6 +21,7 @@ export interface Answer {
2121 answers ?: Option [ ]
2222 correct : Option [ ]
2323 id ?: string
24+
2425 Equal ( content1 : string , content2 : string ) : boolean
2526}
2627
@@ -31,20 +32,25 @@ export class PushAnswer implements Answer {
3132 public status : TopicStatus ;
3233 public answers : Option [ ] ;
3334 public correct : Option [ ] ;
35+
3436 public Equal ( content1 : string , content2 : string ) : boolean {
3537 return content1 == content2 ;
3638 }
3739}
3840
3941export interface Options {
4042 Random ( ) : TopicStatus ;
43+
4144 Fill ( s : Answer ) : TopicStatus ;
45+
4246 Correct ( ) : Answer
4347}
4448
4549export interface Question extends Options {
4650 GetType ( ) : TopicType ;
51+
4752 GetTopic ( ) : string ;
53+
4854 SetStatus ( status : TopicStatus ) : void ;
4955}
5056
@@ -54,11 +60,17 @@ export type FillType = 1;
5460// 1随机答案 2不支持的随机答案类型 3无答案 4无符合答案
5561export type TopicStatus = "ok" | "random" | "no_support_random" | "no_answer" | "no_match" ;
5662
57- let statusMap = new Map < TopicStatus , string > ( ) ;
58- statusMap . set ( "ok" , "搜索成功" ) . set ( "random" , "随机答案" ) . set ( "no_support_random" , "不支持的随机答案类型" ) .
59- set ( "no_answer" , "题库中没有搜索到答案" ) . set ( "no_match" , "题库中没有符合的答案" ) ;
63+ let topicStatusMap = new Map < TopicStatus , string > ( ) ;
64+ topicStatusMap . set ( "ok" , "搜索成功" ) . set ( "random" , "随机答案" ) . set ( "no_support_random" , "不支持的随机答案类型" ) . set ( "no_answer" , "题库中没有搜索到答案" ) . set ( "no_match" , "题库中没有符合的答案" ) ;
65+ let questionStatusMap = new Map < QuestionStatus , string > ( ) ;
66+ questionStatusMap . set ( "success" , "搜索成功" ) . set ( "network" , "题库网络错误" ) . set ( "incomplete" , "题库不全" ) . set ( "processing" , "搜索中..." ) ;
67+
6068export function TopicStatusString ( status : TopicStatus ) : string {
61- return statusMap . get ( status ) ;
69+ return topicStatusMap . get ( status ) ;
70+ }
71+
72+ export function QuestionStatusString ( status : QuestionStatus ) : string {
73+ return questionStatusMap . get ( status ) ;
6274}
6375
6476export function SwitchTopicType ( title : string ) : TopicType {
@@ -85,21 +97,26 @@ export type QuestionStatus = "success" | "network" | "incomplete" | "processing"
8597export type QuestionCallback = ( status : QuestionStatus ) => void
8698
8799export type QuestionBankCallback = ( args : { status : QuestionStatus , answer : Answer [ ] } ) => void
100+
88101export interface QuestionBank {
89102 Answer ( topic : Topic [ ] , resolve : QuestionBankCallback ) : void ;
103+
90104 Push ( answer : Answer [ ] ) : Promise < QuestionStatus > ;
105+
91106 SetInfo ( info : QuestionInfo ) : void ;
92107}
93108
94109export interface QuestionInfo {
95110 refer : string
96111 id : string
97112}
113+
98114// 小工具题库
99115export class ToolsQuestionBank implements QuestionBank {
100116
101117 protected platform : string
102118 protected info : QuestionInfo ;
119+
103120 constructor ( platform : string , info ?: QuestionInfo ) {
104121 this . platform = platform ;
105122 this . info = info ;
@@ -158,15 +175,15 @@ export class ToolsQuestionBank implements QuestionBank {
158175 if ( status != "success" ) {
159176 retStatus = status ;
160177 }
161- resolve ( { status : "processing" , answer : tmpResult } ) ;
178+ resolve ( { status : "processing" , answer : tmpResult } ) ;
162179 if ( t < topic . length ) {
163180 next ( t ) ;
164181 } else {
165- return resolve ( { status : retStatus , answer : answer } ) ;
182+ return resolve ( { status : retStatus , answer : answer } ) ;
166183 }
167184 } ,
168185 error : ( ) => {
169- return resolve ( { status : "network" , answer : answer } ) ;
186+ return resolve ( { status : "network" , answer : answer } ) ;
170187 }
171188 } ) ;
172189 }
@@ -194,18 +211,23 @@ export class ToolsQuestionBank implements QuestionBank {
194211 }
195212
196213}
214+
197215export interface QuestionBankFacade {
198216 ClearQuestion ( ) : void
217+
199218 AddQuestion ( q : Question ) : void
219+
200220 Answer ( callback : ( status : QuestionStatus ) => void ) : void
221+
201222 Push ( callback : ( status : QuestionStatus ) => void ) : void
202223}
224+
203225export class ToolsQuestionBankFacade implements QuestionBankFacade {
204226 protected bank : QuestionBank ;
205227 protected question : Array < Question > ;
206228
207- constructor ( bank : QuestionBank ) {
208- this . bank = bank ;
229+ constructor ( platform : string , info ?: any ) {
230+ this . bank = new ToolsQuestionBank ( platform , info ) ;
209231 this . question = new Array < Question > ( ) ;
210232 }
211233
0 commit comments