uniapp学习-登录/注册页面搭建

1.创建路由

2.页面搭建
点击登录/注册切换页面

效果:

QQ2024620-1810


代码:

<template>
    <view class="login">
        <view class="title">
            <view>
                <span>hello</span>
            </view>
            <view>
                <span>欢迎登录请假管理系统</span>
            </view>
        </view>
        <view class="form">
            <input class="uni-input" v-model="username" type="text" placeholder="请输入账号" />
            <input class="uni-input" v-model="password" password type="text" placeholder="请输入密码" />
        </view>
        <view class="btn">
            <button @tap="login">立即登录</button>
            <view class="tip" >
                <text type="primary" @click="addnew">没有账号,请先注册</text>
            </view>
        </view>
    </view>
</template>

<script>
    export default {
        data() {
            return {
                username: "",
                password: ""
            }
        },
        methods: {
            login() {
                uniCloud.callFunction({
                    name: "login",
                    data: {
                        username: this.username,
                        password: this.password
                    },
                    success: (res) => {
                        console.log(res);
                        if (res.result.code == 200) {
                            uni.showToast({
                                title: "登录成功"
                            })
                            setTimeout(() => {
                                uni.navigateTo({
                                    url: "/pages/index/index"
                                })
                                //把用户名存储到本地存储中
                                uni.setStorageSync("name", res.result.user.name)
                            }, 2000)

                        } else {
                            //1.如果用户不存在,或者密码错误弹出提示框
                            //2.进入请假页面,如何只显示当前登录的用户请假列表
                            uni.showToast({
                                title: res.result.msg,
                                icon: "none"

                            })
                        }
                    }
                })
            },
            addnew() {
                uni.navigateTo({
                    url: "/pages/login/new"
                })
            },
        }
    }
</script>

<style lang="scss">
    .login {
        padding: 100rpx 40rpx;
        background: url("../../static/login-bg.png");
        background-size: 100% 100%;
        height: 100vh;

        .title {
            font-weight: bolder;
            font-size: 40rpx;
        }

        .form {
            margin-top: 100rpx;

            input {
                border-bottom: 1px solid #d6d6d6;
                margin-bottom: 40rpx;
            }
        }

        .btn {
            margin-top: 100rpx;

            button {
                background-color: #11d77e;
                color: white;
            }

            .tip {
                text-align: right;
                color: gray;
                margin-top: 20rpx;

            }
        }
    }
</style>

注册页

<template>
    <view class="new">
        <view class="title">
            <view>
                <span>hello</span>
            </view>
            <view>
                <span>欢迎登录请假管理系统</span>
            </view>
        </view>
        <view class="form">
            <view class="form">
                <input class="uni-input" v-model="name" type="text" placeholder="请输入姓名" />
                <input class="uni-input" v-model="username" type="text" placeholder="请输入账号" />
                <input class="uni-input" v-model="stuNo" type="text" placeholder="请输入学号" />
                <input class="uni-input" v-model="stuClass" type="text" placeholder="请输入班级" />
                <input class="uni-input" v-model="password" password type="text" placeholder="请输入密码" />
            </view>
        </view>
        <view class="btn">
            <button @tap="addnew">立即注册</button>
            <view class="tip">
                <text type="primary" @click="addlogin">已有账号,前往登录</text>
            </view>
        </view>
    </view>
</template>

<script>
    export default {
        data() {
            return {
                name: "",
                username: "",
                stuNo: "",
                stuClass: "",
                password: ""
            }
        },
        methods: {
            addnew() {
                /* 后端需要一个新增假条的接口方法
                1. 先拿到页面数据、 附件、 理由、 开始时间、 结束时间、 请假人、 班级、 假条生成时间
                2. 调用后端的接口, 去实现新增假条的功能 */
                uniCloud.callFunction({
                    //函数名(接口名)
                    name: "new",
                    data: {
                        username: this.username,
                        password: this.password,
                        name: this.name,
                        stuNo: this.stuNo,
                        stuClass: this.stuClass
                    },
                    success: (res) => {
                        console.log(res);
                        if (res.result.code == 200) {
                            uni.showToast({
                                title: "注册成功",
                                icon: "none",
                                duration: 2000
                            })
                            setTimeout(() => {
                                uni.navigateTo({
                                    url: "/pages/login/login"
                                })
                            }, 2000)
                            //跳转到请假列表  思考如何刷新数据
                        }
                    }
                })
            },
            addlogin(){
                uni.navigateTo({
                    url: "/pages/login/login"
                })
            }
        }
    }
</script>

<style lang="scss">
    .new {
        padding: 100rpx 40rpx;
        background: url("../../static/login-bg.png");
        background-size: 100% 100%;
        height: 100vh;

        .title {
            font-weight: bolder;
            font-size: 40rpx;
        }

        .form {
            margin-top: 100rpx;

            input {
                border-bottom: 1px solid #d6d6d6;
                margin-bottom: 40rpx;
            }
        }

        .btn {
            margin-top: 100rpx;

            button {
                background-color: #11d77e;
                color: white;
            }

            .tip {
                text-align: right;
                color: gray;
                margin-top: 20rpx;

            }
        }
    }
</style>

uni-app有自己的内置组件,内置组件基本适配了手机的风格。但有时候内置组件只能满足基础需求,当需要更多场景时,就要使用到扩展组件。从性能上面来说,扩展组件的性能略低于内置组件,因此开发者切勿抛弃内置组件,直接使用全套的第三方UI组件库。

uni-app官方对组件的使用建议如下:

1、优先使用内置组件

2、然后使用uni-ui扩展组件
3、其他需求依靠插件市场的其他组件灵活补充。

以下介绍其中一款第三方插件的使用流程,以uView为例:

1、前往uView插件市场,下载相关插件到项目中,下载网址为:网址icon-default.png?t=N7T8https://ext.dcloud.net.cn/plugin?id=1593

2、进行项目的基础配置

2.1  main.js中添加如下配置:

### 如何使用 UniApp 和 Vue 3 构建后台管理系统 #### 创建新项目 为了创建一个新的基于UniApp和Vue 3的项目,可以通过HBuilderX IDE快速初始化。安装完成后打开IDE,选择`新建->项目`,然后按照提示操作。 #### 安装依赖库 确保已经配置好Node.js环境之后,在项目的根目录下运行以下命令来安装必要的开发工具以及依赖包: ```bash npm install @dcloudio/uni-cli-service -g npm install ``` 如果遇到证书错误等问题,则建议调整npm源至国内镜像以提高下载速度并减少失败几率[^5]。 #### 配置路由与页面布局 对于后台管理界面而言,合理的导航结构至关重要。利用`vue-router`定义不同功能模块之间的跳转关系,并通过条件渲染实现权限控制等功能。同时引入Element Plus或其他UI组件库简化复杂控件的设计工作。 ```javascript // main.js 中引入路由配置 import { createRouter, createWebHistory } from 'vue-router' const routes = [ { path: '/', name: 'Home', component: () => import('@/views/Home.vue') }, // 更多路由... ]; const router = createRouter({ history: createWebHistory(), routes, }); export default router; ``` #### 实现用户认证机制 考虑到安全性因素,通常还需要集成身份验证逻辑。这里可以借鉴已有案例中的做法,比如调用后端接口完成登录校验过程[^3]。 ```javascript methods:{ async handleLogin(){ const res=await this.$axios.post('/login',{username:this.username,password:this.password}) if(res.data.code===200){ localStorage.setItem('token',res.data.token); this.$router.push({name:'Dashboard'}) } } } ``` #### 自定义主题风格 最后一步就是美化整个应用啦!借助Ant Design Vue这样的解决方案能够轻松搞定全局样式统一的问题[^4]。 ```css /* App.vue */ <style> @import '~ant-design-vue/dist/reset.css'; </style> ``` 以上便是关于如何采用最新版Vue框架配合跨平台框架UniApp打造一套完整的后台管理系统的大致流程介绍。当然具体实施过程中可能还会涉及到更多细节上的考量,例如性能优化、SEO支持等方面的内容。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值