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