敬告:此 demo 演示为开放测试页面,仅用于开发者快速测试体验应用功能,请严格遵守开发者协议,云顶集团3118-云顶集团3118acm登录入口。
♦ js-sdk 引用方式:
♦ 普通网页 script 方式加载:下载最新版 ,请在页面上调用 jsbridge 接口之前引用 jsbridge-mini.js 库;
♦ js module 方式引用:npm install ym-jsbridge
♦ app端文件及目录管理;
♦ 提供本地文件/目录/下载/解压/哈希/分享/打开等操作接口;
♦ 本地文件路径规则:fs://{maindirectory}/yourpath
♦ 仅允许如下两个主目录:
一般文件目录 fs://file/yourpath
缓存文件目录 fs://cache/yourpath
jsbridge.fs.mkdir("fs://file/my_dir/", function(succ, msg){ alert(succ ? "创建成功" : msg); });
jsbridge.fs.exist("fs://file/my_dir/", function(succ, msg){ alert(succ ? "存在" : "不存在"); });
jsbridge.fs.exist("fs://file/my_dir/my.txt", function(succ, msg){ alert(succ ? "存在" : "不存在"); });
• 回调参数 data 中以斜杠 / 结束的是子目录,否则是文件。
jsbridge.fs.list("fs://file/", function(succ, data) { alert("succ:" succ "\n" json.stringify(data)); });
• 回调参数 data 中以斜杠 / 结束的是子目录,否则是文件。
jsbridge.fs.list("fs://file/my_dir/", function(succ, data) { alert("succ:" succ "\n" json.stringify(data)); });
• 如果文件不存在则返回 0
jsbridge.fs.size("fs://file/my_dir/my.txt", function(succ, data) { alert("succ:" succ "\n" data); });
• 如果指定的是目录,则会删除此目录及其目录下的所有文件。
jsbridge.fs.delete("fs://file/my_dir/", function(succ, msg) { alert(succ ? "删除成功" : msg); });
jsbridge.fs.writetext( //文件路径,不存在则创建,已存在则覆盖 "fs://file/my_dir/my.txt", //文本内容(utf8编码) "hello world!\n你好,世界!", //回调 function(succ, msg) { alert(succ ? "写入成功" : msg); } );
jsbridge.fs.appendtext( //文件路径,不存在则创建,已存在则追加到文件末尾 "fs://file/my_dir/my.txt", //文本内容(utf8编码) "\n这是追加的文本...", //回调 function(succ, msg) { alert(succ ? "追加成功" : msg); } );
jsbridge.fs.readtext("fs://file/my_dir/my.txt", function(succ, data) { alert("succ:" succ "\n" data); });
jsbridge.fs.writebinary( //文件路径,不存在则创建,已存在则覆盖 "fs://file/my_dir/love.png", //二进制的base64编码串(这是一张 png 图片) "ivborw0kggoaaaansuheugaaaekaaabacayaaabwffouaaajq0leqvr4xuwcd4wcdrxhv2/29relfykiqwl3t4dyt7olokeofdap2ntwfmxatvdaukt xngakohvg0tarfwrbrptkbaoluov wnqchyu/g8dqdheztts3s2ebwml2ck2o3v3e2b2dq 7s7ozo/vn7nr9jztlzn7v/d7vm2/evpn93hyhzpamrj6reu8forukrez8bu4bcnd5excqmz2/gzosptwpn72zzigxiyys/abzpnqsijqjgznw9heagn3q0a1gt1jqc6k3r7oemakwysmmrgbjjpd9nrxeb4oea/hzdmlrj 4 0lotbnfpy2lur67wcdoycv61ctl zpuztmc05mfikfu3gwqbbijkrcoxaepgee0nopc7pwpvamrrvt ts/tafy nlzlbnkwfekfiupqad9q7locxqvip99jrq9vvfsthunlwlqbxvqs4ql9 ahfrln2lw8aiijtbubfakic qroy8bra9yes9jovbcpcmlojm6b4nybobwuzaacavaxmayby4tihc/epxmkqae egkvtlt1ltbbng7acll2dk7v6x71tt2zhaco2x0igjcwg gc 8n8fujmvp 4xhp8pxcr 4ilq2hqinztb48vonaesy chbjzhm 7vabwk5i16kvnqux7bj4tp0zsawuuce0m37avl6sklyzdhlqbd4ini3mka3zfosr tdjnd55oty1o17l/etisavonhgyoitfpbru5ymdccjxstc0nxir94qlu2jw/pg2zmbgdgag9d3ixijfgezjqgrrr7d8xc52ikfgdcjiq6nitcukkwog7dziz8vwa6d8ayj3e36pb9jffxekhgthwpjns8fbjct59p/cu9o kkanqwouj2el7rexhwjfppxdfeha6g1rerkcd8hqf a bd7o7mdfmilb678hgrpksmxergjzxibotbdrdcjmcmdstexmw4h8chxwk36jz9rwbvgbqaumxl4fnuiy1xexvkfjh/3avjbczgukton27zbumdgvnnzymaphdezkpiagk2m9n39fs65ijvoytih0okjadd5tnbnwff0lyth5zjg5bywbtjgoxtcegbhbeobklm4k6omkqrpshmlxq48wf9an6tri7fx4iopq3u91oeajm o 086zrekh jtfoinsfkiywdmxbrwrkxf0os4iuau4qiel9bkuhnwwi4juaxmvopexlw6uj635matig3qfkgrypqktd4h0lafcdvy3qsgrxzmvd8tspcqacyf/szwkz5n5g3htkz5w37sh ojlrvoiyujjdnltbd9 pw5htzseysshlmxytyn8i8vzzikiih xmea6u7tkbfv8zco/uapbzyzs54urfsiqoqpngnzjc4so0iw m99vnljdwk bwalw/05xvipzklwzgxro/p5udov8stkzvumrvlsivby21imhqztssbc8ef1c37skybo1z6tcnwmrcwkc4dsykpxxicvl94ol/x wf2zrz6gwti4tywlwwwtw9i7jqcoawpvgjgkakxmtvjiikhwfhkwyndumwplwekkcp7bl5q1uw61fficeymmwmwxdqbhol1mmx4aqznkwjcb g99se9ddfbhc4ktvif6rnpje/jlo2mqmziyqcif0xql njjhjtg0gb8wg8zc/zmnlxvmzxblifu7fsoix1tjayphgcqggcfytmkq5z8rvxhv6rha6ezds8kijwgngxnrjvhi1gcudhspfjilskm299zeixt htmpflpwvf4xm0t8gjpkzl8rgssddyey2oebb0neyz8b6zufeyewpyinprt9ix1tlaajaxzoqfgatxkfeqgrmpm6pj6atpgg6lb9/brspeg8zbkjh9advr8/mwdglsjxj4dqgifkvtzzrgezgicsohb3yththeaaszxqeugzmmgz8upkgbfrdbawej87hqxok1gx4gbkkmfp8b8l5biow/6yn7c8cviecdnhp tmsjgdfn4au3ktadchmrm4hpbctc 7ecoindkwnk3p56e69lj89cssrw9qt6regeno2bujw /lizzl12mjkyishxufss1y37yiykxaepg5/uy2wjgjwevammf4gizsv70psk1rgjn4pzvtphuq9v71ubafjjkr4i4cqxxb/tltubgg1c2nmaxh5qec7yycrx51enyoigbwdrz90xjqa hbf6xiicnbdavqwy j7ekfl9lisr26t8sykgeibupqfju8kortfqnkpeb7vypn0 1dhjysg0duwhoblniwhpbdujdf6pzy2aicu2aj90dzzaqjmxyexm3uqb8z3qs1vd62q vsxivwdgjtzq2wo9ymfnqktzoi dbav3ld5 pr5psoeuslwmflcgff8asnfryn6bqzur3at4h4atjnvqyahyqiqnqqgvpn3kozuhhvnu/p5jfvsxdf lgr6qbvdvkllpgrtoor9ta1nurnown2lha8dkwxrwbb1cxdutkehsir3kvfhuuifrzen3qpquy/uyku2ago5akhiezxlv4o40j0rkycic31vrlvyofxhsdtsbad46um89mxpzwsrfjx15w4n4uf6mjkiosclfkl0vylk3huzbz5dckzpf0qgpqhtszqpeahdwspeon6lyqdhipz apsmvyjdcqug5z7hbea1p13ol1r2t3edmmhjf88shxu16yl7w7kdzmwefypmqtdsqkecbltnuzgbfwrkxvpkv9xyzatuu0kcmcj8dkfedzcwpxgqb5aoiwallgrudx3dmck/okmkpgnpxgjtlgz j92s wqsmlxkfqblwanqjadxck/ktsurxjwjmlu5uojq1xla gi6wujmbcahpklk3xkz8eyw5jy9t5pxxvobrtyiqb8ip/obssxsnqkmqcnmuu3/o1cewnqatsljpg4kc8vggg6zungyaajokp1aardgt9lxvgvib9dyrna9zgiyeki8owlq9xy4savvkvg4qgf tfm9vjqahg tvufi1btnujcfbwd4etfdj1dge6nuuwm stv/duwa/qwwppgmugbv0lh2fw9yhuc gooaqrhpiivxwqee4n5y5x2b ywjodmlisbsipwexw9o4o73buxi/vm/xkxtysbvaof8notpny i3wdzh9wx3qifuezt3tm1 4gvn9mrebwaieedjeypkxqisvapduojw 3cdzqq3lldb4yt83ujzj991stnutxqf6w4mibhrsxndkhnapmpaaagdns8xnd9rypynwc8nupl1wwunp 7/ayc fgcch4c2aaaaaelftksuqmcc", //回调 function(succ, msg) { alert(succ ? "写入成功" : msg); } );
jsbridge.fs.appendbinary( //文件路径,不存在则创建,已存在则追加到文件末尾 "fs://file/my_dir/my.bin", //二进制的base64编码串 "xg7ov5nmmk/ov73liqdnmotmlofmnkwuli4=", //回调 function(succ, msg) { alert(succ ? "追加成功" : msg); } );
jsbridge.fs.readbinary("fs://file/my_dir/my.bin", function(succ, data) { //data参数返回base64串,请自行转码 alert("succ:" succ "\n" data); });
jsbridge.fs.copy( //源文件 "fs://file/my_dir/my.txt", //复制为目标文件 "fs://file/my_dir/my_copy.txt", //回调 function(succ, msg) { alert(succ ? "复制成功" : msg); } );
• 转换为 file:///... 形式
jsbridge.fs.touri("fs://file/my_dir/www/index.html", function(succ, data) { alert("succ:" succ "\n" data); });
jsbridge.fs.toabsolute("fs://file/my_dir/my.txt", function(succ, data) { alert("succ:" succ "\n" data); });
file:
jsbridge.fs.share("{{share1.file}}", function(succ, msg) { if (!succ) { alert(msg); } });
jsbridge.fs.share("fs://file/my_dir/love.png", function(succ, msg) { if (!succ) { alert(msg); } });
jsbridge.fs.open("fs://file/my_dir/my.txt", function(succ, msg) { if (!succ) { alert(msg); } });
• 记录文件下载状态,已下载的可以避免重复下载;
• 支持断点续传;
• 支持下载完成后自动打开文件;
url:
path:
force:
autoopen:
jsbridge.fs.download({ //get请求的网络链接 url : "{{download1.url}}", //下载保存到本地文件 path : "{{download1.path}}", //如果文件已经下载过了,是否强制重新下载,默认false (仅安卓) //true 时重新下载文件 //false 时不重新下载 force : {{download1.force}}, //下载完成后是否自动打开文件,默认 false (仅安卓) autoopen: {{download1.autoopen}}, //下载进度回调 progress: function(total, loaded) { console.log("共" total "字节,已下载" loaded); } }, //下载结束回调 function(succ, msg) { alert(succ ? "下载成功" : msg); } );
url:
path:
jsbridge.fs.download({ //get请求的网络链接 url : "{{download2.url}}", //下载保存到本地文件 path : "{{download2.path}}", //true 始终下载,false 如果已经下载过了就不再下载 force : true, //下载进度回调 progress: function(total, loaded) { console.log("共" total "字节,已下载" loaded); } }, //下载结束回调 function(succ, msg) { alert(succ ? "下载成功" : msg); } );
jsbridge.fs.download({ //get请求的网络链接 url : "https://www.yimenapp.com/doc/doc.pdf", //下载保存到本地文件 path : "fs://file/my_dir/doc.pdf", //下载完成是否自动打开文件,默认 false (仅安卓) autoopen: true, //下载进度回调 progress: function(total, loaded) { console.log("共" total "字节,已下载" loaded); } }, //下载结束回调 function(succ, msg) { if (!succ) { alert("下载失败:" msg); } } );
var url = "https://www.yimenapp.com/doc/doc.pdf"; var path = "fs://file/my_dir/doc.pdf"; jsbridge.fs.exist(path, function(succ, msg){ if (succ) { //使用 插件打开 jsbridge.txdoc.open({ file: path }); } else { alert("本地文件不存在,准备下载。"); jsbridge.fs.download({ //get请求的网络链接 url : url, //下载保存到本地文件 path : path, //下载进度回调 progress: function(total, loaded) { console.log("共" total "字节,已下载" loaded); } }, //下载结束回调 function(succ, msg) { if (succ) { alert("下载完成,准备打开。"); jsbridge.txdoc.open({ file: path }); } else { alert("下载失败:" msg); } } ); } });
var url = "http://1252463788.vod2.myqcloud.com/95576ef5vodtransgzp1252463788/e1ab85305285890781763144364/v.f10.mp4"; var path = "fs://file/my_dir/f10.mp4"; jsbridge.fs.exist(path, function(succ, msg){ if (succ) { //使用 超级播放器 插件原生播放本地视频 jsbridge.txvideo.play(path); } else { alert("本地文件不存在,准备下载。"); jsbridge.fs.download({ //get请求的网络链接 url : url, //下载保存到本地文件 path : path, //下载进度回调 progress: function(total, loaded) { console.log("共" total "字节,已下载" loaded); } }, //下载结束回调 function(succ, msg) { if (succ) { alert("下载完成,准备播放。"); jsbridge.txvideo.play(path); } else { alert("下载失败:" msg); } } ); } });
jsbridge.fs.download({ //下载链接 url : "https://www.yimenapp.com/doc/www.zip", //保存为 path: "fs://file/my_dir/www.zip" }, function(succ, msg) { if (succ) { alert("下载成功"); //解压 jsbridge.fs.unzip({ //要解压的 zip 文件 src: "fs://file/my_dir/www.zip", //解压到哪个目录 dst: "fs://file/my_dir/", //密码 pwd: "" }, function(succ, msg) { alert(succ ? "解压成功" : msg); }); } else { alert("下载失败" msg); } });
jsbridge.fs.download({ url : "https://www.yimenapp.com/doc/www-with-password.zip", path: "fs://file/my_dir/www-with-password.zip" }, function(succ, msg) { if (succ) { alert("下载成功"); //解压 jsbridge.fs.unzip({ //要解压的 zip 文件 src: "fs://file/my_dir/www-with-password.zip", //解压到哪个目录 dst: "fs://file/my_dir/", //密码 pwd: "123456" }, function(succ, msg) { alert(succ ? "解压成功" : msg); }); } else { alert("下载失败" msg); } });
jsbridge.fs.list("fs://file/my_dir/www/", function(succ, data) { alert("succ:" succ "\n" json.stringify(data)); });
• 计算文件 md5 哈希值
jsbridge.fs.md5("fs://file/my_dir/doc.pdf", function(succ, data) { alert("succ:" succ "\n" data); });
• 计算文件 sha1 哈希值
jsbridge.fs.sha1("fs://file/my_dir/doc.pdf", function(succ, data) { alert("succ:" succ "\n" data); });
• 计算文件 sha256 哈希值
jsbridge.fs.sha256("fs://file/my_dir/doc.pdf", function(succ, data) { alert("succ:" succ "\n" data); });