home.vue 74 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249
  1. <template>
  2. <div>
  3. <el-container style="user-select: none; height: 100vh;">
  4. <el-container>
  5. <!-- #333744 -->
  6. <el-aside width="180px" style="border-right: 1px solid #fafafa; background-color: #333744; overflow-x: hidden;">
  7. <p class="soft-name" style="-webkit-app-region: drag; color: #fff;">
  8. <img src="../assets/image/icon.png" class="soft-icon" />
  9. <span style="letter-spacing: 1px;">{{productName}}</span>
  10. </p>
  11. <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;">
  12. <el-submenu index="a">
  13. <template slot="title"><img src="../assets/image/m-download.png" class="m-image"/>图片下载</template>
  14. <el-menu-item index="3">
  15. <img src="../assets/image/m-tmall.png" class="m-image"/><span slot="title">天猫</span>
  16. </el-menu-item>
  17. <el-menu-item index="2">
  18. <img src="../assets/image/m-jd.png" class="m-image"/><span slot="title">京东</span>
  19. </el-menu-item>
  20. <el-menu-item index="4">
  21. <img src="../assets/image/m-taobao.png" class="m-image"/><span slot="title">淘宝</span>
  22. </el-menu-item>
  23. <el-menu-item index="1">
  24. <img src="../assets/image/m-alibaba.png" class="m-image"/><span slot="title">阿里巴巴</span>
  25. </el-menu-item>
  26. <el-menu-item index="10">
  27. <img src="../assets/image/m-chrome.png" class="m-image"/><span slot="title">其他网址(Beta)</span>
  28. </el-menu-item>
  29. </el-submenu>
  30. <el-submenu index="b">
  31. <template slot="title"><img src="../assets/image/m-edit.png" class="m-image"/>图片处理</template>
  32. <el-menu-item index="2-1">
  33. <img src="../assets/image/m-geshi.png" class="m-image"/><span slot="title">格式转换</span>
  34. </el-menu-item>
  35. <el-menu-item index="2-2">
  36. <img src="../assets/image/m-yasuo.png" class="m-image"/><span slot="title">图片压缩</span>
  37. </el-menu-item>
  38. <el-menu-item index="2-3">
  39. <img src="../assets/image/m-chicun.png" class="m-image"/><span slot="title">修改尺寸</span>
  40. </el-menu-item>
  41. <el-menu-item index="2-5">
  42. <img src="../assets/image/m-shuiyin.png" class="m-image"/><span slot="title">添加水印</span>
  43. </el-menu-item>
  44. </el-submenu>
  45. </el-menu>
  46. </el-aside>
  47. <el-container>
  48. <el-header height="45px" style="background-color: #fafafa; padding: 0 10px;">
  49. <soft-header ref="headerRef" @update-soft="updateSoft()" @export-file="exportFile" @login-url="loginUrl" @clear-cache="clearCache"></soft-header>
  50. </el-header>
  51. <soft-img ref="imgRef" v-show="['2-1', '2-2', '2-3', '2-5'].indexOf(menuIndex) > -1" @open-vip="openVip" @check-authority="checkAuthority"></soft-img>
  52. <el-main v-show="['1', '2', '3', '4', '10'].indexOf(menuIndex) > -1" ref="el-main" style="background-color: #fafafa;">
  53. <template>
  54. <div class="content-top">
  55. <div>
  56. <el-button-group>
  57. <el-button type="primary" size="mini" icon="el-icon-circle-plus-outline"
  58. @click="addVisible = true;">添加链接</el-button>
  59. <el-button type="primary" size="mini" icon="el-icon-upload"
  60. @click="pickLink()">导入链接</el-button>
  61. <el-button type="primary" size="mini" icon="el-icon-delete"
  62. @click="clearList()">清空链接</el-button>
  63. </el-button-group>
  64. <el-link type="info" style="margin-left: 20px; vertical-align:baseline;" @click="downloadExample()">模板下载<i class="el-icon-download"></i></el-link>
  65. </div>
  66. <el-row type="flex" style="align-items: center;">
  67. <div class="set-item">
  68. <span class="set-title">保存目录:</span>
  69. <el-input :title="downloadDir" ref="upload-input" size="mini" @focus="pickPath" placeholder="请选择输出目录" v-model="downloadDir" readonly style="width:200px;" prefix-icon="el-icon-folder"></el-input>
  70. <el-popover placement="bottom" popper-class="popper-open" trigger="hover" content="打开保存目录">
  71. <i class="el-icon-folder-opened" slot="reference" style="padding-left: 5px; cursor: pointer; font-size: 22px; vertical-align: middle;" @click="openFolder()"></i>
  72. </el-popover>
  73. </div>
  74. <el-button type="danger" @click="exportFile()" :loading="loading">开始下载</el-button>
  75. </el-row>
  76. </div>
  77. <div style="padding: 20px 20px 0 20px; height: calc(100% - 62px);">
  78. <el-row type="flex" justify="space-between">
  79. <div>
  80. <h3 style="display: inline-block;">
  81. <span v-if="menuIndex == '1'">阿里巴巴 - </span>
  82. <span v-if="menuIndex == '2'">京东 - </span>
  83. <span v-if="menuIndex == '3'">天猫 - </span>
  84. <span v-if="menuIndex == '4'">淘宝 - </span>
  85. <span v-if="menuIndex == '10'">网页 - </span>
  86. 图片下载
  87. </h3>
  88. <el-link v-if="menuIndex == '3' || menuIndex == '4'" :underline="false" type="danger" style="text-align: center; font-size: 12px;">
  89. (需登录{{menuIndex == '3' ? '天猫' : '淘宝'}}账号后才能下载)
  90. </el-link>
  91. <el-link v-if="menuIndex == '2'" :underline="false" type="danger" style="text-align: center; font-size: 12px;">
  92. (需登录京东账号后才能下载)
  93. </el-link>
  94. <el-link v-if="menuIndex == '10'" :underline="false" type="info" style="text-align: center; font-size: 12px;">
  95. (非会员功能,仅提供试用)
  96. </el-link>
  97. </div>
  98. <el-link v-if="((menuIndex == '3' || menuIndex == '4') && tbStatus == 3) || (menuIndex == '2' && jdStatus == 3)" :underline="false" type="danger" style="text-align: center; font-size: 12px;">登录完成后请关闭浏览器</el-link>
  99. </el-row>
  100. <div style="padding: 15px 0 20px;">
  101. <el-row type="flex" justify="space-between">
  102. <div v-if="menuIndex == '10'" style="padding-top: 10px;">
  103. <label>下载类型:</label>
  104. <el-checkbox :value="true" style="opacity: 0.6; cursor: not-allowed;">图片</el-checkbox>
  105. </div>
  106. <div v-if="menuIndex < 10" style="padding-top: 10px;">
  107. <label>下载类型:</label>
  108. <el-checkbox :value="true" style="opacity: 0.6; cursor: not-allowed;">主图</el-checkbox>
  109. <el-checkbox v-model="settingData.detailImg" >详情图</el-checkbox>
  110. <el-checkbox v-model="settingData.skuImg" >SKU图</el-checkbox>
  111. <el-checkbox v-model="settingData.commentImg" v-if="menuIndex == '3' || menuIndex == '4'">评论图</el-checkbox>
  112. <el-checkbox v-model="settingData.video" >视频</el-checkbox>
  113. </div>
  114. <!-- 天猫/淘宝 -->
  115. <template v-if="menuIndex == '3' || menuIndex == '4'">
  116. <div>
  117. <el-tag type="info" size="mini" v-if="tbStatus == 1">未检测</el-tag>
  118. <el-tag type="success" size="mini" v-if="tbStatus == 2">{{menuIndex == '3' ? '天猫' : '淘宝'}}账号已登录</el-tag>
  119. <el-link type="danger" style="text-decoration: underline;" v-if="tbStatus == 3" :underline="false" @click="loginUrl('https://login.taobao.com')">未登录,点击登录<span>{{menuIndex == '3' ? '天猫' : '淘宝'}}</span>账号</el-link>
  120. <el-button size="mini" type="warning" :loading="checkLoading" style="margin-left: 10px;" :disabled='tbStatus == 2' @click="checkLogin">检测登录状态</el-button>
  121. </div>
  122. </template>
  123. <!-- 京东账号 -->
  124. <template v-if="menuIndex == '2'">
  125. <div>
  126. <el-tag type="info" size="mini" v-if="jdStatus == 1">未检测</el-tag>
  127. <el-tag type="success" size="mini" v-if="jdStatus == 2">京东账号已登录</el-tag>
  128. <el-link type="danger" style="text-decoration: underline;" v-if="jdStatus == 3" :underline="false" @click="loginUrl('https://passport.jd.com/new/login.aspx')">未登录,点击登录京东账号</el-link>
  129. <el-button size="mini" type="warning" :loading="checkLoading" style="margin-left: 10px;" :disabled='jdStatus == 2' @click="checkJdLogin">检测登录状态</el-button>
  130. </div>
  131. </template>
  132. </el-row>
  133. </div>
  134. <div class="table-scroll">
  135. <!-- 1、 -->
  136. <vxe-table ref="xTable" show-overflow class="img-table" max-height="100%" empty-text="没有更多数据了!" :loading="tabLoading" :row-config="{isHover: true}"
  137. :loading-config="{icon: 'vxe-icon-indicator roll', text: '列表加载中...'}" :data="this[listStr+'List']" :scroll-y="{enabled: true}">
  138. <vxe-column type="seq" width="60"></vxe-column>
  139. <vxe-column field="title" title="目录名称" width="200">
  140. <template #default="{ row, rowIndex }">
  141. <span v-if="row.title">{{row.title}}</span>
  142. <el-tag size="mini" v-else>默认使用网页标题</el-tag>
  143. </template>
  144. </vxe-column>
  145. <vxe-column field="url" title="网页链接"></vxe-column>
  146. <vxe-column field="status" title="下载状态" width="200">
  147. <template #default="{ row }">
  148. <template v-if="row.status == '1'">
  149. <i class="el-icon-info" style="font-size: 16px; color: #999;"></i>
  150. <span>待操作</span>
  151. </template>
  152. <template v-if="row.status == '2'">
  153. <i class="el-icon-loading" style="font-size: 16px; color: #999;"></i>
  154. <span>任务处理中...</span>
  155. </template>
  156. <template v-if="row.status == '3'">
  157. <i class="el-icon-loading" style="font-size: 16px; color: #999;"></i>
  158. <span>图片下载中..<span v-if="row.num > 0">第{{row.num}}张</span></span>
  159. </template>
  160. <template v-if="row.status == '4'">
  161. <i class="el-icon-success" style="font-size: 16px; color: #19be6b;"></i>
  162. <span>下载完成</span>
  163. </template>
  164. <template v-if="row.status == '5'">
  165. <i class="el-icon-error" style="font-size: 16px; color: #ed4014;"></i>
  166. <span>网络异常,请重试!</span>
  167. </template>
  168. </template>
  169. </vxe-column>
  170. <vxe-column title="操作" width="80">
  171. <template #default="{ row, rowIndex }">
  172. <i class="el-icon-delete cur-pointer" style="font-size: 20px;" @click="delFile(rowIndex)"></i>
  173. </template>
  174. </vxe-column>
  175. </vxe-table>
  176. </div>
  177. </div>
  178. </template>
  179. <el-dialog title="添加链接" :visible.sync="addVisible" width="500px" :close-on-click-modal="false" :close-on-press-escape="false" :show-close="false">
  180. <div>
  181. <el-form label-position="right" label-width="80px" :rules="rules" :model="formData" ref="formData">
  182. <el-form-item label="目录名称" prop="title">
  183. <el-input v-model="formData.title" placeholder="为空则默认使用网页标题前20个字符"></el-input>
  184. </el-form-item>
  185. <el-form-item label="网页链接" prop="url">
  186. <el-input type="textarea" :rows="10" :placeholder="'请输入网址链接(例:' + exampleUrl[menuIndex-1] + ')'" v-model="formData.url"></el-input>
  187. </el-form-item>
  188. </el-form>
  189. </div>
  190. <span slot="footer" class="dialog-footer">
  191. <el-button @click="addVisible = false; $refs['formData'].resetFields();">取 消</el-button>
  192. <el-button type="primary" @click="onSubmit">确 定</el-button>
  193. </span>
  194. </el-dialog>
  195. <el-dialog title="提示" :visible.sync="loginVisible" width="400px" :close-on-click-modal="false" :close-on-press-escape="false">
  196. <div style="text-align: center; color: #999; font-size: 14px;">
  197. <p>{{menuIndex == '2' ? '京东' : '天猫/淘宝'}}渠道需要登录后才能下载</p>
  198. <p style="font-size: 18px; color: #f73131; font-weight: 600; padding: 30px 40px 0;">目前检测还未登录{{menuIndex == '2' ? '京东' : '天猫/淘宝'}}账号,需立即登录</p>
  199. </div>
  200. <div slot="footer" class="dialog-footer-center">
  201. <el-button v-if="menuIndex == '2'" @click="loginVisible = false; loginUrl('https://passport.jd.com/new/login.aspx')">点击登录京东账号</el-button>
  202. <el-button v-else @click="loginVisible = false; loginUrl('https://login.taobao.com')">点击登录天猫/淘宝账号</el-button>
  203. </div>
  204. </el-dialog>
  205. </el-main>
  206. <el-footer height="48px">
  207. <!-- 更新 -->
  208. <soft-update ref="updateRef" :showDowload="dowloadModel" :dowloadFinish="finishModel"></soft-update>
  209. </el-footer>
  210. </el-container>
  211. </el-container>
  212. </el-container>
  213. </div>
  214. </template>
  215. <script>
  216. import os from 'os'
  217. import fs from 'fs'
  218. import request from 'request'
  219. import path from 'path';
  220. import xlsx from 'node-xlsx';
  221. import softUpdate from './update.vue';
  222. import softHeader from './header.vue';
  223. import softImg from './img.vue';
  224. import electronApi from '@/utils/electronApi';
  225. import pjson from '/package.json'
  226. // import puppeteer from 'puppeteer'
  227. import puppeteer from 'puppeteer-extra'
  228. const StealthPlugin = require('puppeteer-extra-plugin-stealth');
  229. let separator = '';
  230. if (os.platform == 'linux') {
  231. separator = '/'
  232. } else {
  233. separator = '\\'
  234. }
  235. // let chromePath = process.cwd() + '\\resources\\app\\node_modules\\puppeteer\\.local-chromium\\win64-1045629\\chrome-win\\chrome.exe';
  236. // if (process.env.NODE_ENV == 'development') {
  237. // chromePath = process.cwd() + '\\node_modules\\puppeteer\\.local-chromium\\win64-1045629\\chrome-win\\chrome.exe';
  238. // }
  239. export default {
  240. name: 'landing-page',
  241. components: {
  242. softUpdate,
  243. softHeader,
  244. softImg
  245. },
  246. data() {
  247. return {
  248. loginVisible: false,
  249. addVisible: false,
  250. formData: {
  251. title: '',
  252. url: ''
  253. },
  254. rules:{ //
  255. title: [
  256. { min: 0, max: 20, message: '不能超过 20 个字符', trigger: 'blur' },
  257. { pattern: /^[^\\/:*?"<>|]*$/, message: '标题中不能包含 \\ / : * ? " < > |', trigger: 'blur' }
  258. ],
  259. url: [
  260. { required: true, message: '请输入网页链接', trigger: 'blur' },
  261. { pattern: /^(http|https):\/\/.+$/, message: '请输入正确的网址链接(http://或https://开头)', trigger: 'blur' }
  262. ],
  263. },
  264. tabLoading: false,
  265. alibabaList: [],
  266. jdList: [],
  267. tbList: [],
  268. tmallList: [],
  269. commonList: [],
  270. productName: pjson.softInfo.softName,
  271. imgUrl: this.$api.imgUrl,
  272. imgSrc: '',
  273. menuIndex: '3',
  274. jdBrowser: '', // 打开京东的浏览器
  275. settingData: {
  276. detailImg: true,
  277. skuImg: true,
  278. commentImg: false,
  279. video: false,
  280. },
  281. exampleUrl: ['https://www.1688.com', 'https://www.jd.com', 'https://www.tmall.com', 'https://www.taobao.com'],
  282. fileList: [],
  283. downloadDir: os.userInfo().homedir + separator + "Downloads",
  284. dowloadModel: false,
  285. finishModel: false,
  286. loading: false,
  287. checkLoading: false, //点击检测登录状态
  288. tbStatus: 1, // 1、未检测 2、已经登录 3、未登录
  289. jdStatus: 1, // 1、未检测 2、已经登录 3、未登录
  290. execLimit: 2,
  291. execNum: 3, // 限制5张
  292. };
  293. },
  294. computed: {
  295. listStr: function(){
  296. let str = 'alibaba';
  297. switch(this.menuIndex){
  298. case '1':
  299. str = 'alibaba';
  300. break;
  301. case '2':
  302. str = 'jd';
  303. break;
  304. case '3':
  305. str = 'tmall';
  306. break;
  307. case '4':
  308. str = 'tb';
  309. break;
  310. case '10':
  311. str = 'common';
  312. break;
  313. }
  314. return str;
  315. }
  316. },
  317. async mounted() {
  318. this.$refs.updateRef.updateSoft(true);
  319. let homedir = os.userInfo().homedir;
  320. if (fs.existsSync(homedir + separator + "Desktop")) {
  321. this.downloadDir = homedir + separator + "Desktop"
  322. } else {
  323. this.downloadDir = homedir + separator + "Downloads"
  324. }
  325. if (!fs.existsSync(os.tmpdir() + separator + 'chrome-data-capture')) {
  326. fs.mkdirSync(os.tmpdir() + separator + 'chrome-data-capture');
  327. }
  328. if (!fs.existsSync(os.tmpdir() + separator + 'chrome-data-capture-jd')) {
  329. fs.mkdirSync(os.tmpdir() + separator + 'chrome-data-capture-jd');
  330. }
  331. let path = os.tmpdir() + separator + 'chrome-data-capture';
  332. let path2 = os.tmpdir() + separator + 'chrome-data-capture-jd';
  333. //this.deleteAll(path, false);
  334. //this.deleteAll(path2, false);
  335. // 打开浏览器
  336. const {
  337. shell
  338. } = require('electron');
  339. const links = document.querySelectorAll('a[href]');
  340. links.forEach(link => {
  341. link.addEventListener('click', e => {
  342. const url = link.getAttribute('href');
  343. e.preventDefault();
  344. shell.openExternal(url);
  345. });
  346. });
  347. },
  348. methods: {
  349. // 删除文件夹内容
  350. deleteAll(folderPath, flag) {
  351. if (fs.existsSync(folderPath)) {
  352. fs.readdirSync(folderPath).forEach((file, index) => {
  353. var curPath = path.join(folderPath, file);
  354. if (fs.lstatSync(curPath).isDirectory()) {
  355. this.deleteAll(curPath, true);
  356. } else {
  357. fs.unlinkSync(curPath);
  358. }
  359. });
  360. if(flag){
  361. fs.rmdirSync(folderPath);
  362. }
  363. }
  364. },
  365. checkAuthority(){
  366. let authority = this.$refs.headerRef.authority;
  367. this.$refs.imgRef.authority = authority;
  368. },
  369. setMenuIndex(index){
  370. this.menuIndex = index;
  371. if(index.indexOf('2-') > -1){
  372. let num = Number(index.split('-')[1]);
  373. this.$refs.imgRef.setMenuIndex(num);
  374. }
  375. },
  376. // 选择目录
  377. pickPath() {
  378. this.$refs['upload-input'].blur();
  379. electronApi.call('pickDir', []).then((path) => {
  380. if (path) {
  381. this.downloadDir = path;
  382. }
  383. });
  384. },
  385. // 打开自定义下载目录
  386. openFolder() {
  387. let path = this.downloadDir;
  388. if (fs.existsSync(this.downloadDir + separator + pjson.softInfo.softName)) {
  389. path = this.downloadDir + separator + pjson.softInfo.softName;
  390. } else {
  391. fs.mkdirSync(this.downloadDir + separator + pjson.softInfo.softName);
  392. path = this.downloadDir + separator + pjson.softInfo.softName;
  393. }
  394. electronApi.call('showItemInfolder', [path + '\\tty.tty'])
  395. },
  396. openVip() {
  397. this.$refs.headerRef.openVip();
  398. },
  399. updateSoft() {
  400. this.$refs.updateRef.updateSoft();
  401. },
  402. // 删除文件
  403. delFile(rowIndex){
  404. let type = 'alibaba';
  405. switch(this.menuIndex){
  406. case '1':
  407. type = 'alibaba';
  408. break;
  409. case '2':
  410. type = 'jd';
  411. break;
  412. case '3':
  413. type = 'tmall';
  414. break;
  415. case '4':
  416. type = 'tb';
  417. break;
  418. case '10':
  419. type = 'common';
  420. break;
  421. }
  422. this.$confirm('确认删除此行数据吗?', '提示', {
  423. confirmButtonText: '确定',
  424. cancelButtonText: '取消',
  425. type: 'warning'
  426. }).then(() => {
  427. this[type+'List'].splice(rowIndex, 1);
  428. if(this[type+'List'].length == 0) {
  429. this.clearList();
  430. }
  431. }).catch(() => {
  432. });
  433. },
  434. // 清除列表
  435. clearList() {
  436. switch(this.menuIndex){
  437. case '1':
  438. this.alibabaList = [];
  439. break;
  440. case '2':
  441. this.jdList = [];
  442. break;
  443. case '3':
  444. this.tmallList = [];
  445. break;
  446. case '4':
  447. this.tbList = [];
  448. break;
  449. case '10':
  450. this.commonList = [];
  451. break;
  452. }
  453. },
  454. // 提交表单
  455. onSubmit(){
  456. this.$refs['formData'].validate((valid) => {
  457. if (valid) {
  458. let info = {
  459. url: this.formData.url,
  460. title: this.formData.title,
  461. status: '1',
  462. num: 0,
  463. newPath: ''
  464. }
  465. switch(this.menuIndex){
  466. case '1':
  467. this.alibabaList.push(info);
  468. break;
  469. case '2':
  470. this.jdList.push(info);
  471. break;
  472. case '3':
  473. this.tmallList.push(info);
  474. break;
  475. case '4':
  476. this.tbList.push(info);
  477. break;
  478. case '10':
  479. this.commonList.push(info);
  480. break;
  481. }
  482. this.$refs['formData'].resetFields();
  483. this.addVisible = false;
  484. } else {
  485. return false;
  486. }
  487. });
  488. },
  489. async pickLink() {
  490. const spinLoad = this.$loading();
  491. await electronApi.call('pickFile', ['xlsx,xls', true]).then(async (path) => {
  492. spinLoad.close();
  493. if(path.length > 0){
  494. this.$notify({
  495. title: '提示',
  496. message: '导入成功',
  497. type: 'success'
  498. });
  499. let workSheetsFromBuffer = xlsx.parse(fs.readFileSync(path[0]));
  500. if(workSheetsFromBuffer && workSheetsFromBuffer.length > 0){
  501. let errMsg = "";
  502. workSheetsFromBuffer[0].data.map((item, index) => {
  503. if(item.length > 0){
  504. let ititle = '';
  505. if(item[0]){
  506. ititle = item[0].toString().trim();
  507. }
  508. if(item[0] == '目录名称' && item[1] == '网页链接'){
  509. return false;
  510. }
  511. if(this.containsAnyChar(ititle.toString(), ['\\', '/', ':', '*', '?', '"', '<', '>', '|'])){ //判断是否含有特殊字符
  512. errMsg += "第" + (index+1) + '行-名称不能包以下字符 \\ / : * ? " < > |';
  513. ititle = ititle.replace(/[\\|/|:|*|?|"|<|>||]/g, "");
  514. }
  515. if(item[1] == undefined){
  516. errMsg += "第" + (index+1) + "行格式有误</br>";
  517. item[1] = '';
  518. }else if(!/^(http|https):\/\/.+$/.exec(item[1])){
  519. errMsg += "第" + (index+1) + "行网址格式有误</br>";
  520. }else{
  521. let info = {
  522. url: item[1],
  523. title: ititle,
  524. status: '1',
  525. num: 0,
  526. newPath: ''
  527. }
  528. switch(this.menuIndex){
  529. case '1':
  530. this.alibabaList.push(info);
  531. break;
  532. case '2':
  533. this.jdList.push(info);
  534. break;
  535. case '3':
  536. this.tmallList.push(info);
  537. break;
  538. case '4':
  539. this.tbList.push(info);
  540. break;
  541. case '10':
  542. this.commonList.push(info);
  543. break;
  544. }
  545. }
  546. }
  547. });
  548. if(errMsg){
  549. this.$notify({
  550. title: '请检查文件以下问题',
  551. dangerouslyUseHTMLString: true,
  552. message: errMsg,
  553. type: 'warning'
  554. });
  555. }
  556. }else{
  557. this.$notify({
  558. title: '提示',
  559. message: '格式有误,请重新导入',
  560. type: 'warning'
  561. });
  562. }
  563. }
  564. });
  565. },
  566. // 清除缓存
  567. clearCache(){
  568. this.jdStatus = 3;
  569. this.tbStatus = 3;
  570. },
  571. // 去登录
  572. loginUrl(url){
  573. (async () => {
  574. try{
  575. if (!fs.existsSync(os.tmpdir() + separator + 'chrome-data-capture')) {
  576. fs.mkdirSync(os.tmpdir() + separator + 'chrome-data-capture');
  577. }
  578. if (!fs.existsSync(os.tmpdir() + separator + 'chrome-data-capture-jd')) {
  579. fs.mkdirSync(os.tmpdir() + separator + 'chrome-data-capture-jd');
  580. }
  581. let userDataDir = os.tmpdir() + separator + 'chrome-data-capture';
  582. if(url.indexOf('.jd.com/') > -1){
  583. userDataDir = os.tmpdir() + separator + 'chrome-data-capture-jd';
  584. }
  585. const tbBrowser = await puppeteer.launch({
  586. headless: false,
  587. executablePath: puppeteer.executablePath().replace('win32-1', 'win64-1'),
  588. args: ['--window-size=1280,800'],
  589. userDataDir: userDataDir,
  590. });
  591. const page = await tbBrowser.newPage();
  592. await page.setViewport({ width: 1280, height: 800 });
  593. await page.evaluateOnNewDocument(() => {
  594. const newProto = navigator.__proto__;
  595. delete newProto.webdriver;
  596. navigator.__proto__ = newProto;
  597. });
  598. await page.goto(url, {waitUntil : 'networkidle2'});
  599. }catch(e){
  600. this.showError(e);
  601. }
  602. })();
  603. },
  604. // 开始下载
  605. async exportFile(flag) {
  606. let authority = this.$refs.headerRef.authority.isAuthority;
  607. if (!fs.existsSync(this.downloadDir + separator + pjson.softInfo.softName)) {
  608. fs.mkdirSync(this.downloadDir + separator + pjson.softInfo.softName);
  609. }
  610. let fileList = [];
  611. switch(this.menuIndex){
  612. case '1': // 阿里巴巴
  613. fileList = this.alibabaList;
  614. break;
  615. case '2': // 京东
  616. fileList = this.jdList;
  617. break;
  618. case '3': // 天猫
  619. fileList = this.tmallList;
  620. break;
  621. case '4': // 淘宝
  622. fileList = this.tbList;
  623. break;
  624. case '10': // 普通网址
  625. fileList = this.commonList;
  626. break;
  627. }
  628. if(fileList.length > 0){
  629. if (!authority && !flag) { // 非会员点击转换弹出提示框
  630. this.$refs.headerRef.memberModel = true;
  631. this.$refs.headerRef.isClick = true;
  632. return false;
  633. } else {
  634. this.$refs.headerRef.memberModel = false;
  635. this.loading = true;
  636. setTimeout(() => {
  637. this.loading = false;
  638. }, 60000);
  639. }
  640. if (!fs.existsSync(os.tmpdir() + separator + 'chrome-data-capture')) {
  641. fs.mkdirSync(os.tmpdir() + separator + 'chrome-data-capture');
  642. }
  643. if(this.menuIndex == '2'){ // 京东
  644. if(this.jdStatus == 1 || this.jdStatus == 3){ // 未检测登录状态/或提示未登录状态,开始检测
  645. await this.checkJdLogin().then((data) => {
  646. if(data != 2){ // 未登录
  647. this.jdStatus = 3;
  648. this.loginVisible = true;
  649. }
  650. }).catch(err => {
  651. this.jdStatus = 3;
  652. });
  653. if(this.jdStatus == 3){
  654. this.loading = false;
  655. return false;
  656. }
  657. }
  658. }
  659. if(this.menuIndex == '3' || this.menuIndex == '4'){ // 天猫/淘宝
  660. if(this.tbStatus == 1 || this.tbStatus == 3){ // 未检测登录状态/或提示未登录状态,开始检测
  661. await this.checkLogin().then((data) => {
  662. if(data != 2){ // 未登录
  663. this.tbStatus = 3;
  664. this.loginVisible = true;
  665. }
  666. }).catch(err => {
  667. this.tbStatus = 3;
  668. });
  669. }
  670. if(this.tbStatus == 3){
  671. this.loading = false;
  672. return false;
  673. }
  674. }
  675. let taskArr = [];
  676. let task = "";
  677. for(let i = 0; i < fileList.length; i++){
  678. let item = fileList[i];
  679. switch(this.menuIndex){
  680. case '1': // 阿里巴巴
  681. task = this.alibabaDownload(item);
  682. break;
  683. case '2': // 京东
  684. task = this.jdScanImg(item);
  685. break;
  686. case '3': // 天猫
  687. case '4': // 淘宝
  688. task = this.tbScanImg(item);
  689. break;
  690. case '10': // 普通网址
  691. task = this.normalDownload(item);
  692. break;
  693. }
  694. if(task){
  695. taskArr.push(task);
  696. }
  697. if((i+1) % this.execLimit == 0){
  698. await Promise.all(taskArr).then(result => {
  699. taskArr = [];
  700. }).catch(err => {
  701. console.log('err'+i, err)
  702. })
  703. }
  704. }
  705. if(taskArr.length > 0){
  706. await Promise.all(taskArr).then(result => {
  707. taskArr = [];
  708. }).catch(err => {
  709. // 错误文件添加到服务中
  710. console.log('err',err)
  711. })
  712. }
  713. let tbLogin = true,jdLogin = true;
  714. if((this.menuIndex == '3' || this.menuIndex == '4') && this.tbStatus == 3){
  715. tbLogin = false;
  716. }
  717. if(this.menuIndex == '2' && this.jdStatus == 3){
  718. jdLogin = false;
  719. }
  720. this.loading = false;
  721. // 打开文件夹
  722. if(fileList.length > 0 && tbLogin && jdLogin){
  723. this.$message({message: '恭喜你,任务已完成!', type: 'success'});
  724. electronApi.call('showItemInfolder',[this.downloadDir + separator + pjson.softInfo.softName +'\\tty.tty'])
  725. }
  726. }
  727. },
  728. // 10-普通网址下载
  729. async normalDownload(urlInfo){
  730. let task = await new Promise((resolve,reject) =>{
  731. (async () => {
  732. try{
  733. let authority = this.$refs.headerRef.authority.isAuthority;
  734. let number = 0;
  735. urlInfo.status = '2';
  736. urlInfo.num = 0;
  737. const browser = await puppeteer.launch({
  738. executablePath: puppeteer.executablePath().replace('win32-1', 'win64-1'),
  739. userDataDir: os.tmpdir() + separator + 'chrome-data-capture',
  740. });
  741. const page = await browser.newPage();
  742. page.on('response', async(response) => {
  743. // 检查响应的 MIME 类型是否以 'image/' 开头
  744. if (response.headers()['content-type'] && response.headers()['content-type'].startsWith('image/') && response.headers()['content-length']) {
  745. let imgArr = ['gif', 'jpeg', 'png', 'webp', 'svg', 'tiff', 'bmp', 'ico', 'avif'];
  746. let imgType = 'jpg';
  747. let isBase = false;
  748. imgArr.map((item, index) => {
  749. if(response.headers()['content-type'].indexOf(item) > -1){
  750. imgType = item;
  751. if(item == 'jpeg'){
  752. imgType = 'jpg';
  753. }else if(item == 'avif'){
  754. imgType = 'png';
  755. }
  756. }
  757. });
  758. let url = response.url();
  759. let regex = /^data:image\/[\w|+|-]+;base64,/;
  760. if(regex.exec(url)){
  761. url = response.url().replace(/^data:image\/[\w|+|-]+;base64,/, '');
  762. isBase = true;
  763. }
  764. let imgInfo = {
  765. url: url,
  766. contentType: response.headers()['content-type'],
  767. status: response.status(),
  768. imgType: imgType,
  769. isBase: isBase
  770. }
  771. if(urlInfo.title){
  772. if (fs.existsSync(this.downloadDir + separator + pjson.softInfo.softName + separator + urlInfo.title)) {
  773. urlInfo.newPath = this.downloadDir + separator + pjson.softInfo.softName + separator + urlInfo.title;
  774. } else {
  775. fs.mkdirSync(this.downloadDir + separator + pjson.softInfo.softName + separator + urlInfo.title);
  776. urlInfo.newPath = this.downloadDir + separator + pjson.softInfo.softName + separator + urlInfo.title;
  777. }
  778. }else{
  779. await this.getTitle(page, urlInfo); // 生成页面标题对应的文件夹
  780. }
  781. let outputPath = urlInfo.newPath + '\\' + this.randomString(35) + '.' + imgInfo.imgType;
  782. urlInfo.status = '3';
  783. number++;
  784. if(!authority && number <= this.execNum){
  785. if(imgInfo.isBase){ //base64位图片下载
  786. this.downloadBaseImage(imgInfo.url, outputPath, urlInfo)
  787. }else{
  788. this.downloadImage(imgInfo.url, outputPath, urlInfo);
  789. }
  790. }
  791. if(authority){
  792. if(imgInfo.isBase){ //base64位图片下载
  793. this.downloadBaseImage(imgInfo.url, outputPath, urlInfo)
  794. }else{
  795. this.downloadImage(imgInfo.url, outputPath, urlInfo);
  796. }
  797. }
  798. }
  799. });
  800. await page.goto(urlInfo.url, {waitUntil : 'networkidle2'});
  801. let pageInfo = await page.evaluate(() => {
  802. let cHeight = document.documentElement.clientHeight;
  803. let scrollHeight = document.body.scrollHeight;
  804. return {'scrollHeight': scrollHeight, 'cHeight': cHeight}
  805. });
  806. let scrollHeight = pageInfo.scrollHeight;
  807. let cHeight = pageInfo.cHeight;
  808. let num = Math.ceil(scrollHeight / cHeight);
  809. let start = -1;
  810. let scrollInt = setInterval(async() => {
  811. start ++;
  812. await page.evaluate((start) => {
  813. let cHeight = document.documentElement.clientHeight;
  814. window.scrollTo({
  815. top: cHeight * start,
  816. behavior: "smooth"
  817. });
  818. }, start);
  819. if(start > num || start > 200){ // 防止页面过长,滚动200次自动停止
  820. clearInterval(scrollInt);
  821. await browser.close();
  822. urlInfo.status = '4';
  823. resolve(true);
  824. this.loading = false;
  825. }
  826. }, 500);
  827. }catch(e){
  828. urlInfo.status = '5';
  829. reject(e);
  830. this.showError(e);
  831. }
  832. })();
  833. });
  834. },
  835. // 1 - 阿里巴巴下载
  836. async alibabaDownload(urlInfo){
  837. let task = await new Promise((resolve,reject) =>{
  838. (async () => {
  839. try{
  840. let authority = this.$refs.headerRef.authority.isAuthority;
  841. urlInfo.status = '2';
  842. urlInfo.num = 0;
  843. puppeteer.use(StealthPlugin());
  844. const browser = await puppeteer.launch({
  845. executablePath: puppeteer.executablePath().replace('win32-1', 'win64-1'),
  846. userDataDir: os.tmpdir() + separator + 'chrome-data-capture',
  847. });
  848. const page = await browser.newPage();
  849. await page.goto(urlInfo.url, {waitUntil : 'networkidle2'});
  850. if(urlInfo.title){
  851. if (fs.existsSync(this.downloadDir + separator + pjson.softInfo.softName + separator + urlInfo.title)) {
  852. urlInfo.newPath = this.downloadDir + separator + pjson.softInfo.softName + separator + urlInfo.title;
  853. } else {
  854. fs.mkdirSync(this.downloadDir + separator + pjson.softInfo.softName + separator + urlInfo.title);
  855. urlInfo.newPath = this.downloadDir + separator + pjson.softInfo.softName + separator + urlInfo.title;
  856. }
  857. }else{
  858. await this.getTitle(page, urlInfo); // 生成页面标题对应的文件夹
  859. }
  860. let pageInfo = await page.evaluate(() => {
  861. let cHeight = document.documentElement.clientHeight;
  862. let scrollHeight = document.body.scrollHeight;
  863. return {'scrollHeight': scrollHeight, 'cHeight': cHeight}
  864. });
  865. let scrollHeight = pageInfo.scrollHeight;
  866. let cHeight = pageInfo.cHeight;
  867. let num = Math.ceil(scrollHeight / cHeight);
  868. let start = -1;
  869. let scrollInt = setInterval(async() => {
  870. start ++;
  871. num = await page.evaluate((start) => {
  872. let scrollHeight = document.body.scrollHeight;
  873. let cHeight = document.documentElement.clientHeight;
  874. let num = Math.ceil(scrollHeight / cHeight);
  875. window.scrollTo({
  876. top: cHeight * start,
  877. behavior: "smooth"
  878. });
  879. return num;
  880. }, start);
  881. if(start > num || start > 200){ // 防止页面过长,滚动200次自动停止
  882. urlInfo.status = '3';
  883. clearInterval(scrollInt);
  884. await this.alibabaScanImg(browser, page, urlInfo, authority);
  885. this.loading = false;
  886. urlInfo.status = '4';
  887. resolve(true);
  888. }
  889. }, 500);
  890. }catch(e){
  891. urlInfo.status = '5';
  892. reject(e);
  893. this.showError(e);
  894. }
  895. })();
  896. });
  897. },
  898. // 检查京东登录状态
  899. checkJdLogin(){
  900. this.checkLoading = true;
  901. this.jdStatus = 1;
  902. return new Promise((resolve, reject) => {
  903. (async () => {
  904. try{
  905. const jdBrowser = await puppeteer.launch({
  906. executablePath: puppeteer.executablePath().replace('win32-1', 'win64-1'),
  907. userDataDir: os.tmpdir() + separator + 'chrome-data-capture-jd',
  908. });
  909. const page = await jdBrowser.newPage();
  910. let testUrl = 'https://www.jd.com';
  911. await page.goto(testUrl, {waitUntil : 'networkidle2'});
  912. let loginInfo = await page.evaluate(() => {
  913. let navTags = document.querySelector('.link-login');
  914. let userTags = document.querySelector('.nickname');
  915. let userTags2 = document.querySelector('.nick'); //企业账号
  916. if(navTags && navTags.innerHTML.indexOf('请登录') > -1){
  917. return false;
  918. }else if(userTags || userTags2){
  919. return true;
  920. }else{
  921. return false;
  922. }
  923. });
  924. if(loginInfo){
  925. this.jdStatus = 2;
  926. }else{
  927. this.jdStatus = 3;
  928. }
  929. resolve(this.jdStatus);
  930. this.checkLoading = false;
  931. jdBrowser.close();
  932. }catch(e){
  933. reject(3);
  934. this.showError(e);
  935. }
  936. })();
  937. });
  938. },
  939. // 京东下载
  940. async jdScanImg(urlInfo){
  941. let task = await new Promise((resolve,reject) =>{
  942. (async () => {
  943. try{
  944. let authority = this.$refs.headerRef.authority.isAuthority;
  945. urlInfo.status = '2';
  946. urlInfo.num = 0;
  947. puppeteer.use(StealthPlugin());
  948. const jdBrowser = await puppeteer.launch({
  949. executablePath: puppeteer.executablePath().replace('win32-1', 'win64-1'),
  950. userDataDir: os.tmpdir() + separator + 'chrome-data-capture-jd',
  951. args: [
  952. '--no-sandbox',
  953. '--disable-setuid-sandbox',
  954. '--disable-blink-features=AutomationControlled',
  955. ]
  956. });
  957. const page = await jdBrowser.newPage();
  958. await page.evaluateOnNewDocument(() => {
  959. const newProto = navigator.__proto__;
  960. delete newProto.webdriver;
  961. navigator.__proto__ = newProto;
  962. });
  963. let jdImgInfo = {
  964. mainImg: [],
  965. skuImg: [],
  966. commentImg: [],
  967. detailImg: [],
  968. video: []
  969. };
  970. let titleFlag = true;
  971. let skuNum = 0, mainNum = 0, videoNum = 0;
  972. page.on('response', async(response) => {
  973. if(titleFlag){ // 第一次生成页面标题
  974. if(urlInfo.title){
  975. if (fs.existsSync(this.downloadDir + separator + pjson.softInfo.softName + separator + urlInfo.title)) {
  976. urlInfo.newPath = this.downloadDir + separator + pjson.softInfo.softName + separator + urlInfo.title;
  977. } else {
  978. fs.mkdirSync(this.downloadDir + separator + pjson.softInfo.softName + separator + urlInfo.title);
  979. urlInfo.newPath = this.downloadDir + separator + pjson.softInfo.softName + separator + urlInfo.title;
  980. }
  981. }else{
  982. await this.getTitle(page, urlInfo); // 生成页面标题对应的文件夹
  983. }
  984. titleFlag = false;
  985. }
  986. // 检查响应的 MIME 类型是否以 'image/' 开头
  987. if (response.headers()['content-type'] && response.headers()['content-type'].startsWith('application/json')) {
  988. let detailUrl = '';
  989. let videoUrl = '';
  990. if(response.url().indexOf('/description/') > -1){ // 商品详情接口
  991. detailUrl = response.url();
  992. }
  993. if(response.url().indexOf('/tencent/video_v3') > -1){ // 商品视频接口
  994. videoUrl = response.url();
  995. }
  996. urlInfo.status = '3';
  997. if(detailUrl && this.settingData.detailImg){ // jd商品详情
  998. try {
  999. let data = await response.text();
  1000. if(data.indexOf('showdesc(') > -1){
  1001. data = data.slice(0, -1).replace('showdesc(', '');
  1002. }
  1003. let detailInfo = JSON.parse(data);
  1004. let regex = /\/\/img[0-9]+.360buyimg.com\S+.(jpg|jpeg|png|gif|avif|tif|tiff)/g;
  1005. let detailImgArr = [];
  1006. if(detailInfo && detailInfo.content){
  1007. detailImgArr = detailInfo.content.match(regex);
  1008. }
  1009. jdImgInfo.detailImg = detailImgArr;
  1010. for(let i = 0; i < detailImgArr.length; i++){
  1011. let imgUrl = 'https:' + detailImgArr[i];
  1012. let fileName = imgUrl.split('/').pop();
  1013. if(fileName){
  1014. let queryIndex = fileName.indexOf('?');
  1015. if (queryIndex !== -1) {
  1016. fileName = fileName.substr(0, queryIndex);
  1017. }
  1018. let num = Number(i) + 1;
  1019. let suffix = '';
  1020. if(fileName.lastIndexOf('.') > -1){
  1021. suffix = fileName.substr(fileName.lastIndexOf('.'));
  1022. }
  1023. if (!fs.existsSync(urlInfo.newPath + '\\详情图')) {
  1024. fs.mkdirSync(urlInfo.newPath + '\\详情图');
  1025. }
  1026. let outputPath = urlInfo.newPath + '\\详情图\\详情图' + num + suffix;
  1027. if(!authority && i < this.execNum){
  1028. await this.downloadImage(imgUrl, outputPath, urlInfo);
  1029. }
  1030. if(authority){
  1031. await this.downloadImage(imgUrl, outputPath, urlInfo);
  1032. }
  1033. }
  1034. }
  1035. } catch (error) {
  1036. console.error('详情图片解析失败:', error);
  1037. }
  1038. }
  1039. if(videoUrl && this.settingData.video){ // jd商品视频
  1040. try {
  1041. let data = await response.text();
  1042. data = data.slice(0, -1).replace(/^jQuery[0-9]+\(/, '');
  1043. let videoInfo = JSON.parse(data);
  1044. let videoUrl = videoInfo.playUrl;
  1045. jdImgInfo.video.push(videoUrl);
  1046. let fileName = videoUrl.split('/').pop();
  1047. if(fileName){
  1048. let queryIndex = fileName.indexOf('?');
  1049. if (queryIndex !== -1) {
  1050. fileName = fileName.substr(0, queryIndex);
  1051. }
  1052. if (!fs.existsSync(urlInfo.newPath + '\\视频')) {
  1053. fs.mkdirSync(urlInfo.newPath + '\\视频');
  1054. }
  1055. let outputPath = urlInfo.newPath + '\\视频\\' + fileName;
  1056. await this.downloadImage(videoUrl, outputPath, urlInfo);
  1057. }
  1058. } catch (error) {
  1059. console.error('视频解析失败:', error);
  1060. }
  1061. }
  1062. }
  1063. // if (response.headers()['content-type'] && response.headers()['content-type'].startsWith('image/')) {
  1064. // let regex = /^https:\/\/img[0-9]+.360buyimg.com\/n/;
  1065. // if(regex.exec(response.url())){ // 匹配符合规则的图片路径
  1066. // let skuReg = /\/n[0-9]+\/s(60|40)x(80|40)_jfs\//;
  1067. // if(response.url().match(skuReg) && this.settingData.skuImg){ // sku图片
  1068. // let replaceStr = '/n1/s800x800_jfs/';
  1069. // if(response.url().match(/\/n[0-9]+\/s60x80_jfs\//)){
  1070. // replaceStr = '/n1/s750x1000_jfs/';
  1071. // }
  1072. // let skuImgUrl = response.url().replace(skuReg, replaceStr).replace('.avif', '');
  1073. // if(response.url().match(skuReg))
  1074. // jdImgInfo.skuImg.push(skuImgUrl);
  1075. // let fileName = skuImgUrl.split('/').pop();
  1076. // if(fileName){
  1077. // let queryIndex = fileName.indexOf('?');
  1078. // if (queryIndex !== -1) {
  1079. // fileName = fileName.substr(0, queryIndex);
  1080. // }
  1081. // if (!fs.existsSync(urlInfo.newPath + '\\sku图')) {
  1082. // fs.mkdirSync(urlInfo.newPath + '\\sku图');
  1083. // }
  1084. // let outputPath = urlInfo.newPath + '\\sku图\\' + fileName;
  1085. // skuNum ++;
  1086. // if(!authority && skuNum <= this.execNum){
  1087. // await this.downloadImage(skuImgUrl, outputPath, urlInfo);
  1088. // }
  1089. // if(authority){
  1090. // await this.downloadImage(skuImgUrl, outputPath, urlInfo);
  1091. // }
  1092. // }
  1093. // }
  1094. // let reg = /\/n[0-9]+\/jfs\//;
  1095. // let reg2 = /\/n[0-9]+\/s(54|50)x(54|66)_jfs\//;
  1096. // if(response.url().match(reg) || response.url().match(reg2)){ // 主图
  1097. // let replaceStr = '/n1/s800x800_jfs/';
  1098. // if(response.url().match(/\/n[0-9]+\/s50x66_jfs\//)){
  1099. // replaceStr = '/n1/s750x1000_jfs/';
  1100. // }
  1101. // let mainImgUrl = response.url().replace(reg, replaceStr).replace(reg2, replaceStr).replace('.avif', '');
  1102. // jdImgInfo.mainImg.push(mainImgUrl);
  1103. // let fileName = mainImgUrl.split('/').pop();
  1104. // if(fileName){
  1105. // let queryIndex = fileName.indexOf('?');
  1106. // let queryIndex2 = fileName.indexOf('!');
  1107. // if (queryIndex !== -1) {
  1108. // fileName = fileName.substr(0, queryIndex);
  1109. // }
  1110. // if (queryIndex2 !== -1) {
  1111. // fileName = fileName.substr(0, queryIndex2);
  1112. // }
  1113. // if (!fs.existsSync(urlInfo.newPath + '\\主图')) {
  1114. // fs.mkdirSync(urlInfo.newPath + '\\主图');
  1115. // }
  1116. // let outputPath = urlInfo.newPath + '\\主图\\' + fileName;
  1117. // mainNum ++;
  1118. // if(!authority && mainNum <= this.execNum){
  1119. // await this.downloadImage(mainImgUrl, outputPath, urlInfo);
  1120. // }
  1121. // if(authority){
  1122. // await this.downloadImage(mainImgUrl, outputPath, urlInfo);
  1123. // }
  1124. // }
  1125. // }
  1126. // }
  1127. // }
  1128. });
  1129. await page.goto(urlInfo.url, {waitUntil : 'networkidle2'});
  1130. /**new**/
  1131. //detailImg:详情图;skuImg:sku图片;commentImg: 评论图;video: 视频
  1132. const imgInfo = await page.evaluate((authority, execNum) => {
  1133. let outObj = {
  1134. mainImg: [],
  1135. skuImg: [],
  1136. };
  1137. //主图
  1138. let arr1 = document.querySelectorAll('#spec-list img');
  1139. for(let i=0; i< arr1.length; i++){
  1140. let mainImgUrl = arr1[i].src;
  1141. let reg = /\/n[0-9]+\/jfs\//;
  1142. let reg2 = /\/n[0-9]+\/s(54|50)x(54|66)_jfs\//;
  1143. let replaceStr = '/n1/s800x800_jfs/';
  1144. if(mainImgUrl.match(/\/n[0-9]+\/s50x66_jfs\//)){
  1145. replaceStr = '/n1/s750x1000_jfs/';
  1146. }
  1147. mainImgUrl = mainImgUrl.replace(reg, replaceStr).replace(reg2, replaceStr).replace('.avif', '');
  1148. if(!authority && i < execNum){
  1149. outObj.mainImg.push(mainImgUrl);
  1150. }
  1151. if(authority){
  1152. outObj.mainImg.push(mainImgUrl);
  1153. }
  1154. }
  1155. //sku图片
  1156. let arr2 = document.querySelectorAll('#choose-attr-1 img');
  1157. for(let i=0; i< arr2.length; i++){
  1158. let skuImgUrl = arr2[i].src;
  1159. let skuReg = /\/n[0-9]+\/s(60|40)x(80|40)_jfs\//;
  1160. let replaceStr = '/n1/s800x800_jfs/';
  1161. if(skuImgUrl.match(/\/n[0-9]+\/s60x80_jfs\//)){
  1162. replaceStr = '/n1/s750x1000_jfs/';
  1163. }
  1164. skuImgUrl = skuImgUrl.replace(skuReg, replaceStr).replace('.avif', '');
  1165. if(!authority && i < execNum){
  1166. outObj.skuImg.push(skuImgUrl);
  1167. }
  1168. if(authority){
  1169. outObj.skuImg.push(skuImgUrl);
  1170. }
  1171. }
  1172. return outObj;
  1173. }, authority, this.execNum);
  1174. // 主图下载
  1175. for(let j = 0; j < imgInfo.mainImg.length; j++){
  1176. let fileName = imgInfo.mainImg[j].split('/').pop();
  1177. if(fileName){
  1178. let queryIndex = fileName.indexOf('?');
  1179. if (queryIndex !== -1) {
  1180. fileName = fileName.substr(0, queryIndex);
  1181. }
  1182. let num = Number(j) + 1;
  1183. let suffix = '';
  1184. if(fileName.lastIndexOf('.') > -1){
  1185. suffix = fileName.substr(fileName.lastIndexOf('.'));
  1186. }
  1187. if (!fs.existsSync(urlInfo.newPath + '\\主图')) {
  1188. fs.mkdirSync(urlInfo.newPath + '\\主图');
  1189. }
  1190. let outputPath = urlInfo.newPath + '\\主图\\主图' + num + suffix;
  1191. await this.downloadImage(imgInfo.mainImg[j], outputPath, urlInfo);
  1192. }
  1193. }
  1194. // sku图片下载
  1195. if(this.settingData.skuImg){
  1196. for(let j = 0; j < imgInfo.skuImg.length; j++){
  1197. let fileName = imgInfo.skuImg[j].split('/').pop();
  1198. if(fileName){
  1199. let queryIndex = fileName.indexOf('?');
  1200. if (queryIndex !== -1) {
  1201. fileName = fileName.substr(0, queryIndex);
  1202. }
  1203. let num = Number(j) + 1;
  1204. let suffix = '';
  1205. if(fileName.lastIndexOf('.') > -1){
  1206. suffix = fileName.substr(fileName.lastIndexOf('.'));
  1207. }
  1208. if (!fs.existsSync(urlInfo.newPath + '\\sku图')) {
  1209. fs.mkdirSync(urlInfo.newPath + '\\sku图');
  1210. }
  1211. let outputPath = urlInfo.newPath + '\\sku图\\sku图' + num + suffix;
  1212. await this.downloadImage(imgInfo.skuImg[j], outputPath, urlInfo);
  1213. }
  1214. }
  1215. }
  1216. /**end**/
  1217. await jdBrowser.close();
  1218. urlInfo.status = '4';
  1219. resolve(true);
  1220. }catch(e){
  1221. reject(e);
  1222. this.showError(e);
  1223. }
  1224. })();
  1225. });
  1226. },
  1227. // 检查天猫淘宝登录状态
  1228. checkLogin(){
  1229. this.checkLoading = true;
  1230. this.tbStatus = 1;
  1231. return new Promise((resolve, reject) => {
  1232. (async () => {
  1233. try{
  1234. const tbBrowser = await puppeteer.launch({
  1235. executablePath: puppeteer.executablePath().replace('win32-1', 'win64-1'),
  1236. userDataDir: os.tmpdir() + separator + 'chrome-data-capture',
  1237. });
  1238. const page = await tbBrowser.newPage();
  1239. let testUrl = 'https://www.taobao.com';
  1240. await page.goto(testUrl, {waitUntil : 'networkidle2'});
  1241. let loginInfo = await page.evaluate(() => {
  1242. let navTags = document.querySelector('.site-nav-sign a');
  1243. let userTags = document.querySelector('.site-nav-user a');
  1244. if(navTags && navTags.innerHTML.indexOf('登录') > -1){
  1245. return false;
  1246. }else if(userTags){
  1247. return true;
  1248. }else{
  1249. return false;
  1250. }
  1251. });
  1252. if(loginInfo){
  1253. this.tbStatus = 2;
  1254. }else{
  1255. this.tbStatus = 3;
  1256. }
  1257. resolve(this.tbStatus);
  1258. this.checkLoading = false;
  1259. tbBrowser.close();
  1260. }catch(e){
  1261. reject(3);
  1262. this.showError(e);
  1263. }
  1264. })();
  1265. });
  1266. },
  1267. // 淘宝天猫扫描下载图片
  1268. async tbScanImg(urlInfo){
  1269. let task = await new Promise((resolve,reject) =>{
  1270. (async () => {
  1271. try{
  1272. let authority = this.$refs.headerRef.authority.isAuthority;
  1273. urlInfo.status = '2';
  1274. urlInfo.num = 0;
  1275. puppeteer.use(StealthPlugin());
  1276. const tbBrowser = await puppeteer.launch({
  1277. executablePath: puppeteer.executablePath().replace('win32-1', 'win64-1'),
  1278. userDataDir: os.tmpdir() + separator + 'chrome-data-capture',
  1279. });
  1280. const page = await tbBrowser.newPage();
  1281. await page.goto(urlInfo.url, {waitUntil : 'networkidle0'});
  1282. if(urlInfo.title){
  1283. if (fs.existsSync(this.downloadDir + separator + pjson.softInfo.softName + separator + urlInfo.title)) {
  1284. urlInfo.newPath = this.downloadDir + separator + pjson.softInfo.softName + separator + urlInfo.title;
  1285. } else {
  1286. fs.mkdirSync(this.downloadDir + separator + pjson.softInfo.softName + separator + urlInfo.title);
  1287. urlInfo.newPath = this.downloadDir + separator + pjson.softInfo.softName + separator + urlInfo.title;
  1288. }
  1289. }else{
  1290. await this.getTitle(page, urlInfo); // 生成页面标题对应的文件夹
  1291. }
  1292. let responseVideo = [];
  1293. page.on('response', async(response) => {
  1294. // 检查响应的 MIME 类型是否以 'video/' 开头
  1295. if (response.headers()['content-type'] && response.headers()['content-type'].startsWith('video/')) {
  1296. responseVideo.push(response.url());
  1297. }
  1298. });
  1299. let pageInfo = await page.evaluate(() => {
  1300. let cHeight = document.documentElement.clientHeight;
  1301. let scrollHeight = document.body.scrollHeight;
  1302. return {'scrollHeight': scrollHeight, 'cHeight': cHeight}
  1303. });
  1304. //鼠标放在主图第一张,生成视频
  1305. const elementHandle = await page.$('li[class*=thumbnail--]');
  1306. if(elementHandle){
  1307. const classListProperty = await elementHandle.getProperty('classList');
  1308. const classList = await classListProperty.jsonValue();
  1309. const classesArray = Object.values(classList);
  1310. const allClasses = classesArray.join('.');
  1311. if(allClasses && allClasses.indexOf('active-') < 0){
  1312. await page.hover('li.'+allClasses);
  1313. }
  1314. }
  1315. let scrollHeight = pageInfo.scrollHeight;
  1316. let cHeight = pageInfo.cHeight;
  1317. let num = Math.ceil(scrollHeight / cHeight);
  1318. let start = -1;
  1319. let scrollInt = setInterval(async() => {
  1320. start ++;
  1321. num = await page.evaluate((start) => {
  1322. let scrollHeight = document.body.scrollHeight;
  1323. let cHeight = document.documentElement.clientHeight;
  1324. let num = Math.ceil(scrollHeight / cHeight);
  1325. window.scrollTo({
  1326. top: cHeight * start,
  1327. behavior: "smooth"
  1328. });
  1329. return num;
  1330. }, start);
  1331. if(start > num || start > 200){ // 防止页面过长,滚动200次自动停止
  1332. urlInfo.status = '3';
  1333. clearInterval(scrollInt);
  1334. //detailImg:详情图;skuImg:sku图片;commentImg: 评论图;video: 视频
  1335. const imgInfo = await page.evaluate((authority, execNum) => {
  1336. let outObj = {
  1337. mainImg: [],
  1338. detailImg: [],
  1339. skuImg: [],
  1340. commentImg: [],
  1341. video: []
  1342. };
  1343. // 正则表达式匹配字符 重写图片路径
  1344. let regex = /\.(.{3,4})_[0-9a-zA-z]+\.(.{3,4})_\.(.{3,4})/;
  1345. //主图
  1346. let arr1 = document.querySelectorAll('img[class^=PicGallery--thumbnailPic--]');
  1347. if(arr1.length === 0){
  1348. arr1 = document.querySelectorAll('img[class*=thumbnailPic--]');
  1349. }
  1350. for(let i=0; i< arr1.length; i++){
  1351. let mainImgUrl = arr1[i].src;
  1352. let result = regex.exec(mainImgUrl);
  1353. if(result){
  1354. mainImgUrl = mainImgUrl.replace(result[0], '.'+result[1]);
  1355. }
  1356. if(!authority && i < execNum){
  1357. outObj.mainImg.push(mainImgUrl);
  1358. }
  1359. if(authority){
  1360. outObj.mainImg.push(mainImgUrl);
  1361. }
  1362. }
  1363. //sku图片
  1364. let arr2 = document.querySelectorAll('img[class^=SkuContent--valueItemImg--]');
  1365. if(arr2.length === 0){
  1366. arr2 = document.querySelectorAll('img[class*=valueItemImg--]');
  1367. }
  1368. for(let i=0; i< arr2.length; i++){
  1369. let skuImgUrl = arr2[i].src;
  1370. let result = regex.exec(skuImgUrl);
  1371. if(result){
  1372. skuImgUrl = skuImgUrl.replace(result[0], '.'+result[1]);
  1373. }
  1374. if(!authority && i < execNum){
  1375. outObj.skuImg.push(skuImgUrl);
  1376. }
  1377. if(authority){
  1378. outObj.skuImg.push(skuImgUrl);
  1379. }
  1380. }
  1381. //详情图片
  1382. let arr3 = document.querySelectorAll('#content img');
  1383. for(let i=0; i< arr3.length; i++){
  1384. let detailImgUrl = arr3[i].src;
  1385. let lazyUrl = arr3[i].getAttribute('data-src');
  1386. if(arr3[i].src.indexOf('/s.gif') > -1 && lazyUrl){
  1387. detailImgUrl = lazyUrl;
  1388. if(!/^http/.exec(lazyUrl)){
  1389. detailImgUrl = 'https:' + lazyUrl;
  1390. }
  1391. }
  1392. let result = regex.exec(detailImgUrl);
  1393. if(result){
  1394. detailImgUrl = detailImgUrl.replace(result[0], '.'+result[1]);
  1395. }
  1396. if(!authority && i < execNum){
  1397. outObj.detailImg.push(detailImgUrl);
  1398. }
  1399. if(authority){
  1400. outObj.detailImg.push(detailImgUrl);
  1401. }
  1402. }
  1403. //评论图片
  1404. let arr4 = document.querySelectorAll('div[class^=Comments--comments--] img');
  1405. if(arr4.length === 0){
  1406. arr4 = document.querySelectorAll('div[class^=comments--] img');
  1407. }
  1408. for(let i=0; i< arr4.length; i++){
  1409. if(arr4[i].src.indexOf('/avatar/sns/user/flag/sns_logo') == -1){ //过滤淘宝用户头像
  1410. if(!authority && i < execNum){
  1411. outObj.commentImg.push(arr4[i].src);
  1412. }
  1413. if(authority){
  1414. outObj.commentImg.push(arr4[i].src);
  1415. }
  1416. }
  1417. }
  1418. // 视频
  1419. let arr5 = document.querySelectorAll('video.lib-video');
  1420. for(let i=0; i< arr5.length; i++){
  1421. if(outObj.video.indexOf(arr5[i].src) == -1){
  1422. if(!authority && i < execNum){
  1423. outObj.video.push(arr5[i].src);
  1424. }
  1425. if(authority){
  1426. outObj.video.push(arr5[i].src);
  1427. }
  1428. }
  1429. }
  1430. return outObj;
  1431. }, authority, this.execNum);
  1432. if(imgInfo.video.length == 0 && responseVideo.length > 0){
  1433. imgInfo.video = responseVideo;
  1434. }
  1435. // 主图下载
  1436. for(let j = 0; j < imgInfo.mainImg.length; j++){
  1437. let fileName = imgInfo.mainImg[j].split('/').pop();
  1438. if(fileName){
  1439. let queryIndex = fileName.indexOf('?');
  1440. if (queryIndex !== -1) {
  1441. fileName = fileName.substr(0, queryIndex);
  1442. }
  1443. let num = Number(j) + 1;
  1444. let suffix = '';
  1445. if(fileName.lastIndexOf('.') > -1){
  1446. suffix = fileName.substr(fileName.lastIndexOf('.'));
  1447. }
  1448. if (!fs.existsSync(urlInfo.newPath + '\\主图')) {
  1449. fs.mkdirSync(urlInfo.newPath + '\\主图');
  1450. }
  1451. let outputPath = urlInfo.newPath + '\\主图\\主图' + num + suffix;
  1452. await this.downloadImage(imgInfo.mainImg[j], outputPath, urlInfo);
  1453. }
  1454. }
  1455. // sku图片下载
  1456. if(this.settingData.skuImg){
  1457. for(let j = 0; j < imgInfo.skuImg.length; j++){
  1458. let fileName = imgInfo.skuImg[j].split('/').pop();
  1459. if(fileName){
  1460. let queryIndex = fileName.indexOf('?');
  1461. if (queryIndex !== -1) {
  1462. fileName = fileName.substr(0, queryIndex);
  1463. }
  1464. let num = Number(j) + 1;
  1465. let suffix = '';
  1466. if(fileName.lastIndexOf('.') > -1){
  1467. suffix = fileName.substr(fileName.lastIndexOf('.'));
  1468. }
  1469. if (!fs.existsSync(urlInfo.newPath + '\\sku图')) {
  1470. fs.mkdirSync(urlInfo.newPath + '\\sku图');
  1471. }
  1472. let outputPath = urlInfo.newPath + '\\sku图\\sku图' + num + suffix;
  1473. await this.downloadImage(imgInfo.skuImg[j], outputPath, urlInfo);
  1474. }
  1475. }
  1476. }
  1477. //详情图下载
  1478. if(this.settingData.detailImg){
  1479. for(let j = 0; j < imgInfo.detailImg.length; j++){
  1480. let fileName = imgInfo.detailImg[j].split('/').pop();
  1481. if(fileName){
  1482. let queryIndex = fileName.indexOf('?');
  1483. if (queryIndex !== -1) {
  1484. fileName = fileName.substr(0, queryIndex);
  1485. }
  1486. let num = Number(j) + 1;
  1487. let suffix = '';
  1488. if(fileName.lastIndexOf('.') > -1){
  1489. suffix = fileName.substr(fileName.lastIndexOf('.'));
  1490. }
  1491. if (!fs.existsSync(urlInfo.newPath + '\\详情图')) {
  1492. fs.mkdirSync(urlInfo.newPath + '\\详情图');
  1493. }
  1494. let outputPath = urlInfo.newPath + '\\详情图\\详情图' + num + suffix;
  1495. await this.downloadImage(imgInfo.detailImg[j], outputPath, urlInfo);
  1496. }
  1497. }
  1498. }
  1499. //评论图下载
  1500. if(this.settingData.commentImg){
  1501. for(let j = 0; j < imgInfo.commentImg.length; j++){
  1502. let fileName = imgInfo.commentImg[j].split('/').pop();
  1503. if(fileName){
  1504. let queryIndex = fileName.indexOf('?');
  1505. if (queryIndex !== -1) {
  1506. fileName = fileName.substr(0, queryIndex);
  1507. }
  1508. let num = Number(j) + 1;
  1509. let suffix = '';
  1510. if(fileName.lastIndexOf('.') > -1){
  1511. suffix = fileName.substr(fileName.lastIndexOf('.'));
  1512. }
  1513. if (!fs.existsSync(urlInfo.newPath + '\\评论图')) {
  1514. fs.mkdirSync(urlInfo.newPath + '\\评论图');
  1515. }
  1516. let outputPath = urlInfo.newPath + '\\评论图\\评论图' + num + suffix;
  1517. await this.downloadImage(imgInfo.commentImg[j], outputPath, urlInfo);
  1518. }
  1519. }
  1520. }
  1521. //视频下载
  1522. if(this.settingData.video){
  1523. for(let j = 0; j < imgInfo.video.length; j++){
  1524. let fileName = imgInfo.video[j].split('/').pop();
  1525. if(fileName){
  1526. let queryIndex = fileName.indexOf('?');
  1527. if (queryIndex !== -1) {
  1528. fileName = fileName.substr(0, queryIndex);
  1529. }
  1530. if (!fs.existsSync(urlInfo.newPath + '\\视频')) {
  1531. fs.mkdirSync(urlInfo.newPath + '\\视频');
  1532. }
  1533. let outputPath = urlInfo.newPath + '\\视频\\' + fileName;
  1534. await this.downloadImage(imgInfo.video[j], outputPath, urlInfo);
  1535. }
  1536. }
  1537. }
  1538. await tbBrowser.close();
  1539. urlInfo.status = '4';
  1540. resolve(true);
  1541. this.loading = false;
  1542. }
  1543. }, 300);
  1544. }catch(e){
  1545. reject(e);
  1546. this.showError(e);
  1547. }
  1548. })();
  1549. });
  1550. },
  1551. // 阿里巴巴 - 扫描并下载图片
  1552. async alibabaScanImg(browser, page, urlInfo, authority){
  1553. //detailImg:详情图;skuImg:sku图片;commentImg: 评论图;video: 视频
  1554. const imgInfo = await page.evaluate((authority, execNum) => {
  1555. let outObj = {
  1556. mainImg: [],
  1557. detailImg: [],
  1558. skuImg: [],
  1559. commentImg: [],
  1560. video: []
  1561. };
  1562. //主图
  1563. let arr1 = document.querySelectorAll('img.detail-gallery-img');
  1564. for(let i=0; i< arr1.length; i++){
  1565. if(!authority && i < execNum){
  1566. outObj.mainImg.push(arr1[i].src);
  1567. }
  1568. if(authority){
  1569. outObj.mainImg.push(arr1[i].src);
  1570. }
  1571. }
  1572. //sku图片
  1573. let arr2 = document.querySelectorAll('.prop-img');
  1574. if(arr2.length == 0){
  1575. arr2 = document.querySelectorAll('.sku-item-image');
  1576. }
  1577. for(let i=0; i< arr2.length; i++){
  1578. let src = window.getComputedStyle(arr2[i]).backgroundImage.replace(/url\(["']?(.+?)["']?\)/i, '$1');
  1579. if(!authority && i < execNum){
  1580. outObj.skuImg.push(src);
  1581. }
  1582. if(authority){
  1583. outObj.skuImg.push(src);
  1584. }
  1585. }
  1586. //详情图片
  1587. let arr3 = document.querySelectorAll('img.desc-img-loaded');
  1588. for(let i=0; i< arr3.length; i++){
  1589. if(!authority && i < execNum){
  1590. outObj.detailImg.push(arr3[i].src);
  1591. }
  1592. if(authority){
  1593. outObj.detailImg.push(arr3[i].src);
  1594. }
  1595. }
  1596. //评论图片 -- 需要点击切换
  1597. // let arr4 = document.querySelectorAll('img.image-box');
  1598. // for(let i=0; i< arr4.length; i++){
  1599. // if(!authority && i < execNum){
  1600. // outObj.commentImg.push(arr4[i].src);
  1601. // }
  1602. // if(authority){
  1603. // outObj.commentImg.push(arr4[i].src);
  1604. // }
  1605. // }
  1606. // 视频
  1607. let arr5 = document.querySelectorAll('video.lib-video');
  1608. for(let i=0; i< arr5.length; i++){
  1609. if(outObj.video.indexOf(arr5[i].src) == -1){
  1610. if(!authority && i < execNum){
  1611. outObj.video.push(arr5[i].src);
  1612. }
  1613. if(authority){
  1614. outObj.video.push(arr5[i].src);
  1615. }
  1616. }
  1617. }
  1618. return outObj;
  1619. }, authority, this.execNum);
  1620. // 主图下载
  1621. for(let j = 0; j < imgInfo.mainImg.length; j++){
  1622. let fileName = imgInfo.mainImg[j].split('/').pop();
  1623. if(fileName){
  1624. let queryIndex = fileName.indexOf('?');
  1625. if (queryIndex !== -1) {
  1626. fileName = fileName.substr(0, queryIndex);
  1627. }
  1628. let num = Number(j) + 1;
  1629. let suffix = '';
  1630. if(fileName.lastIndexOf('.') > -1){
  1631. suffix = fileName.substr(fileName.lastIndexOf('.'));
  1632. }
  1633. if (!fs.existsSync(urlInfo.newPath + '\\主图')) {
  1634. fs.mkdirSync(urlInfo.newPath + '\\主图');
  1635. }
  1636. let outputPath = urlInfo.newPath + '\\主图\\主图' + num + suffix;
  1637. await this.downloadImage(imgInfo.mainImg[j], outputPath, urlInfo);
  1638. }
  1639. }
  1640. // sku图片下载
  1641. if(this.settingData.skuImg){
  1642. for(let j = 0; j < imgInfo.skuImg.length; j++){
  1643. let fileName = imgInfo.skuImg[j].split('/').pop();
  1644. if(fileName){
  1645. let queryIndex = fileName.indexOf('?');
  1646. if (queryIndex !== -1) {
  1647. fileName = fileName.substr(0, queryIndex);
  1648. }
  1649. let num = Number(j) + 1;
  1650. let suffix = '';
  1651. if(fileName.lastIndexOf('.') > -1){
  1652. suffix = fileName.substr(fileName.lastIndexOf('.'));
  1653. }
  1654. if (!fs.existsSync(urlInfo.newPath + '\\sku图')) {
  1655. fs.mkdirSync(urlInfo.newPath + '\\sku图');
  1656. }
  1657. let outputPath = urlInfo.newPath + '\\sku图\\sku图' + num + suffix;
  1658. await this.downloadImage(imgInfo.skuImg[j], outputPath, urlInfo);
  1659. }
  1660. }
  1661. }
  1662. //详情图下载
  1663. if(this.settingData.detailImg){
  1664. for(let j = 0; j < imgInfo.detailImg.length; j++){
  1665. let fileName = imgInfo.detailImg[j].split('/').pop();
  1666. if(fileName){
  1667. let queryIndex = fileName.indexOf('?');
  1668. if (queryIndex !== -1) {
  1669. fileName = fileName.substr(0, queryIndex);
  1670. }
  1671. let num = Number(j) + 1;
  1672. let suffix = '';
  1673. if(fileName.lastIndexOf('.') > -1){
  1674. suffix = fileName.substr(fileName.lastIndexOf('.'));
  1675. }
  1676. if (!fs.existsSync(urlInfo.newPath + '\\详情图')) {
  1677. fs.mkdirSync(urlInfo.newPath + '\\详情图');
  1678. }
  1679. let outputPath = urlInfo.newPath + '\\详情图\\' + '详情图' + num + suffix;
  1680. await this.downloadImage(imgInfo.detailImg[j], outputPath, urlInfo);
  1681. }
  1682. }
  1683. }
  1684. //评论图下载
  1685. // if(this.settingData.commentImg){
  1686. // for(let j = 0; j < imgInfo.commentImg.length; j++){
  1687. // let fileName = imgInfo.commentImg[j].split('/').pop();
  1688. // if(fileName){
  1689. // let queryIndex = fileName.indexOf('?');
  1690. // if (queryIndex !== -1) {
  1691. // fileName = fileName.substr(0, queryIndex);
  1692. // }
  1693. // if (!fs.existsSync(urlInfo.newPath + '\\评论图')) {
  1694. // fs.mkdirSync(urlInfo.newPath + '\\评论图');
  1695. // }
  1696. // let outputPath = urlInfo.newPath + '\\评论图\\' + fileName;
  1697. // await this.downloadImage(imgInfo.commentImg[j], outputPath, urlInfo);
  1698. // }
  1699. // }
  1700. // }
  1701. //视频下载
  1702. if(this.settingData.video){
  1703. for(let j = 0; j < imgInfo.video.length; j++){
  1704. let fileName = imgInfo.video[j].split('/').pop();
  1705. if(fileName){
  1706. let queryIndex = fileName.indexOf('?');
  1707. if (queryIndex !== -1) {
  1708. fileName = fileName.substr(0, queryIndex);
  1709. }
  1710. if (!fs.existsSync(urlInfo.newPath + '\\视频')) {
  1711. fs.mkdirSync(urlInfo.newPath + '\\视频');
  1712. }
  1713. let outputPath = urlInfo.newPath + '\\视频\\' + fileName;
  1714. await this.downloadImage(imgInfo.video[j], outputPath, urlInfo);
  1715. }
  1716. }
  1717. }
  1718. await browser.close();
  1719. },
  1720. //
  1721. downloadExample(){
  1722. let url = 'https://www.xingyousoft.com/soft/XYCapture/example.xlsx';
  1723. if (!fs.existsSync(this.downloadDir + separator + pjson.softInfo.softName)) {
  1724. fs.mkdirSync(this.downloadDir + separator + pjson.softInfo.softName);
  1725. }
  1726. let path = this.downloadDir + separator + pjson.softInfo.softName + '\\链接模板下载.xlsx';
  1727. this.downloadImage(url, path, 'example');
  1728. },
  1729. // 下载网址链接的图片
  1730. async downloadImage(imageUrl, outputPath, urlInfo) {
  1731. let _this = this;
  1732. let received_bytes = 0;
  1733. let total_bytes = 0;
  1734. try {
  1735. let req = request({
  1736. method: 'GET', uri: imageUrl, strictSSL: false
  1737. });
  1738. let out = fs.createWriteStream(outputPath);
  1739. req.pipe(out);
  1740. return new Promise((resolve, reject) => {
  1741. req.on('response', (data) => {
  1742. total_bytes = parseInt(data.headers['content-length']);
  1743. const status = data.statusCode;
  1744. if (status < 200 || status >= 300) {
  1745. //reject(false);
  1746. this.$notify.error({
  1747. title: '网络图片访问异常!- 1',
  1748. message: imageUrl.slice(0,50)
  1749. });
  1750. }else if(isNaN(total_bytes)){
  1751. //reject(false);
  1752. this.$notify.error({
  1753. title: '网络图片访问异常!- 2',
  1754. message: imageUrl.slice(0,50)
  1755. });
  1756. }else{
  1757. // console.log('下载中...')
  1758. }
  1759. });
  1760. req.on('data', (chunk) => {
  1761. received_bytes += chunk.length;
  1762. });
  1763. req.on('end', ()=> {
  1764. if(urlInfo != 'example'){
  1765. urlInfo.num += 1;
  1766. }else{
  1767. this.$msgbox({
  1768. title: '消息',
  1769. message: '模板下载成功,保存位置:' + this.downloadDir + separator + pjson.softInfo.softName,
  1770. showCancelButton: true,
  1771. confirmButtonText: '去查看',
  1772. cancelButtonText: '取消',
  1773. }).then(action => {
  1774. this.openFolder();
  1775. }).catch(action => {
  1776. });
  1777. }
  1778. //console.log('下载完成', outputPath)
  1779. resolve(true);
  1780. });
  1781. });
  1782. } catch (error) {
  1783. console.error(imageUrl, `Failed to download image: ${error.message}`);
  1784. throw error;
  1785. }
  1786. },
  1787. // 获取页面标题 - 生成对应的文件夹
  1788. async getTitle(page, urlInfo){
  1789. // 已页面标题作为新建文件夹,保留前20个字
  1790. let title = await page.title();
  1791. if(title){
  1792. title = title.substring(0, 20);
  1793. if(this.containsAnyChar(title, ['\\', '/', ':', '*', '?', '"', '<', '>', '|'])){ //判断是否含有特殊字符
  1794. title = title.replace(/[\\|/|:|*|?|"|<|>||]/g, "");
  1795. }
  1796. if (fs.existsSync(this.downloadDir + separator + pjson.softInfo.softName + separator + title)) {
  1797. urlInfo.newPath = this.downloadDir + separator + pjson.softInfo.softName + separator + title;
  1798. } else {
  1799. fs.mkdirSync(this.downloadDir + separator + pjson.softInfo.softName + separator + title);
  1800. urlInfo.newPath = this.downloadDir + separator + pjson.softInfo.softName + separator + title;
  1801. }
  1802. }
  1803. },
  1804. // 下载base64位的图片
  1805. async downloadBaseImage(base64String, outputPath, urlInfo) {
  1806. const buffer = Buffer.from(base64String, 'base64');
  1807. const writeStream = fs.createWriteStream(outputPath);
  1808. writeStream.write(buffer);
  1809. writeStream.end();
  1810. writeStream.on('finish', () => {
  1811. urlInfo.num += 1;
  1812. });
  1813. // 监听错误事件
  1814. writeStream.on('error', (err) => {
  1815. console.error('base64位写入文件时出错:', err);
  1816. });
  1817. },
  1818. // 错误提示
  1819. showError(e){
  1820. let str = '';
  1821. if(e.toString().indexOf('ERR_NAME_NOT_RESOLVE') > -1){
  1822. str = '无法解析该网址,请查看网址是否正确!-1';
  1823. }else if(e.toString().indexOf('Cannot navigate to invalid URL') > -1){
  1824. str = '无效的网址,请查看网址格式是否正确!-2';
  1825. }else if(e.toString().indexOf('ERR_CONNECTION_TIMED_OUT') > -1){
  1826. str = '链接请求超时,请查看网络状态!-3';
  1827. }else if(e.toString().indexOf('TimeoutError') > -1){
  1828. str = '链接请求超时,请查看网络状态!-4';
  1829. }else if(e.toString().indexOf('operation not permitted') > -1){
  1830. str = '权限受限,请以管理员权限运行软件!-5';
  1831. }else if(e.toString().indexOf('browser has disconnected') > -1){
  1832. str = '浏览器断开链接!-6';
  1833. }else{
  1834. str = e.toString();
  1835. //console.log(e);
  1836. }
  1837. this.loading = false;
  1838. this.$notify.error({
  1839. title: '提示',
  1840. message: str
  1841. });
  1842. },
  1843. // 是否包含特殊字符
  1844. containsAnyChar(str, charsArray) {
  1845. for (let i = 0; i < charsArray.length; i++) {
  1846. if (str.includes(charsArray[i])) {
  1847. return true;
  1848. }
  1849. }
  1850. return false;
  1851. },
  1852. // 随机生成字符
  1853. randomString(length) {
  1854. let result = '';
  1855. const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
  1856. const charactersLength = characters.length;
  1857. for (let i = 0; i < length; i++ ) {
  1858. result += characters.charAt(Math.floor(Math.random() * charactersLength));
  1859. }
  1860. return result;
  1861. }
  1862. }
  1863. };
  1864. </script>
  1865. <style lang="scss">
  1866. @import "../assets/css/fontx/iconfont.css";
  1867. @import "../assets/css/home.scss";
  1868. .ivu-input-number-controls-outside-btn i {
  1869. font-weight: 800;
  1870. }
  1871. .update-point {
  1872. display: inline-block;
  1873. width: 8px;
  1874. height: 8px;
  1875. border-radius: 8px;
  1876. background: #ff0000;
  1877. top: 14px;
  1878. position: absolute;
  1879. left: -13px;
  1880. }
  1881. .menu-item {
  1882. padding: 8px 0;
  1883. font-size: 14px;
  1884. .iconfont {
  1885. font-size: 32px;
  1886. }
  1887. &:hover,
  1888. &.active {
  1889. color: #ed4014;
  1890. }
  1891. }
  1892. .ivu-progress-show-info .ivu-progress-outer {
  1893. padding-right: 40px !important;
  1894. margin-right: -40px !important;
  1895. }
  1896. .tips {
  1897. text-align: center;
  1898. padding: 10px 0;
  1899. color: #ed4014;
  1900. font-size: 12px;
  1901. }
  1902. .handle-desc {
  1903. display: inline-block;
  1904. width: calc(100% - 100px);
  1905. overflow: hidden;
  1906. }
  1907. .ivu-menu-submenu-title {
  1908. font-weight: 600;
  1909. }
  1910. .ivu-menu .ivu-menu-item {
  1911. line-height: 1;
  1912. }
  1913. // new-el
  1914. .el-menu {
  1915. border-right: none !important;
  1916. }
  1917. .cmenu-item {
  1918. padding: 0 20px 20px;
  1919. margin-bottom: 15px;
  1920. .cmenu-title {
  1921. font-size: 18px;
  1922. font-weight: 600;
  1923. padding-bottom: 20px;
  1924. }
  1925. .citem-nav {
  1926. text-align: center;
  1927. border-radius: 10px;
  1928. min-height: 110px;
  1929. padding: 15px 0;
  1930. background-color: #fff;
  1931. font-size: 15px;
  1932. cursor: pointer;
  1933. &.bg-linear1 {
  1934. color: #fff;
  1935. font-size: 20px;
  1936. background: linear-gradient(to right bottom, #2A56CA, #5795F4);
  1937. }
  1938. &.bg-linear2 {
  1939. color: #fff;
  1940. font-size: 20px;
  1941. background: linear-gradient(to right top, #147FBB, #5EB3E3);
  1942. }
  1943. &.bg-linear3 {
  1944. color: #fff;
  1945. font-size: 20px;
  1946. background: linear-gradient(to right bottom, #2F9E8A, #56CDB1);
  1947. }
  1948. &:hover {
  1949. margin-top: -5px;
  1950. box-shadow: 3px 3px 6px #ccc, -3px -3px 6px #ccc;
  1951. }
  1952. .citem-img {
  1953. width: 50px;
  1954. margin-bottom: 10px;
  1955. }
  1956. }
  1957. }
  1958. .popper-open{
  1959. text-align: center !important;
  1960. padding: 10px !important;
  1961. background: #303133 !important;
  1962. color: #fff !important;
  1963. min-width: 120px !important;
  1964. opacity: 0.8;
  1965. }
  1966. .popper-open[x-placement^=bottom] .popper__arrow::after{
  1967. border-bottom-color: #303133 !important;
  1968. }
  1969. textarea.el-textarea__inner{
  1970. height: 100% !important;
  1971. font-family: "Helvetica Neue",Helvetica,"PingFang SC","Hiragino Sans GB","Microsoft YaHei","微软雅黑",Arial,sans-serif;
  1972. }
  1973. .set-item{
  1974. margin-right: 15px;
  1975. .set-title{
  1976. font-size: 13px;
  1977. }
  1978. }
  1979. .outarea{
  1980. height: 100%;
  1981. border: 1px solid #DCDFE6;
  1982. background-color: #4851a415;
  1983. padding: 15px;
  1984. font-size: 20px;
  1985. overflow: hidden auto;
  1986. }
  1987. .outtext{
  1988. height: 100%;
  1989. font-size: 20px;
  1990. overflow: hidden auto;
  1991. textarea{
  1992. background-color: #4851a415;
  1993. }
  1994. }
  1995. .pin-tips{
  1996. font-size: 14px;
  1997. position: absolute;
  1998. bottom: 10px;
  1999. color: #ff0000;
  2000. left: 0;
  2001. right: 0;
  2002. margin: auto;
  2003. text-align: center;
  2004. }
  2005. .outarea.red-border{
  2006. border: 1px solid #F56C6C;
  2007. }
  2008. .outtext.red-border textarea{
  2009. border: 1px solid #F56C6C;
  2010. }
  2011. h3{
  2012. margin: 0;
  2013. }
  2014. .m-image{
  2015. width: 20px;
  2016. margin-right: 5px;
  2017. }
  2018. .dialog-footer-center{
  2019. text-align: center;
  2020. }
  2021. </style>