uniapp+vue+uview适配安卓4.4项目实现简单登录和操作页面

简介: uniapp+vue+uview适配安卓4.4项目实现简单登录和操作页面

前言

大家好 我是歌谣 最近遇到了一个新的问题 就是兼容一个安卓4.4的平板仪器 利用react打包之后再用Hbulderx打包成apk之后白屏 于是就开始漫长的尝试过程


转折

多方测试发现 原生js可以识别 于是乎开始了原生js的开发

<!DOCTYPE html>
<html class="ui-page-login">
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
        <title></title>
        <link href="css/mui.min.css" rel="stylesheet" />
        <link href="css/style.css" rel="stylesheet" />
        <style>
            .area {
                margin: 20px auto 0px auto;
            }
            .mui-input-group {
                margin-top: 10px;
            }
            .mui-input-group:first-child {
                margin-top: 20px;
            }
            .mui-input-group label {
                width: 22%;
            }
            .mui-input-row label~input,
            .mui-input-row label~select,
            .mui-input-row label~textarea {
                width: 78%;
            }
            .mui-checkbox input[type=checkbox],
            .mui-radio input[type=radio] {
                top: 6px;
            }
            .mui-content-padded {
                margin-top: 25px;
            }
            .mui-btn {
                padding: 10px;
            }
            .link-area {
                display: block;
                margin-top: 25px;
                text-align: center;
            }
            .spliter {
                color: #bbb;
                padding: 0px 8px;
            }
            .oauth-area {
                position: absolute;
                bottom: 20px;
                left: 0px;
                text-align: center;
                width: 100%;
                padding: 0px;
                margin: 0px;
            }
            .oauth-area .oauth-btn {
                display: inline-block;
                width: 50px;
                height: 50px;
                background-size: 30px 30px;
                background-position: center center;
                background-repeat: no-repeat;
                margin: 0px 20px;
                /*-webkit-filter: grayscale(100%); */
                border: solid 1px #ddd;
                border-radius: 25px;
            }
            .oauth-area .oauth-btn:active {
                border: solid 1px #aaa;
            }
            .oauth-area .oauth-btn.disabled {
                background-color: #ddd;
            }
        </style>
    </head>
    <body>
        <header class="mui-bar mui-bar-nav">
            <h1 class="mui-title">登录</h1>
        </header>
        <div class="mui-content">
            <form id='login-form' class="mui-input-group">
                <div class="mui-input-row">
                    <label>账号</label>
                    <input id='account' type="text" class="mui-input-clear mui-input" placeholder="请输入账号">
                </div>
                <div class="mui-input-row">
                    <label>密码</label>
                    <input id='password' type="password" class="mui-input-clear mui-input" placeholder="请输入密码">
                </div>
            </form>
            <div class="mui-content-padded">
                <button  id='login' class="mui-btn mui-btn-block mui-btn-primary">登录</button>
            <!--    <div class="link-area"><a id='reg'>注册账号</a> <span class="spliter">|</span> <a id='forgetPassword'>忘记密码</a>
                </div> -->
            </div>
        </div>
        <script src="js/mui.min.js"></script>
        <script src="js/mui.enterfocus.js"></script>
        <script src="js/app.js"></script>
        <script>
            var login=document.getElementById("login");
            var account=document.getElementById("account")
            var password=document.getElementById("password")
            var test=document.getElementById("test")
            //监听点击事件
            login.addEventListener("tap",function () {
                mui.ajax('http://xxxxxx/pda/login',{
                    data:{
                        account:document.getElementById("account").value,
                        password:document.getElementById("password").value
                    },
                    dataType:'json',//服务器返回json格式数据
                    type:'post',//HTTP请求类型
                    timeout:10000,//超时时间设置为10秒;
                    headers:{'Content-Type':'application/json'},                  
                    success:function(response){
                        // test.innerHTML=JSON.stringify(response)
                        if(response.code==200){
                            window.location.href="./home.html"
                            mui.toast('登陆成功',{ duration:'long', type:'div' })
                        }else{
                            mui.toast('登陆失败',{ duration:'long', type:'div' })
                        }
                        //服务器返回响应,根据响应结果,分析是否登录成功;
                    },
                    error:function(xhr,type,errorThrown){
                        // test.innerHTML=JSON.stringify(xhr)
                        //异常处理;
                        console.log(type);
                    }
                });
            });
            //触发submit按钮的点击事件
            mui.trigger(login,'tap')
        </script>
    </body>
</html>

结果

结果遇到了一些问题 无法进行数据的双向绑定


实现结果

image.png


接着就开始换一种思路

利用uniapp+uview1.8+vue开发 login.vue

<template>
    <view class="content">
        <!--    <image class="logo" src="/static/logo.png"></image>
        <view class="text-area">
            <text class="title">
                uView - 多平台快速开发的UI框架
            </text>
        </view>
        <view class="button-demo">
            <u-button type="primary" plain @click="$u.route('/pages/login/login')">通用登录页展示</u-button>
        </view> -->
        <u-form :model="form" ref="uForm">
            <u-form-item label="姓名">
                <u-input v-model="form.account" placeholder="请输入账号"></u-input>
            </u-form-item>
            <u-form-item label="密码">
                <u-input v-model="form.password"  placeholder="请输入密码"></u-input>
            </u-form-item>
        </u-form>
        <view style="padding: 20px;">
        <u-button v-on:click="handleClick" type="primary" text="登录">登录</u-button>
        </view>
    </view>
</template>
<script>
    export default {
        data() {
            return {
                title: 'Hello',
                form: {
                    account: "",
                    password:""
                },
                status:"1"
            }
        },
        onLoad() {
        },
        methods: {
             handleClick(){
                // this.status="-1"
                // var that=this
                 uni.$u.http.post('http://xxxxxx',{account: this.form.account, password: this.form.password}).then(res => {
                      console.log(this,"22222")
                // that.status="-1"
                uni.navigateTo({
                    url: '/pages/index/index',
                });
                }).catch(err => {
                    console.log("-----------”")
                console.log(err,"11111")
                console.log("-----------”")
                })
            }
        }
    }
</script>
<style lang="scss" scoped>
    .content {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        padding: 40rpx;
    }
    .logo {
        height: 200rpx;
        width: 200rpx;
        margin-top: 100rpx;
        margin-left: auto;
        margin-right: auto;
        margin-bottom: 50rpx;
    }
    .text-area {
        display: flex;
        justify-content: center;
    }
    .title {
        font-size: 28rpx;
        color: $u-content-color;
    }
    .button-demo {
        margin-top: 80rpx;
    }
</style>
相关文章
|
5天前
|
JavaScript 数据安全/隐私保护 UED
UniApp 中的路由魔法:玩转页面导航与跳转
UniApp 中的路由魔法:玩转页面导航与跳转
32 3
|
12天前
|
小程序 JavaScript Java
基于SpringBoot+Vue+uniapp微信小程序的校园水电费管理微信小程序的详细设计和实现
基于SpringBoot+Vue+uniapp微信小程序的校园水电费管理微信小程序的详细设计和实现
35 0
|
12天前
|
小程序 JavaScript Java
基于SpringBoot+Vue+uniapp微信小程序的优购电商小程序的详细设计和实现
基于SpringBoot+Vue+uniapp微信小程序的优购电商小程序的详细设计和实现
34 0
|
5天前
|
JavaScript 安全 前端开发
Vue 项目中的权限管理:让页面也学会说“你无权访问!
Vue 项目中的权限管理:让页面也学会说“你无权访问!
15 3
|
6天前
|
JavaScript 前端开发
vue3+ts+element home页面侧边栏+头部组件+路由组件组合页面教程
这是一个Vue.js组件代码示例,展示了带有侧边栏导航和面包屑导航的布局。模板中使用Element Plus组件库,包含可折叠的侧边栏,其中左侧有 Logo 和导航列表,右侧显示更具体的子菜单。`asideDisplay`控制侧边栏宽度。在`script`部分,使用Vue的响应式数据和生命周期钩子初始化路由相关数据,并从localStorage恢复状态。样式部分定义了组件的颜色、尺寸和布局。
14 1
|
8天前
|
Android开发
Android源代码定制:添加customize.mk文件进行分项目和分客户的定制
Android源代码定制:添加customize.mk文件进行分项目和分客户的定制
3 0
|
11天前
|
小程序 JavaScript Java
基于SpringBoot+Vue+uniapp微信小程序的微信课堂助手小程序的详细设计和实现
基于SpringBoot+Vue+uniapp微信小程序的微信课堂助手小程序的详细设计和实现
46 3
|
11天前
|
小程序 JavaScript Java
基于SpringBoot+Vue+uniapp微信小程序的电子商城购物平台的详细设计和实现
基于SpringBoot+Vue+uniapp微信小程序的电子商城购物平台的详细设计和实现
41 3
|
11天前
|
小程序 JavaScript Java
基于SpringBoot+Vue+uniapp微信小程序的英语学习交流平台的详细设计和实现
基于SpringBoot+Vue+uniapp微信小程序的英语学习交流平台的详细设计和实现
27 2
|
11天前
|
小程序 JavaScript Java
基于SpringBoot+Vue+uniapp微信小程序的微信阅读网站小程序的详细设计和实现
基于SpringBoot+Vue+uniapp微信小程序的微信阅读网站小程序的详细设计和实现
39 2

热门文章

最新文章

相关实验场景

更多