From 9850328c9d2671e0ffe914c82b7f34df4fa219b1 Mon Sep 17 00:00:00 2001 From: hackrobot Date: Mon, 25 Mar 2024 01:17:01 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E7=94=A8=E6=88=B7=E5=A4=B4=E5=83=8F?= =?UTF-8?q?=E6=95=B0=E6=8D=AE/=E6=98=B5=E7=A7=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/index/index.jsx | 76 +++++++++++++++++++-------------------- src/pages/my/index.jsx | 28 +++++++++------ 2 files changed, 53 insertions(+), 51 deletions(-) diff --git a/src/pages/index/index.jsx b/src/pages/index/index.jsx index f944eab..2bc1514 100644 --- a/src/pages/index/index.jsx +++ b/src/pages/index/index.jsx @@ -63,13 +63,22 @@ export default function Index() { console.log("Page loaded."); }); + // 获取用户标识符 useEffect(() => { - try { - let getuserInfo = Taro.getStorageSync("userInfo"); - if (getuserInfo) { - setuserInfo(getuserInfo); - console.log("本地用户信息存在"); - } else { + // 获取路由参数 + const params = Taro.getCurrentInstance().router.params; + console.log("params", params); + // const [wxid, openId] = params; + + // debug + params.wxid = "wxid_4413224132412"; + if (params?.wxid) { + setuserInfo({ + wxid: params?.wxid, //个人号wxid + }); + try { + // 本地存储 + Taro.setStorageSync("wxid", params?.wxid ?? ""); Taro.login({ success: function (res) { if (res.code) { @@ -78,7 +87,7 @@ export default function Index() { url: "http://127.0.0.1:28369/login", data: { code: res.code, - wxid: userInfo?.wxid ?? "wxid_4413224132412", //debug eric 的wxid + wxid: params?.wxid ?? null, //debug eric 的wxid }, success: function (resUser) { console.log(resUser); @@ -96,29 +105,19 @@ export default function Index() { } }, }); - } - } catch (e) { - console.log("error", e); - } - }, []); - - // 获取用户标识符 - useEffect(() => { - // 获取路由参数 - const params = Taro.getCurrentInstance().router.params; - console.log("params", params); - // const [wxid, openId] = params; - - if (params.wxid) { - setuserInfo({ - wxid: params?.wxid, //个人号wxid - // openId: params?.openId, //小程序openid - }); - // 本地存储 - - try { - Taro.setStorageSync("wxid", params?.wxid ?? ""); } catch (e) {} + } else { + try { + let getuserInfo = Taro.getStorageSync("userInfo"); + if (getuserInfo) { + setuserInfo(getuserInfo); + console.log("本地用户信息存在"); + } else { + console.log("本地用户信息,不存在"); + } + } catch (e) { + console.log("error", e); + } } }, []); @@ -264,17 +263,14 @@ export default function Index() { {/* 顶部 */} - - {/* 头像 */} - 0 ? userInfo.smallhead : touxiang - } - > - {/* color="#F00" */} - - + {userInfo?.smallhead ? ( + + {/* 头像 */} + + {/* color="#F00" */} + + + ) : null} {/* 省份标签 */} diff --git a/src/pages/my/index.jsx b/src/pages/my/index.jsx index 7d75ee0..89706ea 100644 --- a/src/pages/my/index.jsx +++ b/src/pages/my/index.jsx @@ -21,11 +21,15 @@ import TabbarCom from "@/componments/TabbarCom"; import { useEffect, useState } from "react"; const my = () => { const [open, setopen] = useState(false); - useEffect(()=>{ + const [localuserInfo, setlocaluserInfo] = useState( + Taro.getStorageSync("userInfo") + ); + + useEffect(() => { // 获取路由参数 - const params= Taro.getCurrentInstance().router.params - console.log('params',params) - },[]) + const params = Taro.getCurrentInstance().router.params; + console.log("params", params); + }, []); const handleClick = (value) => { setopen(true); @@ -35,9 +39,12 @@ const my = () => { {/* 头像 */} - + - 星球新居民 + {localuserInfo?.nickname??星球新居民} {/* */} @@ -54,11 +61,11 @@ const my = () => { // note="描述信息" arrow="right" thumb="http://img10.360buyimg.com/jdphoto/s72x72_jfs/t5872/209/5240187906/2872/8fa98cd/595c3b2aN4155b931.png" - onClick={()=>{ + onClick={() => { // 跳转到目的页面,打开新页面 -Taro.navigateTo({ - url: '/pages/my/componments/Log/index', -}) + Taro.navigateTo({ + url: "/pages/my/componments/Log/index", + }); }} /> - {/* 个人客服 */} {/*