前端登陸註冊頁面

01.前端登陸註冊頁面


1、vue後端地址配置

  1. 在vue項目的assets/js/settings.js前端

    export default {
      BASE_URL:'http://127.0.0.1:8000/'
    }
  2. main.js中導入vue

    import settings from './assets/js/settings'
    Vue.prototype.$BASE_URL=settings.BASE_URL
  3. 在組件中直接使用python

    this.$$BASE_URL

2、media_url的做用

1.只要是數據庫中文件,圖片,配置這個
	media_url='/media/'
2.序列化字段(文件,圖片)
	-當前域+/media/+數據庫中存的路徑

3、模態登陸組件

<template>
    <div class="login">
        <div class="box">
            <i class="el-icon-close" @click="close_login"></i>
            <div class="content">
                <div class="nav">
                    <span :class="{active: login_method === 'is_pwd'}"
                          @click="change_login_method('is_pwd')">密碼登陸</span>
                    <span :class="{active: login_method === 'is_sms'}"
                          @click="change_login_method('is_sms')">短信登陸</span>
                </div>
                <el-form v-if="login_method === 'is_pwd'">
                    <el-input
                            placeholder="用戶名/手機號/郵箱"
                            prefix-icon="el-icon-user"
                            v-model="username"
                            clearable>
                    </el-input>
                    <el-input
                            placeholder="密碼"
                            prefix-icon="el-icon-key"
                            v-model="password"
                            clearable
                            show-password>
                    </el-input>
                    <el-button type="primary">登陸</el-button>
                </el-form>
                <el-form v-if="login_method === 'is_sms'">
                    <el-input
                            placeholder="手機號"
                            prefix-icon="el-icon-phone-outline"
                            v-model="mobile"
                            clearable
                            @blur="check_mobile">
                    </el-input>
                    <el-input
                            placeholder="驗證碼"
                            prefix-icon="el-icon-chat-line-round"
                            v-model="sms"
                            clearable>
                        <template slot="append">
                            <span class="sms" @click="send_sms">{{ sms_interval }}</span>
                        </template>
                    </el-input>
                    <el-button type="primary">登陸</el-button>
                </el-form>
                <div class="foot">
                    <span @click="go_register">當即註冊</span>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
    export default {
        name: "Login",
        data() {
            return {
                username: '',
                password: '',
                mobile: '',
                sms: '',
                login_method: 'is_pwd',
                sms_interval: '獲取驗證碼',
                is_send: false,
            }
        },
        methods: {
            close_login() {
                this.$emit('close')
            },
            go_register() {
                this.$emit('go')
            },
            change_login_method(method) {
                this.login_method = method;
            },
            check_mobile() {
                if (!this.mobile) return;
                if (!this.mobile.match(/^1[3-9][0-9]{9}$/)) {
                    this.$message({
                        message: '手機號有誤',
                        type: 'warning',
                        duration: 1000,
                        onClose: () => {
                            this.mobile = '';
                        }
                    });
                    return false;
                }
                this.is_send = true;
            },
            send_sms() {

                if (!this.is_send) return;
                this.is_send = false;
                let sms_interval_time = 60;
                this.sms_interval = "發送中...";
                let timer = setInterval(() => {
                    if (sms_interval_time <= 1) {
                        clearInterval(timer);
                        this.sms_interval = "獲取驗證碼";
                        this.is_send = true; // 從新回覆點擊發送功能的條件
                    } else {
                        sms_interval_time -= 1;
                        this.sms_interval = `${sms_interval_time}秒後再發`;
                    }
                }, 1000);
            }
        }
    }
</script>

<style scoped>
    .login {
        width: 100vw;
        height: 100vh;
        position: fixed;
        top: 0;
        left: 0;
        z-index: 10;
        background-color: rgba(0, 0, 0, 0.3);
    }

    .box {
        width: 400px;
        height: 420px;
        background-color: white;
        border-radius: 10px;
        position: relative;
        top: calc(50vh - 210px);
        left: calc(50vw - 200px);
    }

    .el-icon-close {
        position: absolute;
        font-weight: bold;
        font-size: 20px;
        top: 10px;
        right: 10px;
        cursor: pointer;
    }

    .el-icon-close:hover {
        color: darkred;
    }

    .content {
        position: absolute;
        top: 40px;
        width: 280px;
        left: 60px;
    }

    .nav {
        font-size: 20px;
        height: 38px;
        border-bottom: 2px solid darkgrey;
    }

    .nav > span {
        margin: 0 20px 0 35px;
        color: darkgrey;
        user-select: none;
        cursor: pointer;
        padding-bottom: 10px;
        border-bottom: 2px solid darkgrey;
    }

    .nav > span.active {
        color: black;
        border-bottom: 3px solid black;
        padding-bottom: 9px;
    }

    .el-input, .el-button {
        margin-top: 40px;
    }

    .el-button {
        width: 100%;
        font-size: 18px;
    }

    .foot > span {
        float: right;
        margin-top: 20px;
        color: orange;
        cursor: pointer;
    }

    .sms {
        color: orange;
        cursor: pointer;
        display: inline-block;
        width: 70px;
        text-align: center;
        user-select: none;
    }
</style>

流程:

1. components中新建Login.vue文件, 寫入如上代碼
2. components中的Header.vue中. 導入組件, 註冊組件, 使用組件
3. 登陸註冊綁定點擊事件, 爲Login組件使用條件渲染指令v-if, 指定一個值is_login控制Login組件的展現狀態. 
    在點擊登陸按鈕時is_login爲True
    在點擊登陸組件中×時, Login組件應該控制傳遞數據, 控制父組件的展現或者隱藏. 子組件對×綁定事件的傳遞this.$emit('close')
5. 父組件中的Login組件中獲取到傳遞過來的事件@close. 綁定一個父組件中的觸發該事的方法, 一當該事件觸發, 表示用戶×了登陸界面. 此時is_login因該爲false.

4、模態註冊組件

<template>
    <div class="register">
        <div class="box">
            <i class="el-icon-close" @click="close_register"></i>
            <div class="content">
                <div class="nav">
                    <span class="active">新用戶註冊</span>
                </div>
                <el-form>
                    <el-input
                            placeholder="手機號"
                            prefix-icon="el-icon-phone-outline"
                            v-model="mobile"
                            clearable
                            @blur="check_mobile">
                    </el-input>
                    <el-input
                            placeholder="密碼"
                            prefix-icon="el-icon-key"
                            v-model="password"
                            clearable
                            show-password>
                    </el-input>
                    <el-input
                            placeholder="驗證碼"
                            prefix-icon="el-icon-chat-line-round"
                            v-model="sms"
                            clearable>
                        <template slot="append">
                            <span class="sms" @click="send_sms">{{ sms_interval }}</span>
                        </template>
                    </el-input>
                    <el-button type="primary">註冊</el-button>
                </el-form>
                <div class="foot">
                    <span @click="go_login">當即登陸</span>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
    export default {
        name: "Register",
        data() {
            return {
                mobile: '',
                password: '',
                sms: '',
                sms_interval: '獲取驗證碼',
                is_send: false,
            }
        },
        methods: {
            close_register() {
                this.$emit('close', false)
            },
            go_login() {
                this.$emit('go')
            },
            check_mobile() {
                if (!this.mobile) return;
                if (!this.mobile.match(/^1[3-9][0-9]{9}$/)) {
                    this.$message({
                        message: '手機號有誤',
                        type: 'warning',
                        duration: 1000,
                        onClose: () => {
                            this.mobile = '';
                        }
                    });
                    return false;
                }
                this.is_send = true;
            },
            send_sms() {
                if (!this.is_send) return;
                this.is_send = false;
                let sms_interval_time = 60;
                this.sms_interval = "發送中...";
                let timer = setInterval(() => {
                    if (sms_interval_time <= 1) {
                        clearInterval(timer);
                        this.sms_interval = "獲取驗證碼";
                        this.is_send = true; // 從新回覆點擊發送功能的條件
                    } else {
                        sms_interval_time -= 1;
                        this.sms_interval = `${sms_interval_time}秒後再發`;
                    }
                }, 1000);
            }
        }
    }
</script>

<style scoped>
    .register {
        width: 100vw;
        height: 100vh;
        position: fixed;
        top: 0;
        left: 0;
        z-index: 10;
        background-color: rgba(0, 0, 0, 0.3);
    }

    .box {
        width: 400px;
        height: 480px;
        background-color: white;
        border-radius: 10px;
        position: relative;
        top: calc(50vh - 240px);
        left: calc(50vw - 200px);
    }

    .el-icon-close {
        position: absolute;
        font-weight: bold;
        font-size: 20px;
        top: 10px;
        right: 10px;
        cursor: pointer;
    }

    .el-icon-close:hover {
        color: darkred;
    }

    .content {
        position: absolute;
        top: 40px;
        width: 280px;
        left: 60px;
    }

    .nav {
        font-size: 20px;
        height: 38px;
        border-bottom: 2px solid darkgrey;
    }

    .nav > span {
        margin-left: 90px;
        color: darkgrey;
        user-select: none;
        cursor: pointer;
        padding-bottom: 10px;
        border-bottom: 2px solid darkgrey;
    }

    .nav > span.active {
        color: black;
        border-bottom: 3px solid black;
        padding-bottom: 9px;
    }

    .el-input, .el-button {
        margin-top: 40px;
    }

    .el-button {
        width: 100%;
        font-size: 18px;
    }

    .foot > span {
        float: right;
        margin-top: 20px;
        color: orange;
        cursor: pointer;
    }

    .sms {
        color: orange;
        cursor: pointer;
        display: inline-block;
        width: 70px;
        text-align: center;
        user-select: none;
    }
</style>

流程

1. components中新建Register.vue文件, 寫入如上代碼
2. components中的Header.vue中. 導入組件, 註冊組件, 使用組件
3. 登陸註冊綁定點擊事件, 爲Register組件使用條件渲染指令v-if, 指定一個值is_Register控制Register組件的展現狀態. 
    在點擊z註冊按鈕時is_register爲True
    在點擊登陸組件中×時, Login組件應該控制傳遞數據, 控制父組件的展現或者隱藏. 子組件對×綁定事件的傳遞this.$emit('close')
5. 父組件中的Register組件中獲取到傳遞過來的事件@close. 綁定一個父組件中的觸發該事的方法, 一當該事件觸發, 表示用戶×了登陸界面. 此時is_register因該爲false.

5、導航條:結合實際狀況完成樣式

<template>
    <div class="nav">
        <span @click="put_login">登陸</span>
        <span @click="put_register">註冊</span>
        <Login v-if="is_login" @close="close_login" @go="put_register" />
        <Register v-if="is_register" @close="close_register" @go="put_login" />
    </div>
</template>

<script>
    import Login from "./Login";
    import Register from "./Register";
    export default {
        name: "Nav",
        data() {
            return {
                is_login: false,
                is_register: false,
            }
        },
        methods: {
            put_login() {
                this.is_login = true;
                this.is_register = false;
            },
            put_register() {
                this.is_login = false;
                this.is_register = true;
            },
            close_login() {
                this.is_login = false;
            },
            close_register() {
                this.is_register = false;
            }
        },
        components: {
            Login,
            Register
        }
    }
</script>

<style scoped>

</style>

6、登陸業務分析

1.多方式登陸

img

分析:

  • 前端:前臺提供帳號密碼,帳號多是 用戶名、手機號、郵箱等
  • 後端接口:後臺只須要提供一個多方式登陸接口便可 - 多方式登陸接口

2.驗證碼登陸

img

分析

1)前臺提供手機號和驗證碼完成登陸

接口:
前臺填完手機號,日後臺發送校驗手機號的請求,若是存在繼續,不存在提示註冊 - 手機號存在與否接口
前臺點擊發送驗證碼,將手機再次發送給後臺,後臺將手機號通知給第三方,發送短信 - 手機驗證碼接口
前臺點擊登陸提交手機號與驗證碼,完成驗證碼登陸 - 驗證碼登陸接口

7、註冊業務分析

1.驗證碼註冊

img

分析

1)前臺提供手機號、驗證碼、密碼完成註冊

接口:
前臺填完手機號,日後臺發送校驗手機號的請求,若是不存在繼續,存在提示登陸 - 手機號存在與否接口
前臺點擊發送驗證碼,將手機再次發送給後臺,後臺將手機號通知給第三方,發送短信 - 手機驗證碼接口
前臺點擊註冊提交手機號、驗證碼及密碼,完成驗證碼註冊 - 驗證碼註冊接口

8、小結

""" 1. 多方式登陸接口 2. 手機號存在與否接口 3. 手機驗證碼接口 4. 驗證碼登陸接口 5. 驗證碼註冊接口 """
相關文章
相關標籤/搜索