Просмотр исходного кода

story-204 临时方案 扫小程序进入健康分析 / 舌面象分析报告 优先判断患者是否需要授权手机号

cc12458 6 месяцев назад
Родитель
Сommit
fdfadbf739

+ 1 - 0
miniprogram/app.json

@@ -100,6 +100,7 @@
   "usingComponents": {
     "t-navbar": "tdesign-miniprogram/navbar/navbar",
     "t-message": "tdesign-miniprogram/message/message",
+    "popup-user-auth": "./components/popup-user-auth/popup-user-auth",
     "popup-privacy": "./components/popup-privacy/popup-privacy"
   },
   "requiredPrivateInfos": ["getFuzzyLocation", "chooseAddress"],

+ 3 - 1
miniprogram/components/button/button.json

@@ -1,4 +1,6 @@
 {
   "component": true,
-  "usingComponents": {}
+  "usingComponents": {
+    "t-loading": "tdesign-miniprogram/loading/loading"
+  }
 }

+ 2 - 0
miniprogram/components/button/button.scss

@@ -31,6 +31,8 @@
       color: white;
       border-radius: 5px;
       left: 10px;
+
+      --td-loading-color: #fff;
     }
   }
 

+ 1 - 1
miniprogram/components/button/button.ts

@@ -4,7 +4,7 @@ Component({
   observers: {
     loading(this: any, val: boolean) {
       // 当外部声明 loading 时,同步禁用状态
-      this.setData({ isDisabled: !!val });
+      if (this.data.disableOnClick) this.setData({ isDisabled: !!val });
     },
   },
   lifetimes: {

+ 2 - 1
miniprogram/components/button/button.wxml

@@ -11,6 +11,7 @@
     disabled="{{isDisabled}}"
     hover-class="{{isDisabled ? '' : 'hover'}}"
   >
-    {{list[index].name}}
+    <t-loading wx:if="{{loading}}" theme="spinner" size="36rpx" slot="note" />
+    <block wx:else>{{list[index].name}}</block>
   </button>
 </view>

+ 10 - 0
miniprogram/components/popup-user-auth/popup-user-auth.json

@@ -0,0 +1,10 @@
+{
+  "component": true,
+  "usingComponents": {
+    "t-cell": "tdesign-miniprogram/cell/cell",
+    "t-loading": "tdesign-miniprogram/loading/loading",
+    "t-radio": "tdesign-miniprogram/radio/radio",
+    "t-popup": "tdesign-miniprogram/popup/popup",
+    "form-button": "../button/button"
+  }
+}

+ 63 - 0
miniprogram/components/popup-user-auth/popup-user-auth.scss

@@ -0,0 +1,63 @@
+/* components/popup-user-auth/popup-user-auth.wxss */
+@import "../../themes/t.scss";
+@import "../../themes/button.scss";
+
+.popup {
+  &__header {
+    padding: 12px;
+    font-size: 18px;
+    text-align: center;
+  }
+
+  &__content {
+    padding: 0 12px;
+  }
+}
+
+.user-auth-form {
+  .open-button {
+    position: relative;
+    font-size: 14px;
+
+    &__inner {
+      position: absolute;
+      top: 0;
+      bottom: 0;
+      left: var(--td-cell-horizontal-padding, 32rpx);
+      right: var(--td-cell-horizontal-padding, 32rpx);
+      opacity: 0;
+    }
+  }
+
+  .privacy-contract-wrapper {
+    --td-radio-icon-checked-color: #1D6FF6;
+    --td-radio-font-size: 12px;
+    --td-radio-icon-size: 20px;
+
+    .privacy-contract {
+      display: flex;
+      flex-direction: row;
+      align-items: center;
+    }
+
+    padding: 6px var(--td-cell-horizontal-padding, 32rpx);
+    font-size: 12px;
+
+    .name {
+      // color: var(--primary-color, #38FF6E);
+      color: #1D6FF6;
+    }
+
+    .no-border {
+      display: none;
+    }
+  }
+}
+
+.phone-cell {
+  color: black !important; // 使用 !important 确保优先级
+
+  .note-class {
+    color: black !important; // 确保 note 字体为黑色
+  }
+}

+ 79 - 0
miniprogram/components/popup-user-auth/popup-user-auth.ts

@@ -0,0 +1,79 @@
+// components/popup-user-auth/popup-user-auth.ts
+import { openPrivacyContract } from "../../lib/wx/open-api";
+import { usePhoneNumber } from "../../lib/use/use-phone";
+import { createPhoneRegister } from "../../lib/request/common";
+let submitting = false;
+Component({
+  properties: {
+    show: { type: Boolean, value: false },
+    overlay: { type: Boolean, value: true },
+    scene: { type: String, value: '' },
+  },
+  data: {
+    visible: false,
+    title: '完善信息',
+    privacyContract: { agree: false, name: "《隐私政策》", show: false },
+
+    loading: false,
+    submitting: false,
+    model: { } as { phone?: string },
+  },
+  observers: {
+    'show'(visible) {
+      this.setData({ visible })
+    }
+  },
+  methods: {
+    getPhoneNumberHandle(event: WechatMiniprogram.ButtonGetPhoneNumber) {
+      this.setData({ loading: true });
+      const { getPhoneNumber } = usePhoneNumber();
+      getPhoneNumber(event, (value) => {
+        this.setData({ "model.phone": value, loading: false })
+      })
+    },
+    openPrivacyContract: openPrivacyContract,
+    onPrivacySetting({ detail }: { detail: WechatMiniprogram.GetPrivacySettingSuccessCallbackResult; }) {
+      this.setData({
+        "privacyContract.name": detail.privacyContractName,
+        // 'privacyContract.agree': !detail.needAuthorization,
+      });
+    },
+    onAgreeChange(event: any) {
+      const agree = event?.detail?.checked;
+      if (agree) this.setData({ "privacyContract.show": true });
+      else this.setData({ "privacyContract.agree": agree });
+    },
+    onAgree() {
+      this.setData({ "privacyContract.agree": true });
+    },
+
+    async onSubmit(event: WechatMiniprogram.FormSubmit) {
+      if (this.data.submitting || submitting) return;
+      submitting = true;
+      try {
+        const data = { ...this.data.model, ...event.detail.value, scene: this.data.scene };
+
+        if (!data.agemust) data.agemust = this.data.privacyContract.agree ? "Y" : "N";
+        if (data.agemust === "N") {
+          this.setData({ "privacyContract.show": true });
+          throw `请阅读并同意${this.data.privacyContract.name}`;
+        }
+        if (!data.phone) throw `请获取手机号码`;
+
+        this.setData({ "submitting": submitting });
+        const { patientId } = await createPhoneRegister(<any>data);
+        wx.setStorageSync("patientId", patientId);
+        this.setData({ 'visible': false });
+        this.triggerEvent('register', { patientId });
+      } catch (error) {
+        if (typeof error === 'string') this.triggerEvent('message', { type: 'warning', content: error });
+        else if (error.errMsg) {
+          this.triggerEvent('message', { type: 'error', content: error.errMsg });
+          this.setData({ "model.phone": '', loading: false })
+        }
+      }
+      submitting = false;
+      this.setData({ "submitting": submitting });
+    },
+  }
+})

+ 23 - 0
miniprogram/components/popup-user-auth/popup-user-auth.wxml

@@ -0,0 +1,23 @@
+<!--components/popup-user-auth/popup-user-auth.wxml-->
+<t-popup placement="bottom" show-overlay="{{overlay}}" visible="{{visible}}">
+  <view class="popup">
+    <view class="popup__header">{{title}}</view>
+    <view class="popup__content">
+      <form class="user-auth-form" bindsubmit="onSubmit">
+        <view class="open-button">
+          <t-cell t-class="cell-border-gradient phone-cell" t-class-note="note-class" required title="手机号" hover="{{!model['phone']}}" note="{{loading ? '' : model['phone'] || '点击获取手机号码'}}">
+            <t-loading wx:if="{{loading}}" theme="spinner" size="24rpx" slot="note" />
+          </t-cell>
+          <button wx:if="{{!loading && !model['phone']}}" class="open-button__inner" size="mini" open-type="getPhoneNumber" bind:getphonenumber="getPhoneNumberHandle">选择授权手机</button>
+        </view>
+        <view class="privacy-contract-wrapper">
+          <t-radio t-class="privacy-contract" t-class-border="no-border" icon="circle" block="{{false}}" checked="{{privacyContract.agree}}" bind:change="onAgreeChange">
+            <text slot="content" style="font-size: 14px;">我已阅读与同意 <text class="name" catch:tap="openPrivacyContract">{{privacyContract.name}}</text></text>
+          </t-radio>
+        </view>
+        <form-button block index="1" loading="{{submitting}}" disableOnClick="{{false}}">提交</form-button>
+      </form>
+    </view>
+  </view>
+</t-popup>
+<popup-privacy show="{{privacyContract.show}}" bind:setting="onPrivacySetting" bind:agree="onAgree" />

+ 19 - 0
miniprogram/lib/request/common.ts

@@ -0,0 +1,19 @@
+import { Get, Post } from "./method";
+
+// 手机号注册 
+export function createPhoneRegister(params: { phone: string; }) {
+  return Get(`/mobileAccountManage/phoneRegister`, { params }).then(res => ({ patientId: res.data }));
+}
+// 获取默认患者和患者列表,以及是否需要授权
+export function getPatients(id?: string) {
+  id ??= wx.getStorageSync("patientId");
+  const transform = ({ data }: AnyObject) => {
+    const patient = 
+      data.find((item: AnyObject) => item.patientId == id) ??
+      data.find((item: AnyObject) => item.isDefault?.toUpperCase() === "Y") ??
+      data[0];
+
+    return { patient, patients: data, auth: patient?.isPerfectInfo !== false };
+  };
+  return Post("/mobileAccountManage/getPatsByAid", {}, { transform });
+}

+ 3 - 1
miniprogram/lib/use/use-phone.ts

@@ -26,7 +26,7 @@ export function usePhoneNumber() {
       _updateStatus.push(callback);
       callback(status)
     },
-    getPhoneNumber(event: WechatMiniprogram.ButtonGetPhoneNumber) {
+    getPhoneNumber(event: WechatMiniprogram.ButtonGetPhoneNumber, callback?: (value?: string) => void) {
       const code = event.detail.code;
       if (!code) return;
       _updateStatus.forEach(cb => cb('loading'))
@@ -38,10 +38,12 @@ export function usePhoneNumber() {
       }).then(phone => {
         value = phone;
         status = 'success';
+        if (typeof callback === 'function') callback(value)
 
         _updataValue.forEach(cb => cb(value))
         _updateStatus.forEach(cb => cb(status))
       }, (error) => {
+        if (typeof callback === 'function') callback()
         _updateStatus.forEach(cb => cb('pending'))
         wx.showModal({ title: '获取失败', content: error.errMsg || error.message, showCancel: false })
       })

+ 11 - 3
miniprogram/module/health/pages/analysis/analysis.ts

@@ -1,5 +1,6 @@
 import PageContainerBehavior from "../../../../core/behavior/page-container.behavior";
 import TickleBehavior, { getTickleContext } from "../../../../core/behavior/tickle.behavior";
+import { getPatients } from "../../../../lib/request/common";
 
 // module/health/pages/analysis/analysis.ts
 import { toHomePage } from "../../router";
@@ -17,6 +18,7 @@ Page({
     tongue: null as unknown as AnalysisModel,
     face: null as unknown as AnalysisModel,
     dataset: null as unknown as AnyObject,
+    showUserAuth: false,
     switchType: "",
   },
   onLoad(query: any) {
@@ -26,14 +28,16 @@ Page({
         switchType: query.scene,
       });
     }
-    console.log(this.data.switchType,"query1111",query)
   },
 
   async _load(query: Record<'id' | 'scene', string>) {
-    console.log(query,"111");
-    
     wx.showLoading({ title: '加载中' });
     try {
+      if (query.scene) {
+        // 查找患者是否需要授权
+        const { auth } = await getPatients().catch(() => ({ auth: true }));
+        if (auth) this.setData({ showUserAuth: true });
+      }
       const { tongue, face, ...dataset } = await healthAnalysisMethod(query);
       this.setData({ tongue, face, dataset });
     } catch (error) {
@@ -43,4 +47,8 @@ Page({
   },
 
   toHomePage() { toHomePage(this.data.switchType as string); },
+  openMessage(event: any) {
+    const message = event?.detail?.content
+    if (message) getTickleContext.call(this).showMessage(event.detail.type || 'info', message);
+  }
 });

+ 2 - 1
miniprogram/module/health/pages/analysis/analysis.wxml

@@ -12,4 +12,5 @@
   <card-analysis-content tongue="{{tongue}}" face="{{face}}" exception></card-analysis-content>
 </scroll-view>
 </view>
-<t-message id="{{$messageId}}"></t-message>
+<t-message id="{{$messageId}}"></t-message>
+<popup-user-auth show="{{showUserAuth}}" scene="{{switchType}}"></popup-user-auth>

+ 13 - 3
miniprogram/module/health/pages/report/report.ts

@@ -1,7 +1,6 @@
 import PageContainerBehavior from "../../../../core/behavior/page-container.behavior";
-import TickleBehavior, {
-  getTickleContext,
-} from "../../../../core/behavior/tickle.behavior";
+import TickleBehavior, { getTickleContext } from "../../../../core/behavior/tickle.behavior";
+import { getPatients } from "../../../../lib/request/common";
 
 // module/health/pages/report/report.ts
 import { toSchemePage, toHomePage } from "../../router";
@@ -17,6 +16,7 @@ Page({
     schemeId: "",
     healthIndex: { data: [], loading: false, message: "" },
     tongueAnalysis: [] as AnyArray,
+    showUserAuth: false,
     switchType: "",
   },
   onLoad(query: any) {
@@ -34,6 +34,12 @@ Page({
     let id = "";
     wx.showLoading({ title: "加载中" });
     try {
+      if (query.scene) {
+        // 查找患者是否需要授权
+        const { auth } = await getPatients().catch(() => ({ auth: true }));
+        if (auth) this.setData({ showUserAuth: true });
+      }
+
       const { __origin__, ...dataset } = await healthReportMethod(query);
       id = dataset.id;
       const showScheme = __origin__?.isHaveConditioningProgram === "Y";
@@ -78,4 +84,8 @@ Page({
   toSchemePage() {
     toSchemePage(this.data.schemeId);
   },
+  openMessage(event: any) {
+    const message = event?.detail?.content
+    if (message) getTickleContext.call(this).showMessage(event.detail.type || 'info', message);
+  }
 });

+ 2 - 1
miniprogram/module/health/pages/report/report.wxml

@@ -92,4 +92,5 @@
     </report-health-index>
   </scroll-view>
 </view>
-<t-message id="{{$messageId}}"></t-message>
+<t-message id="{{$messageId}}"></t-message>
+<popup-user-auth show="{{showUserAuth}}" scene="{{switchType}}"></popup-user-auth>

+ 2 - 2
miniprogram/pages/home/home.ts

@@ -400,9 +400,9 @@ Page({
       const { patient } = await getPatients(/*this.data.patientId*/);
       // if (!patient) await toCertificationPage();
       if (!patient) {
-        if (wx.getStorageSync("doctorId")) {
+        /*if (wx.getStorageSync("doctorId")) {
           toCertificationPage();
-        }
+        }*/
         this.setData({
           "healthReport.loading": false,
           isShowComplete: true,