home.vue 108 KB

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