hui框架开发APP

2024-01-12 07:40
文章标签 app 开发 框架 hui

本文主要是介绍hui框架开发APP,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

hui是类似于mui框架的app构建框架,通过一段时间学习,写了个app例子

GitHub地址   等待中..........

数据来源--------聚合数据

hui框架地址:http://www.hcoder.net/hui/docs

 

先看下效果吧

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

功能就这么简单

 

 

开始吧

入口界面  index.html

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<title>HUI</title>
<link rel="stylesheet" type="text/css" href="css/hui.css" />
<style type="text/css">hui-start-banner{width:100%; height:100%; position:fixed; z-index:9998; left:0px; top:0px; background:#FFFFFF; display:none;}
#hui-start-banner-close{width:50px; height:50px; position:fixed; z-index:9999; top:50px; right:20px; background:#F5F6F7; display:none; text-align:center; border-radius:50px; line-height:50px; font-size:14px; color:#666;}
.hui-start-banner .hui-swipe-indicator{width:96%; position:absolute; z-index:3; left:2%; bottom:20px; display:none;}
#hui-footer a{
-webkit-tap-highlight-color: rgba(255, 255, 255, 0);
-webkit-user-select: none;
-moz-user-focus: none;
-moz-user-select: none;
}
</style>
</head>
<body>	
<div class="hui-wrap"></div>
<div id="hui-footer"><a href="javascript:changeSubView(0);" id="nav-home" class="hui-footer-active"><div class="hui-footer-icons hui-icons-home"></div><div class="hui-footer-text">首页</div></a><a href="javascript:changeSubView(1);" id="nav-news"><div class="hui-footer-icons hui-icons-news"></div><div class="hui-footer-text">新闻</div></a><a href="javascript:changeSubView(2);" id="nav-forum"><div class="hui-footer-icons hui-icons-forum"></div><div class="hui-footer-text">社区</div></a><a href="javascript:changeSubView(3);" id="nav-my"><div class="hui-footer-icons hui-icons-my"></div><div class="hui-footer-text">我的</div></a>
</div>
<script src="js/hui.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">setTimeout(function(){plus.navigator.closeSplashscreen();},1500)// 创建子窗口
var subpages =  new Array(new Array('html/sub1.html', {top:'0px', bottom:"55px", left:"0"}),new Array('html/sub2.html', {top:'0px', bottom:"55px", left:"100%"}),new Array('html/sub3.html', {top:'0px', bottom:"55px", left:"200%"}),new Array('html/cutPicture.html', {top:'0px', bottom:"55px", left:"300%"})
);
hui.plusReady(function(){hui.subpages(subpages);
});//点击底部按钮切换窗口
function changeSubView(index){for(var i = 0; i< subpages.length; i++){var subpage = hui.getView(subpages[i][0]);subpage.setStyle({'top':0,'left' : ((index - i) * 100 )+'%'});}//选项状态激活hui('#hui-footer a').removeClass('hui-footer-active');hui('#hui-footer a').eq(index).addClass('hui-footer-active');
}var height = document.documentElement.clientHeight || document.body.clientHeight;
window.onresize = function() {var heightView = document.documentElement.clientHeight || document.body.clientHeight;if(heightView < height) {plus.webview.currentWebview().setStyle({height: height});}
}
</script>
</body>
</html>

 sub1.html  新闻列表页

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<title>HUI</title>
<link rel="stylesheet" type="text/css" href="../css/hui.css" />
</head>
<body>
<header class="hui-header"><h1>腾讯新闻</h1>
</header>
<div class="hui-wrap"><div class="hui-swipe" id="swipe2"><div class="hui-swipe-items"></div></div>
</div>
<div class="hui-wrap"><div class="hui-center-title"><h1>新闻列表</h1></div><div style="padding:10px;"><div id="refreshContainer" class="hui-refresh"><div class="hui-refresh-icon"></div><div class="hui-refresh-content hui-list" id="list"><ul id="arcicle"><!--描述:内容集合--></ul></div></div></div>
</div><script src="../js/hui.js" type="text/javascript" charset="utf-8"></script>
<script src="../js/hui-swipe.js" type="text/javascript" charset="utf-8"></script>
<script src="../js/hui-refresh-load-more.js"></script>
<script src="../js/jquery-3.1.1.min.js"></script>
<script type="text/javascript">hui.Back = null;
hui.plusReady(function(){//判断是否支持沉浸式var isImmersedStatusbar = plus.navigator.isImmersedStatusbar();//获取系统状态栏高度var StatusbarHeight = plus.navigator.getStatusbarHeight();		   console.log(StatusbarHeight);hui('.hui-header').css({'paddingTop':StatusbarHeight + 'px'});hui('#hui-back').css({top:StatusbarHeight+'px'});var indexView = plus.webview.getLaunchWebview();var nextPage = {pageId : 'html/sub2.html', callBack : function(){indexView.evalJS('hui("#hui-footer").find("a").removeClass("hui-footer-active"); hui("#nav-news").addClass("hui-footer-active")');}};var prevPage = null;hui.drag(prevPage, nextPage);
});
hui.get('http://hoa.hcoder.net/index.php?user=hcoder&pwd=hcoder&m=lunbo',function(res){var arr  = res.split('--hcSplitor--');for(var i = 0; i < arr.length; i++){var div = document.createElement('div')div.setAttribute('class', 'hui-swipe-item');div.innerHTML = arr[i];hui(div).appendTo('#swipe2 .hui-swipe-items');    }var swipe2 = new huiSwpie('#swipe2');swipe2.run();},function(){hui.toast('读取远程数据失败');}   
);	
</script>
<script>function showProductInfo(url,titles){hui.open("createShow.html",{},true,{url:url,titles:titles})}
hui.refresh('#refreshContainer', refresh);
hui.loadMore(getMore);
//加载更多
function getMore(){$.ajax({ url:'http://v.juhe.cn/toutiao/index?key=76db99a8de0bb25da0ea78e8747f4971&type=guoji', type:'GET', dataType:'json',  // 处理Ajax跨域问题success: function(res){ var data = JSON.stringify(res);data = JSON.parse(data);data = data.result.data;for(var i = 0; i < data.length; i++){var li = document.createElement('li');li.style.borderBottom="1px solid gray";li.style.height="auto";var pic1 =  data[i].thumbnail_pic_s02 ? '<img src='+data[i].thumbnail_pic_s02+'/>':" ";var pic2 =  data[i].thumbnail_pic_s03 ? '<img src='+data[i].thumbnail_pic_s03+'/>':" ";li.innerHTML ='<div class="hui-media-content" style="width:100%;height:auto">'+'<p style="width:95%;margin:1em auto;color:red"><a href="javascript:showProductInfo(\''+data[i].url+'\',\''+data[i].author_name+'\');">'+data[i].title +'</a></p>'+'<img src='+data[i].thumbnail_pic_s+'/>'+pic1+pic2+'<p>'+'<span>'+data[i].author_name+'</span>'+'<span style="float: right;">'+data[i].date+'</span>'+'</p>'+'</div>';hui(li).appendTo('#arcicle');}hui.endLoadMore();}})
}
function refresh(){if(hui.refreshNumber < 1){hui.loading('加载中...');}$.ajax({ url:'http://v.juhe.cn/toutiao/index?key=76db99a8de0bb25da0ea78e8747f4971&type=top', type:'GET', dataType:'json',  // 处理Ajax跨域问题success: function(res){ var data = JSON.stringify(res);data = JSON.parse(data);data = data.result.data;console.log(data)var html = '';for(var i = 0; i < data.length; i++){var pic1 =  data[i].thumbnail_pic_s02 ? '<img src='+data[i].thumbnail_pic_s02+'/>':" ";var pic2 =  data[i].thumbnail_pic_s03 ? '<img src='+data[i].thumbnail_pic_s03+'/>':" ";html += '<li style="border-bottom:1px solid gray;height:auto !important">'+'<div class="hui-media-content" style="width:100%;height:auto">'+'<p style="width:95%;margin:1em auto;color:red"><a href="javascript:showProductInfo(\''+data[i].url+'\',\''+data[i].author_name+'\');">'+data[i].title +'</a></p>'+'<img src='+data[i].thumbnail_pic_s+'/>'+pic1+pic2+'<p>'+'<span>'+data[i].author_name+'</span>'+'<span style="float: right;">'+data[i].date+'</span>'+'</p>'+'</div>'+'</li>';}hui('#arcicle').html(html);hui.endRefresh();//关闭loadinghui.loading('加载中...', true);},error:function(){hui.loading('加载中...', true);title="无法完成操作"message="由于你的支付宝账户还未绑定淘宝账户请登请登录www.taobao.com"hui('#arcicle').html('<div style="text-align: center;margin:50px auto">'+'<img src="../image/GIyMDJnuqmcqPLpHCSkj.svg">'+'<h2 style="text-align: center;line-height: 2rem;">无法获取数据</h2>'+'<p style="text-align: center;color:red;ine-height:2rem;">请检查网络是否正确</p>'+'</div>');hui.toast('连接服务器失败!');hui.endRefresh();}}); }
</script>
</body>
</html>

 

sub2.html   笑话总集

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" /><title>HUI</title>
<link rel="stylesheet" type="text/css" href="../css/hui.css" />
</head>
<body>
<header class="hui-header"><h1>笑话总集</h1> 
</header>
<div class="hui-wrap"> <div class="hui-wrap"><div id="refreshContainer" class="hui-refresh"><div class="hui-refresh-icon"></div><div class="hui-refresh-content hui-list" id="list"><ul id="arcicle" style="margin-top: 10px;"><!--描述:内容集合--></ul></div></div>
</div>
</div><!--播放笑话
-->
<div id="bdtts_div_id"><audio id="tts_autio_id" autoplay="autoplay"><source id="tts_source_id" src="http://tts.baidu.com/text2audio?lan=zh&ie=UTF-8&spd=5&text=" type="audio/mpeg"><embed id="tts_embed_id" height="0" width="0" src=""></audio>
</div>
<script src="../js/hui.js" type="text/javascript" charset="utf-8"></script>
<script src="../js/hui-refresh-load-more.js"></script>
<script type="text/javascript" src="../js/jquery-3.1.1.min.js"></script>
<script type="text/javascript">
hui.refresh('#refreshContainer', refresh);hui.loadMore(getMore);
//加载更多
function getMore(){$.ajax({ url:"https:\/\/v.juhe.cn\/joke\/content\/text.php?key=e0f404df1a1469811b3ce7239f0462d4&pagesize=10&page="+page, type:'GET', dataType:'JSONP',  // 处理Ajax跨域问题success: function(res){ var data = JSON.stringify(res);data = JSON.parse(data);data = data.result.data;for(var i = 0; i < data.length; i++){var li = document.createElement('li');li.style.borderBottom="1px solid gray";li.style.height="auto";li.innerHTML ='<div class="hui-media-content" style="width:100%;height:auto">'+'<p style="width:95%;margin:1em auto;color:red" onclick="songs(this.innerText)">'+data[i].content +'</p>'+'<p>'+'<span>'+data[i].unixtime+'</span>'+'<span style="float: right;">'+data[i].updatetime+'</span>'+'</p>'+'</div>';hui(li).appendTo('#arcicle');}hui.endLoadMore();page++;}})
}
function refresh(){if(hui.refreshNumber < 1){hui.loading('加载中...');}$.ajax({ url:"https:\/\/v.juhe.cn\/joke\/content\/text.php?key=e0f404df1a1469811b3ce7239f0462d4&page=1&pagesize=10", type:'GET', dataType:'JSONP',  // 处理Ajax跨域问题success: function(res){ var data = JSON.stringify(res);data = JSON.parse(data);data = data.result.data;var html = '';for(var i = 0; i < data.length; i++){html += '<li style="border-bottom:1px solid gray;height:auto !important">'+'<div class="hui-media-content" style="width:100%;height:auto">'+'<p style="width:95%;margin:1em auto;color:red" onclick="songs(this.innerText)">'+data[i].content +'</p>'+'<p>'+'<span>'+data[i].unixtime+'</span>'+'<span style="float: right;">'+data[i].updatetime+'</span>'+'</p>'+'</div>'+'</li>';}hui('#arcicle').html(html);hui.endRefresh();page=2;//关闭loadinghui.loading('加载中...', true);},error:function(){hui.loading('加载中...', true);hui('#arcicle').html('<div style="text-align: center;margin:50px auto">'+'<img src="../image/GIyMDJnuqmcqPLpHCSkj.svg">'+'<h2 style="text-align: center;line-height: 2rem;">无法获取数据</h2>'+'<p style="text-align: center;color:red;ine-height:2rem;">请检查网络是否正确</p>'+'</div>');;hui.toast('连接服务器失败!');hui.endRefresh();}}); }function songs(val){hui.confirm('您确认要播放笑话吗?', ['取消','确定'], function(){var ttsDiv = document.getElementById('bdtts_div_id');var ttsAudio = document.getElementById('tts_autio_id');ttsDiv.removeChild(ttsAudio);var au1 = '<audio id="tts_autio_id" autoplay="autoplay">';var sss = '<source id="tts_source_id" src="http://tts.baidu.com/text2audio?lan=zh&ie=UTF-8&spd=6&text='+val+'" type="audio/mpeg">';var eee = '<embed id="tts_embed_id" height="0" width="0" src="">';var au2 = '</audio>';ttsDiv.innerHTML = au1 + sss + eee + au2;ttsAudio = document.getElementById('tts_autio_id');ttsAudio.play();},function(){console.log('取消后执行...');});
}
</script>
<script type="text/javascript">//禁用返回键
hui.Back = null;
hui.plusReady(function(){//判断是否支持沉浸式var isImmersedStatusbar = plus.navigator.isImmersedStatusbar();//获取系统状态栏高度var StatusbarHeight = plus.navigator.getStatusbarHeight();console.log(StatusbarHeight);hui('.hui-header').css({'paddingTop':StatusbarHeight + 'px'});hui('#hui-back').css({top:StatusbarHeight+'px'});var indexView = plus.webview.getLaunchWebview();var nextPage = {pageId : 'html/sub3.html', callBack : function(){indexView.evalJS('hui("#hui-footer").find("a").removeClass("hui-footer-active"); hui("#nav-forum").addClass("hui-footer-active")');}};var prevPage = {pageId : 'html/sub1.html', callBack : function(){indexView.evalJS('hui("#hui-footer").find("a").removeClass("hui-footer-active"); hui("#nav-home").addClass("hui-footer-active")');}};hui.drag(prevPage, nextPage);});
</script>
</body>
</html>

 

sub3.html  联系我们

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<title>HUI</title>
<link rel="stylesheet" type="text/css" href="../css/hui.css" />
</head>
<body>
<header class="hui-header"><h1 style="text-align: left;">反馈信息</h1><h1 style="text-align: right;" id="subMitConfig">提交反馈</h1>
</header>
<div class="hui-warp" style="margin-top:55px;"><textarea name="textareas" rows="20" id="textareas" style="margin:10px 5% 10px;width:80%;border-radius: 20px;padding-left:5%;padding-right:5%" placeholder="请留下您宝贵的建议,让我们一同进步吧~~"></textarea>
</div>
<div class="hui-warp" style="position: relative;"><h2 style="text-align: center;">十分真诚的希望留下您的印记</h2>
</div>
<script src="../js/hui.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
hui.Back = null;
hui.plusReady(function(){//判断是否支持沉浸式var isImmersedStatusbar = plus.navigator.isImmersedStatusbar();//获取系统状态栏高度var StatusbarHeight = plus.navigator.getStatusbarHeight();		   console.log(StatusbarHeight);hui('.hui-header').css({'paddingTop':StatusbarHeight + 'px'});hui('#hui-back').css({top:StatusbarHeight+'px'});var indexView = plus.webview.getLaunchWebview();var nextPage = {pageId : 'html/cutPicture.html', callBack : function(){indexView.evalJS('hui("#hui-footer").find("a").removeClass("hui-footer-active"); hui("#nav-my").addClass("hui-footer-active")');}};var prevPage = {pageId : 'html/sub2.html', callBack : function(){indexView.evalJS('hui("#hui-footer").find("a").removeClass("hui-footer-active"); hui("#nav-news").addClass("hui-footer-active")');}};hui.drag(prevPage, nextPage);});hui("#subMitConfig").click(function(){hui.toast(hui("#textareas").val());if(hui("#textareas").val()==""){hui.toast("请留下您的意见,谢谢");}else{hui.toast("感谢您宝贵的意见,我们会尽快完善的,谢谢");hui("#textareas").val("");}	})</script>
</body>
</html>

cutPicture.html   个人中心

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<link rel="stylesheet" type="text/css" href="../css/hui.css" />
<style type="text/css">#hui-swaper{position: fixed;bottom:10%;}#hui-swaper h2{text-align: center;margin-top:2%;color: grey;}
</style>
</head>
<body>
<header class="hui-header"><h1>abuot us</h1>
</header>
<div class="hui-warp" style="margin:0 auto;margin-top: 150px;"><div style="margin:0 auto; width:120px"><img src="../image/chrome.png" style="width:120px;height:120px;border-radius: 15%;"/></div><h2 style="text-align: center;font-size: 24px;color: royalblue;">IReading</h2><p style="text-align: center;font-size: 24px;color: red;">让生活更精彩</p>
</div>
<div id="hui-swaper" style="height: 100px;width: 100%;"><h2>版权所有@ wangweiruning<h2><h2>开法者 :wangweiruning@163.com</h2><h2>如有需求,请发送消息至邮箱wangweiruning163.con</h2>
</div>
<script type="text/javascript" src="../js/hui.js" charset="UTF-8"></script>
<script type="text/javascript" src="../js/hui-image-cuter.js" charset="UTF-8"></script>
<script type="text/javascript">hui.Back = null;hui.plusReady(function(){//判断是否支持沉浸式var isImmersedStatusbar = plus.navigator.isImmersedStatusbar();//获取系统状态栏高度var StatusbarHeight = plus.navigator.getStatusbarHeight();		   console.log(StatusbarHeight);hui('.hui-header').css({'paddingTop':StatusbarHeight + 'px'});hui('#hui-back').css({top:StatusbarHeight+'px'});var indexView = plus.webview.getLaunchWebview();var nextPage = null;var prevPage ={pageId : 'html/sub3.html', callBack : function(){indexView.evalJS('hui("#hui-footer").find("a").removeClass("hui-footer-active"); hui("#nav-forum").addClass("hui-footer-active")');}}; hui.drag(prevPage, nextPage);});</script>
</body>
</html>

 

createShow.html    新闻详情页

<!doctype html>
<html><head><meta charset="UTF-8"><title></title><meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" /><link href="../css/hui.css" rel="stylesheet" /></head><body><header class="hui-header"><div id="hui-back"></div><h1 id="titles"></h1></header><script src="../js/hui.js"></script><script type="text/javascript">hui.loading("加载中...");var _self;hui.plusReady(function(){_self = plus.webview.currentWebview();var urls = _self.url;var titles = _self.titles;hui("#titles").html(titles);var bnv = plus.webview.create(urls,'detail',{top:"60px"},{});plus.webview.currentWebview().append(bnv);hui.closeLoading();})</script></body></html>

应用打包请使用  hbuilder  开发工具

配置项在manifest.json中设置

写不下去了,具体看代码吧(~_~)~~~~~~~~~~~~~~~~~

 

欢迎大家一起交流

这篇关于hui框架开发APP的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/597212

相关文章

一文详解Python如何开发游戏

《一文详解Python如何开发游戏》Python是一种非常流行的编程语言,也可以用来开发游戏模组,:本文主要介绍Python如何开发游戏的相关资料,文中通过代码介绍的非常详细,需要的朋友可以参考下... 目录一、python简介二、Python 开发 2D 游戏的优劣势优势缺点三、Python 开发 3D

基于Python开发Windows自动更新控制工具

《基于Python开发Windows自动更新控制工具》在当今数字化时代,操作系统更新已成为计算机维护的重要组成部分,本文介绍一款基于Python和PyQt5的Windows自动更新控制工具,有需要的可... 目录设计原理与技术实现系统架构概述数学建模工具界面完整代码实现技术深度分析多层级控制理论服务层控制注

uni-app小程序项目中实现前端图片压缩实现方式(附详细代码)

《uni-app小程序项目中实现前端图片压缩实现方式(附详细代码)》在uni-app开发中,文件上传和图片处理是很常见的需求,但也经常会遇到各种问题,下面:本文主要介绍uni-app小程序项目中实... 目录方式一:使用<canvas>实现图片压缩(推荐,兼容性好)示例代码(小程序平台):方式二:使用uni

Java中的分布式系统开发基于 Zookeeper 与 Dubbo 的应用案例解析

《Java中的分布式系统开发基于Zookeeper与Dubbo的应用案例解析》本文将通过实际案例,带你走进基于Zookeeper与Dubbo的分布式系统开发,本文通过实例代码给大家介绍的非常详... 目录Java 中的分布式系统开发基于 Zookeeper 与 Dubbo 的应用案例一、分布式系统中的挑战二

Java 缓存框架 Caffeine 应用场景解析

《Java缓存框架Caffeine应用场景解析》文章介绍Caffeine作为高性能Java本地缓存框架,基于W-TinyLFU算法,支持异步加载、灵活过期策略、内存安全机制及统计监控,重点解析其... 目录一、Caffeine 简介1. 框架概述1.1 Caffeine的核心优势二、Caffeine 基础2

基于Go语言开发一个 IP 归属地查询接口工具

《基于Go语言开发一个IP归属地查询接口工具》在日常开发中,IP地址归属地查询是一个常见需求,本文将带大家使用Go语言快速开发一个IP归属地查询接口服务,有需要的小伙伴可以了解下... 目录功能目标技术栈项目结构核心代码(main.go)使用方法扩展功能总结在日常开发中,IP 地址归属地查询是一个常见需求:

基于 Cursor 开发 Spring Boot 项目详细攻略

《基于Cursor开发SpringBoot项目详细攻略》Cursor是集成GPT4、Claude3.5等LLM的VSCode类AI编程工具,支持SpringBoot项目开发全流程,涵盖环境配... 目录cursor是什么?基于 Cursor 开发 Spring Boot 项目完整指南1. 环境准备2. 创建

SpringBoot 多环境开发实战(从配置、管理与控制)

《SpringBoot多环境开发实战(从配置、管理与控制)》本文详解SpringBoot多环境配置,涵盖单文件YAML、多文件模式、MavenProfile分组及激活策略,通过优先级控制灵活切换环境... 目录一、多环境开发基础(单文件 YAML 版)(一)配置原理与优势(二)实操示例二、多环境开发多文件版

使用docker搭建嵌入式Linux开发环境

《使用docker搭建嵌入式Linux开发环境》本文主要介绍了使用docker搭建嵌入式Linux开发环境,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面... 目录1、前言2、安装docker3、编写容器管理脚本4、创建容器1、前言在日常开发全志、rk等不同

GSON框架下将百度天气JSON数据转JavaBean

《GSON框架下将百度天气JSON数据转JavaBean》这篇文章主要为大家详细介绍了如何在GSON框架下实现将百度天气JSON数据转JavaBean,文中的示例代码讲解详细,感兴趣的小伙伴可以了解下... 目录前言一、百度天气jsON1、请求参数2、返回参数3、属性映射二、GSON属性映射实战1、类对象映