Administrator 2 tahun lalu
induk
melakukan
fa0d8948ed

+ 7 - 0
data/dao/Userdao.go

@@ -31,6 +31,13 @@ func Logins(username, password, t string) (domain.User, error) {
 	}
 	return domain.User{}, err
 }
+
+func GetUserByPhone(phone string) (domain.User, error) {
+	var user = domain.User{}
+	_, err := configs.Engine.Where("phone = ?", phone).Get(&user)
+	return user, err
+}
+
 func SendSms(matched bool, username string) string {
 	mins := big.NewInt(100000)
 	maxs := big.NewInt(999999)

+ 1 - 0
file/assets/css/detail.css

@@ -726,3 +726,4 @@
 .value-now:before {
     content: "¥";
 }
+

+ 116 - 4
file/assets/css/index.css

@@ -133,11 +133,16 @@ body, html, div {
 
 .login-center {
     display: inline-block;
+    position: absolute;
     margin: 10% auto 0 auto;
+    top: 10%;
+    left: calc(50% - 200px);
+    text-align: center;
 }
 
 .login-content {
     display: inline-block;
+
     width: 437px;
     height: 430px;
     background-color: transparent;
@@ -206,7 +211,7 @@ body, html, div {
     border-radius: 20px;
     box-shadow: #888888 0 0 5px;
     transition: margin-left 0.2s ease-in-out;
-    z-index: 0;
+    z-index: 1;
 }
 
 
@@ -295,9 +300,13 @@ body, html, div {
 .login-email {
     display: flex;
     justify-content: center;
+    flex-direction: column;
     margin: 20px auto 20px auto;
     width: 300px;
 }
+.login-email .login-email-input{
+    margin: 0 auto 20px auto;
+}
 
 .login-email-input {
     height: 32px;
@@ -319,7 +328,7 @@ body, html, div {
 }
 
 .login-email-input:active {
-    border: transparent 0;
+    /*border: transparent 0;*/
 }
 
 
@@ -336,6 +345,7 @@ body, html, div {
     user-select: none;
     color: #dddddd;
     font-size: 18px;
+
     line-height: 42px;
     font-weight: bold;
 }
@@ -456,6 +466,7 @@ body, html, div {
 }
 
 .login-wx-refresh-icon {
+
 }
 
 .login-wx-refresh-icon img {
@@ -509,7 +520,8 @@ body, html, div {
 
 .login-image {
     border-radius: 25px;
-    background-image: linear-gradient(to right, rgba(0, 0, 0, 0.1), rgba(0, 0, 0, 0.9));
+    background-image: url('https://cdn.yicanggongyi.com/yinhe/icon/login.png'); width: 430px; height: 430px;
+    /*background-image: linear-gradient(to right, rgba(0, 0, 0, 0.1), rgba(0, 0, 0, 0.9));*/
     position: absolute;
     transform: translateX(-70%);
     width: 437px;
@@ -758,4 +770,104 @@ body, html, div {
 
 .footer-about-app img {
     margin-right: 30px;
-}
+}
+
+
+/*注册*/
+body, html {
+    margin: 0;
+    padding: 0;
+    font-family: Arial, sans-serif;
+}
+
+.register-center {
+    position: absolute;
+    margin: 10% auto 0 auto;
+    top: 10%;
+    left: calc(50% - 200px);
+    display: flex;
+    justify-content: center;
+    align-items: center;
+    color: #888;
+}
+
+.register-content {
+    display: flex;
+    flex-direction: column;
+    align-items: center;
+    width: 350px;
+    height: 430px;
+    background-color: white;
+    border-radius: 20px;
+    padding: 20px 40px;
+    box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
+}
+
+.register-content-title {
+    color: #333;
+    font-size: 24px;
+    font-weight: bold;
+    margin-bottom: 20px;
+}
+
+.register-content-input {
+    width: 100%;
+    margin-bottom: 20px;
+}
+
+.register-content-input input {
+    width: 100%;
+    height: 32px;
+    padding: 5px;
+    border: 2px solid #ddd;
+    border-radius: 15px;
+    outline: none;
+    font-size: 16px;
+}
+
+.register-content-code {
+    display: flex;
+    justify-content: space-between;
+    width: 100%;
+}
+
+
+.register-content-code-input {
+    width: 60%;
+}
+.register-content-code-input input {
+    width: 100%;
+    height: 32px;
+    padding: 5px;
+    border: 2px solid #ddd;
+    border-radius: 15px;
+    outline: none;
+    font-size: 16px;
+}
+.register-content-code-btn {
+    width: 32%;
+    height: 42px;
+    background-color: #207cfb;
+    color: white;
+    border-radius: 15px;
+    display: flex;
+    justify-content: center;
+    align-items: center;
+    cursor: pointer;
+    user-select: none;
+}
+
+.register-content-submit {
+    width: 100%;
+    height: 42px;
+    background-color: #207cfb;
+    color: white;
+    border-radius: 15px;
+    display: flex;
+    justify-content: center;
+    align-items: center;
+    cursor: pointer;
+    user-select: none;
+    font-weight: bold;
+    margin-top: 20px;
+}

+ 358 - 7
file/assets/js/handler.js

@@ -1,10 +1,361 @@
-const routerArray = [
-    {
-        path: '/',
-        name: '首页',
-    }]
+const routerArray = [{
+    path: '/', name: '首页',
+}]
+const handler = {
+    routerArray, JumpRouter, getToken, setToken, GetUserInfo
+}
+var loginState = false;
 
 //=======================链接跳转
 function JumpRouter(url, query) {
-    window.location.href = url + "?routerlink=" + query;
-}
+    if (query) {
+        window.location.href = url + "?routerlink=" + query;
+    } else {
+        window.location.href = url
+    }
+}
+
+function getToken() {
+    return localStorage.getItem("token");
+}
+
+function setToken(value) {
+    localStorage.setItem("token", value);
+    console.log("token set", getToken())
+}
+
+function GetUserInfo() {
+    console.log("获取用户信息")
+    fetch('/api/user/info', {
+        method: 'GET', headers: {
+            // 'Content-Type': 'application/json',
+            "auth-sign": getToken()
+        }, // body: JSON.stringify(data)
+    })
+        .then(response => response.json())
+        .then(data => {
+            if (data.code !== 200) {
+                loginState = false;
+                //头像修改
+                document.getElementById("not-login").style.display = "black";
+                document.getElementById("logged-in").style.display = "none";
+                //用户名称
+                document.getElementById("login-name").innerText = "登录";
+            } else {
+                //导航栏头像处理
+                if (data.data.avatar) {
+                    document.getElementById("not-login").style.display = "none";
+                    let logged = document.getElementById("logged-in");
+                    logged.style.display = "block"
+                    logged.src = data.data.avatar;
+                } else {
+                    document.getElementById("not-login").style.display = "black";
+                    document.getElementById("logged-in").style.display = "none";
+                }
+                // 导航栏名字问题
+                document.getElementById("login-name").innerText = data.data.name;
+                loginState = true;
+            }
+        })
+        .catch((error) => {
+            loginState = false;
+            //头像修改
+            document.getElementById("not-login").style.display = "black";
+            document.getElementById("logged-in").style.display = "none";
+            //用户名称
+            document.getElementById("login-name").innerText = "登录";
+            console.error('Error:', error);
+            // alert("获取登录信息失败");
+        });
+
+}
+
+function clickAvatar() {
+    if (loginState) {
+        //已经登录的,进入管理页面
+        JumpRouter("/manage/info");
+    } else {
+        let loginBody = document.getElementById("login-body");
+        let loginCenter = document.getElementById("login-center");
+        let registerCenter = document.getElementById("register-center");
+        loginBody.style.display = "";
+        loginCenter.style.display = "";
+        registerCenter.style.display = "none"
+    }
+}
+
+function closeLoginBody() {
+    console.log(6666666666)
+    let loginBody = document.getElementById("login-body");
+    let loginCenter = document.getElementById("login-center");
+    let registerCenter = document.getElementById("register-center");
+    loginBody.style.display = "none";
+    loginCenter.style.display = "none";
+    registerCenter.style.display = "none"
+
+
+}
+
+function openLoginBody(type) {
+    if (type === "register") {
+        let loginBody = document.getElementById("login-body");
+        let loginCenter = document.getElementById("login-center");
+        let registerCenter = document.getElementById("register-center");
+        loginBody.style.display = "";
+        loginCenter.style.display = "none";
+        registerCenter.style.display = ""
+    } else if (type === "login") {
+        let loginBody = document.getElementById("login-body");
+        let loginCenter = document.getElementById("login-center");
+        let registerCenter = document.getElementById("register-center");
+        loginBody.style.display = "";
+        loginCenter.style.display = "";
+        registerCenter.style.display = "none"
+    }
+}
+
+//登录
+document.addEventListener('DOMContentLoaded', () => {
+    const selectType = 'email';
+    const phoneTab = document.getElementById('phone-tab');
+    const emailTab = document.getElementById('email-tab');
+    const wxTab = document.getElementById('wx-tab');
+    const phoneSection = document.getElementById('phone-section');
+    const emailSection = document.getElementById('email-section');
+    const wxSection = document.getElementById('wx-section');
+    const selectBar = document.getElementById('select-bar');
+
+    const sendCodeBtn = document.getElementById('send-code-btn');
+    const phoneLoginBtn = document.getElementById('phone-login-btn');
+
+    const emailLoginBtn = document.getElementById('email-login-btn');
+    const refreshWxCode = document.getElementById('refresh-wx-code');
+
+    function setType(type) {
+        phoneSection.style.display = 'none';
+        emailSection.style.display = 'none';
+        wxSection.style.display = 'none';
+
+        if (type === 'phone') {
+            phoneSection.style.display = 'block';
+
+            selectBar.style.marginLeft = '-200px';
+        } else if (type === 'email') {
+            emailSection.style.display = 'block';
+            selectBar.style.marginLeft = '0';
+        } else if (type === 'wx') {
+            wxSection.style.display = 'block';
+            selectBar.style.marginLeft = '200px';
+        }
+    }
+
+    phoneTab.addEventListener('click', () => setType('phone'));
+    emailTab.addEventListener('click', () => setType('email'));
+    wxTab.addEventListener('click', () => setType('wx'));
+
+    function showTip(msg) {
+        alert(msg);
+    }
+
+    function validateEmail(email) {
+        const re = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
+        return re.test(String(email).toLowerCase());
+    }
+
+    function validatePhone(phone) {
+        const re = /^1[3-9]\d{9}$/;
+        return re.test(String(phone));
+    }
+
+    function validateCode(code) {
+        const re = /^\d{6}$/;
+        return re.test(String(code));
+    }
+
+
+    sendCodeBtn.addEventListener('click', () => {
+        const phone = document.getElementById('phone-input').value;
+        if (!validatePhone(phone)) {
+            showTip('手机号格式错误');
+            return;
+        }
+        fetch("/api/user/loginCode", {
+            method: 'POST',
+            headers: {
+                'Content-Type': 'application/json'
+            },
+            body: JSON.stringify({
+                phone: phone
+            })
+        })
+            .then(response => {
+                if (!response.ok) {
+                    throw new Error('Network response was not ok ' + response.statusText);
+                }
+                return response.json();
+            })
+            .then(data => {
+                if (data.success) {
+                    console.log('Verification code sent successfully:', data);
+                } else {
+                    console.error('Failed to send verification code:', data.message);
+                }
+            })
+            .catch(error => {
+                console.error('There has been a problem with your fetch operation:', error);
+            });
+        alert('验证码已发送');
+
+
+    });
+
+    phoneLoginBtn.addEventListener('click', () => {
+        const phone = document.getElementById('phone-input').value;
+        const code = document.getElementById('phone-code-input').value;
+        if (!validatePhone(phone)) {
+            showTip('手机号格式错误');
+            return;
+        }
+        if (!validateCode(code)) {
+            showTip('验证码错误');
+            return;
+        }
+        fetch("/api/user/login", {
+            method: 'POST',
+            headers: {
+                'Content-Type': 'application/json'
+            },
+            body: JSON.stringify({
+                username: phone,
+                password: code,
+                type: "phone"
+            })
+        }).then(response => {
+            if (!response.ok) {
+                throw new Error('Network response was not ok ' + response.statusText);
+            }
+            return response.json();
+        }).then(data => {
+            if (data.code === 200) {
+                setToken(data.data.token)
+                //刷新页面
+                window.location.reload();
+            } else {
+                alert(data.msg)
+            }
+        }).catch(error => {
+            console.error('There has been a problem with your fetch operation:', error);
+        });
+
+
+        alert('手机号登录成功');
+    });
+
+    emailLoginBtn.addEventListener('click', () => {
+        const email = document.getElementById('email-input').value;
+        const password = document.getElementById('email-password-input').value;
+        if (!validateEmail(email)) {
+            showTip('邮箱格式错误');
+            return;
+        }
+        if (password.length < 6) {
+            showTip('密码过短');
+            return;
+        }
+        //TODO 邮箱登录
+        alert('邮箱登录成功');
+    });
+
+    refreshWxCode.addEventListener('click', () => {
+        console.log('二维码已刷新');
+    });
+
+    setType(selectType);
+});
+//注册
+document.addEventListener('DOMContentLoaded', () => {
+    const username = document.getElementById('username');
+    const password = document.getElementById('password');
+    const requirePassword = document.getElementById('requirePassword');
+    const phone = document.getElementById('phone');
+    const code = document.getElementById('code');
+    const sendCodeBtn = document.getElementById('send-register-code');
+    const registerBtn = document.getElementById('register-btn');
+
+    let awaitCode = 0;
+
+    function showTip(msg) {
+        alert(msg);
+    }
+
+    function validateEmail(email) {
+        const re = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
+        return re.test(String(email).toLowerCase());
+    }
+
+    function validatePhone(phone) {
+        const re = /^1[3-9]\d{9}$/;
+        return re.test(String(phone));
+    }
+
+    function validatePassword(password) {
+        const re = /^[a-zA-Z0-9,./<>?;'\\:"|\[\]{}~!@#$%^&*()_+=-]{6,32}$/;
+        return re.test(String(password));
+    }
+
+    function validateCode(code) {
+        const re = /^[0-9]{6}$/;
+        return re.test(String(code));
+    }
+
+    sendCodeBtn.addEventListener('click', () => {
+        if (awaitCode === 0) {
+            const phoneVal = phone.value;
+            if (!validatePhone(phoneVal)) {
+                showTip('手机号格式错误');
+                return;
+            }
+            alert('验证码已发送');
+            awaitCode = 5;
+            const interval = setInterval(() => {
+                awaitCode--;
+                sendCodeBtn.textContent = awaitCode > 0 ? `${awaitCode}s` : '发送验证码';
+                if (awaitCode === 0) {
+                    clearInterval(interval);
+                }
+            }, 1000);
+        }
+    });
+
+    registerBtn.addEventListener('click', () => {
+        const usernameVal = username.value;
+        const passwordVal = password.value;
+        const requirePasswordVal = requirePassword.value;
+        const phoneVal = phone.value;
+        const codeVal = code.value;
+
+        if (!validateEmail(usernameVal)) {
+            showTip('邮箱格式错误');
+            return;
+        }
+        if (!validatePassword(passwordVal)) {
+            showTip('密码格式错误');
+            return;
+        }
+        if (passwordVal !== requirePasswordVal) {
+            showTip('两次密码不一致');
+            return;
+        }
+        if (!validatePhone(phoneVal)) {
+            showTip('手机号格式错误');
+            return;
+        }
+        if (!validateCode(codeVal)) {
+            showTip('验证码错误');
+            return;
+        }
+
+        alert('注册成功');
+        // Here you can make an API request to register the user
+    });
+});

+ 26 - 3
file/assets/js/index.js

@@ -96,7 +96,6 @@ var CardListElements = null
 //初始化加载 topic列表
 function TopicListShowLoad() {
     CardListElements = document.getElementsByClassName("card-list");
-    console.log(6666666666)
     for (let i = 0; i < CardListElements.length; i++) {
         let goodsInfoEles = CardListElements[i].getElementsByClassName("goods-info")
         for (let i = 0; i < goodsInfoEles.length; i++) {
@@ -105,12 +104,10 @@ function TopicListShowLoad() {
             }
         }
         let showEle = CardListElements[i].getElementsByClassName("card-show")
-        console.log(showEle)
         if (!showEle || showEle.length === 0) {
             continue
         }
         let linkElement = showEle.item(0).getElementsByTagName("a").item(0);
-        console.log(linkElement)
         linkElement.addEventListener("click", (e) => {
             if (linkElement.getAttribute("show")==="true") {
                 linkElement.setAttribute("show", "false");
@@ -142,5 +139,31 @@ function TopicListShowLoad() {
 
 }
 
+// fetch('/api/order/submit', {
+//     method: 'POST',
+//     headers: {
+//         'Content-Type': 'application/json'
+//     },
+//     body: JSON.stringify(data)
+// })
+//     .then(response => response.json())
+//     .then(data => {
+//         console.log('Success:', data);
+//         alert("假装购买成功");
+//     })
+//     .catch((error) => {
+//         console.error('Error:', error);
+//         alert("购买失败");
+//     });
+
+
+
+
+
+
+
+
+
+
 handleScroll()
 TopicListShowLoad()

+ 67 - 68
file/static/detail.html

@@ -5,14 +5,19 @@
     <title>详情</title>
     <link rel="stylesheet" href="../assets/css/index.css">
     <link rel="stylesheet" href="../assets/css/detail.css">
+    <script src="../assets/js/handler.js"></script>
 </head>
 <body>
+
 <div class="navigation-bar">
     <div class="nav-body">
         <!--      <router-link to="/" class="nav-logo">-->
         <div class="nav-logo">
             <img src="../assets/image/logo.png" alt="logo" onclick="JumpRouter('/','')"/>
         </div>
+        <!--        <button onclick="setToken('eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3MTg3ODIzOTMsImlzcyI6IjEifQ.b6tID6zWsYtMKnxen0ZuGBpsSE2bpupAHYf80WsH2gQ')">-->
+        <!--            首页-->
+        <!--        </button>-->
         <!--      </router-link>-->
         <div class="nav-search">
             <form action="/search" target="_blank">
@@ -31,88 +36,77 @@
             </form>
         </div>
         <div class="nav-user">
-
             <!--                todo 头像处理-->
-            <div class="nav-user-icon" @click="openView()">
+            <div class="nav-user-icon" onclick="clickAvatar()">
                 <div class="nav-user-icon-bg">
-                    <el-icon size="24">
-                        <User/>
-                    </el-icon>
-                    <img :src="userInfo.avatar" v-else alt="6"/>
+                    <svg id="not-login" style="width: 24px;height: 24px"
+                         xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1024 1024">
+                        <path fill="currentColor"
+                              d="M512 512a192 192 0 1 0 0-384 192 192 0 0 0 0 384m0 64a256 256 0 1 1 0-512 256 256 0 0 1 0 512m320 320v-96a96 96 0 0 0-96-96H288a96 96 0 0 0-96 96v96a32 32 0 1 1-64 0v-96a160 160 0 0 1 160-160h448a160 160 0 0 1 160 160v96a32 32 0 1 1-64 0"></path>
+                    </svg>
+                    <img id="logged-in" style="display: none" alt="6"/>
                 </div>
-                <span>{1{ isLogin ? userInfo.name : "登录" }1}</span>
+                <span id="login-name">登录</span>
             </div>
 
-            <div class="login-body" style="display: none">
-                <div class="login-center" style="display: none">
+            <div class="login-body" id="login-body" style="display: none">
+                <div class="login-center" id="login-center" style="display: none">
                     <div class="login-content">
-                        <div class="login-image" :style="loginImageStyle"></div>
+                        <div class="login-image"></div>
                         <form>
                             <div class="login-from">
                                 <div class="login-select">
-                                    <div class=" login-select-item "
-                                         :class="selectType=='phone'?'select-item':''"
-                                         @click="setType('phone')">
+                                    <div class="login-select-item select-item" id="phone-tab">
                                         <span>手机号登录</span>
                                     </div>
-                                    <div class=" login-select-item "
-                                         :class="selectType=='email'?'select-item':''"
-                                         @click="setType('email')">
+                                    <div class="login-select-item select-item" id="email-tab">
                                         <span>邮箱登录</span>
                                     </div>
-                                    <div class=" login-select-item "
-                                         :class="selectType=='wx'?'select-item':''"
-                                         @click="setType('wx')">
+                                    <div class="login-select-item select-item" id="wx-tab">
                                         <span>微信扫码登录</span>
                                     </div>
-                                    <!--特效白条-->
-                                    <div class="select-item2" :style="getSelectTypeStyle()"></div>
+                                    <div class="select-item2" id="select-bar"></div>
                                 </div>
 
-                                <div class="login-type-phone" v-show="selectType=='phone'||selectType=='email'">
+                                <div class="login-type-phone" id="phone-section">
                                     <div class="login-phone">
-
                                         <div class="login-phone-input">
-                                            <input name="username" v-model="username"
-                                                   autocomplete="off"
-                                                   :placeholder="selectType=='phone'?'手机号码':'邮箱'"/>
+                                            <input name="username" id="phone-input" autocomplete="off"
+                                                   placeholder="手机号码"/>
                                         </div>
                                     </div>
-                                    <div class="login-phone-code" v-if="selectType=='phone'">
+                                    <div class="login-phone-code">
                                         <div class="login-phone-code-input">
-                                            <input name="username" v-model="password"
-                                                   autocomplete="off"
+                                            <input name="password" id="phone-code-input" autocomplete="off"
                                                    placeholder="验证码"/>
                                         </div>
-                                        <div class="login-phone-code-btn" @click="getCode()">
-                                            {1{ awaitCode > 0 ? awaitCode + 's' : '发送验证码' }1}
-                                        </div>
+                                        <div class="login-phone-code-btn" id="send-code-btn">发送验证码</div>
+                                    </div>
+                                    <div class="login-btn" id="phone-login-btn">
+                                        <div class="login-btn-div">登录</div>
                                     </div>
+                                </div>
 
-                                    <div class="login-email" v-if="selectType=='email'">
+                                <div class="login-type-email" id="email-section">
+                                    <div class="login-email">
+                                        <div class="login-email-input">
+                                            <input name="username" id="email-input" autocomplete="off"
+                                                   placeholder="邮箱"/>
+                                        </div>
                                         <div class="login-email-input">
-                                            <input name="username" v-model="password"
-                                                   autocomplete="off"
-                                                   type="password"
-                                                   placeholder="密码"/>
+                                            <input name="password" id="email-password-input" autocomplete="off"
+                                                   type="password" placeholder="密码"/>
                                         </div>
                                     </div>
-
-                                    <div class="login-btn" @click="login()">
+                                    <div class="login-btn" id="email-login-btn">
                                         <div class="login-btn-div">登录</div>
                                     </div>
                                 </div>
 
-                                <div class="login-type-wx" v-show="selectType=='wx'">
-                                    <div class="login-wx-refresh" @click="refreshWxCode()">
-                                        <div class="login-wx-refresh-icon"
-                                             style="transform: translateY(15%)">
-                                            <el-icon size="25" :class="refreshWxCodeState?'is-loading':''">
-                                                <refresh/>
-                                            </el-icon>
-                                        </div>
-                                        <div class="login-wx-refresh-text">
-                                            <span style="line-height: 25px">刷新二维码</span>
+                                <div class="login-type-wx" id="wx-section">
+                                    <div class="login-wx-refresh" id="refresh-wx-code">
+                                        <div class="login-wx-refresh-icon">
+                                            <span>刷新二维码</span>
                                         </div>
                                     </div>
                                     <div class="login-wx-tip">
@@ -123,51 +117,56 @@
                                         <span>请使用微信扫码登录</span>
                                     </div>
                                 </div>
-                                <span class="login-register-btn"
-                                      v-if="selectType!=='wx'"
-                                      @click="setShowRegister('register')">注册</span>
+
+                                <span class="login-register-btn" onclick="openLoginBody('register')">注册</span>
                             </div>
                         </form>
                     </div>
                 </div>
-                <div class="register-center" style="display: none">
-                    <div class="register-content">
+                <div id="register-center" class="register-center" style="display: none">
+                    <div class="register-content" >
                         <form>
                             <div class="register-content-title">
                                 注册
                             </div>
                             <div class="register-content-input">
-                                <k-k-c-input name="username" @binding="setUsername" :text="username"
-                                             placeholder="请输入邮箱" type="text"/>
+                                <label>
+                                    <input name="username" id="username" placeholder="请输入邮箱" type="text"/>
+                                </label>
                             </div>
                             <div class="register-content-input">
-                                <k-k-c-input name="password" @binding="setPassword" :text="password"
-                                             type="password" placeholder="请输入密码"/>
+                                <label>
+                                    <input name="password" id="password" type="password" placeholder="请输入密码"/>
+                                </label>
                             </div>
                             <div class="register-content-input">
-                                <k-k-c-input name="username" @binding="setRequirePassword" :text="requirePassword"
-                                             type="password" placeholder="请输入密码"/>
+                                <label>
+                                    <input name="requirePassword" id="requirePassword" type="password"
+                                           placeholder="请输入密码"/>
+                                </label>
                             </div>
                             <div class="register-content-input">
-                                <k-k-c-input name="username" @binding="setPhone" :text="phone"
-                                             placeholder="请输入手机号" type="text"/>
+                                <label>
+                                    <input name="phone" id="phone" placeholder="请输入手机号" type="text"/>
+                                </label>
                             </div>
                             <div class="register-content-code">
                                 <div class="register-content-code-input">
-                                    <k-k-c-input name="username" @binding="setCode" :text="code"
-                                                 placeholder="请输入手机号" type="text"/>
+                                    <label>
+                                        <input name="username" id="code" placeholder="请输入验证码" type="text"/>
+                                    </label>
                                 </div>
-                                <div class="register-content-code-btn" @click="sendCode()">
-                                    {1{ awaitCode > 0 ? awaitCode + 's' : '发送验证码' }1}
+                                <div class="register-content-code-btn" id="send-register-code">
+                                    发送验证码
                                 </div>
                             </div>
-                            <div class="register-content-submit" @click="register()">
+                            <div class="register-content-submit" id="register-btn">
                                 注册
                             </div>
                         </form>
                     </div>
                 </div>
-                <div class="login-body-shield" @click="showViewType=''"></div>
+                <div class="login-body-shield" onclick="closeLoginBody()"></div>
             </div>
         </div>
     </div>

+ 72 - 69
file/static/index.html

@@ -16,6 +16,9 @@
         <div class="nav-logo">
             <img src="../assets/image/logo.png" alt="logo" onclick="JumpRouter('/','')"/>
         </div>
+        <!--        <button onclick="setToken('eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3MTg3ODIzOTMsImlzcyI6IjEifQ.b6tID6zWsYtMKnxen0ZuGBpsSE2bpupAHYf80WsH2gQ')">-->
+        <!--            首页-->
+        <!--        </button>-->
         <!--      </router-link>-->
         <div class="nav-search">
             <form action="/search" target="_blank">
@@ -34,88 +37,77 @@
             </form>
         </div>
         <div class="nav-user">
-
             <!--                todo 头像处理-->
-            <div class="nav-user-icon" @click="openView()">
+            <div class="nav-user-icon" onclick="clickAvatar()">
                 <div class="nav-user-icon-bg">
-                    <el-icon size="24">
-                        <User/>
-                    </el-icon>
-                    <img :src="userInfo.avatar" v-else alt="6"/>
+                    <svg id="not-login" style="width: 24px;height: 24px"
+                         xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1024 1024">
+                        <path fill="currentColor"
+                              d="M512 512a192 192 0 1 0 0-384 192 192 0 0 0 0 384m0 64a256 256 0 1 1 0-512 256 256 0 0 1 0 512m320 320v-96a96 96 0 0 0-96-96H288a96 96 0 0 0-96 96v96a32 32 0 1 1-64 0v-96a160 160 0 0 1 160-160h448a160 160 0 0 1 160 160v96a32 32 0 1 1-64 0"></path>
+                    </svg>
+                    <img id="logged-in" style="display: none" alt="6"/>
                 </div>
-                <span>{1{ isLogin ? userInfo.name : "登录" }1}</span>
+                <span id="login-name">登录</span>
             </div>
 
-            <div class="login-body" style="display: none">
-                <div class="login-center" style="display: none">
+            <div class="login-body" id="login-body" style="display: none">
+                <div class="login-center" id="login-center" style="display: none">
                     <div class="login-content">
-                        <div class="login-image" :style="loginImageStyle"></div>
+                        <div class="login-image"></div>
                         <form>
                             <div class="login-from">
                                 <div class="login-select">
-                                    <div class=" login-select-item "
-                                         :class="selectType=='phone'?'select-item':''"
-                                         @click="setType('phone')">
+                                    <div class="login-select-item select-item" id="phone-tab">
                                         <span>手机号登录</span>
                                     </div>
-                                    <div class=" login-select-item "
-                                         :class="selectType=='email'?'select-item':''"
-                                         @click="setType('email')">
+                                    <div class="login-select-item select-item" id="email-tab">
                                         <span>邮箱登录</span>
                                     </div>
-                                    <div class=" login-select-item "
-                                         :class="selectType=='wx'?'select-item':''"
-                                         @click="setType('wx')">
+                                    <div class="login-select-item select-item" id="wx-tab">
                                         <span>微信扫码登录</span>
                                     </div>
-                                    <!--特效白条-->
-                                    <div class="select-item2" :style="getSelectTypeStyle()"></div>
+                                    <div class="select-item2" id="select-bar"></div>
                                 </div>
 
-                                <div class="login-type-phone" v-show="selectType=='phone'||selectType=='email'">
+                                <div class="login-type-phone" id="phone-section">
                                     <div class="login-phone">
-
                                         <div class="login-phone-input">
-                                            <input name="username" v-model="username"
-                                                   autocomplete="off"
-                                                   :placeholder="selectType=='phone'?'手机号码':'邮箱'"/>
+                                            <input name="username" id="phone-input" autocomplete="off"
+                                                   placeholder="手机号码"/>
                                         </div>
                                     </div>
-                                    <div class="login-phone-code" v-if="selectType=='phone'">
+                                    <div class="login-phone-code">
                                         <div class="login-phone-code-input">
-                                            <input name="username" v-model="password"
-                                                   autocomplete="off"
+                                            <input name="password" id="phone-code-input" autocomplete="off"
                                                    placeholder="验证码"/>
                                         </div>
-                                        <div class="login-phone-code-btn" @click="getCode()">
-                                            {1{ awaitCode > 0 ? awaitCode + 's' : '发送验证码' }1}
-                                        </div>
+                                        <div class="login-phone-code-btn" id="send-code-btn">发送验证码</div>
                                     </div>
+                                    <div class="login-btn" id="phone-login-btn">
+                                        <div class="login-btn-div">登录</div>
+                                    </div>
+                                </div>
 
-                                    <div class="login-email" v-if="selectType=='email'">
+                                <div class="login-type-email" id="email-section">
+                                    <div class="login-email">
                                         <div class="login-email-input">
-                                            <input name="username" v-model="password"
-                                                   autocomplete="off"
-                                                   type="password"
-                                                   placeholder="密码"/>
+                                            <input name="username" id="email-input" autocomplete="off"
+                                                   placeholder="邮箱"/>
+                                        </div>
+                                        <div class="login-email-input">
+                                            <input name="password" id="email-password-input" autocomplete="off"
+                                                   type="password" placeholder="密码"/>
                                         </div>
                                     </div>
-
-                                    <div class="login-btn" @click="login()">
+                                    <div class="login-btn" id="email-login-btn">
                                         <div class="login-btn-div">登录</div>
                                     </div>
                                 </div>
 
-                                <div class="login-type-wx" v-show="selectType=='wx'">
-                                    <div class="login-wx-refresh" @click="refreshWxCode()">
-                                        <div class="login-wx-refresh-icon"
-                                             style="transform: translateY(15%)">
-                                            <el-icon size="25" :class="refreshWxCodeState?'is-loading':''">
-                                                <refresh/>
-                                            </el-icon>
-                                        </div>
-                                        <div class="login-wx-refresh-text">
-                                            <span style="line-height: 25px">刷新二维码</span>
+                                <div class="login-type-wx" id="wx-section">
+                                    <div class="login-wx-refresh" id="refresh-wx-code">
+                                        <div class="login-wx-refresh-icon">
+                                            <span>刷新二维码</span>
                                         </div>
                                     </div>
                                     <div class="login-wx-tip">
@@ -126,51 +118,56 @@
                                         <span>请使用微信扫码登录</span>
                                     </div>
                                 </div>
-                                <span class="login-register-btn"
-                                      v-if="selectType!=='wx'"
-                                      @click="setShowRegister('register')">注册</span>
+
+                                <span class="login-register-btn" onclick="openLoginBody('register')">注册</span>
                             </div>
                         </form>
                     </div>
                 </div>
-                <div class="register-center" style="display: none">
-                    <div class="register-content">
+                <div id="register-center" class="register-center" style="display: none">
+                    <div class="register-content" >
                         <form>
                             <div class="register-content-title">
                                 注册
                             </div>
                             <div class="register-content-input">
-                                <k-k-c-input name="username" @binding="setUsername" :text="username"
-                                             placeholder="请输入邮箱" type="text"/>
+                                <label>
+                                    <input name="username" id="username" placeholder="请输入邮箱" type="text"/>
+                                </label>
                             </div>
                             <div class="register-content-input">
-                                <k-k-c-input name="password" @binding="setPassword" :text="password"
-                                             type="password" placeholder="请输入密码"/>
+                                <label>
+                                    <input name="password" id="password" type="password" placeholder="请输入密码"/>
+                                </label>
                             </div>
                             <div class="register-content-input">
-                                <k-k-c-input name="username" @binding="setRequirePassword" :text="requirePassword"
-                                             type="password" placeholder="请输入密码"/>
+                                <label>
+                                    <input name="requirePassword" id="requirePassword" type="password"
+                                           placeholder="请输入密码"/>
+                                </label>
                             </div>
                             <div class="register-content-input">
-                                <k-k-c-input name="username" @binding="setPhone" :text="phone"
-                                             placeholder="请输入手机号" type="text"/>
+                                <label>
+                                    <input name="phone" id="phone" placeholder="请输入手机号" type="text"/>
+                                </label>
                             </div>
                             <div class="register-content-code">
                                 <div class="register-content-code-input">
-                                    <k-k-c-input name="username" @binding="setCode" :text="code"
-                                                 placeholder="请输入手机号" type="text"/>
+                                    <label>
+                                        <input name="username" id="code" placeholder="请输入验证码" type="text"/>
+                                    </label>
                                 </div>
-                                <div class="register-content-code-btn" @click="sendCode()">
-                                    {1{ awaitCode > 0 ? awaitCode + 's' : '发送验证码' }1}
+                                <div class="register-content-code-btn" id="send-register-code">
+                                    发送验证码
                                 </div>
                             </div>
-                            <div class="register-content-submit" @click="register()">
+                            <div class="register-content-submit" id="register-btn">
                                 注册
                             </div>
                         </form>
                     </div>
                 </div>
-                <div class="login-body-shield" @click="showViewType=''"></div>
+                <div class="login-body-shield" onclick="closeLoginBody()"></div>
             </div>
         </div>
     </div>
@@ -579,5 +576,11 @@
 
 </div>
 </body>
-<script src="../assets/js/index.js" defer></script>
+<script src="../assets/js/index.js"></script>
+
+<script>
+    window.onload = function () {
+        handler.GetUserInfo()
+    }
+</script>
 </html>

+ 67 - 68
file/static/topic.html

@@ -5,14 +5,19 @@
     <title>Topic</title>
     <link rel="stylesheet" href="../assets/css/index.css">
     <link rel="stylesheet" href="../assets/css/topic.css">
+    <script src="../assets/js/handler.js"></script>
 </head>
 <body>
+
 <div class="navigation-bar">
     <div class="nav-body">
         <!--      <router-link to="/" class="nav-logo">-->
         <div class="nav-logo">
             <img src="../assets/image/logo.png" alt="logo" onclick="JumpRouter('/','')"/>
         </div>
+        <!--        <button onclick="setToken('eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3MTg3ODIzOTMsImlzcyI6IjEifQ.b6tID6zWsYtMKnxen0ZuGBpsSE2bpupAHYf80WsH2gQ')">-->
+        <!--            首页-->
+        <!--        </button>-->
         <!--      </router-link>-->
         <div class="nav-search">
             <form action="/search" target="_blank">
@@ -31,88 +36,77 @@
             </form>
         </div>
         <div class="nav-user">
-
             <!--                todo 头像处理-->
-            <div class="nav-user-icon" @click="openView()">
+            <div class="nav-user-icon" onclick="clickAvatar()">
                 <div class="nav-user-icon-bg">
-                    <el-icon size="24">
-                        <User/>
-                    </el-icon>
-                    <img :src="userInfo.avatar" v-else alt="6"/>
+                    <svg id="not-login" style="width: 24px;height: 24px"
+                         xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1024 1024">
+                        <path fill="currentColor"
+                              d="M512 512a192 192 0 1 0 0-384 192 192 0 0 0 0 384m0 64a256 256 0 1 1 0-512 256 256 0 0 1 0 512m320 320v-96a96 96 0 0 0-96-96H288a96 96 0 0 0-96 96v96a32 32 0 1 1-64 0v-96a160 160 0 0 1 160-160h448a160 160 0 0 1 160 160v96a32 32 0 1 1-64 0"></path>
+                    </svg>
+                    <img id="logged-in" style="display: none" alt="6"/>
                 </div>
-                <span>{1{ isLogin ? userInfo.name : "登录" }1}</span>
+                <span id="login-name">登录</span>
             </div>
 
-            <div class="login-body" style="display: none">
-                <div class="login-center" style="display: none">
+            <div class="login-body" id="login-body" style="display: none">
+                <div class="login-center" id="login-center" style="display: none">
                     <div class="login-content">
-                        <div class="login-image" :style="loginImageStyle"></div>
+                        <div class="login-image"></div>
                         <form>
                             <div class="login-from">
                                 <div class="login-select">
-                                    <div class=" login-select-item "
-                                         :class="selectType=='phone'?'select-item':''"
-                                         @click="setType('phone')">
+                                    <div class="login-select-item select-item" id="phone-tab">
                                         <span>手机号登录</span>
                                     </div>
-                                    <div class=" login-select-item "
-                                         :class="selectType=='email'?'select-item':''"
-                                         @click="setType('email')">
+                                    <div class="login-select-item select-item" id="email-tab">
                                         <span>邮箱登录</span>
                                     </div>
-                                    <div class=" login-select-item "
-                                         :class="selectType=='wx'?'select-item':''"
-                                         @click="setType('wx')">
+                                    <div class="login-select-item select-item" id="wx-tab">
                                         <span>微信扫码登录</span>
                                     </div>
-                                    <!--特效白条-->
-                                    <div class="select-item2" :style="getSelectTypeStyle()"></div>
+                                    <div class="select-item2" id="select-bar"></div>
                                 </div>
 
-                                <div class="login-type-phone" v-show="selectType=='phone'||selectType=='email'">
+                                <div class="login-type-phone" id="phone-section">
                                     <div class="login-phone">
-
                                         <div class="login-phone-input">
-                                            <input name="username" v-model="username"
-                                                   autocomplete="off"
-                                                   :placeholder="selectType=='phone'?'手机号码':'邮箱'"/>
+                                            <input name="username" id="phone-input" autocomplete="off"
+                                                   placeholder="手机号码"/>
                                         </div>
                                     </div>
-                                    <div class="login-phone-code" v-if="selectType=='phone'">
+                                    <div class="login-phone-code">
                                         <div class="login-phone-code-input">
-                                            <input name="username" v-model="password"
-                                                   autocomplete="off"
+                                            <input name="password" id="phone-code-input" autocomplete="off"
                                                    placeholder="验证码"/>
                                         </div>
-                                        <div class="login-phone-code-btn" @click="getCode()">
-                                            {1{ awaitCode > 0 ? awaitCode + 's' : '发送验证码' }1}
-                                        </div>
+                                        <div class="login-phone-code-btn" id="send-code-btn">发送验证码</div>
+                                    </div>
+                                    <div class="login-btn" id="phone-login-btn">
+                                        <div class="login-btn-div">登录</div>
                                     </div>
+                                </div>
 
-                                    <div class="login-email" v-if="selectType=='email'">
+                                <div class="login-type-email" id="email-section">
+                                    <div class="login-email">
+                                        <div class="login-email-input">
+                                            <input name="username" id="email-input" autocomplete="off"
+                                                   placeholder="邮箱"/>
+                                        </div>
                                         <div class="login-email-input">
-                                            <input name="username" v-model="password"
-                                                   autocomplete="off"
-                                                   type="password"
-                                                   placeholder="密码"/>
+                                            <input name="password" id="email-password-input" autocomplete="off"
+                                                   type="password" placeholder="密码"/>
                                         </div>
                                     </div>
-
-                                    <div class="login-btn" @click="login()">
+                                    <div class="login-btn" id="email-login-btn">
                                         <div class="login-btn-div">登录</div>
                                     </div>
                                 </div>
 
-                                <div class="login-type-wx" v-show="selectType=='wx'">
-                                    <div class="login-wx-refresh" @click="refreshWxCode()">
-                                        <div class="login-wx-refresh-icon"
-                                             style="transform: translateY(15%)">
-                                            <el-icon size="25" :class="refreshWxCodeState?'is-loading':''">
-                                                <refresh/>
-                                            </el-icon>
-                                        </div>
-                                        <div class="login-wx-refresh-text">
-                                            <span style="line-height: 25px">刷新二维码</span>
+                                <div class="login-type-wx" id="wx-section">
+                                    <div class="login-wx-refresh" id="refresh-wx-code">
+                                        <div class="login-wx-refresh-icon">
+                                            <span>刷新二维码</span>
                                         </div>
                                     </div>
                                     <div class="login-wx-tip">
@@ -123,51 +117,56 @@
                                         <span>请使用微信扫码登录</span>
                                     </div>
                                 </div>
-                                <span class="login-register-btn"
-                                      v-if="selectType!=='wx'"
-                                      @click="setShowRegister('register')">注册</span>
+
+                                <span class="login-register-btn" onclick="openLoginBody('register')">注册</span>
                             </div>
                         </form>
                     </div>
                 </div>
-                <div class="register-center" style="display: none">
-                    <div class="register-content">
+                <div id="register-center" class="register-center" style="display: none">
+                    <div class="register-content" >
                         <form>
                             <div class="register-content-title">
                                 注册
                             </div>
                             <div class="register-content-input">
-                                <k-k-c-input name="username" @binding="setUsername" :text="username"
-                                             placeholder="请输入邮箱" type="text"/>
+                                <label>
+                                    <input name="username" id="username" placeholder="请输入邮箱" type="text"/>
+                                </label>
                             </div>
                             <div class="register-content-input">
-                                <k-k-c-input name="password" @binding="setPassword" :text="password"
-                                             type="password" placeholder="请输入密码"/>
+                                <label>
+                                    <input name="password" id="password" type="password" placeholder="请输入密码"/>
+                                </label>
                             </div>
                             <div class="register-content-input">
-                                <k-k-c-input name="username" @binding="setRequirePassword" :text="requirePassword"
-                                             type="password" placeholder="请输入密码"/>
+                                <label>
+                                    <input name="requirePassword" id="requirePassword" type="password"
+                                           placeholder="请输入密码"/>
+                                </label>
                             </div>
                             <div class="register-content-input">
-                                <k-k-c-input name="username" @binding="setPhone" :text="phone"
-                                             placeholder="请输入手机号" type="text"/>
+                                <label>
+                                    <input name="phone" id="phone" placeholder="请输入手机号" type="text"/>
+                                </label>
                             </div>
                             <div class="register-content-code">
                                 <div class="register-content-code-input">
-                                    <k-k-c-input name="username" @binding="setCode" :text="code"
-                                                 placeholder="请输入手机号" type="text"/>
+                                    <label>
+                                        <input name="username" id="code" placeholder="请输入验证码" type="text"/>
+                                    </label>
                                 </div>
-                                <div class="register-content-code-btn" @click="sendCode()">
-                                    {1{ awaitCode > 0 ? awaitCode + 's' : '发送验证码' }1}
+                                <div class="register-content-code-btn" id="send-register-code">
+                                    发送验证码
                                 </div>
                             </div>
-                            <div class="register-content-submit" @click="register()">
+                            <div class="register-content-submit" id="register-btn">
                                 注册
                             </div>
                         </form>
                     </div>
                 </div>
-                <div class="login-body-shield" @click="showViewType=''"></div>
+                <div class="login-body-shield" onclick="closeLoginBody()"></div>
             </div>
         </div>
     </div>

+ 54 - 55
router/TestRouter.go

@@ -1,7 +1,6 @@
 package router
 
 import (
-	"demo/configs"
 	"demo/data/dao"
 	"demo/data/dao/manage"
 	"demo/data/domain"
@@ -53,24 +52,24 @@ func DataTest(c *gin.Context) {
 func Home(c *gin.Context) {
 	m := make(map[string]interface{})
 	//获取登录信息
-	id := GetUserId(c)
-	if id != 0 {
-		var userInfo = domain.User{}
-		_, err := configs.Engine.Table("user").Where("id = ?", id).Get(&userInfo)
-		if err != nil {
-			c.JSON(200, CreateResultError(401, "用户信息查询失败"))
-			return
-		}
-		userInfoMap := map[string]interface{}{
-			"userInfo": userInfo,
-		}
-		u, err := json.Marshal(userInfoMap)
-		if err != nil {
-			c.JSON(200, CreateResultError(401, "用户查询失败"))
-			return
-		}
-		json.Unmarshal(u, &m)
-	}
+	/*	id := GetUserId(c)
+		if id != 0 {
+			var userInfo = domain.User{}
+			_, err := configs.Engine.Table("user").Where("id = ?", id).Get(&userInfo)
+			if err != nil {
+				c.JSON(200, CreateResultError(401, "用户信息查询失败"))
+				return
+			}
+			userInfoMap := map[string]interface{}{
+				"userInfo": userInfo,
+			}
+			u, err := json.Marshal(userInfoMap)
+			if err != nil {
+				c.JSON(200, CreateResultError(401, "用户查询失败"))
+				return
+			}
+			json.Unmarshal(u, &m)
+		}*/
 	//首页宣传信息
 	data, err := dao.GetAdviceData()
 	if err != nil {
@@ -111,24 +110,24 @@ func Topic(c *gin.Context) {
 	topicId := c.Query("topicId")
 	m := make(map[string]interface{})
 	//获取登录信息
-	id := GetUserId(c)
-	if id != 0 {
-		var userInfo = domain.User{}
-		_, err := configs.Engine.Table("user").Where("id = ?", id).Get(&userInfo)
-		if err != nil {
-			c.JSON(200, CreateResultError(401, "用户信息查询失败"))
-			return
-		}
-		userInfoMap := map[string]interface{}{
-			"userInfo": userInfo,
-		}
-		u, err := json.Marshal(userInfoMap)
-		if err != nil {
-			c.JSON(200, CreateResultError(401, "用户查询失败"))
-			return
-		}
-		json.Unmarshal(u, &m)
-	}
+	/*	id := GetUserId(c)
+		if id != 0 {
+			var userInfo = domain.User{}
+			_, err := configs.Engine.Table("user").Where("id = ?", id).Get(&userInfo)
+			if err != nil {
+				c.JSON(200, CreateResultError(401, "用户信息查询失败"))
+				return
+			}
+			userInfoMap := map[string]interface{}{
+				"userInfo": userInfo,
+			}
+			u, err := json.Marshal(userInfoMap)
+			if err != nil {
+				c.JSON(200, CreateResultError(401, "用户查询失败"))
+				return
+			}
+			json.Unmarshal(u, &m)
+		}*/
 	list, err := dao.GetTopicPageDataListById(cast.ToInt64(topicId))
 	if err != nil {
 		c.JSON(200, CreateResultError(401, "主题列表查询失败"))
@@ -148,24 +147,24 @@ func Detail(c *gin.Context) {
 	skuId := c.Query("skuId")
 	m := make(map[string]interface{})
 	//获取登录信息
-	id := GetUserId(c)
-	if id != 0 {
-		var userInfo = domain.User{}
-		_, err := configs.Engine.Table("user").Where("id = ?", id).Get(&userInfo)
-		if err != nil {
-			c.JSON(200, CreateResultError(401, "用户信息查询失败"))
-			return
-		}
-		userInfoMap := map[string]interface{}{
-			"userInfo": userInfo,
-		}
-		u, err := json.Marshal(userInfoMap)
-		if err != nil {
-			c.JSON(200, CreateResultError(401, "用户查询失败"))
-			return
-		}
-		json.Unmarshal(u, &m)
-	}
+	/*	id := GetUserId(c)
+		if id != 0 {
+			var userInfo = domain.User{}
+			_, err := configs.Engine.Table("user").Where("id = ?", id).Get(&userInfo)
+			if err != nil {
+				c.JSON(200, CreateResultError(401, "用户信息查询失败"))
+				return
+			}
+			userInfoMap := map[string]interface{}{
+				"userInfo": userInfo,
+			}
+			u, err := json.Marshal(userInfoMap)
+			if err != nil {
+				c.JSON(200, CreateResultError(401, "用户查询失败"))
+				return
+			}
+			json.Unmarshal(u, &m)
+		}*/
 	//标签
 	tagList, err := manage.GetGoodsTagList(domain.GoodsTag{}, 1, 10000)
 	if err != nil {

+ 131 - 70
router/UserRouter.go

@@ -23,28 +23,6 @@ import (
 
 func UserRouth(engine *gin.RouterGroup) {
 	user := engine.Group("/user")
-	//{
-	//	//获取用户基本信息
-	//	user.GET("/info", GetUserInfo)
-	//	//获取用户钱包
-	//	user.GET("/wallet", GetUserWallet)
-	//	//修改名字
-	//	user.PUT("/name", SetNameValue)
-	//	//获取用户的订单信息
-	//	user.POST("/order", GetUserOrder)
-	//	//用户登录
-	//	user.POST("/login", login)
-	//	//注册
-	//	user.POST("/register", register)
-	//
-	//	//发送邮箱注册验证码
-	//	user.POST("/registerCode", registerCode)
-	//	//发送验证码
-	//	user.POST("/sendSms", SendVerificationCode)
-	//	//图片验证码
-	//	user.GET("/captcha", VerificationCode)
-	//}
-	//获取用户基本信息
 
 	PushRouter(user, "GET", "/info", GetUserInfo)
 	//获取用户钱包
@@ -55,18 +33,66 @@ func UserRouth(engine *gin.RouterGroup) {
 	PushRouter(user, "POST", "/order", GetUserOrder)
 	//用户登录
 	PushRouter(user, "POST", "/login", login)
+	//发送手机验证码 ,模拟
+	PushRouter(user, "POST", "/loginCode", SendPhoneCode)
+
 	//注册
 	PushRouter(user, "POST", "/register", register)
 	//发送邮箱注册验证码
 	PushRouter(user, "POST", "/registerCode", registerCode)
-	//发送验证码
-	PushRouter(user, "POST", "/sendSms", SendVerificationCode)
+
 	//图片验证码
 	PushRouter(user, "GET", "/captcha", VerificationCode)
+	//发送验证码
+	PushRouter(user, "POST", "/sendSms", SendLoginVerificationCode)
 	PushRouter(user, "GET", "/base/info", GetUserBaseInfo)
 	PushRouter(user, "POST", "/base/info", GetUserBaseInfoList)
 }
 
+func SendPhoneCode(c *gin.Context) {
+	data := share.GetJsonAnyParam(c)
+	var err error
+	phone, _ := data("phone")
+	if phone == "" {
+		c.JSON(200, CreateResultError(401, "参数不全"))
+		return
+	}
+	// 定义正则表达式
+	regexPattern := `^1[3-9][0-9]{9}$`
+
+	// 编译正则表达式
+	reg, err := regexp.Compile(regexPattern)
+	if err != nil {
+		fmt.Println("Error compiling regex:", err)
+		return
+	}
+	matched := reg.MatchString(cast.ToString(phone))
+	if !matched {
+		c.JSON(200, CreateResultError(401, "手机号格式错误"))
+		return
+	}
+	user, err := dao.GetUserByPhone(cast.ToString(phone))
+	if err != nil {
+		c.JSON(200, CreateResultError(401, "手机号未绑定邮箱"))
+		return
+	}
+	//user.Email
+	code := testSendMail(user.Email)
+	//查看是否已经发送过验证码了
+	exists := configs.RedisDb.Exists(ctx, "PhoneLoginVerificationCodeTime_"+cast.ToString(phone))
+	if exists.Val() == 1 {
+		c.JSON(http.StatusOK, CreateResultError(200, "验证码已经发送,请等待"))
+		return
+	}
+	set := configs.RedisDb.Set(ctx, "PhoneLoginVerificationCode_"+cast.ToString(phone), code, 5*60*time.Second)
+	configs.RedisDb.Set(ctx, "PhoneLoginVerificationCodeTime_"+cast.ToString(phone), code, 60*time.Second)
+	if set.Err() != nil {
+		c.JSON(200, CreateResultError(401, "发送失败"))
+		return
+	}
+	c.JSON(200, CreateResult())
+}
+
 func GetUserBaseInfo(c *gin.Context) {
 	id := c.Query("userId")
 	if id == "" {
@@ -116,7 +142,7 @@ func GetUserBaseInfoList(c *gin.Context) {
 // GetUserInfo 获取用户的个人信息
 func GetUserInfo(c *gin.Context) {
 	header := c.GetHeader("auth-sign")
-	if header == "" {
+	if header == "" || header == "null" {
 		c.JSON(200, CreateResultError(401, "用户未登录"))
 		return
 	}
@@ -191,6 +217,7 @@ func GetUserOrder(c *gin.Context) {
 	c.JSON(200, CreateResultData(vo))
 }
 
+// VerificationCode 图片验证码
 func VerificationCode(c *gin.Context) {
 	// 配置
 	driver := base64Captcha.NewDriverDigit(80, 240, 4, 0.5, 80)
@@ -224,7 +251,6 @@ func VerificationCode(c *gin.Context) {
 func login(c *gin.Context) {
 	data := share.GetJsonAnyParam(c)
 	var user domain.User
-	var err error
 	username, _ := data("username")
 	password, _ := data("password")
 	t, _ := data("type")
@@ -246,6 +272,22 @@ func login(c *gin.Context) {
 			c.JSON(http.StatusOK, CreateResultError(400, "邮箱格式错误!!!"))
 			return
 		}
+		user, err = dao.Logins(cast.ToString(username), cast.ToString(password), cast.ToString(t))
+
+		if err == nil && user.Id != 0 {
+			fmt.Println("用户登录成功!!!")
+			token, err := share.GenerateToken(cast.ToString(user.Id))
+			if err == nil {
+				c.Header("auth-sign", token)
+				c.JSON(http.StatusOK, CreateResultData(map[string]string{"token": token}))
+			} else {
+				c.JSON(http.StatusOK, CreateResultError(400, "生成token失败!!!"))
+			}
+		} else {
+			fmt.Println("用户登录失败!!!")
+			c.JSON(http.StatusOK, CreateResultError(401, "用户密码错误!!!"))
+		}
+		return
 	} else if cast.ToString(t) == "phone" {
 		regexPattern := `^1[3-9]\d{9}$`
 		// 编译正则表达式
@@ -262,23 +304,38 @@ func login(c *gin.Context) {
 			c.JSON(http.StatusOK, CreateResultError(400, "手机格式错误!!!"))
 			return
 		}
-	}
-
-	user, err = dao.Logins(cast.ToString(username), cast.ToString(password), cast.ToString(t))
-
-	if err == nil && user.Id != 0 {
-		fmt.Println("用户登录成功!!!")
-		token, err := share.GenerateToken(cast.ToString(user.Id))
-		if err == nil {
-			c.Header("auth-sign", token)
-			c.JSON(http.StatusOK, CreateResultData(map[string]string{"token": token}))
+		//获取用户数据
+		user, err := dao.GetUserByPhone(cast.ToString(username))
+		if err != nil {
+			fmt.Println(err)
+			c.JSON(http.StatusOK, CreateResultError(400, "用户未绑定邮箱"))
+		}
+		//发送邮件
+		result, err := configs.RedisDb.Get(ctx, "PhoneLoginVerificationCode_"+user.Phone).Result()
+		if err != nil {
+			fmt.Println(err)
+			c.JSON(http.StatusOK, CreateResultError(400, "验证码已过期"))
+			return
+		}
+		if result == cast.ToString(password) {
+			configs.RedisDb.Del(ctx, "PhoneLoginVerificationCode_"+user.Phone)
+			//登录成功
+			fmt.Println("用户登录成功!!!")
+			token, err := share.GenerateToken(cast.ToString(user.Id))
+			if err == nil {
+				c.Header("auth-sign", token)
+				c.JSON(http.StatusOK, CreateResultData(map[string]string{"token": token}))
+				return
+			} else {
+				c.JSON(http.StatusOK, CreateResultError(400, "生成token失败!!!"))
+				return
+			}
 		} else {
-			c.JSON(http.StatusOK, CreateResultError(400, "生成token失败!!!"))
+			c.JSON(http.StatusOK, CreateResultError(400, "验证码错误!!!"))
+			return
 		}
-	} else {
-		fmt.Println("用户登录失败!!!")
-		c.JSON(http.StatusOK, CreateResultError(401, "用户密码错误!!!"))
 	}
+	c.JSON(http.StatusOK, CreateResultError(400, "未知错误!!!"))
 }
 
 func registerCode(c *gin.Context) {
@@ -445,6 +502,40 @@ func register(c *gin.Context) {
 	}
 }
 
+// SendLoginVerificationCode 发送手机验证码,模拟邮箱验证码
+func SendLoginVerificationCode(c *gin.Context) {
+	data := share.GetJsonAnyParam(c)
+	var err error
+	username, _ := data("username")
+	code, _ := data("code")
+	codeId, _ := data("codeId")
+	val, err := configs.RedisDb.Get(ctx, cast.ToString(codeId)).Result()
+	if err != nil {
+		log.Fatal(err)
+	}
+	if val != cast.ToString(code) {
+		c.JSON(200, gin.H{"code": 400, "message": "验证码错误!!!"})
+		c.Abort()
+		return
+	}
+	// 定义正则表达式
+	regexPattern := `^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$`
+
+	// 编译正则表达式
+	reg, err := regexp.Compile(regexPattern)
+	if err != nil {
+		fmt.Println("Error compiling regex:", err)
+		return
+	}
+	matched := reg.MatchString(cast.ToString(username))
+	dao.SendSms(matched, cast.ToString(username))
+	c.JSON(200, gin.H{"code": 200, "message": "发送成功!!!"})
+}
+
+//==================================================================================================
+//==================================================================================================
+//==================================================================================================
+
 func checkEmail(c *gin.Context, email string) bool {
 	//// 定义正则表达式
 	regexPattern := `^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$`
@@ -517,33 +608,3 @@ func checkCode(c *gin.Context, code string) bool {
 
 	return true
 }
-
-// SendVerificationCode 发送验证码
-func SendVerificationCode(c *gin.Context) {
-	data := share.GetJsonAnyParam(c)
-	var err error
-	username, _ := data("username")
-	code, _ := data("code")
-	codeId, _ := data("codeId")
-	val, err := configs.RedisDb.Get(ctx, cast.ToString(codeId)).Result()
-	if err != nil {
-		log.Fatal(err)
-	}
-	if val != cast.ToString(code) {
-		c.JSON(200, gin.H{"code": 400, "message": "验证码错误!!!"})
-		c.Abort()
-		return
-	}
-	// 定义正则表达式
-	regexPattern := `^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$`
-
-	// 编译正则表达式
-	reg, err := regexp.Compile(regexPattern)
-	if err != nil {
-		fmt.Println("Error compiling regex:", err)
-		return
-	}
-	matched := reg.MatchString(cast.ToString(username))
-	dao.SendSms(matched, cast.ToString(username))
-	c.JSON(200, gin.H{"code": 200, "message": "发送成功!!!"})
-}