liyongli 1 år sedan
förälder
incheckning
f04a9b5d2d
4 ändrade filer med 81 tillägg och 36 borttagningar
  1. 1 1
      project.private.config.json
  2. 1 0
      src/config/base.ts
  3. 6 0
      src/pages/us/index.scss
  4. 73 35
      src/pages/us/index.tsx

+ 1 - 1
project.private.config.json

@@ -2,7 +2,7 @@
   "description": "项目私有配置文件。此文件中的内容将覆盖 project.config.json 中的相同字段。项目的改动优先同步到此文件中。详见文档:https://developers.weixin.qq.com/miniprogram/dev/devtools/projectconfig.html",
   "setting": {
     "compileHotReLoad": true,
-    "urlCheck": false
+    "urlCheck": true
   },
   "projectname": "shaoershuhua"
 }

+ 1 - 0
src/config/base.ts

@@ -1,3 +1,4 @@
 export default {
   baseUrlEle: "https://cxzx.smcic.net",
+  baseAPI: "https://shuhuadasai2024api.smcic.net",
 };

+ 6 - 0
src/pages/us/index.scss

@@ -5,6 +5,12 @@
   box-sizing: border-box;
   position: relative;
 
+  .login {
+    margin: 1em 0;
+    background-color: $main-color-light;
+    color: $color-FFF;
+  }
+
   .user {
     position: absolute;
     top: 235px;

+ 73 - 35
src/pages/us/index.tsx

@@ -13,6 +13,8 @@ import expert from "../../images/expert.png";
 
 import user from "../../images/user.png";
 
+import base from "../../config/base";
+
 class Us extends React.Component<any, any> {
   static defaultProps = {};
   #systemInfo = Taro.getSystemInfoSync();
@@ -21,7 +23,8 @@ class Us extends React.Component<any, any> {
     this.state = {
       height: 0,
       heightKf: 0,
-      userUrl: Taro.getStorageSync('userUrl') || ""
+      userUrl: Taro.getStorageSync("userUrl") || "",
+      userPhone: Taro.getStorageSync("userPhone") || "",
     };
   }
 
@@ -40,60 +43,95 @@ class Us extends React.Component<any, any> {
   };
 
   onChooseAvatar = (e: any) => {
-    Taro.setStorageSync('userUrl', e.detail.avatarUrl)
+    Taro.setStorageSync("userUrl", e.detail.avatarUrl);
     this.setState({
-        userUrl: e.detail.avatarUrl
-    })
+      userUrl: e.detail.avatarUrl,
+    });
+  };
+
+  onGetPhoneNumber = (e: any) => {
+    Taro.request({
+      url: base.baseAPI + "/wx/getuserphonenumber?code=" + e.detail.code,
+      method: "GET",
+    }).then((res: any) => {
+      const { data: { code, data: { phoneInfo } }, statusCode } = res;
+      if (statusCode !== 200 || code !== 0) return Taro.showToast({
+        title: "获取手机号失败",
+        icon: "none",
+      });
+      const { phoneNumber } = phoneInfo;
+      this.setState({
+        userPhone: phoneNumber || ""
+      })
+      Taro.setStorageSync("userPhone", phoneNumber || "");
+    });
   };
 
   render() {
     // const {  } = this.props;
     return (
       <View className="Us">
-        <Button className="user" open-type="chooseAvatar" onChooseAvatar={this.onChooseAvatar}>
+        <Button
+          className="user"
+          open-type="chooseAvatar"
+          onChooseAvatar={this.onChooseAvatar}
+        >
           <Image src={this.state.userUrl || user} className="userImg"></Image>
         </Button>
 
         <Image
-          style={`width: ${this.#systemInfo.screenWidth}px;height: ${
-            this.state.height
-          }px;`}
+          style={`width: ${this.#systemInfo.screenWidth}px;height: ${this.state.height
+            }px;`}
           src="https://cxzx.smcic.net/topic/tool/img/%E5%B0%91%E5%84%BF%E4%B9%A6%E7%94%BB%E5%A4%A7%E8%B5%9B/us-top.png"
           onLoad={this.getImageSize}
         />
         <InputBox>
-          <View className="us_cell">
-            <View className="left">
-              <Image src={application} className="img"></Image>
-              <Text className="text">报名信息</Text>
-            </View>
-            <View className="right">
-              <Image src={right} className="img"></Image>
-            </View>
-          </View>
-          <View className="us_cell">
-            <View className="left">
-              <Image src={certificate} className="img"></Image>
-              <Text className="text">证书下载</Text>
-            </View>
-            <View className="right">
-              <Image src={right} className="img"></Image>
+          {!this.state.userPhone && (
+            <Button
+              className="login"
+              openType="getPhoneNumber"
+              onGetPhoneNumber={this.onGetPhoneNumber}
+            >
+              登录
+            </Button>
+          )}
+          {this.state.userPhone && (
+            <View className="us_cell">
+              <View className="left">
+                <Image src={application} className="img"></Image>
+                <Text className="text">报名信息</Text>
+              </View>
+              <View className="right">
+                <Image src={right} className="img"></Image>
+              </View>
             </View>
-          </View>
-          <View className="us_cell">
-            <View className="left">
-              <Image src={expert} className="img"></Image>
-              <Text className="text">专家评审</Text>
+          )}
+          {this.state.userPhone && (
+            <View className="us_cell">
+              <View className="left">
+                <Image src={certificate} className="img"></Image>
+                <Text className="text">证书下载</Text>
+              </View>
+              <View className="right">
+                <Image src={right} className="img"></Image>
+              </View>
             </View>
-            <View className="right">
-              <Image src={right} className="img"></Image>
+          )}
+          {this.state.userPhone && (
+            <View className="us_cell">
+              <View className="left">
+                <Image src={expert} className="img"></Image>
+                <Text className="text">专家评审</Text>
+              </View>
+              <View className="right">
+                <Image src={right} className="img"></Image>
+              </View>
             </View>
-          </View>
+          )}
         </InputBox>
         <Image
-          style={`width: ${this.#systemInfo.screenWidth * 0.92}px;height: ${
-            this.state.heightKf
-          }px;display: block;margin: 0 auto`}
+          style={`width: ${this.#systemInfo.screenWidth * 0.92}px;height: ${this.state.heightKf
+            }px;display: block;margin: 0 auto`}
           showMenuByLongpress={true}
           src="https://cxzx.smcic.net/topic/tool/img/%E5%B0%91%E5%84%BF%E4%B9%A6%E7%94%BB%E5%A4%A7%E8%B5%9B/us-kf.png"
           onLoad={this.getImageKf}