|
|
|
@ -1,16 +1,22 @@ |
|
|
|
// 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
|
|
|
|
exports.tcdate = (date) => { |
|
|
|
function tcdate(date) { |
|
|
|
for (var i = 0; i < date.length; i++) { |
|
|
|
if (date[i].treeChildren.length == 0) { |
|
|
|
date[i].treeChildren = undefined; |
|
|
|
} else { |
|
|
|
this.tcdate(date[i].treeChildren); |
|
|
|
tcdate(date[i].treeChildren); |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
exports.tcdate = tcdate; |
|
|
|
|
|
|
|
//json 对像赋值 只从 from 对象 赋值 to 中有的 key 项 add by pengjun
|
|
|
|
exports.objCopy = (from, to) => { |
|
|
|
function objCopy(from, to) { |
|
|
|
if (from && to) { |
|
|
|
let keys = Object.keys(to); |
|
|
|
for (let key in keys) { |
|
|
|
@ -20,30 +26,32 @@ exports.objCopy = (from, to) => { |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
exports.objCopy = objCopy; |
|
|
|
|
|
|
|
//对象深拷贝
|
|
|
|
function deepCopy(obj) { |
|
|
|
if (obj == null || typeof obj != 'object') { |
|
|
|
return obj; |
|
|
|
return obj; |
|
|
|
} |
|
|
|
let copy; |
|
|
|
if (Array.isArray(obj)) { |
|
|
|
copy = []; |
|
|
|
for (let i = 0; i < obj.length; i++) { |
|
|
|
copy[i] = deepCopy(obj[i]); |
|
|
|
} |
|
|
|
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]); |
|
|
|
} |
|
|
|
copy = {}; |
|
|
|
for (let key in obj) { |
|
|
|
copy[key] = deepCopy(obj[key]); |
|
|
|
} |
|
|
|
} |
|
|
|
return copy; |
|
|
|
}; |
|
|
|
exports.deepCopy = deepCopy; |
|
|
|
|
|
|
|
|
|
|
|
//类似PB中的dddw的功能 add by pengjun
|
|
|
|
exports.dddw = (arrayData, key, value, display) => { |
|
|
|
function dddw(arrayData, key, value, display) { |
|
|
|
//console.log(arrayData,key,value,display)
|
|
|
|
let ret = value; |
|
|
|
if (arrayData) { |
|
|
|
@ -56,9 +64,10 @@ exports.dddw = (arrayData, key, value, display) => { |
|
|
|
} |
|
|
|
return ret; |
|
|
|
}; |
|
|
|
exports.dddw = dddw; |
|
|
|
|
|
|
|
//一般uuid字段为空时,需设置为null值
|
|
|
|
exports.setNull = (obj, arrayKeys) => { |
|
|
|
function setNull(obj, arrayKeys) { |
|
|
|
if (arrayKeys) { |
|
|
|
for (let i = 0; i < arrayKeys.length; i++) { |
|
|
|
if (!obj[arrayKeys[i]] || obj[arrayKeys[i]].length < 1) { |
|
|
|
@ -67,9 +76,10 @@ exports.setNull = (obj, arrayKeys) => { |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
exports.setNull = setNull; |
|
|
|
|
|
|
|
//将字符串转换成二进制形式,中间用空格隔开
|
|
|
|
exports.strToBinary = function (str) { |
|
|
|
function strToBinary(str) { |
|
|
|
let result = []; |
|
|
|
let list = str.split(""); |
|
|
|
for (var i = 0; i < list.length; i++) { |
|
|
|
@ -82,9 +92,10 @@ exports.strToBinary = function (str) { |
|
|
|
} |
|
|
|
return result.join(""); |
|
|
|
}; |
|
|
|
exports.strToBinary = strToBinary; |
|
|
|
|
|
|
|
//将二进制字符串转换成Unicode字符串
|
|
|
|
exports.binaryToStr = function (str) { |
|
|
|
function binaryToStr(str) { |
|
|
|
var result = []; |
|
|
|
var list = str.split(" "); |
|
|
|
for (var i = 0; i < list.length; i++) { |
|
|
|
@ -95,9 +106,10 @@ exports.binaryToStr = function (str) { |
|
|
|
} |
|
|
|
return result.join(""); |
|
|
|
}; |
|
|
|
exports.binaryToStr = binaryToStr; |
|
|
|
|
|
|
|
//数组过滤出符合条件的
|
|
|
|
exports.arrayFilter = function (arr, key, value) { |
|
|
|
function arrayFilter(arr, key, value) { |
|
|
|
let result = []; |
|
|
|
for (let i = 0; i < arr.length; i++) { |
|
|
|
if (arr[i][key] == value) { |
|
|
|
@ -106,9 +118,10 @@ exports.arrayFilter = function (arr, key, value) { |
|
|
|
} |
|
|
|
return result; |
|
|
|
}; |
|
|
|
exports.arrayFilter = arrayFilter; |
|
|
|
|
|
|
|
//数组相减 arrFront = arrFront - reduceArr ;
|
|
|
|
exports.arrayReduce = function (arrFront, reduceArr, key) { |
|
|
|
function arrayReduce(arrFront, reduceArr, key) { |
|
|
|
let keys = key.split("="); |
|
|
|
let keyF = keys[0]; |
|
|
|
let keyR = keys.length > 1 ? keys[1] : keys[0]; |
|
|
|
@ -128,51 +141,133 @@ exports.arrayReduce = function (arrFront, reduceArr, key) { |
|
|
|
} |
|
|
|
return arrFront; |
|
|
|
}; |
|
|
|
exports.arrayReduce = arrayReduce; |
|
|
|
|
|
|
|
//判断数组中 是否存在 某个值的对象记录 如不存在返回 - 1,存在返回相应的 序列
|
|
|
|
exports.arrayExistObj = function (arr, key, value) { |
|
|
|
function arrayExistObj(arr, key, value) { |
|
|
|
let ret = - 1 |
|
|
|
for(let i = 0;i<arr.length;i++){ |
|
|
|
if(arr[i][key] == value){ |
|
|
|
for (let i = 0; i < arr.length; i++) { |
|
|
|
if (arr[i][key] == value) { |
|
|
|
ret = i |
|
|
|
break |
|
|
|
} |
|
|
|
} |
|
|
|
return ret |
|
|
|
} |
|
|
|
}; |
|
|
|
exports.arrayExistObj = arrayExistObj; |
|
|
|
|
|
|
|
//根据身份证号判断出生日期(yyyy-MM-DD),当前年龄与性别 粗犷式,不精确判断闰年平年
|
|
|
|
exports.parseID = function (id) { |
|
|
|
function parseID(id) { |
|
|
|
let yearInMs = 1000 * 60 * 60 * 24 * 365.2425; |
|
|
|
let ret = { |
|
|
|
birthday:'', |
|
|
|
age:-1, |
|
|
|
sex:'U', |
|
|
|
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 |
|
|
|
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.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) |
|
|
|
ret.age = Math.floor((new Date().getTime() - new Date(ret.birthday).getTime()) / yearInMs) |
|
|
|
|
|
|
|
//奇数 男, 偶数 女
|
|
|
|
if(id.substring(16,17)%2 == 0){ |
|
|
|
if (id.substring(16, 17) % 2 == 0) { |
|
|
|
ret.sex = 'F' |
|
|
|
}else{ |
|
|
|
} else { |
|
|
|
ret.sex = 'M' |
|
|
|
} |
|
|
|
|
|
|
|
return ret |
|
|
|
} |
|
|
|
}; |
|
|
|
exports.parseID = parseID; |
|
|
|
|
|
|
|
//根据出生日期,计算当前年龄 粗犷式,不精确判断闰年平年
|
|
|
|
exports.birthdayToAge = function (birthday) { |
|
|
|
function birthdayToAge(birthday) { |
|
|
|
let yearInMs = 1000 * 60 * 60 * 24 * 365.2425; |
|
|
|
//年龄
|
|
|
|
return Math.floor((new Date().getTime() - new Date(birthday).getTime())/yearInMs) |
|
|
|
} |
|
|
|
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; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|