Authored by 邱骏

TDK批量导入修改提示

@@ -180,7 +180,7 @@ r.post('/save', async (ctx) => { @@ -180,7 +180,7 @@ r.post('/save', async (ctx) => {
180 return ctx.response.body = result; 180 return ctx.response.body = result;
181 }); 181 });
182 182
183 -r.post('/upload', async(ctx) => { 183 +r.post('/upload', async(ctx) => { // 导入关键词EXCEL
184 if (ctx.request.body._files) { 184 if (ctx.request.body._files) {
185 let file = ctx.request.body._files.up_excel; 185 let file = ctx.request.body._files.up_excel;
186 const workbook = xlsx.readFile(file.path); 186 const workbook = xlsx.readFile(file.path);
@@ -201,7 +201,7 @@ r.post('/upload', async(ctx) => { @@ -201,7 +201,7 @@ r.post('/upload', async(ctx) => {
201 }); 201 });
202 console.log(post_data); 202 console.log(post_data);
203 if (post_data.length > 0) { 203 if (post_data.length > 0) {
204 - return Req({ 204 + return Req({ // 传数据给爬虫接口
205 method: 'POST', 205 method: 'POST',
206 uri: 'http://spiderwebhook.yoho.cn/importApiHot', // 'http://172.16.6.84:9100/importApiHot', 206 uri: 'http://spiderwebhook.yoho.cn/importApiHot', // 'http://172.16.6.84:9100/importApiHot',
207 body: { 207 body: {
@@ -231,6 +231,7 @@ const tdk = { @@ -231,6 +231,7 @@ const tdk = {
231 let json_data = xlsx.utils.sheet_to_json(worksheet); 231 let json_data = xlsx.utils.sheet_to_json(worksheet);
232 232
233 let post_data = []; 233 let post_data = [];
  234 + let success = 0;
234 235
235 // 处理EXCEL数据,并插入redis 236 // 处理EXCEL数据,并插入redis
236 let createRedisData = async function (ctx, data, index) { 237 let createRedisData = async function (ctx, data, index) {
@@ -266,7 +267,7 @@ const tdk = { @@ -266,7 +267,7 @@ const tdk = {
266 ctx.redis.lpush(`tdk:${type}:links`, hashKey); 267 ctx.redis.lpush(`tdk:${type}:links`, hashKey);
267 } 268 }
268 } 269 }
269 - 270 + success += 1;
270 return createRedisData(ctx, data, index + 1); 271 return createRedisData(ctx, data, index + 1);
271 272
272 } else { 273 } else {
@@ -276,7 +277,7 @@ const tdk = { @@ -276,7 +277,7 @@ const tdk = {
276 result = { 277 result = {
277 code: 200, 278 code: 200,
278 data: data, 279 data: data,
279 - message: `导入完成${index}条` 280 + message: `导入完成${success}条`
280 }; 281 };
281 console.log(result); 282 console.log(result);
282 ctx.response.body = result; 283 ctx.response.body = result;
@@ -429,8 +429,10 @@ @@ -429,8 +429,10 @@
429 contentType: false, 429 contentType: false,
430 success: function(res) { 430 success: function(res) {
431 if(res.code === 200) { 431 if(res.code === 200) {
432 - alert('上传完成!'); 432 + alert(res.message);
433 document.location.reload(); 433 document.location.reload();
  434 + } else {
  435 + alert('导入失败!');
434 } 436 }
435 } 437 }
436 }); 438 });