const sublime = { jumpPagePjax(url) { window.location.href = url; } }; 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) { const message = xhr.responseJSON && xhr.responseJSON.msg || '请求失败,请稍后重试'; if (window.ELEMENT) ELEMENT.Message.error(message); else if (window.vant) vant.Toast.fail(message); } }); Vue.prototype.$downLoad = function(url, data = {}) { const query = $.param(data, true); window.open(url + (url.includes('?') ? '&' : '?') + query); }; Vue.prototype.$download = Vue.prototype.$downLoad; Vue.prototype.$viewImage = function(url) { const address = CREATE_PREVIEW_URL(url); if (window.vant) vant.ImagePreview([address]); else window.open(address); }; window.viewImage = Vue.prototype.$viewImage; // v3 views use the same helper for stored file IDs and v4 download URLs. window.therapyPreview = function(value) { if (!value) return ''; return /^(https?:|data:|blob:|\/)/.test(value) ? value : '/platform/inclusiveTherapyV3/common/preview?id=' + encodeURIComponent(value); }; if (window.vant) { window.preview = function(filename, id) { const address = therapyPreview(id); if (/\.(jpe?g|png|gif|bmp|webp|svg)$/i.test(filename || '')) { vant.ImagePreview([address]); } else { window.open(address); } }; }