Skip to content

Commit

Permalink
添加文本传输功能
Browse files Browse the repository at this point in the history
  • Loading branch information
sirzdy committed Sep 30, 2018
1 parent 1119139 commit 40219f4
Show file tree
Hide file tree
Showing 31 changed files with 7,738 additions and 150 deletions.
31 changes: 30 additions & 1 deletion client/assets/css/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ body {
font-family: Microsoft Yahei;
}

* {
box-sizing: border-box;
}

body {
perspective: 800px;
/* -webkit-app-region: drag; */
Expand Down Expand Up @@ -117,6 +121,32 @@ textarea {
color: #000 !important;
font-weight: bold;
}
/* 发送文字 */
#text{
height: 50px;
display: flex;
flex-direction: row;
align-items: center;
text-align: center;
border-top: 1px solid #eee;
}
#content{
max-height: 50px;
width: 100%;
flex: 1;
height: 100%;
resize: none;
border: none;
outline: none;
background: transparent;
font-family: Microsoft Yahei;
}
#send{
width: 50px;
height: 100%;
line-height: 50px;
border-left: 1px solid #eee;
}

#open {
/* height: 40px; */
Expand All @@ -125,7 +155,6 @@ textarea {
background-color: #ddd;
cursor: pointer;
}

#dir{
font-size: 10px;
}
168 changes: 119 additions & 49 deletions client/assets/js/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@ let close = document.getElementById('close');
let links = document.getElementById('links');
let open = document.getElementById('open');
let dir = document.getElementById('dir');
let send = document.getElementById('send');
let content = document.getElementById('content');
let loading = document.querySelector(".loading", null);

let ips, downloadPort, uploadPort;
/* 二维码初始化 */
let qrcode = new QRCode(document.getElementById('qrcode'), "");


function hint(msg, duration, type) {
function hint(msg, type, duration) {
duration = isNaN(duration) ? 1500 : duration;
var m = document.createElement('div');
m.innerHTML = msg;
Expand Down Expand Up @@ -50,6 +53,14 @@ window.onload = () => {
close.onclick = () => {
ipcRenderer.send('quit');
}
/* 发送文本 */
send.onclick = () => {
if (!content.value) {
hint('请输入内容!', 'fail');
return;
}
ipcRenderer.send('send', content.value);
}

/* 打开目录 */
open.onclick = () => {
Expand Down Expand Up @@ -77,53 +88,8 @@ links.oncontextmenu = function (event) {
}

ipcRenderer.on('start-reply', (event, values) => {
let downloadUrls = [];
let uploadUrls = [];
let [{ ips, wirelessIps }, downloadPort, uploadPort] = values;
loading.style.display = 'none';
if (!wirelessIps || !wirelessIps.length) {
let title = document.createElement('h3');
title.innerHTML = '抱歉,出错啦。<br><small>未连接无线网络或未开启网络热点。</small>';
links.appendChild(title);
let help = document.createElement('p');
help.innerText = '【查看帮助(右键打开)】';
help.setAttribute('link', helpLink);
links.appendChild(help);
let feedback = document.createElement('p');
feedback.innerText = '【意见反馈(右键打开)】';
feedback.setAttribute('link', feedbackLink);
links.appendChild(feedback);
help.click();
return;
}
wirelessIps.forEach((ip) => {
downloadUrls.push('http://' + ip + ':' + downloadPort);
uploadUrls.push('http://' + ip + ':' + uploadPort);
});
if (downloadUrls.length) {
let title = document.createElement('h3');
title.innerText = '【下载】(电脑→其他设备)'
links.appendChild(title);
downloadUrls.forEach((url) => {
let e = document.createElement('p');
e.innerText = url;
e.setAttribute('link', url);
links.appendChild(e);
e.click();
});
}
if (uploadUrls.length) {
let title = document.createElement('h3');
title.innerText = '【上传】(其他设备→电脑)'
links.appendChild(title);
uploadUrls.forEach((url) => {
let e = document.createElement('p');
e.innerText = url;
e.setAttribute('link', url);
links.appendChild(e);
// e.click();
});
}
[{ ips, wirelessIps }, downloadPort, uploadPort, type] = values;
show(type);
})

ipcRenderer.on('copy-reply', (event, rets) => {
Expand All @@ -140,11 +106,22 @@ ipcRenderer.on('copy-reply', (event, rets) => {
})
fail.length ? alert(sucHint + suc.join('\n') + '\n' + failHint + fail.join('\n')) : hint('复制成功!!!');
})

ipcRenderer.on('send-reply', (event, state) => {
if (state) {
hint('发送成功!!!');
} else {
hint('发送失败!', 'fail');
}
})
ipcRenderer.on('files-path', (event, filesPath) => {
dir.innerText = '[' + filesPath + ']';
})

ipcRenderer.on('show-type', (event, type) => {
// alert(type);
show(type);
})

container.ondragstart = (event) => {
event.preventDefault();
}
Expand All @@ -166,4 +143,97 @@ container.ondrop = (event) => {
}
ipcRenderer.send('copy', files)
return false;
}

function show(type) {
loading.style.display = 'none';
let urls = [];
ips.forEach((ip) => {
if (type == 0) {
urls.push('http://' + ip + ':' + uploadPort);
}
if (type == 1) {
if (wirelessIps.indexOf(ip) >= 0) {
urls.push('http://' + ip + ':' + uploadPort);
}
}
if (type == 2) {
if (wirelessIps.indexOf(ip) < 0) {
urls.push('http://' + ip + ':' + uploadPort);
}
}
})
if (urls.length) {
links.innerHTML = "";
urls.forEach((url) => {
let e = document.createElement('p');
e.innerText = url;
e.setAttribute('link', url);
links.appendChild(e);
e.click();
});
} else {
links.innerHTML = "";
let title = document.createElement('h3');
type == 0 && (title.innerHTML = '抱歉,出错啦。<br><small>未连接网络。</small>');
type == 1 && (title.innerHTML = '抱歉,出错啦。<br><small>未连接无线网络或未开启网络热点。</small>');
type == 2 && (title.innerHTML = '抱歉,出错啦。<br><small>未连接有线网络或未插网线。</small>');
links.appendChild(title);
let help = document.createElement('p');
help.innerText = '【查看帮助(右键打开)】';
help.setAttribute('link', helpLink);
links.appendChild(help);
let feedback = document.createElement('p');
feedback.innerText = '【意见反馈(右键打开)】';
feedback.setAttribute('link', feedbackLink);
links.appendChild(feedback);
help.click();
return;
}

// let downloadUrls = [];
// let uploadUrls = [];
// // if (!wirelessIps || !wirelessIps.length) {
// // let title = document.createElement('h3');
// // title.innerHTML = '抱歉,出错啦。<br><small>未连接无线网络或未开启网络热点。</small>';
// // links.appendChild(title);
// // let help = document.createElement('p');
// // help.innerText = '【查看帮助(右键打开)】';
// // help.setAttribute('link', helpLink);
// // links.appendChild(help);
// // let feedback = document.createElement('p');
// // feedback.innerText = '【意见反馈(右键打开)】';
// // feedback.setAttribute('link', feedbackLink);
// // links.appendChild(feedback);
// // help.click();
// // return;
// // }
// wirelessIps.forEach((ip) => {
// // downloadUrls.push('http://' + ip + ':' + downloadPort);
// uploadUrls.push('http://' + ip + ':' + uploadPort);
// });
// // if (downloadUrls.length) {
// // let title = document.createElement('h3');
// // title.innerText = '【下载】(电脑→其他设备)'
// // links.appendChild(title);
// // downloadUrls.forEach((url) => {
// // let e = document.createElement('p');
// // e.innerText = url;
// // e.setAttribute('link', url);
// // links.appendChild(e);
// // e.click();
// // });
// // }
// if (uploadUrls.length) {
// let title = document.createElement('h3');
// // title.innerText = '【上传】(其他设备→电脑)'
// // links.appendChild(title);
// uploadUrls.forEach((url) => {
// let e = document.createElement('p');
// e.innerText = url;
// e.setAttribute('link', url);
// links.appendChild(e);
// e.click();
// });
// }
}
5 changes: 5 additions & 0 deletions client/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
<section class="qr_wrap">
<section id="qrcode" class="center"></section>
</section>
<!-- Text -->
<section id="text">
<textarea name="" id="content" placeholder="请输入文本,回车发送"></textarea>
<div id="send">发送</div>
</section>
<!-- Links -->
<section id="links">
</section>
Expand Down
Loading

0 comments on commit 40219f4

Please sign in to comment.