@caxa-form/core
Version:
vue动态表单,助你轻松搞定表单|form-create is a form generation component that can generate dynamic rendering, data collection, verification and submission functions through JSON. Supports 3 UI frameworks, and supports the generation of any Vue components. Built-in 20
47 lines (41 loc) • 1.44 kB
JavaScript
import extend from '@caxa-form/utils/lib/extend';
import is from '@caxa-form/utils/lib/type';
const EVENT = ['hook:updated', 'hook:mounted'];
export default function usePage(Handler) {
extend(Handler.prototype, {
usePage() {
const page = this.options.page;
if (!page) return;
let first = 25;
let limit = getLimit(this.rules);
if (is.Object(page)) {
if (page.first) first = parseInt(page.first, 10) || first;
if (page.limit) limit = parseInt(page.limit, 10) || limit;
}
extend(this, {
first,
limit,
pageEnd: this.rules.length <= first,
})
this.bus.$on('page-end', () => this.vm.$emit('page-end', this.api));
this.pageLoad();
},
pageLoad() {
const pageFn = () => {
if (this.pageEnd) {
this.vm.$off(EVENT, pageFn);
this.bus.$emit('page-end');
} else {
this.first += this.limit;
this.pageEnd = this.rules.length <= this.first;
this.loadRule();
this.refresh();
}
}
this.vm.$on(EVENT, pageFn);
},
})
}
function getLimit(rules) {
return rules.length < 31 ? 31 : Math.ceil(rules.length / 3);
}