3 lines
35 KiB
JavaScript
3 lines
35 KiB
JavaScript
"use strict";const t=require("../../common/vendor.js"),Kn=require("../composables/useDietAi.js"),Xn=require("../composables/useSpeechToText.js");Math||(Jn+Zn+Qn)();const Jn=()=>"../components/TongjiIcon.js",Qn=()=>"../../components/app-tab-bar/tab-bar-dock.js",Zn=()=>"../../components/dev-training-entry/index.js",ea=30,ta=7,Et={__name:"weekly",setup(aa){const{proxy:y}=t.getCurrentInstance();function Y(e,n=""){if(e==null||e==="")return n;if(typeof e=="string")return e;if(typeof e=="number"||typeof e=="boolean")return String(e);if(Array.isArray(e)){const a=e.map(o=>o==null?"":typeof o=="string"?o:typeof o=="number"||typeof o=="boolean"?String(o):typeof o=="object"?o.msg||o.message||o.error||o.title||o.label||"":String(o)).filter(Boolean);return a.length?a.join(";"):n}return typeof e=="object"?e.msg||e.message||e.error||e.title||e.label||n:String(e)}function h(e,n={}){const a=Y(e,"");a&&t.index.showToast({title:a,icon:n.icon||"none",duration:n.duration||2800})}function jt(e,n=""){var o,r;if(!e)return n;const a=e.msg??e.message??((o=e.data)==null?void 0:o.error)??((r=e.data)==null?void 0:r.msg)??e.errMsg;return Y(a,n)}const f=t.ref(0),O=t.ref("");function Le(){O.value=""}function Ot(e,n="无法开始录入",a={}){const o=jt(e,n);if(o)if(O.value=o,a.alert)t.index.showModal({title:"无法录入血糖",content:o,showCancel:!1,confirmText:"知道了"});else{const r=o.length>14?`${o.slice(0,14)}…`:o;h(r,{duration:3200})}}const z=t.ref(0),N=t.ref(""),zt=t.computed(()=>{const e=String(N.value||"").trim();return e?e.length>10?`${e.slice(0,10)}…`:e:"您好"}),ot=t.ref({}),rt=t.ref({}),we=t.ref({}),H=t.ref(0),K=t.ref(0),{dietAiRecommend:_,dietAiLoading:p,dietAiStreaming:it,dietAiReplacing:lt,dietAiStreamField:D,dietAiAskText:ke,dietAiAsking:T,dietAiAskResult:Z,hasDietAiMealContent:st,fetchDietAiRecommend:Ut,refreshDietAiRecommend:ut,askDietAiFood:De,onDietAiAskInput:ct,applyDietAiToForm:oa,openDietForm:ra}=Kn.useDietAi(y,{diagnosisId:f,showUserToast:h,formatUserMessage:Y}),ee=t.ref(!1),Ee=t.ref(!1);function Gt(){Ee.value=!0}function Wt(){Ee.value=!1}const qt=t.computed(()=>Ee.value||String(ke.value||"").length>0),ge=t.ref(0);function je(e){ge.value=e&&e.height?Math.round(e.height):0}const{sttListening:pe,sttHolding:te,sttSupported:Vt,beginHoldSpeech:Yt,endHoldSpeech:Kt,stopSpeechToText:ft}=Xn.useSpeechToText({onResult(e){const n=String(ke.value||"").trim();ke.value=n?`${n} ${e}`:e},showToast:e=>h(e)});function Xt(){T.value||Yt()}function dt(){Kt()}const Jt=t.computed(()=>(_.value&&Array.isArray(_.value.analysis)?_.value.analysis:[]).filter(n=>n&&typeof n=="object"));t.computed(()=>Jt.value.length>0),t.computed(()=>{const e=_.value&&_.value.exercise;return e&&typeof e=="object"&&Array.isArray(e.items)&&e.items.length?e:null});const U=t.ref(!1),R=t.ref(""),I=t.ref(!1),A=t.ref(0),ve=t.ref(!1),Te=t.ref(!1),gt=t.ref(!1),ne=t.ref([]),Ae=t.ref("7"),Qt=[{value:"7",label:"最近 7 天"},{value:"30",label:"最近 30 天"}],ae=t.ref([]),He=t.ref([]),Me=t.ref([]),$e=t.ref([]),pt=t.ref(null),oe=t.ref({fasting:!0,postprandial:!0});let he=null,G=null,X=0,J=0,re=1;t.computed(()=>H.value>0?`${H.value} 岁`:""),t.computed(()=>({1:"男",2:"女"})[Number(K.value)]||"");const Zt=t.computed(()=>{const e=Qt.find(n=>n.value===Ae.value);return e?e.label:""});function F(e){const n=e.getFullYear(),a=String(e.getMonth()+1).padStart(2,"0"),o=String(e.getDate()).padStart(2,"0");return`${n}-${a}-${o}`}function Oe(e){if(!e)return new Date;const[n,a,o]=e.split("-").map(Number);return new Date(n,(a||1)-1,o||1)}const en=t.computed(()=>{const e=Ae.value==="30"?30:7,n=new Date;n.setHours(0,0,0,0);const a=new Date(n);return a.setDate(a.getDate()-(e-1)),{start:F(a),end:F(n)}}),tn=t.computed(()=>{const e=Ae.value==="30"?30:7,n=Math.max(ea,e),a=new Date;a.setHours(0,0,0,0);const o=new Date(a);return o.setDate(o.getDate()-(n-1)),{start:F(o),end:F(a)}}),ze=t.computed(()=>{const{start:e,end:n}=en.value;if(!e||!n)return[];const a=[],o=Oe(n),r=Oe(e).getTime();for(;o.getTime()>=r;)a.push(F(o)),o.setDate(o.getDate()-1);return a}),M=t.computed(()=>[...ze.value].reverse());function d(e){if(e==null||e==="")return null;const n=Number(e);return Number.isFinite(n)&&n!==0?n:null}function Ue(e){const n=Number(e);return!Number.isFinite(n)||n<=0?{fasting:7,postprandial:10}:n<50?{fasting:7,postprandial:9}:{fasting:8,postprandial:10}}function vt(e){const n=d(e),a=Ue(H.value);return n!==null&&a!==null&&n>=a.fasting}function Ge(e){const n=d(e),a=Ue(H.value);return n!==null&&a!==null&&n>=a.postprandial}function nn(e){if(!e)return!1;const n=d(e.systolic_pressure),a=d(e.diastolic_pressure);return n!==null&&n>140||a!==null&&a>90}function an(e){const n=e==null?void 0:e.systolic_pressure,a=e==null?void 0:e.diastolic_pressure;return(n==null||n===""||n===0)&&(a==null||a===""||a===0)?"—":`${n||"—"} / ${a||"—"}`}const on={1:"低强度",2:"中强度",3:"高强度"},m=t.computed(()=>{const e={};for(const n of ae.value){const a=String(n.record_date||"");if(!a)continue;e[a]||(e[a]={record_date:a,record_time:n.record_time||"",fasting_blood_sugar:"",postprandial_blood_sugar:"",other_blood_sugar:"",systolic_pressure:"",diastolic_pressure:"",western_medicine:"",insulin:"",remark:""});const o=e[a],r=["fasting_blood_sugar","postprandial_blood_sugar","other_blood_sugar","systolic_pressure","diastolic_pressure","western_medicine","insulin","remark"];for(const i of r)(o[i]===""||o[i]===null||o[i]===void 0)&&n[i]!==""&&n[i]!==null&&n[i]!==void 0&&(o[i]=n[i])}for(const n in e){const a=e[n];a.isHighFasting=vt(a.fasting_blood_sugar),a.isHighPostprandial=Ge(a.postprandial_blood_sugar),a.isHighOther=Ge(a.other_blood_sugar),a.isHighBp=nn(a),a.bpText=an(a)}return e});t.computed(()=>{const e={};for(const n of He.value){const a=String(n.record_date||"");!a||e[a]||(e[a]=n)}return e}),t.computed(()=>{const e={};for(const n of Me.value){const a=String(n.record_date||"");if(!a||e[a])continue;const o={...n};o.intensityText=on[Number(n.intensity)]||"",e[a]=o}return e}),t.computed(()=>{const e={};for(const n of $e.value){const a=String(n.note_date||"");!a||e[a]||(e[a]=n)}return e});const rn=["周日","周一","周二","周三","周四","周五","周六"];function ln(e){return rn[Oe(e).getDay()]||""}const Pe=t.computed(()=>F(new Date));t.computed(()=>{const e=[];for(const n of ze.value){const a=m.value[n];if(!a||!(d(a.fasting_blood_sugar)!==null||d(a.postprandial_blood_sugar)!==null||d(a.other_blood_sugar)!==null))continue;const[r,i,l]=n.split("-");e.push({date:n,dateLabel:`${i}-${l}`,weekday:ln(n),isToday:n===Pe.value,blood:a})}return e});function We(e){return e?d(e.fasting_blood_sugar)!==null||d(e.postprandial_blood_sugar)!==null||d(e.other_blood_sugar)!==null:!1}const sn=t.computed(()=>M.value.some(e=>We(m.value[e]))),un=t.computed(()=>M.value.filter(e=>We(m.value[e])).length),cn=t.computed(()=>{let e=0;for(const n of Object.keys(m.value))We(m.value[n])&&e++;return e}),me=t.computed(()=>f.value?cn.value<ta:!0),fn=t.computed(()=>{const e={},n=M.value;return n.forEach((a,o)=>{const r=n.length>1?o/(n.length-1):0,i=Number((5.2+Math.sin(r*Math.PI)*.5+o%2*.15).toFixed(1)),l=Number((7.6+Math.cos(r*Math.PI)*1.1+o%3*.25).toFixed(1)),g={record_date:a,fasting_blood_sugar:i,postprandial_blood_sugar:l,other_blood_sugar:"",systolic_pressure:"",diastolic_pressure:""};g.isHighFasting=vt(g.fasting_blood_sugar),g.isHighPostprandial=Ge(g.postprandial_blood_sugar),g.isHighOther=!1,g.isHighBp=!1,g.bpText="—",e[a]=g}),e}),dn=t.computed(()=>me.value?fn.value:m.value),ht=t.computed(()=>me.value?M.value.length>0:sn.value),gn=t.computed(()=>M.value.filter(e=>{const n=m.value[e];return n&&(n.isHighFasting||n.isHighPostprandial)}).length);t.computed(()=>un.value-gn.value);function qe(e,n,a=1){if(e==null||n==null)return null;const o=Number(e)-Number(n);if(!Number.isFinite(o))return null;const r=Math.abs(o),i=r<.01?"flat":o>0?"up":"down",g=i==="flat"?"持平":`${i==="up"?"+":i==="down"?"-":""}${r.toFixed(a)}`;return{dir:i,delta:r,deltaText:g,prev:n}}function Ve(e,n){const a=M.value,o=a.indexOf(n);if(o<=0)return null;for(let r=o-1;r>=0;r--){const i=m.value[a[r]];if(!i)continue;const l=d(i[e]);if(l!==null)return{date:a[r],value:l}}return null}const Ye=t.computed(()=>{const e=[...M.value].reverse(),n={value:"—",date:"暂无记录",isHigh:!1,trend:null},a={fasting:{...n},postprandial:{...n},other:{...n}};for(const o of e){const r=m.value[o];if(r){if(a.fasting.value==="—"&&d(r.fasting_blood_sugar)!==null){const i=d(r.fasting_blood_sugar),l=Ve("fasting_blood_sugar",o);a.fasting={value:String(r.fasting_blood_sugar),date:o.slice(5),isHigh:r.isHighFasting,trend:l?qe(i,l.value):null}}if(a.postprandial.value==="—"&&d(r.postprandial_blood_sugar)!==null){const i=d(r.postprandial_blood_sugar),l=Ve("postprandial_blood_sugar",o);a.postprandial={value:String(r.postprandial_blood_sugar),date:o.slice(5),isHigh:r.isHighPostprandial,trend:l?qe(i,l.value):null}}if(a.other.value==="—"&&d(r.other_blood_sugar)!==null){const i=d(r.other_blood_sugar),l=Ve("other_blood_sugar",o);a.other={value:String(r.other_blood_sugar),date:o.slice(5),isHigh:r.isHighOther,trend:l?qe(i,l.value):null}}if(a.fasting.value!=="—"&&a.postprandial.value!=="—"&&a.other.value!=="—")break}}return a});function mt(e,n,a){if(!e)return{label:a,value:"—",isHigh:!1};if(d(e[n])===null)return{label:a,value:"—",isHigh:!1};const r=n==="fasting_blood_sugar"?e.isHighFasting:n==="postprandial_blood_sugar"?e.isHighPostprandial:e.isHighOther;return{label:a,value:String(e[n]),isHigh:!!r}}const Ke=t.computed(()=>m.value[Pe.value]||null);t.computed(()=>mt(Ke.value,"fasting_blood_sugar","空腹")),t.computed(()=>mt(Ke.value,"postprandial_blood_sugar","餐后")),t.computed(()=>{const e=Ke.value;return e?d(e.postprandial_blood_sugar)!==null?{hasValue:!0,typeLabel:"餐后",value:String(e.postprandial_blood_sugar),isHigh:!!e.isHighPostprandial}:d(e.fasting_blood_sugar)!==null?{hasValue:!0,typeLabel:"空腹",value:String(e.fasting_blood_sugar),isHigh:!!e.isHighFasting}:{hasValue:!1,typeLabel:"",value:"—",isHigh:!1}:{hasValue:!1,typeLabel:"",value:"—",isHigh:!1}});let Q=null;function ie(){return!!String(t.index.getStorageSync("token")||"").trim()}function bt(){t.index.removeStorageSync("token"),Q=null}function pn(){return new Promise((e,n)=>{t.index.login({provider:"weixin",success:a=>{a&&a.code?e(a.code):n(new Error("微信登录未返回 code"))},fail:n})})}async function vn(e){const n=await y.apiUrl({url:"/api/login/mnpLogin",method:"POST",data:{code:e}},!1);if(n&&n.code===1&&n.data&&n.data.token)return t.index.setStorageSync("token",n.data.token),t.index.setStorageSync("userData",n.data),n.data;throw bt(),new Error(Y(n==null?void 0:n.msg,"登录失败"))}async function yt(){const e=await pn();return await vn(e),ie()}async function hn(){if(!ie())return yt();try{const e=await y.apiUrl({url:"/api/user/info",method:"POST"},!1);if(e&&e.code===1&&e.data)return t.index.setStorageSync("userData",e.data),!0}catch{}bt();try{return await yt()}catch{return!1}}async function _t(){return Q||(Q=hn().then(e=>(e||(Q=null),!!e)).catch(()=>(Q=null,!1)),Q)}async function xt(){if(!ie())return[];gt.value=!0;try{const e=await y.apiUrl({url:"/api/tcm/getCardList",method:"GET",data:{}},!1);return e&&e.code===1&&Array.isArray(e.data)?(ne.value=e.data,e.data):(ne.value=[],[])}catch{return ne.value=[],[]}finally{gt.value=!1}}async function Xe(e){!e||!ie()||(f.value=Number(e.id)||0,z.value=Number(e.patient_id)||0,N.value=e.patient_name||"",H.value=Number(e.age)||0,K.value=Number(e.gender)||0)}function Ce(){try{const e=t.index.getStorageSync("userData")||{};R.value=String(e.mobile||e.phone||"").trim()}catch{R.value=""}return R.value}function St(){try{const e=t.index.getStorageSync("userData")||{},n=Number(e.sex);A.value=n===1||n===2?n:0}catch{A.value=0}}async function wt(){if(St(),Ce(),R.value){I.value=!1,await Qe(!1);return}I.value=!0}async function mn(){try{const e=await y.apiUrl({url:"/api/user/info",method:"POST"},!1);e&&e.code===1&&e.data&&(t.index.setStorageSync("userData",e.data),R.value=String(e.data.mobile||e.data.phone||"").trim())}catch{}return R.value}async function Je(e,n={}){if(f.value)return Le(),!0;const a={},o=e??A.value;(o===1||o===2)&&(a.sex=o);const r=await y.apiUrl({url:"/api/tcm/dailyEnsurePhoneContext",method:"POST",data:a},!1);return r&&r.code===1&&r.data&&r.data.diagnosis_id?(Le(),await Xe({id:r.data.diagnosis_id,patient_id:r.data.patient_id,patient_name:r.data.patient_name||"",age:r.data.age||0,gender:r.data.gender||0}),(r.data.created||r.data.linked_existing)&&await xt(),!0):r&&r.data&&r.data.need_mobile?(Le(),"need_mobile"):(Ot(r,"无法开始录入",n),!1)}async function Qe(e=!1){const n=await Je(A.value,{alert:!0});return n===!0?(e&&await Cn(!0),!0):(n==="need_mobile"&&(St(),I.value=!0),!1)}async function kt(){if(f.value)return!0;if(Ce(),!R.value)return wt(),!1;const e=await Je(void 0,{alert:!0});return e==="need_mobile"?(wt(),!1):!!e}function Dt(){ve.value||(I.value=!1,se(),t.nextTick$1(()=>E()))}async function bn(e){const n=(e==null?void 0:e.detail)||{};if(n.errMsg&&!String(n.errMsg).includes("ok")){h("需要授权手机号后才能录入血糖");return}const a=n.code;if(!a){h("获取手机号失败,请重试");return}if(A.value!==1&&A.value!==2){h("请先选择性别");return}ve.value=!0;try{if(Ce(),R.value){I.value=!1,await Qe(!0);return}const o=await y.apiUrl({url:"/api/user/getMobileByMnp",method:"POST",data:{code:a,sex:A.value}},!1);if(!o||o.code!==1){h(Y(o==null?void 0:o.msg,"绑定手机号失败"));return}await mn(),I.value=!1,await Qe(!0)}catch{h("网络异常,请稍后再试")}finally{ve.value=!1}}async function yn(e){!e||Number(e.id)===Number(f.value)||(ae.value=[],He.value=[],Me.value=[],$e.value=[],pt.value=null,await Xe(e),be())}async function be(){if(!ie()||!f.value)return;Te.value=!0;const{start:e,end:n}=tn.value;try{const[a,o]=await Promise.all([y.apiUrl({url:"/api/tcm/dailyTrackingWindow",method:"GET",data:{diagnosis_id:f.value,patient_id:z.value||0,start_date:e,end_date:n}},!1),y.apiUrl({url:"/api/tcm/dailyTrackingNotes",method:"GET",data:{diagnosis_id:f.value,patient_id:z.value||0}},!1)]);if(a&&a.code===1){const r=a.data||{};ae.value=Array.isArray(r.blood_records)?r.blood_records:[],He.value=Array.isArray(r.diet_records)?r.diet_records:[],Me.value=Array.isArray(r.exercise_records)?r.exercise_records:[],r.diagnosis&&(N.value||(N.value=r.diagnosis.patient_name||""),H.value||(H.value=Number(r.diagnosis.age)||0),K.value||(K.value=Number(r.diagnosis.gender)||0),z.value||(z.value=Number(r.diagnosis.patient_id)||0))}else ae.value=[],He.value=[],Me.value=[],a!=null&&a.msg&&h(a.msg);if(o&&o.code===1){const r=Array.isArray(o.data)?o.data:[];$e.value=r.filter(i=>ze.value.includes(String((i==null?void 0:i.note_date)||"")))}else $e.value=[];await Ut(!1)}catch{t.index.showToast({title:"加载失败,请稍后再试",icon:"none"})}finally{if(Te.value=!1,await t.nextTick$1(),E(),Rn.value&&!L.value){const a=++Pt;setTimeout(()=>{a===Pt&&!L.value&&Nt()},350)}}}function _n(){return f.value?`/tongji/pages/more?${[`diagnosis_id=${f.value}`,z.value?`patient_id=${z.value}`:""].filter(Boolean).join("&")}`:"/tongji/pages/more"}async function Tt(){!f.value&&(!await kt()||!f.value)||t.index.navigateTo({url:_n()})}function xn(e){t.index.navigateTo({url:e,fail(){t.index.showToast({title:"暂时无法打开游戏",icon:"none"})}})}function Sn(){xn("/tongji/endless-game/index")}function wn(e=new Date().getHours()){const n=Number(e)||0;return n<5?{text:"夜深了",icon:"moon"}:n<11?{text:"早上好",icon:"sun"}:n<13?{text:"中午好",icon:"sun"}:n<18?{text:"下午好",icon:"sun"}:n<22?{text:"晚上好",icon:"sunset"}:{text:"夜深了",icon:"moon"}}const kn=t.computed(()=>wn());function Ze(e){const n=m.value[e];return n?d(n.fasting_blood_sugar)!==null||d(n.postprandial_blood_sugar)!==null||d(n.other_blood_sugar)!==null:!1}function Dn(e){const n=m.value[e];if(!n)return 0;const o=["fasting_blood_sugar","postprandial_blood_sugar","other_blood_sugar"].filter(r=>d(n[r])!==null).length;return o===0?0:o===1?1:o===2?2:3}const Tn=t.computed(()=>Ze(Pe.value));t.computed(()=>{const e=new Date;let n=0,a=!1;for(let o=0;o<90;o++){const r=new Date(e);r.setDate(e.getDate()-o);const i=F(r);if(Ze(i))n++;else{if(o===0){a=!0;continue}break}}return{days:n,startedFromYesterday:a}});const At=t.computed(()=>{const e=[],n=new Date,a=["日","一","二","三","四","五","六"];for(let o=6;o>=0;o--){const r=new Date(n);r.setDate(n.getDate()-o);const i=F(r);e.push({date:i,label:a[r.getDay()],isToday:o===0,hasRecord:Ze(i)})}return e});t.computed(()=>At.value.filter(e=>e.hasRecord).length);function An(e){const n=m.value[e];return!!(n&&d(n.fasting_blood_sugar)!==null)}function Hn(e){const n=m.value[e];return!!(n&&d(n.postprandial_blood_sugar)!==null)}function Mn(e){return An(e)&&Hn(e)}t.computed(()=>At.value.filter(e=>Mn(e.date)).length);const et=t.computed(()=>{const e=M.value;if(!e||!e.length)return[];const n=[...e].sort(),a=new Date(n[0]),o=new Date(n[n.length-1]),r=(a.getDay()+6)%7,i=(o.getDay()+6)%7,l=new Date(a);l.setDate(a.getDate()-r);const g=new Date(o);g.setDate(o.getDate()+(6-i));const S=Math.round((g-l)/864e5)+1,b=[];let B=new Date(l);for(let _e=0;_e<Math.ceil(S/7);_e++){const Be=[];for(let ue=0;ue<7;ue++){const W=F(B),ce=n.includes(W);Be.push({date:W,day:B.getDate(),inRange:ce,isToday:W===Pe.value,level:ce?Dn(W):-1}),B.setDate(B.getDate()+1)}b.push(Be)}return b});t.computed(()=>{let e=0;for(const n of et.value)for(const a of n)a.inRange&&a.level>0&&e++;return e}),t.computed(()=>{let e=0;for(const n of et.value)for(const a of n)a.inRange&&e++;return e}),t.computed(()=>{const e=et.value;if(!e.length)return"";const n=new Map;for(const l of e)for(const g of l){if(!g.inRange)continue;const[S,b]=g.date.split("-"),B=`${S}-${b}`;n.set(B,(n.get(B)||0)+1)}if(!n.size){const l=e[0][0].date.split("-");return`${Number(l[0])}年${Number(l[1])}月`}let a="",o=-1;for(const[l,g]of n)g>o&&(a=l,o=g);const[r,i]=a.split("-");return`${Number(r)}年${Number(i)}月`});const $n=t.computed(()=>{const e=new Date,n=String(e.getMonth()+1).padStart(2,"0"),a=String(e.getDate()).padStart(2,"0"),o=["周日","周一","周二","周三","周四","周五","周六"];return`${e.getFullYear()}-${n}-${a} ${o[e.getDay()]}`}),Ht=()=>({visible:!1,loading:!1,submitting:!1,id:0,fasting_blood_sugar:"",postprandial_blood_sugar:"",other_blood_sugar:"",remark:""}),s=t.ref(Ht());function Pn(){se(),ye()}function Ne(e,n){var o;const a=((o=n==null?void 0:n.detail)==null?void 0:o.value)??"";s.value[e]=a}async function Cn(e=!1){if(!t.index.getStorageSync("token")){h("请先登录后再录入");return}if(!(!e&&!await kt())){if(!f.value){h("请先授权手机号");return}Pn(),s.value={...Ht(),visible:!0,loading:!0};try{const a=await y.apiUrl({url:"/api/tcm/dailyTodayBloodRecord",method:"GET",data:{diagnosis_id:f.value}},!1);if(a&&a.code===1&&a.data&&a.data.record){const o=a.data.record;s.value.id=Number(o.id)||0,s.value.fasting_blood_sugar=tt(o.fasting_blood_sugar),s.value.postprandial_blood_sugar=tt(o.postprandial_blood_sugar),s.value.other_blood_sugar=tt(o.other_blood_sugar),s.value.remark=String(o.remark||"")}}catch{}finally{s.value.loading=!1}}}function tt(e){return e==null||e===""||e===0||e==="0"||typeof e=="object"?"":String(e)}function Mt(){s.value.submitting||(s.value.visible=!1,se(),t.nextTick$1(()=>E()))}const L=t.computed(()=>s.value.visible||I.value);t.watch(L,e=>{e||(se(),t.nextTick$1(()=>E()))});async function Nn(){if(s.value.submitting||s.value.loading)return;const e=s.value;if(!([e.fasting_blood_sugar,e.postprandial_blood_sugar,e.other_blood_sugar].some(a=>a!==""&&a!==null&&Number(a)>0)||!!(e.remark&&e.remark.trim()))){t.index.showToast({title:"请至少填写一项数据",icon:"none"});return}s.value.submitting=!0;try{const a=await y.apiUrl({url:"/api/tcm/dailySaveBloodRecord",method:"POST",data:{diagnosis_id:f.value,fasting_blood_sugar:e.fasting_blood_sugar,postprandial_blood_sugar:e.postprandial_blood_sugar,other_blood_sugar:e.other_blood_sugar,remark:e.remark}},!1);a&&a.code===1?(h(a.msg||"已保存",{icon:"success"}),s.value.visible=!1,await be()):h(a&&a.msg||"保存失败")}catch{t.index.showToast({title:"网络异常,请稍后再试",icon:"none"})}finally{s.value.submitting=!1}}function Bn(){!s.value.id||s.value.submitting||t.index.showModal({title:"删除确认",content:"确定删除今天已录入的数据吗?删除后无法恢复。",confirmColor:"#dc2626",success:async e=>{if(e.confirm){s.value.submitting=!0;try{const n=await y.apiUrl({url:"/api/tcm/dailyDeleteBloodRecord",method:"POST",data:{diagnosis_id:f.value,id:s.value.id}},!1);n&&n.code===1?(t.index.showToast({title:"已删除",icon:"success"}),s.value.visible=!1,be()):h(n&&n.msg||"删除失败")}catch{t.index.showToast({title:"网络异常,请稍后再试",icon:"none"})}finally{s.value.submitting=!1}}}})}const $t=t.ref(!0),Rn=t.ref(!1),$=t.ref(!1);let x=null,Pt=0;function Ct(){if(x){try{x.stop()}catch{}try{x.destroy&&x.destroy()}catch{}x=null}}function ye(){Ct(),$.value=!1}function In(e){return e==null?"":typeof e=="string"?e.replace(/\s+/g," ").trim():Array.isArray(e)?e.map(n=>typeof n=="string"?n:n&&typeof n=="object"?n.title||n.label||n.desc||n.msg||n.message||"":Y(n,"")).filter(Boolean).join(","):typeof e=="object"?e.title||e.label||e.desc||e.msg||e.message||"":Y(e,"")}function Fn(e){if(!$t.value)return;const n=In(e);if(n){ye();try{const a=requirePlugin("WechatSI");$.value=!0,a.textToSpeech({lang:"zh_CN",tts:!0,content:n,success:o=>{if(!o||!o.filename){$.value=!1;return}Ct(),x=t.index.createInnerAudioContext(),x.src=o.filename,x.obeyMuteSwitch=!1,x.onPlay(()=>{$.value=!0}),x.onEnded(()=>{$.value=!1}),x.onError(()=>{$.value=!1}),x.onStop(()=>{$.value=!1}),x.play()},fail:o=>{$.value=!1,t.index.__f__("warn","at tongji/pages/weekly.vue:1999","WechatSI textToSpeech failed",o),t.index.showToast({title:"语音不可用,请检查网络/插件",icon:"none",duration:2e3})}});return}catch(a){t.index.__f__("warn","at tongji/pages/weekly.vue:2005","WechatSI plugin not available",a)}h(n,{duration:3200})}}function le(e){return e==null||e===""?"":String(e).replace(/(\d+)\.(\d+)/g,(n,a,o)=>`${a}点${o}`)}function Ln(){const e=Ye.value.fasting,n=Ye.value.postprandial,a=Ye.value.other,o=`${N.value||"您"}的最新血糖情况:`,r=[];if(e&&e.value!=="—"){let i=`空腹血糖 ${le(e.value)} 毫摩每升`;e.isHigh?i+=",偏高,请遵医嘱。":i+="。",e.trend&&e.trend.dir!=="flat"&&(i+=`比上次${e.trend.dir==="up"?"升高":"下降"} ${le(e.trend.delta.toFixed(1))}。`),r.push(i)}if(n&&n.value!=="—"){let i=`餐后血糖 ${le(n.value)} 毫摩每升`;n.isHigh?i+=",偏高,请注意饮食。":i+="。",n.trend&&n.trend.dir!=="flat"&&(i+=`比上次${n.trend.dir==="up"?"升高":"下降"} ${le(n.trend.delta.toFixed(1))}。`),r.push(i)}if(a&&a.value!=="—"){let i=`其他时段血糖 ${le(a.value)} 毫摩每升`;a.isHigh?i+=",偏高,请遵医嘱。":i+="。",a.trend&&a.trend.dir!=="flat"&&(i+=`比上次${a.trend.dir==="up"?"升高":"下降"} ${le(a.trend.delta.toFixed(1))}。`),r.push(i)}return r.length?o+r.join(" "):`${N.value||"您"}近期暂无血糖记录。`}function Nt(){const e=Ln();e&&Fn(e)}function se(){G=null,he=null,X=0,J=0}function En(){try{const e=t.index.getSystemInfoSync(),n=t.index.upx2px(40)*2,a=t.index.upx2px(40)*2;return{width:Math.max(280,e.windowWidth-n-a),height:t.index.upx2px(360)}}catch{return{width:320,height:180}}}function nt(e=0){return new Promise(n=>{if(G&&X>0&&J>0){n(!0);return}G&&(X<=0||J<=0)&&se(),t.index.createSelectorQuery().in(y).select("#bloodWaveChart").fields({node:!0,size:!0}).exec(o=>{const r=o&&o[0];if(!r||!r.node){e<10?setTimeout(()=>nt(e+1).then(n),e<4?100:180):n(!1);return}let i=r.width||0,l=r.height||0;if(i<=0||l<=0){const g=En();i=i>0?i:g.width,l=l>0?l:g.height}if((r.width<=0||r.height<=0)&&e<6){setTimeout(()=>nt(e+1).then(n),120);return}he=r.node,G=he.getContext("2d");try{re=t.index.getSystemInfoSync().pixelRatio||1}catch{re=1}X=i,J=l,he.width=X*re,he.height=J*re,G.setTransform(1,0,0,1,0,0),G.scale(re,re),n(!0)})})}let at=!1;function E(){at||(at=!0,setTimeout(async()=>{at=!1,await nt(),On()},60))}function Bt(e){return M.value.map(n=>{const a=dn.value[n];return a?d(a[e]):null})}function jn(...e){const n=e.flat().filter(i=>i!==null);if(!n.length)return{yMin:4,yMax:12};let a=Math.min(...n),o=Math.max(...n);const r=o-a;return r<2?(a=Math.max(0,a-1),o=o+1):(a=Math.max(0,a-r*.2),o=o+r*.2),a=Math.max(2,Math.floor(a)),o=Math.min(28,Math.ceil(o)),o-a<4&&(o=a+4),{yMin:a,yMax:o}}function On(){if(!G||!X||!J)return;const e=G,n=X,a=J;e.clearRect(0,0,n,a);const o={left:40,right:18,top:12,bottom:28},r=n-o.left-o.right,i=a-o.top-o.bottom,l=Bt("fasting_blood_sugar"),g=Bt("postprandial_blood_sugar"),S=M.value.length,b=Ue(H.value),B=[{key:"fasting",data:l,color:"#006c49",fillTop:"rgba(0,108,73,0.18)",fillBottom:"rgba(0,108,73,0)",label:"空腹",highThreshold:b?b.fasting:null},{key:"postprandial",data:g,color:"#a43a3a",fillTop:"rgba(164,58,58,0.18)",fillBottom:"rgba(164,58,58,0)",label:"餐后",highThreshold:b?b.postprandial:null}],_e=B.filter(u=>oe.value[u.key]),Be=_e.length?_e.map(u=>u.data):[l,g],{yMin:ue,yMax:W}=jn(...Be),ce=u=>o.top+i*(1-(u-ue)/(W-ue));if(e.fillStyle="#fbfcfd",e.fillRect(o.left,o.top,r,i),b){const u=ce(b.fasting),v=Math.max(o.top,Math.min(u,o.top+i));if(v>o.top){const P=e.createLinearGradient(0,o.top,0,v);P.addColorStop(0,"rgba(254, 226, 226, 0.55)"),P.addColorStop(1,"rgba(254, 226, 226, 0.15)"),e.fillStyle=P,e.fillRect(o.left,o.top,r,v-o.top)}}e.strokeStyle="#eef2f5",e.lineWidth=1;const xe=4;for(let u=0;u<=xe;u++){const v=o.top+i*u/xe;e.beginPath(),e.moveTo(o.left,v),e.lineTo(o.left+r,v),e.stroke()}e.font="bold 12px sans-serif",e.fillStyle="#64748b",e.textAlign="right",e.textBaseline="middle";for(let u=0;u<=xe;u++){const v=o.top+i*u/xe,P=W-(W-ue)*u/xe;e.fillText(P.toFixed(1),o.left-8,v)}if(e.font="bold 12px sans-serif",e.fillStyle="#475569",e.textAlign="center",e.textBaseline="top",S>0){const u=S>20?5:6,v=Math.max(1,Math.ceil(S/u));M.value.forEach((P,C)=>{if(C!==0&&C!==S-1&&C%v!==0)return;const Se=S===1?o.left+r/2:o.left+r*C/(S-1);e.fillText(P.slice(5),Se,o.top+i+8)})}if(b){const u=ce(b.fasting);if(u>=o.top&&u<=o.top+i){e.strokeStyle="#fda4af",e.lineWidth=1;try{e.setLineDash([6,5])}catch{}e.beginPath(),e.moveTo(o.left,u),e.lineTo(o.left+r,u),e.stroke();try{e.setLineDash([])}catch{}e.font="bold 11px sans-serif",e.fillStyle="#dc2626",e.textAlign="left",e.textBaseline="middle",e.fillText(`空腹阈 ${b.fasting}`,o.left+6,u-9)}}const Wn=u=>S===1?o.left+r/2:o.left+r*u/(S-1),qn={fasting:[],postprandial:[]},Vn=S<=10;B.forEach(u=>{const v=u.data.map((c,j)=>({x:Wn(j),y:c===null?null:ce(c),value:c}));if(qn[u.key]=v,!oe.value[u.key])return;const P=[];let C=[];v.forEach(c=>{c.y!==null?C.push(c):C.length&&(P.push(C),C=[])}),C.length&&P.push(C),P.forEach(c=>{if(c.length===1){e.fillStyle=u.color,e.beginPath(),e.arc(c[0].x,c[0].y,4,0,Math.PI*2),e.fill();return}const j=()=>{e.beginPath(),e.moveTo(c[0].x,c[0].y);for(let w=0;w<c.length-1;w++){const Re=c[w-1]||c[w],de=c[w],k=c[w+1],q=c[w+2]||c[w+1],V=de.x+(k.x-Re.x)/6,Ie=de.y+(k.y-Re.y)/6,Fe=k.x-(q.x-de.x)/6,Yn=k.y-(q.y-de.y)/6;e.bezierCurveTo(V,Ie,Fe,Yn,k.x,k.y)}};j(),e.lineTo(c[c.length-1].x,o.top+i),e.lineTo(c[0].x,o.top+i),e.closePath();const fe=e.createLinearGradient(0,o.top,0,o.top+i);fe.addColorStop(0,u.fillTop),fe.addColorStop(1,u.fillBottom),e.fillStyle=fe,e.fill(),j(),e.strokeStyle=u.color,e.lineWidth=2.4,e.lineCap="round",e.lineJoin="round",e.stroke(),Vn&&c.forEach(w=>{e.beginPath(),e.arc(w.x,w.y,3,0,Math.PI*2),e.fillStyle="#ffffff",e.fill(),e.strokeStyle=u.color,e.lineWidth=1.8,e.stroke()})});let Se=-1,Lt=-1/0;if(v.forEach((c,j)=>{c.value!=null&&c.value>Lt&&(Lt=c.value,Se=j)}),Se>=0){const c=v[Se],j=u.highThreshold!=null&&c.value>=u.highThreshold;e.beginPath(),e.arc(c.x,c.y,5,0,Math.PI*2),e.fillStyle=j?"#dc2626":u.color,e.fill(),e.strokeStyle="#ffffff",e.lineWidth=2.5,e.stroke();const fe=String(c.value);e.font="bold 12px sans-serif";const w=e.measureText(fe).width,Re=8,de=5,k=w+Re*2,q=14+de*2;let V=c.x,Ie=!0;c.y-12-q-4<o.top&&(Ie=!1);let Fe=Ie?c.y-12-q/2:c.y+12+q/2;V-k/2<o.left+2&&(V=o.left+k/2+2),V+k/2>o.left+r-2&&(V=o.left+r-k/2-2),e.fillStyle=j?"#dc2626":u.color,e.fillRect(V-k/2,Fe-q/2,k,q),e.fillStyle="#ffffff",e.textAlign="center",e.textBaseline="middle",e.fillText(fe,V,Fe)}})}function Rt(e){e!=="fasting"&&e!=="postprandial"||(oe.value[e]=!oe.value[e],pt.value=null,E())}t.watch(Ae,()=>{E()}),t.watch([me,ae],()=>{E()});function zn(){try{const e=t.index.getStorageSync("userData");if(!e)return;const n=String(e.real_name||e.nickname||"").trim();!N.value&&n&&(N.value=n);const a=Number(e.sex);!K.value&&(a===1||a===2)&&(K.value=a===1?1:0),!H.value&&e.age&&(H.value=Number(e.age)||0)}catch{}}function It(){const e=t.index.upx2px(80),n=t.index.upx2px(16);let a=t.index.upx2px(200),o=t.index.upx2px(24);try{const r=t.index.getSystemInfoSync();o=(Number(r.statusBarHeight)||0)+t.index.upx2px(16);const l=typeof t.index.getMenuButtonBoundingClientRect=="function"?t.index.getMenuButtonBoundingClientRect():null;l&&l.width>0?(a=r.windowWidth-l.left+t.index.upx2px(12),o=Math.max(o,l.top),we.value={position:"absolute",right:`${a}px`,top:`${l.top+(l.height-e)/2}px`}):we.value={}}catch{o=t.index.upx2px(48),we.value={}}ot.value={paddingTop:`${o}px`,paddingRight:`${a+e+n}px`},rt.value={}}async function Un(e){e=e||{},It(),Gn.value=!1,U.value=!0;const n=Number(e.diagnosis_id||e.id||0);if(Number(e.patient_id||0),e.patient_name&&decodeURIComponent(String(e.patient_name)),Number(e.age),Number(e.gender),!await _t()||!ie()){U.value=!1,h("登录失败,请稍后重试");return}zn();const o=await xt();if(Array.isArray(o)&&o.length>0){let r=null;n&&(r=o.find(i=>Number(i.id)===Number(n))),r||(r=o[0]),await Xe(r)}else f.value=0,z.value=0,N.value="",H.value=0,K.value=0,Ce(),R.value&&await Je(void 0,{alert:!1});U.value=!1,f.value?await be():(ae.value=[],await t.nextTick$1(),E())}t.onLoad(e=>{Un(e)}),t.onShow(()=>{It();try{t.index.onKeyboardHeightChange(je)}catch{}U.value||(se(),t.nextTick$1(()=>E()))}),t.onPullDownRefresh(async()=>{await _t()&&await be(),t.index.stopPullDownRefresh()}),t.onHide(()=>{ye(),ft();try{t.index.offKeyboardHeightChange(je)}catch{}ge.value=0}),t.onUnload(()=>{ye(),ft();try{t.index.offKeyboardHeightChange(je)}catch{}ge.value=0});const Gn=t.ref(!1);t.ref(!1),t.ref("");const Ft=t.ref({});return t.ref(!1),t.ref("家人"),t.ref(!1),t.computed(()=>Number(Ft.value.tree_level)||0),t.computed(()=>{const e=Ft.value.daily_records;return Array.isArray(e)?e:[]}),(e,n)=>t.e({a:U.value},U.value?{}:{},{b:!U.value},U.value?{}:t.e({c:t.p({name:"person",size:"md",color:"#006c49"}),d:t.t(kn.value.text),e:t.t(zt.value),f:t.t(Tn.value?"今日血糖已记录":"今日还没记血糖"),g:t.s(rt.value),h:t.p({name:$.value?"pause":"volume",size:"md",color:"#006c49"}),i:$t.value?"":1,j:$.value?1:"",k:t.s(we.value),l:t.o(a=>$.value?ye():Nt(),"7a"),m:t.s(ot.value),n:ne.value.length>1},ne.value.length>1?{o:t.f(ne.value,(a,o,r)=>({a:t.t(a.patient_name||"就诊卡"),b:a.id,c:Number(a.id)===Number(f.value)?1:"",d:t.o(i=>yn(a),a.id)}))}:{},{p:O.value&&!f.value},O.value&&!f.value?{q:t.t(O.value)}:{},{r:t.t(Zt.value),s:oe.value.fasting?"":1,t:t.o(a=>Rt("fasting"),"b7"),v:oe.value.postprandial?"":1,w:t.o(a=>Rt("postprandial"),"2d"),x:!L.value},L.value?{}:{y:t.o(Tt,"69")},{z:L.value},L.value?{}:{},{A:!ht.value&&!Te.value&&!L.value},!ht.value&&!Te.value&&!L.value?{}:{},{B:t.o(Tt,"d7"),C:me.value},me.value?{}:{},{D:t.p({name:"sparkles",size:"sm",color:"#006c49"}),E:t.p({name:"chevron-right",size:"sm",color:"#64748b"}),F:t.o(Sn,"69"),G:t.p({inline:!0,tone:"weekly"}),H:f.value},f.value?t.e({I:t.p({name:"sparkles",size:"sm",color:"#ffffff"}),J:t.unref(p)?1:"",K:t.p({name:"refresh",size:"sm",color:"#006c49"}),L:t.t(t.unref(p)?"生成中":"换一换"),M:t.unref(p)?1:"",N:t.o((...a)=>t.unref(ut)&&t.unref(ut)(...a),"f5"),O:t.unref(p)&&!t.unref(st)&&!t.unref(it)&&!t.unref(lt)},t.unref(p)&&!t.unref(st)&&!t.unref(it)&&!t.unref(lt)?{P:t.f(2,(a,o,r)=>({a:"sk-"+a}))}:t.e({Q:t.p({name:"sun",size:"sm",color:"#fb923c"}),R:t.t(t.unref(_).breakfast||(t.unref(p)?"…":"—")),S:t.unref(p)&&t.unref(D)==="breakfast"},t.unref(p)&&t.unref(D)==="breakfast"?{}:{},{T:t.unref(_).drinks||t.unref(p)&&t.unref(D)==="drinks"},t.unref(_).drinks||t.unref(p)&&t.unref(D)==="drinks"?t.e({U:t.p({name:"droplet",size:"sm",color:"#0ea5e9"}),V:t.t(t.unref(_).drinks||"…"),W:t.unref(p)&&t.unref(D)==="drinks"},t.unref(p)&&t.unref(D)==="drinks"?{}:{}):{},{X:t.p({name:"leaf",size:"sm",color:"#006c49"}),Y:t.t(t.unref(_).lunch||(t.unref(p)?"…":"—")),Z:t.unref(p)&&t.unref(D)==="lunch"},t.unref(p)&&t.unref(D)==="lunch"?{}:{},{aa:t.unref(_).dinner||t.unref(p)&&t.unref(D)==="dinner"},t.unref(_).dinner||t.unref(p)&&t.unref(D)==="dinner"?t.e({ab:t.p({name:"moon",size:"sm",color:"#7e85cc"}),ac:t.t(t.unref(_).dinner||"…"),ad:t.unref(p)&&t.unref(D)==="dinner"},t.unref(p)&&t.unref(D)==="dinner"?{}:{}):{})):{},{ae:f.value&&ee.value},f.value&&ee.value?{af:t.p({name:"sparkles",size:"sm",color:"#ffffff"}),ag:t.o(a=>ee.value=!1,"e1")}:{},{ah:f.value&&!ee.value},f.value&&!ee.value?t.e({ai:t.o(a=>ee.value=!0,"16"),aj:t.p({name:"sparkles",size:"sm",color:"#006c49"}),ak:t.unref(ke),al:-1,am:t.o((...a)=>t.unref(ct)&&t.unref(ct)(...a),"67"),an:t.o((...a)=>t.unref(De)&&t.unref(De)(...a),"3e"),ao:t.o(Gt,"58"),ap:t.o(Wt,"ac"),aq:t.p({name:"mic",size:"sm",color:t.unref(pe)||t.unref(te)?"#ffffff":"#006c49"}),ar:t.unref(pe)||t.unref(te)?1:"",as:t.unref(T)||!t.unref(Vt)?1:"",at:t.o(Xt,"69"),av:t.o(dt,"a9"),aw:t.o(dt,"78"),ax:t.p({name:"send",size:"sm",color:"#ffffff"}),ay:t.unref(T)?1:"",az:t.o((...a)=>t.unref(De)&&t.unref(De)(...a),"8f"),aA:qt.value?1:"",aB:t.unref(te)&&!t.unref(T)},t.unref(te)&&!t.unref(T)?{aC:t.t(t.unref(pe)?"松手结束":"准备录音…")}:{},{aD:t.unref(T)||t.unref(Z).advice},t.unref(T)||t.unref(Z).advice?t.e({aE:t.unref(Z).level_label},t.unref(Z).level_label?{aF:t.t(t.unref(Z).level_label)}:{},{aG:t.t(t.unref(Z).advice||(t.unref(T)?"正在想…":"")),aH:t.unref(T)},t.unref(T)?{}:{}):{}):{},{aI:t.unref(te)&&!t.unref(T)},t.unref(te)&&!t.unref(T)?{aJ:t.p({name:"mic",size:"lg",color:"#ffffff"}),aK:t.unref(pe)?1:"",aL:t.t(t.unref(pe)?"正在聆听…":"准备录音…")}:{},{aM:I.value},I.value?t.e({aN:t.o(Dt,"0f"),aO:O.value},O.value?{aP:t.t(O.value)}:{},{aQ:A.value===1?1:"",aR:t.o(a=>A.value=1,"ac"),aS:A.value===2?1:"",aT:t.o(a=>A.value=2,"32"),aU:ve.value,aV:ve.value||!A.value,aW:t.o(bn,"7f"),aX:t.o(()=>{},"8f"),aY:t.o(Dt,"54")}):{},{aZ:s.value.visible},s.value.visible?t.e({ba:t.t(s.value.id?"修改今日血糖":"录入今日血糖"),bb:t.t($n.value),bc:t.t(N.value||"本人"),bd:t.o(Mt,"0a"),be:s.value.loading},s.value.loading?{}:{bf:s.value.fasting_blood_sugar,bg:t.o(a=>Ne("fasting_blood_sugar",a),"49"),bh:s.value.postprandial_blood_sugar,bi:t.o(a=>Ne("postprandial_blood_sugar",a),"1a"),bj:s.value.other_blood_sugar,bk:t.o(a=>Ne("other_blood_sugar",a),"e2"),bl:s.value.remark,bm:t.o(a=>Ne("remark",a),"50")},{bn:s.value.id},s.value.id?{bo:s.value.submitting?1:"",bp:t.o(Bn,"47")}:{},{bq:t.t(s.value.submitting?"提交中…":s.value.id?"保存修改":"提交录入"),br:s.value.submitting||s.value.loading?1:"",bs:t.o(Nn,"b4"),bt:t.s(ge.value?{marginBottom:ge.value+"px"}:{}),bv:t.o(()=>{},"e5"),bw:t.o(Mt,"b3")}):{}),{bx:t.p({active:0})})}},na=t._export_sfc(Et,[["__scopeId","data-v-b5693e32"]]);Et.__runtimeHooks=2;wx.createPage(na);
|
||
//# sourceMappingURL=../../../.sourcemap/mp-weixin/tongji/pages/weekly.js.map
|