|
|
// import sysConfig from "./mm";
// import { getapi, postapi, putapi, deletapi } from "@/api/api";
const sysConfig = require('./mm');const {getapi, postapi, putapi, deletapi} = require('../api/api');
//多级联动选择数据处理 add by pengjun
function tcdate(date) { for (var i = 0; i < date.length; i++) { if (date[i].treeChildren.length == 0) { date[i].treeChildren = undefined; } else { tcdate(date[i].treeChildren); } }};exports.tcdate = tcdate;
//json 对像赋值 只从 from 对象 赋值 to 中有的 key 项 add by pengjun
function objCopy(from, to) { if (from && to) { let keys = Object.keys(to); for (let key in keys) { if (from[keys[key]] !== undefined) { to[keys[key]] = from[keys[key]]; } } }};exports.objCopy = objCopy;
//对象深拷贝
function deepCopy(obj) { if (obj == null || typeof obj != 'object') { return obj; } let copy; if (Array.isArray(obj)) { copy = []; for (let i = 0; i < obj.length; i++) { copy[i] = deepCopy(obj[i]); } } else { copy = {}; for (let key in obj) { copy[key] = deepCopy(obj[key]); } } return copy;};exports.deepCopy = deepCopy;
//类似PB中的dddw的功能 add by pengjun
function dddw(arrayData, key, value, display) { //console.log(arrayData,key,value,display)
let ret = value; if (arrayData) { for (let i = 0; i < arrayData.length; i++) { if (arrayData[i][key] == value) { ret = arrayData[i][display]; break; } } } return ret;};exports.dddw = dddw;
//一般uuid字段为空时,需设置为null值
function setNull(obj, arrayKeys) { if (arrayKeys) { for (let i = 0; i < arrayKeys.length; i++) { if (!obj[arrayKeys[i]] || obj[arrayKeys[i]].length < 1) { obj[arrayKeys[i]] = null; } } }};exports.setNull = setNull;
//将字符串转换成二进制形式,中间用空格隔开
function strToBinary(str) { let result = []; let list = str.split(""); for (var i = 0; i < list.length; i++) { if (i != 0) { result.push(" "); } let item = list[i]; let binaryStr = item.charCodeAt().toString(2); result.push(binaryStr); } return result.join("");};exports.strToBinary = strToBinary;
//将二进制字符串转换成Unicode字符串
function binaryToStr(str) { var result = []; var list = str.split(" "); for (var i = 0; i < list.length; i++) { var item = list[i]; var asciiCode = parseInt(item, 2); var charValue = String.fromCharCode(asciiCode); result.push(charValue); } return result.join("");};exports.binaryToStr = binaryToStr;
//数组过滤出符合条件的
function arrayFilter(arr, key, value) { let result = []; for (let i = 0; i < arr.length; i++) { if (arr[i][key] == value) { result.push(arr[i]); } } return result;};exports.arrayFilter = arrayFilter;
//数组相减 arrFront = arrFront - reduceArr ;
function arrayReduce(arrFront, reduceArr, key) { let keys = key.split("="); let keyF = keys[0]; let keyR = keys.length > 1 ? keys[1] : keys[0]; //console.log(arrFront, reduceArr)
if (!arrFront || arrFront.length < 1 || !reduceArr || reduceArr.length < 1) { return arrFront; } //console.log(arrFront.length, reduceArr.length)
for (let i = 0; i < reduceArr.length; i++) { //console.log('i', i)
for (let j = 0; j < arrFront.length; j++) { //console.log('j', j)
if (reduceArr[i][keyR] == arrFront[j][keyF]) { arrFront.splice(j, 1); } } } return arrFront;};exports.arrayReduce = arrayReduce;
//判断数组中 是否存在 某个值的对象记录 如不存在返回 - 1,存在返回相应的 序列
function arrayExistObj(arr, key, value) { let ret = - 1 for (let i = 0; i < arr.length; i++) { if (arr[i][key] == value) { ret = i break } } return ret};exports.arrayExistObj = arrayExistObj;
//根据身份证号判断出生日期(yyyy-MM-DD),当前年龄与性别 粗犷式,不精确判断闰年平年
function parseID(id) { let yearInMs = 1000 * 60 * 60 * 24 * 365.2425; let ret = { birthday: '', age: -1, sex: 'U', } if (!id || id.length != 18) return ret if (id.substring(10, 12).parseInt > 12 || id.substring(10, 12).parseInt == 0) return ret if (id.substring(12, 14).parseInt > 31 || id.substring(12, 14).parseInt == 0) return ret
//出生日期
ret.birthday = id.substring(6, 10) + '-' + id.substring(10, 12) + '-' + id.substring(12, 14)
//年龄
ret.age = Math.floor((new Date().getTime() - new Date(ret.birthday).getTime()) / yearInMs)
//奇数 男, 偶数 女
if (id.substring(16, 17) % 2 == 0) { ret.sex = 'F' } else { ret.sex = 'M' }
return ret};exports.parseID = parseID;
//根据出生日期,计算当前年龄 粗犷式,不精确判断闰年平年
function birthdayToAge(birthday) { let yearInMs = 1000 * 60 * 60 * 24 * 365.2425; //年龄
return Math.floor((new Date().getTime() - new Date(birthday).getTime()) / yearInMs)};exports.birthdayToAge = birthdayToAge;
//分析身份证数据
function parsIcCardtoLocal(idNos, dictSex, dictNation) { let local = deepCopy(idNos); // {
// "Code": "Success",
// "Name": "刘滔",
// "Sex": "男",
// "Nation": "汉",
// "Birthday": "1986-01-22",
// "Address": "湖南省长沙县春华镇九木村新元组367号",
// "DepartmentIC": "长沙县公安局",
// "StartDateIC": "2019-11-25",
// "EndDateIC": "2039-11-25",
// "IDCode": "430121198601223693",
// "Photo": ""
// }
console.log(local, dictSex, dictNation) let lfind = -1; lfind = arrayExistObj(dictSex, 'displayName', local.Sex) console.log(lfind,local.Sex) if (lfind > -1) local.sexId = dictSex[lfind].id;
lfind = arrayExistObj(dictNation, 'displayName', local.Nation + '族') console.log(lfind,local.Nation) if (lfind > -1) local.nationId = dictNation[lfind].nationId;
local.birthDate = new Date(local.Birthday) local.age = birthdayToAge(local.Birthday) return local};exports.parsIcCardtoLocal = parsIcCardtoLocal;
function photoParse(photo) { //console.log(sysConfig,photo)
let lphoto = '' //data:image、UpLoad/、/pic/Photo.jpg
if (photo.indexOf("UpLoad/") > - 1) { lphoto = sysConfig.apiurl + '/' + photo + '?' + new Date().getTime() } else { lphoto = photo } //console.log(lphoto)
return lphoto};exports.photoParse = photoParse;
async function savePeoplePhoto(peopleId, photoBase64) { let lres = { code: -1, msg: '' } if (!peopleId) return { code: -1, msg: '人员ID不能为空' } if (!photoBase64 || photoBase64.indexOf('data:image') < 0) return { code: -1, msg: '图像数据不是合法的base64编码数据' }
let uploadPhoto = { patientRegisterId: peopleId, photo: photoBase64.split(",")[1], };
try { lres = await postapi(`/api/app/patient-register/up-load-img`, uploadPhoto) let body = { patientRegisterId: peopleId, photo: lres.data, } await postapi(`/api/app/patient-register/update-photo`, body)
} catch (error) { lres = { code: -1, msg: error } } return lres};exports.savePeoplePhoto = savePeoplePhoto;
|