全角チェックのアップデート

This commit is contained in:
kanarutsuda
2024-06-04 14:35:11 +09:00
parent 22e9094d4c
commit 544370688e
7 changed files with 131 additions and 63 deletions

View File

@@ -12,7 +12,7 @@ interface IButtonAddProps {
position: string;
//イベント名
eventName:string
}
}
export class ButtonAddAction implements IAction {
name: string;
@@ -97,7 +97,6 @@ export class ButtonAddAction implements IAction {
return result;
}
}
register(): void {
actionAddins[this.name] = this;

View File

@@ -0,0 +1,102 @@
import { actionAddins } from ".";
import { IAction,IActionResult, IActionNode, IActionProperty, IField, IContext } from "../types/ActionTypes";
//クラス名を設計書に揃える
/**
* アクションの属性定義
*/
interface FullWidthProps{
//checkOption:Array<string>,
field:IField
}
/**
* 全角チェックアクション
*/
export class FullWidthAction implements IAction{
name: string;
actionProps: IActionProperty[];
props:FullWidthProps;
constructor(){
this.name="全角チェック"; /* pgadminのnameと同様 */
this.actionProps=[];
this.props={
//checkOption:[],
field:{code:''}
}
//アクションを登録する
this.register();
}
/**
* アクションの実行を呼び出す
* @param actionNode
* @param event
* @returns
*/
async process(actionNode:IActionNode,event:any,context:IContext):Promise<IActionResult> {
let result={
canNext:true,
result:false
};
try{
//属性設定を取得する
this.actionProps=actionNode.actionProps;
if (!('field' in actionNode.ActionValue) ) {
return result
}
this.props = actionNode.ActionValue as FullWidthProps;
//条件式の計算結果を取得
const record = event.record;
const value = record[this.props.field.code]?.value;
//条件分岐
//未入力時は何も処理をせず終了
if(value===undefined || value===''){
return result;
}
//半角が含まれていた場合resultがfalse
if(!this.containsFullWidthChars(value)){
//エラー時に出力される文字設定
record[this.props.field.code].error="半角が含まれています";
//次の処理を中止する値設定
result.canNext=false;
return result;
}
//resultプロパティ指定
result= {
canNext:true,
result:true
}
return result;
//例外処理
}catch(error){
event.error=error;
console.error(error);
result.canNext=false;
return result;
}
}
//全て全角の文字列の場合はtrue、そうでない場合はfalse
containsFullWidthChars(text: string): boolean {
//半角英数字カナを除外
const checkRegex="^[^\x01-\x7E\uFF61-\uFF9F]+$";
//正規表現オブジェクト生成
const fullWidthRegex = new RegExp(checkRegex);
//正規表現チェック
return fullWidthRegex.test(text);
//全角を表すUnicodeの全角正規表現(参照先URL)
// \u3000-\u303F句読点・記号
// \u3040-\u309Fすべてのひらがな
// \u30A0-\u30FF:すべてのカタカナ
// \u4E00-\u9FAF:すべての漢字
// \uFF00-\uFFEF:全角英数字と半角カタカナ
// \u3400-\u4DBF:CJK統合漢字拡張
//const fullWidthRegex = /[/^[\u3000-\u303F\u3040-\u309F\u30A0-\u30FF\uFF00-\uFFEF\u4E00-\u9FAF\u3400-\u4DBF]+$/g;
}
//戻り値を持たないためvoid型
register(): void {
actionAddins[this.name]=this;
}
}
new FullWidthAction();

View File

@@ -6,7 +6,7 @@ import '../actions/field-shown';
import '../actions/error-show';
import '../actions/button-add';
import '../actions/condition-action';
import '../actions/fullwidth-check';
import '../actions/validation fullwidth';
import { ActionFlow,IActionFlow, IActionResult,IContext } from "./ActionTypes";
export class ActionProcess{