home.vue 59 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871
  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="1">
  15. <img src="../assets/image/m-alibaba.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="3">
  21. <img src="../assets/image/m-tmall.png" class="m-image"/><span slot="title">天猫</span>
  22. </el-menu-item>
  23. <el-menu-item index="4">
  24. <img src="../assets/image/m-taobao.png" class="m-image"/><span slot="title">淘宝</span>
  25. </el-menu-item>
  26. <el-menu-item index="10">
  27. <img src="../assets/image/m-chrome.png" class="m-image"/><span slot="title">其他网址</span>
  28. </el-menu-item>
  29. </el-submenu>
  30. <el-submenu index="b">
  31. <template slot="title"><img src="../assets/image/m-edit.png" class="m-image"/>图片处理</template>
  32. <el-menu-item index="2-1">
  33. <img src="../assets/image/m-geshi.png" class="m-image"/><span slot="title">格式转换</span>
  34. </el-menu-item>
  35. <el-menu-item index="2-2">
  36. <img src="../assets/image/m-yasuo.png" class="m-image"/><span slot="title">图片压缩</span>
  37. </el-menu-item>
  38. <el-menu-item index="2-3">
  39. <img src="../assets/image/m-chicun.png" class="m-image"/><span slot="title">修改尺寸</span>
  40. </el-menu-item>
  41. <el-menu-item index="2-5">
  42. <img src="../assets/image/m-shuiyin.png" class="m-image"/><span slot="title">添加水印</span>
  43. </el-menu-item>
  44. </el-submenu>
  45. </el-menu>
  46. </el-aside>
  47. <el-container>
  48. <el-header height="45px" style="background-color: #fafafa; padding: 0 10px;">
  49. <soft-header ref="headerRef" @update-soft="updateSoft()" @export-file="exportFile" @login-url="loginUrl"></soft-header>
  50. </el-header>
  51. <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>
  52. <el-main v-show="['1', '2', '3', '4', '10'].indexOf(menuIndex) > -1" ref="el-main" style="background-color: #fafafa;">
  53. <template>
  54. <div class="content-top">
  55. <div>
  56. <el-button-group>
  57. <el-button type="primary" size="mini" icon="el-icon-circle-plus-outline"
  58. @click="addVisible = true;">添加链接</el-button>
  59. <el-button type="primary" size="mini" icon="el-icon-upload"
  60. @click="pickLink()">导入链接</el-button>
  61. <el-button type="primary" size="mini" icon="el-icon-delete"
  62. @click="clearList()">清空链接</el-button>
  63. </el-button-group>
  64. <el-link type="info" style="margin-left: 20px; vertical-align:baseline;" @click="downloadExample()">模板下载<i class="el-icon-download"></i></el-link>
  65. </div>
  66. <el-row type="flex" style="align-items: center;">
  67. <div class="set-item">
  68. <span class="set-title">保存目录:</span>
  69. <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>
  70. <el-popover placement="bottom" popper-class="popper-open" trigger="hover" content="打开保存目录">
  71. <i class="el-icon-folder-opened" slot="reference" style="padding-left: 5px; cursor: pointer; font-size: 22px; vertical-align: middle;" @click="openFolder()"></i>
  72. </el-popover>
  73. </div>
  74. <el-button type="danger" @click="exportFile()" :loading="loading">开始下载</el-button>
  75. </el-row>
  76. </div>
  77. <div style="padding: 20px 20px 0 20px; height: calc(100% - 62px);">
  78. <el-row type="flex" justify="space-between">
  79. <h3>
  80. <span v-if="menuIndex == '1'">阿里巴巴 - </span>
  81. <span v-if="menuIndex == '2'">京东 - </span>
  82. <span v-if="menuIndex == '3'">天猫 - </span>
  83. <span v-if="menuIndex == '4'">淘宝 - </span>
  84. <span v-if="menuIndex == '10'">网页 - </span>
  85. 图片下载
  86. </h3>
  87. <el-link v-if="tbStatus == 3" :underline="false" type="danger" style="text-align: center; font-size: 13px;">登录完成后请关闭浏览器</el-link>
  88. </el-row>
  89. <div style="padding: 15px 0 20px;">
  90. <el-row type="flex" justify="space-between">
  91. <div v-if="menuIndex == '10'" style="padding-top: 10px;">
  92. <label>下载类型:</label>
  93. <el-checkbox :value="true" style="opacity: 0.6; cursor: not-allowed;">图片</el-checkbox>
  94. </div>
  95. <div v-if="menuIndex < 10" style="padding-top: 10px;">
  96. <label>下载类型:</label>
  97. <el-checkbox :value="true" style="opacity: 0.6; cursor: not-allowed;">主图</el-checkbox>
  98. <el-checkbox v-model="settingData.detailImg" >详情图</el-checkbox>
  99. <el-checkbox v-model="settingData.skuImg" >SKU图</el-checkbox>
  100. <el-checkbox v-model="settingData.commentImg" v-if="menuIndex == '3' || menuIndex == '4'">评论图</el-checkbox>
  101. <el-checkbox v-model="settingData.video" >视频</el-checkbox>
  102. </div>
  103. <!-- 天猫/淘宝 -->
  104. <template v-if="menuIndex == '3' || menuIndex == '4'">
  105. <div>
  106. <div>
  107. <el-tag type="info" size="mini" v-if="tbStatus == 1">未检测</el-tag>
  108. <el-tag type="success" size="mini" v-if="tbStatus == 2">账号已登录</el-tag>
  109. <el-link type="danger" v-if="tbStatus == 3" @click="loginUrl('https://login.taobao.com')">未登录,点我去登录</el-link>
  110. <el-button size="mini" type="warning" :loading="checkLoading" style="margin-left: 10px;" :disabled='tbStatus == 2' @click="checkLogin">检测登录状态</el-button>
  111. </div>
  112. </div>
  113. </template>
  114. </el-row>
  115. </div>
  116. <div class="table-scroll">
  117. <!-- 1、 -->
  118. <vxe-table ref="xTable" show-overflow class="img-table" max-height="100%" empty-text="没有更多数据了!" :loading="tabLoading" :row-config="{isHover: true}"
  119. :loading-config="{icon: 'vxe-icon-indicator roll', text: '列表加载中...'}" :data="this[listStr+'List']" :scroll-y="{enabled: true}">
  120. <vxe-column type="seq" width="60"></vxe-column>
  121. <vxe-column field="title" title="目录名称" width="200">
  122. <template #default="{ row, rowIndex }">
  123. <span v-if="row.title">{{row.title}}</span>
  124. <el-tag size="mini" v-else>默认使用网页标题</el-tag>
  125. </template>
  126. </vxe-column>
  127. <vxe-column field="url" title="网页链接"></vxe-column>
  128. <vxe-column field="status" title="下载状态" width="200">
  129. <template #default="{ row }">
  130. <template v-if="row.status == '1'">
  131. <i class="el-icon-info" style="font-size: 16px; color: #999;"></i>
  132. <span>待操作</span>
  133. </template>
  134. <template v-if="row.status == '2'">
  135. <i class="el-icon-loading" style="font-size: 16px; color: #999;"></i>
  136. <span>任务处理中...</span>
  137. </template>
  138. <template v-if="row.status == '3'">
  139. <i class="el-icon-loading" style="font-size: 16px; color: #999;"></i>
  140. <span>图片下载中..<span v-if="row.num > 0">第{{row.num}}张</span></span>
  141. </template>
  142. <template v-if="row.status == '4'">
  143. <i class="el-icon-success" style="font-size: 16px; color: #19be6b;"></i>
  144. <span>下载完成</span>
  145. </template>
  146. <template v-if="row.status == '5'">
  147. <i class="el-icon-error" style="font-size: 16px; color: #ed4014;"></i>
  148. <span>网络异常,请重试!</span>
  149. </template>
  150. </template>
  151. </vxe-column>
  152. <vxe-column title="操作" width="80">
  153. <template #default="{ row, rowIndex }">
  154. <i class="el-icon-delete cur-pointer" style="font-size: 20px;" @click="delFile(rowIndex, 'alibaba')"></i>
  155. </template>
  156. </vxe-column>
  157. </vxe-table>
  158. </div>
  159. </div>
  160. </template>
  161. <el-dialog title="添加链接" :visible.sync="addVisible" width="500px" :close-on-click-modal="false" :close-on-press-escape="false" :show-close="false">
  162. <div>
  163. <el-form label-position="right" label-width="80px" :rules="rules" :model="formData" ref="formData">
  164. <el-form-item label="目录名称" prop="title">
  165. <el-input v-model="formData.title" placeholder="为空则默认使用网页标题前20个字符"></el-input>
  166. </el-form-item>
  167. <el-form-item label="网页链接" prop="url">
  168. <el-input type="textarea" :rows="10" :placeholder="'请输入网址链接(例:' + exampleUrl[menuIndex-1] + ')'" v-model="formData.url"></el-input>
  169. </el-form-item>
  170. </el-form>
  171. </div>
  172. <span slot="footer" class="dialog-footer">
  173. <el-button @click="addVisible = false; $refs['formData'].resetFields();">取 消</el-button>
  174. <el-button type="primary" @click="onSubmit">确 定</el-button>
  175. </span>
  176. </el-dialog>
  177. </el-main>
  178. <el-footer height="48px">
  179. <!-- 更新 -->
  180. <soft-update ref="updateRef" :showDowload="dowloadModel" :dowloadFinish="finishModel"></soft-update>
  181. </el-footer>
  182. </el-container>
  183. </el-container>
  184. </el-container>
  185. </div>
  186. </template>
  187. <script>
  188. import os from 'os'
  189. import fs from 'fs'
  190. import request from 'request'
  191. import xlsx from 'node-xlsx';
  192. import softUpdate from './update.vue';
  193. import softHeader from './header.vue';
  194. import softImg from './img.vue';
  195. import electronApi from '@/utils/electronApi';
  196. import pjson from '/package.json'
  197. import puppeteer from 'puppeteer'
  198. let separator = '';
  199. if (os.platform == 'linux') {
  200. separator = '/'
  201. } else {
  202. separator = '\\'
  203. }
  204. // let chromePath = process.cwd() + '\\resources\\app\\node_modules\\puppeteer\\.local-chromium\\win64-1045629\\chrome-win\\chrome.exe';
  205. // if (process.env.NODE_ENV == 'development') {
  206. // chromePath = process.cwd() + '\\node_modules\\puppeteer\\.local-chromium\\win64-1045629\\chrome-win\\chrome.exe';
  207. // }
  208. export default {
  209. name: 'landing-page',
  210. components: {
  211. softUpdate,
  212. softHeader,
  213. softImg
  214. },
  215. data() {
  216. return {
  217. addVisible: false,
  218. formData: {
  219. title: '',
  220. url: ''
  221. },
  222. rules:{ //
  223. title: [
  224. { min: 0, max: 20, message: '不能超过 20 个字符', trigger: 'blur' },
  225. { pattern: /^[^\\/:*?"<>|]*$/, message: '标题中不能包含 \\ / : * ? " < > |', trigger: 'blur' }
  226. ],
  227. url: [
  228. { required: true, message: '请输入网页链接', trigger: 'blur' },
  229. { pattern: /^(http|https):\/\/.+$/, message: '请输入正确的网址链接(http://或https://开头)', trigger: 'blur' }
  230. ],
  231. },
  232. tabLoading: false,
  233. alibabaList: [],
  234. jdList: [],
  235. tbList: [],
  236. tmallList: [],
  237. commonList: [],
  238. productName: pjson.softInfo.softName,
  239. imgUrl: this.$api.imgUrl,
  240. imgSrc: '',
  241. menuIndex: '1',
  242. jdBrowser: '', // 打开京东的浏览器
  243. settingData: {
  244. detailImg: true,
  245. skuImg: true,
  246. commentImg: true,
  247. video: true,
  248. },
  249. exampleUrl: ['https://www.1688.com', 'https://www.jd.com', 'https://www.tmall.com', 'https://www.taobao.com'],
  250. fileList: [],
  251. downloadDir: os.userInfo().homedir + separator + "Downloads",
  252. dowloadModel: false,
  253. finishModel: false,
  254. loading: false,
  255. checkLoading: false, //点击检测登录状态
  256. tbStatus: 1, // 1、未检测 2、已经登录 3、未登录
  257. execLimit: 2,
  258. execNum: 5, // 限制5张
  259. };
  260. },
  261. computed: {
  262. listStr: function(){
  263. let str = 'alibaba';
  264. switch(this.menuIndex){
  265. case '1':
  266. str = 'alibaba';
  267. break;
  268. case '2':
  269. str = 'jd';
  270. break;
  271. case '3':
  272. str = 'tmall';
  273. break;
  274. case '4':
  275. str = 'tb';
  276. break;
  277. case '10':
  278. str = 'common';
  279. break;
  280. }
  281. return str;
  282. }
  283. },
  284. async mounted() {
  285. this.$refs.updateRef.updateSoft(true);
  286. let homedir = os.userInfo().homedir;
  287. if (fs.existsSync(homedir + separator + "Desktop")) {
  288. this.downloadDir = homedir + separator + "Desktop"
  289. } else {
  290. this.downloadDir = homedir + separator + "Downloads"
  291. }
  292. if (!fs.existsSync(os.tmpdir() + separator + 'chrome-data-capture')) {
  293. fs.mkdirSync(os.tmpdir() + separator + 'chrome-data-capture');
  294. }
  295. // 打开浏览器
  296. const {
  297. shell
  298. } = require('electron');
  299. const links = document.querySelectorAll('a[href]');
  300. links.forEach(link => {
  301. link.addEventListener('click', e => {
  302. const url = link.getAttribute('href');
  303. e.preventDefault();
  304. shell.openExternal(url);
  305. });
  306. });
  307. },
  308. methods: {
  309. checkAuthority(){
  310. let authority = this.$refs.headerRef.authority;
  311. this.$refs.imgRef.authority = authority;
  312. },
  313. setMenuIndex(index){
  314. this.menuIndex = index;
  315. if(index.indexOf('2-') > -1){
  316. let num = Number(index.split('-')[1]);
  317. this.$refs.imgRef.setMenuIndex(num);
  318. }
  319. },
  320. // 选择目录
  321. pickPath() {
  322. this.$refs['upload-input'].blur();
  323. electronApi.call('pickDir', []).then((path) => {
  324. if (path) {
  325. this.downloadDir = path;
  326. }
  327. });
  328. },
  329. // 打开自定义下载目录
  330. openFolder() {
  331. let path = this.downloadDir;
  332. if (fs.existsSync(this.downloadDir + separator + pjson.softInfo.softName)) {
  333. path = this.downloadDir + separator + pjson.softInfo.softName;
  334. } else {
  335. fs.mkdirSync(this.downloadDir + separator + pjson.softInfo.softName);
  336. path = this.downloadDir + separator + pjson.softInfo.softName;
  337. }
  338. electronApi.call('showItemInfolder', [path + '\\tty.tty'])
  339. },
  340. openVip() {
  341. this.$refs.headerRef.openVip();
  342. },
  343. updateSoft() {
  344. this.$refs.updateRef.updateSoft();
  345. },
  346. // 删除文件
  347. delFile(rowIndex, type){
  348. this.$confirm('确认删除此行数据吗?', '提示', {
  349. confirmButtonText: '确定',
  350. cancelButtonText: '取消',
  351. type: 'warning'
  352. }).then(() => {
  353. this[type+'List'].splice(rowIndex, 1);
  354. this[type+'List'].splice(rowIndex, 1);
  355. if(this[type+'List'].length == 0) {
  356. this.clearList();
  357. }
  358. }).catch(() => {
  359. });
  360. },
  361. // 清除列表
  362. clearList() {
  363. switch(this.menuIndex){
  364. case '1':
  365. this.alibabaList = [];
  366. break;
  367. case '2':
  368. this.jdList = [];
  369. break;
  370. case '3':
  371. this.tmallList = [];
  372. break;
  373. case '4':
  374. this.tbList = [];
  375. break;
  376. case '10':
  377. this.commonList = [];
  378. break;
  379. }
  380. },
  381. // 提交表单
  382. onSubmit(){
  383. this.$refs['formData'].validate((valid) => {
  384. if (valid) {
  385. let info = {
  386. url: this.formData.url,
  387. title: this.formData.title,
  388. status: '1',
  389. num: 0,
  390. newPath: ''
  391. }
  392. switch(this.menuIndex){
  393. case '1':
  394. this.alibabaList.push(info);
  395. break;
  396. case '2':
  397. this.jdList.push(info);
  398. break;
  399. case '3':
  400. this.tmallList.push(info);
  401. break;
  402. case '4':
  403. this.tbList.push(info);
  404. break;
  405. case '10':
  406. this.commonList.push(info);
  407. break;
  408. }
  409. this.$refs['formData'].resetFields();
  410. this.addVisible = false;
  411. } else {
  412. return false;
  413. }
  414. });
  415. },
  416. async pickLink() {
  417. const spinLoad = this.$loading();
  418. await electronApi.call('pickFile', ['xlsx,xls', true]).then(async (path) => {
  419. spinLoad.close();
  420. if(path.length > 0){
  421. this.$notify({
  422. title: '提示',
  423. message: '导入成功',
  424. type: 'success'
  425. });
  426. let workSheetsFromBuffer = xlsx.parse(fs.readFileSync(path[0]));
  427. if(workSheetsFromBuffer && workSheetsFromBuffer.length > 0){
  428. let errMsg = "";
  429. workSheetsFromBuffer[0].data.map((item, index) => {
  430. if(item.length > 0){
  431. if(item[1] == undefined){
  432. errMsg += "第" + (index+1) + "行格式有误</br>";
  433. item[1] = '';
  434. }else if(!/^(http|https):\/\/.+$/.exec(item[1])){
  435. errMsg += "第" + (index+1) + "行网址格式有误</br>";
  436. }else{
  437. let info = {
  438. url: item[1],
  439. title: item[0].trim(),
  440. status: '1',
  441. num: 0,
  442. newPath: ''
  443. }
  444. switch(this.menuIndex){
  445. case '1':
  446. this.alibabaList.push(info);
  447. break;
  448. case '2':
  449. this.jdList.push(info);
  450. break;
  451. case '3':
  452. this.tmallList.push(info);
  453. break;
  454. case '4':
  455. this.tbList.push(info);
  456. break;
  457. case '10':
  458. this.commonList.push(info);
  459. break;
  460. }
  461. }
  462. }
  463. });
  464. if(errMsg){
  465. this.$notify({
  466. title: '请检查文件以下问题',
  467. dangerouslyUseHTMLString: true,
  468. message: errMsg,
  469. type: 'warning'
  470. });
  471. }
  472. }else{
  473. this.$notify({
  474. title: '提示',
  475. message: '格式有误,请重新导入',
  476. type: 'warning'
  477. });
  478. }
  479. }
  480. });
  481. },
  482. // 去登录
  483. loginUrl(url){
  484. (async () => {
  485. try{
  486. if (!fs.existsSync(os.tmpdir() + separator + 'chrome-data-capture')) {
  487. fs.mkdirSync(os.tmpdir() + separator + 'chrome-data-capture');
  488. }
  489. const tbBrowser = await puppeteer.launch({
  490. headless: false,
  491. executablePath: puppeteer.executablePath().replace('win32-1', 'win64-1'),
  492. args: ['--window-size=1280,800'],
  493. userDataDir: os.tmpdir() + separator + 'chrome-data-capture',
  494. });
  495. const page = await tbBrowser.newPage();
  496. await page.setViewport({ width: 1280, height: 800 });
  497. await page.evaluateOnNewDocument(() => {
  498. const newProto = navigator.__proto__;
  499. delete newProto.webdriver;
  500. navigator.__proto__ = newProto;
  501. });
  502. await page.goto(url, {waitUntil : 'networkidle2'});
  503. }catch(e){
  504. this.showError(e);
  505. }
  506. })();
  507. },
  508. // 开始下载
  509. async exportFile(flag) {
  510. let authority = this.$refs.headerRef.authority.isAuthority;
  511. if (!fs.existsSync(this.downloadDir + separator + pjson.softInfo.softName)) {
  512. fs.mkdirSync(this.downloadDir + separator + pjson.softInfo.softName);
  513. }
  514. let fileList = [];
  515. switch(this.menuIndex){
  516. case '1': // 阿里巴巴
  517. fileList = this.alibabaList;
  518. break;
  519. case '2': // 京东
  520. fileList = this.jdList;
  521. break;
  522. case '3': // 天猫
  523. fileList = this.tmallList;
  524. break;
  525. case '4': // 淘宝
  526. fileList = this.tbList;
  527. break;
  528. case '10': // 普通网址
  529. fileList = this.commonList;
  530. break;
  531. }
  532. if(fileList.length > 0){
  533. if (!authority && !flag) { // 非会员点击转换弹出提示框
  534. this.$refs.headerRef.memberModel = true;
  535. this.$refs.headerRef.isClick = true;
  536. return false;
  537. } else {
  538. this.$refs.headerRef.memberModel = false;
  539. this.loading = true;
  540. setTimeout(() => {
  541. this.loading = false;
  542. }, 60000);
  543. }
  544. if (!fs.existsSync(os.tmpdir() + separator + 'chrome-data-capture')) {
  545. fs.mkdirSync(os.tmpdir() + separator + 'chrome-data-capture');
  546. }
  547. let taskArr = [];
  548. let task = "";
  549. for(let i = 0; i < fileList.length; i++){
  550. let item = fileList[i];
  551. switch(this.menuIndex){
  552. case '1': // 阿里巴巴
  553. task = this.alibabaDownload(item);
  554. break;
  555. case '2': // 京东
  556. task = this.jdDownload(item);
  557. break;
  558. case '3': // 天猫
  559. case '4': // 淘宝
  560. task = this.tbDownload(item);
  561. break;
  562. case '10': // 普通网址
  563. task = this.normalDownload(item);
  564. break;
  565. }
  566. if(task){
  567. taskArr.push(task);
  568. }
  569. if((i+1) % this.execLimit == 0){
  570. await Promise.all(taskArr).then(result => {
  571. taskArr = [];
  572. }).catch(err => {
  573. console.log('err'+i, err)
  574. })
  575. }
  576. }
  577. if(taskArr.length > 0){
  578. await Promise.all(taskArr).then(result => {
  579. taskArr = [];
  580. }).catch(err => {
  581. // 错误文件添加到服务中
  582. console.log('err',err)
  583. })
  584. }
  585. let tbLogin = true;
  586. if((this.menuIndex == '3' || this.menuIndex == '4') && this.tbStatus == 3){
  587. tbLogin = false;
  588. }
  589. this.loading = false;
  590. // 打开文件夹
  591. if(fileList.length > 0 && tbLogin){
  592. this.$message({message: '恭喜你,任务已完成!', type: 'success'});
  593. electronApi.call('showItemInfolder',[this.downloadDir + separator + pjson.softInfo.softName +'\\tty.tty'])
  594. }
  595. }
  596. },
  597. // 10-普通网址下载
  598. async normalDownload(urlInfo){
  599. let task = await new Promise((resolve,reject) =>{
  600. (async () => {
  601. try{
  602. let authority = this.$refs.headerRef.authority.isAuthority;
  603. let number = 0;
  604. urlInfo.status = '2';
  605. urlInfo.num = 0;
  606. const browser = await puppeteer.launch({
  607. executablePath: puppeteer.executablePath().replace('win32-1', 'win64-1'),
  608. userDataDir: os.tmpdir() + separator + 'chrome-data-capture',
  609. });
  610. const page = await browser.newPage();
  611. page.on('response', async(response) => {
  612. // 检查响应的 MIME 类型是否以 'image/' 开头
  613. if (response.headers()['content-type'] && response.headers()['content-type'].startsWith('image/')) {
  614. let imgArr = ['gif', 'jpeg', 'png', 'webp', 'svg', 'tiff', 'bmp', 'ico', 'avif'];
  615. let imgType = 'jpg';
  616. let isBase = false;
  617. imgArr.map((item, index) => {
  618. if(response.headers()['content-type'].indexOf(item) > -1){
  619. imgType = item;
  620. if(item == 'jpeg'){
  621. imgType = 'jpg';
  622. }else if(item == 'avif'){
  623. imgType = 'png';
  624. }
  625. }
  626. });
  627. let url = response.url();
  628. let regex = /^data:image\/[\w|+|-]+;base64,/;
  629. if(regex.exec(url)){
  630. url = response.url().replace(/^data:image\/[\w|+|-]+;base64,/, '');
  631. isBase = true;
  632. }
  633. let imgInfo = {
  634. url: url,
  635. contentType: response.headers()['content-type'],
  636. status: response.status(),
  637. imgType: imgType,
  638. isBase: isBase
  639. }
  640. if(urlInfo.title){
  641. if (fs.existsSync(this.downloadDir + separator + pjson.softInfo.softName + separator + urlInfo.title)) {
  642. urlInfo.newPath = this.downloadDir + separator + pjson.softInfo.softName + separator + urlInfo.title;
  643. } else {
  644. fs.mkdirSync(this.downloadDir + separator + pjson.softInfo.softName + separator + urlInfo.title);
  645. urlInfo.newPath = this.downloadDir + separator + pjson.softInfo.softName + separator + urlInfo.title;
  646. }
  647. }else{
  648. await this.getTitle(page, urlInfo); // 生成页面标题对应的文件夹
  649. }
  650. let outputPath = urlInfo.newPath + '\\' + this.randomString(35) + '.' + imgInfo.imgType;
  651. urlInfo.status = '3';
  652. number++;
  653. if(!authority && number <= this.execNum){
  654. if(imgInfo.isBase){ //base64位图片下载
  655. this.downloadBaseImage(imgInfo.url, outputPath, urlInfo)
  656. }else{
  657. this.downloadImage(imgInfo.url, outputPath, urlInfo);
  658. }
  659. }
  660. if(authority){
  661. if(imgInfo.isBase){ //base64位图片下载
  662. this.downloadBaseImage(imgInfo.url, outputPath, urlInfo)
  663. }else{
  664. this.downloadImage(imgInfo.url, outputPath, urlInfo);
  665. }
  666. }
  667. }
  668. });
  669. await page.goto(urlInfo.url, {waitUntil : 'networkidle2'});
  670. let pageInfo = await page.evaluate(() => {
  671. let cHeight = document.documentElement.clientHeight;
  672. let scrollHeight = document.body.scrollHeight;
  673. return {'scrollHeight': scrollHeight, 'cHeight': cHeight}
  674. });
  675. let scrollHeight = pageInfo.scrollHeight;
  676. let cHeight = pageInfo.cHeight;
  677. let num = Math.ceil(scrollHeight / cHeight);
  678. let start = -1;
  679. let scrollInt = setInterval(async() => {
  680. start ++;
  681. await page.evaluate((start) => {
  682. let cHeight = document.documentElement.clientHeight;
  683. window.scrollTo({
  684. top: cHeight * start,
  685. behavior: "smooth"
  686. });
  687. }, start);
  688. if(start > num || start > 200){ // 防止页面过长,滚动200次自动停止
  689. clearInterval(scrollInt);
  690. await browser.close();
  691. urlInfo.status = '4';
  692. resolve(true);
  693. this.loading = false;
  694. }
  695. }, 500);
  696. }catch(e){
  697. urlInfo.status = '5';
  698. reject(e);
  699. this.showError(e);
  700. }
  701. })();
  702. });
  703. },
  704. // 1 - 阿里巴巴下载
  705. async alibabaDownload(urlInfo){
  706. let task = await new Promise((resolve,reject) =>{
  707. (async () => {
  708. try{
  709. let authority = this.$refs.headerRef.authority.isAuthority;
  710. urlInfo.status = '2';
  711. urlInfo.num = 0;
  712. const browser = await puppeteer.launch({
  713. executablePath: puppeteer.executablePath().replace('win32-1', 'win64-1'),
  714. userDataDir: os.tmpdir() + separator + 'chrome-data-capture',
  715. });
  716. const page = await browser.newPage();
  717. await page.goto(urlInfo.url, {waitUntil : 'networkidle2'});
  718. if(urlInfo.title){
  719. if (fs.existsSync(this.downloadDir + separator + pjson.softInfo.softName + separator + urlInfo.title)) {
  720. urlInfo.newPath = this.downloadDir + separator + pjson.softInfo.softName + separator + urlInfo.title;
  721. } else {
  722. fs.mkdirSync(this.downloadDir + separator + pjson.softInfo.softName + separator + urlInfo.title);
  723. urlInfo.newPath = this.downloadDir + separator + pjson.softInfo.softName + separator + urlInfo.title;
  724. }
  725. }else{
  726. await this.getTitle(page, urlInfo); // 生成页面标题对应的文件夹
  727. }
  728. let pageInfo = await page.evaluate(() => {
  729. let cHeight = document.documentElement.clientHeight;
  730. let scrollHeight = document.body.scrollHeight;
  731. return {'scrollHeight': scrollHeight, 'cHeight': cHeight}
  732. });
  733. let scrollHeight = pageInfo.scrollHeight;
  734. let cHeight = pageInfo.cHeight;
  735. let num = Math.ceil(scrollHeight / cHeight);
  736. let start = -1;
  737. urlInfo.status = '3';
  738. let scrollInt = setInterval(async() => {
  739. start ++;
  740. await page.evaluate((start) => {
  741. let cHeight = document.documentElement.clientHeight;
  742. window.scrollTo({
  743. top: cHeight * start,
  744. behavior: "smooth"
  745. });
  746. }, start);
  747. if(start > num || start > 200){ // 防止页面过长,滚动200次自动停止
  748. clearInterval(scrollInt);
  749. await this.alibabaScanImg(browser, page, urlInfo, authority);
  750. this.loading = false;
  751. urlInfo.status = '4';
  752. resolve(true);
  753. }
  754. }, 500);
  755. }catch(e){
  756. urlInfo.status = '5';
  757. reject(e);
  758. this.showError(e);
  759. }
  760. })();
  761. });
  762. },
  763. // 京东下载
  764. async jdDownload(urlInfo){
  765. let task = await new Promise((resolve,reject) =>{
  766. (async () => {
  767. try{
  768. let authority = this.$refs.headerRef.authority.isAuthority;
  769. urlInfo.status = '2';
  770. urlInfo.num = 0;
  771. const jdBrowser = await puppeteer.launch({
  772. executablePath: puppeteer.executablePath().replace('win32-1', 'win64-1'),
  773. userDataDir: os.tmpdir() + separator + 'chrome-data-capture',
  774. });
  775. const page = await jdBrowser.newPage();
  776. let jdImgInfo = {
  777. mainImg: [],
  778. skuImg: [],
  779. commentImg: [],
  780. detailImg: [],
  781. video: []
  782. };
  783. let titleFlag = true;
  784. page.on('response', async(response) => {
  785. if(titleFlag){ // 第一次生成页面标题
  786. if(urlInfo.title){
  787. if (fs.existsSync(this.downloadDir + separator + pjson.softInfo.softName + separator + urlInfo.title)) {
  788. urlInfo.newPath = this.downloadDir + separator + pjson.softInfo.softName + separator + urlInfo.title;
  789. } else {
  790. fs.mkdirSync(this.downloadDir + separator + pjson.softInfo.softName + separator + urlInfo.title);
  791. urlInfo.newPath = this.downloadDir + separator + pjson.softInfo.softName + separator + urlInfo.title;
  792. }
  793. }else{
  794. await this.getTitle(page, urlInfo); // 生成页面标题对应的文件夹
  795. }
  796. titleFlag = false;
  797. }
  798. // 检查响应的 MIME 类型是否以 'image/' 开头
  799. if (response.headers()['content-type'] && response.headers()['content-type'].startsWith('application/json')) {
  800. let detailUrl = '';
  801. let videoUrl = '';
  802. if(response.url().indexOf('&callback=showdesc') > -1 && response.url().indexOf('/description/') > -1){ // 商品详情接口
  803. detailUrl = response.url();
  804. }
  805. if(response.url().indexOf('/tencent/video_v3') > -1){ // 商品视频接口
  806. videoUrl = response.url();
  807. }
  808. urlInfo.status = '3';
  809. if(detailUrl && this.settingData.detailImg){ // jd商品详情
  810. try {
  811. let data = await response.text();
  812. data = data.slice(0, -1).replace('showdesc(', '');
  813. let detailInfo = JSON.parse(data);
  814. let regex = /\/\/img[0-9]+.360buyimg.com\S+.(jpg|jpeg|png|gif|avif|tif|tiff)/g;
  815. let detailImgArr = [];
  816. if(detailInfo && detailInfo.content){
  817. detailImgArr = detailInfo.content.match(regex);
  818. }
  819. jdImgInfo.detailImg = detailImgArr;
  820. for(let i = 0; i < detailImgArr.length; i++){
  821. let imgUrl = 'https:' + detailImgArr[i];
  822. let fileName = imgUrl.split('/').pop();
  823. if(fileName){
  824. let queryIndex = fileName.indexOf('?');
  825. if (queryIndex !== -1) {
  826. fileName = fileName.substr(0, queryIndex);
  827. }
  828. if (!fs.existsSync(urlInfo.newPath + '\\详情图')) {
  829. fs.mkdirSync(urlInfo.newPath + '\\详情图');
  830. }
  831. let outputPath = urlInfo.newPath + '\\详情图\\' + fileName;
  832. if(!authority && i < this.execNum){
  833. await this.downloadImage(imgUrl, outputPath, urlInfo);
  834. }
  835. if(authority){
  836. await this.downloadImage(imgUrl, outputPath, urlInfo);
  837. }
  838. }
  839. }
  840. } catch (error) {
  841. console.error('详情图片解析失败:', error);
  842. }
  843. }
  844. if(videoUrl && this.settingData.video){ // jd商品视频
  845. try {
  846. let data = await response.text();
  847. data = data.slice(0, -1).replace(/^jQuery[0-9]+\(/, '');
  848. let videoInfo = JSON.parse(data);
  849. let videoUrl = videoInfo.playUrl;
  850. jdImgInfo.video.push(videoUrl);
  851. let fileName = videoUrl.split('/').pop();
  852. if(fileName){
  853. let queryIndex = fileName.indexOf('?');
  854. if (queryIndex !== -1) {
  855. fileName = fileName.substr(0, queryIndex);
  856. }
  857. if (!fs.existsSync(urlInfo.newPath + '\\视频')) {
  858. fs.mkdirSync(urlInfo.newPath + '\\视频');
  859. }
  860. let outputPath = urlInfo.newPath + '\\视频\\' + fileName;
  861. await this.downloadImage(videoUrl, outputPath, urlInfo);
  862. }
  863. } catch (error) {
  864. console.error('视频解析失败:', error);
  865. }
  866. }
  867. }
  868. if (response.headers()['content-type'] && response.headers()['content-type'].startsWith('image/')) {
  869. let regex = /^https:\/\/img[0-9]+.360buyimg.com\/n/;
  870. if(regex.exec(response.url())){ // 匹配符合规则的图片路径
  871. if(response.url().indexOf('/s40x40_jfs/') > -1 && this.settingData.skuImg){ // sku图片
  872. let skuNum = 0;
  873. let skuImgUrl = response.url().replace('/s40x40_jfs/', '/jfs/').replace(/\/n[0-9]+\/jfs\//, '/n1/jfs/').replace('.avif', '');
  874. jdImgInfo.skuImg.push(skuImgUrl);
  875. let fileName = skuImgUrl.split('/').pop();
  876. if(fileName){
  877. let queryIndex = fileName.indexOf('?');
  878. if (queryIndex !== -1) {
  879. fileName = fileName.substr(0, queryIndex);
  880. }
  881. if (!fs.existsSync(urlInfo.newPath + '\\sku图')) {
  882. fs.mkdirSync(urlInfo.newPath + '\\sku图');
  883. }
  884. let outputPath = urlInfo.newPath + '\\sku图\\' + fileName;
  885. skuNum ++;
  886. if(!authority && skuNum <= this.execNum){
  887. await this.downloadImage(skuImgUrl, outputPath, urlInfo);
  888. }
  889. if(authority){
  890. await this.downloadImage(skuImgUrl, outputPath, urlInfo);
  891. }
  892. }
  893. }
  894. let reg = /\/n[0-9]+\/jfs\//;
  895. let reg2 = /\/n[0-9]+\/s54x54_jfs\//;
  896. if(response.url().match(reg) || response.url().match(reg2)){ // 主图
  897. let mainNum = 0;
  898. let mainImgUrl = response.url().replace(reg, '/n1/jfs/').replace(reg2, '/n1/jfs/').replace('.avif', '');
  899. jdImgInfo.mainImg.push(mainImgUrl);
  900. let fileName = mainImgUrl.split('/').pop();
  901. if(fileName){
  902. let queryIndex = fileName.indexOf('?');
  903. if (queryIndex !== -1) {
  904. fileName = fileName.substr(0, queryIndex);
  905. }
  906. if (!fs.existsSync(urlInfo.newPath + '\\主图')) {
  907. fs.mkdirSync(urlInfo.newPath + '\\主图');
  908. }
  909. let outputPath = urlInfo.newPath + '\\主图\\' + fileName;
  910. mainNum ++;
  911. if(!authority && mainNum <= this.execNum){
  912. await this.downloadImage(mainImgUrl, outputPath, urlInfo);
  913. }
  914. if(authority){
  915. await this.downloadImage(mainImgUrl, outputPath, urlInfo);
  916. }
  917. }
  918. }
  919. }
  920. }
  921. });
  922. await page.goto(urlInfo.url, {waitUntil : 'networkidle2'});
  923. await jdBrowser.close();
  924. urlInfo.status = '4';
  925. resolve(true);
  926. }catch(e){
  927. reject(e);
  928. this.showError(e);
  929. }
  930. })();
  931. });
  932. },
  933. // 检查天猫淘宝登录状态
  934. checkLogin(){
  935. this.checkLoading = true;
  936. this.tbStatus = 1;
  937. return new Promise((resolve, reject) => {
  938. (async () => {
  939. try{
  940. const tbBrowser = await puppeteer.launch({
  941. executablePath: puppeteer.executablePath().replace('win32-1', 'win64-1'),
  942. userDataDir: os.tmpdir() + separator + 'chrome-data-capture',
  943. });
  944. const page = await tbBrowser.newPage();
  945. let testUrl = 'https://www.taobao.com';
  946. await page.goto(testUrl, {waitUntil : 'networkidle2'});
  947. let loginInfo = await page.evaluate(() => {
  948. let navTags = document.querySelector('.site-nav-sign a');
  949. let userTags = document.querySelector('.site-nav-user a');
  950. if(navTags && navTags.innerHTML.indexOf('登录') > -1){
  951. return false;
  952. }else if(userTags){
  953. return true;
  954. }else{
  955. return false;
  956. }
  957. });
  958. if(loginInfo){
  959. this.tbStatus = 2;
  960. }else{
  961. this.tbStatus = 3;
  962. }
  963. resolve(this.tbStatus);
  964. this.checkLoading = false;
  965. tbBrowser.close();
  966. }catch(e){
  967. reject(3);
  968. this.showError(e);
  969. }
  970. })();
  971. });
  972. },
  973. //淘宝\天猫下载
  974. async tbDownload(urlInfo){
  975. let task = null;
  976. if(this.tbStatus == 1 || this.tbStatus == 3){ // 未检测登录状态/或提示未登录状态,开始检测
  977. await this.checkLogin().then((data) => {
  978. if(data == 2){ // 已经登录,处理下载
  979. task = this.tbScanImg(urlInfo);
  980. }else{ // 未登录
  981. task = 'notLogin';
  982. this.tbStatus = 3;
  983. this.$notify.error({
  984. title: '淘宝/天猫账号未登录,下载失败!'
  985. });
  986. }
  987. }).catch(err => {
  988. task = 'notLogin';
  989. this.tbStatus = 3;
  990. });
  991. }else if(this.tbStatus == 2){ // 已经登录
  992. task = this.tbScanImg(urlInfo);
  993. }
  994. return task;
  995. },
  996. // 淘宝天猫扫描下载图片
  997. async tbScanImg(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. const tbBrowser = await puppeteer.launch({
  1005. executablePath: puppeteer.executablePath().replace('win32-1', 'win64-1'),
  1006. userDataDir: os.tmpdir() + separator + 'chrome-data-capture',
  1007. });
  1008. const page = await tbBrowser.newPage();
  1009. await page.goto(urlInfo.url, {waitUntil : 'networkidle2'});
  1010. if(urlInfo.title){
  1011. if (fs.existsSync(this.downloadDir + separator + pjson.softInfo.softName + separator + urlInfo.title)) {
  1012. urlInfo.newPath = this.downloadDir + separator + pjson.softInfo.softName + separator + urlInfo.title;
  1013. } else {
  1014. fs.mkdirSync(this.downloadDir + separator + pjson.softInfo.softName + separator + urlInfo.title);
  1015. urlInfo.newPath = this.downloadDir + separator + pjson.softInfo.softName + separator + urlInfo.title;
  1016. }
  1017. }else{
  1018. await this.getTitle(page, urlInfo); // 生成页面标题对应的文件夹
  1019. }
  1020. let pageInfo = await page.evaluate(() => {
  1021. let cHeight = document.documentElement.clientHeight;
  1022. let scrollHeight = document.body.scrollHeight;
  1023. return {'scrollHeight': scrollHeight, 'cHeight': cHeight}
  1024. });
  1025. let scrollHeight = pageInfo.scrollHeight;
  1026. let cHeight = pageInfo.cHeight;
  1027. let num = Math.ceil(scrollHeight / cHeight);
  1028. let start = -1;
  1029. let scrollInt = setInterval(async() => {
  1030. start ++;
  1031. await page.evaluate((start) => {
  1032. let cHeight = document.documentElement.clientHeight;
  1033. window.scrollTo({
  1034. top: cHeight * start,
  1035. behavior: "smooth"
  1036. });
  1037. }, start);
  1038. if(start > num || start > 200){ // 防止页面过长,滚动200次自动停止
  1039. urlInfo.status = '3';
  1040. clearInterval(scrollInt);
  1041. //detailImg:详情图;skuImg:sku图片;commentImg: 评论图;video: 视频
  1042. const imgInfo = await page.evaluate((authority, execNum) => {
  1043. let outObj = {
  1044. mainImg: [],
  1045. detailImg: [],
  1046. skuImg: [],
  1047. commentImg: [],
  1048. video: []
  1049. };
  1050. // 正则表达式匹配字符 重写图片路径
  1051. let regex = /\.(.{3,4})_[0-9a-zA-z]+\.(.{3,4})_\.(.{3,4})/;
  1052. //主图
  1053. let arr1 = document.querySelectorAll('img[class^=PicGallery--thumbnailPic--]');
  1054. if(arr1.length === 0){
  1055. arr1 = document.querySelectorAll('img[class*=thumbnailPic--]');
  1056. }
  1057. for(let i=0; i< arr1.length; i++){
  1058. let mainImgUrl = arr1[i].src;
  1059. let result = regex.exec(mainImgUrl);
  1060. if(result){
  1061. mainImgUrl = mainImgUrl.replace(result[0], '.'+result[1]);
  1062. }
  1063. if(!authority && i < execNum){
  1064. outObj.mainImg.push(mainImgUrl);
  1065. }
  1066. if(authority){
  1067. outObj.mainImg.push(mainImgUrl);
  1068. }
  1069. }
  1070. //sku图片
  1071. let arr2 = document.querySelectorAll('img[class^=SkuContent--valueItemImg--]');
  1072. if(arr2.length === 0){
  1073. arr2 = document.querySelectorAll('img[class*=valueItemImg--]');
  1074. }
  1075. for(let i=0; i< arr2.length; i++){
  1076. let skuImgUrl = arr2[i].src;
  1077. let result = regex.exec(skuImgUrl);
  1078. if(result){
  1079. skuImgUrl = skuImgUrl.replace(result[0], '.'+result[1]);
  1080. }
  1081. if(!authority && i < execNum){
  1082. outObj.skuImg.push(skuImgUrl);
  1083. }
  1084. if(authority){
  1085. outObj.skuImg.push(skuImgUrl);
  1086. }
  1087. }
  1088. //详情图片
  1089. let arr3 = document.querySelectorAll('#content img')
  1090. for(let i=0; i< arr3.length; i++){
  1091. let detailImgUrl = arr3[i].src;
  1092. let result = regex.exec(detailImgUrl);
  1093. if(result){
  1094. detailImgUrl = detailImgUrl.replace(result[0], '.'+result[1]);
  1095. }
  1096. if(!authority && i < execNum){
  1097. outObj.detailImg.push(detailImgUrl);
  1098. }
  1099. if(authority){
  1100. outObj.detailImg.push(detailImgUrl);
  1101. }
  1102. }
  1103. //评论图片
  1104. let arr4 = document.querySelectorAll('div[class^=Comments--comments--] img');
  1105. if(arr4.length === 0){
  1106. arr4 = document.querySelectorAll('div[class^=comments--] img');
  1107. }
  1108. for(let i=0; i< arr4.length; i++){
  1109. if(arr4[i].src.indexOf('/avatar/sns/user/flag/sns_logo') == -1){ //过滤淘宝用户头像
  1110. if(!authority && i < execNum){
  1111. outObj.commentImg.push(arr4[i].src);
  1112. }
  1113. if(authority){
  1114. outObj.commentImg.push(arr4[i].src);
  1115. }
  1116. }
  1117. }
  1118. // 视频
  1119. let arr5 = document.querySelectorAll('video.lib-video');
  1120. for(let i=0; i< arr5.length; i++){
  1121. if(outObj.video.indexOf(arr5[i].src) == -1){
  1122. if(!authority && i < execNum){
  1123. outObj.video.push(arr5[i].src);
  1124. }
  1125. if(authority){
  1126. outObj.video.push(arr5[i].src);
  1127. }
  1128. }
  1129. }
  1130. return outObj;
  1131. }, authority, this.execNum);
  1132. // 主图下载
  1133. for(let j = 0; j < imgInfo.mainImg.length; j++){
  1134. let fileName = imgInfo.mainImg[j].split('/').pop();
  1135. if(fileName){
  1136. let queryIndex = fileName.indexOf('?');
  1137. if (queryIndex !== -1) {
  1138. fileName = fileName.substr(0, queryIndex);
  1139. }
  1140. if (!fs.existsSync(urlInfo.newPath + '\\主图')) {
  1141. fs.mkdirSync(urlInfo.newPath + '\\主图');
  1142. }
  1143. let outputPath = urlInfo.newPath + '\\主图\\' + fileName;
  1144. await this.downloadImage(imgInfo.mainImg[j], outputPath, urlInfo);
  1145. }
  1146. }
  1147. // sku图片下载
  1148. if(this.settingData.skuImg){
  1149. for(let j = 0; j < imgInfo.skuImg.length; j++){
  1150. let fileName = imgInfo.skuImg[j].split('/').pop();
  1151. if(fileName){
  1152. let queryIndex = fileName.indexOf('?');
  1153. if (queryIndex !== -1) {
  1154. fileName = fileName.substr(0, queryIndex);
  1155. }
  1156. if (!fs.existsSync(urlInfo.newPath + '\\sku图')) {
  1157. fs.mkdirSync(urlInfo.newPath + '\\sku图');
  1158. }
  1159. let outputPath = urlInfo.newPath + '\\sku图\\' + fileName;
  1160. await this.downloadImage(imgInfo.skuImg[j], outputPath, urlInfo);
  1161. }
  1162. }
  1163. }
  1164. //详情图下载
  1165. if(this.settingData.detailImg){
  1166. for(let j = 0; j < imgInfo.detailImg.length; j++){
  1167. let fileName = imgInfo.detailImg[j].split('/').pop();
  1168. if(fileName){
  1169. let queryIndex = fileName.indexOf('?');
  1170. if (queryIndex !== -1) {
  1171. fileName = fileName.substr(0, queryIndex);
  1172. }
  1173. if (!fs.existsSync(urlInfo.newPath + '\\详情图')) {
  1174. fs.mkdirSync(urlInfo.newPath + '\\详情图');
  1175. }
  1176. let outputPath = urlInfo.newPath + '\\详情图\\' + fileName;
  1177. await this.downloadImage(imgInfo.detailImg[j], outputPath, urlInfo);
  1178. }
  1179. }
  1180. }
  1181. //评论图下载
  1182. if(this.settingData.commentImg){
  1183. for(let j = 0; j < imgInfo.commentImg.length; j++){
  1184. let fileName = imgInfo.commentImg[j].split('/').pop();
  1185. if(fileName){
  1186. let queryIndex = fileName.indexOf('?');
  1187. if (queryIndex !== -1) {
  1188. fileName = fileName.substr(0, queryIndex);
  1189. }
  1190. if (!fs.existsSync(urlInfo.newPath + '\\评论图')) {
  1191. fs.mkdirSync(urlInfo.newPath + '\\评论图');
  1192. }
  1193. let outputPath = urlInfo.newPath + '\\评论图\\' + fileName;
  1194. await this.downloadImage(imgInfo.commentImg[j], outputPath, urlInfo);
  1195. }
  1196. }
  1197. }
  1198. //视频下载
  1199. if(this.settingData.video){
  1200. for(let j = 0; j < imgInfo.video.length; j++){
  1201. let fileName = imgInfo.video[j].split('/').pop();
  1202. if(fileName){
  1203. let queryIndex = fileName.indexOf('?');
  1204. if (queryIndex !== -1) {
  1205. fileName = fileName.substr(0, queryIndex);
  1206. }
  1207. if (!fs.existsSync(urlInfo.newPath + '\\视频')) {
  1208. fs.mkdirSync(urlInfo.newPath + '\\视频');
  1209. }
  1210. let outputPath = urlInfo.newPath + '\\视频\\' + fileName;
  1211. await this.downloadImage(imgInfo.video[j], outputPath, urlInfo);
  1212. }
  1213. }
  1214. }
  1215. await tbBrowser.close();
  1216. urlInfo.status = '4';
  1217. resolve(true);
  1218. this.loading = false;
  1219. }
  1220. }, 500);
  1221. }catch(e){
  1222. reject(e);
  1223. this.showError(e);
  1224. }
  1225. })();
  1226. });
  1227. },
  1228. // 阿里巴巴 - 扫描并下载图片
  1229. async alibabaScanImg(browser, page, urlInfo, authority){
  1230. //detailImg:详情图;skuImg:sku图片;commentImg: 评论图;video: 视频
  1231. const imgInfo = await page.evaluate((authority, execNum) => {
  1232. let outObj = {
  1233. mainImg: [],
  1234. detailImg: [],
  1235. skuImg: [],
  1236. commentImg: [],
  1237. video: []
  1238. };
  1239. //主图
  1240. let arr1 = document.querySelectorAll('img.detail-gallery-img');
  1241. for(let i=0; i< arr1.length; i++){
  1242. if(!authority && i < execNum){
  1243. outObj.mainImg.push(arr1[i].src);
  1244. }
  1245. if(authority){
  1246. outObj.mainImg.push(arr1[i].src);
  1247. }
  1248. }
  1249. //sku图片
  1250. let arr2 = document.querySelectorAll('.prop-img');
  1251. for(let i=0; i< arr2.length; i++){
  1252. let src = window.getComputedStyle(arr2[i]).backgroundImage.replace(/url\(["']?(.+?)["']?\)/i, '$1');
  1253. if(!authority && i < execNum){
  1254. outObj.skuImg.push(src);
  1255. }
  1256. if(authority){
  1257. outObj.skuImg.push(src);
  1258. }
  1259. }
  1260. //详情图片
  1261. let arr3 = document.querySelectorAll('img.desc-img-loaded');
  1262. for(let i=0; i< arr3.length; i++){
  1263. if(!authority && i < execNum){
  1264. outObj.detailImg.push(arr3[i].src);
  1265. }
  1266. if(authority){
  1267. outObj.detailImg.push(arr3[i].src);
  1268. }
  1269. }
  1270. //评论图片 -- 需要点击切换
  1271. // let arr4 = document.querySelectorAll('img.image-box');
  1272. // for(let i=0; i< arr4.length; i++){
  1273. // if(!authority && i < execNum){
  1274. // outObj.commentImg.push(arr4[i].src);
  1275. // }
  1276. // if(authority){
  1277. // outObj.commentImg.push(arr4[i].src);
  1278. // }
  1279. // }
  1280. // 视频
  1281. let arr5 = document.querySelectorAll('video.lib-video');
  1282. for(let i=0; i< arr5.length; i++){
  1283. if(outObj.video.indexOf(arr5[i].src) == -1){
  1284. if(!authority && i < execNum){
  1285. outObj.video.push(arr5[i].src);
  1286. }
  1287. if(authority){
  1288. outObj.video.push(arr5[i].src);
  1289. }
  1290. }
  1291. }
  1292. return outObj;
  1293. }, authority, this.execNum);
  1294. // 主图下载
  1295. for(let j = 0; j < imgInfo.mainImg.length; j++){
  1296. let fileName = imgInfo.mainImg[j].split('/').pop();
  1297. if(fileName){
  1298. let queryIndex = fileName.indexOf('?');
  1299. if (queryIndex !== -1) {
  1300. fileName = fileName.substr(0, queryIndex);
  1301. }
  1302. if (!fs.existsSync(urlInfo.newPath + '\\主图')) {
  1303. fs.mkdirSync(urlInfo.newPath + '\\主图');
  1304. }
  1305. let outputPath = urlInfo.newPath + '\\主图\\' + fileName;
  1306. await this.downloadImage(imgInfo.mainImg[j], outputPath, urlInfo);
  1307. }
  1308. }
  1309. // sku图片下载
  1310. if(this.settingData.skuImg){
  1311. for(let j = 0; j < imgInfo.skuImg.length; j++){
  1312. let fileName = imgInfo.skuImg[j].split('/').pop();
  1313. if(fileName){
  1314. let queryIndex = fileName.indexOf('?');
  1315. if (queryIndex !== -1) {
  1316. fileName = fileName.substr(0, queryIndex);
  1317. }
  1318. if (!fs.existsSync(urlInfo.newPath + '\\sku图')) {
  1319. fs.mkdirSync(urlInfo.newPath + '\\sku图');
  1320. }
  1321. let outputPath = urlInfo.newPath + '\\sku图\\' + fileName;
  1322. await this.downloadImage(imgInfo.skuImg[j], outputPath, urlInfo);
  1323. }
  1324. }
  1325. }
  1326. //详情图下载
  1327. if(this.settingData.detailImg){
  1328. for(let j = 0; j < imgInfo.detailImg.length; j++){
  1329. let fileName = imgInfo.detailImg[j].split('/').pop();
  1330. if(fileName){
  1331. let queryIndex = fileName.indexOf('?');
  1332. if (queryIndex !== -1) {
  1333. fileName = fileName.substr(0, queryIndex);
  1334. }
  1335. if (!fs.existsSync(urlInfo.newPath + '\\详情图')) {
  1336. fs.mkdirSync(urlInfo.newPath + '\\详情图');
  1337. }
  1338. let outputPath = urlInfo.newPath + '\\详情图\\' + fileName;
  1339. await this.downloadImage(imgInfo.detailImg[j], outputPath, urlInfo);
  1340. }
  1341. }
  1342. }
  1343. //评论图下载
  1344. // if(this.settingData.commentImg){
  1345. // for(let j = 0; j < imgInfo.commentImg.length; j++){
  1346. // let fileName = imgInfo.commentImg[j].split('/').pop();
  1347. // if(fileName){
  1348. // let queryIndex = fileName.indexOf('?');
  1349. // if (queryIndex !== -1) {
  1350. // fileName = fileName.substr(0, queryIndex);
  1351. // }
  1352. // if (!fs.existsSync(urlInfo.newPath + '\\评论图')) {
  1353. // fs.mkdirSync(urlInfo.newPath + '\\评论图');
  1354. // }
  1355. // let outputPath = urlInfo.newPath + '\\评论图\\' + fileName;
  1356. // await this.downloadImage(imgInfo.commentImg[j], outputPath, urlInfo);
  1357. // }
  1358. // }
  1359. // }
  1360. //视频下载
  1361. if(this.settingData.video){
  1362. for(let j = 0; j < imgInfo.video.length; j++){
  1363. let fileName = imgInfo.video[j].split('/').pop();
  1364. if(fileName){
  1365. let queryIndex = fileName.indexOf('?');
  1366. if (queryIndex !== -1) {
  1367. fileName = fileName.substr(0, queryIndex);
  1368. }
  1369. if (!fs.existsSync(urlInfo.newPath + '\\视频')) {
  1370. fs.mkdirSync(urlInfo.newPath + '\\视频');
  1371. }
  1372. let outputPath = urlInfo.newPath + '\\视频\\' + fileName;
  1373. await this.downloadImage(imgInfo.video[j], outputPath, urlInfo);
  1374. }
  1375. }
  1376. }
  1377. await browser.close();
  1378. },
  1379. //
  1380. downloadExample(){
  1381. let url = 'https://www.xingyousoft.com/soft/XYCapture/example.xlsx';
  1382. if (!fs.existsSync(this.downloadDir + separator + pjson.softInfo.softName)) {
  1383. fs.mkdirSync(this.downloadDir + separator + pjson.softInfo.softName);
  1384. }
  1385. let path = this.downloadDir + separator + pjson.softInfo.softName + '\\链接模板下载.xlsx';
  1386. this.downloadImage(url, path, 'example');
  1387. },
  1388. // 下载网址链接的图片
  1389. async downloadImage(imageUrl, outputPath, urlInfo) {
  1390. let _this = this;
  1391. let received_bytes = 0;
  1392. let total_bytes = 0;
  1393. try {
  1394. let req = request({
  1395. method: 'GET', uri: imageUrl, strictSSL: false
  1396. });
  1397. let out = fs.createWriteStream(outputPath);
  1398. req.pipe(out);
  1399. return new Promise((resolve, reject) => {
  1400. req.on('response', (data) => {
  1401. total_bytes = parseInt(data.headers['content-length']);
  1402. const status = data.statusCode;
  1403. if (status < 200 || status >= 300) {
  1404. reject(false);
  1405. this.$notify.error({
  1406. title: '网络异常,请稍后重试!- 1 - ' + imageUrl
  1407. });
  1408. }else if(isNaN(total_bytes)){
  1409. reject(false);
  1410. this.$notify.error({
  1411. title: '网络异常,请稍后重试!- 2 - ' + imageUrl
  1412. });
  1413. }else{
  1414. // console.log('下载中...')
  1415. }
  1416. });
  1417. req.on('data', (chunk) => {
  1418. received_bytes += chunk.length;
  1419. });
  1420. req.on('end', ()=> {
  1421. if(urlInfo != 'example'){
  1422. urlInfo.num += 1;
  1423. }else{
  1424. this.$msgbox({
  1425. title: '消息',
  1426. message: '模板下载成功,保存位置:' + this.downloadDir + separator + pjson.softInfo.softName,
  1427. showCancelButton: true,
  1428. confirmButtonText: '去查看',
  1429. cancelButtonText: '取消',
  1430. }).then(action => {
  1431. this.openFolder();
  1432. }).catch(action => {
  1433. });
  1434. }
  1435. //console.log('下载完成', outputPath)
  1436. resolve(true);
  1437. });
  1438. });
  1439. } catch (error) {
  1440. console.error(imageUrl, `Failed to download image: ${error.message}`);
  1441. throw error;
  1442. }
  1443. },
  1444. // 获取页面标题 - 生成对应的文件夹
  1445. async getTitle(page, urlInfo){
  1446. // 已页面标题作为新建文件夹,保留前20个字
  1447. let title = await page.title();
  1448. if(title){
  1449. title = title.substring(0, 20);
  1450. if(this.containsAnyChar(title, ['\\', '/', ':', '*', '?', '"', '<', '>', '|'])){ //判断是否含有特殊字符
  1451. title = title.replace(/[\\|/|:|*|?|"|<|>||]/g, "");
  1452. }
  1453. if (fs.existsSync(this.downloadDir + separator + pjson.softInfo.softName + separator + title)) {
  1454. urlInfo.newPath = this.downloadDir + separator + pjson.softInfo.softName + separator + title;
  1455. } else {
  1456. fs.mkdirSync(this.downloadDir + separator + pjson.softInfo.softName + separator + title);
  1457. urlInfo.newPath = this.downloadDir + separator + pjson.softInfo.softName + separator + title;
  1458. }
  1459. }
  1460. },
  1461. // 下载base64位的图片
  1462. async downloadBaseImage(base64String, outputPath, urlInfo) {
  1463. const buffer = Buffer.from(base64String, 'base64');
  1464. const writeStream = fs.createWriteStream(outputPath);
  1465. writeStream.write(buffer);
  1466. writeStream.end();
  1467. writeStream.on('finish', () => {
  1468. urlInfo.num += 1;
  1469. });
  1470. // 监听错误事件
  1471. writeStream.on('error', (err) => {
  1472. console.error('base64位写入文件时出错:', err);
  1473. });
  1474. },
  1475. // 错误提示
  1476. showError(e){
  1477. let str = '';
  1478. if(e.toString().indexOf('ERR_NAME_NOT_RESOLVE') > -1){
  1479. str = '无法解析该网址,请查看网址是否正确!-1';
  1480. }else if(e.toString().indexOf('Cannot navigate to invalid URL') > -1){
  1481. str = '无效的网址,请查看网址格式是否正确!-2';
  1482. }else if(e.toString().indexOf('ERR_CONNECTION_TIMED_OUT') > -1){
  1483. str = '链接请求超时,请查看网络状态!-3';
  1484. }else if(e.toString().indexOf('TimeoutError') > -1){
  1485. str = '链接请求超时,请查看网络状态!-4';
  1486. }else{
  1487. str = e.toString();
  1488. console.log(e);
  1489. }
  1490. this.loading = false;
  1491. this.$notify.error({
  1492. title: '提示',
  1493. message: str
  1494. });
  1495. },
  1496. // 是否包含特殊字符
  1497. containsAnyChar(str, charsArray) {
  1498. for (let i = 0; i < charsArray.length; i++) {
  1499. if (str.includes(charsArray[i])) {
  1500. return true;
  1501. }
  1502. }
  1503. return false;
  1504. },
  1505. // 随机生成字符
  1506. randomString(length) {
  1507. let result = '';
  1508. const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
  1509. const charactersLength = characters.length;
  1510. for (let i = 0; i < length; i++ ) {
  1511. result += characters.charAt(Math.floor(Math.random() * charactersLength));
  1512. }
  1513. return result;
  1514. }
  1515. }
  1516. };
  1517. </script>
  1518. <style lang="scss">
  1519. @import "../assets/css/font/iconfont.css";
  1520. @import "../assets/css/fontx/iconfont.css";
  1521. @import "../assets/css/home.scss";
  1522. .ivu-input-number-controls-outside-btn i {
  1523. font-weight: 800;
  1524. }
  1525. .update-point {
  1526. display: inline-block;
  1527. width: 8px;
  1528. height: 8px;
  1529. border-radius: 8px;
  1530. background: #ff0000;
  1531. top: 14px;
  1532. position: absolute;
  1533. left: -13px;
  1534. }
  1535. .menu-item {
  1536. padding: 8px 0;
  1537. font-size: 14px;
  1538. .iconfont {
  1539. font-size: 32px;
  1540. }
  1541. &:hover,
  1542. &.active {
  1543. color: #ed4014;
  1544. }
  1545. }
  1546. .ivu-progress-show-info .ivu-progress-outer {
  1547. padding-right: 40px !important;
  1548. margin-right: -40px !important;
  1549. }
  1550. .tips {
  1551. text-align: center;
  1552. padding: 10px 0;
  1553. color: #ed4014;
  1554. font-size: 12px;
  1555. }
  1556. .handle-desc {
  1557. display: inline-block;
  1558. width: calc(100% - 100px);
  1559. overflow: hidden;
  1560. }
  1561. .ivu-menu-submenu-title {
  1562. font-weight: 600;
  1563. }
  1564. .ivu-menu .ivu-menu-item {
  1565. line-height: 1;
  1566. }
  1567. // new-el
  1568. .el-menu {
  1569. border-right: none !important;
  1570. }
  1571. .cmenu-item {
  1572. padding: 0 20px 20px;
  1573. margin-bottom: 15px;
  1574. .cmenu-title {
  1575. font-size: 18px;
  1576. font-weight: 600;
  1577. padding-bottom: 20px;
  1578. }
  1579. .citem-nav {
  1580. text-align: center;
  1581. border-radius: 10px;
  1582. min-height: 110px;
  1583. padding: 15px 0;
  1584. background-color: #fff;
  1585. font-size: 15px;
  1586. cursor: pointer;
  1587. &.bg-linear1 {
  1588. color: #fff;
  1589. font-size: 20px;
  1590. background: linear-gradient(to right bottom, #2A56CA, #5795F4);
  1591. }
  1592. &.bg-linear2 {
  1593. color: #fff;
  1594. font-size: 20px;
  1595. background: linear-gradient(to right top, #147FBB, #5EB3E3);
  1596. }
  1597. &.bg-linear3 {
  1598. color: #fff;
  1599. font-size: 20px;
  1600. background: linear-gradient(to right bottom, #2F9E8A, #56CDB1);
  1601. }
  1602. &:hover {
  1603. margin-top: -5px;
  1604. box-shadow: 3px 3px 6px #ccc, -3px -3px 6px #ccc;
  1605. }
  1606. .citem-img {
  1607. width: 50px;
  1608. margin-bottom: 10px;
  1609. }
  1610. }
  1611. }
  1612. .popper-open{
  1613. text-align: center !important;
  1614. padding: 10px !important;
  1615. background: #303133 !important;
  1616. color: #fff !important;
  1617. min-width: 120px !important;
  1618. opacity: 0.8;
  1619. }
  1620. .popper-open[x-placement^=bottom] .popper__arrow::after{
  1621. border-bottom-color: #303133 !important;
  1622. }
  1623. textarea.el-textarea__inner{
  1624. height: 100% !important;
  1625. font-family: "Helvetica Neue",Helvetica,"PingFang SC","Hiragino Sans GB","Microsoft YaHei","微软雅黑",Arial,sans-serif;
  1626. }
  1627. .set-item{
  1628. margin-right: 15px;
  1629. .set-title{
  1630. font-size: 13px;
  1631. }
  1632. }
  1633. .outarea{
  1634. height: 100%;
  1635. border: 1px solid #DCDFE6;
  1636. background-color: #4851a415;
  1637. padding: 15px;
  1638. font-size: 20px;
  1639. overflow: hidden auto;
  1640. }
  1641. .outtext{
  1642. height: 100%;
  1643. font-size: 20px;
  1644. overflow: hidden auto;
  1645. textarea{
  1646. background-color: #4851a415;
  1647. }
  1648. }
  1649. .pin-tips{
  1650. font-size: 14px;
  1651. position: absolute;
  1652. bottom: 10px;
  1653. color: #ff0000;
  1654. left: 0;
  1655. right: 0;
  1656. margin: auto;
  1657. text-align: center;
  1658. }
  1659. .outarea.red-border{
  1660. border: 1px solid #F56C6C;
  1661. }
  1662. .outtext.red-border textarea{
  1663. border: 1px solid #F56C6C;
  1664. }
  1665. h3{
  1666. margin: 0;
  1667. }
  1668. .m-image{
  1669. width: 20px;
  1670. margin-right: 5px;
  1671. }
  1672. </style>