qiushang 11 tháng trước cách đây
mục cha
commit
5782d557e9
2 tập tin đã thay đổi với 94 bổ sung70 xóa
  1. 18 2
      src/renderer/components/header.vue
  2. 76 68
      src/renderer/components/home.vue

+ 18 - 2
src/renderer/components/header.vue

@@ -125,8 +125,12 @@
 		<!-- 软件设置 -->
 		<el-dialog title="软件设置" :visible.sync="settingModal" width="400px">
 			<div>
-				<el-divider content-position="left">开机启动</el-divider>
-				<el-checkbox v-model="boot">开机时自动启动此软件</el-checkbox>
+				<el-divider content-position="left">账号登录</el-divider>
+				<el-row type="flex" justify="space-between">
+					<el-button size="mini" @click="toLogin('alibaba')">阿里巴巴账号</el-button>
+					<el-button size="mini" @click="toLogin('jd')">京东账号</el-button>
+					<el-button size="mini" @click="toLogin('tb')">天猫/淘宝账号</el-button>
+				</el-row>
 				<el-divider content-position="left">退出设置</el-divider>
 				<el-radio-group v-model="closeType">
 				    <el-radio :label="1">最小化到系统托盘</el-radio>
@@ -270,6 +274,18 @@
 			})
 		},
 		methods: {
+			// 点击去登录
+			toLogin(type){
+				let url = '';
+				if(type == 'alibaba'){
+					url = 'https://login.taobao.com/?redirect_url=https%3A%2F%2Flogin.1688.com%2Fmember%2Fjump.htm%3Ftarget%3Dhttps%253A%252F%252Flogin.1688.com%252Fmember%252FmarketSigninJump.htm%253FDone%253Dhttps%25253A%25252F%25252Fp4psearch.1688.com%25252Fhamlet.html%25253Fscene%25253D6%252526cosite%25253Dbaidujj_pz%252526location%25253Dre%252526trackid%25253D885662561117990122602&style=tao_custom&from=1688web';
+				}else if(type == 'jd'){
+					url = 'https://passport.jd.com/new/login.aspx';
+				}else if(type == 'tb'){
+					url = 'https://login.taobao.com';
+				}
+				this.$emit('login-url', url);
+			},
 			softMini() { // 软件最小化
 			    ipcRenderer.send('min');
 			},

+ 76 - 68
src/renderer/components/home.vue

@@ -9,7 +9,7 @@
 						<span style="letter-spacing: 1px;">{{productName}}</span>
 					</p>
 					
-					<el-menu :default-openeds="['a']" :default-active="menuIndex" @select="setMenuIndex" active-text-color="#409EFF" background-color="#333744" text-color="#fff" style="margin-top: 10px;">
+					<el-menu :default-openeds="['a', 'b']" :default-active="menuIndex" @select="setMenuIndex" active-text-color="#409EFF" background-color="#333744" text-color="#fff" style="margin-top: 10px;">
 						<el-submenu index="a">
 							<template slot="title"><i class="el-icon-picture"></i>图片下载</template>
 							<el-menu-item index="1">阿里巴巴</el-menu-item>
@@ -21,16 +21,18 @@
 						
 						<el-submenu index="b">
 							<template slot="title"><i class="el-icon-picture-outline-round"></i>图片处理</template>
-							<el-menu-item index="11">选项1</el-menu-item>
-							<el-menu-item index="12">选项2</el-menu-item>
+							<el-menu-item index="11">格式转换</el-menu-item>
+							<el-menu-item index="12">图片压缩</el-menu-item>
+							<el-menu-item index="13">修改尺寸</el-menu-item>
+							<el-menu-item index="14">添加水印</el-menu-item>
+							<el-menu-item index="15">批量命名</el-menu-item>
 						</el-submenu>
 					</el-menu>
 				</el-aside>
 				
 				<el-container>
 					<el-header height="45px" style="background-color: #fafafa; padding: 0 10px;">
-						<soft-header ref="headerRef" @update-soft="updateSoft()"
-							@export-file="exportFile"></soft-header>
+						<soft-header ref="headerRef" @update-soft="updateSoft()" @export-file="exportFile" @login-url="loginUrl"></soft-header>
 					</el-header>
 					<el-main ref="el-main" style="background-color: #fafafa;">
 						<template>
@@ -69,8 +71,6 @@
 									</h3>
 								</el-row>
 								
-								<!-- <el-input type="textarea" :rows="5" :placeholder="'请输入网址链接(例:' + exampleUrl[menuIndex-1] + ')'" v-model="url"></el-input> -->
-								
 								<div style="padding: 15px 0 20px;">
 									<el-row type="flex" justify="space-between">
 										<div v-if="menuIndex == '10'" style="padding-top: 10px;">
@@ -91,21 +91,13 @@
 												<div>
 													<el-tag type="info" size="mini" v-if="tbStatus == 1">未检测</el-tag>
 													<el-tag type="success" size="mini" v-if="tbStatus == 2">账号已登录</el-tag>
-													<el-link type="danger" v-if="tbStatus == 3" @click="tmLogin">未登录,点我去登录</el-link>
+													<el-link type="danger" v-if="tbStatus == 3" @click="loginUrl('https://login.taobao.com')">未登录,点我去登录</el-link>
 													<el-button size="mini" type="warning" :loading="checkLoading" style="margin-left: 10px;" :disabled='tbStatus == 2' @click="checkLogin">检测登录状态</el-button>
 												</div>
 											</div>
 										</template>
-										
 									</el-row>
 									
-									<!-- <div style="width: 50%;">
-										<el-timeline style="padding: 0; margin-top: 20px;">
-										    <el-timeline-item v-for="(activity, index) in activities" :key="index" type="primary" >
-												<el-alert :title="activity.content + (activity.num?activity.num+'张' : '')" :type="activity.type" show-icon :closable="false"></el-alert>
-											</el-timeline-item>
-										</el-timeline>
-									</div> -->
 								</div>
 							
 								<div class="table-scroll">
@@ -244,7 +236,6 @@
 					commentImg: true,
 					video: true,
 				},
-				activities: [],
 				exampleUrl: ['https://www.1688.com', 'https://www.jd.com', 'https://www.tmall.com', 'https://www.taobao.com'],
 
 				fileList: [],
@@ -449,6 +440,24 @@
 				});
 			},
 			
+			// 去登录
+			loginUrl(url){
+				(async () => {
+					try{
+						const tbBrowser = await puppeteer.launch({
+							headless: false,
+							args: ['--window-size=1280,800'],
+							userDataDir: os.tmpdir() + separator + 'chrome-data-capture', 
+						});
+						const page = await tbBrowser.newPage();
+						await page.setViewport({ width: 1280, height: 800 });
+						await page.goto(url, {waitUntil : 'networkidle2'});
+					}catch(e){
+						this.showError(e);
+					}
+				})();
+			},
+			
 			// 开始下载
 			async exportFile(flag) {
 				let authority = this.$refs.headerRef.authority.isAuthority;
@@ -531,10 +540,14 @@
 						})
 					}
 					
-					this.loading = false;
+					let tbLogin = true;
+					if((this.menuIndex == '3' || this.menuIndex == '4') && this.tbStatus == 3){
+						tbLogin = false;
+					}
 					
+					this.loading = false;
 					// 打开文件夹
-					if(fileList.length > 0){
+					if(fileList.length > 0 && tbLogin){
 						this.$message({message: '恭喜你,任务已完成!', type: 'success'});
 						electronApi.call('showItemInfolder',[this.downloadDir + separator + pjson.softInfo.softName +'\\tty.tty'])
 					}
@@ -936,28 +949,7 @@
 				});
 				
 			},
-			
-			// 天猫、淘宝去登录
-			tmLogin(){
-				(async () => {
-					try{
-						const tbBrowser = await puppeteer.launch({
-							headless: false,
-							args: ['--window-size=1280,800'],
-							userDataDir: os.tmpdir() + separator + 'chrome-data-capture', 
-						});
-						const page = await tbBrowser.newPage();
-						await page.setViewport({ width: 1280, height: 800 });
-
-						let testUrl = 'https://login.taobao.com';
-						await page.goto(testUrl, {waitUntil : 'networkidle2'});
-
-					}catch(e){
-						this.showError(e);
-					}
-				})();
-			},
-			
+	
 			//淘宝\天猫下载
 			async tbDownload(urlInfo){
 				let task = null;
@@ -966,18 +958,20 @@
 						if(data == 2){ // 已经登录,处理下载
 							task = this.tbScanImg(urlInfo);
 						}else{ // 未登录
+							task = 'notLogin';
 							this.tbStatus = 3;
 							this.$notify.error({
-								title: '淘宝/天猫账号未登录,下载失败!',
-								message: str
+								title: '淘宝/天猫账号未登录,下载失败!'
 							});
 						}
 					}).catch(err => {
+						task = 'notLogin';
 						this.tbStatus = 3;
 					});
 				}else if(this.tbStatus == 2){ // 已经登录
 					task = this.tbScanImg(urlInfo);
 				}else if(this.tbStatus == 3){ // 未登录
+					task = 'notLogin';
 					this.$notify.error({
 						title: '请先登录淘宝/天猫账号后使用!'
 					});
@@ -1016,8 +1010,6 @@
 								return {'scrollHeight': scrollHeight, 'cHeight': cHeight}
 							});
 							
-							urlInfo.status = '3';
-							
 							let scrollHeight = pageInfo.scrollHeight;
 							let cHeight = pageInfo.cHeight;
 							
@@ -1033,6 +1025,7 @@
 									});
 								}, start);
 								if(start > num || start > 200){ // 防止页面过长,滚动200次自动停止
+									urlInfo.status = '3';
 									clearInterval(scrollInt);
 									
 									//detailImg:详情图;skuImg:sku图片;commentImg: 评论图;video: 视频
@@ -1050,6 +1043,9 @@
 										
 										//主图 
 										let arr1 = document.querySelectorAll('img[class^=PicGallery--thumbnailPic--]');
+										if(arr1.length === 0){
+											arr1 = document.querySelectorAll('img[class*=thumbnailPic--]');
+										}
 										for(let i=0; i< arr1.length; i++){
 											let mainImgUrl = arr1[i].src;
 											let result = regex.exec(mainImgUrl);
@@ -1060,6 +1056,9 @@
 										}
 										//sku图片 
 										let arr2 = document.querySelectorAll('img[class^=SkuContent--valueItemImg--]');
+										if(arr2.length === 0){
+											arr2 = document.querySelectorAll('img[class*=valueItemImg--]');
+										}
 										for(let i=0; i< arr2.length; i++){
 											let skuImgUrl = arr2[i].src;
 											let result = regex.exec(skuImgUrl);
@@ -1080,6 +1079,9 @@
 										}
 										//评论图片  
 										let arr4 = document.querySelectorAll('div[class^=Comments--comments--] img');
+										if(arr4.length === 0){
+											arr4 = document.querySelectorAll('div[class^=comments--] img');
+										}
 										for(let i=0; i< arr4.length; i++){ 
 											if(arr4[i].src.indexOf('/avatar/sns/user/flag/sns_logo') == -1){ //过滤淘宝用户头像
 												outObj.commentImg.push(arr4[i].src);
@@ -1362,32 +1364,38 @@
 					});
 					let out = fs.createWriteStream(outputPath);
 					req.pipe(out);
-								
-					req.on('response', (data) => {
-						total_bytes = parseInt(data.headers['content-length']);
-						const status = data.statusCode;
-						if (status < 200 || status >= 300) {
-							this.$notify.error({
-								title: '网络异常,请稍后重试!- 1 - ' + imageUrl
-							});
-						}else if(isNaN(total_bytes)){
-							this.$notify.error({
-								title: '网络异常,请稍后重试!- 2 - ' + imageUrl
-							});
-						}else{
-							// console.log('下载中...')
-						}
-					});
-								
-					req.on('data', (chunk) => {
-					    received_bytes += chunk.length;
+					
+					return new Promise((resolve, reject) => { 
+						req.on('response', (data) => {
+							total_bytes = parseInt(data.headers['content-length']);
+							const status = data.statusCode;
+							if (status < 200 || status >= 300) {
+								reject(false);
+								this.$notify.error({
+									title: '网络异常,请稍后重试!- 1 - ' + imageUrl
+								});
+							}else if(isNaN(total_bytes)){
+								reject(false);
+								this.$notify.error({
+									title: '网络异常,请稍后重试!- 2 - ' + imageUrl
+								});
+							}else{
+								// console.log('下载中...')
+							}
+						});
+									
+						req.on('data', (chunk) => {
+						    received_bytes += chunk.length;
+						});
+						
+						req.on('end', ()=> {
+							urlInfo.num += 1;
+							//console.log('下载完成', outputPath)
+							resolve(true);
+						});
 					});
 					
 					
-					req.on('end', ()=> {
-						urlInfo.num += 1;
-						// console.log('下载完成', outputPath)
-					});
 			  
 			    } catch (error) {  
 			        console.error(imageUrl, `Failed to download image: ${error.message}`);