diff --git a/CONFIG.md b/CONFIG.md index bf00f38..a6a85aa 100755 --- a/CONFIG.md +++ b/CONFIG.md @@ -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 diff --git a/CONFIG_CN.md b/CONFIG_CN.md index e6856ca..793255d 100644 --- a/CONFIG_CN.md +++ b/CONFIG_CN.md @@ -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 diff --git a/packages/ncform-e2e/ncform/cypress/integration/examples/others.js b/packages/ncform-e2e/ncform/cypress/integration/examples/others.js index 56af222..863f37f 100644 --- a/packages/ncform-e2e/ncform/cypress/integration/examples/others.js +++ b/packages/ncform-e2e/ncform/cypress/integration/examples/others.js @@ -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"]); + }) + }) + }) diff --git a/packages/ncform/src/components/vue-ncform/index.js b/packages/ncform/src/components/vue-ncform/index.js index c2861b5..8043ff3 100755 --- a/packages/ncform/src/components/vue-ncform/index.js +++ b/packages/ncform/src/components/vue-ncform/index.js @@ -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); } };