feat(ncform): add $ncformAllRules and $ncformAllWidgets apis

This commit is contained in:
daniel.xiao
2019-04-28 17:51:14 +08:00
parent beead193b8
commit c5659920a2
4 changed files with 55 additions and 1 deletions
+18
View File
@@ -253,6 +253,24 @@ class MyCustomRule extends ncformCommon.ValidationRule {
this.$ncformAddRule({name: 'myCustom', rule: MyCustomRule});
```
- $ncformAllRules()
Get all registered check rules of ncform
```
// Demo code:
const allRules = this.$ncformAllRules();
```
- $ncformAllWidgets()
Get all registered widgets of ncform
```
// Demo code:
const allRules = this.$ncformAllWidgets();
```
## ncform event
- submit
+18
View File
@@ -254,6 +254,24 @@ class MyCustomRule extends ncformCommon.ValidationRule {
this.$ncformAddRule({name: 'myCustom', rule: MyCustomRule});
```
- $ncformAllRules()
取得ncform所有注册的校验规则
```
// Demo code:
const allRules = this.$ncformAllRules();
```
- $ncformAllWidgets()
取得ncform所有注册的表单组件
```
// Demo code:
const allRules = this.$ncformAllWidgets();
```
## ncform event
- submit
@@ -80,4 +80,11 @@ context('Others', () => {
})
})
it('$ncformAllWidgets and $ncformAllRules()', () => {
cy.window().then(win => {
expect(win.Vue.prototype.$ncformAllRules()).to.deep.equal(["contains", "exclusiveMinimum", "ipv6", "maximum", "minimum", "required", "dateTime", "hostname", "maxItems", "minItems", "multipleOf", "tel", "email", "maxLength", "minLength", "number", "uniqueItems", "exclusiveMaximum", "ipv4", "maxProperties", "minProperties", "pattern", "url", "ajax"]);
expect(win.Vue.prototype.$ncformAllWidgets()).to.deep.equal(["object", "array", "array-table", "input"]);
})
})
})
@@ -22,6 +22,8 @@ module.exports = {
install: (Vue, options = { extComponents: {}, extRules: [], lang: '' }) => {
window.__$ncform = {}; // 属于ncform的全局变量
window.__$ncform.__ncformComponents = {};
window.__$ncform.__ncFormsGlobalList = {};
window.__$ncform.__ncformRegularValidation = new RegularValidation();
@@ -31,7 +33,7 @@ module.exports = {
// 注册组件
_map(
Object.assign(defLayouts, defControls, options.extComponents || {}),
(compItem, name) => Vue.component(`ncform-${_kebabCase(name)}`, compItem)
(compItem, name) => { window.__$ncform.__ncformComponents[_kebabCase(name)] = 1; Vue.component(`ncform-${_kebabCase(name)}`, compItem) }
);
// 注册验证规则
@@ -62,6 +64,7 @@ module.exports = {
};
Vue.prototype.$ncformAddWidget = function({name, widget}) {
window.__$ncform.__ncformComponents[_kebabCase(name)] = 1;
Vue.component(`ncform-${_kebabCase(name)}`, widget)
}
@@ -71,6 +74,14 @@ module.exports = {
window.__$ncform.__ncformRegularValidation.registerRule(ruleItem);
}
Vue.prototype.$ncformAllRules = function() {
return Object.keys(window.__$ncform.__ncformRegularValidation.allRules);
}
Vue.prototype.$ncformAllWidgets = function() {
return Object.keys(window.__$ncform.__ncformComponents);
}
Vue.component("ncform", ncform);
}
};