Browse Source

style(小程序): 短链需求代码格式化

qq12rrr 3 months ago
parent
commit
a7cd0d5c66
3 changed files with 121 additions and 121 deletions
  1. 87 81
      src/pages/user/components/LoginBox.tsx
  2. 17 23
      src/utils/storageUtil.ts
  3. 17 17
      src/utils/toolsUtil.ts

+ 87 - 81
src/pages/user/components/LoginBox.tsx

@@ -4,51 +4,51 @@ import Button from "@/component/button";
 import APPConfig from "@/config";
 import UserHelper from "@/helper/userHelper";
 import RouteUtil from "@/utils/routeUtil";
-import { Image, ScrollView, View, Text, Input } from "@tarojs/components";
+import { Image, View, Text, Input } from "@tarojs/components";
 import { useRequest } from "ahooks";
-import { parseQueryParams, isOuterLink } from "../../../utils/toolsUtil"
-import React, {
-  useState,
-  useEffect,
-  useCallback,
-  useRef,
-  useImperativeHandle,
-  forwardRef,
-} from "react";
+import { parseQueryParams, isOuterLink } from "../../../utils/toolsUtil";
+import { useState, useEffect, useImperativeHandle, forwardRef } from "react";
 import { AtFloatLayout } from "taro-ui";
 import { showToast } from "@tarojs/taro";
 import ctyptoUtil from "@/utils/crypto";
 
-const LoginBox = forwardRef((props,ref) => {
-    useImperativeHandle(ref, () => ({
-        handleOpen() {
-            handleOpen();
-        }
-    }))    
-  const indexInfoResult = useRequest(() => {
+// @ts-ignore
+const LoginBox = forwardRef((props, ref) => {
+  useImperativeHandle(ref, () => ({
+    handleOpen() {
+      handleOpen();
+    },
+  }));
+  const indexInfoResult: any = useRequest(() => {
     return UserApi.getIndexInfoUsingPost({
       params: { appId: APPConfig.APPID },
     }).toData();
   });
   const postJumpUrlResult = () => {
-    const params = parseQueryParams(indexInfoResult.data.link)
+    const params: any = parseQueryParams(indexInfoResult.data.link);
     return UserApi.getJumpUrlPost({
       loading: true,
-      data: { appId: APPConfig.APPID, channelCode: params.channelCode, productId: params.productId }
-    }).toData().then(res => {
-      console.log("获取跳转链接结果", res)
-      RouteUtil.toWebViewPage({ url: res?.adJumpLink })
+      data: {
+        appId: APPConfig.APPID,
+        channelCode: params.channelCode,
+        productId: params.productId,
+      },
     })
-}
+      .toData()
+      .then((res: any) => {
+        console.log("获取跳转链接结果", res);
+        RouteUtil.toWebViewPage({ url: res?.adJumpLink });
+      });
+  };
 
   const loginFlowHandler = async () => {
-    await UserHelper.UpdateOpenId()
+    await UserHelper.UpdateOpenId();
     if (isOuterLink(indexInfoResult?.data.link)) {
-      await postJumpUrlResult()
+      await postJumpUrlResult();
     } else {
-      await RouteUtil.toWebViewPage({ url: indexInfoResult?.data.link })
+      await RouteUtil.toWebViewPage({ url: indexInfoResult?.data.link });
     }
-  }
+  };
 
   const [isSHow, setIsSHow] = useState(false);
   // 打开浮动层的函数
@@ -104,7 +104,7 @@ const LoginBox = forwardRef((props,ref) => {
       //   await UserHelper.callback();
       // }
 
-      loginFlowHandler()
+      loginFlowHandler();
     }
   };
   const [time, setTime] = useState(60);
@@ -151,7 +151,7 @@ const LoginBox = forwardRef((props,ref) => {
       setTime(60); // 重置倒计时
       let obj = {
         // channelCode: "jiheyanfa",
-        "channelCode":"txxcx04",
+        channelCode: "txxcx04",
         phone: ctyptoUtil.AesEncode(phone),
         sceneType: "register",
       };
@@ -210,7 +210,7 @@ const LoginBox = forwardRef((props,ref) => {
       return;
     }
     let obj = {
-      "channelCode":"txxcx01",
+      channelCode: "txxcx01",
       phone: ctyptoUtil.AesEncode(phone),
       sceneType: "register",
       uctrackid: "",
@@ -242,7 +242,7 @@ const LoginBox = forwardRef((props,ref) => {
           // if (UserHelper.callback) {
           //   await UserHelper.callback();
           // }
-          loginFlowHandler()
+          loginFlowHandler();
         }
       })
       .catch((err) => {
@@ -255,7 +255,7 @@ const LoginBox = forwardRef((props,ref) => {
     }).toData();
   });
   const goRegPage = () => {
-    aggrement.data?.map((p, index) => {
+    aggrement.data?.map((p) => {
       if (p.name == "用户服务协议") {
         RouteUtil.toWebViewPage({ url: p.url });
       }
@@ -263,7 +263,7 @@ const LoginBox = forwardRef((props,ref) => {
   };
   const goPrivacyPage = () => {
     console.log(aggrement);
-    aggrement.data?.map((p, index) => {
+    aggrement.data?.map((p) => {
       if (p.name == "隐私政策") {
         RouteUtil.toWebViewPage({ url: p.url });
       }
@@ -271,7 +271,7 @@ const LoginBox = forwardRef((props,ref) => {
   };
   const goStudentPage = () => {
     console.log(aggrement);
-    aggrement.data?.map((p, index) => {
+    aggrement.data?.map((p) => {
       if (p.name == "非学生承诺函") {
         RouteUtil.toWebViewPage({ url: p.url });
       }
@@ -282,30 +282,30 @@ const LoginBox = forwardRef((props,ref) => {
       {showNum == 0 && (
         <Image
           src={require("@/assets/box-bg.png")}
-          className='avatar-image-bg'
+          className="avatar-image-bg"
         />
       )}
       {showNum == 0 ? (
-        <View className='login-introduce'>
-          <View className='title'>
+        <View className="login-introduce">
+          <View className="title">
             登录方式选择及隐私政策告知
             <View onClick={handleClose}>
               <Image
                 src={require("@/assets/close.png")}
-                className='avatar-image'
+                className="avatar-image"
               />
             </View>
           </View>
-          <View className='text'>
+          <View className="text">
             为了您正常的使用我们的小程序服务,我们需要处理您的个人信息,具体详见{" "}
-            <Text onClick={goPrivacyPage} className='blue'>
+            <Text onClick={goPrivacyPage} className="blue">
               《隐私政策》
             </Text>
             。 在您未确认
-            <Text onClick={goPrivacyPage} className='blue'>
+            <Text onClick={goPrivacyPage} className="blue">
               《隐私政策》
             </Text>
-            前,我们不会搜集您的任何信息。 
+            前,我们不会搜集您的任何信息。
             {/* 当您勾选协议后即标识您已阅读并同意
             <Text onClick={goPrivacyPage} className="blue">
               《隐私政策》
@@ -316,124 +316,130 @@ const LoginBox = forwardRef((props,ref) => {
             </Text>
             上的全部内容 */}
           </View>
-          <View className='checkd'>
-            <View className='checkbox'>
+          <View className="checkd">
+            <View className="checkbox">
               {checked ? (
                 <Image
                   onClick={handleCheckboxChange}
                   src={require("@/assets/checkd.png")}
-                  className='avatar-image'
+                  className="avatar-image"
                 />
               ) : (
                 <Image
                   onClick={handleCheckboxChange}
                   src={require("@/assets/check.png")}
-                  className='avatar-image'
+                  className="avatar-image"
                 />
               )}
-              <Text className='agree' onClick={handleCheckboxChange}>
+              <Text className="agree" onClick={handleCheckboxChange}>
                 请确定已阅读并同意
               </Text>
             </View>
-            <Text onClick={goPrivacyPage} className='blue'>
+            <Text onClick={goPrivacyPage} className="blue">
               《隐私政策》
             </Text>
-            <Text onClick={goRegPage} className='blue'>
+            <Text onClick={goRegPage} className="blue">
               《用户服务协议》
             </Text>
-            <Text className='agree'>和</Text>
-            <Text onClick={goStudentPage} className='blue'>
+            <Text className="agree">和</Text>
+            <Text onClick={goStudentPage} className="blue">
               《非学生承诺函》
             </Text>
           </View>
           <View>
             {checked ? (
               <Button
-                className='index-quck-btn fontsize36'
-                openType='getPhoneNumber'
+                className="index-quck-btn fontsize36"
+                openType="getPhoneNumber"
                 onGetPhoneNumber={quickLogin}
               >
                 一键快捷登录
               </Button>
             ) : (
-              <Button className='index-quck-btn fontsize36' onClick={quickLogin}>
+              <Button
+                className="index-quck-btn fontsize36"
+                onClick={quickLogin}
+              >
                 一键快捷登录
               </Button>
             )}
           </View>
-          <View onClick={showNumChange.bind(null, 1)} className='other-login'>
+          <View onClick={showNumChange.bind(null, 1)} className="other-login">
             输入手机号登录
           </View>
         </View>
       ) : (
-        <View className='login-introduce phone-login'>
-          <View className='title'>
-            <Text className='text-title'>登录诚易融</Text>
-            <View onClick={handleClose} className='float'>
+        <View className="login-introduce phone-login">
+          <View className="title">
+            <Text className="text-title">登录诚易融</Text>
+            <View onClick={handleClose} className="float">
               <Image
                 src={require("@/assets/close.png")}
-                className='avatar-image'
+                className="avatar-image"
               />
             </View>
           </View>
-          <View className='input-box'>
-            <View className='input-phone'>
+          <View className="input-box">
+            <View className="input-phone">
               <Input
-                type='text'
-                placeholderClass='gray'
+                type="text"
+                placeholderClass="gray"
                 onInput={phoneNumChange}
                 value={phone}
-                placeholder='请输入本人实名认证手机号'
+                placeholder="请输入本人实名认证手机号"
                 maxlength={11}
               />
             </View>
-            <View className='input-password'>
+            <View className="input-password">
               <Input
-                type='text'
-                placeholderClass='gray'
+                type="text"
+                placeholderClass="gray"
                 onInput={validateChange}
                 value={validate}
-                placeholder='请输入验证码'
+                placeholder="请输入验证码"
                 maxlength={6}
               />
               {isGetValidate ? (
-                <View className='gray'>重新发送 ({time}S)</View>
+                <View className="gray">重新发送 ({time}S)</View>
               ) : (
-                <View className='gettime' onClick={isGetValidateChange}>
+                <View className="gettime" onClick={isGetValidateChange}>
                   获取验证码
                 </View>
               )}
             </View>
           </View>
-          <View className='checkd'>
-            <View className='checkbox'>
+          <View className="checkd">
+            <View className="checkbox">
               {checkedPhone ? (
                 <Image
                   onClick={phoneChange}
                   src={require("@/assets/checkd.png")}
-                  className='avatar-image'
+                  className="avatar-image"
                 />
               ) : (
                 <Image
                   onClick={phoneChange}
                   src={require("@/assets/check.png")}
-                  className='avatar-image'
+                  className="avatar-image"
                 />
               )}
-              <Text className='agree' onClick={phoneChange}>请确定已阅读并同意</Text>
+              <Text className="agree" onClick={phoneChange}>
+                请确定已阅读并同意
+              </Text>
             </View>
-            <Text onClick={goPrivacyPage} className='blue'>
+            <Text onClick={goPrivacyPage} className="blue">
               《隐私政策》
             </Text>
-            <Text onClick={goRegPage} className='blue'>
+            <Text onClick={goRegPage} className="blue">
               《用户服务协议》
-            </Text>和
-            <Text onClick={goStudentPage} className='blue'>
+            </Text>
+            和
+            <Text onClick={goStudentPage} className="blue">
               《非学生承诺函》
             </Text>
           </View>
           <View>
-            <Button className='index-quck-btn fontsize36' onClick={submitClick}>
+            <Button className="index-quck-btn fontsize36" onClick={submitClick}>
               立即登录
             </Button>
           </View>

+ 17 - 23
src/utils/storageUtil.ts

@@ -1,31 +1,25 @@
 import Taro from "@tarojs/taro";
 
 export enum EStorage {
-    userInfo = "USER_INFO",
-    tabMenu = "TAB_MENU"
+  userInfo = "USER_INFO",
+  tabMenu = "TAB_MENU",
 }
 
 export default class StorageUtil {
-
-    public static set(key: EStorage, value: any) {
-        if (typeof value !== "string") {
-            try {
-                value = JSON.stringify(value);
-            } catch (error) {
-
-            }
-        }
-        Taro.setStorageSync(key, value)
+  public static set(key: EStorage, value: any) {
+    if (typeof value !== "string") {
+      try {
+        value = JSON.stringify(value);
+      } catch (error) {}
     }
+    Taro.setStorageSync(key, value);
+  }
 
-    public static get<T>(key: EStorage): T {
-        let value = Taro.getStorageSync(key);
-        try {
-            value = value && JSON.parse(value)
-        } catch (error) {
-
-        }
-        return value;
-
-    }
-};
+  public static get<T>(key: EStorage): T {
+    let value = Taro.getStorageSync(key);
+    try {
+      value = value && JSON.parse(value);
+    } catch (error) {}
+    return value;
+  }
+}

+ 17 - 17
src/utils/toolsUtil.ts

@@ -5,40 +5,40 @@
  * @example
  * ```js
  * const url = 'https://baidu.com?s=hello&k=world'
- * 
+ *
  * parseQueryParams(url)  // { s:'hello', k:'world' }
- * 
+ *
  * const url2 = 'https://www.baidu.com'
- * 
+ *
  * parseQueryParams(url2) // {}
- * 
+ *
  * ```
  */
 export const parseQueryParams = (url: string) => {
-  const param = {}
+  const param = {};
   if (!url) {
-    throw new ReferenceError('param url can not be undefined')
+    throw new ReferenceError("param url can not be undefined");
   }
   // if the url not includes ? then return result straight
-  if (!url.includes('?')) {
-    return param
+  if (!url.includes("?")) {
+    return param;
   }
 
-  const [,queryParamsString] = url.split('?')
+  const [, queryParamsString] = url.split("?");
 
-  const queryParamsArray = queryParamsString.split('&')
+  const queryParamsArray = queryParamsString.split("&");
 
   queryParamsArray.forEach((queryItem) => {
-    const [key, value] = queryItem.split('=')
-    param[key] = value
-  })
+    const [key, value] = queryItem.split("=");
+    param[key] = value;
+  });
 
-  return param
-}
+  return param;
+};
 
 /**
  * 判断是直接跳转内部H5还是外部获取url进行跳转
  */
 export const isOuterLink = (url: string) => {
-  return !url.includes('/promote/home')
-}
+  return !url.includes("/promote/home");
+};