Commit b0fa78aa by 王锐

第一次提交

parents
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<title></title>
</head>
<style>
#btn{
width: 100%;
height: 40px;
line-height: 40px;
text-align: center;
background: red;
}
#btn2{
width: 100%;
height: 40px;
line-height: 40px;
text-align: center;
background: red;
}
#reader{
width: 100%;
height: 40px;
line-height: 40px;
text-align: center;
background: red;
}
#filewrite{
width: 100%;
height: 40px;
line-height: 40px;
text-align: center;
background: red;
}
#filereader{
width: 100%;
height: 40px;
line-height: 40px;
text-align: center;
background: greenyellow;
}
#filedownload{
width: 100%;
height: 40px;
line-height: 40px;
text-align: center;
background: greenyellow;
}
</style>
<body>
<br>
<div id="btn">获取经纬度</div>
<br>
<div id="btn2">写文件</div>
<br>
<div id="reader">读文件</div>
<br>
<div id="list"> </div>
<br>
<div id="filewrite">创建文件夹</div>
<br>
<div id="filereader">读取文件夹</div>
<br />
<div id="filedownload">下载文件</div>
</body>
</html>
<script src="js/jquery-3.2.1.min.js" type="text/javascript" charset="utf-8"></script>
<script src="js/methods.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
document.addEventListener('plusready', function() {
var btn = document.getElementById('btn')
var btn2 = document.getElementById('btn2')
var data = JSON.stringify({
"employees": [{
"firstName": "Bil",
"lastName": "Gates"
},
{
"firstName": "George",
"lastName": "Bush"
},
{
"firstName": "Thomas",
"lastName": "Carter"
}
]
})
//获取经纬度
btn.onclick = function() {
latitude(success, error)
function success(res) {
alert("纬度:" + res.latitude + ", 经度:" + res.longitude)
};
function error(e) {}
}
//写文件
btn2.onclick = function() {
var name = "xxx";
function success(res) {
alert('ok')
}
function error(res) {}
write(name, data, success, error)
}
//读文件
$("#reader").on("click", function() {
let name = "xxx"
function success(res) {
let data = JSON.parse(res.target.result)
list.innerHTML = "<div style='background:red'>" + data.employees[0].firstName + "</div></br>"
$('#list').append("<div style='background:green' id=''aaaa'>" + data.employees[1].firstName + "</div>")
}
function error(res) {}
reader(name, success, error)
})
//读取指定文件夹文件
$("#filereader").on("click", function() {
let path = "abc/"
let name = "test"
function success(res) {
let data = JSON.parse(res.target.result)
list.innerHTML = "<div style='background:red'>" + data.employees[0].firstName + "</div></br>"
$('#list').append("<div style='background:green' id=''aaaa'>" + data.employees[1].firstName + "</div>")
}
function error(res) {}
readerFile(path, name, success, error)
})
//往指定文件夹新建文件
$("#filewrite").on("click", function() {
let path = "abc/"; //文件夹名,
let name = "test"; //文件名
// let data //文件内容
function success(res) {
alert('ok')
}
function error(res) {}
writeFile(path, name, data, success, error)
})
netChange(
function ntWifi() {
alert('wifi')
},
function nt4g() {
alert('4g')
},
function ntNo() {
alert('no')
},
)
}, false);
$("#filedownload").on("click", function() {
var arr=["http://img-cdn-qiniu.dcloud.net.cn/static/images/activity/plugin-side.png","https://www.baidu.com/img/bd_logo1.png"]
//http://img-cdn-qiniu.dcloud.net.cn/static/images/activity/plugin-side.png
// var downUrl = "https://www.baidu.com/img/bd_logo1.png"
var savePath = "image/"
function success(res) {
alert(res)
}
function error(res) {
alert(res)
}
for(var i=0; i<arr.length; i++){
fileDownload(arr[i], savePath, success, error);
}
})
</script>
This source diff could not be displayed because it is too large. You can view the blob instead.
function latitude(succ, error) {
plus.geolocation.getCurrentPosition(
function(res) {
//成功回调
var user_latitude = res.coords.latitude; //纬度
var user_longitude = res.coords.longitude; //经度
succ(res.coords)
},
//失败
function(e) {
error(
e
);
}
);
}
function write(name, data, success, error) {
plus.io.requestFileSystem(plus.io.PUBLIC_DOCUMENTS, function(fs) {
fs.root.getFile(name + '.json', {
create: true
}, function(fileEntry) {
fileEntry.file(function(file) {
var fileWrite = new plus.io.FileWriter;
fileEntry.createWriter(function(fileWrite) {
fileWrite.write(data);
fileWrite.onwrite = function(e) {
success(e)
}
})
});
}, function(e) {
error(e)
});
});
};
function reader(name, success, error) {
plus.io.requestFileSystem(plus.io.PUBLIC_DOCUMENTS, function(fs) {
fs.root.getFile(name + '.json', {
create: true
}, function(fileEntry) {
fileEntry.file(function(file) {
var fileReader = new plus.io.FileReader();
fileReader.readAsText(file, 'utf-8');
fileReader.onloadend = function(evt) {
success(evt)
}
});
},
function(e) {
error(e)
}
);
});
}
function netChange(ntWifi, nt4g, ntNo) {
document.addEventListener("netchange", onNetChange, false);
function onNetChange() {
//获取当前网络类型
var nt = plus.networkinfo.getCurrentType();
switch (nt) {
case plus.networkinfo.CONNECTION_ETHERNET:
case plus.networkinfo.CONNECTION_WIFI:
ntWifi();
break;
case plus.networkinfo.CONNECTION_CELL2G:
case plus.networkinfo.CONNECTION_CELL3G:
case plus.networkinfo.CONNECTION_CELL4G:
nt4g();
break;
default:
ntNo();
break;
}
}
}
function writeFile(path, name, data, success, error) {
plus.io.requestFileSystem(plus.io.PUBLIC_DOCUMENTS, function(fs) {
fs.root.getDirectory(path, {
create: true,
exclusive: false
}, function(dir) {
dir.getFile(name + ".josn", {
create: true
}, function(w) {
w.createWriter(function(write) {
write.seek(0);
write.write(data);
write.onwrite = function(e) {
success(e)
}
});
}, function(e) {
error(e)
});
}, function(e) {
error(e)
});
}, function(e) {
error(e)
})
}
function readerFile(path, name, success, error) {
plus.io.requestFileSystem(plus.io.PUBLIC_DOCUMENTS, function(fs) {
fs.root.getDirectory(path, {
create: true,
exclusive: false
}, function(dir) {
dir.getFile(name + ".josn", {
create: true
}, function(file) {
var fileReader = new plus.io.FileReader();
fileReader.readAsText(file, 'utf-8');
fileReader.onloadend = function(evt) {
success(evt)
}
}, function(e) {
error(e)
});
}, function(e) {
error(e)
});
}, function(e) {
error(e)
});
}
function fileDownload(downUrl, savePath, success, error) {
//处理链接后问号
var allUrl = downUrl.split("?")[0]
//获取文件名称
var filename = allUrl.substring(
allUrl.lastIndexOf("/") + 1,
allUrl.length
);
//修改为本地路径
var relativePath = "_downloads/" + savePath + filename;
//检查文件是否已存在
plus.io.resolveLocalFileSystemURL(
relativePath,
function(entry) {
console.log(savePath + "文件存在=" + relativePath);
//如果文件存在
function callback(res) {
error(res)
}
setUrlFromLocal(relativePath, callback)
},
function(e) {
console.log()
console.log(savePath + "文件不存在,联网下载=" + relativePath);
//如果文件不存在
downloadLocal(relativePath, savePath, success)
}
);
function downloadLocal(relativePath, savePath, success) {
var dtask = plus.downloader.createDownload(
allUrl, {
method: "GET",
filename: "_downloads/" + savePath
},
function(d, status) {
if (status == 200) {
//下载成功
console.log("下载成功=" + relativePath);
//d.filename
setUrlFromLocal(d.filename, callback)
function callback(res) {
alert(res)
}
} else {
//下载失败,需删除 本地临时文件,否则下次进来时会检查到文件已存在
console.log("下载失败=" + status + "==" + relativePath);
//dtask.abort();//文档描述:取消下载,删除临时文件(但经测试临时文件没有删除,故使用delFile()方法删除);
if (relativePath != null) {
delFile(relativePath);
}
}
}
);
dtask.start();
}
//本地相对路径("_downloads/logo.jpg")转成SD卡绝对路径("/storage/emulated/0/Android/data/io.dcloud.HBuilder/.HBuilder/downloads/logo.jpg");
function setUrlFromLocal(relativePath, callback) {
var sd_path = plus.io.convertLocalFileSystemURL(relativePath);
callback(sd_path)
}
function delFile(relativePath) {
plus.io.resolveLocalFileSystemURL(relativePath, function(entry) {
entry.remove(
function(entry) {
console.log("文件删除成功==" + relativePath);
},
function(e) {
console.log("文件删除失败=" + relativePath);
}
);
});
}
}
\ No newline at end of file
<!DOCTYPE HTML>
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8" />
<script type="text/javascript">
//压缩图片
function compressImage(){
plus.zip.compressImage({
src:"_www/a.jpg",
dst:"_downloads/a.jpg",
quality:20
},
function() {
alert("Compress success!");
},function(error) {
alert("Compress error!");
});
}
//缩放图片
function zoomImage(){
plus.zip.compressImage({
src:"_www/a.jpg",
dst:"_downloads/a.jpg",
width:"50%" // 缩小到原来的一半
},
function() {
alert("Compress success!");
},function(error) {
alert("Compress error!");
});
}
//旋转图片
function rotateImage(){
plus.zip.compressImage({
src:"_www/a.jpg",
dst:"_downloads/a.jpg",
rotate:90 // 旋转90度
},
function() {
alert("Compress success!");
},function(error) {
alert("Compress error!");
});
}
//裁剪图片
function clipImage(){
plus.zip.compressImage({
src:"_www/a.jpg",
dst:"_downloads/a.jpg",
clip:{top:"25%",left:"25%",width:"50%",height:"50%"} // 裁剪图片中心区域
},
function() {
alert("Compress success!");
},function(error) {
alert("Compress error!");
});
}
//格式转换
function convertImage(){
plus.zip.compressImage({
src:"_www/a.jpg",
dst:"_downloads/a.png",
format:"png" // 将jpg转换成png格式
},
function() {
alert("Compress success!");
},function(error) {
alert("Compress error!");
});
}
</script>
</head>
<body >
<button onclick="compressImage()">压缩图片</button><br/>
<button onclick="zoomImage()">缩放图片</button><br/>
<button onclick="rotateImage()">旋转图片</button><br/>
<button onclick="clipImage()">裁剪图片</button><br/>
<button onclick="convertImage()">格式转换</button><br/>
</body>
</html>
\ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
<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 rel="stylesheet" href="css/mui.min.css" />
<script type="text/javascript" src="js/mui.min.js"></script>
<style type="text/css">
.top {
margin-top: 40px;
}
.weixin {
width: 200px;
height: 50px;
margin-left: 50px;
background: url(../images/icon-weixin.png);
}
.zhifubao {
width: 200px;
height: 50px;
margin-left: 50px;
background: url(../images/alipay.jpg);
}
#jine{
-webkit-user-select:text;
text-align:right;
padding:0 1em;
border: 0px;
border-bottom:1px solid #ECB100;
border-radius: 0;
font-size:16px;
width:30%;
outline:none;
text-align:center;
}
</style>
</head>
<body>
<hrader class="mui-bar mui-bar-nav">
<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
<h1 class="mui-title">第三方支付</h1>
</hrader>
<div class="mui-content">
捐赠金额:<input id="jine" type="number" value="1" />
<div class="top" id="testLogin" >
<input type="button" class="weixin" id="weixin1" value="微信支付" />
<input type="button" class="zhifubao" id="zhifubao" value="支付宝支付" />
</div>
</div>
</body>
</html>
<script>
var wxChannel = null; // 微信支付
var aliChannel = null; // 付宝支付
var channel = null; //支付通道
mui.init({
swipeBack:true //启用右滑关闭功能
});
mui.plusReady(function() {
// 获取支付通道
plus.payment.getChannels(function(channels){
for (var i in channels) {
if (channels[i].id == "wxpay") {
wxChannel=channels[i];
}else{
aliChannel=channels[i];
}
}
},function(e){
alert("获取支付通道失败:"+e.message);
});
})
document.getElementById('weixin1').addEventListener('tap',function() {
console.log("微信");
pay('wxpay');
})
document.getElementById('zhifubao').addEventListener('tap',function() {
console.log("zhifubao");
pay('alipay');
})
var ALIPAYSERVER='http://demo.dcloud.net.cn/helloh5/payment/alipay.php?total=';
var WXPAYSERVER='http://demo.dcloud.net.cn/helloh5/payment/wxpay.php?total=';
// 2. 发起支付请求
function pay(id){
// 从服务器请求支付订单
var PAYSERVER='';
if(id=='alipay'){
PAYSERVER=ALIPAYSERVER;
channel = aliChannel;
}else if(id=='wxpay'){
PAYSERVER=WXPAYSERVER;
channel = wxChannel;
}else{
plus.nativeUI.alert("不支持此支付通道!",null,"捐赠");
return;
}
var xhr=new XMLHttpRequest();
var amount = document.getElementById('jine').value;
xhr.onreadystatechange=function(){
switch(xhr.readyState){
case 4:
if(xhr.status==200){
plus.payment.request(channel,xhr.responseText,function(result){
plus.nativeUI.alert("支付成功!",function(){
// back();
});
},function(error){
plus.nativeUI.alert("支付失败:" + error.code);
});
}else{
alert("获取订单信息失败!");
}
break;
default:
break;
}
}
xhr.open('GET',PAYSERVER+amount);
xhr.send();
}
</script>
\ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
{
{
"@platforms": ["android", "iPhone", "iPad"],
"id" : "H5580BA96",/*应用的标识,创建应用时自动生成,勿手动修改*/
"name" : "app",/*应用名称,程序桌面图标名称*/
"version": {
"name": "1.0.0",/*应用版本名称*/
"code": "83"
},
"description": "",/*应用描述信息*/
"icons": {
"72": "icon.png"
},
"launch_path": "index.html",/*应用的入口页面,默认为根目录下的index.html;支持网络地址,必须以http://或https://开头*/
"developer": {
"name": "",/*开发者名称*/
"email": "",/*开发者邮箱地址*/
"url": "http://www.dcloud.io"
},
"permissions": {
"Cache": {
"description": "管理应用缓存"
},
"Console": {
"description": "跟踪调试输出日志"
},
"Contacts": {
"description": "访问系统联系人信息"
},
"Events": {
"description": "应用扩展事件"
},
"Messaging": {
"description": "访问通讯能力"
},
"Maps": {
"description": "管理地图插件"
},
"Speech": {
"description": "管理语音识别插件"
}
},
"plus": {
"splashscreen": {
"autoclose": true,/*是否自动关闭程序启动界面,true表示应用加载应用入口页面后自动关闭;false则需调plus.navigator.closeSplashscreen()关闭*/
"waiting": true
},
"runmode": "liberate",/*应用的首次启动运行模式,可取liberate或normal,liberate模式在第一次启动时将解压应用资源(Android平台File API才可正常访问_www目录)*/
"signature": "Sk9JTiBVUyBtYWlsdG86aHIyMDEzQGRjbG91ZC5pbw==",/*可选,保留给应用签名,暂不使用*/
"distribute": {
"apple": {
"appid": "",/*iOS应用标识,苹果开发网站申请的appid,如io.dcloud.HelloH5*/
"mobileprovision": "",/*iOS应用打包配置文件*/
"password": "",/*iOS应用打包个人证书导入密码*/
"p12": "",/*iOS应用打包个人证书,打包配置文件关联的个人证书*/
"devices": "universal",/*iOS应用支持的设备类型,可取值iphone/ipad/universal*/
"frameworks": []
},
"google": {
"packagename": "",/*Android应用包名,如io.dcloud.HelloH5*/
"keystore": "",/*Android应用打包使用的密钥库文件*/
"password": "",/*Android应用打包使用密钥库中证书的密码*/
"aliasname": "",/*Android应用打包使用密钥库中证书的别名*/
"permissions": ["<uses-permission android:name=\"android.permission.CHANGE_NETWORK_STATE\"/>","<uses-permission android:name=\"android.permission.MOUNT_UNMOUNT_FILESYSTEMS\"/>","<uses-permission android:name=\"android.permission.READ_CONTACTS\"/>","<uses-permission android:name=\"android.permission.VIBRATE\"/>","<uses-permission android:name=\"android.permission.READ_LOGS\"/>","<uses-permission android:name=\"android.permission.ACCESS_WIFI_STATE\"/>","<uses-feature android:name=\"android.hardware.camera.autofocus\"/>","<uses-permission android:name=\"android.permission.WRITE_CONTACTS\"/>","<uses-permission android:name=\"android.permission.ACCESS_NETWORK_STATE\"/>","<uses-permission android:name=\"com.android.launcher.permission.UNINSTALL_SHORTCUT\"/>","<uses-permission android:name=\"android.permission.CAMERA\"/>","<uses-permission android:name=\"android.permission.GET_ACCOUNTS\"/>","<uses-permission android:name=\"android.permission.RECORD_AUDIO\"/>","<uses-permission android:name=\"android.permission.MODIFY_AUDIO_SETTINGS\"/>","<uses-permission android:name=\"com.android.launcher.permission.INSTALL_SHORTCUT\"/>","<uses-permission android:name=\"android.permission.READ_PHONE_STATE\"/>","<uses-permission android:name=\"android.permission.CHANGE_WIFI_STATE\"/>","<uses-permission android:name=\"android.permission.WAKE_LOCK\"/>","<uses-permission android:name=\"android.permission.FLASHLIGHT\"/>","<uses-permission android:name=\"android.permission.CALL_PHONE\"/>","<uses-permission android:name=\"android.permission.ACCESS_COARSE_LOCATION\"/>","<uses-feature android:name=\"android.hardware.camera\"/>","<uses-permission android:name=\"android.permission.ACCESS_FINE_LOCATION\"/>","<uses-permission android:name=\"android.permission.WRITE_SETTINGS\"/>"]
},
"orientation": ["portrait-primary", "portrait-secondary"],/*应用支持的方向,portrait-primary:竖屏正方向;portrait-secondary:竖屏反方向;landscape-primary:横屏正方向;landscape-secondary:横屏反方向*/
"icons": {
"ios": {
"prerendered": true, /*应用图标是否已经高亮处理,在iOS6及以下设备上有效*/
"auto": "", /*应用图标,分辨率:512x512,用于自动生成各种尺寸程序图标*/
"iphone": {
"normal": "",/*iPhone普通屏幕程序图标,分辨率:57x57*/
"retina": "",/*iPhone高分屏程序图标,分辨率:114x114*/
"retina7": "",/*iPhone iOS7高分屏程序图标,分辨率:120x120*/
"spotlight-normal": "", /*iPhone Spotlight搜索程序图标,分辨率:29x29*/
"spotlight-retina": "", /*iPhone高分屏Spotlight搜索程序图标,分辨率:58x58*/
"spotlight-retina7": "",/*iPhone iOS7高分屏Spotlight搜索程序图标,分辨率:80x80*/
"settings-normal": "", /*iPhone设置页面程序图标,分辨率:29x29*/
"settings-retina": ""
},
"ipad": {
"normal": "", /*iPad普通屏幕程序图标,分辨率:72x72*/
"retina": "", /*iPad高分屏程序图标,分辨率:144x144*/
"normal7": "", /*iPad iOS7程序图标,分辨率:76x76*/
"retina7": "", /*iPad iOS7高分屏程序图标,分辨率:152x152*/
"spotlight-normal": "", /*iPad Spotlight搜索程序图标,分辨率:50x50*/
"spotlight-retina": "", /*iPad高分屏Spotlight搜索程序图标,分辨率:100x100*/
"spotlight-normal7": "",/*iPad iOS7 Spotlight搜索程序图标,分辨率:40x40*/
"spotlight-retina7": "",/*iPad iOS7高分屏Spotlight搜索程序图标,分辨率:80x80*/
"settings-normal": "",/*iPad设置页面程序图标,分辨率:29x29*/
"settings-retina": ""
}
},
"android": {
"mdpi": "", /*普通屏程序图标,分辨率:48x48*/
"ldpi": "", /*大屏程序图标,分辨率:48x48*/
"hdpi": "", /*高分屏程序图标,分辨率:72x72*/
"xhdpi": "",/*720P高分屏程序图标,分辨率:96x96*/
"xxhdpi": ""
}
},
"splashscreen": {
"ios": {
"iphone": {
"default": "", /*iPhone3启动图片选,分辨率:320x480*/
"retina35": "",/*3.5英寸设备(iPhone4)启动图片,分辨率:640x960*/
"retina40": ""
},
"ipad": {
"portrait": "", /*iPad竖屏启动图片,分辨率:768x1004*/
"portrait-retina": "",/*iPad高分屏竖屏图片,分辨率:1536x2008*/
"landscape": "", /*iPad横屏启动图片,分辨率:1024x748*/
"landscape-retina": "", /*iPad高分屏横屏启动图片,分辨率:2048x1496*/
"portrait7": "", /*iPad iOS7竖屏启动图片,分辨率:768x1024*/
"portrait-retina7": "",/*iPad iOS7高分屏竖屏图片,分辨率:1536x2048*/
"landscape7": "", /*iPad iOS7横屏启动图片,分辨率:1024x768*/
"landscape-retina7": ""
}
},
"android": {
"mdpi": "", /*普通屏启动图片,分辨率:240x282*/
"ldpi": "", /*大屏启动图片,分辨率:320x442*/
"hdpi": "", /*高分屏启动图片,分辨率:480x762*/
"xhdpi": "", /*720P高分屏启动图片,分辨率:720x1242*/
"xxhdpi": ""
}
}
}
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment