123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- const FormTypes = {
- normal: 'normal',
- input: 'input',
- inputNumber: 'inputNumber',
- checkbox: 'checkbox',
- select: 'select',
- date: 'date',
- datetime: 'datetime',
- upload: 'upload',
- file: 'file',
- image: 'image',
- popup:'popup',
- list_multi:"list_multi",
- sel_search:"sel_search",
- radio:'radio',
- checkbox_meta:"checkbox_meta",
- slot: 'slot',
- hidden: 'hidden'
- }
- const VALIDATE_NO_PASSED = Symbol()
- export { FormTypes, VALIDATE_NO_PASSED }
- export function getRefPromise(vm, name) {
- return new Promise((resolve) => {
- (function next() {
- let ref = vm.$refs[name]
- if (ref) {
- resolve(ref)
- } else {
- setTimeout(() => {
- next()
- }, 10)
- }
- })()
- })
- }
- export function validateFormAndTables(form, cases) {
- if (!(form && typeof form.validateFields === 'function')) {
- throw `form 参数需要的是一个form对象,而传入的却是${typeof form}`
- }
- let options = {}
- return new Promise((resolve, reject) => {
-
- form.validateFields((err, values) => {
- err ? reject({ error: VALIDATE_NO_PASSED }) : resolve(values)
- })
- }).then(values => {
- Object.assign(options, { formValue: values })
-
- return validateTables(cases)
- }).then(all => {
- Object.assign(options, { tablesValue: all })
- return Promise.resolve(options)
- }).catch(error => {
- return Promise.reject(error)
- })
- }
- export function validateTables(cases) {
- if (!(cases instanceof Array)) {
- throw `'validateTables'函数的'cases'参数需要的是一个数组,而传入的却是${typeof cases}`
- }
- return new Promise((resolve, reject) => {
- let tables = []
- let index = 0;
- (function next() {
- let vm = cases[index]
- vm.getAll(true).then(all => {
- tables[index] = all
-
- if (++index === cases.length) {
- resolve(tables)
- } else (
- next()
- )
- }, error => {
-
- if (error === VALIDATE_NO_PASSED) {
- reject({ error: VALIDATE_NO_PASSED, index })
- }
- reject(error)
- })
- })()
- })
- }
|