-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.js
194 lines (183 loc) · 5.39 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
/**
* 主入口
*/
let gui = require('nw.gui');
gui.App.clearCache();
// 获取window对象
var win = nw.Window.get();
win.maximize();
//win.showDevTools();
// Listen to main window's close event
win.on('close', function() {
// Hide the window to give user the feeling of closing immediately
this.close(true);
});
// # Alipay-Supervisor Startup
const forever=require("forever");
var schedule = require("node-schedule");
var moment = require("moment");
var app_config = require("./app/config");
var iframe ,iframeDOM,currentHtml,search_iframeDOM,search_iframe;
Spider.vue=new Vue({
el:'#app',
data:{
login_text:'登录',
start_text:'开始',
start_loading:false,
activeName:'first',
spider_categorys:[],
logs:[],
searchs:[],
containAdd:'',
category:'',
search_dates:'',
pickerOptions: {
shortcuts: [{
text: '最近一周',
onClick(picker) {
const end = new Date();
const start = new Date();
start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
picker.$emit('pick', [start, end]);
}
}, {
text: '最近一个月',
onClick(picker) {
const end = new Date();
const start = new Date();
start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
picker.$emit('pick', [start, end]);
}
}, {
text: '最近三个月',
onClick(picker) {
const end = new Date();
const start = new Date();
start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
picker.$emit('pick', [start, end]);
}
}]
}
},
methods:{
clear(){
this.logs=[];
},
handleOpen(key, keyPath) {
},
handleClose(key, keyPath) {
},
handleClick(tab, event) {
},
login(){
Spider.logout("打开登录扫码页面");
currentHtml='login';
iframe.attr('src',newrank.login);
iframeDOM.onload = iframeLoad;
},
start(){
if(currentHtml!='wx_list') {
Spider.logout("打开排行榜页面");
currentHtml = "wx_list";
iframe.attr('src', newrank.weixin.html);
}else{
Spider.logout("开始读取公众号列表");
$.publish('newrank_weixin_start');
$('#end_btn').show();
}
},
close(){
Spider.logout("正在关闭...");
$.publish('newrank_weixin_stop');
},
search(){
if(currentHtml!='search_list') {
Spider.logout("打开搜索页面...");
currentHtml="search_list";
iframe.attr('src', newrank.weixin.dataSearch_html);
}else{
searchData();
}
}
}
});
function searchData() {
Spider.logout("正在搜索...");
var startDate='',endDate='',week=1;
if(Spider.vue.search_dates.length>0) {
week=3;
startDate = moment(Spider.vue.search_dates[0]).format("YYYY-MM-DD");
endDate = moment(Spider.vue.search_dates[1]).format("YYYY-MM-DD");
}
$.publish('newrank_weixin_search_start', {
param: {
startDate,
endDate,
week,
//category: Spider.vue.category,
containAdd: Spider.vue.containAdd,
}
});
}
/**
* 输出日志
* @param text
*/
Spider.logout=function(text,type) {
if (!app_config.default.debug || !text) {
return;
}
type=type?type:'info';
Spider.vue.logs.push({title:`[${moment().format("YYYY-MM-DD HH:mm:ss")}] ${text}`,type});
};
$(function () {
iframe = $('#pay_iframe');
app_config.default.iframe=iframe;
iframeDOM = document.getElementById("pay_iframe");
//iframe.show();
search_iframe = $('#search_iframe');
search_iframeDOM = document.getElementById("search_iframe");
});
/**
* 页面加载完成事件
*/
function iframeLoad() {
app_config.default.newrank.Cookies = iframeDOM.contentWindow.document.cookie;
switch (currentHtml){
case 'login':
getCode();
break;
case 'logining':
Spider.logout("登录成功");
Spider.vue.login_text='重新登录';
$('#login_code').hide();
$('#start_btn').show();
break;
case 'wx_list':
Spider.logout("开始读取公众号列表");
Spider.vue.start_text='抓取中...';
Spider.vue.start_loading=true;
$.publish('newrank_weixin_start');
$('#end_btn').show();
break;
case 'search_list':
searchData();
break;
}
}
/**
* 获取二维码
*/
function getCode() {
var img=iframe.contents().find(".login-action-code").children('img');
if(img.length>0){
$('#login_code').show();
$('#login_code').attr('src',img.attr("src"));
if(img.attr('src').indexOf("mp.weixin.qq.com")>1){
Spider.logout("请扫码二维码");
currentHtml='logining';
return;
}
}
setTimeout(getCode, 1000);
}