96 lines
3.0 KiB
TypeScript
96 lines
3.0 KiB
TypeScript
import { actionAddins } from ".";
|
|
import { IAction,IActionResult, IActionNode, IActionProperty, IField, IContext } from "../types/ActionTypes";
|
|
|
|
/**
|
|
* アクションの属性定義
|
|
*/
|
|
interface FullWidthProps{
|
|
field:IField
|
|
}
|
|
/**
|
|
* 全角チェックアクション
|
|
*/
|
|
export class FullWidthAction implements IAction{
|
|
name: string;
|
|
actionProps: IActionProperty[];
|
|
props:FullWidthProps;
|
|
constructor(){
|
|
this.name="全角チェック"; /* pgadminのnameと同様 */
|
|
this.actionProps=[];
|
|
this.props={
|
|
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===''){
|
|
record[this.props.field.code].error=null;
|
|
}
|
|
//半角が含まれていた場合resultがfalse
|
|
if(!this.containsFullWidthChars(value) && !(value === undefined || value ==='')){
|
|
//エラー時に出力される文字設定
|
|
record[this.props.field.code].error="半角が含まれています";
|
|
//次の処理を中止する値設定
|
|
result.canNext=false;
|
|
}
|
|
else{
|
|
record[this.props.field.code].error=null;
|
|
}
|
|
//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);
|
|
}
|
|
|
|
//戻り値を持たないためvoid型
|
|
register(): void {
|
|
actionAddins[this.name]=this;
|
|
}
|
|
}
|
|
new FullWidthAction(); |