home.vue 115 KB

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