柒零 1 年間 前
コミット
31421cb54e

+ 222 - 1
componets/authorized-login-dialog/authorizedLoginDialog.js

@@ -1,18 +1,57 @@
 // componets/authorized-login-dialog/authorizedLoginDialog.js
+const defaultAvatarUrl = "../../static/images/no-avatar.png"
+const homeApi_empower = "https://aipush.aidsleep.cn";
+const token_empower = "b74fd5754c5ef24cf600c39194abdaeb";
 Component({
 
   /**
    * 组件的属性列表
    */
   properties: {
+    showDialog: {
+      type: Boolean,
+      value: false,
+      observer(newVal, oldVal, changePath) {
+        console.log(newVal, oldVal, changePath)
+        const that = this;
+        if (newVal) {
+          console.log("开始登录");
 
+          wx.login({
+            success: res => {
+              if (res.code) {
+                // 发送 code 到服务器换取 session_key, openid  
+                console.log('res.code==' + res.code);
+                that.setData({ wxCode: res.code })
+              }
+            }
+          });
+        } else {
+          console.log('that.data.wxCode==' + that.data.wxCode);
+        }
+      }
+    }
   },
 
+  attached() {
+  },
   /**
    * 组件的初始数据
    */
   data: {
-    showDialog:false
+    intervalId: null,
+    canIUseGetUserProfile: wx.canIUse('getUserProfile'),
+    canIUseNicknameComp: wx.canIUse('input.type.nickname'),
+    avatarUrl: defaultAvatarUrl,
+    encryptphone: "",
+    phoneNumber: "",
+    nickName: "",
+    disableCommitBtn: false,
+    hasUserInfo: false,
+    wxCode: "",
+    unionid: "",
+    openid: "",
+    session_key: "",
   },
 
   /**
@@ -22,5 +61,187 @@ Component({
     onCloseDialog() {
       this.setData({ showDialog: false });
     },
+    onChooseAvatar(e) {
+      const { avatarUrl } = e.detail
+      this.setData({
+        avatarUrl: avatarUrl,
+      })
+    },
+    onInputNameChange(e) {
+      console.log('e.detail==' + JSON.stringify(e.detail));
+      const nickName = e.detail.value
+      this.setData({
+        nickName: nickName,
+      })
+    },
+    onInputPhoneChange(e) {
+      console.log('e.detail==' + JSON.stringify(e.detail));
+      const phoneNumber = e.detail.value
+      this.setData({
+        phoneNumber: phoneNumber,
+      })
+    },
+    onGetPhoneNumber: function (e) {
+      console.log('onGetPhoneNumber=' + JSON.stringify(e));
+      var that = this;
+      if (e.detail.errMsg === "getPhoneNumber:ok") {
+        // 发送 encryptedData, iv, 和 sessionKey 到你的后台服务器  
+        wx.request({
+          url: `${homeApi_empower}/wxtel`,
+          method: 'POST',
+          data: {
+            encryptedData: e.detail.encryptedData,
+            iv: e.detail.iv,
+            code: that.data.wxCode,
+            token: token_empower,
+          },
+          success: function (res) {
+            // 处理服务器返回的结果  
+            console.log('手机号获取结果:', res.data);
+            console.log('手机号获取结果:', res.data.encryptphone);
+            console.log('手机号获取结果:', res.data.shieldphone);
+            if (!res.data || !res.data.encryptphone || !res.data.shieldphone) {
+              wx.showToast({
+                title: '无法获取用户手机号',
+                icon: 'none'
+              });
+              return;
+            }
+            console.log('e==' + JSON.stringify(e));
+            console.log('e.detail==' + JSON.stringify(e.detail));
+            that.setData({
+              encryptphone: res.data.encryptphone,
+              phoneNumber: res.data.shieldphone,
+            })
+            wx.setStorageSync('phoneNumber', res.data.shieldphone);
+          }
+        })
+      }
+    },
+
+    handleUserInfo: function (e) {
+      if (!this.data.hasUserInfo) {
+        wx.showToast({
+          title: '请设置头像、昵称和手机号',
+          icon: 'none'
+        });
+        return;
+      }
+      var that = this;
+      if (e.detail.userInfo) {
+        // 用户点击允许,获取到用户信息  
+        this.setData({
+          disableCommitBtn: true,
+        });
+        wx.showLoading()
+
+        wx.request({
+          url: `${homeApi_empower}/wxlogin`,
+          data: {
+            code: that.data.wxCode,
+            token: token_empower,
+            nickname: that.data.userInfo.nickName,
+            encryptphone: that.data.encryptphone
+          },
+          method: 'POST',
+          success: function (loginRes) {
+            console.log('loginRes=' + JSON.stringify(loginRes));
+            console.log('loginRes.data=' + JSON.stringify(loginRes.data));
+            if (loginRes.data.codes && loginRes.data.codes == 'success') {
+              console.log('123123123');
+              console.log('loginRes.data.back.unionid=' + loginRes.data.back.unionid);
+              console.log('loginRes.data.back.openid=' + loginRes.data.back.openid);
+              wx.setStorageSync('unionid', loginRes.data.back.unionid);
+              wx.setStorageSync('openid', loginRes.data.back.openid);
+              // 获取后台授权
+              that.startInterval();
+              // 可以在这里提示用户进行手机号授权  
+              that.setData({
+                unionid: loginRes.data.back.unionid,
+                openid: loginRes.data.back.openid,
+                session_key: loginRes.data.back.session_key,
+              });
+            }
+          },
+          fail: function () {
+            wx.hideLoading()
+            wx.showToast({
+              title: '后台授权失败',
+              icon: 'none'
+            });
+          }
+        });
+
+      } else {
+        // 用户拒绝授权  
+        wx.showToast({
+          title: '您拒绝了授权',
+          icon: 'none'
+        });
+
+        // 可以选择在这里处理用户拒绝授权后的逻辑,如跳转到其他页面或显示提示信息  
+      }
+    },
+
+    startInterval: function () {
+      var that = this;
+      this.data.intervalId = setInterval(() => {
+        console.log('后台授权中...');
+        console.log('startInterval-unionid=' + that.data.unionid);
+        console.log('startInterval-openid=' + that.data.openid);
+        wx.request({
+          url: `${homeApi_empower}/wxstatus`,
+          data: {
+            //nickName: that.data.userInfo.nickName,
+            unionid: wx.getStorageSync('unionid'),
+            openid: wx.getStorageSync('openid'),
+            //phoneNumber: that.data.phoneNumber,
+            token: token_empower,
+          },
+          method: 'POST',
+          success: function (intervalRes) {
+            wx.hideLoading()
+            console.log('intervalRes=' + JSON.stringify(intervalRes));
+            console.log('intervalRes.data=' + JSON.stringify(intervalRes.data));
+            //empower.js? [sm]:152 intervalRes.data={"st":"success","status":"0"}
+            if (intervalRes.data && intervalRes.data.st && intervalRes.data.status && intervalRes.data.st == 'success' && intervalRes.data.status == '1') {
+              wx.setStorageSync('hasAuth', 'hasAuth');
+              wx.setStorageSync('hotelEmpower', intervalRes.data.hotel);
+              wx.setStorageSync('roomEmpower', intervalRes.data.room);
+              that.setData({
+                disableCommitBtn: false,
+              });
+              wx.showToast({
+                title: '后台授权成功',
+                icon: 'none'
+              });
+
+              that.clearInterval();
+              that.triggerEvent('authorizationSuccessful', true);
+            } else {
+              wx.showToast({
+                title: '授权失败,请先办理入住',
+                icon: 'none'
+              });
+            }
+          },
+          fail: function (error) {
+            wx.hideLoading()
+            that.clearInterval();
+            wx.showToast({
+              title: '后台授权失败',
+              icon: 'none'
+            });
+          }
+        });
+      }, 3000);
+    },
+    clearInterval: function () {
+      var that = this;
+      if (this.data.intervalId) {
+        clearInterval(that.data.intervalId);
+        that.data.intervalId = null;
+      }
+    },
   }
 })

+ 26 - 2
componets/authorized-login-dialog/authorizedLoginDialog.wxml

@@ -1,4 +1,28 @@
 <!--componets/authorized-login-dialog/authorizedLoginDialog.wxml-->
-<van-popup show="{{ showDialog }}" close-on-click-overlay="{{false}}" z-index="10086" overlay bind:close="onCloseDialog"
-    custom-style="background-color: transparent;">
+<van-popup show="{{ showDialog }}" close-on-click-overlay="{{false}}" position="bottom" z-index="10087" overlay
+    bind:close="onCloseDialog" custom-style="background-color: transparent;">
+    <view class="dialog-bg">
+        <view class="close-btn" bindtap="onCloseDialog">
+            <van-icon name="cross" />
+        </view>
+        <view class="title-box">
+            <image class="logo" src="../../static/images/logo.png" mode="widthFix"></image>
+            <text class="title">舒眠大健康</text>
+        </view>
+        <text class="desc">请您授权头像、昵称、手机号信息,您授权的信息将受到严格保护,请放心使用。</text>
+        <button class="avatar-wrapper" open-type="chooseAvatar" bind:chooseavatar="onChooseAvatar">
+            <image class="avatar" src="{{avatarUrl}}" mode="widthFix"></image>
+        </button>
+        <input type="nickname" class="nickname-input" placeholder="请输入昵称" bind:change="onInputNameChange"
+            placeholder-style="color: #888888;" value="{{nickName}}" />
+
+        <button wx:if="{{!phoneNumber.length}}" open-type="getPhoneNumber" class="custom-input-button"
+            bindgetphonenumber="onGetPhoneNumber">请输入手机号码</button>
+        <input wx:else type="number" class="nickname-input" placeholder="请输入手机号码" bindinput="onInputPhoneChange"
+            placeholder-style="color: #888888;" value="{{phoneNumber}}" maxlength="11" disabled="{{true}}" />
+        <button open-type="getUserInfo" bindgetuserinfo="handleUserInfo" class="auth-button"
+            disabled="{{disableCommitBtn}}">
+            确认授权
+        </button>
+    </view>
 </van-popup>

+ 110 - 1
componets/authorized-login-dialog/authorizedLoginDialog.wxss

@@ -1 +1,110 @@
-/* componets/authorized-login-dialog/authorizedLoginDialog.wxss */
+/* componets/authorized-login-dialog/authorizedLoginDialog.wxss */
+
+.dialog-bg {
+    width: 100vw;
+    min-height: 730rpx;
+    height: 730rpx;
+    background: #F7F7F7;
+    border-radius: 32rpx 32rpx 0 0;
+    display: flex;
+    flex-direction: column;
+    align-items: center;
+    position: relative;
+}
+
+.close-btn {
+    position: absolute;
+    right: 0;
+    top: 0;
+    width: 128rpx;
+    height: 128rpx;
+    display: flex;
+    flex-direction: column;
+    align-items: center;
+    justify-content: center;
+}
+
+.title-box {
+    width: 100%;
+    margin-top: 40rpx;
+    display: flex;
+    flex-direction: row;
+    align-items: center;
+}
+
+.logo {
+    width: 48rpx;
+    margin-left: 40rpx;
+    height: 48rpx;
+}
+
+.title {
+    margin-left: 16rpx;
+    color: #333333;
+    font-size: 32rpx;
+}
+
+.desc {
+    margin: 20rpx 40rpx 0;
+    color: #666666;
+    font-size: 24rpx;
+}
+
+.avatar-wrapper {
+    width: 128rpx;
+    padding: 0;
+    border: 0;
+    height: 128rpx;
+    margin: 20rpx auto 0;
+}
+
+.avatar {
+    width: 128rpx;
+    height: 128rpx;
+    display: block;
+}
+
+button::after {
+    border: 0;
+}
+
+.nickname-input {
+    width: calc(100% - 120rpx);
+    height: 80rpx;
+    padding: 0 30rpx;
+    margin-top: 40rpx;
+    background: #EEEEEE;
+    color: #333333;
+    border-radius: 80rpx;
+    font-size: 28rpx;
+}
+
+.custom-input-button {
+    width: calc(100% - 80rpx);
+    height: 80rpx;
+    margin-top: 40rpx;
+    line-height: 80rpx;
+    text-align: left;
+    background: #EEEEEE;
+    color: #888888;
+    border-radius: 80rpx;
+    font-size: 28rpx !important;
+}
+
+.auth-button {
+    width: calc(100% - 80rpx);
+    line-height: 80rpx;
+    margin-top: 40rpx;
+    font-size: 32rpx;
+    border-radius: 80rpx;
+    height: 80rpx;
+    background: linear-gradient(315deg, #0ABCA4 0%, rgba(11, 195, 170, 0.8) 100%);
+    color: #FFFFFF;
+}
+
+
+button[disabled] {
+    color: #FFFFFF;
+    background: linear-gradient(315deg, #0ABCA4 0%, rgba(11, 195, 170, 0.8) 100%);
+    opacity: 0.6;
+}

+ 6 - 0
pages/mine/mine.js

@@ -5,8 +5,14 @@ Page({
    * 页面的初始数据
    */
   data: {
+    showAuthorizedDialog:false
 
   },
+  showDialog(){
+    this.setData({
+      showAuthorizedDialog:true
+    })
+  },
 
   /**
    * 生命周期函数--监听页面加载

+ 5 - 1
pages/mine/mine.wxml

@@ -1 +1,5 @@
-<!--pages/mine/mine.wxml-->
+<!--pages/mine/mine.wxml-->
+<view class="container">
+    <button style="margin-top: 200rpx;" bindtap="showDialog">点击弹窗</button>
+    <authorized-login-dialog showDialog="{{showAuthorizedDialog}}"></authorized-login-dialog>
+</view>

+ 8 - 0
pages/mine/mine.wxss

@@ -1,4 +1,12 @@
 /* pages/mine/mine.wxss */
 page {
     background-color: #F8F9FA;
+}
+
+.container {
+    min-height: 100vh !important;
+    background: #F8F9FA;
+    display: flex;
+    flex-direction: column;
+    box-sizing: border-box;
 }

+ 66 - 0
pages/setTime/setTime.wxss

@@ -0,0 +1,66 @@
+/* pages/setTime/setTime.wxss */
+
+.switch-view {
+  display: flex;
+  flex-direction: row;
+  align-items: center;
+  justify-content: space-between;
+  width: 600rpx;
+  margin: 30rpx;
+  color: #62c4d9;
+}
+switch{
+  zoom: .7;
+}
+.picker-view {
+  width: 500rpx;
+  height: 300rpx;
+}
+
+.indicator-class {
+  height: 100rpx;
+  display: flex;
+  flex-direction: row;
+}
+
+.mask-class {
+  opacity: 0;
+}
+
+.picker-item {
+  line-height: 100rpx;
+  color: #62c4d9;
+  width: 100%;
+  text-align: center;
+}
+
+.list {
+  width: 670rpx;
+  margin: 30rpx 40rpx 30rpx 40rpx;
+  display: flex;
+  flex-direction: row;
+  align-items: center;
+  justify-content: space-between;
+  font-size: 32rpx;
+  color: #62c4d9;
+}
+
+.content {
+  font-size: 28rpx;
+  color: #62c4d9;
+  width: 420rpx;
+  display: flex;
+  justify-content: flex-end;
+}
+
+.list image {
+  width: 30rpx;
+  height: 30rpx;
+}
+
+.foot-text {
+  line-height: 50rpx;
+  font-size: 30rpx;
+  margin: 34rpx;
+  color: #62c4d9;
+}

+ 7 - 0
project.private.config.json

@@ -10,6 +10,13 @@
   "condition": {
     "miniprogram": {
       "list": [
+        {
+          "name": "pages/mine/mine",
+          "pathName": "pages/mine/mine",
+          "query": "",
+          "launchMode": "default",
+          "scene": null
+        },
         {
           "name": "subpages/testSAS/testSAS",
           "pathName": "subpages/testSAS/testSAS",

+ 0 - 0
subpages/images/logo.png → static/images/logo.png


+ 0 - 0
subpages/images/no-avatar.png → static/images/no-avatar.png