Skip to content

Commit 677f3ff

Browse files
committed
host branch
1 parent 7d6957c commit 677f3ff

File tree

1 file changed

+31
-4
lines changed

1 file changed

+31
-4
lines changed

_tasks/plugins/TmTIndex.js

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,34 @@
33
*/
44
var fs = require('fs'),
55
path = require('path'),
6-
format = function () {
7-
};
6+
os = require('os');
7+
8+
var getIp = function () {
9+
var platform = os.platform();
10+
var interfaces = os.networkInterfaces();
11+
var IPv4 = '127.0.0.1';
12+
13+
if (platform === 'win32') {
14+
var addressMes = interfaces['本地连接'];
15+
if (addressMes && addressMes.length) {
16+
for (var i = 0; i < addressMes.length; i++) {
17+
if (addressMes[i]['family'] && addressMes[i]['family'] === 'IPv4') {
18+
return addressMes[i]['address'];
19+
}
20+
}
21+
}
22+
} else {
23+
for (var key in interfaces) {
24+
interfaces[key].forEach(function (details) {
25+
if (details.family == 'IPv4' && key == 'en0') {
26+
IPv4 = details.address;
27+
}
28+
});
29+
}
30+
}
31+
32+
return IPv4;
33+
}
834

935
module.exports = function (config) {
1036
var html = [
@@ -30,7 +56,8 @@ module.exports = function (config) {
3056
].join(''),
3157
tmpHtml = '',
3258
length = '/dev/html/'.length,
33-
collector = listdir('./dev/html');
59+
collector = listdir('./dev/html'),
60+
ip = getIp();
3461

3562

3663
showdir(collector, 0);
@@ -99,7 +126,7 @@ module.exports = function (config) {
99126

100127
html = html + tmpHtml;
101128

102-
html += '</tbody></table><div id="qrcode"></div><script src="http://wximg.gtimg.com/tmt/tools/file-list/js/jquery-2.1.3.min.js"></script><script src="http://wximg.gtimg.com/tmt/tools/file-list/js/qrcode.min.js"></script><script type="text/javascript">$(document).ready(function(){document.title= "' + config.projectName + ' 资源列表"; $(".level1").prependTo(".table-body"); $(".td-qrcode i").bind("mouseenter ",function(){$("#qrcode").show().empty();new QRCode(document.getElementById("qrcode"), encodeURI(window.location.href.split("TmTIndex.html")[0]+$(this).parent().parent().find("a").attr("href")));});$("body").bind("click",function(){$("#qrcode").hide();});});</script></body></html>';
129+
html += '</tbody></table><div id="qrcode"></div><script src="http://wximg.gtimg.com/tmt/tools/file-list/js/jquery-2.1.3.min.js"></script><script src="http://wximg.gtimg.com/tmt/tools/file-list/js/qrcode.min.js"></script><script type="text/javascript">$(document).ready(function(){ var url = location.href.replace("localhost", "' + ip + '");document.title= "' + config.projectName + ' 资源列表"; $(".level1").prependTo(".table-body"); $(".td-qrcode i").bind("mouseenter ",function(){$("#qrcode").show().empty();new QRCode(document.getElementById("qrcode"), encodeURI(url.split("TmTIndex.html")[0]+$(this).parent().parent().find("a").attr("href")));});$("body").bind("click",function(){$("#qrcode").hide();});});</script></body></html>';
103130

104131
var out = fs.createWriteStream('./dev/html/TmTIndex.html', {encoding: "utf8"});
105132
out.write(html, function (err) {

0 commit comments

Comments
 (0)