58 lines
1.5 KiB
JavaScript
58 lines
1.5 KiB
JavaScript
const formatNumber = (n) => {
|
|
n = n.toString();
|
|
return n[1] ? n : `0${n}`;
|
|
};
|
|
|
|
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(':')}`;
|
|
};
|
|
|
|
// 复制到本地临时路径,方便预览
|
|
const getLocalUrl = (path, name) => {
|
|
const fs = wx.getFileSystemManager();
|
|
const tempFileName = `${wx.env.USER_DATA_PATH}/${name}`;
|
|
fs.copyFileSync(path, tempFileName);
|
|
return tempFileName;
|
|
};
|
|
|
|
/**
|
|
* 解析实验室结果字符串为结构化对象数组
|
|
* @param {string} str - 原始字符串
|
|
* @returns {Array} 结构化结果数组
|
|
*/
|
|
function parseLabResults(str) {
|
|
if (!str) return [];
|
|
// 替换特殊换行符为标准换行
|
|
str = str.replace(/↵/g, '\n');
|
|
const lines = str.split(/\n+/).filter(Boolean);
|
|
const result = [];
|
|
const regex = /^(\d+)([\u4e00-\u9fa5A-Za-z]+)([\d.]+)([a-zA-Zμ\/]+)?([\d.\-]+)?/;
|
|
lines.forEach(line => {
|
|
// 尝试用正则提取
|
|
const match = line.match(/^(\d+)([\u4e00-\u9fa5A-Za-z]+)([\d.]+)([a-zA-Zμ\/]+)?([\d.\-]+)?/);
|
|
if (match) {
|
|
result.push({
|
|
index: Number(match[1]),
|
|
name: match[2],
|
|
value: Number(match[3]),
|
|
unit: match[4] || '',
|
|
reference: match[5] || ''
|
|
});
|
|
}
|
|
});
|
|
return result;
|
|
}
|
|
|
|
module.exports = {
|
|
formatTime,
|
|
getLocalUrl,
|
|
parseLabResults,
|
|
};
|