home.vue 129 KB

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