home.vue 128 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799
  1. <template>
  2. <div>
  3. <el-container style="height: 100vh;">
  4. <!-- #333744 -->
  5. <el-aside width="180px" style="user-select: none; border-right: 1px solid #fafafa; background-color: #333744; overflow-x: hidden;">
  6. <p class="soft-name" style="-webkit-app-region: drag; color: #fff;">
  7. <img src="../assets/image/icon.png" class="soft-icon" />
  8. <span style="letter-spacing: 1px;">{{productName}}</span>
  9. </p>
  10. <el-menu :default-openeds="['a']" :default-active="menuIndex" @select="setMenuIndex" active-text-color="#409EFF" background-color="#333744" text-color="#fff" style="margin-top: 10px;">
  11. <el-submenu index="a">
  12. <template slot="title"><img src="../assets/image/m-download.png" class="m-image"/>图片下载</template>
  13. <el-menu-item index="3">
  14. <img src="../assets/image/m-tmall.png" class="m-image"/><span slot="title">天猫</span>
  15. </el-menu-item>
  16. <el-menu-item index="2">
  17. <img src="../assets/image/m-jd.png" class="m-image"/><span slot="title">京东</span>
  18. </el-menu-item>
  19. <el-menu-item index="4">
  20. <img src="../assets/image/m-taobao.png" class="m-image"/><span slot="title">淘宝</span>
  21. </el-menu-item>
  22. <el-menu-item index="1">
  23. <img src="../assets/image/m-alibaba.png" class="m-image"/><span slot="title">阿里巴巴</span>
  24. </el-menu-item>
  25. <el-menu-item index="6">
  26. <img src="../assets/image/m-aliguoji.png" class="m-image"/><span slot="title">阿里国际</span>
  27. </el-menu-item>
  28. <el-menu-item index="9">
  29. <img src="../assets/image/m-pdd.png" class="m-image"/><span slot="title">拼多多</span>
  30. </el-menu-item>
  31. <el-menu-item index="7">
  32. <img src="../assets/image/m-baidu.png" class="m-image"/><span slot="title">百度爱采购</span>
  33. </el-menu-item>
  34. <!-- <el-menu-item index="8">
  35. <img src="../assets/image/m-amazon.png" class="m-image"/><span slot="title">亚马逊</span>
  36. </el-menu-item> -->
  37. <el-menu-item index="5">
  38. <img src="../assets/image/m-hong.png" class="m-image"/><span slot="title">小红书</span>
  39. </el-menu-item>
  40. <el-menu-item index="10">
  41. <img src="../assets/image/m-chrome.png" class="m-image"/><span slot="title">其他(Beta)</span>
  42. </el-menu-item>
  43. </el-submenu>
  44. <el-submenu index="b">
  45. <template slot="title"><img src="../assets/image/m-edit.png" class="m-image"/>图片处理</template>
  46. <el-menu-item index="2-1">
  47. <img src="../assets/image/m-geshi.png" class="m-image"/><span slot="title">格式转换</span>
  48. </el-menu-item>
  49. <el-menu-item index="2-2">
  50. <img src="../assets/image/m-yasuo.png" class="m-image"/><span slot="title">图片压缩</span>
  51. </el-menu-item>
  52. <el-menu-item index="2-3">
  53. <img src="../assets/image/m-chicun.png" class="m-image"/><span slot="title">修改尺寸</span>
  54. </el-menu-item>
  55. <el-menu-item index="2-5">
  56. <img src="../assets/image/m-shuiyin.png" class="m-image"/><span slot="title">添加水印</span>
  57. </el-menu-item>
  58. </el-submenu>
  59. </el-menu>
  60. </el-aside>
  61. <el-container>
  62. <el-header height="45px" style="background-color: #fafafa; padding: 0 10px;">
  63. <soft-header ref="headerRef" @update-soft="updateSoft()" @export-file="exportFile" @login-url="loginUrl" @clear-cache="clearCache"></soft-header>
  64. </el-header>
  65. <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>
  66. <el-main v-show="['1', '2', '3', '4', '5', '6', '7', '8', '9', '10'].indexOf(menuIndex) > -1" ref="el-main" style="background-color: #fafafa;">
  67. <template>
  68. <div class="content-top">
  69. <div>
  70. <el-button-group>
  71. <el-button type="primary" size="mini" icon="el-icon-circle-plus-outline"
  72. @click="addVisible = true; add();">添加链接</el-button>
  73. <el-button type="primary" size="mini" icon="el-icon-upload"
  74. @click="pickLink()">导入链接</el-button>
  75. <el-button type="primary" size="mini" icon="el-icon-delete"
  76. @click="clearList()">清空链接</el-button>
  77. <el-button type="danger" size="mini" icon="el-icon-video-pause" :disabled="pauseFlag"
  78. @click="pause()">任务中止</el-button>
  79. <!-- <el-button type="danger" size="mini" icon="el-icon-video-pause"
  80. @click="del()">批量删除</el-button> -->
  81. </el-button-group>
  82. <el-link type="info" style="margin-left: 10px; vertical-align:baseline; font-size: 12px;" @click="downloadExample()">导入模板<i class="el-icon-download"></i></el-link>
  83. </div>
  84. <el-row type="flex" style="align-items: center;">
  85. <div class="set-item">
  86. <span class="set-title">保存目录:</span>
  87. <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>
  88. <el-popover placement="bottom" popper-class="popper-open" trigger="hover" content="打开保存目录">
  89. <i class="el-icon-folder-opened" slot="reference" style="padding-left: 5px; cursor: pointer; font-size: 22px; vertical-align: middle;" @click="openFolder()"></i>
  90. </el-popover>
  91. </div>
  92. <el-button type="danger" @click="exportFile()" :loading="loading">开始下载</el-button>
  93. </el-row>
  94. </div>
  95. <div style="padding: 20px 20px 0 20px; height: calc(100% - 62px);">
  96. <el-row type="flex" justify="space-between">
  97. <div>
  98. <h3 style="display: inline-block;">
  99. <span v-if="menuIndex == '1'">阿里巴巴 - </span>
  100. <span v-if="menuIndex == '2'">京东 - </span>
  101. <span v-if="menuIndex == '3'">天猫 - </span>
  102. <span v-if="menuIndex == '4'">淘宝 - </span>
  103. <span v-if="menuIndex == '5'">小红书 - </span>
  104. <span v-if="menuIndex == '6'">阿里国际 - </span>
  105. <span v-if="menuIndex == '7'">百度爱采购 - </span>
  106. <span v-if="menuIndex == '8'">亚马逊 - </span>
  107. <span v-if="menuIndex == '9'">拼多多 - </span>
  108. <span v-if="menuIndex == '10'">网页 - </span>
  109. 图片下载
  110. </h3>
  111. <el-link v-if="menuIndex == '5'" :underline="false" type="danger" style="text-align: center; font-size: 12px;">
  112. 仅支持win10及以上系统,浏览器请选择最新版本
  113. </el-link>
  114. <el-link v-if="menuIndex == '10'" :underline="false" type="danger" style="text-align: center; font-size: 12px;">
  115. 非会员功能,仅提供测试试用
  116. </el-link>
  117. </div>
  118. </el-row>
  119. <div style="padding: 15px 0 20px;">
  120. <el-row type="flex" justify="space-between">
  121. <div v-if="menuIndex == '5'" style="padding-top: 10px;">
  122. <label>下载类型:</label>
  123. <el-checkbox-group :min="1" v-model="settingArr" style="display: inline-block;" @input="settingGroup">
  124. <el-checkbox label="mainImg">文章图</el-checkbox>
  125. <el-checkbox label="video">视频</el-checkbox>
  126. </el-checkbox-group>
  127. <!-- <el-checkbox :value="true" style="opacity: 0.6; cursor: not-allowed;">文章图/视频</el-checkbox> -->
  128. <el-popover placement="bottom" popper-class="popper-open" trigger="hover" content="实况(Live)图下载的格式是mp4视频">
  129. <i class="el-icon-info" slot="reference" style="margin-left: 10px; color: #F56C6C;"></i>
  130. </el-popover>
  131. </div>
  132. <div v-if="menuIndex == '10'" style="padding-top: 10px;">
  133. <label>下载类型:</label>
  134. <el-checkbox :value="true" style="opacity: 0.6; cursor: not-allowed;">图片</el-checkbox>
  135. </div>
  136. <div v-if="['1', '2', '3', '4', '6', '7', '8', '9'].indexOf(menuIndex) > -1" style="padding-top: 10px;">
  137. <label>下载类型:</label>
  138. <el-checkbox-group :min="1" v-model="settingArr" style="display: inline-block;" @input="settingGroup">
  139. <el-checkbox label="mainImg">主图</el-checkbox>
  140. <el-checkbox label="detailImg">详情图</el-checkbox>
  141. <el-checkbox label="skuImg" v-if="menuIndex != '7'">SKU图</el-checkbox>
  142. <el-checkbox label="commentImg" v-if="menuIndex == '3' || menuIndex == '4'">评论图</el-checkbox>
  143. <el-checkbox label="video">视频</el-checkbox>
  144. </el-checkbox-group>
  145. <el-popover placement="bottom" popper-class="popper-open" trigger="hover"
  146. :content="menuIndex == '9' ? '视频下载的是商品视频,非商品讲解视频' : '下载类型至少选一个,评论图默认只下载商品首页展示的评论内容'">
  147. <i class="el-icon-info" slot="reference" style="margin-left: 10px; color: #F56C6C;"></i>
  148. </el-popover>
  149. </div>
  150. <!-- 阿里巴巴账号 -->
  151. <template v-if="menuIndex == '1'">
  152. <div>
  153. <el-tag type="info" size="mini" v-if="alibabaStatus == 1">未检测</el-tag>
  154. <el-tag type="success" size="mini" v-if="alibabaStatus == 2">阿里巴巴账号已登录</el-tag>
  155. <el-link type="danger" style="text-decoration: underline;" v-if="alibabaStatus == 3" :underline="false" @click="loginUrl('https://www.1688.com')">未登录,点击登录阿里巴巴账号</el-link>
  156. <el-button size="mini" type="warning" :loading="checkLoading" style="margin-left: 10px;" :disabled='alibabaStatus == 2' @click="checkAlibabaLogin">检测登录状态</el-button>
  157. </div>
  158. </template>
  159. <!-- 天猫/淘宝 -->
  160. <template v-if="menuIndex == '3' || menuIndex == '4'">
  161. <div>
  162. <el-tag type="info" size="mini" v-if="tbStatus == 1">未检测</el-tag>
  163. <el-tag type="success" size="mini" v-if="tbStatus == 2">{{menuIndex == '3' ? '天猫' : '淘宝'}}账号已登录</el-tag>
  164. <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>
  165. <el-button size="mini" type="warning" :loading="checkLoading" style="margin-left: 10px;" :disabled='tbStatus == 2' @click="checkLogin">检测登录状态</el-button>
  166. </div>
  167. </template>
  168. <!-- 京东账号 -->
  169. <template v-if="menuIndex == '2'">
  170. <div>
  171. <el-tag type="info" size="mini" v-if="jdStatus == 1">未检测</el-tag>
  172. <el-tag type="success" size="mini" v-if="jdStatus == 2">京东账号已登录</el-tag>
  173. <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>
  174. <el-button size="mini" type="warning" :loading="checkLoading" style="margin-left: 10px;" :disabled='jdStatus == 2' @click="checkJdLogin">检测登录状态</el-button>
  175. </div>
  176. </template>
  177. <!-- 小红书 -->
  178. <template v-if="menuIndex == '5'">
  179. <div>
  180. <el-tag type="info" size="mini" v-if="redStatus == 1">未检测</el-tag>
  181. <el-tag type="success" size="mini" v-if="redStatus == 2">小红书账号已登录</el-tag>
  182. <el-link type="danger" style="text-decoration: underline;" v-if="redStatus == 3" :underline="false" @click="loginUrl('https://www.xiaohongshu.com')">未登录,点击登录小红书账号</el-link>
  183. <el-button size="mini" type="warning" :loading="checkLoading" style="margin-left: 10px;" :disabled='redStatus == 2' @click="checkRedLogin">检测登录状态</el-button>
  184. </div>
  185. </template>
  186. <!-- 拼多多 -->
  187. <template v-if="menuIndex == '9'">
  188. <div>
  189. <el-tag type="info" size="mini" v-if="pddStatus == 1">未检测</el-tag>
  190. <el-tag type="success" size="mini" v-if="pddStatus == 2">拼多多账号已登录</el-tag>
  191. <el-link type="danger" style="text-decoration: underline;" v-if="pddStatus == 3" :underline="false" @click="loginUrl('https://mobile.yangkeduo.com/login.html')">未登录,点击登录拼多多账号</el-link>
  192. <el-button size="mini" type="warning" :loading="checkLoading" style="margin-left: 10px;" :disabled='pddStatus == 2' @click="checkPddLogin">检测登录状态</el-button>
  193. </div>
  194. </template>
  195. </el-row>
  196. </div>
  197. <div class="table-scroll">
  198. <!-- 1、 -->
  199. <vxe-table ref="xTable" show-overflow class="img-table" max-height="100%" empty-text="没有更多数据了!" :loading="tabLoading" :row-config="{isHover: true}"
  200. :loading-config="{icon: 'vxe-icon-indicator roll', text: '列表加载中...'}" :data="this[listStr+'List']" :scroll-y="{enabled: true}">
  201. <!-- <vxe-column type="checkbox" width="40"></vxe-column> -->
  202. <vxe-column type="seq" width="60"></vxe-column>
  203. <vxe-column field="title" title="目录名称" width="180">
  204. <template #default="{ row, rowIndex }">
  205. <span v-if="row.title">{{row.title}}</span>
  206. <el-tag size="mini" v-else>默认使用网页标题</el-tag>
  207. </template>
  208. </vxe-column>
  209. <vxe-column field="url" title="网页链接"></vxe-column>
  210. <vxe-column field="status" title="下载状态" width="200">
  211. <template #default="{ row }">
  212. <template v-if="row.status == '1'">
  213. <i class="el-icon-info" style="font-size: 16px; color: #999;"></i>
  214. <span>待操作</span>
  215. </template>
  216. <template v-if="row.status == '2'">
  217. <i class="el-icon-loading" style="font-size: 16px; color: #999;"></i>
  218. <span>任务处理中...</span>
  219. </template>
  220. <template v-if="row.status == '3'">
  221. <i class="el-icon-loading" style="font-size: 16px; color: #999;"></i>
  222. <span>图片下载中..<span v-if="row.num > 0">第{{row.num}}张</span></span>
  223. </template>
  224. <template v-if="row.status == '4'">
  225. <i class="el-icon-success" style="font-size: 16px; color: #19be6b;"></i>
  226. <span>下载完成</span>
  227. </template>
  228. <template v-if="row.status == '5'">
  229. <i class="el-icon-error" style="font-size: 16px; color: #ed4014;"></i>
  230. <span>网络异常,请重试!</span>
  231. </template>
  232. <template v-if="row.status == '6'">
  233. <i class="el-icon-error" style="font-size: 16px; color: #ed4014;"></i>
  234. <span>验证码拦截,请手动验证!</span>
  235. </template>
  236. <template v-if="row.status == '7'">
  237. <i class="el-icon-error" style="font-size: 16px; color: #ed4014;"></i>
  238. <span>频繁访问受限,清除缓存重试</span>
  239. </template>
  240. </template>
  241. </vxe-column>
  242. <vxe-column title="操作" width="80">
  243. <template #default="{ row, rowIndex }">
  244. <i class="el-icon-delete cur-pointer" style="font-size: 20px;" @click="delFile(rowIndex)"></i>
  245. </template>
  246. </vxe-column>
  247. </vxe-table>
  248. </div>
  249. </div>
  250. </template>
  251. <el-dialog title="添加链接" :visible.sync="addVisible" width="500px" :close-on-click-modal="false" :close-on-press-escape="false" :show-close="false">
  252. <div>
  253. <el-form label-position="right" label-width="80px" :rules="rules" :model="formData" ref="formData">
  254. <el-form-item label="目录名称" prop="title">
  255. <el-input id="aaa" v-model="formData.title" placeholder="为空则默认使用网页标题前50个字符"></el-input>
  256. </el-form-item>
  257. <el-form-item label="网页链接" prop="url">
  258. <el-input id="bbb" type="textarea" :rows="10" :placeholder="'请输入网址链接(例:' + exampleUrl[menuIndex-1] + ')'" v-model="formData.url"></el-input>
  259. </el-form-item>
  260. </el-form>
  261. </div>
  262. <span slot="footer" class="dialog-footer">
  263. <el-button @click="addVisible = false; $refs['formData'].resetFields();">取 消</el-button>
  264. <el-button type="primary" @click="onSubmit">确 定</el-button>
  265. </span>
  266. </el-dialog>
  267. <el-dialog title="提示" :visible.sync="loginVisible" width="400px" :close-on-click-modal="false" :close-on-press-escape="false">
  268. <div style="text-align: center; color: #999; font-size: 14px;">
  269. <template v-if="menuIndex == '1'">
  270. <p>阿里巴巴渠道建议登录后下载</p>
  271. <p class="visible-tips-style">目前检测还未登录阿里巴巴账号,未登录可能会导致图片下载不全</p>
  272. </template>
  273. <template v-else-if="menuIndex == '2'">
  274. <p>京东渠道需要登录后才能下载</p>
  275. <p class="visible-tips-style">目前检测还未登录京东账号,需立即登录</p>
  276. </template>
  277. <template v-else-if="menuIndex == '5'">
  278. <p>小红书渠道需要登录后才能下载</p>
  279. <p class="visible-tips-style">目前检测还未登录小红书账号,需立即登录</p>
  280. </template>
  281. <template v-else-if="menuIndex == '9'">
  282. <p>拼多多渠道需要登录后才能下载</p>
  283. <p class="visible-tips-style">目前检测还未登录拼多多账号,需立即登录</p>
  284. </template>
  285. <template v-else>
  286. <p>天猫/淘宝渠道需要登录后才能下载</p>
  287. <p class="visible-tips-style">目前检测还未登录天猫/淘宝账号,需立即登录</p>
  288. </template>
  289. </div>
  290. <div slot="footer" class="dialog-footer-center">
  291. <el-button v-if="menuIndex == '2'" @click="loginVisible = false; loginUrl('https://passport.jd.com/new/login.aspx')">点击登录京东账号</el-button>
  292. <template v-else-if="menuIndex == '1'">
  293. <el-button @click="loginVisible = false; loginUrl('https://www.1688.com')">点击登录阿里巴巴账号</el-button>
  294. <el-button type="primary" @click="loginVisible = false; skipLogin = true; exportFile();">继续下载</el-button>
  295. </template>
  296. <el-button v-else-if="menuIndex == '5'" @click="loginVisible = false; loginUrl('https://www.xiaohongshu.com')">点击登录小红书账号</el-button>
  297. <el-button v-else-if="menuIndex == '9'" @click="loginVisible = false; loginUrl('https://mobile.yangkeduo.com/login.html')">点击登录拼多多账号</el-button>
  298. <el-button v-else @click="loginVisible = false; loginUrl('https://login.taobao.com')">点击登录天猫/淘宝账号</el-button>
  299. </div>
  300. </el-dialog>
  301. <!-- 非会员转换提示框 -->
  302. <el-dialog title="非会员提示" :visible.sync="tipsModal" width="400px">
  303. <div class="member-model">
  304. <div class="tips-flex">
  305. <i class="el-icon-s-opportunity"></i>
  306. <p class="m-title">{{tipsDesc}}</p>
  307. </div>
  308. <div class="member-btn">
  309. <el-button size="small" round type="primary" @click="openVip()">开通会员</el-button>
  310. </div>
  311. </div>
  312. </el-dialog>
  313. </el-main>
  314. <el-footer height="48px">
  315. <!-- 更新 -->
  316. <soft-update ref="updateRef" :showDowload="dowloadModel" :dowloadFinish="finishModel"></soft-update>
  317. </el-footer>
  318. </el-container>
  319. </el-container>
  320. </div>
  321. </template>
  322. <script>
  323. import os from 'os'
  324. import fs from 'fs'
  325. import request from 'request'
  326. import path from 'path';
  327. import xlsx from 'node-xlsx';
  328. import softUpdate from './update.vue';
  329. import softHeader from './header.vue';
  330. import softImg from './img.vue';
  331. import electronApi from '@/utils/electronApi';
  332. import pjson from '/package.json'
  333. // import puppeteer from 'puppeteer'
  334. import puppeteer from 'puppeteer-extra'
  335. const StealthPlugin = require('puppeteer-extra-plugin-stealth');
  336. const listNameArr = ['alibaba','jd','tmall','tb','red','aliguoji','acaigou','amazon', 'pdd' ,'common'];
  337. // const headless = true;
  338. // const waitUntil = 'networkidle2';
  339. const { ipcRenderer } = require('electron');
  340. //const chromePath = "C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\msedge.exe";
  341. let separator = '';
  342. if (os.platform == 'linux') {
  343. separator = '/'
  344. } else {
  345. separator = '\\'
  346. }
  347. // let chromePath = process.cwd() + '\\resources\\app\\node_modules\\puppeteer\\.local-chromium\\win64-1045629\\chrome-win\\chrome.exe';
  348. // if (process.env.NODE_ENV == 'development') {
  349. // chromePath = process.cwd() + '\\node_modules\\puppeteer\\.local-chromium\\win64-1045629\\chrome-win\\chrome.exe';
  350. // }
  351. export default {
  352. name: 'landing-page',
  353. components: {
  354. softUpdate,
  355. softHeader,
  356. softImg
  357. },
  358. data() {
  359. return {
  360. tipsModal: false,
  361. tipsDesc: "非VIP用户不能下载视频,如需完整功能请开通VIP会员。",
  362. settingArr: ['mainImg'],
  363. loginVisible: false,
  364. addVisible: false,
  365. formData: {
  366. title: '',
  367. url: ''
  368. },
  369. rules:{ //
  370. title: [
  371. { min: 0, max: 50, message: '不能超过 50 个字符', trigger: 'blur' },
  372. { pattern: /^[^\\/:*?"<>|]*$/, message: '标题中不能包含 \\ / : * ? " < > |', trigger: 'blur' }
  373. ],
  374. url: [
  375. { required: true, message: '请输入网页链接', trigger: 'blur' },
  376. { pattern: /^(http|https):\/\/.+$/, message: '请输入正确的网址链接(http://或https://开头),结尾不能有换行符', trigger: 'blur' }
  377. ],
  378. },
  379. tabLoading: false,
  380. alibabaList: [],
  381. aliguojiList: [],
  382. amazonList: [],
  383. acaigouList: [],
  384. jdList: [],
  385. tbList: [],
  386. tmallList: [],
  387. redList: [],
  388. pddList: [],
  389. commonList: [],
  390. productName: pjson.softInfo.softName,
  391. imgUrl: this.$api.imgUrl,
  392. imgSrc: '',
  393. menuIndex: '3',
  394. settingData: {
  395. detailImg: true,
  396. skuImg: true,
  397. commentImg: false,
  398. video: false,
  399. },
  400. exampleUrl: ['https://www.1688.com', 'https://www.jd.com', 'https://www.tmall.com', 'https://www.taobao.com', 'https://www.xiaohongshu.com',
  401. 'https://www.alibaba.com', 'https://b2b.baidu.com', 'https://www.amazon.com', 'https://mobile.yangkeduo.com/goods.html', 'https://www.example.com'],
  402. fileList: [],
  403. downloadDir: os.userInfo().homedir + separator + "Downloads",
  404. dowloadModel: false,
  405. finishModel: false,
  406. loading: false,
  407. checkLoading: false, //点击检测登录状态
  408. tbStatus: 1, // 1、未检测 2、已经登录 3、未登录
  409. jdStatus: 1, // 1、未检测 2、已经登录 3、未登录
  410. redStatus: 1, //同上
  411. alibabaStatus: 1, //同上上
  412. aliguojiStatus: 1, //同上上上
  413. pddStatus: 1,
  414. execLimit: 1,
  415. execNum: 3, // 限制5张
  416. /** 浏览器名称 **/
  417. alibabaBrowser: null,
  418. aliguojiBrowser: null,
  419. amazonBrowser: null,
  420. acaigouBrowser: null,
  421. tbBrowser: null,
  422. jdBrowser: null,
  423. commonBrowser: null,
  424. redBrowser: null,
  425. pddBrowser: null,
  426. loginBrowser: null, // 登录用的浏览器实例
  427. skipLogin: false,
  428. pauseFlag: true, //暂停中止标志
  429. rightClick: false, // 右击事件绑定
  430. };
  431. },
  432. computed: {
  433. listStr: function(){
  434. let index = Number(this.menuIndex) - 1;
  435. return listNameArr[index];
  436. }
  437. },
  438. async mounted() {
  439. this.$refs.updateRef.updateSoft(true);
  440. let homedir = os.userInfo().homedir;
  441. if (fs.existsSync(homedir + separator + "Desktop")) {
  442. this.downloadDir = homedir + separator + "Desktop"
  443. } else {
  444. this.downloadDir = homedir + separator + "Downloads"
  445. }
  446. if (!fs.existsSync(os.tmpdir() + separator + 'chrome-data-capture')) {
  447. fs.mkdirSync(os.tmpdir() + separator + 'chrome-data-capture');
  448. }
  449. if (!fs.existsSync(os.tmpdir() + separator + 'chrome-data-capture-jd')) {
  450. fs.mkdirSync(os.tmpdir() + separator + 'chrome-data-capture-jd');
  451. }
  452. if (!fs.existsSync(os.tmpdir() + separator + 'chrome-data-capture-local')) {
  453. fs.mkdirSync(os.tmpdir() + separator + 'chrome-data-capture-local');
  454. }
  455. let path = os.tmpdir() + separator + 'chrome-data-capture';
  456. let path2 = os.tmpdir() + separator + 'chrome-data-capture-jd';
  457. //this.deleteAll(path, false);
  458. //this.deleteAll(path2, false);
  459. // 打开浏览器
  460. const {
  461. shell
  462. } = require('electron');
  463. const links = document.querySelectorAll('a[href]');
  464. links.forEach(link => {
  465. link.addEventListener('click', e => {
  466. const url = link.getAttribute('href');
  467. e.preventDefault();
  468. shell.openExternal(url);
  469. });
  470. });
  471. // 判断系统版本 低于10使用兼容模式
  472. if(os.release() && os.release().indexOf('.') > -1){
  473. let systemVersion = Number(os.release().split('.')[0]);
  474. if(systemVersion < 10){ // 低于win10,软件打开时候浏览器设置为兼容版
  475. this.$utils.setStorage('versionType', 1);
  476. }else{
  477. this.$utils.setStorage('versionType', 2);
  478. }
  479. }
  480. // 初始化开发者设置
  481. this.$utils.setStorage('headless', 1);
  482. this.$utils.setStorage('waitUntil', 'networkidle2');
  483. },
  484. methods: {
  485. add(){
  486. if(!this.rightClick){
  487. setTimeout(() => {
  488. document.getElementById('aaa').addEventListener('contextmenu', e => {
  489. e.preventDefault();
  490. // 发送事件到主进程,附带元素类型信息
  491. ipcRenderer.send('show-context-menu', 'input');
  492. });
  493. document.getElementById('bbb').addEventListener('contextmenu', e => {
  494. e.preventDefault();
  495. // 发送事件到主进程,附带元素类型信息
  496. ipcRenderer.send('show-context-menu', 'input');
  497. });
  498. }, 800)
  499. this.rightClick = true;
  500. }
  501. },
  502. // 实时获取浏览器路径
  503. initPath(){
  504. let chromeType = this.$utils.getStorage('chromeType');
  505. let chromePath = puppeteer.executablePath().replace('win32-1', 'win64-1');
  506. if(chromeType == 1){ // 电脑自带浏览器
  507. chromePath = this.$utils.getStorage('chromePath');
  508. }else{
  509. chromePath = puppeteer.executablePath().replace('win32-1', 'win64-1');
  510. let versionType = this.$utils.getStorage('versionType');
  511. if(versionType && versionType == 1){
  512. chromePath = chromePath.replace('chrome-win', 'chrome7');
  513. }
  514. }
  515. return chromePath;
  516. },
  517. // 实时获取浏览器数据缓存
  518. initDataDir(tag){
  519. let chromeType = this.$utils.getStorage('chromeType');
  520. let userDataDir = os.tmpdir() + separator + 'chrome-data-capture';
  521. if(chromeType == 1){ // 电脑自带浏览器
  522. userDataDir = os.tmpdir() + separator + 'chrome-data-capture-local';
  523. }else{
  524. userDataDir = os.tmpdir() + separator + 'chrome-data-capture';
  525. if(tag == 'jd'){
  526. userDataDir = os.tmpdir() + separator + 'chrome-data-capture-jd';
  527. }
  528. }
  529. return userDataDir;
  530. },
  531. // 实时获取页面滚动加载时间
  532. initMs(){
  533. let pageMs = this.$utils.getStorage('pageMs');
  534. if(pageMs){
  535. return Number(pageMs);
  536. }else{
  537. return 500;
  538. }
  539. },
  540. // 实时获取淘宝的开发者设置
  541. initDevelop(){
  542. let develop = {
  543. headless: true,
  544. waitUntil: 'networkidle2'
  545. };
  546. let n1 = this.$utils.getStorage('headless');
  547. let n2 = this.$utils.getStorage('waitUntil');
  548. if(n1){
  549. if(n1 == 1){
  550. develop.headless = true;
  551. }else if(n1 == 2){
  552. develop.headless = false;
  553. }
  554. }
  555. if(n2){
  556. develop.waitUntil = n2;
  557. }
  558. return develop;
  559. },
  560. // 删除文件夹内容
  561. deleteAll(folderPath, flag) {
  562. if (fs.existsSync(folderPath)) {
  563. fs.readdirSync(folderPath).forEach((file, index) => {
  564. var curPath = path.join(folderPath, file);
  565. if (fs.lstatSync(curPath).isDirectory()) {
  566. this.deleteAll(curPath, true);
  567. } else {
  568. fs.unlinkSync(curPath);
  569. }
  570. });
  571. if(flag){
  572. fs.rmdirSync(folderPath);
  573. }
  574. }
  575. },
  576. checkAuthority(){
  577. let authority = this.$refs.headerRef.authority;
  578. this.$refs.imgRef.authority = authority;
  579. },
  580. setMenuIndex(index){
  581. this.menuIndex = index;
  582. if(index.indexOf('2-') > -1){
  583. let num = Number(index.split('-')[1]);
  584. this.$refs.imgRef.setMenuIndex(num);
  585. }
  586. },
  587. // 选择目录
  588. pickPath() {
  589. this.$refs['upload-input'].blur();
  590. electronApi.call('pickDir', []).then((path) => {
  591. if (path) {
  592. this.downloadDir = path;
  593. }
  594. });
  595. },
  596. // 打开自定义下载目录
  597. openFolder() {
  598. let path = this.downloadDir;
  599. if (fs.existsSync(this.downloadDir + separator + pjson.softInfo.softName)) {
  600. path = this.downloadDir + separator + pjson.softInfo.softName;
  601. } else {
  602. fs.mkdirSync(this.downloadDir + separator + pjson.softInfo.softName);
  603. path = this.downloadDir + separator + pjson.softInfo.softName;
  604. }
  605. electronApi.call('showItemInfolder', [path + '\\tty.tty'])
  606. },
  607. openVip() {
  608. this.$refs.headerRef.openVip();
  609. },
  610. updateSoft() {
  611. this.$refs.updateRef.updateSoft();
  612. },
  613. // 删除文件
  614. delFile(rowIndex){
  615. let index = Number(this.menuIndex) - 1;
  616. let type = listNameArr[index];
  617. this.$confirm('确认删除此行数据吗?', '提示', {
  618. confirmButtonText: '确定',
  619. cancelButtonText: '取消',
  620. type: 'warning'
  621. }).then(() => {
  622. this[type+'List'].splice(rowIndex, 1);
  623. if(this[type+'List'].length == 0) {
  624. this.clearList();
  625. }
  626. }).catch(() => {
  627. });
  628. },
  629. // 清除列表
  630. clearList() {
  631. let index = Number(this.menuIndex) - 1;
  632. this[listNameArr[index]+'List'] = [];
  633. },
  634. // 提交表单
  635. onSubmit(){
  636. this.$refs['formData'].validate((valid) => {
  637. if (valid) {
  638. let info = {
  639. url: this.formData.url,
  640. title: this.formData.title,
  641. status: '1',
  642. num: 0,
  643. newPath: ''
  644. }
  645. let index = Number(this.menuIndex) - 1;
  646. this[listNameArr[index]+'List'].push(info);
  647. this.$refs['formData'].resetFields();
  648. this.addVisible = false;
  649. } else {
  650. return false;
  651. }
  652. });
  653. },
  654. async pickLink() { // 导入链接
  655. const spinLoad = this.$loading();
  656. await electronApi.call('pickFile', ['xlsx,xls', true]).then(async (path) => {
  657. spinLoad.close();
  658. if(path.length > 0){
  659. this.$notify({
  660. title: '提示',
  661. message: '导入成功',
  662. type: 'success'
  663. });
  664. let workSheetsFromBuffer = xlsx.parse(fs.readFileSync(path[0]));
  665. if(workSheetsFromBuffer && workSheetsFromBuffer.length > 0){
  666. let errMsg = "";
  667. workSheetsFromBuffer[0].data.map((item, index) => {
  668. if(item.length > 0){
  669. let ititle = '';
  670. if(item[0]){
  671. ititle = item[0].toString().trim();
  672. }
  673. if(item[0] == '目录名称' && item[1] == '网页链接'){
  674. return false;
  675. }
  676. if(this.containsAnyChar(ititle.toString(), ['\\', '/', ':', '*', '?', '"', '<', '>', '|'])){ //判断是否含有特殊字符
  677. errMsg += "第" + (index+1) + '行-名称不能包以下字符 \\ / : * ? " < > |';
  678. ititle = ititle.replace(/[\\|/|:|*|?|"|<|>||]/g, "");
  679. }
  680. if(item[1] == undefined){
  681. errMsg += "第" + (index+1) + "行格式有误</br>";
  682. item[1] = '';
  683. }else if(!/^(http|https):\/\/.+$/.exec(item[1])){
  684. errMsg += "第" + (index+1) + "行网址格式有误</br>";
  685. }else{
  686. let info = {
  687. url: item[1],
  688. title: ititle,
  689. status: '1',
  690. num: 0,
  691. newPath: ''
  692. }
  693. let key = Number(this.menuIndex) - 1;
  694. this[listNameArr[key]+'List'].push(info);
  695. }
  696. }
  697. });
  698. if(errMsg){
  699. this.$notify({
  700. title: '请检查文件以下问题',
  701. dangerouslyUseHTMLString: true,
  702. message: errMsg,
  703. type: 'warning'
  704. });
  705. }
  706. }else{
  707. this.$notify({
  708. title: '提示',
  709. message: '格式有误,请重新导入',
  710. type: 'warning'
  711. });
  712. }
  713. }
  714. });
  715. },
  716. settingGroup(name){
  717. let authority = this.$refs.headerRef.authority.isAuthority;
  718. let index = name.indexOf('video');
  719. if(index > -1 && !authority){ // 非会员选中下载视频选项-提示
  720. this.tipsModal = true;
  721. name.splice(index, 1);
  722. }
  723. },
  724. // 清除缓存的后续操作
  725. async clearCache(){
  726. this.jdStatus = 3;
  727. this.tbStatus = 3;
  728. this.redStatus = 3;
  729. this.alibabaStatus = 3;
  730. this.aliguojiStatus = 3;
  731. this.pddStatus = 3;
  732. if(this.loginBrowser){
  733. await this.loginBrowser.close();
  734. this.loginBrowser = null;
  735. }
  736. for(let i = 0; i < listNameArr.length; i++){
  737. if(listNameArr[i]){
  738. if(this[listNameArr[i]+'Browser']){
  739. await this[listNameArr[i]+'Browser'].close();
  740. this[listNameArr[i]+'Browser'] = null;
  741. }
  742. }
  743. }
  744. },
  745. // 去登录
  746. loginUrl(url){
  747. (async () => {
  748. try{
  749. if (!fs.existsSync(os.tmpdir() + separator + 'chrome-data-capture')) {
  750. fs.mkdirSync(os.tmpdir() + separator + 'chrome-data-capture');
  751. }
  752. if (!fs.existsSync(os.tmpdir() + separator + 'chrome-data-capture-jd')) {
  753. fs.mkdirSync(os.tmpdir() + separator + 'chrome-data-capture-jd');
  754. }
  755. if (!fs.existsSync(os.tmpdir() + separator + 'chrome-data-capture-local')) {
  756. fs.mkdirSync(os.tmpdir() + separator + 'chrome-data-capture-local');
  757. }
  758. let userDataDir = this.initDataDir();
  759. if(url.indexOf('.jd.com/') > -1){
  760. userDataDir = this.initDataDir('jd');
  761. }
  762. puppeteer.use(StealthPlugin());
  763. this.loginBrowser = await puppeteer.launch({
  764. headless: false,
  765. executablePath: this.initPath(),
  766. args: ['--window-size=1280,800'],
  767. userDataDir: userDataDir,
  768. });
  769. const page = await this.loginBrowser.newPage();
  770. await page.setViewport({ width: 1280, height: 800 });
  771. await page.evaluateOnNewDocument(() => {
  772. const newProto = navigator.__proto__;
  773. delete newProto.webdriver;
  774. navigator.__proto__ = newProto;
  775. window.navigator.chrome = {
  776. runtime: {}
  777. };
  778. });
  779. await page.goto(url, {waitUntil : 'networkidle2'});
  780. }catch(e){
  781. this.showError(e);
  782. }
  783. })();
  784. },
  785. del(){
  786. let info = this.$refs.xTable.getCheckboxRecords();
  787. console.log(info);
  788. },
  789. //任务暂停
  790. async pause(){
  791. this.$confirm('是否中止下载任务?', '提示', {
  792. confirmButtonText: '确定',
  793. cancelButtonText: '取消',
  794. type: 'warning'
  795. }).then(async() => {
  796. if(this.loginBrowser){
  797. await this.loginBrowser.close();
  798. this.loginBrowser = null;
  799. }
  800. this.pauseFlag = true;
  801. for(let i = 0; i < listNameArr.length; i++){
  802. if(listNameArr[i]){
  803. if(this[listNameArr[i]+'Browser']){
  804. await this[listNameArr[i]+'Browser'].close();
  805. this[listNameArr[i]+'Browser'] = null;
  806. }
  807. }
  808. }
  809. let index = Number(this.menuIndex) - 1;
  810. this[listNameArr[index]+'List'].map(item => {
  811. if(item.status != '4'){
  812. item.status = '1';
  813. }
  814. });
  815. }).catch(() => {
  816. });
  817. },
  818. // 开始下载
  819. async exportFile(flag) {
  820. this.pauseFlag = false;
  821. if(this.loginBrowser){
  822. await this.loginBrowser.close();
  823. this.loginBrowser = null;
  824. }
  825. let authority = this.$refs.headerRef.authority.isAuthority;
  826. if (!fs.existsSync(this.downloadDir + separator + pjson.softInfo.softName)) {
  827. fs.mkdirSync(this.downloadDir + separator + pjson.softInfo.softName);
  828. }
  829. let index = Number(this.menuIndex) - 1;
  830. let fileList = this[listNameArr[index]+'List'];
  831. if(fileList.length > 0){
  832. if (!authority && !flag) { // 非会员点击转换弹出提示框
  833. this.$refs.headerRef.memberModel = true;
  834. this.$refs.headerRef.isClick = true;
  835. return false;
  836. } else {
  837. this.$refs.headerRef.memberModel = false;
  838. this.loading = true;
  839. setTimeout(() => {
  840. this.loading = false;
  841. }, 60000);
  842. }
  843. if(this.menuIndex == '1' && !this.skipLogin){ // 阿里巴巴
  844. if(this.alibabaStatus == 1 || this.alibabaStatus == 3){ // 未检测登录状态/或提示未登录状态,开始检测
  845. await this.checkAlibabaLogin().then((data) => {
  846. if(data != 2){ // 未登录
  847. this.alibabaStatus = 3;
  848. this.loginVisible = true;
  849. }
  850. }).catch(err => {
  851. this.alibabaStatus = 3;
  852. });
  853. if(this.alibabaStatus == 3){
  854. this.loading = false;
  855. return false;
  856. }
  857. }
  858. }
  859. if(this.menuIndex == '2'){ // 京东
  860. if(this.jdStatus == 1 || this.jdStatus == 3){ // 未检测登录状态/或提示未登录状态,开始检测
  861. await this.checkJdLogin().then((data) => {
  862. if(data != 2){ // 未登录
  863. this.jdStatus = 3;
  864. this.loginVisible = true;
  865. }
  866. }).catch(err => {
  867. this.jdStatus = 3;
  868. });
  869. if(this.jdStatus == 3){
  870. this.loading = false;
  871. return false;
  872. }
  873. }
  874. }
  875. if(this.menuIndex == '3' || this.menuIndex == '4'){ // 天猫/淘宝
  876. if(this.tbStatus == 1 || this.tbStatus == 3){ // 未检测登录状态/或提示未登录状态,开始检测
  877. await this.checkLogin().then((data) => {
  878. if(data != 2){ // 未登录
  879. this.tbStatus = 3;
  880. this.loginVisible = true;
  881. }
  882. }).catch(err => {
  883. this.tbStatus = 3;
  884. });
  885. }
  886. if(this.tbStatus == 3){
  887. this.loading = false;
  888. return false;
  889. }
  890. }
  891. if(this.menuIndex == '5'){ // 小红书
  892. if(this.redStatus == 1 || this.redStatus == 3){ // 未检测登录状态/或提示未登录状态,开始检测
  893. await this.checkRedLogin().then((data) => {
  894. if(data != 2){ // 未登录
  895. this.redStatus = 3;
  896. this.loginVisible = true;
  897. }
  898. }).catch(err => {
  899. this.redStatus = 3;
  900. });
  901. if(this.redStatus == 3){
  902. this.loading = false;
  903. return false;
  904. }
  905. }
  906. }
  907. if(this.menuIndex == '9'){ // 拼多多
  908. if(this.pddStatus == 1 || this.pddStatus == 3){ // 未检测登录状态/或提示未登录状态,开始检测
  909. await this.checkPddLogin().then((data) => {
  910. if(data != 2){ // 未登录
  911. this.pddStatus = 3;
  912. this.loginVisible = true;
  913. }
  914. }).catch(err => {
  915. this.pddStatus = 3;
  916. });
  917. if(this.pddStatus == 3){
  918. this.loading = false;
  919. return false;
  920. }
  921. }
  922. }
  923. let taskArr = [];
  924. let task = "";
  925. let userDataDir = this.initDataDir();
  926. if(this.menuIndex == '2'){
  927. userDataDir = this.initDataDir('jd');
  928. }
  929. // 运行不同平台的浏览器
  930. puppeteer.use(StealthPlugin());
  931. let browserName = listNameArr[index] + 'Browser';
  932. if(index == '2'){ // 天猫和淘宝共用一个
  933. browserName = 'tbBrowser';
  934. }
  935. let headless = true;
  936. headless = this.initDevelop().headless;
  937. this[browserName] = await puppeteer.launch({
  938. headless: headless,
  939. executablePath: this.initPath(),
  940. userDataDir: userDataDir,
  941. args: [
  942. '--start-maximized',
  943. '--no-sandbox',
  944. '--disable-setuid-sandbox',
  945. '--disable-blink-features=AutomationControlled'
  946. ]
  947. });
  948. for(let i = 0; i < fileList.length; i++){
  949. let item = fileList[i];
  950. switch(this.menuIndex){
  951. case '1': // 阿里巴巴
  952. task = this.alibabaDownload(item, this.alibabaBrowser);
  953. break;
  954. case '2': // 京东
  955. task = this.jdScanImg(item, this.jdBrowser);
  956. break;
  957. case '3': // 天猫
  958. case '4': // 淘宝
  959. task = this.tbScanImg(item, this.tbBrowser);
  960. break;
  961. case '5': // 小红书
  962. task = this.redDownload(item, this.redBrowser);
  963. break;
  964. case '6': // 阿里国际
  965. task = this.alibabaDownload(item, this.aliguojiBrowser);
  966. break;
  967. case '7': // 百度爱采购
  968. task = this.alibabaDownload(item, this.acaigouBrowser);
  969. break;
  970. case '8': // 亚马逊
  971. task = this.alibabaDownload(item, this.amazonBrowser);
  972. break;
  973. case '9': // 拼多多
  974. task = this.pddDownload(item, this.pddBrowser);
  975. break;
  976. case '10': // 普通网址
  977. task = this.normalDownload(item, this.commonBrowser);
  978. break;
  979. }
  980. if(this.pauseFlag){ //暂停跳出循环
  981. break;
  982. }
  983. if(task){
  984. taskArr.push(task);
  985. }
  986. if((i+1) % this.execLimit == 0){
  987. await Promise.all(taskArr).then(result => {
  988. taskArr = [];
  989. }).catch(err => {
  990. console.log('err'+i, err)
  991. })
  992. }
  993. }
  994. if(taskArr.length > 0){
  995. await Promise.all(taskArr).then(result => {
  996. taskArr = [];
  997. }).catch(err => {
  998. // 错误文件添加到服务中
  999. console.log('err',err)
  1000. })
  1001. }
  1002. if(this[browserName]){
  1003. this[browserName].close();
  1004. this[browserName] = null;
  1005. }
  1006. this.loading = false;
  1007. // 打开文件夹
  1008. if(fileList.length > 0){
  1009. this.$message({message: '恭喜你,任务已完成!', type: 'success'});
  1010. electronApi.call('showItemInfolder',[this.downloadDir + separator + pjson.softInfo.softName +'\\tty.tty'])
  1011. }
  1012. }
  1013. },
  1014. // 10-普通网址下载
  1015. async normalDownload(urlInfo, commonBrowser){
  1016. let task = await new Promise((resolve,reject) =>{
  1017. (async () => {
  1018. try{
  1019. let authority = this.$refs.headerRef.authority.isAuthority;
  1020. let number = 0;
  1021. urlInfo.status = '2';
  1022. urlInfo.num = 0;
  1023. const page = await commonBrowser.newPage();
  1024. let titleFlag = true;
  1025. page.on('response', async(response) => {
  1026. if(titleFlag){ // 第一次生成页面标题
  1027. if(urlInfo.title){
  1028. if (fs.existsSync(this.downloadDir + separator + pjson.softInfo.softName + separator + urlInfo.title)) {
  1029. urlInfo.newPath = this.downloadDir + separator + pjson.softInfo.softName + separator + urlInfo.title;
  1030. } else {
  1031. fs.mkdirSync(this.downloadDir + separator + pjson.softInfo.softName + separator + urlInfo.title);
  1032. urlInfo.newPath = this.downloadDir + separator + pjson.softInfo.softName + separator + urlInfo.title;
  1033. }
  1034. }else{
  1035. await this.getTitle(page, urlInfo); // 生成页面标题对应的文件夹
  1036. }
  1037. titleFlag = false;
  1038. }
  1039. // 检查响应的 MIME 类型是否以 'image/' 开头
  1040. let flag = false;
  1041. if(response.headers()['content-encoding'] && response.headers()['content-encoding'].indexOf('gzip') > -1){
  1042. flag = true;
  1043. }
  1044. if (response.headers()['content-type'] && response.headers()['content-type'].startsWith('image/') && (flag || response.headers()['content-length'])) {
  1045. let imgArr = ['gif', 'jpeg', 'png', 'webp', 'svg', 'tiff', 'bmp', 'ico', 'avif'];
  1046. let imgType = 'jpg';
  1047. let isBase = false;
  1048. imgArr.map((item, index) => {
  1049. if(response.headers()['content-type'].indexOf(item) > -1){
  1050. imgType = item;
  1051. if(item == 'jpeg'){
  1052. imgType = 'jpg';
  1053. }else if(item == 'avif'){
  1054. imgType = 'png';
  1055. }
  1056. }
  1057. });
  1058. let url = response.url();
  1059. let regex = /^data:image\/[\w|+|-]+;base64,/;
  1060. if(regex.exec(url)){
  1061. url = response.url().replace(/^data:image\/[\w|+|-]+;base64,/, '');
  1062. isBase = true;
  1063. }
  1064. let imgInfo = {
  1065. url: url,
  1066. contentType: response.headers()['content-type'],
  1067. status: response.status(),
  1068. imgType: imgType,
  1069. isBase: isBase
  1070. }
  1071. let outputPath = urlInfo.newPath + '\\' + this.randomString(35) + '.' + imgInfo.imgType;
  1072. urlInfo.status = '3';
  1073. number++;
  1074. if(!authority && number <= this.execNum){
  1075. if(imgInfo.isBase){ //base64位图片下载
  1076. this.downloadBaseImage(imgInfo.url, outputPath, urlInfo)
  1077. }else{
  1078. this.downloadImage(imgInfo.url, outputPath, urlInfo);
  1079. }
  1080. }
  1081. if(authority){
  1082. if(imgInfo.isBase){ //base64位图片下载
  1083. this.downloadBaseImage(imgInfo.url, outputPath, urlInfo)
  1084. }else{
  1085. this.downloadImage(imgInfo.url, outputPath, urlInfo);
  1086. }
  1087. }
  1088. }
  1089. });
  1090. await page.goto(urlInfo.url, {waitUntil : 'networkidle2'});
  1091. let pageInfo = await page.evaluate(() => {
  1092. let cHeight = document.documentElement.clientHeight;
  1093. let scrollHeight = document.body.scrollHeight;
  1094. return {'scrollHeight': scrollHeight, 'cHeight': cHeight}
  1095. });
  1096. let scrollHeight = pageInfo.scrollHeight;
  1097. let cHeight = pageInfo.cHeight;
  1098. let num = Math.ceil(scrollHeight / cHeight);
  1099. let start = -1;
  1100. let scrollTime = this.initMs();
  1101. let scrollInt = setInterval(async() => {
  1102. start ++;
  1103. await page.evaluate((start) => {
  1104. let cHeight = document.documentElement.clientHeight;
  1105. window.scrollTo({
  1106. top: cHeight * start,
  1107. behavior: "smooth"
  1108. });
  1109. }, start);
  1110. if(start > num || start > 200){ // 防止页面过长,滚动200次自动停止
  1111. clearInterval(scrollInt);
  1112. await page.close();
  1113. urlInfo.status = '4';
  1114. resolve(true);
  1115. this.loading = false;
  1116. }
  1117. }, scrollTime);
  1118. }catch(e){
  1119. urlInfo.status = '5';
  1120. reject(e);
  1121. this.showError(e);
  1122. }
  1123. })();
  1124. });
  1125. },
  1126. // 检查阿里巴巴登录状态
  1127. checkAlibabaLogin(){
  1128. this.checkLoading = true;
  1129. this.alibabaStatus = 1;
  1130. return new Promise((resolve, reject) => {
  1131. (async () => {
  1132. try{
  1133. if(this.loginBrowser){
  1134. await this.loginBrowser.close();
  1135. this.loginBrowser = null;
  1136. }
  1137. this.loginBrowser = await puppeteer.launch({
  1138. executablePath: this.initPath(),
  1139. args: ['--window-size=1280,800'],
  1140. userDataDir: this.initDataDir()
  1141. });
  1142. const page = await this.loginBrowser.newPage();
  1143. await page.setViewport({ width: 1280, height: 800 });
  1144. let testUrl = 'https://www.1688.com';
  1145. await page.goto(testUrl, {waitUntil : 'networkidle2'});
  1146. const cookies = await page.cookies();
  1147. let loginDiv = await page.$('div[class^=userNotLogin-]');
  1148. const loginEle = await page.$('div[class^=loginAvatar-]');
  1149. let loginText = '';
  1150. if (loginEle) {
  1151. loginText = await page.evaluate(el => el.innerText, loginEle);
  1152. }
  1153. const loginCookie = cookies.find(cookie =>
  1154. cookie.name === '__cn_logon__'
  1155. );
  1156. let logonValue = '';
  1157. if(loginCookie){
  1158. logonValue = loginCookie.value;
  1159. }
  1160. if(loginDiv || loginText == '登录' || logonValue == 'false' || logonValue == false){
  1161. this.alibabaStatus = 3; //未登录
  1162. }else{
  1163. this.alibabaStatus = 2;
  1164. }
  1165. resolve(this.alibabaStatus);
  1166. this.checkLoading = false;
  1167. await this.loginBrowser.close();
  1168. this.loginBrowser = null;
  1169. }catch(e){
  1170. this.checkLoading = false;
  1171. reject(3);
  1172. this.showError(e);
  1173. }
  1174. })();
  1175. });
  1176. },
  1177. // 1 - 阿里巴巴下载
  1178. async alibabaDownload(urlInfo, browser){
  1179. let task = await new Promise((resolve,reject) =>{
  1180. (async () => {
  1181. try{
  1182. let authority = this.$refs.headerRef.authority.isAuthority;
  1183. urlInfo.status = '2';
  1184. urlInfo.num = 0;
  1185. const page = await browser.newPage();
  1186. let waitUntil = 'networkidle2';
  1187. waitUntil = this.initDevelop().waitUntil;
  1188. let goUrl = urlInfo.url;
  1189. if(this.menuIndex == '1' && goUrl.indexOf('version=0') == -1){ // 阿里巴巴
  1190. if(goUrl.indexOf('?') > -1){
  1191. goUrl += "&version=0";
  1192. }else{
  1193. goUrl += "?verison=0";
  1194. }
  1195. }
  1196. await page.goto(goUrl, {waitUntil : waitUntil});
  1197. if(urlInfo.title){
  1198. if (fs.existsSync(this.downloadDir + separator + pjson.softInfo.softName + separator + urlInfo.title)) {
  1199. urlInfo.newPath = this.downloadDir + separator + pjson.softInfo.softName + separator + urlInfo.title;
  1200. } else {
  1201. fs.mkdirSync(this.downloadDir + separator + pjson.softInfo.softName + separator + urlInfo.title);
  1202. urlInfo.newPath = this.downloadDir + separator + pjson.softInfo.softName + separator + urlInfo.title;
  1203. }
  1204. }else{
  1205. await this.getTitle(page, urlInfo); // 生成页面标题对应的文件夹
  1206. }
  1207. let pageInfo = await page.evaluate(() => {
  1208. let cHeight = document.documentElement.clientHeight;
  1209. let scrollHeight = document.body.scrollHeight;
  1210. return {'scrollHeight': scrollHeight, 'cHeight': cHeight}
  1211. });
  1212. let scrollHeight = pageInfo.scrollHeight;
  1213. let cHeight = pageInfo.cHeight;
  1214. let num = Math.ceil(scrollHeight / cHeight);
  1215. let start = -1;
  1216. let scrollTime = this.initMs();
  1217. if(scrollTime < 800 && this.menuIndex == '6'){
  1218. scrollTime = 800;
  1219. }
  1220. let scrollInt = setInterval(async() => {
  1221. start ++;
  1222. if(this.settingArr.indexOf('detailImg') > -1){
  1223. let scrollHeight2 = await page.evaluate((start) => {
  1224. let scrollHeight = document.body.scrollHeight;
  1225. let cHeight = document.documentElement.clientHeight;
  1226. // let num = Math.ceil(scrollHeight / cHeight);
  1227. window.scrollTo({
  1228. top: cHeight * start,
  1229. behavior: "smooth"
  1230. });
  1231. return scrollHeight;
  1232. }, start);
  1233. num = Math.ceil(scrollHeight2 / cHeight);
  1234. }
  1235. if(start > num || start > 200){ // 防止页面过长,滚动200次自动停止
  1236. urlInfo.status = '3';
  1237. clearInterval(scrollInt);
  1238. if(this.menuIndex == '1'){ // 阿里巴巴
  1239. await this.alibabaScanImg(browser, page, urlInfo, authority);
  1240. }else if(this.menuIndex == '6'){ //阿里国际
  1241. await this.aliguojiScanImg(browser, page, urlInfo, authority);
  1242. }else if(this.menuIndex == '7'){ // 爱采购
  1243. await this.acaigouScanImg(browser, page, urlInfo, authority);
  1244. }else if(this.menuIndex == '8'){ // 亚马逊
  1245. await this.amazonScanImg(browser, page, urlInfo, authority);
  1246. }
  1247. this.loading = false;
  1248. urlInfo.status = '4';
  1249. resolve(true);
  1250. }
  1251. }, scrollTime);
  1252. }catch(e){
  1253. urlInfo.status = '5';
  1254. reject(e);
  1255. this.showError(e);
  1256. }
  1257. })();
  1258. });
  1259. },
  1260. // 检查京东登录状态
  1261. checkJdLogin(){
  1262. this.checkLoading = true;
  1263. this.jdStatus = 1;
  1264. return new Promise((resolve, reject) => {
  1265. (async () => {
  1266. try{
  1267. if(this.loginBrowser){
  1268. await this.loginBrowser.close();
  1269. this.loginBrowser = null;
  1270. }
  1271. this.loginBrowser = await puppeteer.launch({
  1272. executablePath: this.initPath(),
  1273. args: ['--window-size=1280,800'],
  1274. userDataDir: this.initDataDir('jd'),
  1275. args: [
  1276. '--start-maximized',
  1277. '--no-sandbox',
  1278. '--disable-setuid-sandbox',
  1279. '--disable-blink-features=AutomationControlled'
  1280. ]
  1281. });
  1282. const page = await this.loginBrowser.newPage();
  1283. await page.setViewport({ width: 1280, height: 800 });
  1284. let testUrl = 'https://www.jd.com';
  1285. await page.goto(testUrl, {waitUntil : 'networkidle2'});
  1286. let loginInfo = await page.evaluate(() => {
  1287. let navTags = document.querySelector('.link-login');
  1288. let userTags = document.querySelector('.nickname');
  1289. let userTags2 = document.querySelector('.nick'); //企业账号
  1290. let userInfo2 = document.querySelector('.login_info'); //页面右侧的登录信息
  1291. let userTags3 = false;
  1292. if(userInfo2 && userInfo2.innerText.indexOf('退出') > -1){
  1293. userTags3 = true;
  1294. }
  1295. if(navTags && navTags.innerHTML.indexOf('请登录') > -1 && !userTags3){
  1296. return false;
  1297. }else if(userTags || userTags2 || userTags3){
  1298. return true;
  1299. }else{
  1300. return false;
  1301. }
  1302. });
  1303. if(loginInfo){
  1304. this.jdStatus = 2;
  1305. }else{
  1306. this.jdStatus = 3;
  1307. }
  1308. resolve(this.jdStatus);
  1309. this.checkLoading = false;
  1310. await this.loginBrowser.close();
  1311. this.loginBrowser = null;
  1312. }catch(e){
  1313. this.checkLoading = false;
  1314. reject(3);
  1315. this.showError(e);
  1316. }
  1317. })();
  1318. });
  1319. },
  1320. // 京东下载
  1321. async jdScanImg(urlInfo, jdBrowser){
  1322. let task = await new Promise((resolve,reject) =>{
  1323. (async () => {
  1324. try{
  1325. let authority = this.$refs.headerRef.authority.isAuthority;
  1326. urlInfo.status = '2';
  1327. urlInfo.num = 0;
  1328. const page = await jdBrowser.newPage();
  1329. await page.evaluateOnNewDocument(() => {
  1330. const newProto = navigator.__proto__;
  1331. delete newProto.webdriver;
  1332. navigator.__proto__ = newProto;
  1333. window.navigator.chrome = {
  1334. runtime: {}
  1335. };
  1336. });
  1337. let jdImgInfo = {
  1338. mainImg: [],
  1339. skuImg: [],
  1340. commentImg: [],
  1341. detailImg: [],
  1342. video: []
  1343. };
  1344. let titleFlag = true;
  1345. let skuNum = 0, mainNum = 0, videoNum = 0;
  1346. page.on('response', async(response) => {
  1347. if(titleFlag){ // 第一次生成页面标题
  1348. if(urlInfo.title){
  1349. if (fs.existsSync(this.downloadDir + separator + pjson.softInfo.softName + separator + urlInfo.title)) {
  1350. urlInfo.newPath = this.downloadDir + separator + pjson.softInfo.softName + separator + urlInfo.title;
  1351. } else {
  1352. fs.mkdirSync(this.downloadDir + separator + pjson.softInfo.softName + separator + urlInfo.title);
  1353. urlInfo.newPath = this.downloadDir + separator + pjson.softInfo.softName + separator + urlInfo.title;
  1354. }
  1355. }else{
  1356. await this.getTitle(page, urlInfo); // 生成页面标题对应的文件夹
  1357. }
  1358. titleFlag = false;
  1359. }
  1360. // 检查响应的 MIME 类型是否以 'image/' 开头
  1361. if (response.headers()['content-type']) {
  1362. let detailUrl = '';
  1363. let videoUrl = '';
  1364. if(response.url().indexOf('/description/') > -1){ // 商品详情接口
  1365. detailUrl = response.url();
  1366. }
  1367. if(response.url().indexOf('/tencent/video_v3') > -1){ // 商品视频接口
  1368. videoUrl = response.url();
  1369. }
  1370. urlInfo.status = '3';
  1371. if(detailUrl && this.settingArr.indexOf('detailImg') > -1){ // jd商品详情
  1372. try {
  1373. let data = await response.text();
  1374. if(data.indexOf('showdesc(') > -1){
  1375. data = data.slice(0, -1).replace('showdesc(', '');
  1376. }
  1377. let detailInfo = JSON.parse(data);
  1378. let regex = /\/\/img[0-9]+.360buyimg.com\S+.(jpg|jpeg|png|gif|avif|tif|tiff)/g;
  1379. let detailImgArr = [];
  1380. if(detailInfo && detailInfo.content){
  1381. if(detailInfo.content.match(regex)){
  1382. detailImgArr = detailInfo.content.match(regex);
  1383. }
  1384. }
  1385. jdImgInfo.detailImg = detailImgArr;
  1386. for(let i = 0; i < detailImgArr.length; i++){
  1387. let imgUrl = 'https:' + detailImgArr[i];
  1388. imgUrl = imgUrl.replace('.avif', '');
  1389. let fileName = imgUrl.split('/').pop();
  1390. if(fileName){
  1391. let queryIndex = fileName.indexOf('?');
  1392. if (queryIndex !== -1) {
  1393. fileName = fileName.substr(0, queryIndex);
  1394. }
  1395. let num = Number(i) + 1;
  1396. let suffix = '';
  1397. if(fileName.lastIndexOf('.') > -1){
  1398. suffix = fileName.substr(fileName.lastIndexOf('.'));
  1399. }
  1400. if (!fs.existsSync(urlInfo.newPath + '\\详情图')) {
  1401. fs.mkdirSync(urlInfo.newPath + '\\详情图');
  1402. }
  1403. let outputPath = urlInfo.newPath + '\\详情图\\详情图' + num + suffix;
  1404. if(!authority && i < this.execNum){
  1405. await this.downloadImage(imgUrl, outputPath, urlInfo);
  1406. }
  1407. if(authority){
  1408. await this.downloadImage(imgUrl, outputPath, urlInfo);
  1409. }
  1410. }
  1411. }
  1412. } catch (error) {
  1413. console.error('详情图片解析失败:', error);
  1414. }
  1415. }
  1416. if(videoUrl && this.settingArr.indexOf('video') > -1){ // jd商品视频
  1417. try {
  1418. let data = await response.text();
  1419. data = data.slice(0, -1).replace(/^jQuery[0-9]+\(/, '');
  1420. let videoInfo = JSON.parse(data);
  1421. let videoUrl = videoInfo.playUrl;
  1422. jdImgInfo.video.push(videoUrl);
  1423. let fileName = videoUrl.split('/').pop();
  1424. if(fileName){
  1425. let queryIndex = fileName.indexOf('?');
  1426. if (queryIndex !== -1) {
  1427. fileName = fileName.substr(0, queryIndex);
  1428. }
  1429. if (!fs.existsSync(urlInfo.newPath + '\\视频')) {
  1430. fs.mkdirSync(urlInfo.newPath + '\\视频');
  1431. }
  1432. let outputPath = urlInfo.newPath + '\\视频\\' + fileName;
  1433. await this.downloadImage(videoUrl, outputPath, urlInfo);
  1434. }
  1435. } catch (error) {
  1436. console.error('视频解析失败:', error);
  1437. }
  1438. }
  1439. }
  1440. });
  1441. await page.goto(urlInfo.url, {waitUntil : 'networkidle2'});
  1442. let pageInfo = await page.evaluate(() => {
  1443. let cHeight = document.documentElement.clientHeight;
  1444. let scrollHeight = document.body.scrollHeight;
  1445. return {'scrollHeight': scrollHeight, 'cHeight': cHeight}
  1446. });
  1447. let scrollHeight = pageInfo.scrollHeight;
  1448. let cHeight = pageInfo.cHeight;
  1449. let num = Math.ceil(scrollHeight / cHeight);
  1450. let start = -1;
  1451. let scrollTime = this.initMs();
  1452. let scrollInt = setInterval(async() => {
  1453. start ++;
  1454. if(this.settingArr.indexOf('detailImg') > -1){ // 选择详情图
  1455. let scrollHeight2 = await page.evaluate((start) => {
  1456. let scrollHeight = document.body.scrollHeight;
  1457. let cHeight = document.documentElement.clientHeight;
  1458. let obj = document.querySelector('.detail-content') || document.querySelector('.detail-content-item');
  1459. if(obj && obj.getBoundingClientRect().top < 0){
  1460. return -1;
  1461. }
  1462. window.scrollTo({
  1463. top: cHeight * start,
  1464. behavior: "smooth"
  1465. });
  1466. return scrollHeight;
  1467. }, start);
  1468. if(scrollHeight2 > 0){
  1469. num = Math.ceil(scrollHeight2 / cHeight);
  1470. }else{
  1471. num = 0;
  1472. }
  1473. }else{
  1474. num = 0;
  1475. }
  1476. if(start > num || start > 20){ // 防止页面过长,滚动20次自动停止
  1477. clearInterval(scrollInt);
  1478. //detailImg:详情图;skuImg:sku图片;commentImg: 评论图;video: 视频
  1479. const imgInfo = await page.evaluate((authority, execNum) => {
  1480. let outObj = {
  1481. mainImg: [],
  1482. skuImg: [],
  1483. detailImg: []
  1484. };
  1485. //主图
  1486. let arr1 = document.querySelectorAll('#spec-list img');
  1487. for(let i=0; i< arr1.length; i++){
  1488. let mainImgUrl = arr1[i].src;
  1489. let reg = /\/n[0-9]+\/jfs\//;
  1490. let reg2 = /\/n[0-9]+\/s([0-9]+)x([0-9]+)_jfs\//;
  1491. let reg3 = /![a-z]+_[0-9]+x[0-9]+(.avif)?/;
  1492. let replaceStr = '/n5/s800x800_jfs/';
  1493. if(mainImgUrl.match(/\/n[0-9]+\/s50x66_jfs\//)){
  1494. replaceStr = '/n5/s750x1000_jfs/';
  1495. }
  1496. mainImgUrl = mainImgUrl.replace(reg, replaceStr).replace(reg2, replaceStr).replace(reg3, '').replace('.avif', '');
  1497. if(!authority && i < execNum){
  1498. outObj.mainImg.push(mainImgUrl);
  1499. }
  1500. if(authority){
  1501. outObj.mainImg.push(mainImgUrl);
  1502. }
  1503. }
  1504. //sku图片
  1505. let arr2 = document.querySelectorAll('#choose-attr-1 img');
  1506. for(let i=0; i< arr2.length; i++){
  1507. let skuImgUrl = arr2[i].src;
  1508. let skuReg = /\/n[0-9]+\/s([0-9]+)x([0-9]+)_jfs\//;
  1509. let replaceStr = '/n5/s800x800_jfs/';
  1510. if(skuImgUrl.match(/\/n[0-9]+\/s60x80_jfs\//)){
  1511. replaceStr = '/n5/s750x1000_jfs/';
  1512. }
  1513. skuImgUrl = skuImgUrl.replace(skuReg, replaceStr).replace('.avif', '');
  1514. if(!authority && i < execNum){
  1515. outObj.skuImg.push(skuImgUrl);
  1516. }
  1517. if(authority){
  1518. outObj.skuImg.push(skuImgUrl);
  1519. }
  1520. }
  1521. //详情图 - 图片类目需要网页直接抓取
  1522. let arr3 = document.querySelectorAll('.book-detail-content img');
  1523. for(let i=0; i< arr3.length; i++){
  1524. let detailImgUrl = arr3[i].src;
  1525. detailImgUrl = detailImgUrl.replace('.avif', '');
  1526. if(!authority && i < execNum){
  1527. outObj.detailImg.push(detailImgUrl);
  1528. }
  1529. if(authority){
  1530. outObj.detailImg.push(detailImgUrl);
  1531. }
  1532. }
  1533. return outObj;
  1534. }, authority, this.execNum);
  1535. if(this.settingArr.indexOf('mainImg') > -1){
  1536. // 主图下载
  1537. for(let j = 0; j < imgInfo.mainImg.length; j++){
  1538. let fileName = imgInfo.mainImg[j].split('/').pop();
  1539. if(fileName){
  1540. let queryIndex = fileName.indexOf('?');
  1541. if (queryIndex !== -1) {
  1542. fileName = fileName.substr(0, queryIndex);
  1543. }
  1544. let num = Number(j) + 1;
  1545. let suffix = '';
  1546. if(fileName.lastIndexOf('.') > -1){
  1547. suffix = fileName.substr(fileName.lastIndexOf('.'));
  1548. }
  1549. if (!fs.existsSync(urlInfo.newPath + '\\主图')) {
  1550. fs.mkdirSync(urlInfo.newPath + '\\主图');
  1551. }
  1552. let outputPath = urlInfo.newPath + '\\主图\\主图' + num + suffix;
  1553. await this.downloadImage(imgInfo.mainImg[j], outputPath, urlInfo);
  1554. }
  1555. }
  1556. }
  1557. // sku图片下载
  1558. if(this.settingArr.indexOf('skuImg') > -1){
  1559. for(let j = 0; j < imgInfo.skuImg.length; j++){
  1560. let fileName = imgInfo.skuImg[j].split('/').pop();
  1561. if(fileName){
  1562. let queryIndex = fileName.indexOf('?');
  1563. if (queryIndex !== -1) {
  1564. fileName = fileName.substr(0, queryIndex);
  1565. }
  1566. let num = Number(j) + 1;
  1567. let suffix = '';
  1568. if(fileName.lastIndexOf('.') > -1){
  1569. suffix = fileName.substr(fileName.lastIndexOf('.'));
  1570. }
  1571. if (!fs.existsSync(urlInfo.newPath + '\\sku图')) {
  1572. fs.mkdirSync(urlInfo.newPath + '\\sku图');
  1573. }
  1574. let outputPath = urlInfo.newPath + '\\sku图\\sku图' + num + suffix;
  1575. await this.downloadImage(imgInfo.skuImg[j], outputPath, urlInfo);
  1576. }
  1577. }
  1578. }
  1579. // 详情图下载 --图书类目
  1580. if(this.settingArr.indexOf('detailImg') > -1 && jdImgInfo.detailImg.length == 0){
  1581. for(let j = 0; j < imgInfo.detailImg.length; j++){
  1582. let fileName = imgInfo.detailImg[j].split('/').pop();
  1583. if(fileName){
  1584. let queryIndex = fileName.indexOf('?');
  1585. if (queryIndex !== -1) {
  1586. fileName = fileName.substr(0, queryIndex);
  1587. }
  1588. let num = Number(j) + 1;
  1589. let suffix = '';
  1590. if(fileName.lastIndexOf('.') > -1){
  1591. suffix = fileName.substr(fileName.lastIndexOf('.'));
  1592. }
  1593. if (!fs.existsSync(urlInfo.newPath + '\\详情图')) {
  1594. fs.mkdirSync(urlInfo.newPath + '\\详情图');
  1595. }
  1596. let outputPath = urlInfo.newPath + '\\详情图\\详情图' + num + suffix;
  1597. await this.downloadImage(imgInfo.detailImg[j], outputPath, urlInfo);
  1598. }
  1599. }
  1600. }
  1601. /**end**/
  1602. await page.close();
  1603. urlInfo.status = '4';
  1604. resolve(true);
  1605. this.loading = false;
  1606. }
  1607. }, scrollTime);
  1608. }catch(e){
  1609. reject(e);
  1610. this.showError(e);
  1611. }
  1612. })();
  1613. });
  1614. },
  1615. // 检查天猫淘宝登录状态
  1616. checkLogin(){
  1617. this.checkLoading = true;
  1618. this.tbStatus = 1;
  1619. return new Promise((resolve, reject) => {
  1620. (async () => {
  1621. try{
  1622. if(this.loginBrowser){
  1623. await this.loginBrowser.close();
  1624. this.loginBrowser = null;
  1625. }
  1626. this.loginBrowser = await puppeteer.launch({
  1627. executablePath: this.initPath(),
  1628. args: ['--window-size=1280,800'],
  1629. userDataDir: this.initDataDir()
  1630. });
  1631. const page = await this.loginBrowser.newPage();
  1632. await page.setViewport({ width: 1280, height: 800 });
  1633. let testUrl = 'https://www.taobao.com';
  1634. await page.goto(testUrl, {waitUntil : 'networkidle2'});
  1635. let loginInfo = await page.evaluate(() => {
  1636. let navTags = document.querySelector('.site-nav-sign a');
  1637. let userTags = document.querySelector('.site-nav-user a');
  1638. if(navTags && navTags.innerHTML.indexOf('登录') > -1){
  1639. return false;
  1640. }else if(userTags){
  1641. return true;
  1642. }else{
  1643. return false;
  1644. }
  1645. });
  1646. if(loginInfo){
  1647. this.tbStatus = 2;
  1648. }else{
  1649. this.tbStatus = 3;
  1650. }
  1651. resolve(this.tbStatus);
  1652. this.checkLoading = false;
  1653. await this.loginBrowser.close();
  1654. this.loginBrowser = null;
  1655. }catch(e){
  1656. this.checkLoading = false;
  1657. reject(3);
  1658. this.showError(e);
  1659. }
  1660. })();
  1661. });
  1662. },
  1663. // 淘宝天猫扫描下载图片
  1664. async tbScanImg(urlInfo, tbBrowser){
  1665. let task = await new Promise((resolve,reject) =>{
  1666. (async () => {
  1667. try{
  1668. let authority = this.$refs.headerRef.authority.isAuthority;
  1669. urlInfo.status = '2';
  1670. urlInfo.num = 0;
  1671. let page = await tbBrowser.newPage();
  1672. let responseVideo = [];
  1673. page.on('response', async(response) => {
  1674. // 检查响应的 MIME 类型是否以 'video/' 开头
  1675. if (response.headers()['content-type'] && response.headers()['content-type'].startsWith('video/')) {
  1676. if(responseVideo.indexOf(response.url()) < 0 && !response.url().startsWith('blob:https://')){
  1677. responseVideo.push(response.url());
  1678. }
  1679. }
  1680. });
  1681. let waitUntil = 'networkidle2';
  1682. waitUntil = this.initDevelop().waitUntil;
  1683. await page.goto(urlInfo.url, {waitUntil : waitUntil});
  1684. if(this.settingArr.indexOf('video') > -1){ // 用户选择下载视频的时候才会触发
  1685. //鼠标放在主图第一张,生成视频
  1686. const elementHandle = await page.$('li[class*=thumbnail--]');
  1687. if(elementHandle){
  1688. const classListProperty = await elementHandle.getProperty('classList');
  1689. const classList = await classListProperty.jsonValue();
  1690. const classesArray = Object.values(classList);
  1691. const allClasses = classesArray.join('.');
  1692. if(allClasses && allClasses.indexOf('active-') < 0){
  1693. await page.hover('li.'+allClasses);
  1694. }
  1695. }
  1696. }
  1697. let frames = await page.$$('iframe');
  1698. if(frames.length == 1){ // 就一个
  1699. let isAdVisible = false;
  1700. try{ //判断是否是隐藏弹窗iframe
  1701. isAdVisible = await page.$eval('iframe', ad => {
  1702. return getComputedStyle(ad).display !== 'none';
  1703. });
  1704. }catch(e){
  1705. }
  1706. if(isAdVisible){
  1707. let m2 = await page.$('img[class*=thumbnailPic--]');
  1708. if(!m2){ // 出现弹窗而且没有主图,判断为拦截模式
  1709. await page.close();
  1710. urlInfo.status = '6';
  1711. resolve(true);
  1712. this.loading = false;
  1713. return false;
  1714. }
  1715. }
  1716. }else if(frames.length > 1){ //多个弹窗就判断是否有图片显示
  1717. let m2 = await page.$('img[class*=thumbnailPic--]');
  1718. if(!m2){ // 出现弹窗而且没有主图,判断为拦截模式
  1719. await page.close();
  1720. urlInfo.status = '6';
  1721. resolve(true);
  1722. this.loading = false;
  1723. return false;
  1724. }
  1725. }
  1726. let pageInfo = await page.evaluate(() => {
  1727. let cHeight = document.documentElement.clientHeight;
  1728. let scrollHeight = document.body.scrollHeight;
  1729. return {'scrollHeight': scrollHeight, 'cHeight': cHeight}
  1730. });
  1731. let scrollHeight = pageInfo.scrollHeight;
  1732. let cHeight = pageInfo.cHeight;
  1733. let num = Math.ceil(scrollHeight / cHeight);
  1734. let start = -1;
  1735. let scrollTime = this.initMs();
  1736. let scrollInt = setInterval(async() => {
  1737. start ++;
  1738. if(this.settingArr.indexOf('commentImg') > -1 && this.settingArr.indexOf('detailImg') < 0){ // 选择了评论图没选择详情图
  1739. let scrollHeight2 = await page.evaluate((start) => {
  1740. let scrollHeight = document.body.scrollHeight;
  1741. let cHeight = document.documentElement.clientHeight;
  1742. let obj = document.getElementById('container') || document.getElementById('content');
  1743. if(obj && obj.getBoundingClientRect().top < -500){
  1744. return -1;
  1745. }
  1746. window.scrollTo({
  1747. top: cHeight * start,
  1748. behavior: "smooth"
  1749. });
  1750. return scrollHeight;
  1751. }, start);
  1752. if(scrollHeight2 > 0){
  1753. num = Math.ceil(scrollHeight2 / cHeight);
  1754. }else{
  1755. num = 0;
  1756. }
  1757. }
  1758. if(this.settingArr.indexOf('detailImg') > -1){ // 选择详情图
  1759. let scrollHeight2 = await page.evaluate((start) => {
  1760. let scrollHeight = document.body.scrollHeight;
  1761. let cHeight = document.documentElement.clientHeight;
  1762. let obj = document.getElementById('container') || document.getElementById('content');
  1763. if(obj && obj.getBoundingClientRect().bottom < 100){
  1764. return -1;
  1765. }
  1766. window.scrollTo({
  1767. top: cHeight * start,
  1768. behavior: "smooth"
  1769. });
  1770. return scrollHeight;
  1771. }, start);
  1772. if(scrollHeight2 > 0){
  1773. num = Math.ceil(scrollHeight2 / cHeight);
  1774. }else{
  1775. num = 0;
  1776. }
  1777. }
  1778. if(this.settingArr.indexOf('skuImg') > -1 && this.settingArr.indexOf('commentImg') < 0 && this.settingArr.indexOf('detailImg') < 0){ // 选择了sku图片没选择评论和详情
  1779. let scrollHeight2 = await page.evaluate((start) => {
  1780. let scrollHeight = document.body.scrollHeight;
  1781. let cHeight = document.documentElement.clientHeight;
  1782. let obj = document.querySelector('div[class^=SkuContent--]');
  1783. if(obj && obj.getBoundingClientRect().bottom < 500){
  1784. return -1;
  1785. }
  1786. window.scrollTo({
  1787. top: cHeight * start,
  1788. behavior: "smooth"
  1789. });
  1790. return scrollHeight;
  1791. }, start);
  1792. if(scrollHeight2 > 0){
  1793. num = Math.ceil(scrollHeight2 / cHeight);
  1794. }else{
  1795. num = 0;
  1796. }
  1797. }
  1798. if(this.settingArr.indexOf('skuImg') < 0 && this.settingArr.indexOf('detailImg') < 0 && this.settingArr.indexOf('commentImg') < 0){ // 没有选择评论图和详情图
  1799. num = 0;
  1800. }
  1801. if(start > num || start > 200){ // 防止页面过长,滚动200次自动停止
  1802. urlInfo.status = '3';
  1803. clearInterval(scrollInt);
  1804. if(urlInfo.title){
  1805. if (fs.existsSync(this.downloadDir + separator + pjson.softInfo.softName + separator + urlInfo.title)) {
  1806. urlInfo.newPath = this.downloadDir + separator + pjson.softInfo.softName + separator + urlInfo.title;
  1807. } else {
  1808. fs.mkdirSync(this.downloadDir + separator + pjson.softInfo.softName + separator + urlInfo.title);
  1809. urlInfo.newPath = this.downloadDir + separator + pjson.softInfo.softName + separator + urlInfo.title;
  1810. }
  1811. }else{
  1812. await this.getTitle(page, urlInfo); // 生成页面标题对应的文件夹
  1813. }
  1814. //detailImg:详情图;skuImg:sku图片;commentImg: 评论图;video: 视频
  1815. const imgInfo = await page.evaluate((authority, execNum) => {
  1816. let outObj = {
  1817. mainImg: [],
  1818. detailImg: [],
  1819. skuImg: [],
  1820. commentImg: [],
  1821. video: []
  1822. };
  1823. // 正则表达式匹配字符 重写图片路径
  1824. let regex = /\.(.{3,4})_[0-9a-zA-z]+\.(.{3,4})_\.(.{3,4})/;
  1825. //主图
  1826. let arr1 = document.querySelectorAll('img[class^=PicGallery--thumbnailPic--]');
  1827. if(arr1.length === 0){
  1828. arr1 = document.querySelectorAll('img[class*=thumbnailPic--]');
  1829. }
  1830. for(let i=0; i< arr1.length; i++){
  1831. let mainImgUrl = arr1[i].src;
  1832. let result = regex.exec(mainImgUrl);
  1833. if(result){
  1834. mainImgUrl = mainImgUrl.replace(result[0], '.'+result[1]);
  1835. }
  1836. if(!authority && i < execNum){
  1837. outObj.mainImg.push(mainImgUrl);
  1838. }
  1839. if(authority){
  1840. outObj.mainImg.push(mainImgUrl);
  1841. }
  1842. }
  1843. //sku图片
  1844. let arr2 = document.querySelectorAll('img[class^=SkuContent--valueItemImg--]');
  1845. if(arr2.length === 0){
  1846. arr2 = document.querySelectorAll('img[class*=valueItemImg--]');
  1847. }
  1848. for(let i=0; i< arr2.length; i++){
  1849. let skuImgUrl = arr2[i].src;
  1850. let result = regex.exec(skuImgUrl);
  1851. if(result){
  1852. skuImgUrl = skuImgUrl.replace(result[0], '.'+result[1]);
  1853. }
  1854. if(!authority && i < execNum){
  1855. outObj.skuImg.push(skuImgUrl);
  1856. }
  1857. if(authority){
  1858. outObj.skuImg.push(skuImgUrl);
  1859. }
  1860. }
  1861. //详情图片
  1862. let arr3 = document.querySelectorAll('#content img');
  1863. for(let i=0; i< arr3.length; i++){
  1864. let detailImgUrl = arr3[i].src;
  1865. let lazyUrl = arr3[i].getAttribute('data-src');
  1866. if(arr3[i].src.indexOf('/s.gif') > -1 && lazyUrl){
  1867. detailImgUrl = lazyUrl;
  1868. if(!/^http/.exec(lazyUrl)){
  1869. detailImgUrl = 'https:' + lazyUrl;
  1870. }
  1871. }
  1872. let result = regex.exec(detailImgUrl);
  1873. if(result){
  1874. detailImgUrl = detailImgUrl.replace(result[0], '.'+result[1]);
  1875. }
  1876. if(!authority && i < execNum){
  1877. outObj.detailImg.push(detailImgUrl);
  1878. }
  1879. if(authority){
  1880. outObj.detailImg.push(detailImgUrl);
  1881. }
  1882. }
  1883. //评论图片
  1884. let arr4 = document.querySelectorAll('div[class*=Comments--] img');
  1885. if(arr4.length === 0){
  1886. arr4 = document.querySelectorAll('div[class*=comments--] img');
  1887. }
  1888. for(let i=0; i< arr4.length; i++){
  1889. if(arr4[i].src.indexOf('/avatar/sns/user/flag/sns_logo') == -1 && arr4[i].className.indexOf('creditImg') == -1){ //过滤淘宝用户头像
  1890. if(!authority && i < execNum){
  1891. outObj.commentImg.push(arr4[i].src);
  1892. }
  1893. if(authority){
  1894. outObj.commentImg.push(arr4[i].src);
  1895. }
  1896. }
  1897. }
  1898. // 视频
  1899. let arr5 = document.querySelectorAll('video');
  1900. for(let i=0; i< arr5.length; i++){
  1901. if(outObj.video.indexOf(arr5[i].src) == -1){
  1902. if(!authority && i < execNum){
  1903. outObj.video.push(arr5[i].src);
  1904. }
  1905. if(authority){
  1906. outObj.video.push(arr5[i].src);
  1907. }
  1908. }
  1909. }
  1910. return outObj;
  1911. }, authority, this.execNum);
  1912. if(responseVideo.length > 0){
  1913. for(let l=0; l<responseVideo.length; l++){
  1914. if(imgInfo.video.indexOf(responseVideo[l]) == -1){
  1915. imgInfo.video.push(responseVideo[l]);
  1916. }
  1917. }
  1918. }
  1919. if(this.settingArr.indexOf('mainImg') > -1){
  1920. // 主图下载
  1921. for(let j = 0; j < imgInfo.mainImg.length; j++){
  1922. let fileName = imgInfo.mainImg[j].split('/').pop();
  1923. if(fileName){
  1924. let queryIndex = fileName.indexOf('?');
  1925. if (queryIndex !== -1) {
  1926. fileName = fileName.substr(0, queryIndex);
  1927. }
  1928. let num = Number(j) + 1;
  1929. let suffix = '';
  1930. if(fileName.lastIndexOf('.') > -1){
  1931. suffix = fileName.substr(fileName.lastIndexOf('.'));
  1932. }
  1933. if (!fs.existsSync(urlInfo.newPath + '\\主图')) {
  1934. fs.mkdirSync(urlInfo.newPath + '\\主图');
  1935. }
  1936. let outputPath = urlInfo.newPath + '\\主图\\主图' + num + suffix;
  1937. await this.downloadImage(imgInfo.mainImg[j], outputPath, urlInfo);
  1938. }
  1939. }
  1940. }
  1941. // sku图片下载
  1942. if(this.settingArr.indexOf('skuImg') > -1){
  1943. for(let j = 0; j < imgInfo.skuImg.length; j++){
  1944. let fileName = imgInfo.skuImg[j].split('/').pop();
  1945. if(fileName){
  1946. let queryIndex = fileName.indexOf('?');
  1947. if (queryIndex !== -1) {
  1948. fileName = fileName.substr(0, queryIndex);
  1949. }
  1950. let num = Number(j) + 1;
  1951. let suffix = '';
  1952. if(fileName.lastIndexOf('.') > -1){
  1953. suffix = fileName.substr(fileName.lastIndexOf('.'));
  1954. }
  1955. if (!fs.existsSync(urlInfo.newPath + '\\sku图')) {
  1956. fs.mkdirSync(urlInfo.newPath + '\\sku图');
  1957. }
  1958. let outputPath = urlInfo.newPath + '\\sku图\\sku图' + num + suffix;
  1959. await this.downloadImage(imgInfo.skuImg[j], outputPath, urlInfo);
  1960. }
  1961. }
  1962. }
  1963. //详情图下载
  1964. if(this.settingArr.indexOf('detailImg') > -1){
  1965. for(let j = 0; j < imgInfo.detailImg.length; j++){
  1966. let fileName = imgInfo.detailImg[j].split('/').pop();
  1967. if(fileName){
  1968. let queryIndex = fileName.indexOf('?');
  1969. if (queryIndex !== -1) {
  1970. fileName = fileName.substr(0, queryIndex);
  1971. }
  1972. let num = Number(j) + 1;
  1973. let suffix = '';
  1974. if(fileName.lastIndexOf('.') > -1){
  1975. suffix = fileName.substr(fileName.lastIndexOf('.'));
  1976. }
  1977. if (!fs.existsSync(urlInfo.newPath + '\\详情图')) {
  1978. fs.mkdirSync(urlInfo.newPath + '\\详情图');
  1979. }
  1980. let outputPath = urlInfo.newPath + '\\详情图\\详情图' + num + suffix;
  1981. await this.downloadImage(imgInfo.detailImg[j], outputPath, urlInfo);
  1982. }
  1983. }
  1984. }
  1985. //评论图下载
  1986. if(this.settingArr.indexOf('commentImg') > -1){
  1987. for(let j = 0; j < imgInfo.commentImg.length; j++){
  1988. let fileName = imgInfo.commentImg[j].split('/').pop();
  1989. if(fileName){
  1990. let queryIndex = fileName.indexOf('?');
  1991. if (queryIndex !== -1) {
  1992. fileName = fileName.substr(0, queryIndex);
  1993. }
  1994. let num = Number(j) + 1;
  1995. let suffix = '';
  1996. if(fileName.lastIndexOf('.') > -1){
  1997. suffix = fileName.substr(fileName.lastIndexOf('.'));
  1998. }
  1999. if (!fs.existsSync(urlInfo.newPath + '\\评论图')) {
  2000. fs.mkdirSync(urlInfo.newPath + '\\评论图');
  2001. }
  2002. let outputPath = urlInfo.newPath + '\\评论图\\评论图' + num + suffix;
  2003. await this.downloadImage(imgInfo.commentImg[j], outputPath, urlInfo);
  2004. }
  2005. }
  2006. }
  2007. //视频下载
  2008. if(this.settingArr.indexOf('video') > -1){
  2009. for(let j = 0; j < imgInfo.video.length; j++){
  2010. let fileName = imgInfo.video[j].split('/').pop();
  2011. if(fileName){
  2012. let queryIndex = fileName.indexOf('?');
  2013. if (queryIndex !== -1) {
  2014. fileName = fileName.substr(0, queryIndex);
  2015. }
  2016. if (!fs.existsSync(urlInfo.newPath + '\\视频')) {
  2017. fs.mkdirSync(urlInfo.newPath + '\\视频');
  2018. }
  2019. let outputPath = urlInfo.newPath + '\\视频\\' + fileName;
  2020. await this.downloadImage(imgInfo.video[j], outputPath, urlInfo);
  2021. }
  2022. }
  2023. }
  2024. await page.close();
  2025. urlInfo.status = '4';
  2026. resolve(true);
  2027. this.loading = false;
  2028. }
  2029. }, scrollTime);
  2030. }catch(e){
  2031. reject(e);
  2032. this.showError(e);
  2033. }
  2034. })();
  2035. });
  2036. },
  2037. // 阿里巴巴 - 扫描并下载图片
  2038. async alibabaScanImg(browser, page, urlInfo, authority){
  2039. //detailImg:详情图;skuImg:sku图片;commentImg: 评论图;video: 视频
  2040. const imgInfo = await page.evaluate((authority, execNum) => {
  2041. let outObj = {
  2042. mainImg: [],
  2043. detailImg: [],
  2044. skuImg: [],
  2045. commentImg: [],
  2046. video: []
  2047. };
  2048. //主图
  2049. let arr1 = document.querySelectorAll('img[class*="-gallery-img"]');
  2050. for(let i=0; i< arr1.length; i++){
  2051. let srcUrl = arr1[i].src;
  2052. if(srcUrl.endsWith('_b.jpg')){
  2053. srcUrl = srcUrl.replace(/_b\.jpg$/, '');
  2054. }
  2055. if(!authority && i < execNum){
  2056. outObj.mainImg.push(srcUrl);
  2057. }
  2058. if(authority){
  2059. outObj.mainImg.push(srcUrl);
  2060. }
  2061. }
  2062. //sku图片
  2063. let type = 'bg';
  2064. let arr2 = document.querySelectorAll('.prop-img');
  2065. if(arr2.length == 0){
  2066. arr2 = document.querySelectorAll('.sku-item-image');
  2067. }
  2068. if(arr2.length == 0){
  2069. arr2 = document.querySelectorAll('.ant-image-img');
  2070. type = 'img';
  2071. }
  2072. for(let i=0; i< arr2.length; i++){
  2073. let src;
  2074. if(type == 'bg'){
  2075. src = window.getComputedStyle(arr2[i]).backgroundImage.replace(/url\(["']?(.+?)["']?\)/i, '$1');
  2076. }
  2077. if(type == 'img'){
  2078. src = arr2[i].src;
  2079. }
  2080. if(src.endsWith('_sum.jpg')){
  2081. src = src.replace(/_sum\.jpg$/, '');
  2082. }
  2083. if(!authority && i < execNum){
  2084. outObj.skuImg.push(src);
  2085. }
  2086. if(authority){
  2087. outObj.skuImg.push(src);
  2088. }
  2089. }
  2090. //详情图片
  2091. let arr3 = document.querySelectorAll('img.desc-img-loaded');
  2092. if(arr3.length == 0){
  2093. if(document.getElementById('description') && document.getElementById('description').querySelector('.html-description')){
  2094. arr3 = document.getElementById('description').querySelector('.html-description').shadowRoot.querySelectorAll('img');
  2095. }
  2096. }
  2097. for(let i=0; i< arr3.length; i++){
  2098. if(!authority && i < execNum){
  2099. outObj.detailImg.push(arr3[i].src);
  2100. }
  2101. if(authority){
  2102. outObj.detailImg.push(arr3[i].src);
  2103. }
  2104. }
  2105. // 视频
  2106. let arr5 = document.querySelectorAll('video');
  2107. for(let i=0; i< arr5.length; i++){
  2108. if(outObj.video.indexOf(arr5[i].src) == -1){
  2109. if(!authority && i < execNum){
  2110. outObj.video.push(arr5[i].src);
  2111. }
  2112. if(authority){
  2113. outObj.video.push(arr5[i].src);
  2114. }
  2115. }
  2116. }
  2117. return outObj;
  2118. }, authority, this.execNum);
  2119. // 主图下载
  2120. if(this.settingArr.indexOf('mainImg') > -1){
  2121. for(let j = 0; j < imgInfo.mainImg.length; j++){
  2122. let fileName = imgInfo.mainImg[j].split('/').pop();
  2123. if(fileName){
  2124. let queryIndex = fileName.indexOf('?');
  2125. if (queryIndex !== -1) {
  2126. fileName = fileName.substr(0, queryIndex);
  2127. }
  2128. let num = Number(j) + 1;
  2129. let suffix = '';
  2130. if(fileName.lastIndexOf('.') > -1){
  2131. suffix = fileName.substr(fileName.lastIndexOf('.'));
  2132. }
  2133. if (!fs.existsSync(urlInfo.newPath + '\\主图')) {
  2134. fs.mkdirSync(urlInfo.newPath + '\\主图');
  2135. }
  2136. let outputPath = urlInfo.newPath + '\\主图\\主图' + num + suffix;
  2137. await this.downloadImage(imgInfo.mainImg[j], outputPath, urlInfo);
  2138. }
  2139. }
  2140. }
  2141. // sku图片下载
  2142. if(this.settingArr.indexOf('skuImg') > -1){
  2143. for(let j = 0; j < imgInfo.skuImg.length; j++){
  2144. let fileName = imgInfo.skuImg[j].split('/').pop();
  2145. if(fileName){
  2146. let queryIndex = fileName.indexOf('?');
  2147. if (queryIndex !== -1) {
  2148. fileName = fileName.substr(0, queryIndex);
  2149. }
  2150. let num = Number(j) + 1;
  2151. let suffix = '';
  2152. if(fileName.lastIndexOf('.') > -1){
  2153. suffix = fileName.substr(fileName.lastIndexOf('.'));
  2154. }
  2155. if (!fs.existsSync(urlInfo.newPath + '\\sku图')) {
  2156. fs.mkdirSync(urlInfo.newPath + '\\sku图');
  2157. }
  2158. let outputPath = urlInfo.newPath + '\\sku图\\sku图' + num + suffix;
  2159. await this.downloadImage(imgInfo.skuImg[j], outputPath, urlInfo);
  2160. }
  2161. }
  2162. }
  2163. //详情图下载
  2164. if(this.settingArr.indexOf('detailImg') > -1){
  2165. for(let j = 0; j < imgInfo.detailImg.length; j++){
  2166. let fileName = imgInfo.detailImg[j].split('/').pop();
  2167. if(fileName){
  2168. let queryIndex = fileName.indexOf('?');
  2169. if (queryIndex !== -1) {
  2170. fileName = fileName.substr(0, queryIndex);
  2171. }
  2172. let num = Number(j) + 1;
  2173. let suffix = '';
  2174. if(fileName.lastIndexOf('.') > -1){
  2175. suffix = fileName.substr(fileName.lastIndexOf('.'));
  2176. }
  2177. if (!fs.existsSync(urlInfo.newPath + '\\详情图')) {
  2178. fs.mkdirSync(urlInfo.newPath + '\\详情图');
  2179. }
  2180. let outputPath = urlInfo.newPath + '\\详情图\\' + '详情图' + num + suffix;
  2181. await this.downloadImage(imgInfo.detailImg[j], outputPath, urlInfo);
  2182. }
  2183. }
  2184. }
  2185. //视频下载
  2186. if(this.settingArr.indexOf('video') > -1){
  2187. for(let j = 0; j < imgInfo.video.length; j++){
  2188. let fileName = imgInfo.video[j].split('/').pop();
  2189. if(fileName){
  2190. let queryIndex = fileName.indexOf('?');
  2191. if (queryIndex !== -1) {
  2192. fileName = fileName.substr(0, queryIndex);
  2193. }
  2194. if (!fs.existsSync(urlInfo.newPath + '\\视频')) {
  2195. fs.mkdirSync(urlInfo.newPath + '\\视频');
  2196. }
  2197. let outputPath = urlInfo.newPath + '\\视频\\' + fileName;
  2198. await this.downloadImage(imgInfo.video[j], outputPath, urlInfo);
  2199. }
  2200. }
  2201. }
  2202. await page.close(); // 关闭页面但不关闭浏览器
  2203. },
  2204. // 检查小红书登录状态
  2205. checkRedLogin(){
  2206. this.checkLoading = true;
  2207. this.redStatus = 1;
  2208. return new Promise((resolve, reject) => {
  2209. (async () => {
  2210. try{
  2211. if(this.loginBrowser){
  2212. await this.loginBrowser.close();
  2213. this.loginBrowser = null;
  2214. }
  2215. puppeteer.use(StealthPlugin());
  2216. this.loginBrowser = await puppeteer.launch({
  2217. executablePath: this.initPath(),
  2218. userDataDir: this.initDataDir(),
  2219. args: [
  2220. '--start-maximized',
  2221. '--no-sandbox',
  2222. '--disable-setuid-sandbox',
  2223. '--disable-blink-features=AutomationControlled',
  2224. '--window-size=1280,800'
  2225. ],
  2226. });
  2227. const page = await this.loginBrowser.newPage();
  2228. await page.setViewport({ width: 1280, height: 800 });
  2229. let testUrl = "https://www.xiaohongshu.com";
  2230. await page.goto(testUrl, {waitUntil : 'networkidle2'});
  2231. let loginBtn = await page.$$('#login-btn');
  2232. let loginContainer = await page.$$('.login-container');
  2233. if(loginContainer.length > 0 || loginBtn.length > 0){
  2234. this.redStatus = 3; //未登录
  2235. }else{
  2236. this.redStatus = 2;
  2237. }
  2238. resolve(this.redStatus);
  2239. this.checkLoading = false;
  2240. await this.loginBrowser.close();
  2241. this.loginBrowser = null;
  2242. }catch(e){
  2243. this.checkLoading = false;
  2244. reject(3);
  2245. this.showError(e);
  2246. }
  2247. })();
  2248. });
  2249. },
  2250. // 5-小红书下载
  2251. async redDownload(urlInfo, redBrowser){
  2252. let task = await new Promise((resolve,reject) =>{
  2253. (async () => {
  2254. try{
  2255. let authority = this.$refs.headerRef.authority.isAuthority;
  2256. let number = 0;
  2257. urlInfo.status = '2';
  2258. urlInfo.num = 0;
  2259. const page = await redBrowser.newPage();
  2260. let responseVideo = [];
  2261. page.on('response', async(response) => {
  2262. // 检查响应的 MIME 类型是否以 'video/' 开头
  2263. if (response.headers()['content-type'] && response.headers()['content-type'].startsWith('video/')) {
  2264. if(responseVideo.indexOf(response.url()) < 0 && !response.url().startsWith('blob:https://')){
  2265. responseVideo.push(response.url());
  2266. }
  2267. }
  2268. });
  2269. await page.goto(urlInfo.url, {waitUntil : 'networkidle2'});
  2270. if(urlInfo.title){
  2271. if (fs.existsSync(this.downloadDir + separator + pjson.softInfo.softName + separator + urlInfo.title)) {
  2272. urlInfo.newPath = this.downloadDir + separator + pjson.softInfo.softName + separator + urlInfo.title;
  2273. } else {
  2274. fs.mkdirSync(this.downloadDir + separator + pjson.softInfo.softName + separator + urlInfo.title);
  2275. urlInfo.newPath = this.downloadDir + separator + pjson.softInfo.softName + separator + urlInfo.title;
  2276. }
  2277. }else{
  2278. await this.getTitle(page, urlInfo); // 生成页面标题对应的文件夹
  2279. }
  2280. urlInfo.status = '3';
  2281. // 定位元素
  2282. const handle = await page.$$('.pagination-media-container .pagination-item');
  2283. if(handle.length > 0){ // 模拟鼠标拖动 将鼠标移动到元素的中心,然后开始拖动
  2284. let handleLength = handle.length;
  2285. const box = await handle[0].boundingBox();
  2286. const boxEnd = await handle[handleLength - 1].boundingBox();
  2287. const center = {
  2288. x: box.x + box.width / 2,
  2289. y: box.y + box.height / 2
  2290. };
  2291. const centerEnd = {
  2292. x: boxEnd.x + boxEnd.width / 2,
  2293. y: boxEnd.y + boxEnd.height / 2
  2294. };
  2295. await page.mouse.move(center.x, center.y);
  2296. await page.mouse.down();
  2297. await page.mouse.move(centerEnd.x, centerEnd.y, { steps: 50 }); // 新的位置,可以根据需要调整步骤数
  2298. }
  2299. //detailImg:详情图;skuImg:sku图片;commentImg: 评论图;video: 视频
  2300. const imgInfo = await page.evaluate((authority, execNum) => {
  2301. let outObj = {
  2302. mainImg: [],
  2303. detailImg: [],
  2304. skuImg: [],
  2305. commentImg: [],
  2306. video: []
  2307. };
  2308. // 正则表达式匹配字符 重写图片路径
  2309. let regex = /\.(.{3,4})_[0-9a-zA-z]+\.(.{3,4})_\.(.{3,4})/;
  2310. //主图
  2311. let arr1 = document.querySelectorAll('img[class^=note-slider-img]');
  2312. for(let i=0; i< arr1.length; i++){
  2313. let mainImgUrl = arr1[i].src;
  2314. let result = regex.exec(mainImgUrl);
  2315. if(result){
  2316. mainImgUrl = mainImgUrl.replace(result[0], '.'+result[1]);
  2317. }
  2318. if(!authority && i < execNum){
  2319. outObj.mainImg.push(mainImgUrl);
  2320. }
  2321. if(authority){
  2322. outObj.mainImg.push(mainImgUrl);
  2323. }
  2324. }
  2325. // 视频
  2326. let arr5 = document.querySelectorAll('video.lib-video');
  2327. for(let i=0; i< arr5.length; i++){
  2328. if(outObj.video.indexOf(arr5[i].src) == -1){
  2329. if(!authority && i < execNum){
  2330. outObj.video.push(arr5[i].src);
  2331. }
  2332. if(authority){
  2333. outObj.video.push(arr5[i].src);
  2334. }
  2335. }
  2336. }
  2337. return outObj;
  2338. }, authority, this.execNum);
  2339. if(imgInfo.mainImg.length >= 3 && authority){
  2340. imgInfo.mainImg = imgInfo.mainImg.slice(1, imgInfo.mainImg.length-1); //小红书轮播图第一个/最后一个和内容重复去掉
  2341. }
  2342. imgInfo.video = responseVideo;
  2343. if(this.settingArr.indexOf('mainImg') > -1){
  2344. // 主图下载
  2345. for(let j = 0; j < imgInfo.mainImg.length; j++){
  2346. let fileName = imgInfo.mainImg[j].split('/').pop();
  2347. if(fileName){
  2348. let queryIndex = fileName.indexOf('?');
  2349. if (queryIndex !== -1) {
  2350. fileName = fileName.substr(0, queryIndex);
  2351. }
  2352. let num = Number(j) + 1;
  2353. let suffix = '.jpg';
  2354. if(fileName.lastIndexOf('.') > -1){
  2355. suffix = fileName.substr(fileName.lastIndexOf('.'));
  2356. }
  2357. let outputPath = urlInfo.newPath + '\\文章图' + num + suffix;
  2358. await this.downloadImage(imgInfo.mainImg[j], outputPath, urlInfo);
  2359. }
  2360. }
  2361. }
  2362. if(this.settingArr.indexOf('video') > -1){
  2363. //视频下载
  2364. for(let j = 0; j < imgInfo.video.length; j++){
  2365. let fileName = imgInfo.video[j].split('/').pop();
  2366. if(fileName){
  2367. let queryIndex = fileName.indexOf('?');
  2368. if (queryIndex !== -1) {
  2369. fileName = fileName.substr(0, queryIndex);
  2370. }
  2371. let num = Number(j) + 1;
  2372. let suffix = '.mp4';
  2373. if(fileName.lastIndexOf('.') > -1){
  2374. suffix = fileName.substr(fileName.lastIndexOf('.'));
  2375. }
  2376. let outputPath = urlInfo.newPath + '\\视频' + num + suffix;
  2377. await this.downloadImage(imgInfo.video[j], outputPath, urlInfo);
  2378. }
  2379. }
  2380. }
  2381. await page.close();
  2382. urlInfo.status = '4';
  2383. resolve(true);
  2384. this.loading = false;
  2385. }catch(e){
  2386. urlInfo.status = '5';
  2387. reject(e);
  2388. this.showError(e);
  2389. }
  2390. })();
  2391. });
  2392. },
  2393. /**************************阿里国际商品图片下载*******************************************************************************************/
  2394. // 6 - 阿里国际 - 扫描并下载图片
  2395. async aliguojiScanImg(browser, page, urlInfo, authority){
  2396. //detailImg:详情图;skuImg:sku图片;commentImg: 评论图;video: 视频
  2397. const imgInfo = await page.evaluate((authority, execNum) => {
  2398. let outObj = {
  2399. mainImg: [],
  2400. detailImg: [],
  2401. skuImg: [],
  2402. commentImg: [],
  2403. video: []
  2404. };
  2405. //主图
  2406. let arr1 = document.querySelectorAll('.module_productImage img[class*="-object-contain"]');
  2407. for(let i=0; i< arr1.length; i++){
  2408. if(!authority && i < execNum){
  2409. outObj.mainImg.push(arr1[i].src);
  2410. }
  2411. if(authority){
  2412. outObj.mainImg.push(arr1[i].src);
  2413. }
  2414. }
  2415. //sku图片
  2416. let arr2 = document.querySelectorAll('.module_sku img[class*="-object-contain"]');
  2417. for(let i=0; i< arr2.length; i++){
  2418. if(!authority && i < execNum){
  2419. outObj.skuImg.push(arr2[i].src);
  2420. }
  2421. if(authority){
  2422. outObj.skuImg.push(arr2[i].src);
  2423. }
  2424. }
  2425. //详情图片
  2426. let arr3 = document.querySelectorAll('#description-layout img');
  2427. // if(arr3.length == 0){
  2428. // if(document.getElementById('description') && document.getElementById('description').querySelector('.html-description')){
  2429. // arr3 = document.getElementById('description').querySelector('.html-description').shadowRoot.querySelectorAll('img');
  2430. // }
  2431. // }
  2432. if(arr3.length == 0){
  2433. if(document.querySelector('#description-layout').querySelector('iframe')){
  2434. arr3 = document.querySelector('#description-layout').querySelector('iframe').contentDocument.querySelectorAll('img')
  2435. }
  2436. }
  2437. for(let i=0; i< arr3.length; i++){
  2438. if(!authority && i < execNum){
  2439. outObj.detailImg.push(arr3[i].src);
  2440. }
  2441. if(authority){
  2442. outObj.detailImg.push(arr3[i].src);
  2443. }
  2444. }
  2445. // 视频
  2446. let arr5 = document.querySelectorAll('video');
  2447. for(let i=0; i< arr5.length; i++){
  2448. if(arr5[i].src && outObj.video.indexOf(arr5[i].src) == -1){
  2449. if(!authority && i < execNum){
  2450. outObj.video.push(arr5[i].src);
  2451. }
  2452. if(authority){
  2453. outObj.video.push(arr5[i].src);
  2454. }
  2455. }
  2456. }
  2457. return outObj;
  2458. }, authority, this.execNum);
  2459. // 主图下载
  2460. if(this.settingArr.indexOf('mainImg') > -1){
  2461. for(let j = 0; j < imgInfo.mainImg.length; j++){
  2462. let fileName = imgInfo.mainImg[j].split('/').pop();
  2463. if(fileName){
  2464. let queryIndex = fileName.indexOf('?');
  2465. if (queryIndex !== -1) {
  2466. fileName = fileName.substr(0, queryIndex);
  2467. }
  2468. let num = Number(j) + 1;
  2469. let suffix = '';
  2470. if(fileName.lastIndexOf('.') > -1){
  2471. suffix = fileName.substr(fileName.lastIndexOf('.'));
  2472. }
  2473. if (!fs.existsSync(urlInfo.newPath + '\\主图')) {
  2474. fs.mkdirSync(urlInfo.newPath + '\\主图');
  2475. }
  2476. let outputPath = urlInfo.newPath + '\\主图\\主图' + num + suffix;
  2477. await this.downloadImage(imgInfo.mainImg[j], outputPath, urlInfo);
  2478. }
  2479. }
  2480. }
  2481. // sku图片下载
  2482. if(this.settingArr.indexOf('skuImg') > -1){
  2483. for(let j = 0; j < imgInfo.skuImg.length; j++){
  2484. let fileName = imgInfo.skuImg[j].split('/').pop();
  2485. if(fileName){
  2486. let queryIndex = fileName.indexOf('?');
  2487. if (queryIndex !== -1) {
  2488. fileName = fileName.substr(0, queryIndex);
  2489. }
  2490. let num = Number(j) + 1;
  2491. let suffix = '';
  2492. if(fileName.lastIndexOf('.') > -1){
  2493. suffix = fileName.substr(fileName.lastIndexOf('.'));
  2494. }
  2495. if (!fs.existsSync(urlInfo.newPath + '\\sku图')) {
  2496. fs.mkdirSync(urlInfo.newPath + '\\sku图');
  2497. }
  2498. let outputPath = urlInfo.newPath + '\\sku图\\sku图' + num + suffix;
  2499. await this.downloadImage(imgInfo.skuImg[j], outputPath, urlInfo);
  2500. }
  2501. }
  2502. }
  2503. //详情图下载
  2504. if(this.settingArr.indexOf('detailImg') > -1){
  2505. for(let j = 0; j < imgInfo.detailImg.length; j++){
  2506. let fileName = imgInfo.detailImg[j].split('/').pop();
  2507. if(fileName){
  2508. let queryIndex = fileName.indexOf('?');
  2509. if (queryIndex !== -1) {
  2510. fileName = fileName.substr(0, queryIndex);
  2511. }
  2512. let num = Number(j) + 1;
  2513. let suffix = '';
  2514. if(fileName.lastIndexOf('.') > -1){
  2515. suffix = fileName.substr(fileName.lastIndexOf('.'));
  2516. }
  2517. if (!fs.existsSync(urlInfo.newPath + '\\详情图')) {
  2518. fs.mkdirSync(urlInfo.newPath + '\\详情图');
  2519. }
  2520. let outputPath = urlInfo.newPath + '\\详情图\\' + '详情图' + num + suffix;
  2521. await this.downloadImage(imgInfo.detailImg[j], outputPath, urlInfo);
  2522. }
  2523. }
  2524. }
  2525. //视频下载
  2526. if(this.settingArr.indexOf('video') > -1){
  2527. for(let j = 0; j < imgInfo.video.length; j++){
  2528. let fileName = imgInfo.video[j].split('/').pop();
  2529. if(fileName){
  2530. let queryIndex = fileName.indexOf('?');
  2531. if (queryIndex !== -1) {
  2532. fileName = fileName.substr(0, queryIndex);
  2533. }
  2534. if (!fs.existsSync(urlInfo.newPath + '\\视频')) {
  2535. fs.mkdirSync(urlInfo.newPath + '\\视频');
  2536. }
  2537. let outputPath = urlInfo.newPath + '\\视频\\' + fileName;
  2538. await this.downloadImage(imgInfo.video[j], outputPath, urlInfo);
  2539. }
  2540. }
  2541. }
  2542. await page.close(); // 关闭页面但不关闭浏览器
  2543. },
  2544. /*********************************************************************************************************************/
  2545. /**************************百度爱采购商品图片下载*******************************************************************************************/
  2546. // 7 - 百度爱采购 - 扫描并下载图片
  2547. async acaigouScanImg(browser, page, urlInfo, authority){
  2548. //detailImg:详情图;skuImg:sku图片;commentImg: 评论图;video: 视频
  2549. const imgInfo = await page.evaluate((authority, execNum) => {
  2550. let outObj = {
  2551. mainImg: [],
  2552. detailImg: [],
  2553. skuImg: [],
  2554. commentImg: [],
  2555. video: []
  2556. };
  2557. //主图
  2558. let arr1 = document.querySelectorAll('.album .img-container .img');
  2559. for(let i=0; i< arr1.length; i++){
  2560. let src = window.getComputedStyle(arr1[i]).backgroundImage.replace(/url\(["']?(.+?)["']?\)/i, '$1');
  2561. if(src && outObj.mainImg.indexOf(src) == -1){
  2562. if(!authority && i < execNum){
  2563. outObj.mainImg.push(src);
  2564. }
  2565. if(authority){
  2566. outObj.mainImg.push(src);
  2567. }
  2568. }
  2569. }
  2570. //sku图片
  2571. // let arr2 = document.querySelectorAll('.module_sku img[class*="-object-contain"]');
  2572. // for(let i=0; i< arr2.length; i++){
  2573. // if(!authority && i < execNum){
  2574. // outObj.skuImg.push(arr2[i].src);
  2575. // }
  2576. // if(authority){
  2577. // outObj.skuImg.push(arr2[i].src);
  2578. // }
  2579. // }
  2580. //详情图片
  2581. let arr3 = document.querySelectorAll('.details .questionable-detail img');
  2582. for(let i=0; i< arr3.length; i++){
  2583. if(!authority && i < execNum){
  2584. outObj.detailImg.push(arr3[i].src);
  2585. }
  2586. if(authority){
  2587. outObj.detailImg.push(arr3[i].src);
  2588. }
  2589. }
  2590. // 视频
  2591. let arr5 = document.querySelectorAll('.album video');
  2592. for(let i=0; i< arr5.length; i++){
  2593. if(arr5[i].src && outObj.video.indexOf(arr5[i].src) == -1){
  2594. if(!authority && i < execNum){
  2595. outObj.video.push(arr5[i].src);
  2596. }
  2597. if(authority){
  2598. outObj.video.push(arr5[i].src);
  2599. }
  2600. }
  2601. }
  2602. return outObj;
  2603. }, authority, this.execNum);
  2604. // 主图下载
  2605. if(this.settingArr.indexOf('mainImg') > -1){
  2606. for(let j = 0; j < imgInfo.mainImg.length; j++){
  2607. let fileName = imgInfo.mainImg[j].split('/').pop();
  2608. if(fileName){
  2609. let queryIndex = fileName.indexOf('?');
  2610. if (queryIndex !== -1) {
  2611. fileName = fileName.substr(0, queryIndex);
  2612. }
  2613. let num = Number(j) + 1;
  2614. let suffix = '.webp';
  2615. if(fileName.lastIndexOf('.') > -1){
  2616. suffix = fileName.substr(fileName.lastIndexOf('.'));
  2617. }
  2618. if (!fs.existsSync(urlInfo.newPath + '\\主图')) {
  2619. fs.mkdirSync(urlInfo.newPath + '\\主图');
  2620. }
  2621. let outputPath = urlInfo.newPath + '\\主图\\主图' + num + suffix;
  2622. await this.downloadImage(imgInfo.mainImg[j], outputPath, urlInfo);
  2623. }
  2624. }
  2625. }
  2626. // sku图片下载
  2627. if(this.settingArr.indexOf('skuImg') > -1){
  2628. for(let j = 0; j < imgInfo.skuImg.length; j++){
  2629. let fileName = imgInfo.skuImg[j].split('/').pop();
  2630. if(fileName){
  2631. let queryIndex = fileName.indexOf('?');
  2632. if (queryIndex !== -1) {
  2633. fileName = fileName.substr(0, queryIndex);
  2634. }
  2635. let num = Number(j) + 1;
  2636. let suffix = '';
  2637. if(fileName.lastIndexOf('.') > -1){
  2638. suffix = fileName.substr(fileName.lastIndexOf('.'));
  2639. }
  2640. if (!fs.existsSync(urlInfo.newPath + '\\sku图')) {
  2641. fs.mkdirSync(urlInfo.newPath + '\\sku图');
  2642. }
  2643. let outputPath = urlInfo.newPath + '\\sku图\\sku图' + num + suffix;
  2644. await this.downloadImage(imgInfo.skuImg[j], outputPath, urlInfo);
  2645. }
  2646. }
  2647. }
  2648. //详情图下载
  2649. if(this.settingArr.indexOf('detailImg') > -1){
  2650. for(let j = 0; j < imgInfo.detailImg.length; j++){
  2651. let fileName = imgInfo.detailImg[j].split('/').pop();
  2652. if(fileName){
  2653. let queryIndex = fileName.indexOf('?');
  2654. if (queryIndex !== -1) {
  2655. fileName = fileName.substr(0, queryIndex);
  2656. }
  2657. let num = Number(j) + 1;
  2658. let suffix = '.webp';
  2659. if(fileName.lastIndexOf('.') > -1){
  2660. suffix = fileName.substr(fileName.lastIndexOf('.'));
  2661. }
  2662. if (!fs.existsSync(urlInfo.newPath + '\\详情图')) {
  2663. fs.mkdirSync(urlInfo.newPath + '\\详情图');
  2664. }
  2665. let outputPath = urlInfo.newPath + '\\详情图\\' + '详情图' + num + suffix;
  2666. await this.downloadImage(imgInfo.detailImg[j], outputPath, urlInfo);
  2667. }
  2668. }
  2669. }
  2670. //视频下载
  2671. if(this.settingArr.indexOf('video') > -1){
  2672. for(let j = 0; j < imgInfo.video.length; j++){
  2673. let fileName = imgInfo.video[j].split('/').pop();
  2674. if(fileName){
  2675. let queryIndex = fileName.indexOf('?');
  2676. if (queryIndex !== -1) {
  2677. fileName = fileName.substr(0, queryIndex);
  2678. }
  2679. if (!fs.existsSync(urlInfo.newPath + '\\视频')) {
  2680. fs.mkdirSync(urlInfo.newPath + '\\视频');
  2681. }
  2682. let outputPath = urlInfo.newPath + '\\视频\\' + fileName;
  2683. await this.downloadImage(imgInfo.video[j], outputPath, urlInfo);
  2684. }
  2685. }
  2686. }
  2687. await page.close(); // 关闭页面但不关闭浏览器
  2688. },
  2689. /*********************************************************************************************************************/
  2690. /**************************亚马逊商品图片下载*******************************************************************************************/
  2691. // 8 - 亚马逊 - 扫描并下载图片
  2692. async amazonScanImg(browser, page, urlInfo, authority){
  2693. //detailImg:详情图;skuImg:sku图片;commentImg: 评论图;video: 视频
  2694. const imgInfo = await page.evaluate((authority, execNum) => {
  2695. let outObj = {
  2696. mainImg: [],
  2697. detailImg: [],
  2698. skuImg: [],
  2699. commentImg: [],
  2700. video: []
  2701. };
  2702. //主图
  2703. let arr1 = document.querySelectorAll('#leftCol img.a-dynamic-image');
  2704. for(let i=0; i< arr1.length; i++){
  2705. if(!authority && i < execNum){
  2706. outObj.mainImg.push(arr1[i].src);
  2707. }
  2708. if(authority){
  2709. outObj.mainImg.push(arr1[i].src);
  2710. }
  2711. }
  2712. //sku图片
  2713. let arr2 = document.querySelectorAll('.module_sku img[class*="-object-contain"]');
  2714. for(let i=0; i< arr2.length; i++){
  2715. if(!authority && i < execNum){
  2716. outObj.skuImg.push(arr2[i].src);
  2717. }
  2718. if(authority){
  2719. outObj.skuImg.push(arr2[i].src);
  2720. }
  2721. }
  2722. //详情图片
  2723. let arr3 = document.querySelectorAll('#description-layout img');
  2724. // if(arr3.length == 0){
  2725. // if(document.getElementById('description') && document.getElementById('description').querySelector('.html-description')){
  2726. // arr3 = document.getElementById('description').querySelector('.html-description').shadowRoot.querySelectorAll('img');
  2727. // }
  2728. // }
  2729. for(let i=0; i< arr3.length; i++){
  2730. if(!authority && i < execNum){
  2731. outObj.detailImg.push(arr3[i].src);
  2732. }
  2733. if(authority){
  2734. outObj.detailImg.push(arr3[i].src);
  2735. }
  2736. }
  2737. // 视频
  2738. let arr5 = document.querySelectorAll('#description-layout video');
  2739. for(let i=0; i< arr5.length; i++){
  2740. if(arr5[i].src && outObj.video.indexOf(arr5[i].src) == -1){
  2741. if(!authority && i < execNum){
  2742. outObj.video.push(arr5[i].src);
  2743. }
  2744. if(authority){
  2745. outObj.video.push(arr5[i].src);
  2746. }
  2747. }
  2748. }
  2749. return outObj;
  2750. }, authority, this.execNum);
  2751. // 主图下载
  2752. if(this.settingArr.indexOf('mainImg') > -1){
  2753. for(let j = 0; j < imgInfo.mainImg.length; j++){
  2754. let fileName = imgInfo.mainImg[j].split('/').pop();
  2755. if(fileName){
  2756. let queryIndex = fileName.indexOf('?');
  2757. if (queryIndex !== -1) {
  2758. fileName = fileName.substr(0, queryIndex);
  2759. }
  2760. let num = Number(j) + 1;
  2761. let suffix = '';
  2762. if(fileName.lastIndexOf('.') > -1){
  2763. suffix = fileName.substr(fileName.lastIndexOf('.'));
  2764. }
  2765. if (!fs.existsSync(urlInfo.newPath + '\\主图')) {
  2766. fs.mkdirSync(urlInfo.newPath + '\\主图');
  2767. }
  2768. let outputPath = urlInfo.newPath + '\\主图\\主图' + num + suffix;
  2769. await this.downloadImage(imgInfo.mainImg[j], outputPath, urlInfo);
  2770. }
  2771. }
  2772. }
  2773. // sku图片下载
  2774. if(this.settingArr.indexOf('skuImg') > -1){
  2775. for(let j = 0; j < imgInfo.skuImg.length; j++){
  2776. let fileName = imgInfo.skuImg[j].split('/').pop();
  2777. if(fileName){
  2778. let queryIndex = fileName.indexOf('?');
  2779. if (queryIndex !== -1) {
  2780. fileName = fileName.substr(0, queryIndex);
  2781. }
  2782. let num = Number(j) + 1;
  2783. let suffix = '';
  2784. if(fileName.lastIndexOf('.') > -1){
  2785. suffix = fileName.substr(fileName.lastIndexOf('.'));
  2786. }
  2787. if (!fs.existsSync(urlInfo.newPath + '\\sku图')) {
  2788. fs.mkdirSync(urlInfo.newPath + '\\sku图');
  2789. }
  2790. let outputPath = urlInfo.newPath + '\\sku图\\sku图' + num + suffix;
  2791. await this.downloadImage(imgInfo.skuImg[j], outputPath, urlInfo);
  2792. }
  2793. }
  2794. }
  2795. //详情图下载
  2796. if(this.settingArr.indexOf('detailImg') > -1){
  2797. for(let j = 0; j < imgInfo.detailImg.length; j++){
  2798. let fileName = imgInfo.detailImg[j].split('/').pop();
  2799. if(fileName){
  2800. let queryIndex = fileName.indexOf('?');
  2801. if (queryIndex !== -1) {
  2802. fileName = fileName.substr(0, queryIndex);
  2803. }
  2804. let num = Number(j) + 1;
  2805. let suffix = '';
  2806. if(fileName.lastIndexOf('.') > -1){
  2807. suffix = fileName.substr(fileName.lastIndexOf('.'));
  2808. }
  2809. if (!fs.existsSync(urlInfo.newPath + '\\详情图')) {
  2810. fs.mkdirSync(urlInfo.newPath + '\\详情图');
  2811. }
  2812. let outputPath = urlInfo.newPath + '\\详情图\\' + '详情图' + num + suffix;
  2813. await this.downloadImage(imgInfo.detailImg[j], outputPath, urlInfo);
  2814. }
  2815. }
  2816. }
  2817. //视频下载
  2818. if(this.settingArr.indexOf('video') > -1){
  2819. for(let j = 0; j < imgInfo.video.length; j++){
  2820. let fileName = imgInfo.video[j].split('/').pop();
  2821. if(fileName){
  2822. let queryIndex = fileName.indexOf('?');
  2823. if (queryIndex !== -1) {
  2824. fileName = fileName.substr(0, queryIndex);
  2825. }
  2826. if (!fs.existsSync(urlInfo.newPath + '\\视频')) {
  2827. fs.mkdirSync(urlInfo.newPath + '\\视频');
  2828. }
  2829. let outputPath = urlInfo.newPath + '\\视频\\' + fileName;
  2830. await this.downloadImage(imgInfo.video[j], outputPath, urlInfo);
  2831. }
  2832. }
  2833. }
  2834. await page.close(); // 关闭页面但不关闭浏览器
  2835. },
  2836. /*********************************************************************************************************************/
  2837. /***********拼多多商品下载**********/
  2838. // 检查pdd登录状态
  2839. checkPddLogin(){
  2840. this.checkLoading = true;
  2841. this.pddStatus = 1;
  2842. return new Promise((resolve, reject) => {
  2843. (async () => {
  2844. try{
  2845. if(this.loginBrowser){
  2846. await this.loginBrowser.close();
  2847. this.loginBrowser = null;
  2848. }
  2849. puppeteer.use(StealthPlugin());
  2850. this.loginBrowser = await puppeteer.launch({
  2851. executablePath: this.initPath(),
  2852. userDataDir: this.initDataDir(),
  2853. args: [
  2854. '--start-maximized',
  2855. '--no-sandbox',
  2856. '--disable-setuid-sandbox',
  2857. '--disable-blink-features=AutomationControlled',
  2858. '--window-size=1280,800'
  2859. ],
  2860. });
  2861. const page = await this.loginBrowser.newPage();
  2862. await page.setViewport({ width: 1280, height: 800 });
  2863. let testUrl = "https://mobile.yangkeduo.com/personal.html";
  2864. await page.goto(testUrl, {waitUntil : 'networkidle2'});
  2865. let loginBtn = await page.$('.login-box');
  2866. if(loginBtn){
  2867. let searchValue = await page.$eval('.login-box', el => el.innerText);
  2868. if(searchValue == '手机登录' || searchValue.indexOf('登录') > -1){
  2869. this.pddStatus = 3; //未登录
  2870. }else{
  2871. this.pddStatus = 2;
  2872. }
  2873. }else{
  2874. this.pddStatus = 2;
  2875. }
  2876. resolve(this.pddStatus);
  2877. this.checkLoading = false;
  2878. await this.loginBrowser.close();
  2879. this.loginBrowser = null;
  2880. }catch(e){
  2881. this.checkLoading = false;
  2882. reject(3);
  2883. this.showError(e);
  2884. }
  2885. })();
  2886. });
  2887. },
  2888. // 9-pdd图片下载
  2889. async pddDownload(urlInfo, pddBrowser){
  2890. let task = await new Promise((resolve,reject) =>{
  2891. (async () => {
  2892. try{
  2893. let authority = this.$refs.headerRef.authority.isAuthority;
  2894. let number = 0;
  2895. urlInfo.status = '2';
  2896. urlInfo.num = 0;
  2897. const page = await pddBrowser.newPage();
  2898. await page.goto(urlInfo.url, {waitUntil : 'networkidle2'});
  2899. if(urlInfo.title){
  2900. if (fs.existsSync(this.downloadDir + separator + pjson.softInfo.softName + separator + urlInfo.title)) {
  2901. urlInfo.newPath = this.downloadDir + separator + pjson.softInfo.softName + separator + urlInfo.title;
  2902. } else {
  2903. fs.mkdirSync(this.downloadDir + separator + pjson.softInfo.softName + separator + urlInfo.title);
  2904. urlInfo.newPath = this.downloadDir + separator + pjson.softInfo.softName + separator + urlInfo.title;
  2905. }
  2906. }else{
  2907. // 获取商品标题
  2908. let titleHandle = await page.$$('span.enable-select');
  2909. if(titleHandle && titleHandle.length > 0){
  2910. let titleValue = await page.$eval('span.enable-select', el => el.innerText);
  2911. await this.getTitle(page, urlInfo, titleValue); // 生成页面标题对应的文件夹
  2912. }else{
  2913. await this.getTitle(page, urlInfo, '拼多多商品-'+new Date().getTime()); // 生成页面标题对应的文件夹
  2914. }
  2915. }
  2916. urlInfo.status = '3';
  2917. // 被平台限制浏览
  2918. let notSale = await page.$$('.not-sale');
  2919. if(notSale && notSale.length > 0){
  2920. let notValue = await page.$eval('.not-sale', el => el.innerText);
  2921. if(notValue.indexOf('商品已售罄') > -1 || notValue.indexOf('推荐以下') > -1){
  2922. await page.close();
  2923. urlInfo.status = '7';
  2924. resolve(true);
  2925. this.loading = false;
  2926. return false;
  2927. }
  2928. }
  2929. //detailImg:详情图;skuImg:sku图片;commentImg: 评论图;video: 视频
  2930. const imgInfo = await page.evaluate((authority, execNum) => {
  2931. let outObj = {
  2932. mainImg: [],
  2933. detailImg: [],
  2934. skuImg: [],
  2935. commentImg: [],
  2936. video: [],
  2937. skuName: []
  2938. };
  2939. let skuHandle = document.querySelector('div[class*=sku-plus] img');
  2940. if(skuHandle){
  2941. skuHandle.click({force: true});
  2942. }
  2943. //主图
  2944. let mainDiv = document.querySelectorAll('#main > div > div')[0];
  2945. let arr1 = mainDiv.querySelectorAll('img');
  2946. for(let i=0; i< arr1.length; i++){
  2947. if(i > 0 && i < arr1.length-1){ // 去掉首尾重复
  2948. let mainImgUrl = arr1[i].src || arr1[i].dataset.src;
  2949. if(!authority && i < execNum){
  2950. outObj.mainImg.push(mainImgUrl);
  2951. }
  2952. if(authority){
  2953. outObj.mainImg.push(mainImgUrl);
  2954. }
  2955. }
  2956. }
  2957. //sku
  2958. let arr2 = document.querySelectorAll('#skuImageSlider img');
  2959. for(let i=0; i< arr2.length; i++){
  2960. if(i > 0 && i < arr2.length-1){ // 去掉首尾重复 -去掉重复图片
  2961. let skuImgUrl = arr2[i].src || arr2[i].dataset.src;
  2962. if(outObj.skuImg.indexOf(skuImgUrl) == -1){
  2963. let nextEle = arr2[i].parentElement.nextElementSibling;
  2964. let num = Number(i) + 1;
  2965. let name = 'sku图' + num + '.jpeg';
  2966. if(nextEle){
  2967. name = nextEle.innerText.split('\n')[0];
  2968. name = name.replace(/[\\|/|:|*|?|"|<|>||]/g, "");
  2969. }
  2970. if(!authority && i < execNum){
  2971. outObj.skuImg.push(skuImgUrl);
  2972. outObj.skuName.push(name);
  2973. }
  2974. if(authority){
  2975. outObj.skuImg.push(skuImgUrl);
  2976. outObj.skuName.push(name);
  2977. }
  2978. }
  2979. }
  2980. }
  2981. //详情图
  2982. let arr3 = document.querySelectorAll('img[class*=pdd-lazy-image][aria-label="查看图片"]');
  2983. if(arr3.length == 0){
  2984. arr3 = [];
  2985. let imgArr = document.querySelectorAll('img[class*=pdd-lazy-image]');
  2986. for(let m = 0; m < imgArr.length; m++){
  2987. if(imgArr[m].parentElement.ariaLabel == '点击查看大图'){
  2988. arr3.push(imgArr[m]);
  2989. }
  2990. }
  2991. }
  2992. for(let i=0; i< arr3.length; i++){
  2993. let detailImgUrl = arr3[i].src || arr3[i].dataset.src;
  2994. if(!authority && i < execNum){
  2995. outObj.detailImg.push(detailImgUrl);
  2996. }
  2997. if(authority){
  2998. outObj.detailImg.push(detailImgUrl);
  2999. }
  3000. }
  3001. // 视频
  3002. let arr5 = document.querySelectorAll('video');
  3003. for(let i=0; i< arr5.length; i++){
  3004. if(outObj.video.indexOf(arr5[i].src) == -1){
  3005. if(!authority && i < execNum){
  3006. outObj.video.push(arr5[i].src);
  3007. }
  3008. if(authority){
  3009. outObj.video.push(arr5[i].src);
  3010. }
  3011. }
  3012. }
  3013. return outObj;
  3014. }, authority, this.execNum);
  3015. // 主图下载
  3016. if(this.settingArr.indexOf('mainImg') > -1){
  3017. for(let j = 0; j < imgInfo.mainImg.length; j++){
  3018. let imgUrl = imgInfo.mainImg[j];
  3019. let queryIndex = imgInfo.mainImg[j].indexOf('?');
  3020. if (queryIndex !== -1) {
  3021. imgUrl = imgUrl.substr(0, queryIndex);
  3022. }
  3023. let fileName = imgUrl.split('/').pop();
  3024. let num = Number(j) + 1;
  3025. let suffix = '.jpg';
  3026. if(fileName.lastIndexOf('.') > -1){
  3027. suffix = fileName.substr(fileName.lastIndexOf('.'));
  3028. }
  3029. if (!fs.existsSync(urlInfo.newPath + '\\主图')) {
  3030. fs.mkdirSync(urlInfo.newPath + '\\主图');
  3031. }
  3032. let outputPath = urlInfo.newPath + '\\主图\\主图' + num + suffix;
  3033. await this.downloadImage(imgInfo.mainImg[j], outputPath, urlInfo);
  3034. }
  3035. }
  3036. // sku图片下载
  3037. if(this.settingArr.indexOf('skuImg') > -1){
  3038. for(let j = 0; j < imgInfo.skuImg.length; j++){
  3039. let imgUrl = imgInfo.skuImg[j];
  3040. let queryIndex = imgInfo.skuImg[j].indexOf('?');
  3041. if (queryIndex !== -1) {
  3042. imgUrl = imgUrl.substr(0, queryIndex);
  3043. }
  3044. let fileName = imgUrl.split('/').pop();
  3045. let num = Number(j) + 1;
  3046. let suffix = '.jpg';
  3047. if(fileName.lastIndexOf('.') > -1){
  3048. suffix = fileName.substr(fileName.lastIndexOf('.'));
  3049. }
  3050. if (!fs.existsSync(urlInfo.newPath + '\\sku图')) {
  3051. fs.mkdirSync(urlInfo.newPath + '\\sku图');
  3052. }
  3053. let outputPath = urlInfo.newPath + '\\sku图\\' + imgInfo.skuName[j] + suffix;
  3054. await this.downloadImage(imgInfo.skuImg[j], outputPath, urlInfo);
  3055. }
  3056. }
  3057. //详情图下载
  3058. if(this.settingArr.indexOf('detailImg') > -1){
  3059. for(let j = 0; j < imgInfo.detailImg.length; j++){
  3060. let imgUrl = imgInfo.detailImg[j];
  3061. let queryIndex = imgInfo.detailImg[j].indexOf('?');
  3062. if (queryIndex !== -1) {
  3063. imgUrl = imgUrl.substr(0, queryIndex);
  3064. }
  3065. let fileName = imgUrl.split('/').pop();
  3066. let num = Number(j) + 1;
  3067. let suffix = '.jpg';
  3068. if(fileName.lastIndexOf('.') > -1){
  3069. suffix = fileName.substr(fileName.lastIndexOf('.'));
  3070. }
  3071. if (!fs.existsSync(urlInfo.newPath + '\\详情图')) {
  3072. fs.mkdirSync(urlInfo.newPath + '\\详情图');
  3073. }
  3074. let outputPath = urlInfo.newPath + '\\详情图\\详情图' + num + suffix;
  3075. await this.downloadImage(imgInfo.detailImg[j], outputPath, urlInfo);
  3076. }
  3077. }
  3078. //视频下载
  3079. if(this.settingArr.indexOf('video') > -1){
  3080. for(let j = 0; j < imgInfo.video.length; j++){
  3081. let fileName = imgInfo.video[j].split('/').pop();
  3082. if(fileName){
  3083. let queryIndex = fileName.indexOf('?');
  3084. if (queryIndex !== -1) {
  3085. fileName = fileName.substr(0, queryIndex);
  3086. }
  3087. if (!fs.existsSync(urlInfo.newPath + '\\视频')) {
  3088. fs.mkdirSync(urlInfo.newPath + '\\视频');
  3089. }
  3090. let outputPath = urlInfo.newPath + '\\视频\\' + fileName;
  3091. await this.downloadImage(imgInfo.video[j], outputPath, urlInfo);
  3092. }
  3093. }
  3094. }
  3095. await page.close();
  3096. urlInfo.status = '4';
  3097. resolve(true);
  3098. this.loading = false;
  3099. }catch(e){
  3100. urlInfo.status = '5';
  3101. reject(e);
  3102. this.showError(e);
  3103. }
  3104. })();
  3105. });
  3106. },
  3107. //
  3108. downloadExample(){
  3109. let url = 'https://www.xingyousoft.com/soft/XYCapture/example.xlsx';
  3110. if (!fs.existsSync(this.downloadDir + separator + pjson.softInfo.softName)) {
  3111. fs.mkdirSync(this.downloadDir + separator + pjson.softInfo.softName);
  3112. }
  3113. let path = this.downloadDir + separator + pjson.softInfo.softName + '\\链接模板下载.xlsx';
  3114. this.downloadImage(url, path, 'example');
  3115. },
  3116. // 下载网址链接的图片
  3117. async downloadImage(imageUrl, outputPath, urlInfo) {
  3118. let _this = this;
  3119. let received_bytes = 0;
  3120. let total_bytes = 0;
  3121. try {
  3122. let req = request({
  3123. method: 'GET', uri: imageUrl, strictSSL: false
  3124. });
  3125. let out = fs.createWriteStream(outputPath);
  3126. req.pipe(out);
  3127. return new Promise((resolve, reject) => {
  3128. req.on('response', (data) => {
  3129. total_bytes = parseInt(data.headers['content-length']);
  3130. const status = data.statusCode;
  3131. if (status < 200 || status >= 300) {
  3132. //reject(false);
  3133. this.$notify.error({
  3134. title: '网络图片访问异常!- 1',
  3135. message: imageUrl.slice(0,50)
  3136. });
  3137. }else if(isNaN(total_bytes)){
  3138. //reject(false);
  3139. this.$notify.error({
  3140. title: '网络图片访问异常!- 2',
  3141. message: imageUrl.slice(0,50)
  3142. });
  3143. }else{
  3144. // console.log('下载中...')
  3145. }
  3146. });
  3147. req.on('data', (chunk) => {
  3148. received_bytes += chunk.length;
  3149. });
  3150. req.on('end', ()=> {
  3151. if(urlInfo != 'example'){
  3152. urlInfo.num += 1;
  3153. }else{
  3154. this.$msgbox({
  3155. title: '消息',
  3156. message: '模板下载成功,保存位置:' + this.downloadDir + separator + pjson.softInfo.softName,
  3157. showCancelButton: true,
  3158. confirmButtonText: '去查看',
  3159. cancelButtonText: '取消',
  3160. }).then(action => {
  3161. this.openFolder();
  3162. }).catch(action => {
  3163. });
  3164. }
  3165. //console.log('下载完成', outputPath)
  3166. resolve(true);
  3167. });
  3168. });
  3169. } catch (error) {
  3170. console.error(imageUrl, `Failed to download image: ${error.message}`);
  3171. throw error;
  3172. }
  3173. },
  3174. // 获取页面标题 - 生成对应的文件夹
  3175. async getTitle(page, urlInfo, tagStr){
  3176. // 已页面标题作为新建文件夹,保留前50个字
  3177. let title = await page.title();
  3178. if(!title){
  3179. title = '无标题-'+new Date().getTime();
  3180. }
  3181. if(tagStr){
  3182. title = tagStr.replace(/\.\.\./g, '');
  3183. }
  3184. if(title){
  3185. title = title.substring(0, 50).trim();
  3186. if(this.containsAnyChar(title, ['\\', '/', ':', '*', '?', '"', '<', '>', '|'])){ //判断是否含有特殊字符
  3187. title = title.replace(/[\\|/|:|*|?|"|<|>||]/g, "");
  3188. }
  3189. if (fs.existsSync(this.downloadDir + separator + pjson.softInfo.softName + separator + title)) {
  3190. urlInfo.newPath = this.downloadDir + separator + pjson.softInfo.softName + separator + title;
  3191. } else {
  3192. fs.mkdirSync(this.downloadDir + separator + pjson.softInfo.softName + separator + title);
  3193. urlInfo.newPath = this.downloadDir + separator + pjson.softInfo.softName + separator + title;
  3194. }
  3195. }
  3196. },
  3197. // 下载base64位的图片
  3198. async downloadBaseImage(base64String, outputPath, urlInfo) {
  3199. const buffer = Buffer.from(base64String, 'base64');
  3200. const writeStream = fs.createWriteStream(outputPath);
  3201. writeStream.write(buffer);
  3202. writeStream.end();
  3203. writeStream.on('finish', () => {
  3204. urlInfo.num += 1;
  3205. });
  3206. // 监听错误事件
  3207. writeStream.on('error', (err) => {
  3208. console.error('base64位写入文件时出错:', err);
  3209. });
  3210. },
  3211. // 错误提示
  3212. showError(e){
  3213. let str = '';
  3214. if(e.toString().indexOf('ERR_NAME_NOT_RESOLVE') > -1){
  3215. str = '无法解析该网址,请查看网址是否正确!-1';
  3216. }else if(e.toString().indexOf('Cannot navigate to invalid URL') > -1){
  3217. str = '无效的网址,请查看网址格式是否正确!-2';
  3218. }else if(e.toString().indexOf('ERR_CONNECTION_TIMED_OUT') > -1){
  3219. str = '链接请求超时,请查看网络状态!-3';
  3220. }else if(e.toString().indexOf('TimeoutError') > -1){
  3221. str = '链接请求超时,请查看网络状态!-4';
  3222. }else if(e.toString().indexOf('operation not permitted') > -1){
  3223. str = '权限受限,请以管理员权限运行软件!-5';
  3224. }else if(e.toString().indexOf('browser has disconnected') > -1){
  3225. str = '内置浏览器已关闭!-6';
  3226. }else if(e.toString().indexOf('Failed to launch the browser') > -1){
  3227. str = '请先关闭内置浏览器!-7';
  3228. }else{
  3229. str = e.toString();
  3230. //console.log(e);
  3231. }
  3232. this.loading = false;
  3233. this.$notify.error({
  3234. title: '提示',
  3235. message: str
  3236. });
  3237. },
  3238. // 是否包含特殊字符
  3239. containsAnyChar(str, charsArray) {
  3240. for (let i = 0; i < charsArray.length; i++) {
  3241. if (str.includes(charsArray[i])) {
  3242. return true;
  3243. }
  3244. }
  3245. return false;
  3246. },
  3247. // 随机生成字符
  3248. randomString(length) {
  3249. let result = '';
  3250. const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
  3251. const charactersLength = characters.length;
  3252. for (let i = 0; i < length; i++ ) {
  3253. result += characters.charAt(Math.floor(Math.random() * charactersLength));
  3254. }
  3255. return result;
  3256. }
  3257. }
  3258. };
  3259. </script>
  3260. <style lang="scss">
  3261. @import "../assets/css/fontx/iconfont.css";
  3262. @import "../assets/css/home.scss";
  3263. .ivu-input-number-controls-outside-btn i {
  3264. font-weight: 800;
  3265. }
  3266. .update-point {
  3267. display: inline-block;
  3268. width: 8px;
  3269. height: 8px;
  3270. border-radius: 8px;
  3271. background: #ff0000;
  3272. top: 14px;
  3273. position: absolute;
  3274. left: -13px;
  3275. }
  3276. .menu-item {
  3277. padding: 8px 0;
  3278. font-size: 14px;
  3279. .iconfont {
  3280. font-size: 32px;
  3281. }
  3282. &:hover,
  3283. &.active {
  3284. color: #ed4014;
  3285. }
  3286. }
  3287. .ivu-progress-show-info .ivu-progress-outer {
  3288. padding-right: 40px !important;
  3289. margin-right: -40px !important;
  3290. }
  3291. .tips {
  3292. text-align: center;
  3293. padding: 10px 0;
  3294. color: #ed4014;
  3295. font-size: 12px;
  3296. }
  3297. .handle-desc {
  3298. display: inline-block;
  3299. width: calc(100% - 100px);
  3300. overflow: hidden;
  3301. }
  3302. .ivu-menu-submenu-title {
  3303. font-weight: 600;
  3304. }
  3305. .ivu-menu .ivu-menu-item {
  3306. line-height: 1;
  3307. }
  3308. // new-el
  3309. .el-menu {
  3310. border-right: none !important;
  3311. }
  3312. .cmenu-item {
  3313. padding: 0 20px 20px;
  3314. margin-bottom: 15px;
  3315. .cmenu-title {
  3316. font-size: 18px;
  3317. font-weight: 600;
  3318. padding-bottom: 20px;
  3319. }
  3320. .citem-nav {
  3321. text-align: center;
  3322. border-radius: 10px;
  3323. min-height: 110px;
  3324. padding: 15px 0;
  3325. background-color: #fff;
  3326. font-size: 15px;
  3327. cursor: pointer;
  3328. &.bg-linear1 {
  3329. color: #fff;
  3330. font-size: 20px;
  3331. background: linear-gradient(to right bottom, #2A56CA, #5795F4);
  3332. }
  3333. &.bg-linear2 {
  3334. color: #fff;
  3335. font-size: 20px;
  3336. background: linear-gradient(to right top, #147FBB, #5EB3E3);
  3337. }
  3338. &.bg-linear3 {
  3339. color: #fff;
  3340. font-size: 20px;
  3341. background: linear-gradient(to right bottom, #2F9E8A, #56CDB1);
  3342. }
  3343. &:hover {
  3344. margin-top: -5px;
  3345. box-shadow: 3px 3px 6px #ccc, -3px -3px 6px #ccc;
  3346. }
  3347. .citem-img {
  3348. width: 50px;
  3349. margin-bottom: 10px;
  3350. }
  3351. }
  3352. }
  3353. .popper-open{
  3354. text-align: center !important;
  3355. padding: 10px !important;
  3356. background: #303133 !important;
  3357. color: #fff !important;
  3358. min-width: 120px !important;
  3359. opacity: 0.8;
  3360. }
  3361. .popper-open[x-placement^=bottom] .popper__arrow::after{
  3362. border-bottom-color: #303133 !important;
  3363. }
  3364. textarea.el-textarea__inner{
  3365. height: 100% !important;
  3366. font-family: "Helvetica Neue",Helvetica,"PingFang SC","Hiragino Sans GB","Microsoft YaHei","微软雅黑",Arial,sans-serif;
  3367. }
  3368. .set-item{
  3369. margin-right: 15px;
  3370. .set-title{
  3371. font-size: 13px;
  3372. }
  3373. }
  3374. .outarea{
  3375. height: 100%;
  3376. border: 1px solid #DCDFE6;
  3377. background-color: #4851a415;
  3378. padding: 15px;
  3379. font-size: 20px;
  3380. overflow: hidden auto;
  3381. }
  3382. .outtext{
  3383. height: 100%;
  3384. font-size: 20px;
  3385. overflow: hidden auto;
  3386. textarea{
  3387. background-color: #4851a415;
  3388. }
  3389. }
  3390. .pin-tips{
  3391. font-size: 14px;
  3392. position: absolute;
  3393. bottom: 10px;
  3394. color: #ff0000;
  3395. left: 0;
  3396. right: 0;
  3397. margin: auto;
  3398. text-align: center;
  3399. }
  3400. .outarea.red-border{
  3401. border: 1px solid #F56C6C;
  3402. }
  3403. .outtext.red-border textarea{
  3404. border: 1px solid #F56C6C;
  3405. }
  3406. h3{
  3407. margin: 0;
  3408. }
  3409. .m-image{
  3410. width: 20px;
  3411. margin-right: 5px;
  3412. }
  3413. .dialog-footer-center{
  3414. text-align: center;
  3415. }
  3416. .visible-tips-style{
  3417. font-size: 18px;
  3418. color: #f73131;
  3419. font-weight: 600;
  3420. padding: 30px 40px 0;
  3421. }
  3422. .no-select{
  3423. user-select: none;
  3424. }
  3425. .tips-flex{
  3426. display: flex;
  3427. flex-wrap: nowrap;
  3428. justify-content: space-around;
  3429. align-items: center;
  3430. .el-icon-s-opportunity{
  3431. font-size: 50px;
  3432. color: #f73131;
  3433. margin-right: 10px;
  3434. }
  3435. .m-title{
  3436. flex: 1;
  3437. color: #f73131;
  3438. }
  3439. }
  3440. </style>