Selaa lähdekoodia

feta:Develop permissions and create user information

wangyuan 2 vuotta sitten
vanhempi
commit
583f985a3c

+ 4 - 1
app.js

@@ -1,4 +1,7 @@
-// app.js
+// @desc: app.js
+// @auth: wangyuan.cc@foxmail.com
+// @date: 2022-09-13 10:44
+
 App({
   onLaunch() {
     console.log('App onLaunch');

+ 3 - 4
app.json

@@ -1,14 +1,13 @@
 {
   "entryPagePath": "pages/permisission/permission",
   "pages": [
-    "pages/permisission/permission",
-    "pages/index/index"
+    "pages/permisission/permission"
   ],
   "window": {
     "backgroundTextStyle": "light",
-    "navigationBarBackgroundColor": "#fff",
+    "navigationBarBackgroundColor": "#45A6B5",
     "navigationBarTitleText": "ITT健康检测",
-    "navigationBarTextStyle": "black"
+    "navigationBarTextStyle": "white"
   },
   "style": "v2",
   "sitemapLocation": "sitemap.json"

+ 5 - 1
app.wxss

@@ -1,4 +1,8 @@
 /**app.wxss**/
+page {
+  height: 100%;
+  --maincolor: #45A6B5;
+}
 .container {
   height: 100%;
   display: flex;
@@ -7,4 +11,4 @@
   justify-content: space-between;
   padding: 200rpx 0;
   box-sizing: border-box;
-} 
+}

+ 0 - 48
pages/index/index.js

@@ -1,48 +0,0 @@
-// index.js
-// 获取应用实例
-const app = getApp()
-
-Page({
-  data: {
-    motto: 'Hello World',
-    userInfo: {},
-    hasUserInfo: false,
-    canIUse: wx.canIUse('button.open-type.getUserInfo'),
-    canIUseGetUserProfile: false,
-    canIUseOpenData: wx.canIUse('open-data.type.userAvatarUrl') && wx.canIUse('open-data.type.userNickName') // 如需尝试获取用户信息可改为false
-  },
-  // 事件处理函数
-  bindViewTap() {
-    wx.navigateTo({
-      url: '../logs/logs'
-    })
-  },
-  onLoad() {
-    if (wx.getUserProfile) {
-      this.setData({
-        canIUseGetUserProfile: true
-      })
-    }
-  },
-  getUserProfile(e) {
-    // 推荐使用wx.getUserProfile获取用户信息,开发者每次通过该接口获取用户个人信息均需用户确认,开发者妥善保管用户快速填写的头像昵称,避免重复弹窗
-    wx.getUserProfile({
-      desc: '展示用户信息', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
-      success: (res) => {
-        console.log(res)
-        this.setData({
-          userInfo: res.userInfo,
-          hasUserInfo: true
-        })
-      }
-    })
-  },
-  getUserInfo(e) {
-    // 不推荐使用getUserInfo获取用户信息,预计自2021年4月13日起,getUserInfo将不再弹出弹窗,并直接返回匿名的用户个人信息
-    console.log(e)
-    this.setData({
-      userInfo: e.detail.userInfo,
-      hasUserInfo: true
-    })
-  }
-})

+ 0 - 3
pages/index/index.json

@@ -1,3 +0,0 @@
-{
-  "usingComponents": {}
-}

+ 0 - 23
pages/index/index.wxml

@@ -1,23 +0,0 @@
-<!--index.wxml-->
-<view class="container">
-  <view class="userinfo">
-    <block wx:if="{{canIUseOpenData}}">
-      <view class="userinfo-avatar" bindtap="bindViewTap">
-        <open-data type="userAvatarUrl"></open-data>
-      </view>
-      <open-data type="userNickName"></open-data>
-    </block>
-    <block wx:elif="{{!hasUserInfo}}">
-      <button wx:if="{{canIUseGetUserProfile}}" bindtap="getUserProfile"> 获取头像昵称 </button>
-      <button wx:elif="{{canIUse}}" open-type="getUserInfo" bindgetuserinfo="getUserInfo"> 获取头像昵称 </button>
-      <view wx:else> 请使用1.4.4及以上版本基础库 </view>
-    </block>
-    <block wx:else>
-      <image bindtap="bindViewTap" class="userinfo-avatar" src="{{userInfo.avatarUrl}}" mode="cover"></image>
-      <text class="userinfo-nickname">{{userInfo.nickName}}</text>
-    </block>
-  </view>
-  <view class="usermotto">
-    <text class="user-motto">{{motto}}</text>
-  </view>
-</view>

+ 0 - 19
pages/index/index.wxss

@@ -1,19 +0,0 @@
-/**index.wxss**/
-.userinfo {
-  display: flex;
-  flex-direction: column;
-  align-items: center;
-  color: #aaa;
-}
-
-.userinfo-avatar {
-  overflow: hidden;
-  width: 128rpx;
-  height: 128rpx;
-  margin: 20rpx;
-  border-radius: 50%;
-}
-
-.usermotto {
-  margin-top: 200px;
-}

+ 45 - 34
pages/permisission/permission.js

@@ -5,7 +5,21 @@ Page({
    * 页面的初始数据
    */
   data: {
-
+    phoneLoading: false,
+    showCreateForm: false,
+    createForm: null,
+    date: '',
+    sexList: [
+      {
+        id: 1,
+        title: '男'
+      },
+      {
+        id: 0,
+        title: '女'
+      }
+    ],
+    sexActive: 0
   },
 
   /**
@@ -15,13 +29,6 @@ Page({
     console.log('permission load');
   },
 
-  /**
-   * 生命周期函数--监听页面初次渲染完成
-   */
-  onReady() {
-
-  },
-
   /**
    * 生命周期函数--监听页面显示
    */
@@ -30,37 +37,41 @@ Page({
   },
 
   /**
-   * 生命周期函数--监听页面隐藏
+   * 获取用户手机号权限
    */
-  onHide() {
-
+  getPhoneNumber (e) {
+    var that = this
+    console.log(e.detail.code)
+    setTimeout(() => {
+      that.getUser()
+    }, 1000);
   },
 
-  /**
-   * 生命周期函数--监听页面卸载
-   */
-  onUnload() {
-
+  getUser () {
+    console.log('get user');
+    wx.getUserProfile({
+      desc: '获取您的微信头像和昵称用于登录',
+      success: (res) => {
+        console.log(res);
+      }
+    })
   },
-
-  /**
-   * 页面相关事件处理函数--监听用户下拉动作
-   */
-  onPullDownRefresh() {
-
+  fillInfo () {
+    console.log('filinfo');
+    wx.reLaunch({
+      url: "/pages/createInfo/createInfo"
+    })
   },
-
-  /**
-   * 页面上拉触底事件的处理函数
-   */
-  onReachBottom() {
-
+  bindDateChange (e) {
+    console.log(e);
+    this.setData({
+      date: e.detail.value
+    })
   },
-
-  /**
-   * 用户点击右上角分享
-   */
-  onShareAppMessage() {
-
+  handleSex (e) {
+    console.log(e.currentTarget.dataset.index)
+    this.setData({
+      sexActive: e.currentTarget.dataset.index
+    })
   }
 })

+ 43 - 2
pages/permisission/permission.wxml

@@ -1,2 +1,43 @@
-<!--pages/permisission/permission.wxml-->
-<text>this is permission page</text>
+<view class="entery-container">
+  <block wx:if="{{showCreateForm}}">
+    <button class="permission-btn" open-type="getPhoneNumber" bindgetphonenumber="getPhoneNumber">获取手机号</button>
+    <button class="permission-btn" bindtap="getUser">获取用户信息</button>
+    <button class="permission-btn" bindtap="fillInfo">填写信息</button>
+  </block>
+  <block wx:else>
+    <view class="form-box">
+      <view class="avatar">
+        <view class="img-item"></view>
+      </view>
+      <view class="form">
+        <view class="form-item username">
+          <view class="title">真实姓名:</view>
+          <view class="username-input">
+            <input class="weui-input" style="width:270px;" placeholder="请输入" placeholder-style="font-size: 26rpx;font-family: PingFangSC-Regular, PingFang SC;font-weight: 400;color: #999999;text-align:right"/>
+          </view>
+        </view>
+        <view class="form-item form-item-date date">
+          <view class="title">生日:</view>
+          <view class="chose-date">{{date}}</view>
+          <picker class="chose-date-picker" mode="date" value="{{date}}" bindchange="bindDateChange">
+            <view class="picker">请选择</view>
+          </picker>
+        </view>
+        <view class="form-item sex">
+          <view class="title">性别:</view>
+          <view class="radio">
+            <block wx:for="{{sexList}}" wx:key="unique">
+              <view class="radio-item">
+                <view class="radio-cricle {{index == sexActive ? 'radio-cricle-active' : ''}}" data-index="{{index}}" bindtap="handleSex">
+                  <view class="inner-cricle"></view>
+                </view>
+                <text class="radio-text">{{item.title}}</text>
+              </view>
+            </block>
+          </view>
+        </view>
+        <view class="submit-btn">确认绑定</view>
+      </view>
+    </view>
+  </block>
+</view>

+ 133 - 1
pages/permisission/permission.wxss

@@ -1 +1,133 @@
-/* pages/permisission/permission.wxss */
+/* pages/permisission/permission.wxss */
+.entery-container {
+  width: 100%;
+  height: 100%;
+  background-color: #F7F7F7;
+  display: flex;
+  flex-direction: column;
+  justify-content: flex-start;
+  align-items: center;
+}
+.permission-btn {
+  background-color: var(--maincolor);
+  color: #fff;
+  margin-top: 10rpx;
+}
+
+.form-box{
+  width: 100%;
+  margin-top: 80rpx;
+}
+
+.avatar {
+  width: 100%;
+  display: flex;
+  justify-content: center;
+}
+.img-item {
+  width: 160rpx;
+  height: 160rpx;
+  background-color: var(--maincolor);
+  border-radius: 50%;
+}
+.form {
+  width: 100%;
+  margin-top: 80rpx;
+}
+.form-item {
+  width: 690rpx;
+  height: 99rpx;
+  margin: 0 auto;
+  position: relative;
+  border-bottom:1px solid #E4E4E4;
+  display: flex;
+  justify-content: flex-start;
+  align-items: center;
+}
+.chose-date-picker {
+  position: absolute;
+  right: 20rpx;
+}
+.form-item .title {
+  font-size: 26rpx;
+  font-family: PingFangSC-Regular, PingFang SC;
+  font-weight: 400;
+  color: #333333;
+}
+.weui-input {
+  font-size: 26rpx;
+  font-family: PingFangSC-Regular, PingFang SC;
+  font-weight: 400;
+  color: #333333;
+}
+.picker {
+  font-size: 26rpx;
+  font-family: PingFangSC-Regular, PingFang SC;
+  font-weight: 400;
+  font-weight: 400;
+  color: #999999;
+}
+.form-item .chose-date {
+  width: 400rpx;
+  height: 100%;
+  display: flex;
+  justify-content: flex-start;
+  align-items: center;
+  font-size: 26rpx;
+  font-family: PingFangSC-Regular, PingFang SC;
+  font-weight: 400;
+  color: #333333;
+  margin-left: 26rpx;
+}
+.radio {
+  display: flex;
+  justify-content: flex-start;
+  align-items: center;
+}
+.radio-item {
+  display: flex;
+  justify-content: flex-start;
+  align-items: center;
+  margin-left: 20rpx;
+  margin-right: 98rpx;
+}
+.radio-cricle {
+  width: 34rpx;
+  height: 34rpx;
+  border-radius: 50%;
+  border: 1rpx solid #D9D9D9;
+  margin-right: 14rpx;
+  display: flex;
+  justify-content: center;
+  align-items: center;
+}
+.radio-cricle .inner-cricle {
+  width: 16rpx;
+  height: 16rpx;
+  border-radius: 50%;
+}
+.radio-cricle-active {
+  border: 1rpx solid #1890FF;
+}
+.radio-cricle-active .inner-cricle{
+  background-color: #1890FF;
+}
+.radio-text {
+  font-size: 28rpx;
+  font-family: PingFangSC-Regular, PingFang SC;
+  font-weight: 400;
+  color: rgba(0,0,0,0.85);
+}
+.submit-btn {
+  width: 690rpx;
+  height: 80rpx;
+  background: #45A6B5;
+  border-radius: 10rpx;
+  margin: 80rpx auto 0;
+  color: #fff;
+  display: flex;
+  justify-content: center;
+  align-items: center;
+  font-size: 26rpx;
+  font-weight: 400;
+}

+ 2 - 1
project.config.json

@@ -37,7 +37,8 @@
       "ignore": [],
       "disablePlugins": [],
       "outputPath": ""
-    }
+    },
+    "ignoreUploadUnusedFiles": true
   },
   "compileType": "miniprogram",
   "libVersion": "2.19.4",

+ 9 - 11
utils/util.js

@@ -1,19 +1,17 @@
-const formatTime = date => {
-  const year = date.getFullYear()
-  const month = date.getMonth() + 1
-  const day = date.getDate()
-  const hour = date.getHours()
-  const minute = date.getMinutes()
-  const second = date.getSeconds()
-
-  return `${[year, month, day].map(formatNumber).join('/')} ${[hour, minute, second].map(formatNumber).join(':')}`
-}
 
 const formatNumber = n => {
   n = n.toString()
   return n[1] ? n : `0${n}`
 }
 
+const ITTLoading = (title) => {
+  wx.showLoading({
+    title: title ? title : '加载中...',
+    mask: true
+  })
+}
+
 module.exports = {
-  formatTime
+  formatNumber,
+  ITTLoading
 }