home.vue 84 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516
  1. <template>
  2. <div>
  3. <el-container style="user-select: none; height: 100vh;">
  4. <el-container>
  5. <!-- #333744 -->
  6. <el-aside width="180px" style="border-right: 1px solid #fafafa; background-color: #333744; overflow-x: hidden;">
  7. <p class="soft-name" style="-webkit-app-region: drag; color: #fff;">
  8. <img src="../assets/image/icon.png" class="soft-icon" />
  9. <span style="letter-spacing: 1px;">{{productName}}</span>
  10. </p>
  11. <el-menu :default-openeds="['a', 'b']" :default-active="menuIndex" @select="setMenuIndex" active-text-color="#409EFF" background-color="#333744" text-color="#fff" style="margin-top: 10px;">
  12. <el-submenu index="a">
  13. <template slot="title"><img src="../assets/image/m-download.png" class="m-image"/>图片下载</template>
  14. <el-menu-item index="3">
  15. <img src="../assets/image/m-tmall.png" class="m-image"/><span slot="title">天猫</span>
  16. </el-menu-item>
  17. <el-menu-item index="2">
  18. <img src="../assets/image/m-jd.png" class="m-image"/><span slot="title">京东</span>
  19. </el-menu-item>
  20. <el-menu-item index="4">
  21. <img src="../assets/image/m-taobao.png" class="m-image"/><span slot="title">淘宝</span>
  22. </el-menu-item>
  23. <el-menu-item index="1">
  24. <img src="../assets/image/m-alibaba.png" class="m-image"/><span slot="title">阿里巴巴</span>
  25. </el-menu-item>
  26. <el-menu-item index="5">
  27. <img src="../assets/image/m-hong.png" class="m-image"/><span slot="title">小红书</span>
  28. </el-menu-item>
  29. <el-menu-item index="10">
  30. <img src="../assets/image/m-chrome.png" class="m-image"/><span slot="title">其他网址(Beta)</span>
  31. </el-menu-item>
  32. </el-submenu>
  33. <el-submenu index="b">
  34. <template slot="title"><img src="../assets/image/m-edit.png" class="m-image"/>图片处理</template>
  35. <el-menu-item index="2-1">
  36. <img src="../assets/image/m-geshi.png" class="m-image"/><span slot="title">格式转换</span>
  37. </el-menu-item>
  38. <el-menu-item index="2-2">
  39. <img src="../assets/image/m-yasuo.png" class="m-image"/><span slot="title">图片压缩</span>
  40. </el-menu-item>
  41. <el-menu-item index="2-3">
  42. <img src="../assets/image/m-chicun.png" class="m-image"/><span slot="title">修改尺寸</span>
  43. </el-menu-item>
  44. <el-menu-item index="2-5">
  45. <img src="../assets/image/m-shuiyin.png" class="m-image"/><span slot="title">添加水印</span>
  46. </el-menu-item>
  47. </el-submenu>
  48. </el-menu>
  49. </el-aside>
  50. <el-container>
  51. <el-header height="45px" style="background-color: #fafafa; padding: 0 10px;">
  52. <soft-header ref="headerRef" @update-soft="updateSoft()" @export-file="exportFile" @login-url="loginUrl" @clear-cache="clearCache"></soft-header>
  53. </el-header>
  54. <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>
  55. <el-main v-show="['1', '2', '3', '4', '5', '10'].indexOf(menuIndex) > -1" ref="el-main" style="background-color: #fafafa;">
  56. <template>
  57. <div class="content-top">
  58. <div>
  59. <el-button-group>
  60. <el-button type="primary" size="mini" icon="el-icon-circle-plus-outline"
  61. @click="addVisible = true;">添加链接</el-button>
  62. <el-button type="primary" size="mini" icon="el-icon-upload"
  63. @click="pickLink()">导入链接</el-button>
  64. <el-button type="primary" size="mini" icon="el-icon-delete"
  65. @click="clearList()">清空链接</el-button>
  66. </el-button-group>
  67. <el-link type="info" style="margin-left: 20px; vertical-align:baseline;" @click="downloadExample()">模板下载<i class="el-icon-download"></i></el-link>
  68. </div>
  69. <el-row type="flex" style="align-items: center;">
  70. <div class="set-item">
  71. <span class="set-title">保存目录:</span>
  72. <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>
  73. <el-popover placement="bottom" popper-class="popper-open" trigger="hover" content="打开保存目录">
  74. <i class="el-icon-folder-opened" slot="reference" style="padding-left: 5px; cursor: pointer; font-size: 22px; vertical-align: middle;" @click="openFolder()"></i>
  75. </el-popover>
  76. </div>
  77. <el-button type="danger" @click="exportFile()" :loading="loading">开始下载</el-button>
  78. </el-row>
  79. </div>
  80. <div style="padding: 20px 20px 0 20px; height: calc(100% - 62px);">
  81. <el-row type="flex" justify="space-between">
  82. <div>
  83. <h3 style="display: inline-block;">
  84. <span v-if="menuIndex == '1'">阿里巴巴 - </span>
  85. <span v-if="menuIndex == '2'">京东 - </span>
  86. <span v-if="menuIndex == '3'">天猫 - </span>
  87. <span v-if="menuIndex == '4'">淘宝 - </span>
  88. <span v-if="menuIndex == '5'">小红书 - </span>
  89. <span v-if="menuIndex == '10'">网页 - </span>
  90. 图片下载
  91. </h3>
  92. <el-link v-if="menuIndex == '3' || menuIndex == '4'" :underline="false" type="danger" style="text-align: center; font-size: 12px;">
  93. (需登录{{menuIndex == '3' ? '天猫' : '淘宝'}}账号后才能下载)
  94. </el-link>
  95. <el-link v-if="menuIndex == '2'" :underline="false" type="danger" style="text-align: center; font-size: 12px;">
  96. (需登录京东账号后才能下载)
  97. </el-link>
  98. <el-link v-if="menuIndex == '10'" :underline="false" type="info" style="text-align: center; font-size: 12px;">
  99. <!-- (非会员功能,仅提供试用) -->
  100. </el-link>
  101. </div>
  102. <el-link v-if="((menuIndex == '3' || menuIndex == '4') && tbStatus == 3) || (menuIndex == '2' && jdStatus == 3)" :underline="false" type="danger" style="text-align: center; font-size: 12px;">登录完成后请关闭浏览器</el-link>
  103. </el-row>
  104. <div style="padding: 15px 0 20px;">
  105. <el-row type="flex" justify="space-between">
  106. <div v-if="menuIndex == '5'" style="padding-top: 10px;">
  107. <label>下载类型:</label>
  108. <el-checkbox :value="true" style="opacity: 0.6; cursor: not-allowed;">文章图</el-checkbox>
  109. <span style="font-size: 12px;">(不包含Live图)</span>
  110. </div>
  111. <div v-if="menuIndex == '10'" style="padding-top: 10px;">
  112. <label>下载类型:</label>
  113. <el-checkbox :value="true" style="opacity: 0.6; cursor: not-allowed;">图片</el-checkbox>
  114. </div>
  115. <div v-if="['1', '2', '3', '4'].indexOf(menuIndex) > -1" style="padding-top: 10px;">
  116. <label>下载类型:</label>
  117. <el-checkbox-group :min="1" v-model="settingArr" style="display: inline-block;">
  118. <el-checkbox label="mainImg">主图</el-checkbox>
  119. <el-checkbox label="detailImg">详情图</el-checkbox>
  120. <el-checkbox label="skuImg">SKU图</el-checkbox>
  121. <el-checkbox label="commentImg" v-if="menuIndex == '3' || menuIndex == '4'">评论图</el-checkbox>
  122. <el-checkbox label="video">视频</el-checkbox>
  123. </el-checkbox-group>
  124. <el-popover placement="bottom" popper-class="popper-open" trigger="hover" content="下载类型至少选一个,评论图默认只下载商品首页展示的评论内容">
  125. <i class="el-icon-info" slot="reference" style="margin-left: 10px; color: #F56C6C;"></i>
  126. </el-popover>
  127. <!-- <el-checkbox :value="true" style="opacity: 0.6; cursor: not-allowed;">主图</el-checkbox>
  128. <el-checkbox v-model="settingData.detailImg" >详情图</el-checkbox>
  129. <el-checkbox v-model="settingData.skuImg" >SKU图</el-checkbox>
  130. <el-checkbox v-model="settingData.commentImg" v-if="menuIndex == '3' || menuIndex == '4'">评论图</el-checkbox>
  131. <el-checkbox v-model="settingData.video" >视频</el-checkbox> -->
  132. </div>
  133. <!-- 天猫/淘宝 -->
  134. <template v-if="menuIndex == '3' || menuIndex == '4'">
  135. <div>
  136. <el-tag type="info" size="mini" v-if="tbStatus == 1">未检测</el-tag>
  137. <el-tag type="success" size="mini" v-if="tbStatus == 2">{{menuIndex == '3' ? '天猫' : '淘宝'}}账号已登录</el-tag>
  138. <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>
  139. <el-button size="mini" type="warning" :loading="checkLoading" style="margin-left: 10px;" :disabled='tbStatus == 2' @click="checkLogin">检测登录状态</el-button>
  140. </div>
  141. </template>
  142. <!-- 京东账号 -->
  143. <template v-if="menuIndex == '2'">
  144. <div>
  145. <el-tag type="info" size="mini" v-if="jdStatus == 1">未检测</el-tag>
  146. <el-tag type="success" size="mini" v-if="jdStatus == 2">京东账号已登录</el-tag>
  147. <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>
  148. <el-button size="mini" type="warning" :loading="checkLoading" style="margin-left: 10px;" :disabled='jdStatus == 2' @click="checkJdLogin">检测登录状态</el-button>
  149. </div>
  150. </template>
  151. </el-row>
  152. </div>
  153. <div class="table-scroll">
  154. <!-- 1、 -->
  155. <vxe-table ref="xTable" show-overflow class="img-table" max-height="100%" empty-text="没有更多数据了!" :loading="tabLoading" :row-config="{isHover: true}"
  156. :loading-config="{icon: 'vxe-icon-indicator roll', text: '列表加载中...'}" :data="this[listStr+'List']" :scroll-y="{enabled: true}">
  157. <vxe-column type="seq" width="60"></vxe-column>
  158. <vxe-column field="title" title="目录名称" width="200">
  159. <template #default="{ row, rowIndex }">
  160. <span v-if="row.title">{{row.title}}</span>
  161. <el-tag size="mini" v-else>默认使用网页标题</el-tag>
  162. </template>
  163. </vxe-column>
  164. <vxe-column field="url" title="网页链接"></vxe-column>
  165. <vxe-column field="status" title="下载状态" width="200">
  166. <template #default="{ row }">
  167. <template v-if="row.status == '1'">
  168. <i class="el-icon-info" style="font-size: 16px; color: #999;"></i>
  169. <span>待操作</span>
  170. </template>
  171. <template v-if="row.status == '2'">
  172. <i class="el-icon-loading" style="font-size: 16px; color: #999;"></i>
  173. <span>任务处理中...</span>
  174. </template>
  175. <template v-if="row.status == '3'">
  176. <i class="el-icon-loading" style="font-size: 16px; color: #999;"></i>
  177. <span>图片下载中..<span v-if="row.num > 0">第{{row.num}}张</span></span>
  178. </template>
  179. <template v-if="row.status == '4'">
  180. <i class="el-icon-success" style="font-size: 16px; color: #19be6b;"></i>
  181. <span>下载完成</span>
  182. </template>
  183. <template v-if="row.status == '5'">
  184. <i class="el-icon-error" style="font-size: 16px; color: #ed4014;"></i>
  185. <span>网络异常,请重试!</span>
  186. </template>
  187. <template v-if="row.status == '6'">
  188. <i class="el-icon-error" style="font-size: 16px; color: #ed4014;"></i>
  189. <span>验证码拦截,请手动验证!</span>
  190. </template>
  191. </template>
  192. </vxe-column>
  193. <vxe-column title="操作" width="80">
  194. <template #default="{ row, rowIndex }">
  195. <i class="el-icon-delete cur-pointer" style="font-size: 20px;" @click="delFile(rowIndex)"></i>
  196. </template>
  197. </vxe-column>
  198. </vxe-table>
  199. </div>
  200. </div>
  201. </template>
  202. <el-dialog title="添加链接" :visible.sync="addVisible" width="500px" :close-on-click-modal="false" :close-on-press-escape="false" :show-close="false">
  203. <div>
  204. <el-form label-position="right" label-width="80px" :rules="rules" :model="formData" ref="formData">
  205. <el-form-item label="目录名称" prop="title">
  206. <el-input v-model="formData.title" placeholder="为空则默认使用网页标题前60个字符"></el-input>
  207. </el-form-item>
  208. <el-form-item label="网页链接" prop="url">
  209. <el-input type="textarea" :rows="10" v-if="menuIndex < 10" :placeholder="'请输入网址链接(例:' + exampleUrl[menuIndex-1] + ')'" v-model="formData.url"></el-input>
  210. <el-input type="textarea" :rows="10" v-else :placeholder="'请输入网址链接'" v-model="formData.url"></el-input>
  211. </el-form-item>
  212. </el-form>
  213. </div>
  214. <span slot="footer" class="dialog-footer">
  215. <el-button @click="addVisible = false; $refs['formData'].resetFields();">取 消</el-button>
  216. <el-button type="primary" @click="onSubmit">确 定</el-button>
  217. </span>
  218. </el-dialog>
  219. <el-dialog title="提示" :visible.sync="loginVisible" width="400px" :close-on-click-modal="false" :close-on-press-escape="false">
  220. <div style="text-align: center; color: #999; font-size: 14px;">
  221. <p>{{menuIndex == '2' ? '京东' : '天猫/淘宝'}}渠道需要登录后才能下载</p>
  222. <p style="font-size: 18px; color: #f73131; font-weight: 600; padding: 30px 40px 0;">目前检测还未登录{{menuIndex == '2' ? '京东' : '天猫/淘宝'}}账号,需立即登录</p>
  223. </div>
  224. <div slot="footer" class="dialog-footer-center">
  225. <el-button v-if="menuIndex == '2'" @click="loginVisible = false; loginUrl('https://passport.jd.com/new/login.aspx')">点击登录京东账号</el-button>
  226. <el-button v-else @click="loginVisible = false; loginUrl('https://login.taobao.com')">点击登录天猫/淘宝账号</el-button>
  227. </div>
  228. </el-dialog>
  229. </el-main>
  230. <el-footer height="48px">
  231. <!-- 更新 -->
  232. <soft-update ref="updateRef" :showDowload="dowloadModel" :dowloadFinish="finishModel"></soft-update>
  233. </el-footer>
  234. </el-container>
  235. </el-container>
  236. </el-container>
  237. </div>
  238. </template>
  239. <script>
  240. import os from 'os'
  241. import fs from 'fs'
  242. import request from 'request'
  243. import path from 'path';
  244. import xlsx from 'node-xlsx';
  245. import softUpdate from './update.vue';
  246. import softHeader from './header.vue';
  247. import softImg from './img.vue';
  248. import electronApi from '@/utils/electronApi';
  249. import pjson from '/package.json'
  250. // import puppeteer from 'puppeteer'
  251. import puppeteer from 'puppeteer-extra'
  252. const StealthPlugin = require('puppeteer-extra-plugin-stealth');
  253. let separator = '';
  254. if (os.platform == 'linux') {
  255. separator = '/'
  256. } else {
  257. separator = '\\'
  258. }
  259. // let chromePath = process.cwd() + '\\resources\\app\\node_modules\\puppeteer\\.local-chromium\\win64-1045629\\chrome-win\\chrome.exe';
  260. // if (process.env.NODE_ENV == 'development') {
  261. // chromePath = process.cwd() + '\\node_modules\\puppeteer\\.local-chromium\\win64-1045629\\chrome-win\\chrome.exe';
  262. // }
  263. export default {
  264. name: 'landing-page',
  265. components: {
  266. softUpdate,
  267. softHeader,
  268. softImg
  269. },
  270. data() {
  271. return {
  272. settingArr: ['mainImg'],
  273. loginVisible: false,
  274. addVisible: false,
  275. formData: {
  276. title: '',
  277. url: ''
  278. },
  279. rules:{ //
  280. title: [
  281. { min: 0, max: 60, message: '不能超过 60 个字符', trigger: 'blur' },
  282. { pattern: /^[^\\/:*?"<>|]*$/, message: '标题中不能包含 \\ / : * ? " < > |', trigger: 'blur' }
  283. ],
  284. url: [
  285. { required: true, message: '请输入网页链接', trigger: 'blur' },
  286. { pattern: /^(http|https):\/\/.+$/, message: '请输入正确的网址链接(http://或https://开头)', trigger: 'blur' }
  287. ],
  288. },
  289. tabLoading: false,
  290. alibabaList: [],
  291. jdList: [],
  292. tbList: [],
  293. tmallList: [],
  294. redList: [],
  295. commonList: [],
  296. productName: pjson.softInfo.softName,
  297. imgUrl: this.$api.imgUrl,
  298. imgSrc: '',
  299. menuIndex: '3',
  300. jdBrowser: '', // 打开京东的浏览器
  301. settingData: {
  302. detailImg: true,
  303. skuImg: true,
  304. commentImg: false,
  305. video: false,
  306. },
  307. exampleUrl: ['https://www.1688.com', 'https://www.jd.com', 'https://www.tmall.com', 'https://www.taobao.com', 'https://www.xiaohongshu.com'],
  308. fileList: [],
  309. downloadDir: os.userInfo().homedir + separator + "Downloads",
  310. dowloadModel: false,
  311. finishModel: false,
  312. loading: false,
  313. checkLoading: false, //点击检测登录状态
  314. tbStatus: 1, // 1、未检测 2、已经登录 3、未登录
  315. jdStatus: 1, // 1、未检测 2、已经登录 3、未登录
  316. execLimit: 1,
  317. execNum: 3, // 限制5张
  318. };
  319. },
  320. computed: {
  321. listStr: function(){
  322. let str = 'alibaba';
  323. switch(this.menuIndex){
  324. case '1':
  325. str = 'alibaba';
  326. break;
  327. case '2':
  328. str = 'jd';
  329. break;
  330. case '3':
  331. str = 'tmall';
  332. break;
  333. case '4':
  334. str = 'tb';
  335. break;
  336. case '5':
  337. str = 'red';
  338. break;
  339. case '10':
  340. str = 'common';
  341. break;
  342. }
  343. return str;
  344. }
  345. },
  346. async mounted() {
  347. this.$refs.updateRef.updateSoft(true);
  348. let homedir = os.userInfo().homedir;
  349. if (fs.existsSync(homedir + separator + "Desktop")) {
  350. this.downloadDir = homedir + separator + "Desktop"
  351. } else {
  352. this.downloadDir = homedir + separator + "Downloads"
  353. }
  354. if (!fs.existsSync(os.tmpdir() + separator + 'chrome-data-capture')) {
  355. fs.mkdirSync(os.tmpdir() + separator + 'chrome-data-capture');
  356. }
  357. if (!fs.existsSync(os.tmpdir() + separator + 'chrome-data-capture-jd')) {
  358. fs.mkdirSync(os.tmpdir() + separator + 'chrome-data-capture-jd');
  359. }
  360. let path = os.tmpdir() + separator + 'chrome-data-capture';
  361. let path2 = os.tmpdir() + separator + 'chrome-data-capture-jd';
  362. //this.deleteAll(path, false);
  363. //this.deleteAll(path2, false);
  364. // 打开浏览器
  365. const {
  366. shell
  367. } = require('electron');
  368. const links = document.querySelectorAll('a[href]');
  369. links.forEach(link => {
  370. link.addEventListener('click', e => {
  371. const url = link.getAttribute('href');
  372. e.preventDefault();
  373. shell.openExternal(url);
  374. });
  375. });
  376. },
  377. methods: {
  378. // 删除文件夹内容
  379. deleteAll(folderPath, flag) {
  380. if (fs.existsSync(folderPath)) {
  381. fs.readdirSync(folderPath).forEach((file, index) => {
  382. var curPath = path.join(folderPath, file);
  383. if (fs.lstatSync(curPath).isDirectory()) {
  384. this.deleteAll(curPath, true);
  385. } else {
  386. fs.unlinkSync(curPath);
  387. }
  388. });
  389. if(flag){
  390. fs.rmdirSync(folderPath);
  391. }
  392. }
  393. },
  394. checkAuthority(){
  395. let authority = this.$refs.headerRef.authority;
  396. this.$refs.imgRef.authority = authority;
  397. },
  398. setMenuIndex(index){
  399. this.menuIndex = index;
  400. if(index.indexOf('2-') > -1){
  401. let num = Number(index.split('-')[1]);
  402. this.$refs.imgRef.setMenuIndex(num);
  403. }
  404. },
  405. // 选择目录
  406. pickPath() {
  407. this.$refs['upload-input'].blur();
  408. electronApi.call('pickDir', []).then((path) => {
  409. if (path) {
  410. this.downloadDir = path;
  411. }
  412. });
  413. },
  414. // 打开自定义下载目录
  415. openFolder() {
  416. let path = this.downloadDir;
  417. if (fs.existsSync(this.downloadDir + separator + pjson.softInfo.softName)) {
  418. path = this.downloadDir + separator + pjson.softInfo.softName;
  419. } else {
  420. fs.mkdirSync(this.downloadDir + separator + pjson.softInfo.softName);
  421. path = this.downloadDir + separator + pjson.softInfo.softName;
  422. }
  423. electronApi.call('showItemInfolder', [path + '\\tty.tty'])
  424. },
  425. openVip() {
  426. this.$refs.headerRef.openVip();
  427. },
  428. updateSoft() {
  429. this.$refs.updateRef.updateSoft();
  430. },
  431. // 删除文件
  432. delFile(rowIndex){
  433. let type = 'alibaba';
  434. switch(this.menuIndex){
  435. case '1':
  436. type = 'alibaba';
  437. break;
  438. case '2':
  439. type = 'jd';
  440. break;
  441. case '3':
  442. type = 'tmall';
  443. break;
  444. case '4':
  445. type = 'tb';
  446. break;
  447. case '5':
  448. type = 'red';
  449. break;
  450. case '10':
  451. type = 'common';
  452. break;
  453. }
  454. this.$confirm('确认删除此行数据吗?', '提示', {
  455. confirmButtonText: '确定',
  456. cancelButtonText: '取消',
  457. type: 'warning'
  458. }).then(() => {
  459. this[type+'List'].splice(rowIndex, 1);
  460. if(this[type+'List'].length == 0) {
  461. this.clearList();
  462. }
  463. }).catch(() => {
  464. });
  465. },
  466. // 清除列表
  467. clearList() {
  468. switch(this.menuIndex){
  469. case '1':
  470. this.alibabaList = [];
  471. break;
  472. case '2':
  473. this.jdList = [];
  474. break;
  475. case '3':
  476. this.tmallList = [];
  477. break;
  478. case '4':
  479. this.tbList = [];
  480. break;
  481. case '5':
  482. this.redList = [];
  483. break;
  484. case '10':
  485. this.commonList = [];
  486. break;
  487. }
  488. },
  489. // 提交表单
  490. onSubmit(){
  491. this.$refs['formData'].validate((valid) => {
  492. if (valid) {
  493. let info = {
  494. url: this.formData.url,
  495. title: this.formData.title,
  496. status: '1',
  497. num: 0,
  498. newPath: ''
  499. }
  500. switch(this.menuIndex){
  501. case '1':
  502. this.alibabaList.push(info);
  503. break;
  504. case '2':
  505. this.jdList.push(info);
  506. break;
  507. case '3':
  508. this.tmallList.push(info);
  509. break;
  510. case '4':
  511. this.tbList.push(info);
  512. break;
  513. case '5':
  514. this.redList.push(info);
  515. break;
  516. case '10':
  517. this.commonList.push(info);
  518. break;
  519. }
  520. this.$refs['formData'].resetFields();
  521. this.addVisible = false;
  522. } else {
  523. return false;
  524. }
  525. });
  526. },
  527. async pickLink() {
  528. const spinLoad = this.$loading();
  529. await electronApi.call('pickFile', ['xlsx,xls', true]).then(async (path) => {
  530. spinLoad.close();
  531. if(path.length > 0){
  532. this.$notify({
  533. title: '提示',
  534. message: '导入成功',
  535. type: 'success'
  536. });
  537. let workSheetsFromBuffer = xlsx.parse(fs.readFileSync(path[0]));
  538. if(workSheetsFromBuffer && workSheetsFromBuffer.length > 0){
  539. let errMsg = "";
  540. workSheetsFromBuffer[0].data.map((item, index) => {
  541. if(item.length > 0){
  542. let ititle = '';
  543. if(item[0]){
  544. ititle = item[0].toString().trim();
  545. }
  546. if(item[0] == '目录名称' && item[1] == '网页链接'){
  547. return false;
  548. }
  549. if(this.containsAnyChar(ititle.toString(), ['\\', '/', ':', '*', '?', '"', '<', '>', '|'])){ //判断是否含有特殊字符
  550. errMsg += "第" + (index+1) + '行-名称不能包以下字符 \\ / : * ? " < > |';
  551. ititle = ititle.replace(/[\\|/|:|*|?|"|<|>||]/g, "");
  552. }
  553. if(item[1] == undefined){
  554. errMsg += "第" + (index+1) + "行格式有误</br>";
  555. item[1] = '';
  556. }else if(!/^(http|https):\/\/.+$/.exec(item[1])){
  557. errMsg += "第" + (index+1) + "行网址格式有误</br>";
  558. }else{
  559. let info = {
  560. url: item[1],
  561. title: ititle,
  562. status: '1',
  563. num: 0,
  564. newPath: ''
  565. }
  566. switch(this.menuIndex){
  567. case '1':
  568. this.alibabaList.push(info);
  569. break;
  570. case '2':
  571. this.jdList.push(info);
  572. break;
  573. case '3':
  574. this.tmallList.push(info);
  575. break;
  576. case '4':
  577. this.tbList.push(info);
  578. break;
  579. case '5':
  580. this.redList.push(info);
  581. break;
  582. case '10':
  583. this.commonList.push(info);
  584. break;
  585. }
  586. }
  587. }
  588. });
  589. if(errMsg){
  590. this.$notify({
  591. title: '请检查文件以下问题',
  592. dangerouslyUseHTMLString: true,
  593. message: errMsg,
  594. type: 'warning'
  595. });
  596. }
  597. }else{
  598. this.$notify({
  599. title: '提示',
  600. message: '格式有误,请重新导入',
  601. type: 'warning'
  602. });
  603. }
  604. }
  605. });
  606. },
  607. // 清除缓存
  608. clearCache(){
  609. this.jdStatus = 3;
  610. this.tbStatus = 3;
  611. },
  612. // 去登录
  613. loginUrl(url){
  614. (async () => {
  615. try{
  616. if (!fs.existsSync(os.tmpdir() + separator + 'chrome-data-capture')) {
  617. fs.mkdirSync(os.tmpdir() + separator + 'chrome-data-capture');
  618. }
  619. if (!fs.existsSync(os.tmpdir() + separator + 'chrome-data-capture-jd')) {
  620. fs.mkdirSync(os.tmpdir() + separator + 'chrome-data-capture-jd');
  621. }
  622. let userDataDir = os.tmpdir() + separator + 'chrome-data-capture';
  623. if(url.indexOf('.jd.com/') > -1){
  624. userDataDir = os.tmpdir() + separator + 'chrome-data-capture-jd';
  625. }
  626. const tbBrowser = await puppeteer.launch({
  627. headless: false,
  628. executablePath: puppeteer.executablePath().replace('win32-1', 'win64-1'),
  629. args: ['--window-size=1280,800'],
  630. userDataDir: userDataDir,
  631. });
  632. const page = await tbBrowser.newPage();
  633. await page.setViewport({ width: 1280, height: 800 });
  634. await page.evaluateOnNewDocument(() => {
  635. const newProto = navigator.__proto__;
  636. delete newProto.webdriver;
  637. navigator.__proto__ = newProto;
  638. });
  639. await page.goto(url, {waitUntil : 'networkidle2'});
  640. }catch(e){
  641. this.showError(e);
  642. }
  643. })();
  644. },
  645. // 开始下载
  646. async exportFile(flag) {
  647. let authority = this.$refs.headerRef.authority.isAuthority;
  648. if (!fs.existsSync(this.downloadDir + separator + pjson.softInfo.softName)) {
  649. fs.mkdirSync(this.downloadDir + separator + pjson.softInfo.softName);
  650. }
  651. let fileList = [];
  652. switch(this.menuIndex){
  653. case '1': // 阿里巴巴
  654. fileList = this.alibabaList;
  655. break;
  656. case '2': // 京东
  657. fileList = this.jdList;
  658. break;
  659. case '3': // 天猫
  660. fileList = this.tmallList;
  661. break;
  662. case '4': // 淘宝
  663. fileList = this.tbList;
  664. break;
  665. case '5': // 小红书
  666. fileList = this.redList;
  667. break;
  668. case '10': // 普通网址
  669. fileList = this.commonList;
  670. break;
  671. }
  672. if(fileList.length > 0){
  673. if (!authority && !flag) { // 非会员点击转换弹出提示框
  674. this.$refs.headerRef.memberModel = true;
  675. this.$refs.headerRef.isClick = true;
  676. return false;
  677. } else {
  678. this.$refs.headerRef.memberModel = false;
  679. this.loading = true;
  680. setTimeout(() => {
  681. this.loading = false;
  682. }, 60000);
  683. }
  684. if (!fs.existsSync(os.tmpdir() + separator + 'chrome-data-capture')) {
  685. fs.mkdirSync(os.tmpdir() + separator + 'chrome-data-capture');
  686. }
  687. if(this.menuIndex == '2'){ // 京东
  688. if(this.jdStatus == 1 || this.jdStatus == 3){ // 未检测登录状态/或提示未登录状态,开始检测
  689. await this.checkJdLogin().then((data) => {
  690. if(data != 2){ // 未登录
  691. this.jdStatus = 3;
  692. this.loginVisible = true;
  693. }
  694. }).catch(err => {
  695. this.jdStatus = 3;
  696. });
  697. if(this.jdStatus == 3){
  698. this.loading = false;
  699. return false;
  700. }
  701. }
  702. }
  703. if(this.menuIndex == '3' || this.menuIndex == '4'){ // 天猫/淘宝
  704. if(this.tbStatus == 1 || this.tbStatus == 3){ // 未检测登录状态/或提示未登录状态,开始检测
  705. await this.checkLogin().then((data) => {
  706. if(data != 2){ // 未登录
  707. this.tbStatus = 3;
  708. this.loginVisible = true;
  709. }
  710. }).catch(err => {
  711. this.tbStatus = 3;
  712. });
  713. }
  714. if(this.tbStatus == 3){
  715. this.loading = false;
  716. return false;
  717. }
  718. }
  719. let taskArr = [];
  720. let task = "";
  721. for(let i = 0; i < fileList.length; i++){
  722. let item = fileList[i];
  723. switch(this.menuIndex){
  724. case '1': // 阿里巴巴
  725. task = this.alibabaDownload(item);
  726. break;
  727. case '2': // 京东
  728. task = this.jdScanImg(item);
  729. break;
  730. case '3': // 天猫
  731. case '4': // 淘宝
  732. task = this.tbScanImg(item);
  733. break;
  734. case '5': // 小红书
  735. task = this.redDownload(item);
  736. break;
  737. case '10': // 普通网址
  738. task = this.normalDownload(item);
  739. break;
  740. }
  741. if(task){
  742. taskArr.push(task);
  743. }
  744. if((i+1) % this.execLimit == 0){
  745. await Promise.all(taskArr).then(result => {
  746. taskArr = [];
  747. }).catch(err => {
  748. console.log('err'+i, err)
  749. })
  750. }
  751. }
  752. if(taskArr.length > 0){
  753. await Promise.all(taskArr).then(result => {
  754. taskArr = [];
  755. }).catch(err => {
  756. // 错误文件添加到服务中
  757. console.log('err',err)
  758. })
  759. }
  760. let tbLogin = true,jdLogin = true;
  761. if((this.menuIndex == '3' || this.menuIndex == '4') && this.tbStatus == 3){
  762. tbLogin = false;
  763. }
  764. if(this.menuIndex == '2' && this.jdStatus == 3){
  765. jdLogin = false;
  766. }
  767. this.loading = false;
  768. // 打开文件夹
  769. if(fileList.length > 0 && tbLogin && jdLogin){
  770. this.$message({message: '恭喜你,任务已完成!', type: 'success'});
  771. electronApi.call('showItemInfolder',[this.downloadDir + separator + pjson.softInfo.softName +'\\tty.tty'])
  772. }
  773. }
  774. },
  775. // 10-普通网址下载
  776. async normalDownload(urlInfo){
  777. let task = await new Promise((resolve,reject) =>{
  778. (async () => {
  779. try{
  780. let authority = this.$refs.headerRef.authority.isAuthority;
  781. let number = 0;
  782. urlInfo.status = '2';
  783. urlInfo.num = 0;
  784. puppeteer.use(StealthPlugin());
  785. const browser = await puppeteer.launch({
  786. executablePath: puppeteer.executablePath().replace('win32-1', 'win64-1'),
  787. userDataDir: os.tmpdir() + separator + 'chrome-data-capture',
  788. args: [
  789. '--start-maximized',
  790. '--no-sandbox',
  791. '--disable-setuid-sandbox',
  792. '--disable-blink-features=AutomationControlled',
  793. ]
  794. });
  795. const page = await browser.newPage();
  796. page.on('response', async(response) => {
  797. // 检查响应的 MIME 类型是否以 'image/' 开头
  798. if (response.headers()['content-type'] && response.headers()['content-type'].startsWith('image/') && response.headers()['content-length']) {
  799. let imgArr = ['gif', 'jpeg', 'png', 'webp', 'svg', 'tiff', 'bmp', 'ico', 'avif'];
  800. let imgType = 'jpg';
  801. let isBase = false;
  802. imgArr.map((item, index) => {
  803. if(response.headers()['content-type'].indexOf(item) > -1){
  804. imgType = item;
  805. if(item == 'jpeg'){
  806. imgType = 'jpg';
  807. }else if(item == 'avif'){
  808. imgType = 'png';
  809. }
  810. }
  811. });
  812. let url = response.url();
  813. let regex = /^data:image\/[\w|+|-]+;base64,/;
  814. if(regex.exec(url)){
  815. url = response.url().replace(/^data:image\/[\w|+|-]+;base64,/, '');
  816. isBase = true;
  817. }
  818. let imgInfo = {
  819. url: url,
  820. contentType: response.headers()['content-type'],
  821. status: response.status(),
  822. imgType: imgType,
  823. isBase: isBase
  824. }
  825. if(urlInfo.title){
  826. if (fs.existsSync(this.downloadDir + separator + pjson.softInfo.softName + separator + urlInfo.title)) {
  827. urlInfo.newPath = this.downloadDir + separator + pjson.softInfo.softName + separator + urlInfo.title;
  828. } else {
  829. fs.mkdirSync(this.downloadDir + separator + pjson.softInfo.softName + separator + urlInfo.title);
  830. urlInfo.newPath = this.downloadDir + separator + pjson.softInfo.softName + separator + urlInfo.title;
  831. }
  832. }else{
  833. await this.getTitle(page, urlInfo); // 生成页面标题对应的文件夹
  834. }
  835. let outputPath = urlInfo.newPath + '\\' + this.randomString(35) + '.' + imgInfo.imgType;
  836. urlInfo.status = '3';
  837. number++;
  838. if(!authority && number <= this.execNum){
  839. if(imgInfo.isBase){ //base64位图片下载
  840. this.downloadBaseImage(imgInfo.url, outputPath, urlInfo)
  841. }else{
  842. this.downloadImage(imgInfo.url, outputPath, urlInfo);
  843. }
  844. }
  845. if(authority){
  846. if(imgInfo.isBase){ //base64位图片下载
  847. this.downloadBaseImage(imgInfo.url, outputPath, urlInfo)
  848. }else{
  849. this.downloadImage(imgInfo.url, outputPath, urlInfo);
  850. }
  851. }
  852. }
  853. });
  854. await page.goto(urlInfo.url, {waitUntil : 'networkidle2'});
  855. let pageInfo = await page.evaluate(() => {
  856. let cHeight = document.documentElement.clientHeight;
  857. let scrollHeight = document.body.scrollHeight;
  858. return {'scrollHeight': scrollHeight, 'cHeight': cHeight}
  859. });
  860. let scrollHeight = pageInfo.scrollHeight;
  861. let cHeight = pageInfo.cHeight;
  862. let num = Math.ceil(scrollHeight / cHeight);
  863. let start = -1;
  864. let scrollInt = setInterval(async() => {
  865. start ++;
  866. await page.evaluate((start) => {
  867. let cHeight = document.documentElement.clientHeight;
  868. window.scrollTo({
  869. top: cHeight * start,
  870. behavior: "smooth"
  871. });
  872. }, start);
  873. if(start > num || start > 200){ // 防止页面过长,滚动200次自动停止
  874. clearInterval(scrollInt);
  875. await browser.close();
  876. urlInfo.status = '4';
  877. resolve(true);
  878. this.loading = false;
  879. }
  880. }, 300);
  881. }catch(e){
  882. urlInfo.status = '5';
  883. reject(e);
  884. this.showError(e);
  885. }
  886. })();
  887. });
  888. },
  889. // 1 - 阿里巴巴下载
  890. async alibabaDownload(urlInfo){
  891. let task = await new Promise((resolve,reject) =>{
  892. (async () => {
  893. try{
  894. let authority = this.$refs.headerRef.authority.isAuthority;
  895. urlInfo.status = '2';
  896. urlInfo.num = 0;
  897. puppeteer.use(StealthPlugin());
  898. const browser = await puppeteer.launch({
  899. executablePath: puppeteer.executablePath().replace('win32-1', 'win64-1'),
  900. userDataDir: os.tmpdir() + separator + 'chrome-data-capture',
  901. });
  902. const page = await browser.newPage();
  903. await page.goto(urlInfo.url, {waitUntil : 'networkidle2'});
  904. if(urlInfo.title){
  905. if (fs.existsSync(this.downloadDir + separator + pjson.softInfo.softName + separator + urlInfo.title)) {
  906. urlInfo.newPath = this.downloadDir + separator + pjson.softInfo.softName + separator + urlInfo.title;
  907. } else {
  908. fs.mkdirSync(this.downloadDir + separator + pjson.softInfo.softName + separator + urlInfo.title);
  909. urlInfo.newPath = this.downloadDir + separator + pjson.softInfo.softName + separator + urlInfo.title;
  910. }
  911. }else{
  912. await this.getTitle(page, urlInfo); // 生成页面标题对应的文件夹
  913. }
  914. let pageInfo = await page.evaluate(() => {
  915. let cHeight = document.documentElement.clientHeight;
  916. let scrollHeight = document.body.scrollHeight;
  917. return {'scrollHeight': scrollHeight, 'cHeight': cHeight}
  918. });
  919. let scrollHeight = pageInfo.scrollHeight;
  920. let cHeight = pageInfo.cHeight;
  921. let num = Math.ceil(scrollHeight / cHeight);
  922. let start = -1;
  923. let scrollInt = setInterval(async() => {
  924. start ++;
  925. if(this.settingArr.indexOf('detailImg') > -1){
  926. let scrollHeight2 = await page.evaluate((start) => {
  927. let scrollHeight = document.body.scrollHeight;
  928. let cHeight = document.documentElement.clientHeight;
  929. // let num = Math.ceil(scrollHeight / cHeight);
  930. window.scrollTo({
  931. top: cHeight * start,
  932. behavior: "smooth"
  933. });
  934. return scrollHeight;
  935. }, start);
  936. num = Math.ceil(scrollHeight2 / cHeight);
  937. }
  938. if(start > num || start > 200){ // 防止页面过长,滚动200次自动停止
  939. urlInfo.status = '3';
  940. clearInterval(scrollInt);
  941. await this.alibabaScanImg(browser, page, urlInfo, authority);
  942. this.loading = false;
  943. urlInfo.status = '4';
  944. resolve(true);
  945. }
  946. }, 300);
  947. }catch(e){
  948. urlInfo.status = '5';
  949. reject(e);
  950. this.showError(e);
  951. }
  952. })();
  953. });
  954. },
  955. // 检查京东登录状态
  956. checkJdLogin(){
  957. this.checkLoading = true;
  958. this.jdStatus = 1;
  959. return new Promise((resolve, reject) => {
  960. (async () => {
  961. try{
  962. const jdBrowser = await puppeteer.launch({
  963. executablePath: puppeteer.executablePath().replace('win32-1', 'win64-1'),
  964. userDataDir: os.tmpdir() + separator + 'chrome-data-capture-jd',
  965. });
  966. const page = await jdBrowser.newPage();
  967. let testUrl = 'https://www.jd.com';
  968. await page.goto(testUrl, {waitUntil : 'networkidle2'});
  969. let loginInfo = await page.evaluate(() => {
  970. let navTags = document.querySelector('.link-login');
  971. let userTags = document.querySelector('.nickname');
  972. let userTags2 = document.querySelector('.nick'); //企业账号
  973. if(navTags && navTags.innerHTML.indexOf('请登录') > -1){
  974. return false;
  975. }else if(userTags || userTags2){
  976. return true;
  977. }else{
  978. return false;
  979. }
  980. });
  981. if(loginInfo){
  982. this.jdStatus = 2;
  983. }else{
  984. this.jdStatus = 3;
  985. }
  986. resolve(this.jdStatus);
  987. this.checkLoading = false;
  988. jdBrowser.close();
  989. }catch(e){
  990. reject(3);
  991. this.showError(e);
  992. }
  993. })();
  994. });
  995. },
  996. // 京东下载
  997. async jdScanImg(urlInfo){
  998. let task = await new Promise((resolve,reject) =>{
  999. (async () => {
  1000. try{
  1001. let authority = this.$refs.headerRef.authority.isAuthority;
  1002. urlInfo.status = '2';
  1003. urlInfo.num = 0;
  1004. puppeteer.use(StealthPlugin());
  1005. const jdBrowser = await puppeteer.launch({
  1006. executablePath: puppeteer.executablePath().replace('win32-1', 'win64-1'),
  1007. userDataDir: os.tmpdir() + separator + 'chrome-data-capture-jd',
  1008. args: [
  1009. '--no-sandbox',
  1010. '--disable-setuid-sandbox',
  1011. '--disable-blink-features=AutomationControlled',
  1012. ]
  1013. });
  1014. const page = await jdBrowser.newPage();
  1015. await page.evaluateOnNewDocument(() => {
  1016. const newProto = navigator.__proto__;
  1017. delete newProto.webdriver;
  1018. navigator.__proto__ = newProto;
  1019. });
  1020. let jdImgInfo = {
  1021. mainImg: [],
  1022. skuImg: [],
  1023. commentImg: [],
  1024. detailImg: [],
  1025. video: []
  1026. };
  1027. let titleFlag = true;
  1028. let skuNum = 0, mainNum = 0, videoNum = 0;
  1029. page.on('response', async(response) => {
  1030. if(titleFlag){ // 第一次生成页面标题
  1031. if(urlInfo.title){
  1032. if (fs.existsSync(this.downloadDir + separator + pjson.softInfo.softName + separator + urlInfo.title)) {
  1033. urlInfo.newPath = this.downloadDir + separator + pjson.softInfo.softName + separator + urlInfo.title;
  1034. } else {
  1035. fs.mkdirSync(this.downloadDir + separator + pjson.softInfo.softName + separator + urlInfo.title);
  1036. urlInfo.newPath = this.downloadDir + separator + pjson.softInfo.softName + separator + urlInfo.title;
  1037. }
  1038. }else{
  1039. await this.getTitle(page, urlInfo); // 生成页面标题对应的文件夹
  1040. }
  1041. titleFlag = false;
  1042. }
  1043. // 检查响应的 MIME 类型是否以 'image/' 开头
  1044. if (response.headers()['content-type'] && response.headers()['content-type'].startsWith('application/json')) {
  1045. let detailUrl = '';
  1046. let videoUrl = '';
  1047. if(response.url().indexOf('/description/') > -1){ // 商品详情接口
  1048. detailUrl = response.url();
  1049. }
  1050. if(response.url().indexOf('/tencent/video_v3') > -1){ // 商品视频接口
  1051. videoUrl = response.url();
  1052. }
  1053. urlInfo.status = '3';
  1054. if(detailUrl && this.settingArr.indexOf('detailImg') > -1){ // jd商品详情
  1055. try {
  1056. let data = await response.text();
  1057. if(data.indexOf('showdesc(') > -1){
  1058. data = data.slice(0, -1).replace('showdesc(', '');
  1059. }
  1060. let detailInfo = JSON.parse(data);
  1061. let regex = /\/\/img[0-9]+.360buyimg.com\S+.(jpg|jpeg|png|gif|avif|tif|tiff)/g;
  1062. let detailImgArr = [];
  1063. if(detailInfo && detailInfo.content){
  1064. detailImgArr = detailInfo.content.match(regex);
  1065. }
  1066. jdImgInfo.detailImg = detailImgArr;
  1067. for(let i = 0; i < detailImgArr.length; i++){
  1068. let imgUrl = 'https:' + detailImgArr[i];
  1069. let fileName = imgUrl.split('/').pop();
  1070. if(fileName){
  1071. let queryIndex = fileName.indexOf('?');
  1072. if (queryIndex !== -1) {
  1073. fileName = fileName.substr(0, queryIndex);
  1074. }
  1075. let num = Number(i) + 1;
  1076. let suffix = '';
  1077. if(fileName.lastIndexOf('.') > -1){
  1078. suffix = fileName.substr(fileName.lastIndexOf('.'));
  1079. }
  1080. if (!fs.existsSync(urlInfo.newPath + '\\详情图')) {
  1081. fs.mkdirSync(urlInfo.newPath + '\\详情图');
  1082. }
  1083. let outputPath = urlInfo.newPath + '\\详情图\\详情图' + num + suffix;
  1084. if(!authority && i < this.execNum){
  1085. await this.downloadImage(imgUrl, outputPath, urlInfo);
  1086. }
  1087. if(authority){
  1088. await this.downloadImage(imgUrl, outputPath, urlInfo);
  1089. }
  1090. }
  1091. }
  1092. } catch (error) {
  1093. console.error('详情图片解析失败:', error);
  1094. }
  1095. }
  1096. if(videoUrl && this.settingArr.indexOf('video') > -1){ // jd商品视频
  1097. try {
  1098. let data = await response.text();
  1099. data = data.slice(0, -1).replace(/^jQuery[0-9]+\(/, '');
  1100. let videoInfo = JSON.parse(data);
  1101. let videoUrl = videoInfo.playUrl;
  1102. jdImgInfo.video.push(videoUrl);
  1103. let fileName = videoUrl.split('/').pop();
  1104. if(fileName){
  1105. let queryIndex = fileName.indexOf('?');
  1106. if (queryIndex !== -1) {
  1107. fileName = fileName.substr(0, queryIndex);
  1108. }
  1109. if (!fs.existsSync(urlInfo.newPath + '\\视频')) {
  1110. fs.mkdirSync(urlInfo.newPath + '\\视频');
  1111. }
  1112. let outputPath = urlInfo.newPath + '\\视频\\' + fileName;
  1113. await this.downloadImage(videoUrl, outputPath, urlInfo);
  1114. }
  1115. } catch (error) {
  1116. console.error('视频解析失败:', error);
  1117. }
  1118. }
  1119. }
  1120. // if (response.headers()['content-type'] && response.headers()['content-type'].startsWith('image/')) {
  1121. // let regex = /^https:\/\/img[0-9]+.360buyimg.com\/n/;
  1122. // if(regex.exec(response.url())){ // 匹配符合规则的图片路径
  1123. // let skuReg = /\/n[0-9]+\/s(60|40)x(80|40)_jfs\//;
  1124. // if(response.url().match(skuReg) && this.settingArr.indexOf('skuImg') > -1){ // sku图片
  1125. // let replaceStr = '/n1/s800x800_jfs/';
  1126. // if(response.url().match(/\/n[0-9]+\/s60x80_jfs\//)){
  1127. // replaceStr = '/n1/s750x1000_jfs/';
  1128. // }
  1129. // let skuImgUrl = response.url().replace(skuReg, replaceStr).replace('.avif', '');
  1130. // if(response.url().match(skuReg))
  1131. // jdImgInfo.skuImg.push(skuImgUrl);
  1132. // let fileName = skuImgUrl.split('/').pop();
  1133. // if(fileName){
  1134. // let queryIndex = fileName.indexOf('?');
  1135. // if (queryIndex !== -1) {
  1136. // fileName = fileName.substr(0, queryIndex);
  1137. // }
  1138. // if (!fs.existsSync(urlInfo.newPath + '\\sku图')) {
  1139. // fs.mkdirSync(urlInfo.newPath + '\\sku图');
  1140. // }
  1141. // let outputPath = urlInfo.newPath + '\\sku图\\' + fileName;
  1142. // skuNum ++;
  1143. // if(!authority && skuNum <= this.execNum){
  1144. // await this.downloadImage(skuImgUrl, outputPath, urlInfo);
  1145. // }
  1146. // if(authority){
  1147. // await this.downloadImage(skuImgUrl, outputPath, urlInfo);
  1148. // }
  1149. // }
  1150. // }
  1151. // let reg = /\/n[0-9]+\/jfs\//;
  1152. // let reg2 = /\/n[0-9]+\/s(54|50)x(54|66)_jfs\//;
  1153. // if(response.url().match(reg) || response.url().match(reg2)){ // 主图
  1154. // let replaceStr = '/n1/s800x800_jfs/';
  1155. // if(response.url().match(/\/n[0-9]+\/s50x66_jfs\//)){
  1156. // replaceStr = '/n1/s750x1000_jfs/';
  1157. // }
  1158. // let mainImgUrl = response.url().replace(reg, replaceStr).replace(reg2, replaceStr).replace('.avif', '');
  1159. // jdImgInfo.mainImg.push(mainImgUrl);
  1160. // let fileName = mainImgUrl.split('/').pop();
  1161. // if(fileName){
  1162. // let queryIndex = fileName.indexOf('?');
  1163. // let queryIndex2 = fileName.indexOf('!');
  1164. // if (queryIndex !== -1) {
  1165. // fileName = fileName.substr(0, queryIndex);
  1166. // }
  1167. // if (queryIndex2 !== -1) {
  1168. // fileName = fileName.substr(0, queryIndex2);
  1169. // }
  1170. // if (!fs.existsSync(urlInfo.newPath + '\\主图')) {
  1171. // fs.mkdirSync(urlInfo.newPath + '\\主图');
  1172. // }
  1173. // let outputPath = urlInfo.newPath + '\\主图\\' + fileName;
  1174. // mainNum ++;
  1175. // if(!authority && mainNum <= this.execNum){
  1176. // await this.downloadImage(mainImgUrl, outputPath, urlInfo);
  1177. // }
  1178. // if(authority){
  1179. // await this.downloadImage(mainImgUrl, outputPath, urlInfo);
  1180. // }
  1181. // }
  1182. // }
  1183. // }
  1184. // }
  1185. });
  1186. await page.goto(urlInfo.url, {waitUntil : 'networkidle2'});
  1187. /**new**/
  1188. //detailImg:详情图;skuImg:sku图片;commentImg: 评论图;video: 视频
  1189. const imgInfo = await page.evaluate((authority, execNum) => {
  1190. let outObj = {
  1191. mainImg: [],
  1192. skuImg: [],
  1193. };
  1194. //主图
  1195. let arr1 = document.querySelectorAll('#spec-list img');
  1196. for(let i=0; i< arr1.length; i++){
  1197. let mainImgUrl = arr1[i].src;
  1198. let reg = /\/n[0-9]+\/jfs\//;
  1199. let reg2 = /\/n[0-9]+\/s(54|50)x(54|66)_jfs\//;
  1200. let replaceStr = '/n1/s800x800_jfs/';
  1201. if(mainImgUrl.match(/\/n[0-9]+\/s50x66_jfs\//)){
  1202. replaceStr = '/n1/s750x1000_jfs/';
  1203. }
  1204. mainImgUrl = mainImgUrl.replace(reg, replaceStr).replace(reg2, replaceStr).replace('.avif', '');
  1205. if(!authority && i < execNum){
  1206. outObj.mainImg.push(mainImgUrl);
  1207. }
  1208. if(authority){
  1209. outObj.mainImg.push(mainImgUrl);
  1210. }
  1211. }
  1212. //sku图片
  1213. let arr2 = document.querySelectorAll('#choose-attr-1 img');
  1214. for(let i=0; i< arr2.length; i++){
  1215. let skuImgUrl = arr2[i].src;
  1216. let skuReg = /\/n[0-9]+\/s(60|40)x(80|40)_jfs\//;
  1217. let replaceStr = '/n1/s800x800_jfs/';
  1218. if(skuImgUrl.match(/\/n[0-9]+\/s60x80_jfs\//)){
  1219. replaceStr = '/n1/s750x1000_jfs/';
  1220. }
  1221. skuImgUrl = skuImgUrl.replace(skuReg, replaceStr).replace('.avif', '');
  1222. if(!authority && i < execNum){
  1223. outObj.skuImg.push(skuImgUrl);
  1224. }
  1225. if(authority){
  1226. outObj.skuImg.push(skuImgUrl);
  1227. }
  1228. }
  1229. return outObj;
  1230. }, authority, this.execNum);
  1231. if(this.settingArr.indexOf('mainImg') > -1){
  1232. // 主图下载
  1233. for(let j = 0; j < imgInfo.mainImg.length; j++){
  1234. let fileName = imgInfo.mainImg[j].split('/').pop();
  1235. if(fileName){
  1236. let queryIndex = fileName.indexOf('?');
  1237. if (queryIndex !== -1) {
  1238. fileName = fileName.substr(0, queryIndex);
  1239. }
  1240. let num = Number(j) + 1;
  1241. let suffix = '';
  1242. if(fileName.lastIndexOf('.') > -1){
  1243. suffix = fileName.substr(fileName.lastIndexOf('.'));
  1244. }
  1245. if (!fs.existsSync(urlInfo.newPath + '\\主图')) {
  1246. fs.mkdirSync(urlInfo.newPath + '\\主图');
  1247. }
  1248. let outputPath = urlInfo.newPath + '\\主图\\主图' + num + suffix;
  1249. await this.downloadImage(imgInfo.mainImg[j], outputPath, urlInfo);
  1250. }
  1251. }
  1252. }
  1253. // sku图片下载
  1254. if(this.settingArr.indexOf('skuImg') > -1){
  1255. for(let j = 0; j < imgInfo.skuImg.length; j++){
  1256. let fileName = imgInfo.skuImg[j].split('/').pop();
  1257. if(fileName){
  1258. let queryIndex = fileName.indexOf('?');
  1259. if (queryIndex !== -1) {
  1260. fileName = fileName.substr(0, queryIndex);
  1261. }
  1262. let num = Number(j) + 1;
  1263. let suffix = '';
  1264. if(fileName.lastIndexOf('.') > -1){
  1265. suffix = fileName.substr(fileName.lastIndexOf('.'));
  1266. }
  1267. if (!fs.existsSync(urlInfo.newPath + '\\sku图')) {
  1268. fs.mkdirSync(urlInfo.newPath + '\\sku图');
  1269. }
  1270. let outputPath = urlInfo.newPath + '\\sku图\\sku图' + num + suffix;
  1271. await this.downloadImage(imgInfo.skuImg[j], outputPath, urlInfo);
  1272. }
  1273. }
  1274. }
  1275. /**end**/
  1276. await jdBrowser.close();
  1277. urlInfo.status = '4';
  1278. resolve(true);
  1279. }catch(e){
  1280. reject(e);
  1281. this.showError(e);
  1282. }
  1283. })();
  1284. });
  1285. },
  1286. // 检查天猫淘宝登录状态
  1287. checkLogin(){
  1288. this.checkLoading = true;
  1289. this.tbStatus = 1;
  1290. return new Promise((resolve, reject) => {
  1291. (async () => {
  1292. try{
  1293. const tbBrowser = await puppeteer.launch({
  1294. executablePath: puppeteer.executablePath().replace('win32-1', 'win64-1'),
  1295. userDataDir: os.tmpdir() + separator + 'chrome-data-capture',
  1296. });
  1297. const page = await tbBrowser.newPage();
  1298. let testUrl = 'https://www.taobao.com';
  1299. await page.goto(testUrl, {waitUntil : 'networkidle2'});
  1300. let loginInfo = await page.evaluate(() => {
  1301. let navTags = document.querySelector('.site-nav-sign a');
  1302. let userTags = document.querySelector('.site-nav-user a');
  1303. if(navTags && navTags.innerHTML.indexOf('登录') > -1){
  1304. return false;
  1305. }else if(userTags){
  1306. return true;
  1307. }else{
  1308. return false;
  1309. }
  1310. });
  1311. if(loginInfo){
  1312. this.tbStatus = 2;
  1313. }else{
  1314. this.tbStatus = 3;
  1315. }
  1316. resolve(this.tbStatus);
  1317. this.checkLoading = false;
  1318. tbBrowser.close();
  1319. }catch(e){
  1320. reject(3);
  1321. this.showError(e);
  1322. }
  1323. })();
  1324. });
  1325. },
  1326. // 淘宝天猫扫描下载图片
  1327. async tbScanImg(urlInfo){
  1328. let task = await new Promise((resolve,reject) =>{
  1329. (async () => {
  1330. try{
  1331. let authority = this.$refs.headerRef.authority.isAuthority;
  1332. urlInfo.status = '2';
  1333. urlInfo.num = 0;
  1334. puppeteer.use(StealthPlugin());
  1335. const tbBrowser = await puppeteer.launch({
  1336. executablePath: puppeteer.executablePath().replace('win32-1', 'win64-1'),
  1337. userDataDir: os.tmpdir() + separator + 'chrome-data-capture',
  1338. });
  1339. const page = await tbBrowser.newPage();
  1340. await page.goto(urlInfo.url, {waitUntil : 'networkidle0'});
  1341. if(urlInfo.title){
  1342. if (fs.existsSync(this.downloadDir + separator + pjson.softInfo.softName + separator + urlInfo.title)) {
  1343. urlInfo.newPath = this.downloadDir + separator + pjson.softInfo.softName + separator + urlInfo.title;
  1344. } else {
  1345. fs.mkdirSync(this.downloadDir + separator + pjson.softInfo.softName + separator + urlInfo.title);
  1346. urlInfo.newPath = this.downloadDir + separator + pjson.softInfo.softName + separator + urlInfo.title;
  1347. }
  1348. }else{
  1349. await this.getTitle(page, urlInfo); // 生成页面标题对应的文件夹
  1350. }
  1351. let responseVideo = [];
  1352. page.on('response', async(response) => {
  1353. // 检查响应的 MIME 类型是否以 'video/' 开头
  1354. if (response.headers()['content-type'] && response.headers()['content-type'].startsWith('video/')) {
  1355. responseVideo.push(response.url());
  1356. }
  1357. });
  1358. let pageInfo = await page.evaluate(() => {
  1359. let cHeight = document.documentElement.clientHeight;
  1360. let scrollHeight = document.body.scrollHeight;
  1361. return {'scrollHeight': scrollHeight, 'cHeight': cHeight}
  1362. });
  1363. //鼠标放在主图第一张,生成视频
  1364. const elementHandle = await page.$('li[class*=thumbnail--]');
  1365. if(elementHandle){
  1366. const classListProperty = await elementHandle.getProperty('classList');
  1367. const classList = await classListProperty.jsonValue();
  1368. const classesArray = Object.values(classList);
  1369. const allClasses = classesArray.join('.');
  1370. if(allClasses && allClasses.indexOf('active-') < 0){
  1371. await page.hover('li.'+allClasses);
  1372. }
  1373. }
  1374. let m1 = document.querySelectorAll('img[class^=PicGallery--thumbnailPic--]');
  1375. let m2 = document.querySelectorAll('img[class*=thumbnailPic--]');
  1376. if(document.querySelector('iframe') && m1.length == 0 && m2.length == 0){ // 出现弹窗而且没有主图,判断为拦截模式
  1377. await tbBrowser.close();
  1378. urlInfo.status = '6';
  1379. resolve(true);
  1380. this.loading = false;
  1381. }
  1382. let scrollHeight = pageInfo.scrollHeight;
  1383. let cHeight = pageInfo.cHeight;
  1384. let num = Math.ceil(scrollHeight / cHeight);
  1385. let start = -1;
  1386. let scrollInt = setInterval(async() => {
  1387. start ++;
  1388. if(this.settingArr.indexOf('commentImg') > -1 && this.settingArr.indexOf('detailImg') < 0){ // 选择了评论图没选择详情图
  1389. let scrollHeight2 = await page.evaluate((start) => {
  1390. let scrollHeight = document.body.scrollHeight;
  1391. let cHeight = document.documentElement.clientHeight;
  1392. let obj = document.getElementById('container') || document.getElementById('content');
  1393. if(obj && obj.getBoundingClientRect().top < -500){
  1394. return -1;
  1395. }
  1396. window.scrollTo({
  1397. top: cHeight * start,
  1398. behavior: "smooth"
  1399. });
  1400. return scrollHeight;
  1401. }, start);
  1402. if(scrollHeight2 > 0){
  1403. num = Math.ceil(scrollHeight2 / cHeight);
  1404. }else{
  1405. num = 0;
  1406. }
  1407. }
  1408. if(this.settingArr.indexOf('detailImg') > -1){
  1409. let scrollHeight2 = await page.evaluate((start) => {
  1410. let scrollHeight = document.body.scrollHeight;
  1411. let cHeight = document.documentElement.clientHeight;
  1412. let obj = document.getElementById('container') || document.getElementById('content');
  1413. if(obj && obj.getBoundingClientRect().bottom < 100){
  1414. return -1;
  1415. }
  1416. window.scrollTo({
  1417. top: cHeight * start,
  1418. behavior: "smooth"
  1419. });
  1420. return scrollHeight;
  1421. }, start);
  1422. if(scrollHeight2 > 0){
  1423. num = Math.ceil(scrollHeight2 / cHeight);
  1424. }else{
  1425. num = 0;
  1426. }
  1427. }
  1428. if(start > num || start > 200){ // 防止页面过长,滚动200次自动停止
  1429. urlInfo.status = '3';
  1430. clearInterval(scrollInt);
  1431. //detailImg:详情图;skuImg:sku图片;commentImg: 评论图;video: 视频
  1432. const imgInfo = await page.evaluate((authority, execNum) => {
  1433. let outObj = {
  1434. mainImg: [],
  1435. detailImg: [],
  1436. skuImg: [],
  1437. commentImg: [],
  1438. video: []
  1439. };
  1440. // 正则表达式匹配字符 重写图片路径
  1441. let regex = /\.(.{3,4})_[0-9a-zA-z]+\.(.{3,4})_\.(.{3,4})/;
  1442. //主图
  1443. let arr1 = document.querySelectorAll('img[class^=PicGallery--thumbnailPic--]');
  1444. if(arr1.length === 0){
  1445. arr1 = document.querySelectorAll('img[class*=thumbnailPic--]');
  1446. }
  1447. for(let i=0; i< arr1.length; i++){
  1448. let mainImgUrl = arr1[i].src;
  1449. let result = regex.exec(mainImgUrl);
  1450. if(result){
  1451. mainImgUrl = mainImgUrl.replace(result[0], '.'+result[1]);
  1452. }
  1453. if(!authority && i < execNum){
  1454. outObj.mainImg.push(mainImgUrl);
  1455. }
  1456. if(authority){
  1457. outObj.mainImg.push(mainImgUrl);
  1458. }
  1459. }
  1460. //sku图片
  1461. let arr2 = document.querySelectorAll('img[class^=SkuContent--valueItemImg--]');
  1462. if(arr2.length === 0){
  1463. arr2 = document.querySelectorAll('img[class*=valueItemImg--]');
  1464. }
  1465. for(let i=0; i< arr2.length; i++){
  1466. let skuImgUrl = arr2[i].src;
  1467. let result = regex.exec(skuImgUrl);
  1468. if(result){
  1469. skuImgUrl = skuImgUrl.replace(result[0], '.'+result[1]);
  1470. }
  1471. if(!authority && i < execNum){
  1472. outObj.skuImg.push(skuImgUrl);
  1473. }
  1474. if(authority){
  1475. outObj.skuImg.push(skuImgUrl);
  1476. }
  1477. }
  1478. //详情图片
  1479. let arr3 = document.querySelectorAll('#content img');
  1480. for(let i=0; i< arr3.length; i++){
  1481. let detailImgUrl = arr3[i].src;
  1482. let lazyUrl = arr3[i].getAttribute('data-src');
  1483. if(arr3[i].src.indexOf('/s.gif') > -1 && lazyUrl){
  1484. detailImgUrl = lazyUrl;
  1485. if(!/^http/.exec(lazyUrl)){
  1486. detailImgUrl = 'https:' + lazyUrl;
  1487. }
  1488. }
  1489. let result = regex.exec(detailImgUrl);
  1490. if(result){
  1491. detailImgUrl = detailImgUrl.replace(result[0], '.'+result[1]);
  1492. }
  1493. if(!authority && i < execNum){
  1494. outObj.detailImg.push(detailImgUrl);
  1495. }
  1496. if(authority){
  1497. outObj.detailImg.push(detailImgUrl);
  1498. }
  1499. }
  1500. //评论图片
  1501. let arr4 = document.querySelectorAll('div[class^=Comments--comments--] img');
  1502. if(arr4.length === 0){
  1503. arr4 = document.querySelectorAll('div[class^=comments--] img');
  1504. }
  1505. for(let i=0; i< arr4.length; i++){
  1506. if(arr4[i].src.indexOf('/avatar/sns/user/flag/sns_logo') == -1){ //过滤淘宝用户头像
  1507. if(!authority && i < execNum){
  1508. outObj.commentImg.push(arr4[i].src);
  1509. }
  1510. if(authority){
  1511. outObj.commentImg.push(arr4[i].src);
  1512. }
  1513. }
  1514. }
  1515. // 视频
  1516. let arr5 = document.querySelectorAll('video.lib-video');
  1517. for(let i=0; i< arr5.length; i++){
  1518. if(outObj.video.indexOf(arr5[i].src) == -1){
  1519. if(!authority && i < execNum){
  1520. outObj.video.push(arr5[i].src);
  1521. }
  1522. if(authority){
  1523. outObj.video.push(arr5[i].src);
  1524. }
  1525. }
  1526. }
  1527. return outObj;
  1528. }, authority, this.execNum);
  1529. if(imgInfo.video.length == 0 && responseVideo.length > 0){
  1530. imgInfo.video = responseVideo;
  1531. }
  1532. if(this.settingArr.indexOf('mainImg') > -1){
  1533. // 主图下载
  1534. for(let j = 0; j < imgInfo.mainImg.length; j++){
  1535. let fileName = imgInfo.mainImg[j].split('/').pop();
  1536. if(fileName){
  1537. let queryIndex = fileName.indexOf('?');
  1538. if (queryIndex !== -1) {
  1539. fileName = fileName.substr(0, queryIndex);
  1540. }
  1541. let num = Number(j) + 1;
  1542. let suffix = '';
  1543. if(fileName.lastIndexOf('.') > -1){
  1544. suffix = fileName.substr(fileName.lastIndexOf('.'));
  1545. }
  1546. if (!fs.existsSync(urlInfo.newPath + '\\主图')) {
  1547. fs.mkdirSync(urlInfo.newPath + '\\主图');
  1548. }
  1549. let outputPath = urlInfo.newPath + '\\主图\\主图' + num + suffix;
  1550. await this.downloadImage(imgInfo.mainImg[j], outputPath, urlInfo);
  1551. }
  1552. }
  1553. }
  1554. // sku图片下载
  1555. if(this.settingArr.indexOf('skuImg') > -1){
  1556. for(let j = 0; j < imgInfo.skuImg.length; j++){
  1557. let fileName = imgInfo.skuImg[j].split('/').pop();
  1558. if(fileName){
  1559. let queryIndex = fileName.indexOf('?');
  1560. if (queryIndex !== -1) {
  1561. fileName = fileName.substr(0, queryIndex);
  1562. }
  1563. let num = Number(j) + 1;
  1564. let suffix = '';
  1565. if(fileName.lastIndexOf('.') > -1){
  1566. suffix = fileName.substr(fileName.lastIndexOf('.'));
  1567. }
  1568. if (!fs.existsSync(urlInfo.newPath + '\\sku图')) {
  1569. fs.mkdirSync(urlInfo.newPath + '\\sku图');
  1570. }
  1571. let outputPath = urlInfo.newPath + '\\sku图\\sku图' + num + suffix;
  1572. await this.downloadImage(imgInfo.skuImg[j], outputPath, urlInfo);
  1573. }
  1574. }
  1575. }
  1576. //详情图下载
  1577. if(this.settingArr.indexOf('detailImg') > -1){
  1578. for(let j = 0; j < imgInfo.detailImg.length; j++){
  1579. let fileName = imgInfo.detailImg[j].split('/').pop();
  1580. if(fileName){
  1581. let queryIndex = fileName.indexOf('?');
  1582. if (queryIndex !== -1) {
  1583. fileName = fileName.substr(0, queryIndex);
  1584. }
  1585. let num = Number(j) + 1;
  1586. let suffix = '';
  1587. if(fileName.lastIndexOf('.') > -1){
  1588. suffix = fileName.substr(fileName.lastIndexOf('.'));
  1589. }
  1590. if (!fs.existsSync(urlInfo.newPath + '\\详情图')) {
  1591. fs.mkdirSync(urlInfo.newPath + '\\详情图');
  1592. }
  1593. let outputPath = urlInfo.newPath + '\\详情图\\详情图' + num + suffix;
  1594. await this.downloadImage(imgInfo.detailImg[j], outputPath, urlInfo);
  1595. }
  1596. }
  1597. }
  1598. //评论图下载
  1599. if(this.settingArr.indexOf('commentImg') > -1){
  1600. for(let j = 0; j < imgInfo.commentImg.length; j++){
  1601. let fileName = imgInfo.commentImg[j].split('/').pop();
  1602. if(fileName){
  1603. let queryIndex = fileName.indexOf('?');
  1604. if (queryIndex !== -1) {
  1605. fileName = fileName.substr(0, queryIndex);
  1606. }
  1607. let num = Number(j) + 1;
  1608. let suffix = '';
  1609. if(fileName.lastIndexOf('.') > -1){
  1610. suffix = fileName.substr(fileName.lastIndexOf('.'));
  1611. }
  1612. if (!fs.existsSync(urlInfo.newPath + '\\评论图')) {
  1613. fs.mkdirSync(urlInfo.newPath + '\\评论图');
  1614. }
  1615. let outputPath = urlInfo.newPath + '\\评论图\\评论图' + num + suffix;
  1616. await this.downloadImage(imgInfo.commentImg[j], outputPath, urlInfo);
  1617. }
  1618. }
  1619. }
  1620. //视频下载
  1621. if(this.settingArr.indexOf('video') > -1){
  1622. for(let j = 0; j < imgInfo.video.length; j++){
  1623. let fileName = imgInfo.video[j].split('/').pop();
  1624. if(fileName){
  1625. let queryIndex = fileName.indexOf('?');
  1626. if (queryIndex !== -1) {
  1627. fileName = fileName.substr(0, queryIndex);
  1628. }
  1629. if (!fs.existsSync(urlInfo.newPath + '\\视频')) {
  1630. fs.mkdirSync(urlInfo.newPath + '\\视频');
  1631. }
  1632. let outputPath = urlInfo.newPath + '\\视频\\' + fileName;
  1633. await this.downloadImage(imgInfo.video[j], outputPath, urlInfo);
  1634. }
  1635. }
  1636. }
  1637. await tbBrowser.close();
  1638. urlInfo.status = '4';
  1639. resolve(true);
  1640. this.loading = false;
  1641. }
  1642. }, 300);
  1643. }catch(e){
  1644. reject(e);
  1645. this.showError(e);
  1646. }
  1647. })();
  1648. });
  1649. },
  1650. // 阿里巴巴 - 扫描并下载图片
  1651. async alibabaScanImg(browser, page, urlInfo, authority){
  1652. //detailImg:详情图;skuImg:sku图片;commentImg: 评论图;video: 视频
  1653. const imgInfo = await page.evaluate((authority, execNum) => {
  1654. let outObj = {
  1655. mainImg: [],
  1656. detailImg: [],
  1657. skuImg: [],
  1658. commentImg: [],
  1659. video: []
  1660. };
  1661. //主图
  1662. let arr1 = document.querySelectorAll('img.detail-gallery-img');
  1663. for(let i=0; i< arr1.length; i++){
  1664. if(!authority && i < execNum){
  1665. outObj.mainImg.push(arr1[i].src);
  1666. }
  1667. if(authority){
  1668. outObj.mainImg.push(arr1[i].src);
  1669. }
  1670. }
  1671. //sku图片
  1672. let arr2 = document.querySelectorAll('.prop-img');
  1673. if(arr2.length == 0){
  1674. arr2 = document.querySelectorAll('.sku-item-image');
  1675. }
  1676. for(let i=0; i< arr2.length; i++){
  1677. let src = window.getComputedStyle(arr2[i]).backgroundImage.replace(/url\(["']?(.+?)["']?\)/i, '$1');
  1678. if(!authority && i < execNum){
  1679. outObj.skuImg.push(src);
  1680. }
  1681. if(authority){
  1682. outObj.skuImg.push(src);
  1683. }
  1684. }
  1685. //详情图片
  1686. let arr3 = document.querySelectorAll('img.desc-img-loaded');
  1687. for(let i=0; i< arr3.length; i++){
  1688. if(!authority && i < execNum){
  1689. outObj.detailImg.push(arr3[i].src);
  1690. }
  1691. if(authority){
  1692. outObj.detailImg.push(arr3[i].src);
  1693. }
  1694. }
  1695. //评论图片 -- 需要点击切换
  1696. // let arr4 = document.querySelectorAll('img.image-box');
  1697. // for(let i=0; i< arr4.length; i++){
  1698. // if(!authority && i < execNum){
  1699. // outObj.commentImg.push(arr4[i].src);
  1700. // }
  1701. // if(authority){
  1702. // outObj.commentImg.push(arr4[i].src);
  1703. // }
  1704. // }
  1705. // 视频
  1706. let arr5 = document.querySelectorAll('video.lib-video');
  1707. for(let i=0; i< arr5.length; i++){
  1708. if(outObj.video.indexOf(arr5[i].src) == -1){
  1709. if(!authority && i < execNum){
  1710. outObj.video.push(arr5[i].src);
  1711. }
  1712. if(authority){
  1713. outObj.video.push(arr5[i].src);
  1714. }
  1715. }
  1716. }
  1717. return outObj;
  1718. }, authority, this.execNum);
  1719. // 主图下载
  1720. if(this.settingArr.indexOf('mainImg') > -1){
  1721. for(let j = 0; j < imgInfo.mainImg.length; j++){
  1722. let fileName = imgInfo.mainImg[j].split('/').pop();
  1723. if(fileName){
  1724. let queryIndex = fileName.indexOf('?');
  1725. if (queryIndex !== -1) {
  1726. fileName = fileName.substr(0, queryIndex);
  1727. }
  1728. let num = Number(j) + 1;
  1729. let suffix = '';
  1730. if(fileName.lastIndexOf('.') > -1){
  1731. suffix = fileName.substr(fileName.lastIndexOf('.'));
  1732. }
  1733. if (!fs.existsSync(urlInfo.newPath + '\\主图')) {
  1734. fs.mkdirSync(urlInfo.newPath + '\\主图');
  1735. }
  1736. let outputPath = urlInfo.newPath + '\\主图\\主图' + num + suffix;
  1737. await this.downloadImage(imgInfo.mainImg[j], outputPath, urlInfo);
  1738. }
  1739. }
  1740. }
  1741. // sku图片下载
  1742. if(this.settingArr.indexOf('skuImg') > -1){
  1743. for(let j = 0; j < imgInfo.skuImg.length; j++){
  1744. let fileName = imgInfo.skuImg[j].split('/').pop();
  1745. if(fileName){
  1746. let queryIndex = fileName.indexOf('?');
  1747. if (queryIndex !== -1) {
  1748. fileName = fileName.substr(0, queryIndex);
  1749. }
  1750. let num = Number(j) + 1;
  1751. let suffix = '';
  1752. if(fileName.lastIndexOf('.') > -1){
  1753. suffix = fileName.substr(fileName.lastIndexOf('.'));
  1754. }
  1755. if (!fs.existsSync(urlInfo.newPath + '\\sku图')) {
  1756. fs.mkdirSync(urlInfo.newPath + '\\sku图');
  1757. }
  1758. let outputPath = urlInfo.newPath + '\\sku图\\sku图' + num + suffix;
  1759. await this.downloadImage(imgInfo.skuImg[j], outputPath, urlInfo);
  1760. }
  1761. }
  1762. }
  1763. //详情图下载
  1764. if(this.settingArr.indexOf('detailImg') > -1){
  1765. for(let j = 0; j < imgInfo.detailImg.length; j++){
  1766. let fileName = imgInfo.detailImg[j].split('/').pop();
  1767. if(fileName){
  1768. let queryIndex = fileName.indexOf('?');
  1769. if (queryIndex !== -1) {
  1770. fileName = fileName.substr(0, queryIndex);
  1771. }
  1772. let num = Number(j) + 1;
  1773. let suffix = '';
  1774. if(fileName.lastIndexOf('.') > -1){
  1775. suffix = fileName.substr(fileName.lastIndexOf('.'));
  1776. }
  1777. if (!fs.existsSync(urlInfo.newPath + '\\详情图')) {
  1778. fs.mkdirSync(urlInfo.newPath + '\\详情图');
  1779. }
  1780. let outputPath = urlInfo.newPath + '\\详情图\\' + '详情图' + num + suffix;
  1781. await this.downloadImage(imgInfo.detailImg[j], outputPath, urlInfo);
  1782. }
  1783. }
  1784. }
  1785. //评论图下载
  1786. // if(this.settingArr.indexOf('commentImg') > -1){
  1787. // for(let j = 0; j < imgInfo.commentImg.length; j++){
  1788. // let fileName = imgInfo.commentImg[j].split('/').pop();
  1789. // if(fileName){
  1790. // let queryIndex = fileName.indexOf('?');
  1791. // if (queryIndex !== -1) {
  1792. // fileName = fileName.substr(0, queryIndex);
  1793. // }
  1794. // if (!fs.existsSync(urlInfo.newPath + '\\评论图')) {
  1795. // fs.mkdirSync(urlInfo.newPath + '\\评论图');
  1796. // }
  1797. // let outputPath = urlInfo.newPath + '\\评论图\\' + fileName;
  1798. // await this.downloadImage(imgInfo.commentImg[j], outputPath, urlInfo);
  1799. // }
  1800. // }
  1801. // }
  1802. //视频下载
  1803. if(this.settingArr.indexOf('video') > -1){
  1804. for(let j = 0; j < imgInfo.video.length; j++){
  1805. let fileName = imgInfo.video[j].split('/').pop();
  1806. if(fileName){
  1807. let queryIndex = fileName.indexOf('?');
  1808. if (queryIndex !== -1) {
  1809. fileName = fileName.substr(0, queryIndex);
  1810. }
  1811. if (!fs.existsSync(urlInfo.newPath + '\\视频')) {
  1812. fs.mkdirSync(urlInfo.newPath + '\\视频');
  1813. }
  1814. let outputPath = urlInfo.newPath + '\\视频\\' + fileName;
  1815. await this.downloadImage(imgInfo.video[j], outputPath, urlInfo);
  1816. }
  1817. }
  1818. }
  1819. await browser.close();
  1820. },
  1821. // 5-小红书下载
  1822. async redDownload(urlInfo){
  1823. let task = await new Promise((resolve,reject) =>{
  1824. (async () => {
  1825. try{
  1826. let authority = this.$refs.headerRef.authority.isAuthority;
  1827. let number = 0;
  1828. urlInfo.status = '2';
  1829. urlInfo.num = 0;
  1830. puppeteer.use(StealthPlugin());
  1831. const browser = await puppeteer.launch({
  1832. executablePath: puppeteer.executablePath().replace('win32-1', 'win64-1'),
  1833. userDataDir: os.tmpdir() + separator + 'chrome-data-capture',
  1834. args: [
  1835. '--start-maximized',
  1836. '--no-sandbox',
  1837. '--disable-setuid-sandbox',
  1838. '--disable-blink-features=AutomationControlled',
  1839. ]
  1840. });
  1841. const page = await browser.newPage();
  1842. await page.goto(urlInfo.url, {waitUntil : 'networkidle2'});
  1843. if(urlInfo.title){
  1844. if (fs.existsSync(this.downloadDir + separator + pjson.softInfo.softName + separator + urlInfo.title)) {
  1845. urlInfo.newPath = this.downloadDir + separator + pjson.softInfo.softName + separator + urlInfo.title;
  1846. } else {
  1847. fs.mkdirSync(this.downloadDir + separator + pjson.softInfo.softName + separator + urlInfo.title);
  1848. urlInfo.newPath = this.downloadDir + separator + pjson.softInfo.softName + separator + urlInfo.title;
  1849. }
  1850. }else{
  1851. await this.getTitle(page, urlInfo); // 生成页面标题对应的文件夹
  1852. }
  1853. urlInfo.status = '3';
  1854. //'blob:https://www.xiaohongshu.com/3696ba14-7658-4d60-b897-1a7608737e15'
  1855. let responseVideo = [];
  1856. page.on('response', async(response) => {
  1857. // 检查响应的 MIME 类型是否以 'video/' 开头
  1858. if (response.headers()['content-type'] && response.headers()['content-type'].startsWith('video/')) {
  1859. if(responseVideo.indexOf(response.url()) < 0){
  1860. responseVideo.push(response.url());
  1861. }
  1862. }
  1863. });
  1864. let noteImg = await page.$$('img[class^=note-slider-img]');
  1865. if(noteImg.length == 0){
  1866. let refreshImg = await page.$$('.xgplayer-error-refresh');
  1867. let startImg = await page.$$('.xgplayer-start');
  1868. //点击播放生成视频
  1869. if(refreshImg.length == 0){
  1870. await page.waitForSelector('.xgplayer-start', { visible: true });
  1871. await page.click('.xgplayer-start');
  1872. }else{
  1873. await page.waitForSelector('.xgplayer-error-refresh', { visible: true });
  1874. await page.click('.xgplayer-error-refresh');
  1875. await page.click('.xgplayer-error-refresh');
  1876. await page.click('.xgplayer-error-refresh');
  1877. }
  1878. }
  1879. //detailImg:详情图;skuImg:sku图片;commentImg: 评论图;video: 视频
  1880. const imgInfo = await page.evaluate((authority, execNum) => {
  1881. let outObj = {
  1882. mainImg: [],
  1883. detailImg: [],
  1884. skuImg: [],
  1885. commentImg: [],
  1886. video: []
  1887. };
  1888. // 正则表达式匹配字符 重写图片路径
  1889. let regex = /\.(.{3,4})_[0-9a-zA-z]+\.(.{3,4})_\.(.{3,4})/;
  1890. //主图
  1891. let arr1 = document.querySelectorAll('img[class^=note-slider-img]');
  1892. for(let i=0; i< arr1.length; i++){
  1893. let mainImgUrl = arr1[i].src;
  1894. let result = regex.exec(mainImgUrl);
  1895. if(result){
  1896. mainImgUrl = mainImgUrl.replace(result[0], '.'+result[1]);
  1897. }
  1898. if(!authority && i < execNum){
  1899. outObj.mainImg.push(mainImgUrl);
  1900. }
  1901. if(authority){
  1902. outObj.mainImg.push(mainImgUrl);
  1903. }
  1904. }
  1905. // 视频
  1906. let arr5 = document.querySelectorAll('video.lib-video');
  1907. for(let i=0; i< arr5.length; i++){
  1908. if(outObj.video.indexOf(arr5[i].src) == -1){
  1909. if(!authority && i < execNum){
  1910. outObj.video.push(arr5[i].src);
  1911. }
  1912. if(authority){
  1913. outObj.video.push(arr5[i].src);
  1914. }
  1915. }
  1916. }
  1917. return outObj;
  1918. }, authority, this.execNum);
  1919. if(imgInfo.mainImg.length >= 3){
  1920. imgInfo.mainImg = imgInfo.mainImg.slice(1, imgInfo.mainImg.length-1); //小红书轮播图第一个/最后一个和内容重复去掉
  1921. }
  1922. imgInfo.video = responseVideo;
  1923. // 主图下载
  1924. for(let j = 0; j < imgInfo.mainImg.length; j++){
  1925. let fileName = imgInfo.mainImg[j].split('/').pop();
  1926. if(fileName){
  1927. let queryIndex = fileName.indexOf('?');
  1928. if (queryIndex !== -1) {
  1929. fileName = fileName.substr(0, queryIndex);
  1930. }
  1931. let num = Number(j) + 1;
  1932. let suffix = '.jpg';
  1933. if(fileName.lastIndexOf('.') > -1){
  1934. suffix = fileName.substr(fileName.lastIndexOf('.'));
  1935. }
  1936. let outputPath = urlInfo.newPath + '\\文章图' + num + suffix;
  1937. await this.downloadImage(imgInfo.mainImg[j], outputPath, urlInfo);
  1938. }
  1939. }
  1940. //视频下载
  1941. for(let j = 0; j < imgInfo.video.length; j++){
  1942. let fileName = imgInfo.video[j].split('/').pop();
  1943. if(fileName){
  1944. let queryIndex = fileName.indexOf('?');
  1945. if (queryIndex !== -1) {
  1946. fileName = fileName.substr(0, queryIndex);
  1947. }
  1948. let outputPath = urlInfo.newPath + '\\' + fileName;
  1949. await this.downloadImage(imgInfo.video[j], outputPath, urlInfo);
  1950. }
  1951. }
  1952. await browser.close();
  1953. urlInfo.status = '4';
  1954. resolve(true);
  1955. this.loading = false;
  1956. }catch(e){
  1957. urlInfo.status = '5';
  1958. reject(e);
  1959. this.showError(e);
  1960. }
  1961. })();
  1962. });
  1963. },
  1964. //
  1965. downloadExample(){
  1966. let url = 'https://www.xingyousoft.com/soft/XYCapture/example.xlsx';
  1967. if (!fs.existsSync(this.downloadDir + separator + pjson.softInfo.softName)) {
  1968. fs.mkdirSync(this.downloadDir + separator + pjson.softInfo.softName);
  1969. }
  1970. let path = this.downloadDir + separator + pjson.softInfo.softName + '\\链接模板下载.xlsx';
  1971. this.downloadImage(url, path, 'example');
  1972. },
  1973. // 下载网址链接的图片
  1974. async downloadImage(imageUrl, outputPath, urlInfo) {
  1975. let _this = this;
  1976. let received_bytes = 0;
  1977. let total_bytes = 0;
  1978. try {
  1979. let req = request({
  1980. method: 'GET', uri: imageUrl, strictSSL: false
  1981. });
  1982. let out = fs.createWriteStream(outputPath);
  1983. req.pipe(out);
  1984. return new Promise((resolve, reject) => {
  1985. req.on('response', (data) => {
  1986. total_bytes = parseInt(data.headers['content-length']);
  1987. const status = data.statusCode;
  1988. if (status < 200 || status >= 300) {
  1989. //reject(false);
  1990. this.$notify.error({
  1991. title: '网络图片访问异常!- 1',
  1992. message: imageUrl.slice(0,50)
  1993. });
  1994. }else if(isNaN(total_bytes)){
  1995. //reject(false);
  1996. this.$notify.error({
  1997. title: '网络图片访问异常!- 2',
  1998. message: imageUrl.slice(0,50)
  1999. });
  2000. }else{
  2001. // console.log('下载中...')
  2002. }
  2003. });
  2004. req.on('data', (chunk) => {
  2005. received_bytes += chunk.length;
  2006. });
  2007. req.on('end', ()=> {
  2008. if(urlInfo != 'example'){
  2009. urlInfo.num += 1;
  2010. }else{
  2011. this.$msgbox({
  2012. title: '消息',
  2013. message: '模板下载成功,保存位置:' + this.downloadDir + separator + pjson.softInfo.softName,
  2014. showCancelButton: true,
  2015. confirmButtonText: '去查看',
  2016. cancelButtonText: '取消',
  2017. }).then(action => {
  2018. this.openFolder();
  2019. }).catch(action => {
  2020. });
  2021. }
  2022. //console.log('下载完成', outputPath)
  2023. resolve(true);
  2024. });
  2025. });
  2026. } catch (error) {
  2027. console.error(imageUrl, `Failed to download image: ${error.message}`);
  2028. throw error;
  2029. }
  2030. },
  2031. // 获取页面标题 - 生成对应的文件夹
  2032. async getTitle(page, urlInfo){
  2033. // 已页面标题作为新建文件夹,保留前60个字
  2034. let title = await page.title();
  2035. if(title){
  2036. title = title.substring(0, 60);
  2037. if(this.containsAnyChar(title, ['\\', '/', ':', '*', '?', '"', '<', '>', '|'])){ //判断是否含有特殊字符
  2038. title = title.replace(/[\\|/|:|*|?|"|<|>||]/g, "");
  2039. }
  2040. if (fs.existsSync(this.downloadDir + separator + pjson.softInfo.softName + separator + title)) {
  2041. urlInfo.newPath = this.downloadDir + separator + pjson.softInfo.softName + separator + title;
  2042. } else {
  2043. fs.mkdirSync(this.downloadDir + separator + pjson.softInfo.softName + separator + title);
  2044. urlInfo.newPath = this.downloadDir + separator + pjson.softInfo.softName + separator + title;
  2045. }
  2046. }
  2047. },
  2048. // 下载base64位的图片
  2049. async downloadBaseImage(base64String, outputPath, urlInfo) {
  2050. const buffer = Buffer.from(base64String, 'base64');
  2051. const writeStream = fs.createWriteStream(outputPath);
  2052. writeStream.write(buffer);
  2053. writeStream.end();
  2054. writeStream.on('finish', () => {
  2055. urlInfo.num += 1;
  2056. });
  2057. // 监听错误事件
  2058. writeStream.on('error', (err) => {
  2059. console.error('base64位写入文件时出错:', err);
  2060. });
  2061. },
  2062. // 错误提示
  2063. showError(e){
  2064. let str = '';
  2065. if(e.toString().indexOf('ERR_NAME_NOT_RESOLVE') > -1){
  2066. str = '无法解析该网址,请查看网址是否正确!-1';
  2067. }else if(e.toString().indexOf('Cannot navigate to invalid URL') > -1){
  2068. str = '无效的网址,请查看网址格式是否正确!-2';
  2069. }else if(e.toString().indexOf('ERR_CONNECTION_TIMED_OUT') > -1){
  2070. str = '链接请求超时,请查看网络状态!-3';
  2071. }else if(e.toString().indexOf('TimeoutError') > -1){
  2072. str = '链接请求超时,请查看网络状态!-4';
  2073. }else if(e.toString().indexOf('operation not permitted') > -1){
  2074. str = '权限受限,请以管理员权限运行软件!-5';
  2075. }else if(e.toString().indexOf('browser has disconnected') > -1){
  2076. str = '浏览器断开链接!-6';
  2077. }else{
  2078. str = e.toString();
  2079. //console.log(e);
  2080. }
  2081. this.loading = false;
  2082. this.$notify.error({
  2083. title: '提示',
  2084. message: str
  2085. });
  2086. },
  2087. // 是否包含特殊字符
  2088. containsAnyChar(str, charsArray) {
  2089. for (let i = 0; i < charsArray.length; i++) {
  2090. if (str.includes(charsArray[i])) {
  2091. return true;
  2092. }
  2093. }
  2094. return false;
  2095. },
  2096. // 随机生成字符
  2097. randomString(length) {
  2098. let result = '';
  2099. const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
  2100. const charactersLength = characters.length;
  2101. for (let i = 0; i < length; i++ ) {
  2102. result += characters.charAt(Math.floor(Math.random() * charactersLength));
  2103. }
  2104. return result;
  2105. }
  2106. }
  2107. };
  2108. </script>
  2109. <style lang="scss">
  2110. @import "../assets/css/fontx/iconfont.css";
  2111. @import "../assets/css/home.scss";
  2112. .ivu-input-number-controls-outside-btn i {
  2113. font-weight: 800;
  2114. }
  2115. .update-point {
  2116. display: inline-block;
  2117. width: 8px;
  2118. height: 8px;
  2119. border-radius: 8px;
  2120. background: #ff0000;
  2121. top: 14px;
  2122. position: absolute;
  2123. left: -13px;
  2124. }
  2125. .menu-item {
  2126. padding: 8px 0;
  2127. font-size: 14px;
  2128. .iconfont {
  2129. font-size: 32px;
  2130. }
  2131. &:hover,
  2132. &.active {
  2133. color: #ed4014;
  2134. }
  2135. }
  2136. .ivu-progress-show-info .ivu-progress-outer {
  2137. padding-right: 40px !important;
  2138. margin-right: -40px !important;
  2139. }
  2140. .tips {
  2141. text-align: center;
  2142. padding: 10px 0;
  2143. color: #ed4014;
  2144. font-size: 12px;
  2145. }
  2146. .handle-desc {
  2147. display: inline-block;
  2148. width: calc(100% - 100px);
  2149. overflow: hidden;
  2150. }
  2151. .ivu-menu-submenu-title {
  2152. font-weight: 600;
  2153. }
  2154. .ivu-menu .ivu-menu-item {
  2155. line-height: 1;
  2156. }
  2157. // new-el
  2158. .el-menu {
  2159. border-right: none !important;
  2160. }
  2161. .cmenu-item {
  2162. padding: 0 20px 20px;
  2163. margin-bottom: 15px;
  2164. .cmenu-title {
  2165. font-size: 18px;
  2166. font-weight: 600;
  2167. padding-bottom: 20px;
  2168. }
  2169. .citem-nav {
  2170. text-align: center;
  2171. border-radius: 10px;
  2172. min-height: 110px;
  2173. padding: 15px 0;
  2174. background-color: #fff;
  2175. font-size: 15px;
  2176. cursor: pointer;
  2177. &.bg-linear1 {
  2178. color: #fff;
  2179. font-size: 20px;
  2180. background: linear-gradient(to right bottom, #2A56CA, #5795F4);
  2181. }
  2182. &.bg-linear2 {
  2183. color: #fff;
  2184. font-size: 20px;
  2185. background: linear-gradient(to right top, #147FBB, #5EB3E3);
  2186. }
  2187. &.bg-linear3 {
  2188. color: #fff;
  2189. font-size: 20px;
  2190. background: linear-gradient(to right bottom, #2F9E8A, #56CDB1);
  2191. }
  2192. &:hover {
  2193. margin-top: -5px;
  2194. box-shadow: 3px 3px 6px #ccc, -3px -3px 6px #ccc;
  2195. }
  2196. .citem-img {
  2197. width: 50px;
  2198. margin-bottom: 10px;
  2199. }
  2200. }
  2201. }
  2202. .popper-open{
  2203. text-align: center !important;
  2204. padding: 10px !important;
  2205. background: #303133 !important;
  2206. color: #fff !important;
  2207. min-width: 120px !important;
  2208. opacity: 0.8;
  2209. }
  2210. .popper-open[x-placement^=bottom] .popper__arrow::after{
  2211. border-bottom-color: #303133 !important;
  2212. }
  2213. textarea.el-textarea__inner{
  2214. height: 100% !important;
  2215. font-family: "Helvetica Neue",Helvetica,"PingFang SC","Hiragino Sans GB","Microsoft YaHei","微软雅黑",Arial,sans-serif;
  2216. }
  2217. .set-item{
  2218. margin-right: 15px;
  2219. .set-title{
  2220. font-size: 13px;
  2221. }
  2222. }
  2223. .outarea{
  2224. height: 100%;
  2225. border: 1px solid #DCDFE6;
  2226. background-color: #4851a415;
  2227. padding: 15px;
  2228. font-size: 20px;
  2229. overflow: hidden auto;
  2230. }
  2231. .outtext{
  2232. height: 100%;
  2233. font-size: 20px;
  2234. overflow: hidden auto;
  2235. textarea{
  2236. background-color: #4851a415;
  2237. }
  2238. }
  2239. .pin-tips{
  2240. font-size: 14px;
  2241. position: absolute;
  2242. bottom: 10px;
  2243. color: #ff0000;
  2244. left: 0;
  2245. right: 0;
  2246. margin: auto;
  2247. text-align: center;
  2248. }
  2249. .outarea.red-border{
  2250. border: 1px solid #F56C6C;
  2251. }
  2252. .outtext.red-border textarea{
  2253. border: 1px solid #F56C6C;
  2254. }
  2255. h3{
  2256. margin: 0;
  2257. }
  2258. .m-image{
  2259. width: 20px;
  2260. margin-right: 5px;
  2261. }
  2262. .dialog-footer-center{
  2263. text-align: center;
  2264. }
  2265. </style>