Browse Source

refactor: 将验证方法提取出来

qufenxi
alan 6 years ago
parent
commit
2334d1a068
  1. 1
      .eslintrc.js
  2. 6
      src/app/link_set/left/left_item/left.item.component.ts
  3. 6
      src/app/link_set/left/left_item/left.item.icon.component.ts
  4. 6
      src/app/link_set/more/more.link.component.ts
  5. 64
      src/app/link_set/right/right_edit/right.edit.component.ts
  6. 4
      src/app/link_set/right/right_edit/right.edit.constant.ts
  7. 58
      src/app/link_set/right/right_edit/right.edit.mysql.component.ts
  8. 4
      src/app/link_set/right/right_edit/right.edit.service.ts
  9. 16
      src/demo/plugin.redis.edit.ts

1
.eslintrc.js

@ -25,6 +25,7 @@ module.exports = {
'for-direction': 2,
// 关键字前后必须有空格
'keyword-spacing': 2,
'key-spacing':2,
// 最大块嵌套深度为 5 层
'max-depth': [2, 5],
// 最大回调深度为 3 层

6
src/app/link_set/left/left_item/left.item.component.ts

@ -5,8 +5,8 @@ import {ACTION_COPY, ACTION_TEST, ACTION_DELETE, DEFAULT_INFO} from '@private/co
const className = 'fr.component.linkSet.left.item';
const Widget: WidgetType = {
props: {
title:'',
id:'',
title: '',
id: '',
creator: '',
},
_store() {
@ -30,7 +30,7 @@ const Widget: WidgetType = {
},
{
type: TextButton,
cls:'link-title',
cls: 'link-title',
textAlign: 'left',
text: title,
title,

6
src/app/link_set/left/left_item/left.item.icon.component.ts

@ -22,7 +22,7 @@ const Widget: WidgetType = {
el: {
type: Icon,
cls,
extraCls: 'action-icon',
baseCls: 'action-icon',
height: 24,
width: 26,
title,
@ -47,14 +47,14 @@ const Widget: WidgetType = {
eventName: BI.BubbleCombo.EVENT_EXPAND,
action () {
iconContent.element.css({
visibility:'visible',
visibility: 'visible',
});
},
}, {
eventName: BI.BubbleCombo.EVENT_AFTER_HIDEVIEW,
action () {
iconContent.element.css({
visibility:'hidden',
visibility: 'hidden',
});
},
}],

6
src/app/link_set/more/more.link.component.ts

@ -10,9 +10,9 @@ const Widget: WidgetType = {
cls: 'more-link',
items: [
{
el:{
el: {
type: Vertical,
items:[{
items: [{
type: SearchEditor,
width: 300,
watermark: BI.i18nText('Dec-Dcm_Search'),
@ -22,7 +22,7 @@ const Widget: WidgetType = {
},
{
type: Left,
cls:'more-link-item',
cls: 'more-link-item',
ref(ref: any) {
morkLinkItem = ref;
},

64
src/app/link_set/right/right_edit/right.edit.component.ts

@ -4,14 +4,14 @@ import charset from './right.edit.constant';
import Model from '../../link-set.model';
import FormItem from '@shared/components/form.item.component';
import Title from '@shared/components/title.component';
import {getDrivers} from './right.edit.service';
import {getDrivers, connectNameChecker} from './right.edit.service';
let ConnectionName: any = null;
const className = 'fr.component.right.edit';
const Widget: WidgetType = {
_store() {
return BI.Models.getModel(Model);
},
watch:{
watch: {
connectionNameErr(msg: string) {
if (msg) {
BI.Bubbles.show('singleBubble', msg, ConnectionName, {
@ -34,7 +34,7 @@ const Widget: WidgetType = {
type: FormItem,
text: BI.i18nText('Dec-Dcm_Connection_Form_ConnectionName'),
hint: BI.i18nText('Dec-Dcm_Connection_Form_ConnectionName-Change-Confirm'),
form:{
form: {
type: Editor,
cls: 'bi-border',
width: 300,
@ -62,14 +62,14 @@ const Widget: WidgetType = {
type: FormItem,
text: BI.i18nText('Dec-Dcm_First_Step'),
height: 400,
form:{
form: {
type: Vertical,
cls: 'right-form',
items:[
items: [
{
type: FormItem,
text: BI.i18nText('Dec-Dcm_Connection_Form_Driver'),
form:{
form: {
type: TextValueCombo,
cls: 'bi-border',
width: 300,
@ -89,10 +89,10 @@ const Widget: WidgetType = {
{
type: FormItem,
text: BI.i18nText('Dec-Dcm_Connection_Form_URL'),
form:{
form: {
type: Editor,
cls: 'bi-border',
watermark:BI.i18nText('Dec-Dcm_Connection_Form_Place_Input'),
watermark: BI.i18nText('Dec-Dcm_Connection_Form_Place_Input'),
width: 300,
value: linkSelected.url,
listeners: [{
@ -109,12 +109,18 @@ const Widget: WidgetType = {
{
type: FormItem,
text: BI.i18nText('Dec-Dcm_Connection_Form_OriginalCharsetName'),
form:{
form: {
type: TextValueCombo,
cls: 'bi-border',
width: 300,
text: linkSelected.originalCharsetName === '' ? BI.i18nText('Dec-Dcm_Connection_Form_Auto') : linkSelected.originalCharsetName,
items: BI.Constants.getConstant(charset),
items: [
{
text: BI.i18nText('Dec-Dcm_Connection_Form_Auto'),
value: '',
},
...BI.Constants.getConstant(charset),
],
listeners: [{
eventName: BI.TextValueCombo.EVENT_CHANGE,
action() {
@ -129,11 +135,11 @@ const Widget: WidgetType = {
{
type: FormItem,
text: BI.i18nText('Dec-Dcm_Connection_Form_UserName'),
form:{
form: {
type: Editor,
cls: 'bi-border',
allowBlank:true,
watermark:BI.i18nText('Dec-Dcm_Connection_Form_Place_Input'),
allowBlank: true,
watermark: BI.i18nText('Dec-Dcm_Connection_Form_Place_Input'),
width: 300,
value: linkSelected.user,
listeners: [{
@ -150,12 +156,12 @@ const Widget: WidgetType = {
{
type: FormItem,
text: BI.i18nText('Dec-Dcm_Connection_Form_Password'),
form:{
form: {
type: Editor,
cls: 'bi-border',
inputType:'password',
allowBlank:true,
watermark:BI.i18nText('Dec-Dcm_Connection_Form_Place_Input'),
inputType: 'password',
allowBlank: true,
watermark: BI.i18nText('Dec-Dcm_Connection_Form_Place_Input'),
width: 300,
value: linkSelected.password,
listeners: [{
@ -177,13 +183,13 @@ const Widget: WidgetType = {
type: FormItem,
text: BI.i18nText('Dec-Dcm_Connection_Form_SQL_Validation_Query'),
height: 100,
form:{
form: {
type: TextAreaEditor,
cls: 'bi-border',
allowBlank:true,
watermark:BI.i18nText('Dec-Dcm_Connection_Form_Place_Input'),
allowBlank: true,
watermark: BI.i18nText('Dec-Dcm_Connection_Form_Place_Input'),
width: 300,
height:100,
height: 100,
value: linkSelected.validationQuery,
listeners: [{
eventName: BI.Editor.EVENT_CHANGE,
@ -199,7 +205,7 @@ const Widget: WidgetType = {
{
type: FormItem,
text: BI.i18nText('Dec-Dcm_Connection_Form_Connection-Check'),
form:{
form: {
type: MultiSelectItem,
text: BI.i18nText('Dec-Dcm_Yes'),
selected: linkSelected.testOnBorrow,
@ -218,21 +224,15 @@ const Widget: WidgetType = {
{
type: FormItem,
text: BI.i18nText('Dec-Dcm_Connection_Form_Connection_Max_Number'),
form:{
form: {
type: Editor,
cls: 'bi-border',
allowBlank:true,
watermark:BI.i18nText('Dec-Dcm_Connection_Form_Place_Input'),
allowBlank: true,
watermark: BI.i18nText('Dec-Dcm_Connection_Form_Place_Input'),
width: 60,
value: linkSelected.maxActive,
errorText: BI.i18nText('Dec-Dcm_Connection_Form_Place_Input-Number'),
validationChecker (v: string) {
if (/^\+?[1-9][0-9]*$/.test(v)) {
return true;
}
return false;
},
validationChecker: connectNameChecker,
listeners: [{
eventName: BI.Editor.EVENT_CHANGE,
action() {

4
src/app/link_set/right/right_edit/right.edit.constant.ts

@ -1,10 +1,6 @@
export const ConstantName = 'bi.constant.database.conf.charset.list';
export const Constant = BI.constant(ConstantName, [
{
text: '自动',
value: '',
},
{
text: 'GBK',
value: 'GBK',

58
src/app/link_set/right/right_edit/right.edit.mysql.component.ts

@ -4,7 +4,7 @@ import charset from './right.edit.constant';
import Model from '../../link-set.model';
import FormItem from '@shared/components/form.item.component';
import Title from '@shared/components/title.component';
import {getDrivers} from './right.edit.service';
import {getDrivers, connectNameChecker} from './right.edit.service';
const className = 'fr.component.right.edit.mysql';
const Widget: WidgetType = {
_store() {
@ -22,7 +22,7 @@ const Widget: WidgetType = {
type: FormItem,
text: BI.i18nText('Dec-Dcm_Connection_Form_ConnectionName'),
hint: BI.i18nText('Dec-Dcm_Connection_Form_ConnectionName-Change-Confirm'),
form:{
form: {
type: Editor,
cls: 'bi-border',
width: 300,
@ -41,7 +41,7 @@ const Widget: WidgetType = {
{
type: FormItem,
text: BI.i18nText('Dec-Dcm_Connection_Form_Driver'),
form:{
form: {
type: TextValueCombo,
cls: 'bi-border',
width: 300,
@ -61,10 +61,10 @@ const Widget: WidgetType = {
{
type: FormItem,
text: BI.i18nText('Dec-Dcm_Connection_Form_URL'),
form:{
form: {
type: Editor,
cls: 'bi-border',
watermark:BI.i18nText('Dec-Dcm_Connection_Form_Place_Input'),
watermark: BI.i18nText('Dec-Dcm_Connection_Form_Place_Input'),
width: 300,
value: linkSelected.url,
listeners: [{
@ -81,12 +81,18 @@ const Widget: WidgetType = {
{
type: FormItem,
text: BI.i18nText('Dec-Dcm_Connection_Form_OriginalCharsetName'),
form:{
form: {
type: TextValueCombo,
cls: 'bi-border',
width: 300,
text: linkSelected.originalCharsetName === '' ? BI.i18nText('Dec-Dcm_Connection_Form_Auto') : linkSelected.originalCharsetName,
items: BI.Constants.getConstant(charset),
items: [
{
text: BI.i18nText('Dec-Dcm_Connection_Form_Auto'),
value: '',
},
...BI.Constants.getConstant(charset),
],
listeners: [{
eventName: BI.TextValueCombo.EVENT_CHANGE,
action() {
@ -101,11 +107,11 @@ const Widget: WidgetType = {
{
type: FormItem,
text: BI.i18nText('Dec-Dcm_Connection_Form_UserName'),
form:{
form: {
type: Editor,
cls: 'bi-border',
allowBlank:true,
watermark:BI.i18nText('Dec-Dcm_Connection_Form_Place_Input'),
allowBlank: true,
watermark: BI.i18nText('Dec-Dcm_Connection_Form_Place_Input'),
width: 300,
value: linkSelected.user,
listeners: [{
@ -122,12 +128,12 @@ const Widget: WidgetType = {
{
type: FormItem,
text: BI.i18nText('Dec-Dcm_Connection_Form_Password'),
form:{
form: {
type: Editor,
cls: 'bi-border',
inputType:'password',
allowBlank:true,
watermark:BI.i18nText('Dec-Dcm_Connection_Form_Place_Input'),
inputType: 'password',
allowBlank: true,
watermark: BI.i18nText('Dec-Dcm_Connection_Form_Place_Input'),
width: 300,
value: linkSelected.password,
listeners: [{
@ -149,13 +155,13 @@ const Widget: WidgetType = {
type: FormItem,
text: BI.i18nText('Dec-Dcm_Connection_Form_SQL_Validation_Query'),
height: 100,
form:{
form: {
type: TextAreaEditor,
cls: 'bi-border',
allowBlank:true,
watermark:BI.i18nText('Dec-Dcm_Connection_Form_Place_Input'),
allowBlank: true,
watermark: BI.i18nText('Dec-Dcm_Connection_Form_Place_Input'),
width: 300,
height:100,
height: 100,
value: linkSelected.validationQuery,
listeners: [{
eventName: BI.Editor.EVENT_CHANGE,
@ -171,7 +177,7 @@ const Widget: WidgetType = {
{
type: FormItem,
text: BI.i18nText('Dec-Dcm_Connection_Form_Connection-Check'),
form:{
form: {
type: MultiSelectItem,
text: BI.i18nText('Dec-Dcm_Yes'),
selected: linkSelected.testOnBorrow,
@ -190,21 +196,15 @@ const Widget: WidgetType = {
{
type: FormItem,
text: BI.i18nText('Dec-Dcm_Connection_Form_Connection_Max_Number'),
form:{
form: {
type: Editor,
cls: 'bi-border',
allowBlank:true,
watermark:BI.i18nText('Dec-Dcm_Connection_Form_Place_Input'),
allowBlank: true,
watermark: BI.i18nText('Dec-Dcm_Connection_Form_Place_Input'),
width: 60,
value: linkSelected.maxActive,
errorText: BI.i18nText('Dec-Dcm_Connection_Form_Place_Input-Number'),
validationChecker (v: string) {
if (/^\+?[1-9][0-9]*$/.test(v)) {
return true;
}
return false;
},
validationChecker: connectNameChecker,
listeners: [{
eventName: BI.Editor.EVENT_CHANGE,
action() {

4
src/app/link_set/right/right_edit/right.edit.service.ts

@ -18,3 +18,7 @@ export function getDrivers(linkSelected: LinkType): {text: string; value: string
return drivers;
}
export function connectNameChecker(name: string): boolean {
return /^\+?[1-9][0-9]*$/.test(name);
}

16
src/demo/plugin.redis.edit.ts

@ -1,7 +1,7 @@
import './style.scss';
const RedisConstantName = 'dec.constant.database.conf.connect.form.redis.value';
const form = {
url:'192.168.1.22',
url: '192.168.1.22',
port: 6379,
password: '123456',
};
@ -11,8 +11,8 @@ const Widget = BI.inherit(BI.Widget, {
render() {
return {
type: 'bi.vertical',
cls:'bi-plugin-redis',
bgap:10,
cls: 'bi-plugin-redis',
bgap: 10,
items: [
{
type: 'bi.left',
@ -29,7 +29,7 @@ const Widget = BI.inherit(BI.Widget, {
type: 'bi.editor',
cls: 'bi-border',
watermark: BI.i18nText('Dec-Dcm_Connection_Form_Database_Addr'),
value:form.url,
value: form.url,
allowBlank: true,
width: 300,
height: 24,
@ -56,11 +56,7 @@ const Widget = BI.inherit(BI.Widget, {
value: form.port,
errorText: BI.i18nText('Dec-Dcm_Connection_Form_Place_Input-Number'),
validationChecker (v: string) {
if (/^\+?[1-9][0-9]*$/.test(v)) {
return true;
}
return false;
return /^\+?[1-9][0-9]*$/.test(v);
},
}],
},
@ -78,7 +74,7 @@ const Widget = BI.inherit(BI.Widget, {
{
type: 'bi.editor',
cls: 'bi-border',
inputType:'password',
inputType: 'password',
value: form.password,
allowBlank: true,
width: 300,

Loading…
Cancel
Save