You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
405 lines
15 KiB
405 lines
15 KiB
<template>
|
|
<view class="content" style="margin-left: 200px;">
|
|
<!-- <button type="primary" @click="hq()">唤起app</button> -->
|
|
<button type="primary" @click="connectFtpServer()">FTP连接</button>
|
|
<button type="primary" @click="ftpUploadFiles()">FTP上传文件夹</button>
|
|
<button type="primary" @click="ftpCreatNewDirectory()">FTP新建文件夹</button>
|
|
<button type="primary" @click="ftpUploadFile()">FTP上传文件</button>
|
|
<button type="primary" @click="ftpDownloadSingleFile()">FTP单个文件下载</button>
|
|
<button type="primary" @click="ftpLoopServerPath()">获取目录</button>
|
|
<button type="primary" @click="ftpDeleteServerFiles()">删除文件</button>
|
|
<button type="primary" @click="ftpDeleteServerFilesWithoutDirectory()">删除文件夹下面文件保留文件夹</button>
|
|
<button type="primary" @click="closeFTPConnect()">FTP断开连接</button>
|
|
<button type="primary" @click="closeSetTime()">刘灿-FTP暂停循环</button>
|
|
<button type="primary" @click="turnUrl()">刘灿-FTP本地文件转URL</button>
|
|
<button type="primary" @click="deleteAppDownLoadFile()">刘灿-删除安卓机目录文件</button>
|
|
|
|
<button type="primary" style="margin-top: 16px;" @click="connectFtpsServer()">FTPS连接</button>
|
|
<button type="primary" @click="ftpsUploadFiles()">FTPS上传文件夹</button>
|
|
<button type="primary" @click="ftpsCreatNewDirectory()">FTPS新建文件夹</button>
|
|
<button type="primary" @click="ftpsUploadFile()">FTPS上传文件</button>
|
|
<button type="primary" @click="ftpsDownloadSingleFile()">FTPS单个文件下载</button>
|
|
<button type="primary" @click="ftpsLoopServerPath()">ftps获取目录</button>
|
|
<button type="primary" @click="ftpsDeleteServerFiles()">ftps删除文件</button>
|
|
<button type="primary" @click="ftpsDeleteServerFilesWithoutDirectory()">ftps删除文件夹下面文件保留文件夹</button>
|
|
<button type="primary" @click="closeFTPSConnect()">FTPS断开连接</button>
|
|
<view class="webViewClass" style="height: 50vh;">
|
|
<web-view ref="webViewRef" @message="messageData" src="http://192.168.0.35:8001/wz_qg/ftpCs"
|
|
:fullscreen="false" :webview-styles="webviewStyles"></web-view>
|
|
</view>
|
|
</view>
|
|
</template>
|
|
|
|
<script>
|
|
var FTP = uni.requireNativePlugin('Zhimi-FTP-Module');
|
|
export default {
|
|
data() {
|
|
return {
|
|
title: 'Hello',
|
|
setInterTime: null,
|
|
remoteUrl: '',
|
|
webviewStyles: {
|
|
width: '300px',
|
|
height: '500px',
|
|
left: '0px',
|
|
top: '200px'
|
|
// top: '100px'
|
|
},
|
|
androidFileDocPath: '',
|
|
ftpLogicDeceteName: '/sda1/logicDelete',
|
|
currentfolderList:[],
|
|
flag:true,
|
|
loopI:0
|
|
}
|
|
},
|
|
onLoad() {
|
|
// console.log(plus.io.convertLocalFileSystemURL('ceshi'));
|
|
},
|
|
methods: {
|
|
// hq() {
|
|
// plus.runtime.launchApplication({
|
|
// packageName: 'com.baidu.BaiduMap'
|
|
// }, function() {
|
|
// console.log('唤醒支付宝成功');
|
|
// }, function(e) {
|
|
// console.error('唤醒支付宝失败: ' + e.message);
|
|
// })
|
|
// },
|
|
// 流程:
|
|
// ftp连接 ---> 获取ftp目录文件夹名和文件名 ---> 下载文件夹中的文件到安卓机 ---> 临时地址转url传输给H5展示
|
|
// ---> H5页面关联确认完,在安卓机中找到关联确认后的文件上传到FTP的另外一个文件夹(新建文件夹) ---> 删除安卓机临时文件 ---> 删除FTP之前文件夹中关联确认后的文件
|
|
// FTP连接
|
|
connectFtpServer() {
|
|
//(“服务地址”, 端口, “用户名”,”密码“, 回调 )
|
|
//回调
|
|
//成功 {type : "connect", data : {data : "相应状态码:200 连接是否成功:true 连接是否有效:true}}
|
|
//失败 {type : "connect", data : {"error" : "失败原因"}}
|
|
// "192.168.50.1", 21, "hmgc", "hmgc"
|
|
// "192.168.50.131", 21, "hmftp", "hmftp"
|
|
FTP.connectFtpServer("192.168.50.1", 21, "hmgc", "hmgc", "gbk", res => {
|
|
console.log(res)
|
|
})
|
|
},
|
|
// 获取FTP服务器目录
|
|
ftpLoopServerPath(name,index,text) {
|
|
// 1是文件夹 0是文件
|
|
//("获取服务器目录下文件,空白为根目录", 回调)
|
|
//回调
|
|
//成功 {type : getFileInfo, data : [{name : "地址", size : 文件大小单位字节, time : “修改时间”}]}
|
|
//失败 {type : "error", data : "失败原因"}
|
|
let pathName = name ? name : '/sda1/deviceNewFile'
|
|
console.log('pathName', pathName);
|
|
if(text==='不走循环') {
|
|
FTP.ftpLoopServerPath(pathName,res=>{
|
|
this.webViewToH5(res)
|
|
})
|
|
} else {
|
|
FTP.ftpLoopServerPath(pathName, res => {
|
|
console.log('res', res)
|
|
|
|
if(res.data.length > 0 && res.data[0].type===1) {
|
|
console.log('type=1',res.data);
|
|
this.currentfolderList = res.data
|
|
} else if(res.data.length > 0 && res.data[0].type ===0) {
|
|
this.flag = true
|
|
this.loopI++;
|
|
} else if (res.data.length <=0) {
|
|
this.currentfolderList.splice(index,1)
|
|
console.log('空文件夹',this.currentfolderList);
|
|
this.flag = true
|
|
}
|
|
})
|
|
|
|
setTimeout(()=>{
|
|
while (this.flag === true && this.loopI <= this.currentfolderList.length -1) {
|
|
this.flag = false
|
|
this.ftpLoopServerPath(this.currentfolderList[this.loopI].name,this.loopI)
|
|
console.log('结果',this.currentfolderList);
|
|
}
|
|
},150)
|
|
|
|
if(this.loopI == this.currentfolderList.length -1) {
|
|
this.webViewToH5({
|
|
type:'getFileInfo',
|
|
data:this.currentfolderList
|
|
})
|
|
}
|
|
}
|
|
|
|
},
|
|
// uniapp 传参给 vue页面---刘灿测试
|
|
webViewToH5(res) {
|
|
let currentWebview = this.$scope.$getAppWebview();
|
|
let wv = currentWebview.children()[0];
|
|
console.log('uniapp 传参给 vue页面');
|
|
wv.evalJS(`getVueMessage(${JSON.stringify(res)})`);
|
|
this.currentfolderList = []
|
|
this.loopI = 0
|
|
},
|
|
// uniapp vue页面传参给UNI ---刘灿测试
|
|
messageData(e) {
|
|
console.log('接收的VUE参数', e.detail.data[0]) // 接收的参数
|
|
let vueDetail = e.detail.data[0]
|
|
if (vueDetail.type === 'getFileInfo') {
|
|
console.log('vueDetail.data', vueDetail.data);
|
|
this.ftpLoopServerPath(vueDetail.data.name,'','不走循环')
|
|
} else if (vueDetail.type === 'getUrlInfo') {
|
|
this.ftpDownloadSingleFile(vueDetail.data)
|
|
} else if (vueDetail.type === 'sendCorrelationConfirm') {
|
|
// 判断logicDelete逻辑删除备份的文件夹中是否有此文件夹
|
|
this.isHaveCurrentFileFolder(vueDetail.data)
|
|
}
|
|
},
|
|
// FTP-单个文件下载至安卓机
|
|
ftpDownloadSingleFile(data) {
|
|
//("要下载到本地文件夹的绝对路径", "要下载的服务器上文件的绝对路径", 回调)
|
|
//回调
|
|
//{type : download, data : {status : true/false, name : "下载的文件名", errpr : "失败原因"}}
|
|
// var inputFile = plus.io.convertLocalFileSystemURL('/static')
|
|
this.androidFileDocPath = plus.io.convertLocalFileSystemURL('_doc')
|
|
console.log(this.androidFileDocPath)
|
|
// '/sda1/deviceNewFile/20240918/20240918logo.png'
|
|
FTP.ftpDownloadSingleFile(this.androidFileDocPath, data.name, res => {
|
|
console.log('单个文件下载至安卓机--成功', res)
|
|
this.turnUrl(data)
|
|
})
|
|
},
|
|
// 获取本地文件路径并转换为远程URL---刘灿测试
|
|
turnUrl(data) {
|
|
var androidFileNamePath = this.androidFileDocPath + data.fileName
|
|
console.log('androidFileNamePath', androidFileNamePath);
|
|
plus.io.resolveLocalFileSystemURL(androidFileNamePath, (entry) => {
|
|
this.remoteUrl = entry.toRemoteURL();
|
|
console.log('Remote URL:', this.remoteUrl);
|
|
this.webViewToH5({
|
|
type: 'getUrlInfo',
|
|
url: this.remoteUrl
|
|
})
|
|
}, function(e) {
|
|
console.log('文件路径解析失败', e);
|
|
})
|
|
},
|
|
// 判断logicDelete逻辑删除备份的文件夹中是否有此文件夹
|
|
isHaveCurrentFileFolder(data) {
|
|
let nameArr = data.name.split("/")
|
|
let folderName = nameArr[nameArr.length - 2]
|
|
// 获取FTP服务器目录
|
|
FTP.ftpLoopServerPath(this.ftpLogicDeceteName, res => {
|
|
let index = res.data.findIndex(item => item.fileName == folderName)
|
|
console.log('判断logicDelete逻辑删除备份的文件夹中是否有此文件夹', index);
|
|
if (index === -1) {
|
|
this.ftpCreatNewDirectory(data, folderName)
|
|
} else {
|
|
this.ftpUploadFile(data, folderName)
|
|
}
|
|
})
|
|
},
|
|
// FTP-新建文件夹至FTP
|
|
ftpCreatNewDirectory(data, folderName) {
|
|
FTP.ftpCreatNewDirectory(this.ftpLogicDeceteName, folderName, res => {
|
|
// 上传文件至服务器
|
|
this.ftpUploadFile(data,folderName)
|
|
console.log('新建文件夹成功',res)
|
|
})
|
|
// let index = 0
|
|
// 循环暴击测试
|
|
// setInterval(() => {
|
|
// let fileIndexName = `2024${index++}`
|
|
// FTP.ftpCreatNewDirectory('/sda1/deviceNewFile', fileIndexName, res => {
|
|
// var inputFile = plus.io.convertLocalFileSystemURL('/static/logo.png')
|
|
// // 上传文件至服务器
|
|
// FTP.ftpUploadFile(inputFile, `/sda1/deviceNewFile/${fileIndexName}`,
|
|
// res => {
|
|
// console.log('获取安卓手机文件夹中的文件---刘灿测试', '文件-上传成功');
|
|
// console.log(res)
|
|
// })
|
|
// })
|
|
// }, 2000)
|
|
|
|
},
|
|
// FTP-上传文件夹至服务器FTP
|
|
ftpUploadFiles() {
|
|
//(“要上传的本地文件绝对路径”, “服务器文件夹名(/htdocs/fileName)”, 回调)
|
|
//回调
|
|
//{type : "upload", data : {path : "本地上传文件地址", status : true/false, msg : "上传完成", error : "失败原因"}}
|
|
// /storage/emulated/0/Download/downladed_rom
|
|
var inputFile = plus.io.convertLocalFileSystemURL('/static')
|
|
FTP.ftpUploadFile(inputFile, "/sda1", res => {
|
|
console.log(res)
|
|
})
|
|
},
|
|
// FTP-上传文件至FTP
|
|
ftpUploadFile(data, folderName) {
|
|
// var inputFile = plus.io.convertLocalFileSystemURL('/static/ceshi.txt')
|
|
// console.log('inputFile文件', inputFile);
|
|
// //同上
|
|
// FTP.ftpUploadFile(inputFile, `/sda1/deviceNewFile/${ftpFwqName}`, res => {
|
|
// console.log(ftpFwqName, '文件-上传成功');
|
|
// console.log(res)
|
|
// })
|
|
|
|
// 获取安卓手机文件夹中的文件并上传至ftp服务器---刘灿测试
|
|
var detailFileName = this.androidFileDocPath + data.fileName
|
|
FTP.ftpUploadFile(detailFileName, `${this.ftpLogicDeceteName}/${folderName}`, res => {
|
|
console.log('获取安卓手机文件夹中的文件---刘灿测试', '文件-上传成功');
|
|
console.log(res)
|
|
this.deleteAppDownLoadFile(data.fileName)
|
|
this.ftpDeleteServerFiles(data.name,folderName)
|
|
})
|
|
},
|
|
// 删除安卓机下载下来的文件---刘灿测试
|
|
deleteAppDownLoadFile(fileName) {
|
|
// 获取安卓机路径地址
|
|
var deleteAppFileName = this.androidFileDocPath + fileName
|
|
plus.io.resolveLocalFileSystemURL(deleteAppFileName, function(entry) {
|
|
// 调用 remove 方法删除文件
|
|
entry.remove(() => {
|
|
console.log('文件删除成功');
|
|
}, (error) => {
|
|
console.log('文件删除失败: ' + error.message);
|
|
});
|
|
}, (error) => {
|
|
console.log('无法解析文件路径: ' + error.message);
|
|
})
|
|
},
|
|
// 删除FTP服务器文件
|
|
ftpDeleteServerFiles(name,folderName) {
|
|
//("要删除的文件夹或文件地址", 回调)
|
|
//回调
|
|
//{type : delete, data : {msg : "删除文件/删除文件夹(ps:先删除文件夹里面的文件再删文件夹)", data : "文件名", status : true/false, error : "失败原因"}}
|
|
FTP.ftpDeleteServerFiles(name, res => {
|
|
console.log('FTP服务器文件删除成功', res)
|
|
})
|
|
// this.ftpLoopServerPath()
|
|
setTimeout(()=>{
|
|
console.log('删除后获取目录-路径',`/sda1/deviceNewFile/${folderName}`);
|
|
FTP.ftpLoopServerPath(`/sda1/deviceNewFile/${folderName}`,res=>{
|
|
console.log('删除后获取目录',res);
|
|
this.webViewToH5(res)
|
|
})
|
|
},2000)
|
|
},
|
|
// 删除FTP文件夹下面文件保留文件夹
|
|
ftpDeleteServerFilesWithoutDirectory() {
|
|
//同上,不会删除指定文件夹
|
|
FTP.ftpDeleteServerFilesWithoutDirectory("/sda1/deviceNewFile", res => {
|
|
console.log(res)
|
|
})
|
|
},
|
|
// 关闭循环---刘灿测试
|
|
closeSetTime() {
|
|
console.log('停止循环');
|
|
clearInterval(this.setInterTime)
|
|
},
|
|
|
|
// FTP断开连接
|
|
closeFTPConnect() {
|
|
console.log('点到了!!!!');
|
|
//失败有回调,成功没有回调
|
|
FTP.closeFTPConnect(res => {
|
|
console.log(res)
|
|
})
|
|
},
|
|
|
|
// ----------ftps----------
|
|
|
|
// FTPS连接
|
|
connectFtpsServer() {
|
|
FTP.connectFtpsServer("192.168.0.8", 21, "hmftp", "hmftp", "gbk", res => {
|
|
console.log(res)
|
|
})
|
|
},
|
|
// FTPS上传文件夹至服务器
|
|
ftpsUploadFiles() {
|
|
var inputFile = plus.io.convertLocalFileSystemURL('/static')
|
|
console.log('inputFile文件夹', inputFile);
|
|
FTP.ftpsUploadFile(inputFile, "/sda1", res => {
|
|
console.log(res)
|
|
})
|
|
},
|
|
// FTPS上传文件
|
|
ftpsUploadFile() {
|
|
var inputFile = plus.io.convertLocalFileSystemURL('/static/ceshi.txt')
|
|
FTP.ftpsUploadFile(inputFile, "/sda1", res => {
|
|
console.log(res)
|
|
})
|
|
},
|
|
// FTPS新建文件夹
|
|
ftpsCreatNewDirectory() {
|
|
FTP.ftpsCreatNewDirectory("/sda1", "newDirectory", res => {
|
|
console.log(res)
|
|
})
|
|
},
|
|
// FTPS单个文件下载
|
|
ftpsDownloadSingleFile() {
|
|
var outputFile = plus.io.convertLocalFileSystemURL('_doc')
|
|
console.log('outputFile', outputFile);
|
|
FTP.ftpsDownloadSingleFile(outputFile, "/sda1/ceshi.txt", res => {
|
|
console.log(res)
|
|
})
|
|
},
|
|
// 获取FTPS服务器目录
|
|
ftpsLoopServerPath() {
|
|
FTP.ftpsLoopServerPath("/sda1", res => {
|
|
console.log(res)
|
|
})
|
|
},
|
|
// 删除FTPS服务器文件
|
|
ftpsDeleteServerFiles() {
|
|
//("要删除的文件夹或文件地址", 回调)
|
|
//回调
|
|
//{type : delete, data : {msg : "删除文件/删除文件夹(ps:先删除文件夹里面的文件再删文件夹)", data : "文件名", status : true/false, error : "失败原因"}}
|
|
FTP.ftpsDeleteServerFiles('/sda1/ceshi.txt', res => {
|
|
console.log(res)
|
|
})
|
|
},
|
|
// 删除FTPS文件夹下面文件保留文件夹
|
|
ftpsDeleteServerFilesWithoutDirectory() {
|
|
//同上,不会删除指定文件夹
|
|
FTP.ftpsDeleteServerFilesWithoutDirectory("/sda1", res => {
|
|
console.log(res)
|
|
})
|
|
},
|
|
// FTPS断开连接
|
|
closeFTPSConnect() {
|
|
console.log('点到了!!!!');
|
|
FTP.closeFTPSConnect(res => {
|
|
console.log('点到了进来了!!!!');
|
|
console.log(res)
|
|
})
|
|
}
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<style>
|
|
.content {
|
|
display: flex;
|
|
flex-direction: column;
|
|
align-items: center;
|
|
justify-content: center;
|
|
}
|
|
|
|
.logo {
|
|
height: 200rpx;
|
|
width: 200rpx;
|
|
margin-top: 200rpx;
|
|
margin-left: auto;
|
|
margin-right: auto;
|
|
margin-bottom: 50rpx;
|
|
}
|
|
|
|
.text-area {
|
|
display: flex;
|
|
justify-content: center;
|
|
}
|
|
|
|
.title {
|
|
font-size: 36rpx;
|
|
color: #8f8f94;
|
|
}
|
|
|
|
.webViewClass {
|
|
position: fixed;
|
|
}
|
|
</style>
|