import { $http } from '../config/https'; import { httpconfig } from '../config/httpconfig'; /** * 格式化时间 * @param {Date} date - 日期对象 * @returns {string} 格式化后的时间字符串 */ const formatTime = (date) => { const year = date.getFullYear(); const month = date.getMonth() + 1; const day = date.getDate(); const hour = date.getHours(); const minute = date.getMinutes(); const second = date.getSeconds(); return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':'); }; /** * 数字补零 * @param {number} n - 需要处理的数字 * @returns {string} 补零后的字符串 */ const formatNumber = (n) => { n = n.toString(); return n[1] ? n : '0' + n; }; /** * 防抖函数 * @param {Function} fn - 需要防抖的函数 * @param {number} interval - 间隔时间,默认300ms * @returns {Function} 防抖处理后的函数 */ const debounce = (fn, interval) => { let timer; const gapTime = interval || 300; return function (...args) { clearTimeout(timer); const that = this; timer = setTimeout(() => { fn.call(that, ...args); }, gapTime); }; }; /** * 获取患者信息 * @param {*} admID - 住院ID * @param {Function} callback - 回调函数 */ const getPatInfo = (admID, callback) => { // 移除 $http.post 中的 this 参数(非组件环境中 this 无意义) $http.post('urlDeault',this, { code: '03030002', data: { params: [{ admID }] }, success: (res) => { if (res.errorCode === '0') { // 直接使用全局 uni 对象,无需导入 uni.setStorage({ data: res.result, key: 'patInfo' }); callback(res.result); } } }); }; /** * 获取患者信息新接口 * @param {*} patNo - 患者编号 * @param {Function} callback - 回调函数 */ const getPatInfoNew = (patNo, callback) => { $http.post('urlDeault',this, { code: '03030092', data: { params: [{ patNo }] }, success: (res) => { if (res.errorCode === '0') { uni.setStorage({ data: res.result, key: 'patInfo' }); callback(res.result); } } }); }; /** * 获取条码信息 * @param {*} barcode - 条码 * @param {*} admID - 住院ID * @param {Function} callback - 回调函数 */ const getBarcodeInfo = (barcode, admID, callback) => { $http.post('urlDeault',this, { code: '04220019', data: { params: [{ barcode, admID }] }, success: (res) => { if (res.errorCode === '0') { callback(res.result); } else { uni.showToast({ title: res.errorMessage, icon: 'none' }); } } }); }; export default { formatTime, formatNumber, debounce, getPatInfo, getPatInfoNew, getBarcodeInfo };