home.vue 111 KB

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