|
本帖最后由 uoaccw 于 2018-12-28 20:41 编辑
模块概述
某些 App 具有打开某一页面即可默认弹出键盘的功能,如某些登陆授权、评论页面。但是一个纯 html 的输入框标签,无法实现这一功能。为满足 APICloud 平台开发者对这一功能的需求,特推出了 UIInput 模块。
UIInput 是一个输入框模块,开发者可通过配置相应参数来控制输入框自动获取焦点,并弹出键盘。同普通的 UI 类的模块一样,本模块也可通过 rect 来设置其位置和大小,通过 styles参数设置其样式。为增强输入框功能,模块开放了 keyboardType 参数,开发者可通过设置该参数来控制其键盘类型。
模块文档地址:
https://docs.apicloud.com/Client-API/UI-Layout/UIInput
demo效果图:
附件为widget形式代码包。
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="utf-8">
- <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
- <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
- <title>title</title>
- <link rel="stylesheet" type="text/css" href="../css/api.css" />
- <link rel="stylesheet" type="text/css" href="../css/aui.css" />
- <style>
- html,
- body {
- background-color: #fff;
- }
- .content {
- height: 300px;
- width: 100%;
- }
- .login {
- margin-top: 10px;
- }
- </style>
- </head>
- <body>
- <div class="content">
- </div>
- <ul class="aui-list aui-form-list">
- <li id='inputusername' class="aui-list-item">
- <div class="aui-list-item-inner">
- <div class="aui-list-item-label-icon">
- <i class="aui-iconfont aui-icon-mobile"></i>
- </div>
- <div class="aui-list-item-input">
- </div>
- <div tapmode class="aui-list-item-label-icon" onclick="fnclear()">
- <i class="aui-iconfont aui-icon-close"></i>
- </div>
- </div>
- </li>
- <li id='inputpassword' class="aui-list-item">
- <div class="aui-list-item-inner">
- <div class="aui-list-item-label-icon">
- <i class="aui-iconfont aui-icon-lock"></i>
- </div>
- <div class="aui-list-item-input">
- </div>
- </div>
- </li>
- </ul>
- <div tapmode class="aui-btn aui-btn-block login" onclick="fnlogin()">登录</div>
- </body>
- <script type="text/javascript" src="../script/api.js"></script>
- <script type="text/javascript">
- var winH; //window窗口的高
- var eleinputusername = $api.byId('inputusername');
- var eleinputpassword = $api.byId('inputpassword');
- var y = $api.offset(eleinputusername).t + 7; //定位手机号输入框的位置y
- var y2 = $api.offset(eleinputpassword).t + 7; //定位密码输入框的位置y
- var passWordTop; //计算密码框底部到屏幕底部的距离
- var UIInput;
- apiready = function() {
- winH = api.winHeight;
- passWordTop = winH - $api.offset(eleinputpassword).t - $api.offset(eleinputpassword).h;
- UIInput = api.require('UIInput');
- UIInput_open();
- UIInput_open2();
- }
- function UIInput_open() {
- UIInput.open({
- rect: {
- x: 44,
- y: y,
- w: api.winWidth - 88,
- h: 30
- },
- styles: {
- bgColor: '#fff',
- size: 14,
- color: '#000',
- placeholder: {
- color: '#ccc'
- }
- },
- autoFocus: false,
- maxRows: 1,
- placeholder: '请输入手机号',
- keyboardType: 'number',
- inputType: 'text',
- fixedOn: api.frameName,
- fixed: false
- }, function(ret, err) {
- if (ret) {
- console.log(JSON.stringify(ret));
- id = ret.id;
- UIInput.addEventListener({
- id: id,
- name: 'resignFirstResponder'
- }, function() {
- });
- UIInput.addEventListener({
- id: id,
- name: 'becomeFirstResponder'
- }, function(ret) {
- //console.log("输入框获得焦点!" + api.winHeight + ret.keyboardHeight);
- if (ret.keyboardHeight) {
- if(api.systemType == 'android' || api.systemType == 'Android'){
- fnscoll(ret.keyboardHeight);
- }
- }
- });
- }
- });
- }
- function UIInput_open2() {
- var UIInput = api.require('UIInput');
- UIInput.open({
- rect: {
- x: 44,
- y: y2,
- w: api.winWidth - 88,
- h: 30
- },
- styles: {
- bgColor: '#fff',
- size: 14,
- color: '#000',
- placeholder: {
- color: '#ccc'
- }
- },
- autoFocus: false,
- maxRows: 1,
- placeholder: '请输入密码',
- keyboardType: 'default',
- inputType: 'password',
- fixedOn: api.frameName,
- fixed: false
- }, function(ret, err) {
- if (ret) {
- console.log(JSON.stringify(ret));
- id2 = ret.id;
- UIInput.addEventListener({
- id: id2,
- name: 'resignFirstResponder'
- }, function() {
- console.log("输入框失去焦点!");
- });
- UIInput.addEventListener({
- id: id2,
- name: 'becomeFirstResponder'
- }, function(ret) {
- console.log("输入框获得焦点!" + api.winHeight + ret.keyboardHeight);
- if (ret.keyboardHeight) {
- if(api.systemType == 'android' || api.systemType == 'Android'){
- fnscoll(ret.keyboardHeight);
- }
- }
- });
- }
- });
- }
- function UIInput_value(oneid) {
- UIInput.value({
- id: oneid
- }, function(ret, err) {
- if (ret) {
- console.log(JSON.stringify(ret));
- }
- });
- }
- function closeUIIput(id) {
- UIInput.close({
- id: id
- });
- }
- //滚动页面防止被键盘遮挡,仅Android需要
- function fnscoll(L) {
- console.log(L + ':' + passWordTop);
- if (L > passWordTop) {
- document.body.scrollTop = L - passWordTop; //滚动距离=键盘高度-密码框距屏幕底部距离
- }
- }
- function fnclear() {
- UIInput.value({
- id: id,
- msg: ''
- }, function(ret, err) {
- if (ret) {
- console.log(JSON.stringify(ret));
- }
- });
- }
- function fnlogin() {
- UIInput_value(id);
- UIInput_value(id2);
- }
- </script>
- </html>
复制代码
|
|