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.
333 lines
12 KiB
333 lines
12 KiB
<template>
|
|
<view class="content" style="margin-left: 200px;">
|
|
<view>连接状态:{{isConnect ? '已连接' : '未连接'}}</view>
|
|
<view>循环次数: {{count}}</view>
|
|
<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',
|
|
remoteUrl: '',
|
|
webviewStyles: {
|
|
width: '300px',
|
|
height: '500px',
|
|
left: '0px',
|
|
top: '200px'
|
|
// top: '100px'
|
|
},
|
|
androidFileDocPath: plus.io.convertLocalFileSystemURL('_doc'),
|
|
ftpLogicDeceteName: '/sda1/logicDelete',
|
|
count:0,
|
|
isConnect:false,
|
|
setInterTimeFTP:null
|
|
}
|
|
},
|
|
onShow() {
|
|
console.log('showshowshow');
|
|
// this.ftpLoopServerPath()
|
|
},
|
|
onHide() {
|
|
console.log('hidehidehide');
|
|
},
|
|
onLoad() {
|
|
this.connectFtpServer()
|
|
},
|
|
methods: {
|
|
// 流程:
|
|
// 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.131", 21, "hmftp", "hmftp", "gbk", res => {
|
|
console.log('FTP连接',res)
|
|
clearInterval(this.setInterTimeFTP)
|
|
this.ftpSendNoOp()
|
|
if(res.type==='connect' && res.data.connect === true) {
|
|
this.isConnect = true
|
|
} else if(res.type==='connect' && res.data.connect === false){
|
|
this.isConnect = false
|
|
}
|
|
})
|
|
},
|
|
// 获取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);
|
|
FTP.ftpLoopServerPath(pathName,res=>{
|
|
console.log('获取FTP服务器目录res',res);
|
|
res.data.length > 0 ? this.ftpChangeWorkingDirectory(res.data[0]) : ''
|
|
})
|
|
},
|
|
// 下载前调用这个方法
|
|
ftpChangeWorkingDirectory(data) {
|
|
FTP.ftpChangeWorkingDirectory("/",res=>{
|
|
console.log('下载前调用这个方法',res)
|
|
res.data ? this.ftpDownloadSingleFile(data) : ''
|
|
})
|
|
},
|
|
// FTP-单个文件下载至安卓机
|
|
ftpDownloadSingleFile(data) {
|
|
//("要下载到本地文件夹的绝对路径", "要下载的服务器上文件的绝对路径", 回调)
|
|
//回调
|
|
//{type : download, data : {status : true/false, name : "下载的文件名", errpr : "失败原因"}}
|
|
// var inputFile = plus.io.convertLocalFileSystemURL('/static')
|
|
console.log('androidFileDocPath',this.androidFileDocPath)
|
|
// '/sda1/deviceNewFile/20240918/20240918logo.png'
|
|
FTP.ftpDownloadSingleFile(this.androidFileDocPath, data.name, res => {
|
|
console.log('单个文件下载至安卓机--成功', res)
|
|
if(res.type === 'download') {
|
|
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,
|
|
data:data
|
|
})
|
|
}, function(e) {
|
|
console.log('文件路径解析失败', e);
|
|
})
|
|
},
|
|
// uniapp 传参给 vue页面---刘灿测试
|
|
webViewToH5(res) {
|
|
let currentWebview = this.$scope.$getAppWebview();
|
|
let wv = currentWebview.children()[0];
|
|
console.log('uniapp 传参给 vue页面');
|
|
wv.evalJS(`getVueMessage(${JSON.stringify(res)})`);
|
|
},
|
|
// uniapp vue页面传参给UNI ---刘灿测试
|
|
messageData(e) {
|
|
console.log('接收的VUE参数', e.detail.data[0]) // 接收的参数
|
|
let vueDetail = e.detail.data[0]
|
|
if(vueDetail.type === 'getCgjcSuccess') {
|
|
setTimeout(()=>{
|
|
this.deleteAppDownLoadFile(vueDetail.data)
|
|
this.ftpDeleteServerFiles(vueDetail.data)
|
|
},2000)
|
|
}
|
|
},
|
|
// 删除安卓机下载下来的文件---刘灿测试
|
|
deleteAppDownLoadFile(data) {
|
|
console.log(' 删除安卓机下载下来的文件--data',data);
|
|
// 获取安卓机路径地址
|
|
var deleteAppFileName = this.androidFileDocPath + data.fileName
|
|
plus.io.resolveLocalFileSystemURL(deleteAppFileName, (entry)=> {
|
|
// 调用 remove 方法删除文件
|
|
entry.remove(() => {
|
|
console.log('文件删除成功');
|
|
}, (error) => {
|
|
console.log('文件删除失败: ' + error.message);
|
|
});
|
|
}, (error) => {
|
|
console.log('无法解析文件路径: ' + error.message);
|
|
})
|
|
},
|
|
// 删除FTP服务器文件
|
|
ftpDeleteServerFiles(data) {
|
|
//("要删除的文件夹或文件地址", 回调)
|
|
//回调
|
|
//{type : delete, data : {msg : "删除文件/删除文件夹(ps:先删除文件夹里面的文件再删文件夹)", data : "文件名", status : true/false, error : "失败原因"}}
|
|
FTP.ftpDeleteServerFiles(data.name, res => {
|
|
console.log('FTP服务器文件删除成功', res)
|
|
setTimeout(()=>{
|
|
this.ftpUploadFile(data)
|
|
},3000)
|
|
})
|
|
},
|
|
// FTP-上传文件至FTP
|
|
ftpUploadFile(data) {
|
|
var inputFile = plus.io.convertLocalFileSystemURL('/static/logo.png')
|
|
console.log('inputFile文件', inputFile);
|
|
FTP.ftpUploadFile(inputFile, '/sda1/deviceNewFile', res => {
|
|
console.log('文件-上传成功',res)
|
|
if(res.data.msg==='上传完成') {
|
|
console.log('00000000000000000000');
|
|
this.ftpLoopServerPath()
|
|
console.log(this.count++);
|
|
}
|
|
})
|
|
},
|
|
// FTP断开连接
|
|
closeFTPConnect() {
|
|
console.log('点到了!!!!');
|
|
//失败有回调,成功没有回调
|
|
FTP.closeFTPConnect(res => {
|
|
console.log(res)
|
|
this.isConnect = false
|
|
})
|
|
},
|
|
// 测试是否掉线的方法
|
|
ftpSendNoOp(callback) {
|
|
this.setInterTimeFTP = setInterval(()=>{
|
|
FTP.ftpSendNoOp(res=>{
|
|
if(res.data === true) {
|
|
// console.log('测试是否掉线回调-未掉线',res);
|
|
this.isConnect = true
|
|
// callback(res.data)
|
|
} else {
|
|
console.log('测试是否掉线回调-已掉线',res);
|
|
this.isConnect = false
|
|
this.connectFtpServer()
|
|
// callback(res.data)
|
|
}
|
|
})
|
|
},5000)
|
|
},
|
|
|
|
// ----------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)
|
|
})
|
|
},
|
|
// 测试是否掉线的方法
|
|
ftpsSendNoOp() {
|
|
FTP.ftpsSendNoOp(e=>{
|
|
})
|
|
},
|
|
}
|
|
}
|
|
</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>
|