前端转vue
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

FocusManagerExt.ts 6.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. // // 假设 FieldPolicyCollection 和 TipAdorner 等类型的定义
  2. // interface FieldPolicy {
  3. // Run(d: any, message: string): void;
  4. // }
  5. // interface FieldPolicyCollection {
  6. // [index: number]: FieldPolicy;
  7. // }
  8. // // 定义焦点管理器实例接口
  9. // interface FocusManagerInstance {
  10. // IsFocusContinue: boolean;
  11. // }
  12. // // 焦点管理器类
  13. // class FocusManager {
  14. // // 模拟获取焦点管理器实例
  15. // static GetManagerInstance(d: any): FocusManagerInstance | null {
  16. // return { IsFocusContinue: true };
  17. // }
  18. // // 模拟添加焦点丢失事件处理程序
  19. // static AddPreviewLostFocusHandler(d: any, handler: (sender: any, args: any) => void) {
  20. // if (d.addEventListener) {
  21. // d.addEventListener('blur', handler);
  22. // }
  23. // }
  24. // // 模拟移除焦点丢失事件处理程序
  25. // static RemovePreviewLostFocusHandler(d: any, handler: (sender: any, args: any) => void) {
  26. // if (d.removeEventListener) {
  27. // d.removeEventListener('blur', handler);
  28. // }
  29. // }
  30. // }
  31. // // 焦点管理器扩展类
  32. // class FocusManagerExt {
  33. // // 定义静态属性
  34. // static AssertNotEmptyProperty = Symbol('AssertNotEmpty');
  35. // static RegexValidationProperty = Symbol('RegexValidation');
  36. // static RegexValidateErrorInfoProperty = Symbol('RegexValidateErrorInfo');
  37. // static ValidationFieldProperty = Symbol('ValidationField');
  38. // static FieldEmptyPoliciesProperty = Symbol('FieldEmptyPolicies');
  39. // static RegexValidateErrorPoliciesProperty = Symbol('RegexValidateErrorPolicies');
  40. // static IsFocusAdornerProperty = Symbol('IsFocusAdorner');
  41. // // Getter 和 Setter 方法
  42. // static GetAssertNotEmpty(d: any): boolean {
  43. // return d[this.AssertNotEmptyProperty] || false;
  44. // }
  45. // static SetAssertNotEmpty(d: any, value: boolean) {
  46. // d[this.AssertNotEmptyProperty] = value;
  47. // this.OnAssertNotEmptyChanged(d, value);
  48. // }
  49. // static GetRegexValidation(d: any): string {
  50. // return d[this.RegexValidationProperty] || '';
  51. // }
  52. // static SetRegexValidation(d: any, value: string) {
  53. // d[this.RegexValidationProperty] = value;
  54. // this.OnRegexValidationChanged(d, value);
  55. // }
  56. // static GetRegexValidateErrorInfo(d: any): string {
  57. // return d[this.RegexValidateErrorInfoProperty] || '';
  58. // }
  59. // static SetRegexValidateErrorInfo(d: any, value: string) {
  60. // d[this.RegexValidateErrorInfoProperty] = value;
  61. // }
  62. // static GetValidationField(d: any): string {
  63. // return d[this.ValidationFieldProperty] || '';
  64. // }
  65. // static SetValidationField(d: any, value: string) {
  66. // d[this.ValidationFieldProperty] = value;
  67. // }
  68. // static GetFieldEmptyPolicies(d: any): FieldPolicyCollection | null {
  69. // return d[this.FieldEmptyPoliciesProperty] || null;
  70. // }
  71. // static SetFieldEmptyPolicies(d: any, value: FieldPolicyCollection) {
  72. // d[this.FieldEmptyPoliciesProperty] = value;
  73. // }
  74. // static GetRegexValidateErrorPolicies(d: any): FieldPolicyCollection | null {
  75. // return d[this.RegexValidateErrorPoliciesProperty] || null;
  76. // }
  77. // static SetRegexValidateErrorPolicies(d: any, value: FieldPolicyCollection) {
  78. // d[this.RegexValidateErrorPoliciesProperty] = value;
  79. // }
  80. // static GetIsFocusAdorner(d: any): boolean {
  81. // return d[this.IsFocusAdornerProperty] || false;
  82. // }
  83. // static SetIsFocusAdorner(d: any, value: boolean) {
  84. // d[this.IsFocusAdornerProperty] = value;
  85. // }
  86. // // 属性变化处理方法
  87. // private static OnAssertNotEmptyChanged(d: any, newValue: boolean) {
  88. // if (newValue) {
  89. // FocusManager.AddPreviewLostFocusHandler(d, this.handler);
  90. // } else {
  91. // FocusManager.RemovePreviewLostFocusHandler(d, this.handler);
  92. // }
  93. // }
  94. // private static handler = (sender: any, args: any) => {
  95. // const d = sender;
  96. // const focus = FocusManager.GetManagerInstance(d);
  97. // if (!focus) return;
  98. // const propertyName = this.GetValidationField(d);
  99. // if (!propertyName) return;
  100. // const propertyInfo = d[propertyName];
  101. // if (propertyInfo) {
  102. // const strValue = String(propertyInfo);
  103. // if (strValue.trim() !== '') return;
  104. // }
  105. // const fieldEmptyPolicies = this.GetFieldEmptyPolicies(d);
  106. // if (fieldEmptyPolicies) {
  107. // for (const policy of fieldEmptyPolicies) {
  108. // policy.Run(d, '该输入要素不能为空');
  109. // }
  110. // }
  111. // focus.IsFocusContinue = false;
  112. // args.preventDefault();
  113. // };
  114. // private static OnRegexValidationChanged(dp: any, newRegexValidation: string) {
  115. // const handler = (sender: any, args: any) => {
  116. // const d = sender;
  117. // const focus = FocusManager.GetManagerInstance(d);
  118. // if (!focus) return;
  119. // const propertyName = this.GetValidationField(d);
  120. // if (!propertyName) return;
  121. // const propertyInfo = d[propertyName];
  122. // if (!propertyInfo) return;
  123. // const strValue = String(propertyInfo);
  124. // if (!this.GetAssertNotEmpty(d) && strValue === '') return;
  125. // const reg = this.GetRegexValidation(d);
  126. // if (!reg) return;
  127. // const regex = new RegExp(reg);
  128. // if (regex.test(strValue)) return;
  129. // const fieldPolicies = this.GetFieldEmptyPolicies(d);
  130. // let regexValidateErrorInfo = this.GetRegexValidateErrorInfo(d);
  131. // if (!regexValidateErrorInfo) {
  132. // regexValidateErrorInfo = `输入场要求输入值满足正则表达式:${reg},输入值:${strValue}不满足此要求!`;
  133. // }
  134. // if (fieldPolicies) {
  135. // for (const policy of fieldPolicies) {
  136. // policy.Run(d, regexValidateErrorInfo);
  137. // }
  138. // }
  139. // focus.IsFocusContinue = false;
  140. // args.preventDefault();
  141. // };
  142. // if (newRegexValidation) {
  143. // FocusManager.AddPreviewLostFocusHandler(dp, handler);
  144. // } else {
  145. // FocusManager.RemovePreviewLostFocusHandler(dp, handler);
  146. // }
  147. // }
  148. // }
  149. // export default FocusManagerExt;
  150. //焦点控制TODO后续处理