feat: v3版疗休养优化6
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
const sublime = {
|
||||
jumpPagePjax(url) {
|
||||
window.location.href = url;
|
||||
},
|
||||
showLoadingbar() {
|
||||
if (!document.getElementById('therapy-loading')) {
|
||||
const bar = document.createElement('div');
|
||||
@@ -12,6 +15,77 @@ const sublime = {
|
||||
}
|
||||
};
|
||||
|
||||
Vue.prototype.$validateForm = function(form) {
|
||||
return new Promise(resolve => {
|
||||
if (!form) {
|
||||
this.$message.error('表单尚未加载完成');
|
||||
resolve(false);
|
||||
return;
|
||||
}
|
||||
const uploading = component => {
|
||||
if (Array.isArray(component.uploadFiles) && component.uploadFiles.some(file => file.status === 'uploading')) return true;
|
||||
return (component.$children || []).some(uploading);
|
||||
};
|
||||
if (uploading(form)) {
|
||||
this.$message.warning('请等待图片或附件上传完成后再提交');
|
||||
resolve(false);
|
||||
return;
|
||||
}
|
||||
form.validate((valid, fields) => {
|
||||
if (!valid) {
|
||||
const errors = Object.values(fields || {}).flat();
|
||||
this.$message.warning(errors.length ? errors[0].message : '请检查必填项和填写格式');
|
||||
}
|
||||
resolve(valid);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
Vue.prototype.$confirmAction = async function(...args) {
|
||||
try {
|
||||
return await this.$confirm(...args);
|
||||
} catch (error) {
|
||||
if (error === 'cancel' || error === 'close') return false;
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
Vue.prototype.$actionError = function(error) {
|
||||
if (error === 'cancel' || error === 'close') return;
|
||||
const message = error && (error.responseJSON && error.responseJSON.msg || error.msg || error.message);
|
||||
this.$message.error(message || '操作失败,请稍后重试');
|
||||
};
|
||||
|
||||
Vue.prototype.$downloadFile = function(url) {
|
||||
window.location.href = url;
|
||||
};
|
||||
|
||||
Vue.prototype.$importExcel = function(url, files) {
|
||||
const data = new FormData();
|
||||
files.forEach(file => data.append('file', file.raw, file.raw.name));
|
||||
return $.ajax({url: url, type: 'POST', data: data, processData: false, contentType: false});
|
||||
};
|
||||
|
||||
Vue.directive('throttle', {
|
||||
bind(el) {
|
||||
let lastClick = 0;
|
||||
el.therapyThrottleHandler = event => {
|
||||
const now = Date.now();
|
||||
if (now - lastClick < 1000) {
|
||||
event.preventDefault();
|
||||
event.stopImmediatePropagation();
|
||||
return;
|
||||
}
|
||||
lastClick = now;
|
||||
};
|
||||
el.addEventListener('click', el.therapyThrottleHandler, true);
|
||||
},
|
||||
unbind(el) {
|
||||
el.removeEventListener('click', el.therapyThrottleHandler, true);
|
||||
delete el.therapyThrottleHandler;
|
||||
}
|
||||
});
|
||||
|
||||
$.ajaxSetup({
|
||||
traditional: true,
|
||||
error(xhr) {
|
||||
|
||||
Reference in New Issue
Block a user