home.vue 142 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934
  1. <template>
  2. <div>
  3. <el-container style="user-select: none; height: 100vh;">
  4. <el-container>
  5. <!-- #333744 -->
  6. <el-aside width="170px" style="border-right: 1px solid #fafafa; background-color: #333744;">
  7. <p class="soft-name" style="-webkit-app-region: drag; color: #fff;">
  8. <img src="../assets/image/icon.png" class="soft-icon" />
  9. {{productName}}
  10. </p>
  11. <el-menu default-active="1" class="xy-menu" active-text-color="#409EFF" background-color="#333744" text-color="#fff" style="margin-top: 10px;">
  12. <el-menu-item index="1" @click="setMenuIndex(1)">
  13. <img src="../assets/image/m-geshi.png" class="m-image"/>
  14. <span slot="title">格式转换</span>
  15. </el-menu-item>
  16. <el-menu-item index="2" @click="setMenuIndex(2)">
  17. <img src="../assets/image/m-yasuo.png" class="m-image"/>
  18. <span slot="title">图片压缩</span>
  19. </el-menu-item>
  20. <el-menu-item index="11" @click="setMenuIndex(11)">
  21. <img src="../assets/image/m-dpi.png" class="m-image"/>
  22. <span slot="title">修改DPI</span>
  23. </el-menu-item>
  24. <el-menu-item index="3" @click="setMenuIndex(3)">
  25. <img src="../assets/image/m-chicun.png" class="m-image"/>
  26. <span slot="title">更改尺寸</span>
  27. </el-menu-item>
  28. <el-menu-item index="4" @click="setMenuIndex(4)">
  29. <img src="../assets/image/m-meihua.png" class="m-image"/>
  30. <span slot="title">美化图片</span>
  31. </el-menu-item>
  32. <el-menu-item index="5" @click="setMenuIndex(5)">
  33. <img src="../assets/image/m-shuiyin.png" class="m-image"/>
  34. <span slot="title">添加水印</span>
  35. </el-menu-item>
  36. <el-menu-item index="6" @click="setMenuIndex(6)">
  37. <img src="../assets/image/m-yuanjiao.png" class="m-image"/>
  38. <span slot="title">图片圆角</span>
  39. </el-menu-item>
  40. <el-menu-item index="9" @click="setMenuIndex(9)">
  41. <img src="../assets/image/m-xuanzhuan.png" class="m-image"/>
  42. <span slot="title">批量旋转</span>
  43. </el-menu-item>
  44. <el-menu-item index="7" @click="setMenuIndex(7)">
  45. <img src="../assets/image/m-name.png" class="m-image"/>
  46. <span slot="title">批量命名</span>
  47. </el-menu-item>
  48. <el-menu-item index="10" @click="setMenuIndex(10)">
  49. <img src="../assets/image/m-caijian.png" class="m-image"/>
  50. <span slot="title">批量裁剪</span>
  51. </el-menu-item>
  52. <el-menu-item index="8" @click="setMenuIndex(8)">
  53. <img src="../assets/image/m-pinjie.png" class="m-image"/>
  54. <span slot="title">图片拼接</span>
  55. </el-menu-item>
  56. </el-menu>
  57. </el-aside>
  58. <el-container>
  59. <el-header height="45px" style="background-color: #fafafa; padding: 0 10px;">
  60. <soft-header ref="headerRef" @update-soft="updateSoft()"
  61. @export-file="exportImg"></soft-header>
  62. </el-header>
  63. <el-main ref="el-main" style="background-color: #fafafa;">
  64. <template>
  65. <div class="content-top">
  66. <div>
  67. <el-button type="primary" size="small" icon="el-icon-document"
  68. @click="pickFile()">添加文件</el-button>
  69. <el-button type="primary" size="small" icon="el-icon-folder"
  70. @click="pickDir()">添加文件夹</el-button>
  71. <el-button type="info" size="small" icon="el-icon-delete"
  72. @click="clearList()">清空图片</el-button>
  73. </div>
  74. </div>
  75. <div v-if="(imgList.length == 0 && menuIndex != 8 && menuIndex != 10) || (mergeList.length == 0 && menuIndex == 8) || (cropList.length == 0 && menuIndex == 10)" class="upload-area">
  76. <div class="file-area" @click="pickFile()" id="drag-jimp">
  77. <div>
  78. <img src="../assets/image/upload.png" style="width: 220px;"/>
  79. <p style="font-size: 16px;">将图片文件拖住至此处,或点击此处选择图片</p>
  80. </div>
  81. </div>
  82. </div>
  83. <div class="img-content" v-else>
  84. <!-- 1、格式转换 2、图片压缩 3、修改dpi-->
  85. <template v-if="menuIndex == 1 || menuIndex == 2 || menuIndex == 11 || menuIndex == 7">
  86. <div :style="menuIndex == 7 ? 'height: calc(100% - 120px);' : 'height: calc(100% - 78px);'">
  87. <vxe-table ref="xRenameTable" v-show="menuIndex == 7" show-overflow class="img-table" max-height="100%" empty-text="没有更多数据了!" :row-config="{isCurrent: true, isHover: true}"
  88. :edit-config="{trigger: 'click', mode: 'cell'}" :data="imgList" :scroll-y="{enabled: true}">
  89. <vxe-column field="name" :title="'文件名'+'(' + imgList.length + ')'" min-width="120"></vxe-column>
  90. <vxe-column field="newName" title="新文件名" min-width="120"></vxe-column>
  91. <vxe-column field="path" title="文件位置" min-width="200"></vxe-column>
  92. <vxe-column field="status" title="状态" min-width="110" max-width="160">
  93. <template #default="{ row }">
  94. <div v-if="row.status == '2'"><i class="el-icon-circle-check" style="color: #19be6b;"></i> 修改成功</div>
  95. <div v-else-if="row.status == '3'"><i class="el-icon-circle-close" style="color: #ed4014;"></i> 修改失败</div>
  96. <div v-else-if="row.status == '4'"><i class="el-icon-warning-outline" style="color: #ff9900;"></i> 文件被修改</div>
  97. <div v-else-if="row.status == '5'"><i class="el-icon-warning-outline" style="color: #ff9900;"></i> 文件已存在</div>
  98. <div v-else>待操作</div>
  99. </template>
  100. </vxe-column>
  101. <vxe-column field="action" title="操作" width="80">
  102. <template #default="{ row, rowIndex }">
  103. <i class="el-icon-delete cur-pointer" @click="delImgFile(rowIndex)"></i>
  104. </template>
  105. </vxe-column>
  106. </vxe-table>
  107. <vxe-table ref="xTable" v-show="menuIndex != 7" show-overflow class="img-table" max-height="100%" empty-text="没有更多数据了!" :row-config="{isCurrent: true, isHover: true}"
  108. :edit-config="{trigger: 'click', mode: 'cell'}" :data="imgList" :scroll-y="{enabled: true}">
  109. <vxe-column field="name" :title="'文件名'+'(' + imgList.length + ')'" min-width="120"></vxe-column>
  110. <!-- <vxe-column field="path" title="缩略图" width="70">
  111. <template #default="{ row }">
  112. <el-image style="width: 30px; height: 30px" :src="row.path" fit="contain"></el-image>
  113. </template>
  114. </vxe-column> -->
  115. <vxe-column field="size" title="大小" min-width="100" max-width="120">
  116. <template #default="{ row }">
  117. <span v-if="row.width == 0 && row.height == 0">-</span>
  118. <span v-else>{{row.size}}</span>
  119. </template>
  120. </vxe-column>
  121. <vxe-column field="width" title="尺寸" min-width="110" max-width="130">
  122. <template #default="{ row }">
  123. <span v-if="row.width == 0 && row.height == 0">{{'加载中 '+row.loadPercent+'%'}}</span>
  124. <span v-else>{{row.width + '*' + row.height}}</span>
  125. </template>
  126. </vxe-column>
  127. <vxe-column field="progress" title="进度" min-width="110" max-width="160">
  128. <template #default="{ row }">
  129. <el-progress :text-inside="true" :stroke-width="20" :percentage="row.percent"></el-progress>
  130. </template>
  131. </vxe-column>
  132. <vxe-column field="action" title="操作" width="80">
  133. <template #default="{ row, rowIndex }">
  134. <i class="el-icon-delete cur-pointer" @click="delImgFile(rowIndex)"></i>
  135. </template>
  136. </vxe-column>
  137. </vxe-table>
  138. </div>
  139. </template>
  140. <!-- 3、更改尺寸 4、美化图片 5、添加水印 6、图片圆角 9、批量旋转 10、图片裁剪 -->
  141. <template v-else-if="[3,4,5,6,9,10].indexOf(menuIndex) > -1">
  142. <div class="soft-content">
  143. <div class="content-left" style="width: calc(100% - 270px)">
  144. <!-- 图片裁剪 -->
  145. <div class="merge-flex">
  146. <div class="merge-scroll">
  147. <vxe-table fit v-if="menuIndex == 10" show-overflow :show-header="false" align="center" height="100%" :row-config="{isCurrent: true, isHover: true, height: 100}"
  148. :data="cropList" @cell-click="selectTabCrop">
  149. <vxe-column field="name" width="123" show-overflow>
  150. <template #default="{ row, rowIndex }">
  151. <vxe-button type="text" icon="vxe-icon-close" class="vxebtn-del" @click="deleteMerge(rowIndex, 'crop')"></vxe-button>
  152. <el-image style="width: 60px; height: 60px" :src="row.path" fit="contain" :title="row.name"></el-image>
  153. <div class="img-mid-progress" v-if="row.percent > 0">
  154. <el-progress :percentage="row.percent"></el-progress>
  155. </div>
  156. <div style="padding: 0 5px; overflow: hidden;white-space: nowrap;text-overflow: ellipsis;" :title="row.name">{{row.name}}</div>
  157. </template>
  158. </vxe-column>
  159. </vxe-table>
  160. <vxe-table fit v-else show-overflow :show-header="false" align="center" height="100%" :row-config="{isCurrent: true, isHover: true, height: 100}"
  161. :data="imgList" @cell-click="selectTab">
  162. <vxe-column field="name" width="123" show-overflow>
  163. <template #default="{ row, rowIndex }">
  164. <vxe-button type="text" icon="vxe-icon-close" class="vxebtn-del" @click="delImgFile(rowIndex)"></vxe-button>
  165. <el-image style="width: 60px; height: 60px" :src="row.path" fit="contain" :title="row.name"></el-image>
  166. <div class="img-mid-progress" v-if="row.percent > 0">
  167. <el-progress :percentage="row.percent"></el-progress>
  168. </div>
  169. <div style="padding: 0 5px; overflow: hidden;white-space: nowrap;text-overflow: ellipsis;" :title="row.name">{{row.name}}</div>
  170. </template>
  171. </vxe-column>
  172. </vxe-table>
  173. </div>
  174. <div class="merge-content" v-if="menuIndex == 10">
  175. <div v-if="cropOptionsImgInfo.width" style="text-align: right; color: #999; margin-bottom: 10px;">
  176. 原图尺寸{{cropOptionsImgInfo.width}}*{{cropOptionsImgInfo.height}}
  177. <span style="margin-left: 30px;">缩放比例{{cropOptions.cropScale.toFixed(1)}}%</span>
  178. <el-button style="margin-left: 30px;" type="primary" plain @click="previewImg" icon="el-icon-view">预览</el-button>
  179. </div>
  180. <div class="mlist-scroll" style="height: calc(100% - 50px);">
  181. <div style="width: 100%; height: 100%;">
  182. <vueCropper
  183. ref="cropper"
  184. :img="cropOptions.img"
  185. :autoCrop="cropOptions.autoCrop"
  186. :autoCropWidth="cropOptions.autoCropWidth"
  187. :autoCropHeight="cropOptions.autoCropHeight"
  188. :centerBox="cropOptions.centerBox"
  189. :fixed="cropOptions.fixed"
  190. :fixedNumber="cropOptions.fixedNumber"
  191. :maxImgSize="cropOptions.maxImgSize"
  192. :original="cropOptions.original"
  193. :canMove="cropOptions.canMove"
  194. :infoTrue="cropOptions.infoTrue"
  195. :info="true"
  196. :full="true"
  197. @realTime="realTime"
  198. @imgLoad="cropImgLoad"
  199. ></vueCropper>
  200. </div>
  201. </div>
  202. </div>
  203. <div class="merge-content" v-else>
  204. <div style="width: 100%; height: 100%;">
  205. <div id="show-img" class="show-img" style="position:relative;overflow: hidden; width: 100%; height: 100%;">
  206. <div style="position: absolute;top: 5px; left: 5px;padding: 0 10px 10px 10px; background: #00000060; color: #fff;font-size: 12px;z-index: 2;">
  207. <label>放大:</label>
  208. <el-slider v-model="viewScale" class="info-input" :min="0.5" :max="5" :step="0.1"></el-slider>
  209. {{viewScale.toFixed(1)}}
  210. </div>
  211. <img draggable="false" class="result-img" :src="imgSrc"
  212. :style="{borderRadius: menuIndex == 6 ? handleData.circularValue+'%' : 0, maxWidth: '80%',maxHeight: '500px', transform: 'rotate('+handleData.rotateValue+'deg) rotateY('+ (handleData.hflip ? '180' : '0') +'deg) rotateX('+ (handleData.vflip ? '180' : '0') +'deg) scale('+viewScale+')'}" />
  213. </div>
  214. </div>
  215. </div>
  216. </div>
  217. </div>
  218. <div class="content-right" style="width: 260px;">
  219. <div class="setting-area">
  220. <div class="img-handle">
  221. <!-- 3更改尺寸 -->
  222. <div v-if="menuIndex == 3">
  223. <div class="handle-item">
  224. <el-radio-group v-model="handleData.sizeType">
  225. <el-radio-button label="1">按比例调整</el-radio-button>
  226. <el-radio-button label="2">按尺寸调整</el-radio-button>
  227. </el-radio-group>
  228. </div>
  229. <div class="handle-item" v-if="handleData.sizeType == '1'">
  230. <label class="handle-label">缩放比例:</label>
  231. <el-input-number size="small" v-model="handleData.scaling" :min="1" :max="500"></el-input-number>
  232. </div>
  233. <div class="handle-item" v-if="handleData.sizeType == '2'">
  234. <label class="handle-label">宽度:</label>
  235. <el-input-number size="small" v-model="handleData.width" :min="1" @change="scaleWidthChange"></el-input-number> px
  236. </div>
  237. <div class="handle-item" v-if="handleData.sizeType == '2'">
  238. <label class="handle-label">高度:</label>
  239. <el-input-number size="small" v-model="handleData.height" :min="1" @change="scaleHeightChange"></el-input-number> px
  240. </div>
  241. <div class="handle-item" v-if="handleData.sizeType == '2'">
  242. <label class="handle-label">锁定比例:</label>
  243. <el-checkbox size="small" v-model="handleData.lockScale"></el-checkbox>
  244. <span style="font-size: 12px; color: #666;">(原始尺寸{{imgInfo.originalWidth}}:{{imgInfo.originalHeight}})</span>
  245. </div>
  246. </div>
  247. <!-- 4美化图片 -->
  248. <div v-if="menuIndex == 4">
  249. <div class="handle-item">
  250. <label class="handle-label">滤镜:</label>
  251. <el-select size="small" v-model="handleData.color" style="width:100px;" @change="handleImg">
  252. <el-option value="0" label="原图"></el-option>
  253. <el-option value="1" label="黑白"></el-option>
  254. <el-option value="2" label="灰度"></el-option>
  255. <el-option value="3" label="反转"></el-option>
  256. <!-- <el-option value="4" label="油画"></el-option> -->
  257. </el-select>
  258. </div>
  259. <!-- <div class="handle-item">
  260. <label class="handle-label">油画半径:</label>
  261. <el-slider v-model="handleData.paintValue" class="info-input" @change="handleImg" :min="1" :max="100"></el-slider>
  262. {{handleData.paintValue}}
  263. </div> -->
  264. <div class="handle-item">
  265. <label class="handle-label">色彩数:</label>
  266. <el-slider v-model="handleData.colorValue" class="info-input" @change="handleImg" :min="1" :max="256"></el-slider>
  267. {{handleData.colorValue}}
  268. </div>
  269. <div class="handle-item">
  270. <label class="handle-label">对比度:</label>
  271. <el-slider v-model="handleData.contrastValue" class="info-input" @change="handleImg" :min="-100" :max="100"></el-slider>
  272. {{handleData.contrastValue}}
  273. </div>
  274. <div class="handle-item">
  275. <label class="handle-label">亮度:</label>
  276. <el-slider v-model="handleData.brightnessValue" class="info-input" :min="-100" :max="100" @change="handleImg"></el-slider>
  277. {{handleData.brightnessValue}}
  278. </div>
  279. <div class="handle-item">
  280. <label class="handle-label">饱和度:</label>
  281. <el-slider v-model="handleData.saturationValue" class="info-input" :min="-100" :max="100" @change="handleImg"></el-slider>
  282. {{handleData.saturationValue}}
  283. </div>
  284. <div class="handle-item">
  285. <label class="handle-label">色调:</label>
  286. <el-slider v-model="handleData.hueValue" class="info-input" :min="-100" :max="100" @change="handleImg"></el-slider>
  287. {{handleData.hueValue}}
  288. </div>
  289. <div class="handle-item">
  290. <label class="handle-label">透明度:</label>
  291. <el-slider v-model="handleData.opacityValue" class="info-input" @change="handleImg"></el-slider>
  292. {{handleData.opacityValue}}
  293. </div>
  294. <div class="handle-item">
  295. <label class="handle-label">边框:</label>
  296. <el-checkbox size="small" v-model="handleData.lineFlag" @change="handleImg">是否添加边框</el-checkbox>
  297. </div>
  298. <div class="handle-item" v-if="handleData.lineFlag">
  299. <label class="handle-label">边框宽度:</label>
  300. <el-input-number size="small" v-model="handleData.lineWidth" @change="handleImg" :min="0"></el-input-number>
  301. </div>
  302. <div class="handle-item" v-if="handleData.lineFlag">
  303. <label class="handle-label">边框颜色:</label>
  304. <el-color-picker style="vertical-align: middle;" size="small" v-model="handleData.lineColor" show-alpha @change="handleImg"></el-color-picker>
  305. </div>
  306. </div>
  307. <!-- 6圆角设置 -->
  308. <template v-if="menuIndex == 6">
  309. <div class="handle-item">
  310. <label class="handle-label">角度:</label>
  311. <el-input-number size="small" v-model="handleData.circularValue" :min="1" :max="100"></el-input-number> %
  312. </div>
  313. </template>
  314. <!-- 5添加水印 -->
  315. <div v-if="menuIndex == 5">
  316. <div class="handle-item">
  317. <el-radio-group v-model="handleData.watermarkType">
  318. <el-radio-button label="1">文字水印</el-radio-button>
  319. <el-radio-button label="2">图片水印</el-radio-button>
  320. </el-radio-group>
  321. </div>
  322. <div class="handle-item" v-if="handleData.watermarkType == '1'">
  323. <label class="handle-label">水印类型:</label>
  324. <el-select size="small" v-model="handleData.watermarkStyle" style="width:150px;">
  325. <el-option value="1" label="单个水印"></el-option>
  326. <el-option value="2" label="多个水印"></el-option>
  327. </el-select>
  328. </div>
  329. <div v-if="handleData.watermarkType == '1'">
  330. <div class="handle-item">
  331. <label class="handle-label">文字内容:</label>
  332. <el-input type="text" v-model="handleData.watermarkValue" size="small" placeholder="请输入文字水印内容" style="width:150px;" @change="handleImg"></el-input>
  333. </div>
  334. <div class="handle-item">
  335. <label class="handle-label">文字样式:</label>
  336. <el-color-picker style="vertical-align: middle;" v-model="handleData.watermarkColor" show-alpha @change="handleImg"></el-color-picker>
  337. <el-input-number size="small" style="width: 105px;" v-model="handleData.watermarkFont" @change="handleImg" :min="0" :max="200"></el-input-number>
  338. </div>
  339. <div class="handle-item">
  340. <label class="handle-label">旋转角度:</label>
  341. <el-input-number size="small" style="width: 140px;" v-model="handleData.rotate" @change="handleImg" ></el-input-number> °
  342. </div>
  343. <div class="handle-item">
  344. <label class="handle-label">文字字体:</label>
  345. <el-select size="small" v-model="handleData.fonts" style="width:120px;" @change="handleImg">
  346. <el-option v-for="(item,key) in fonts" :key="key" :value="item.path" :label="item.name"></el-option>
  347. </el-select>
  348. <vxe-button type="text" status="info" icon="vxe-icon-info-circle-fill" @click="$message({message:'文字为中文时,请选择中文字体!', type:'warning'})"></vxe-button>
  349. </div>
  350. <template v-if="handleData.watermarkStyle == 2">
  351. <div class="handle-item" style="overflow: hidden;" v-if="handleData.watermarkType != '0'">
  352. <label class="handle-label">水印行数:</label>
  353. <el-input-number size="small" :min="1" v-model="handleData.watermarkDensityY" @change="handleImg" ></el-input-number>
  354. </div>
  355. <div class="handle-item" style="overflow: hidden;" v-if="handleData.watermarkType != '0'">
  356. <label class="handle-label">水印列数:</label>
  357. <el-input-number size="small" :min="1" v-model="handleData.watermarkDensityX" @change="handleImg" ></el-input-number>
  358. </div>
  359. </template>
  360. </div>
  361. <!-- 图片水印 -->
  362. <div v-if="handleData.watermarkType == '2'">
  363. <div class="handle-item">
  364. <label class="handle-label">图片水印:</label>
  365. <el-upload :style="{display: 'inline-block'}" action="/" :before-upload="getImgPath">
  366. <el-input type="text" readonly v-model="handleData.watermarkImgPath" size="small" style="width:125px;" ></el-input>
  367. <i class="el-icon-folder-opened open-folder" style="font-size:22px;"></i>
  368. </el-upload>
  369. </div>
  370. <div class="handle-item">
  371. <label class="handle-label">比例:</label>
  372. <el-input-number size="small" style="margin-right:5px;" :min="1" :max="200" v-model="handleData.watermarkImgSize" @change="handleImg" ></el-input-number>%
  373. </div>
  374. <div class="handle-item" v-if="handleData.watermarkType == '2'">
  375. <label class="handle-label">不透明度:</label>
  376. <el-input-number size="small" style="margin-right:5px;" :min="1" :max="100" v-model="handleData.watermarkImgOpactiy" @change="handleImg" ></el-input-number>
  377. </div>
  378. </div>
  379. <div class="handle-item" v-if="handleData.watermarkType == '2'">
  380. <label class="handle-label">旋转角度:</label>
  381. <el-input-number size="small" v-model="handleData.watermarkImgRotate" @change="handleImg" ></el-input-number>
  382. </div>
  383. <div class="handle-item" v-if="handleData.watermarkType != '0'">
  384. <label class="handle-label">水印位置:</label>
  385. <el-radio-group class="position-radio" v-model="handleData.watermarkPosition" :style="{width: '120px', color: '#fff'}" @change="handleImg">
  386. <el-radio :disabled="handleData.watermarkStyle == '2' && handleData.watermarkType == 1" :style="{margin: '2px 2px 2px 0', fontSize: 0}" v-for="key in watermarkPosition" :key="key" :label="key"></el-radio>
  387. </el-radio-group>
  388. <div>
  389. <div style="padding-bottom: 3px;">
  390. <label class="handle-label">水平边距:</label>
  391. <el-input-number size="small" v-model="handleData.watermarkX" @change="handleImg" ></el-input-number>
  392. </div>
  393. <div>
  394. <label class="handle-label">垂直边距:</label>
  395. <el-input-number size="small" v-model="handleData.watermarkY" @change="handleImg" ></el-input-number>
  396. </div>
  397. </div>
  398. </div>
  399. </div>
  400. <!-- 9批量旋转 -->
  401. <div v-if="menuIndex == 9">
  402. <div class="handle-item xuan-flex">
  403. <div class="xuan-item" @click="rotateChange(1)">
  404. <img src="../assets/image/ni.png" />
  405. <p>逆时针旋转90°</p>
  406. </div>
  407. <div class="xuan-item" @click="rotateChange(2)">
  408. <img src="../assets/image/shun.png" />
  409. <p>顺时针旋转90°</p>
  410. </div>
  411. </div>
  412. <div class="handle-item xuan-flex">
  413. <div class="xuan-item" :class="handleData.hflip == 'hflip' ? 'active' : '' " @click="flipChange('hflip')">
  414. <img src="../assets/image/left-right.png" />
  415. <p>左右翻转</p>
  416. </div>
  417. <div class="xuan-item" :class="handleData.vflip == 'vflip' ? 'active' : '' " @click="flipChange('vflip')">
  418. <img src="../assets/image/up-down.png" />
  419. <p>上下翻转</p>
  420. </div>
  421. </div>
  422. <div class="handle-item">
  423. <label class="handle-label">旋转角度:</label>
  424. <el-input-number size="small" :max="360" :min="-360" v-model="handleData.rotateValue" ></el-input-number> °
  425. </div>
  426. <div class="handle-item" style="text-align: center;">
  427. <el-tag type="danger">正值向右旋转,负值向左旋转</el-tag>
  428. </div>
  429. </div>
  430. <!-- 10图片裁剪 -->
  431. <template v-if="menuIndex == 10">
  432. <div class="handle-item">
  433. <el-radio-group v-model="cropOptions.cropType">
  434. <el-radio-button label="1">比例裁剪</el-radio-button>
  435. <el-radio-button label="2">尺寸裁剪</el-radio-button>
  436. </el-radio-group>
  437. </div>
  438. <div class="handle-item" style="margin: 5px 0;" v-if="cropOptions.cropType == '1'">
  439. <div class="handle-title">裁剪比例</div>
  440. <div class="flex-crop">
  441. <el-button class="crop-button" :type="cropOptions.fixedValue == 'free' ? 'primary' : 'default'" @click="fixedChange('free')">自由</el-button>
  442. <el-button class="crop-button" :type="cropOptions.fixedValue == 'original' ? 'primary' : 'default'" @click="fixedChange('original')">原图</el-button>
  443. <el-button class="crop-button" :type="cropOptions.fixedValue == '1:1' ? 'primary' : 'default'" @click="fixedChange('1:1')">1:1</el-button>
  444. <el-button class="crop-button" :type="cropOptions.fixedValue == '1:2' ? 'primary' : 'default'" @click="fixedChange('1:2')">1:2</el-button>
  445. <el-button class="crop-button" :type="cropOptions.fixedValue == '2:1' ? 'primary' : 'default'" @click="fixedChange('2:1')">2:1</el-button>
  446. <el-button class="crop-button" :type="cropOptions.fixedValue == '2:3' ? 'primary' : 'default'" @click="fixedChange('2:3')">2:3</el-button>
  447. <el-button class="crop-button" :type="cropOptions.fixedValue == '3:2' ? 'primary' : 'default'" @click="fixedChange('3:2')">3:2</el-button>
  448. <el-button class="crop-button" :type="cropOptions.fixedValue == '3:4' ? 'primary' : 'default'" @click="fixedChange('3:4')">3:4</el-button>
  449. <el-button class="crop-button" :type="cropOptions.fixedValue == '4:3' ? 'primary' : 'default'" @click="fixedChange('4:3')">4:3</el-button>
  450. <el-button class="crop-button" :type="cropOptions.fixedValue == '5:3' ? 'primary' : 'default'" @click="fixedChange('5:3')">5:3</el-button>
  451. <el-button class="crop-button" :type="cropOptions.fixedValue == '9:16' ? 'primary' : 'default'" @click="fixedChange('9:16')">9:16</el-button>
  452. <el-button class="crop-button" :type="cropOptions.fixedValue == '16:9' ? 'primary' : 'default'" @click="fixedChange('16:9')">16:9</el-button>
  453. </div>
  454. </div>
  455. <template v-if="cropOptions.cropType == '2'">
  456. <div class="handle-item">
  457. <el-radio-group size="mini" v-model="cropOptions.cropClassify" @change="classifyChange">
  458. <el-radio-button label="1">自定义</el-radio-button>
  459. <el-radio-button label="2">证件</el-radio-button>
  460. <el-radio-button label="3">电商</el-radio-button>
  461. </el-radio-group>
  462. </div>
  463. <div v-if="cropOptions.cropClassify == '2'">
  464. <el-button class="crop-button" style="width: 220px; margin-bottom: 10px; margin-left: 10px;" :type="cropOptions.fixedValue == '259:377' ? 'primary' : 'default'" @click="fixedChange('259:377')">
  465. 小一寸259x377px | 2.2x3.3cm
  466. <p style="opacity: 0.6; margin-top: 6px;">驾驶证、体检表等</p>
  467. </el-button>
  468. <el-button class="crop-button" style="width: 220px; margin-bottom: 10px;" :type="cropOptions.fixedValue == '295:413' ? 'primary' : 'default'" @click="fixedChange('295:413')">
  469. 一寸295x413px | 2.5x3.5cm
  470. <p style="opacity: 0.6; margin-top: 6px;">学生证、健康证等</p>
  471. </el-button>
  472. <el-button class="crop-button" style="width: 220px; margin-bottom: 10px;" :type="cropOptions.fixedValue == '390:567' ? 'primary' : 'default'" @click="fixedChange('390:567')">
  473. 大一寸390x567px | 3.3x4.8cm
  474. <p style="opacity: 0.6; margin-top: 6px;">护照、港澳通行证等</p>
  475. </el-button>
  476. <el-button class="crop-button" style="width: 220px; margin-bottom: 10px;" :type="cropOptions.fixedValue == '413:531' ? 'primary' : 'default'" @click="fixedChange('413:531')">
  477. 小二寸413x531px | 3.5x4.5cm
  478. <p style="opacity: 0.6; margin-top: 6px;">个人简历、考试报名</p>
  479. </el-button>
  480. <el-button class="crop-button" style="width: 220px; margin-bottom: 10px;" :type="cropOptions.fixedValue == '413:579' ? 'primary' : 'default'" @click="fixedChange('413:579')">
  481. 二寸413x579px | 3.5x4.9cm
  482. <p style="opacity: 0.6; margin-top: 6px;">公务员考试、部分签证等</p>
  483. </el-button>
  484. </div>
  485. <div v-if="cropOptions.cropClassify == '3'">
  486. <el-button class="crop-button" style="width: 220px; margin-bottom: 10px; margin-left: 10px;" :type="cropOptions.fixedValue == '1920:500' ? 'primary' : 'default'" @click="fixedChange('1920:500')">
  487. 首页横幅 1920x500
  488. </el-button>
  489. <el-button class="crop-button" style="width: 220px; margin-bottom: 10px;" :type="cropOptions.fixedValue == '750:800' ? 'primary' : 'default'" @click="fixedChange('750:800')">
  490. 详情页 750x800
  491. </el-button>
  492. <el-button class="crop-button" style="width: 220px; margin-bottom: 10px;" :type="cropOptions.fixedValue == '800:800' ? 'primary' : 'default'" @click="fixedChange('800:800')">
  493. 产品主图 800x800
  494. </el-button>
  495. <el-button class="crop-button" style="width: 220px; margin-bottom: 10px;" :type="cropOptions.fixedValue == '1920:120' ? 'primary' : 'default'" @click="fixedChange('1920:120')">
  496. 店招 1920x120
  497. </el-button>
  498. <el-button class="crop-button" style="width: 220px; margin-bottom: 10px;" :type="cropOptions.fixedValue == '750:500' ? 'primary' : 'default'" @click="fixedChange('750:500')">
  499. 首页横幅 750x500
  500. </el-button>
  501. <el-button class="crop-button" style="width: 220px; margin-bottom: 10px;" :type="cropOptions.fixedValue == '740x352' ? 'primary' : 'default'" @click="fixedChange('740:352')">
  502. 商品主图 740x352
  503. </el-button>
  504. <el-button class="crop-button" style="width: 220px; margin-bottom: 10px;" :type="cropOptions.fixedValue == '640x320' ? 'primary' : 'default'" @click="fixedChange('640:320')">
  505. 手机详情页 640x320
  506. </el-button>
  507. </div>
  508. <template v-if="cropOptions.cropClassify == '1'">
  509. <div class="handle-title">裁剪尺寸</div>
  510. <div class="handle-item">
  511. <label class="handle-label">宽度:</label>
  512. <el-input-number size="small" :min="1" v-model="virtualWidth" @change="cropWidthChange"></el-input-number> px
  513. </div>
  514. <div class="handle-item">
  515. <label class="handle-label">高度:</label>
  516. <el-input-number size="small" :min="1" v-model="virtualHeight" @change="cropHeightChange"></el-input-number> px
  517. </div>
  518. <div class="handle-item">
  519. <label class="handle-label">锁定比例:</label>
  520. <el-checkbox v-model="cropOptions.fixed"></el-checkbox>
  521. <span style="font-size: 12px; color: #666;">(原始尺寸{{cropOptionsImgInfo.originalWidth}}:{{cropOptionsImgInfo.originalHeight}})</span>
  522. </div>
  523. </template>
  524. </template>
  525. <div style="text-align: center;">
  526. <el-badge v-if="cropOptions.cropType == '2' && cropOptions.cropClassify != '1'" is-dot style="font-size: 12px;">裁剪尺寸大于原图尺寸时,会等比例放大原图后进行裁剪</el-badge>
  527. <el-button style="margin: 20px 0;" type="info" @click="setModal = true;">应用全部</el-button>
  528. <el-button type="info" plain @click="resetModal = true;">重置设置</el-button>
  529. </div>
  530. <div class="handle-item" style="text-align: center;">
  531. <el-tag type="danger">批量裁剪请点击“应用全部”按钮</el-tag>
  532. </div>
  533. </template>
  534. </div>
  535. </div>
  536. </div>
  537. </div>
  538. </template>
  539. <!-- 8图片拼接 -->
  540. <template v-if="menuIndex == 8">
  541. <div class="soft-content">
  542. <div class="content-left" style="width: calc(100% - 270px)">
  543. <div class="merge-flex">
  544. <draggable class="merge-scroll" tag="div" v-model="mergeList" :animation="200" :scroll="true" @end="dragEnd" >
  545. <div class="merge-item" v-for=" (item, index) in mergeList" :key="index">
  546. <div class="img-area">
  547. <div style="width: 100%;height: 100%; flex: 1;position: relative;">
  548. <i class="el-icon-close merge-imgdel" @click="deleteMerge(index)"></i>
  549. <img :src="item.path" class="mergelist-img">
  550. </div>
  551. </div>
  552. <p :title="item.name" class="merge-name overflow">{{item.name}}</p>
  553. </div>
  554. </draggable>
  555. <div class="merge-content">
  556. <div class="merge-top">
  557. <div style="line-height: 34px;color: #333;">
  558. {{mergeList.length}} / <span style="color: #999;">100</span>
  559. <!-- <vxe-button type="text" status="info" icon="vxe-icon-info-circle-fill" @click="$message({message:'上下拖动左侧图片可调整前后顺序', type:'warning'})"></vxe-button> -->
  560. </div>
  561. <div class="action-right" v-if="mergeData.sortType == 3">
  562. <div class="action-ritem" @click="zoom('reduce')">
  563. <i class="el-icon-zoom-out" style="font-size: 20px;"></i>
  564. <p>缩小</p>
  565. </div>
  566. <div class="action-ritem" @click="zoom('enlarge')">
  567. <i class="el-icon-zoom-in" style="font-size: 20px;"></i>
  568. <p>放大</p>
  569. </div>
  570. </div>
  571. </div>
  572. <div class="mlist-scroll bgmini">
  573. <!-- 横图 -->
  574. <div class="horizontal-scroll" v-if="mergeData.sortType == 1" :style="'padding: '+ hBorder + 'px;background-color:'+mergeData.backgroundColor+';'">
  575. <div class="horizontal-content" id="horizontal-content">
  576. <img class="horizontal-img" :id="'horizontal-img-'+key" v-for="(item, key) in mergeList" :key="key" :style="'border-radius:'+ mergeData.radius / 2 +'%;margin-right:' + hSpace + 'px;'" :src="item.path" />
  577. </div>
  578. </div>
  579. <!-- 竖图 -->
  580. <div class="vertical-content" id="vertical-content" v-if="mergeData.sortType == 2" :style="'padding: '+ vBorder + 'px;background-color:'+mergeData.backgroundColor+';'">
  581. <img class="vertical-img" v-for="(item, key) in mergeList" :key="key" :style="'border-radius:'+ mergeData.radius / 2 +'%;margin-bottom:' + vSpace + 'px;'" :src="item.path" />
  582. </div>
  583. <!-- 自定义 -->
  584. <div v-if="mergeData.sortType == 3" class="mlist-content" :style="mergeData.autoStyle+'transform: scale('+mergeData.zoom+')'">
  585. <div id="mlist-area" class="mlist-area" :style="'padding: '+ mergeData.border / 10 + '%;background-color:'+mergeData.backgroundColor+';'">
  586. <div class="merge-row" :style="blockStyle('height')" v-for="row in mergeData.row" :key="row">
  587. <div v-if="mergeData.mergeType == 2" class="merge-col" :style="blockStyle('width')" v-for="col in mergeData.col" :key="col">
  588. <img @mouseover="move((row-1)*mergeData.col+col-1)" :id="'merge-imgId-'+Number((row-1)*mergeData.col+col-1)"
  589. class="merge-img" v-if="mergeList.length > (row-1)*mergeData.col+col-1"
  590. :src="mergeList[Number((row-1)*mergeData.col+col-1)].path"
  591. :style="picStyle(Number((row-1)*mergeData.col+col-1))" />
  592. <div v-else class="merge-add" @click="pickFile()">+</div>
  593. </div>
  594. <div v-if="mergeData.mergeType == 1" class="merge-col" :style="blockStyle('width')" v-for="col in mergeData.col" :key="col">
  595. <img @mouseover="move((row-1)*mergeData.col+col-1)" :id="'merge-imgId-'+Number((row-1)*mergeData.col+col-1)"
  596. class="merge-img2" v-if="mergeList.length > (row-1)*mergeData.col+col-1"
  597. :src="mergeList[Number((row-1)*mergeData.col+col-1)].path" />
  598. <div v-else class="merge-add" @click="pickFile()">+</div>
  599. <span v-if="mergeList.length > (row-1)*mergeData.col+col-1" :style="picStyle(Number((row-1)*mergeData.col+col-1))" class="disnone"></span>
  600. </div>
  601. </div>
  602. </div>
  603. </div>
  604. </div>
  605. </div>
  606. </div>
  607. </div>
  608. <div class="content-right" style="width: 260px;">
  609. <div class="setting-area">
  610. <div class="img-handle">
  611. <div class="handle-item">
  612. <el-radio-group v-model="mergeData.sortType" @change="sortChange" size="small">
  613. <el-radio-button :label="2">拼长竖图</el-radio-button>
  614. <el-radio-button :label="1">拼长横图</el-radio-button>
  615. <el-radio-button :label="3">自定义</el-radio-button>
  616. </el-radio-group>
  617. </div>
  618. <div class="handle-item" v-if="mergeData.sortType == 3">
  619. <label class="handle-label">画布尺寸:</label>
  620. <el-select size="small" v-model="mergeData.sizeType" style="width:150px;" @change="canvasChange">
  621. <el-option value="1200*1200px(1:1)"></el-option>
  622. <el-option value="1200*1800px(2:3)"></el-option>
  623. <el-option value="1800*1200px(3:2)"></el-option>
  624. <el-option value="1200*1600px(3:4)"></el-option>
  625. <el-option value="1600*1200px(4:3)"></el-option>
  626. <el-option value="1920*1080px(16:9)"></el-option>
  627. <el-option value="1080*1920px(9:16)"></el-option>
  628. </el-select>
  629. </div>
  630. <div class="handle-item">
  631. <label class="handle-label">画布宽度:</label>
  632. <el-input-number size="small" style="width: 140px;" :max="10000" :min="1" v-model="mergeData.outWidth" @change="outWidthChange" ></el-input-number>
  633. <i class="el-icon-connection" style="font-size: 16px;position: absolute;left: 20px; bottom: -6px;"></i>
  634. </div>
  635. <div class="handle-item">
  636. <label class="handle-label">画布高度:</label>
  637. <el-input-number size="small" style="width: 140px;" :max="10000" :min="1" v-model="mergeData.outHeight" @change="outHeightChange" ></el-input-number>
  638. </div>
  639. <div class="handle-item" v-if="mergeData.sortType != 3">
  640. <label class="handle-label">原图比例:</label>
  641. <el-input v-model="mergeData.width" :disabled="true" size="small" style="width: 70px;"></el-input>
  642. <!-- <el-input-number :disabled="mergeData.sortType != 3" size="small" style="width: 70px;" :max="10000" :min="1" v-model="mergeData.width" @change="widthChange" ></el-input-number> -->
  643. <i class="el-icon-connection" style="font-size: 16px;"></i>
  644. <!-- <el-input-number :disabled="mergeData.sortType != 3" size="small" style="width: 70px;" :max="10000" :min="1" v-model="mergeData.height" @change="heightChange" ></el-input-number> -->
  645. <el-input v-model="mergeData.height" :disabled="true" size="small" style="width: 70px;"></el-input>
  646. </div>
  647. <div class="handle-item" v-if="mergeData.sortType == 3">
  648. <label class="handle-label">锁定比例:</label>
  649. <el-checkbox v-model="mergeData.lockScale"></el-checkbox>
  650. </div>
  651. <div class="handle-item" v-if="mergeData.sortType == 3">
  652. <label class="handle-label">拼接模式:</label>
  653. <el-radio-group size="small" v-model="mergeData.mergeType" style="vertical-align: inherit;">
  654. <el-radio :label="1">自适应</el-radio>
  655. <el-radio :label="2">裁剪</el-radio>
  656. </el-radio-group>
  657. </div>
  658. <div class="handle-item" v-if="mergeData.sortType == 3">
  659. <label class="handle-label">行数:</label>
  660. <el-input-number size="small" style="width: 110px;" :max="50" :min="1" v-model="mergeData.row" @change="rowColChange" ></el-input-number>
  661. </div>
  662. <div class="handle-item" v-if="mergeData.sortType == 3">
  663. <label class="handle-label">列数:</label>
  664. <el-input-number size="small" style="width: 110px;" :max="50" :min="1" v-model="mergeData.col" @change="rowColChange" ></el-input-number>
  665. </div>
  666. <div class="handle-item">
  667. <label class="handle-label">间距:</label>
  668. <el-input-number size="small" style="width: 110px;" :max="100" :min="0" v-model="mergeData.space" @blur="numBlur('space')" @change="sizeChange" ></el-input-number> %
  669. </div>
  670. <div class="handle-item">
  671. <label class="handle-label">边距:</label>
  672. <el-input-number size="small" style="width: 110px;" :max="100" :min="0" v-model="mergeData.border" @blur="numBlur('border')" @change="sizeChange" ></el-input-number> %
  673. </div>
  674. <div class="handle-item">
  675. <label class="handle-label">圆角:</label>
  676. <el-input-number size="small" style="width: 110px;" :max="100" :min="0" v-model="mergeData.radius" @blur="numBlur('radius')" ></el-input-number> %
  677. </div>
  678. <div class="handle-item">
  679. <label class="handle-label">背景:</label>
  680. <el-color-picker size="small" style="vertical-align: middle;" v-model="mergeData.backgroundColor" show-alpha></el-color-picker>
  681. </div>
  682. </div>
  683. </div>
  684. </div>
  685. </div>
  686. </template>
  687. <!-- 底部设置区域 -->
  688. <div class="img-footer-area">
  689. <div class="handle-item" v-if="menuIndex == 7">
  690. <label class="handle-label" style="width:80px;">起始编号:</label>
  691. <el-input-number size="small" style="width: 110px;" :min="0" v-model="handleRename.startNumber" @change="setChange" ></el-input-number>
  692. <label class="handle-label">增量:</label>
  693. <el-input-number size="small" style="width: 110px;" v-model="handleRename.increment" @change="setChange" ></el-input-number>
  694. <span class="i-desc font-12">(后一位编号增加的值)</span>
  695. <label class="handle-label">位数:</label>
  696. <el-input-number size="small" style="width: 110px;" v-model="handleRename.digit" @change="setChange" ></el-input-number>
  697. <span class="i-desc font-12">(例:001的编号位数为3)</span>
  698. </div>
  699. <div class="footer-line-between">
  700. <!-- 1格式转化 -->
  701. <div class="handle-item" v-if="menuIndex == 1">
  702. <label class="handle-label">输出转换:</label>
  703. <el-select v-model="handleData.imgFormat" style="width:100px;" size="small">
  704. <el-option v-for="(item, key) in imgFormat" :key="key" :value="item" :label="item"></el-option>
  705. </el-select>
  706. <vxe-button v-if="handleData.imgFormat == 'ICO'" type="text" status="info" icon="vxe-icon-info-circle-fill" @click="$message('图标资源ICO有最大尺寸限制,建议尺寸低于512x512')"></vxe-button>
  707. <vxe-button v-if="isGif" type="text" status="info" icon="vxe-icon-info-circle-fill" @click="$message('GIF图片默认输出第一帧,多帧输出到单独文件夹中')"></vxe-button>
  708. <el-checkbox v-if="isGif" v-model="gifChecked">GIF图片输出所有帧</el-checkbox>
  709. </div>
  710. <!-- 2图片压缩 -->
  711. <div class="handle-item" v-if="menuIndex == 2">
  712. <label class="handle-label">压缩质量:</label>
  713. <el-input-number v-model="handleData.quality" :min="1" :max="100" size="small"></el-input-number>
  714. <el-tag size="mini" type="danger" style="margin-left: 10px;">质量越低压缩的越小</el-tag>
  715. </div>
  716. <!-- 11修改dpi -->
  717. <div class="handle-item" v-if="menuIndex == 11">
  718. <label>将图片DPI更改为:</label>
  719. <el-select v-model="handleData.dpi" style="width:100px;" size="small">
  720. <el-option :value="72" label="72DPI"></el-option>
  721. <el-option :value="96" label="96DPI"></el-option>
  722. <el-option :value="150" label="150DPI"></el-option>
  723. <el-option :value="200" label="200DPI"></el-option>
  724. <el-option :value="300" label="300DPI"></el-option>
  725. <el-option :value="350" label="350DPI"></el-option>
  726. <el-option :value="500" label="500DPI"></el-option>
  727. <el-option :value="1000" label="1000DPI"></el-option>
  728. </el-select>
  729. <vxe-button type="text" status="info" icon="vxe-icon-info-circle-fill" @click="$message({message:'提高分辨率(DPI)不能让模糊的图片变清晰,也不会改变照片的高宽像素等属性', type:'warning'})"></vxe-button>
  730. </div>
  731. <!-- 8图片拼接 -->
  732. <div v-if="menuIndex == 8">
  733. <el-tag type="danger">拖动左侧列表中的图片可以调整拼接顺序</el-tag>
  734. </div>
  735. <!-- 7重命名 -->
  736. <div v-if="menuIndex == 7">
  737. <div class="handle-item" >
  738. <label class="handle-label" style="width: 80px;">新图片名:</label>
  739. <el-input type="text" v-model="handleRename.fileName" size="small" placeholder="请输入新图片名" style="width:200px;" @change="setChange"></el-input>
  740. </div>
  741. </div>
  742. <div v-else> </div>
  743. <div>
  744. <span>保存目录:</span>
  745. <el-input :title="handleData.newPath" ref="upload-input" @focus="pickPath" placeholder="请选择输出目录" size="small" v-model="handleData.newPath" readonly style="width:180px;" prefix-icon="el-icon-folder"></el-input>
  746. <el-popover placement="bottom" popper-class="popper-open" trigger="hover" content="打开保存目录">
  747. <i class="el-icon-folder-opened" slot="reference" style="padding-left: 5px; cursor: pointer; font-size: 22px; vertical-align: middle;" @click="openFolder()"></i>
  748. </el-popover>
  749. <el-button type="danger" style="margin: 0 20px;" @click="exportImg()" :loading="loading">开始转换</el-button>
  750. </div>
  751. </div>
  752. </div>
  753. </div>
  754. </template>
  755. </el-main>
  756. <el-footer height="48px">
  757. <!-- 更新 -->
  758. <soft-update ref="updateRef" :showDowload="dowloadModel"
  759. :dowloadFinish="finishModel"></soft-update>
  760. </el-footer>
  761. </el-container>
  762. </el-container>
  763. </el-container>
  764. <!-- <el-dialog title="图片预览" :visible.sync="imgShow" :fullscreen="true">
  765. <div style="width:100%;height:100%;overflow: auto;text-align:center">
  766. <img draggable="false" :src="imgSrc"
  767. :style="{borderRadius: menuIndex == 6 ? handleData.circularValue : 0 +'%', 'maxWidth': '100%','maxHeight':'100%',transform: 'rotate('+handleData.rotateValue+'deg) rotateY('+ (handleData.hflipflip ? '180' : '0') +'deg) rotateX('+ (handleData.vflip ? '180' : '0') +'deg) scale('+handleData.scaling/100+')'}"/>
  768. </div>
  769. </el-dialog> -->
  770. <el-dialog title="截图预览" :visible.sync="cropimgShow" :fullscreen="true">
  771. <div v-html="cropOptions.previewInfo" style="margin: auto;"></div>
  772. </el-dialog>
  773. <el-dialog title="温馨提示" :visible.sync="setModal">
  774. <p>是否将当前图片的裁剪设置应用到所有图片?</p>
  775. <span slot="footer">
  776. <el-button @click="setModal = false">取 消</el-button>
  777. <el-button type="primary" @click="setOk()">确 定</el-button>
  778. </span>
  779. </el-dialog>
  780. <el-dialog title="温馨提示" :visible.sync="resetModal">
  781. <p>是否重置所有图片的裁剪设置?</p>
  782. <span slot="footer">
  783. <el-button @click="resetModal = false">取 消</el-button>
  784. <el-button type="primary" @click="resetOk()">确 定</el-button>
  785. </span>
  786. </el-dialog>
  787. <el-dialog :visible.sync="renameModal" width="400px">
  788. <el-result icon="success" title="处理完成" :subTitle="subTitle">
  789. <template slot="extra">
  790. <el-button type="primary" @click="renameModal = false;">确定</el-button>
  791. </template>
  792. </el-result>
  793. </el-dialog>
  794. </div>
  795. </template>
  796. <script>
  797. import os from 'os'
  798. import fs from 'fs'
  799. import pathMod, { resolve } from 'path';
  800. import electronApi from '@/utils/electronApi';
  801. import softUpdate from './update.vue';
  802. import softHeader from './header.vue';
  803. import pjson from '/package.json'
  804. import Draggable from 'vuedraggable'
  805. import Vue from 'vue'
  806. import { VueCropper } from 'vue-cropper'
  807. const sizeOf = require('image-size')
  808. let separator = '';
  809. if (os.platform == 'linux') {
  810. separator = '/'
  811. } else {
  812. separator = '\\'
  813. }
  814. export default {
  815. name: 'landing-page',
  816. components: {
  817. softUpdate,
  818. softHeader,
  819. Draggable,
  820. VueCropper
  821. },
  822. data() {
  823. return {
  824. isGif: false, //是否含有gif图片
  825. gifChecked: false, // 是否输出所有帧
  826. rollFlag: false,
  827. viewScale: 1,
  828. productName: pjson.softInfo.softName,
  829. setModal: false,
  830. resetModal: false,
  831. renameModal: false,
  832. subTitle: '请查看列表文件状态',
  833. cropimgShow: false,
  834. cropImgIndex: -1,
  835. cropInt: false,
  836. selectInt: false,
  837. cropImgLoading: false,
  838. virtualWidth: 0,
  839. virtualHeight: 0,
  840. cropOptionsImgInfo: {},
  841. cropOptions: {
  842. img: '',
  843. autoCrop: true, // 是否默认生成截图框
  844. autoCropWidth: 100,
  845. autoCropHeight: 100,
  846. cropWidth: 100,
  847. cropHeight: 100,
  848. original: false,
  849. maxImgSize: 20000,
  850. canMove: false,
  851. centerBox: true, // 截图框是否被限制在图片里面
  852. fixed: false, //是否开启截图框宽高固定比例
  853. fixedValue: 'free',
  854. cropType: '1',
  855. cropClassify: '1',
  856. fixedNumber: [1, 1],
  857. infoTrue: true,
  858. previewInfo: '',
  859. cropScale: 100,
  860. },
  861. execLimit: 3,
  862. defaultFont:'c:\\windows\\fonts\\simkai.ttf',
  863. imgShow:false,
  864. pickProgress:false,
  865. pickProgressPercent:0,
  866. fonts:[],
  867. watermarkPosition:['NorthWest','North','NorthEast','West','Center','East','SouthWest','South','SouthEast'],
  868. imgUrl: this.$api.imgUrl,
  869. imgSrc: '',
  870. imgList: [],
  871. mergeList: [], // 拼接图片列表
  872. cropList: [], // 裁剪图片列表
  873. imgInfo: '',
  874. imgInfoIndex: 0,
  875. menuIndex: 1, // 选中菜单
  876. imgFormat: ['PNG','BMP','JPEG','JPG','ICO','WBMP','WEBP','HEIC','GIF','JFIF','TTF','TIF','TIFF','SVG','3FR','3G2','3GP','AAI','AI','ART','ARW','BGR','BGRA','BGRO','BIE','BMP2','BMP3','BRF','CAL','CALS','CANVAS','CAPTION','CIN','CIP','CLIP','CMYK','CMYKA','CR2','CRW','CUR','CUT','DATA','DCM','DCR','DCX','DDS','DFONT','DJVU','DNG','DOT','DPX','DXT1','DXT5','EPDF','EPI','EPS','EPS2','EPS3','EPSF','EPSI','EPT','EPT2','EPT3','ERF','EXR','FAX','FILE','FITS','FRACTAL','FTP','FTS','G3','G4','GIF87','GRADIENT','GRAY','GRAYA','GROUP4','GV','H','HALD','HDR','HISTOGRAM','HRZ','ICB','ICON','IIQ','INFO','INLINE','IPL','ISOBRL','ISOBRL6','J2C','J2K','JBG','JBIG','JNG','JNX','JP2','JPC','JPE','JPM','JPS','JPT','JSON','K25','KDC','LABEL','M2V','M4V','MAC','MAGICK','MAP','MASK','MAT','MATTE','MEF','MIFF','MKV','MNG','MONO','MRW','MSL','MSVG','MVG','NEF','NRW','ORF','OTB','OTF','PAL','PALM','PAM','PANGO','PATTERN','PBM','PCD','PCDS','PCL','PCT','PEF','PES','PFA','PFB','PFM','PGM','PGX','PICON','PICT','PIX','PJPEG','PLASMA','PNG00','PNG24','PNG32','PNG48','PNG64','PNG8','PNM','PPM','PREVIEW','PS','PS2','PS3','PSB','PSD','PTIF','PWP','RADIAL-GRADIENT','RAF','RAS','RAW','RGB','RGBA','RGBO','RGF','RLA','RLE','RMF','RW2','SCR','SCT','SFW','SGI','SHTML','SIX','SIXEL','SPARSE-COLOR','SR2','SRF','STEGANO','SUN','SVGZ','TGA','THUMBNAIL','TIFF64','TILE','UBRL','UBRL6','UIL','UYVY','VDA','VICAR','VID','VIFF','VIPS','VST','WMF','WMV','WMZ','WPG','X','X3F','XBM','XC','XCF','XPM','XPS','XV','XWD','YCbCr','YCbCrA','YUV'], // 图片格式
  877. positionList: ['上左', '上中', '上右', '中左', '中间', '中右', '下左', '下中', '下右'],
  878. downloadDir: '', // 默认下载目录
  879. softdownloadDir: '', // 软件下载目录
  880. mergeData: {
  881. space: 0,
  882. border: 0,
  883. radius: 0,
  884. row: 2,
  885. col: 2,
  886. width: 1200,
  887. height: 1200,
  888. contentWidth: 0,
  889. contentHeight: 0,
  890. outWidth: 1200,
  891. outHeight: 1200,
  892. backgroundColor: 'rgba(255,255,255,1)',
  893. sizeType: '1200*1200px(1:1)',
  894. scale: '1:1',
  895. zoom: 1,
  896. lockScale: true,
  897. autoStyle: 'padding-top: 50%;',
  898. mergeType: 2,
  899. sortType: 2
  900. },
  901. handleData: {
  902. dpi: 300,
  903. width: 0,
  904. height: 0,
  905. pathType: '2', // 输出目录类型
  906. newPath: os.userInfo().homedir + separator + "Downloads", // 新路径
  907. autoRename: false, // 是否自动重命名
  908. imgFormat: 'JPG', // 转换类型
  909. quality: 92, // 图片品质
  910. colorNum:256, // 颜色数量 1 - 256
  911. sizeType: '1', // 调整尺寸
  912. scaling: 100, // 缩放比例
  913. rotateValue: 0, // 旋转角度
  914. color: '0', // 图片色彩
  915. colorValue: 256,
  916. paintValue: 1, //油画数值
  917. brightnessValue: 0, // 亮度
  918. saturationValue: 0, //饱和度
  919. hueValue: 0, // 色调
  920. contrastValue: 0, // 对比度
  921. opacityValue: 100, // 透明度
  922. compressScaling:100,
  923. compressOutType:2,
  924. watermarkType: '1', // 水印类型 1文字 2图片
  925. watermarkStyle: '1', // 1 单个 2平铺
  926. watermarkValue: '', // 水印文字内容
  927. watermarkColor: '#ff0000',
  928. watermarkFont: 16,
  929. watermarkX: 0,
  930. watermarkY: 0,
  931. watermarkDensityX: 3, // 平铺水印密度
  932. watermarkDensityY: 3, // 平铺水印密度
  933. watermarkImgPath: '', //图片水印路径
  934. watermarkImgOpactiy: 100, // 水印不透明度
  935. watermarkImgSize: 100, // 水印缩放比例
  936. watermarkImgRotate: 0,
  937. watermarkPosition: 'Center', // 水印位置
  938. lineFlag: false,
  939. lineWidth: 3,
  940. lineColor: '#ff0000',
  941. fonts:'',
  942. rotate: 30,
  943. circularFlag: false,
  944. circularValue: 10,
  945. hflip: false,
  946. vflip: false,
  947. lockScale: true,
  948. },
  949. handleRename: {
  950. fileName: "", // 新文件名
  951. fileCase: "1", // 大小写转换
  952. startNumber: 0, // 起始编号
  953. increment: 1, // 增量
  954. digit: 1 // 位数
  955. },
  956. dowloadModel: false,
  957. finishModel: false,
  958. version: '0.0.1',
  959. isStart: false, // 是否开始转换
  960. isUpdate: false, // 是否有更新
  961. loading: false,
  962. cancelLoadStatus: false,
  963. authority:{}, // 用户权限
  964. sysDefaultTmpPath:'', // 系统水印路径
  965. previewTmpPath:'', // 预览图片路径
  966. imgLoading:false,
  967. renameLoading: false,
  968. mergeLoading: false,
  969. mergeInterval: false,
  970. };
  971. },
  972. computed:{
  973. hBorder: {
  974. get(){
  975. return 250 * this.mergeData.border / 500;
  976. }
  977. },
  978. hSpace: {
  979. get(){
  980. return 250 * this.mergeData.space / 500;
  981. }
  982. },
  983. vBorder: {
  984. get(){
  985. return 250 * this.mergeData.border / 500;
  986. }
  987. },
  988. vSpace: {
  989. get(){
  990. return 250 * this.mergeData.space / 500;
  991. }
  992. }
  993. },
  994. mounted() {
  995. this.$refs.updateRef.updateSoft(true);
  996. let __dirname = os.userInfo().homedir;
  997. this.softdownloadDir = __dirname + separator + "Downloads";
  998. if(fs.existsSync(__dirname + separator + "Desktop")){
  999. this.downloadDir = __dirname + separator + "Desktop"
  1000. } else{
  1001. this.downloadDir = __dirname + separator + "Downloads"
  1002. }
  1003. this.handleData.newPath = this.downloadDir;
  1004. // 预览图片路径
  1005. this.previewTmpPath = os.tmpdir()+separator+'preview.png';
  1006. this.fonts = [
  1007. {
  1008. name:'宋体',
  1009. path:'c:\\Windows\\fonts\\simsun.ttc',
  1010. },
  1011. {
  1012. name:'仿宋',
  1013. path:'c:\\windows\\fonts\\simfang.ttf',
  1014. },
  1015. {
  1016. name:'新宋体',
  1017. path:'c:\\windows\\fonts\\simsun.ttc',
  1018. },
  1019. {
  1020. name:'楷体',
  1021. path:'c:\\windows\\fonts\\simkai.ttf',
  1022. },
  1023. {
  1024. name:'微软雅黑 常规',
  1025. path:'C:\\Windows\\Fonts\\msyh.ttc',
  1026. },
  1027. {
  1028. name:'微软雅黑 粗体',
  1029. path:'c:\\windows\\fonts\\msyhbd.ttc'
  1030. }
  1031. ];
  1032. this.defaultFont = 'c:\\windows\\fonts\\simkai.ttf';
  1033. // 打开浏览器
  1034. const links = document.querySelectorAll('a[href]');
  1035. links.forEach(link => {
  1036. link.addEventListener('click', e => {
  1037. const url = link.getAttribute('href');
  1038. e.preventDefault();
  1039. electronApi.call('openExternal', [url]);
  1040. });
  1041. });
  1042. this.initDrop();
  1043. },
  1044. methods: {
  1045. // 鼠标滚轮事件
  1046. initRoll(){
  1047. let element = document.getElementById('show-img');
  1048. if(!this.rollFlag){
  1049. // 添加滚轮事件监听器
  1050. element.addEventListener('wheel', (event) => {
  1051. this.rollFlag = true;
  1052. // event.deltaY 是滚轮滚动的距离,正值表示向下滚动,负值表示向上滚动
  1053. if (event.deltaY < 0) {
  1054. if(this.viewScale < 5){
  1055. this.viewScale += 0.1;
  1056. }
  1057. } else {
  1058. if(this.viewScale > 0){
  1059. this.viewScale -= 0.1;
  1060. }
  1061. }
  1062. event.preventDefault();
  1063. });
  1064. }
  1065. },
  1066. // 选择目录
  1067. pickPath() {
  1068. this.$refs['upload-input'].blur();
  1069. electronApi.call('pickDir', []).then((path) => {
  1070. if (path) {
  1071. this.handleData.newPath = path;
  1072. this.downloadDir = path;
  1073. }
  1074. });
  1075. },
  1076. // 将裁剪设置应用到所有图片
  1077. setOk(){
  1078. let cropPosition = this.cropList[this.cropImgIndex].cropPosition;
  1079. this.cropList.map(item => {
  1080. item.cropPosition = cropPosition;
  1081. item.cropOptions = this.cropOptions;
  1082. });
  1083. setTimeout(()=>{
  1084. this.setModal = false;
  1085. }, 2000);
  1086. },
  1087. // 重置所有裁剪设置
  1088. resetOk(){
  1089. this.cropList.map(item => {
  1090. item.cropPosition = undefined;
  1091. item.cropOptions = {};
  1092. });
  1093. this.cropOptions.fixedValue = 'free';
  1094. this.cropOptions.fixed = false;
  1095. this.cropOptions.fixedNumber = [this.cropOptionsImgInfo.width, this.cropOptionsImgInfo.height];
  1096. setTimeout(()=>{
  1097. this.resetModal = false;
  1098. }, 500);
  1099. },
  1100. // 选择裁剪比例
  1101. fixedChange(e){
  1102. this.cropOptions.fixedValue = e;
  1103. if(e == 'free'){
  1104. this.cropOptions.fixed = false;
  1105. }else if(e == 'original'){
  1106. this.cropOptions.fixed = true;
  1107. this.cropOptions.fixedNumber = [this.cropOptionsImgInfo.originalWidth, this.cropOptionsImgInfo.originalHeight];
  1108. }else{
  1109. this.cropOptions.fixed = true;
  1110. this.cropOptions.fixedNumber = [e.split(':')[0], e.split(':')[1]];
  1111. }
  1112. setTimeout(() => {
  1113. this.$refs.cropper.goAutoCrop();
  1114. this.$nextTick(() => {
  1115. this.cropOptions.autoCropWidth = Number(this.$refs.cropper.cropW.toFixed(0));
  1116. this.cropOptions.autoCropHeight = Number(this.$refs.cropper.cropH.toFixed(0));
  1117. });
  1118. }, 100);
  1119. },
  1120. // 加载图片成功回调函数
  1121. cropImgLoad(result){
  1122. this.cropImgLoading = result;
  1123. if(this.cropList[this.cropImgIndex].cropPosition){ // 有位置信息
  1124. this.$refs.cropper.goAutoCrop();
  1125. this.$nextTick(() => {
  1126. let width = this.cropList[this.cropImgIndex].cropPosition.x2 - this.cropList[this.cropImgIndex].cropPosition.x1;
  1127. let height = this.cropList[this.cropImgIndex].cropPosition.y2 - this.cropList[this.cropImgIndex].cropPosition.y1;
  1128. this.$refs.cropper.cropOffsertX = this.cropList[this.cropImgIndex].cropPosition.x1;
  1129. this.$refs.cropper.cropOffsertY = this.cropList[this.cropImgIndex].cropPosition.y1;
  1130. this.$refs.cropper.cropW = width;
  1131. this.$refs.cropper.cropH = height;
  1132. });
  1133. }else{
  1134. let imgPosition = this.$refs.cropper.getImgAxis();
  1135. this.cropOptions.autoCropWidth = imgPosition.x2 - imgPosition.x1;
  1136. this.cropOptions.autoCropHeight = imgPosition.y2 - imgPosition.y1;
  1137. }
  1138. },
  1139. // 实时预览
  1140. realTime(data){
  1141. clearInterval(this.cropInt);
  1142. this.cropOptions.previewInfo = data.html;
  1143. if(this.cropImgLoading){
  1144. this.getCropInfo(data);
  1145. }else{
  1146. this.cropInt = setInterval(()=> {
  1147. if(this.cropImgLoading){
  1148. this.getCropInfo(data);
  1149. clearInterval(this.cropInt);
  1150. }
  1151. }, 300);
  1152. }
  1153. },
  1154. getCropInfo(data){
  1155. if(this.cropOptions.cropType == '2' && this.cropOptions.cropClassify != '1'){
  1156. document.getElementsByClassName('crop-info')[0].style.opacity = 0;
  1157. }else{
  1158. document.getElementsByClassName('crop-info')[0].style.opacity = 1;
  1159. }
  1160. setTimeout(() => {
  1161. this.cropOptions.previewInfo = data.html;
  1162. let w = document.getElementsByClassName('crop-info')[0].innerText.split(' × ')[0];
  1163. let h = document.getElementsByClassName('crop-info')[0].innerText.split(' × ')[1];
  1164. let w_px = document.getElementsByClassName('cropper-crop-box')[0].offsetWidth;
  1165. let h_px = document.getElementsByClassName('cropper-crop-box')[0].offsetHeight;
  1166. let scale = w_px / w * 100;
  1167. this.cropOptions.cropWidth = Number(w);
  1168. this.cropOptions.cropHeight = Number(h);
  1169. this.cropOptions.cropScale = Number(scale);
  1170. let cropPosition = this.$refs.cropper.getCropAxis(); //截图框位置信息
  1171. let imgPosition = this.$refs.cropper.getImgAxis();
  1172. let dis_x = cropPosition.x1 < imgPosition.x1 ? 0 : cropPosition.x1 - imgPosition.x1;
  1173. let dis_y = cropPosition.y1 < imgPosition.y1 ? 0 : cropPosition.y1 - imgPosition.y1;
  1174. let cropX = dis_x / (this.cropOptions.cropScale / 100);
  1175. let cropY = dis_y / (this.cropOptions.cropScale / 100);
  1176. cropPosition.cropX = cropX; // 裁剪图片真实尺寸
  1177. cropPosition.cropY = cropY;
  1178. cropPosition.cropWidth = w;
  1179. cropPosition.cropHeight = h;
  1180. this.virtualWidth = Number(w);
  1181. this.virtualHeight = Number(h);
  1182. this.cropList[this.cropImgIndex].cropPosition = cropPosition;
  1183. this.cropList[this.cropImgIndex].cropOptions = JSON.parse(JSON.stringify(this.cropOptions));
  1184. }, 200);
  1185. },
  1186. selectTabCrop(data){
  1187. this.selectCropImg(data.rowIndex);
  1188. },
  1189. // 选择图片
  1190. selectCropImg(index){
  1191. this.cropImgIndex = index;
  1192. if(this.cropList[index].cropOptions){
  1193. this.cropOptions = JSON.parse(JSON.stringify(this.cropList[index].cropOptions));
  1194. }else{
  1195. this.setDefaultCropData();
  1196. }
  1197. this.cropOptions.img = this.cropList[index].path;
  1198. this.cropOptionsImgInfo = this.cropList[index];
  1199. this.cropImgLoading = false;
  1200. this.$forceUpdate();
  1201. },
  1202. // 裁剪分类
  1203. classifyChange(e){
  1204. if(e == '1'){ // 自定义
  1205. this.virtualWidth = this.cropOptionsImgInfo.originalWidth;
  1206. this.virtualHeight = this.cropOptionsImgInfo.originalHeight;
  1207. this.cropOptions.fixed = false;
  1208. this.cropOptions.fixedValue = 'free';
  1209. this.$refs.cropper.goAutoCrop();
  1210. this.$nextTick(() => {
  1211. this.cropOptions.autoCropWidth = Number(this.virtualWidth);
  1212. this.cropOptions.autoCropHeight = Number(this.virtualHeight);
  1213. });
  1214. }
  1215. },
  1216. cropWidthChange(e){
  1217. let scale = Number(this.cropOptionsImgInfo.originalWidth) / Number(this.cropOptionsImgInfo.originalHeight);
  1218. if(this.cropOptions.fixed){ // 锁定比例
  1219. this.virtualHeight = Math.round(this.virtualWidth / scale);
  1220. }
  1221. let cropPosition = this.$refs.cropper.getCropAxis();
  1222. let c_w = cropPosition.x2 - cropPosition.x1;
  1223. let c_h = cropPosition.y2 - cropPosition.y1;
  1224. let w = document.getElementsByClassName('crop-info')[0].innerText.split(' × ')[0];
  1225. let h = document.getElementsByClassName('crop-info')[0].innerText.split(' × ')[1];
  1226. let c_scale = w / c_w;
  1227. this.$refs.cropper.goAutoCrop();
  1228. this.$nextTick(() => {
  1229. this.cropOptions.autoCropWidth = this.virtualWidth / c_scale;
  1230. this.cropOptions.autoCropHeight = this.virtualHeight / c_scale;
  1231. });
  1232. },
  1233. cropHeightChange(e){
  1234. let scale = Number(this.cropOptionsImgInfo.originalWidth) / Number(this.cropOptionsImgInfo.originalHeight);
  1235. if(this.cropOptions.fixed){ // 锁定比例
  1236. this.virtualWidth = Math.round(this.virtualHeight * scale);
  1237. }
  1238. let cropPosition = this.$refs.cropper.getCropAxis();
  1239. let c_w = cropPosition.x2 - cropPosition.x1;
  1240. let c_h = cropPosition.y2 - cropPosition.y1;
  1241. let w = document.getElementsByClassName('crop-info')[0].innerText.split(' × ')[0];
  1242. let h = document.getElementsByClassName('crop-info')[0].innerText.split(' × ')[1];
  1243. let c_scale = w / c_w;
  1244. this.$refs.cropper.goAutoCrop();
  1245. this.$nextTick(() => {
  1246. this.cropOptions.autoCropWidth = this.virtualWidth / c_scale;
  1247. this.cropOptions.autoCropHeight = this.virtualHeight / c_scale;
  1248. });
  1249. },
  1250. cropChange(e){
  1251. if(e == 2 && this.cropOptions.fixed){
  1252. this.cropOptions.fixedValue = 'original';
  1253. this.fixedChange('original');
  1254. }
  1255. },
  1256. // 预览
  1257. previewImg(){
  1258. this.cropimgShow = true;
  1259. },
  1260. // 裁剪图片
  1261. cropImg(){
  1262. this.mergeLoading = this.$loading({
  1263. lock: true,
  1264. text: '图片处理中,请稍后...',
  1265. spinner: 'el-icon-loading',
  1266. background: 'rgba(0, 0, 0, 0.7)'
  1267. });
  1268. for(let index = 0; index < this.cropList.length; index++){
  1269. let item = this.cropList[index];
  1270. let imgType = item.type;
  1271. let suffix = item.name.lastIndexOf('.') != -1 ? item.name.substr(item.name.lastIndexOf('.')+1) : imgType.toLowerCase();
  1272. let newPath = this.downloadDir + separator + pjson.softInfo.softName + separator + item.name.slice(0, item.name.lastIndexOf('.')) + '.' +suffix;
  1273. let str;
  1274. if(item.cropPosition && item.cropPosition.cropWidth){
  1275. str = item.cropPosition.cropWidth + 'x' + item.cropPosition.cropHeight + '+' + item.cropPosition.cropX + '+' + item.cropPosition.cropY;
  1276. }else{
  1277. str = item.width + 'x' + item.height + '+' + 0 + '+' + 0;
  1278. }
  1279. let resize = [];
  1280. if(item.cropOptions && item.cropOptions.cropType == '2' && item.cropOptions.cropClassify != '1'){
  1281. let oWidth = item.cropOptions.fixedNumber[0];
  1282. let oHeight = item.cropOptions.fixedNumber[1];
  1283. resize = ['-resize', `${Number(oWidth)}x${Number(oHeight)}!`,];
  1284. }
  1285. let params = [
  1286. 'convert.exe',
  1287. '-crop',
  1288. str,
  1289. ...resize,
  1290. item.path,
  1291. newPath
  1292. ];
  1293. electronApi.spawnExec(params).then(res => {
  1294. let imgInfo = {};
  1295. if(item.cropPosition && item.cropPosition.cropWidth){
  1296. imgInfo.width = item.cropPosition.cropWidth;
  1297. }else{
  1298. imgInfo.width = item.width;
  1299. }
  1300. this.addWatermark(index, imgInfo, newPath);
  1301. }).catch(err => {
  1302. this.mergeLoading.close();
  1303. // errorIndex = index;
  1304. this.$notify.error({
  1305. title: '第【'+Number(index+1)+'】张图片出错',
  1306. message: '请调整后重试!' + err.stderr.toString()
  1307. });
  1308. });
  1309. }
  1310. setTimeout(() => { // 延迟打开
  1311. this.mergeLoading.close();
  1312. electronApi.call('showItemInfolder',[this.downloadDir + separator + pjson.softInfo.softName + separator +'1.tty'])
  1313. }, 3000);
  1314. },
  1315. handleDownload(data, path){
  1316. var dataBuffer = new Buffer(data.split(',')[1], 'base64');
  1317. fs.writeFileSync(path, dataBuffer, {'flag':'w'});
  1318. },
  1319. // 加载拖拽监听事件
  1320. initDrop(){
  1321. const dragWrapper = document.getElementById("drag-jimp");
  1322. let domArr = [dragWrapper];
  1323. domArr.map(item => {
  1324. //添加拖拽事件监听器
  1325. item.addEventListener("drop", (e) => {
  1326. //阻止默认行为
  1327. e.preventDefault();
  1328. //获取文件列表
  1329. let files = e.dataTransfer.files;
  1330. let pathArr = [];
  1331. for(let i = 0; i < files.length; i++){
  1332. pathArr.push(files[i].path);
  1333. }
  1334. this.pushFileToList(pathArr);
  1335. })
  1336. //阻止拖拽结束事件默认行为
  1337. item.addEventListener("dragover", (e) => {
  1338. e.preventDefault();
  1339. })
  1340. })
  1341. },
  1342. cancelLoad(){
  1343. this.cancelLoadStatus = true;
  1344. },
  1345. openVip(){
  1346. this.$refs.headerRef.openVip();
  1347. },
  1348. updateSoft() {
  1349. this.$refs.updateRef.updateSoft();
  1350. },
  1351. // 打开自定义下载目录
  1352. openFolder(){
  1353. let path = this.downloadDir;
  1354. if(fs.existsSync(this.downloadDir + separator + pjson.softInfo.softName)){
  1355. path = this.downloadDir + separator + pjson.softInfo.softName;
  1356. } else {
  1357. fs.mkdirSync(this.downloadDir + separator + pjson.softInfo.softName);
  1358. path = this.downloadDir + separator + pjson.softInfo.softName;
  1359. }
  1360. electronApi.call('showItemInfolder',[path+'\\tty.tty'])
  1361. },
  1362. // 清除列表
  1363. clearList() {
  1364. if(this.menuIndex != 8 && this.menuIndex != 10){
  1365. this.imgList = [];
  1366. this.imgSrc = '';
  1367. this.setDefaultData();
  1368. }else if(this.menuIndex == 8){
  1369. this.mergeList = [];
  1370. }else{
  1371. this.cropList = [];
  1372. this.cropImgIndex = -1;
  1373. this.setDefaultCropData();
  1374. this.cropOptionsImgInfo = {};
  1375. }
  1376. this.rollFlag = false;
  1377. this.isGif = false;
  1378. this.gifChecked = false;
  1379. },
  1380. setMenuIndex(index){
  1381. this.menuIndex = index;
  1382. this.setDefaultData();
  1383. if(index == 5){
  1384. this.handleData.fonts = this.defaultFont.toString();
  1385. }else if(index == 3){
  1386. this.handleData.width = this.imgInfo.width ? this.imgInfo.width : 0;
  1387. this.handleData.height = this.imgInfo.height ? this.imgInfo.height : 0;
  1388. }else if(index == 7){
  1389. this.setChange();
  1390. }
  1391. if(this.imgList.length > 0){
  1392. this.setDefaultImgInfo(this.imgList[0]);
  1393. }
  1394. if([3,4,5,6,9].indexOf(this.menuIndex) == -1){ // 滚动事件
  1395. this.rollFlag = false;
  1396. }
  1397. },
  1398. setDefaultCropData(){
  1399. this.cropOptions = {
  1400. img: '',
  1401. autoCrop: true, // 是否默认生成截图框
  1402. autoCropWidth: 100,
  1403. autoCropHeight: 100,
  1404. cropWidth: 100,
  1405. cropHeight: 100,
  1406. original: false,
  1407. maxImgSize: 20000,
  1408. canMove: false,
  1409. centerBox: true, // 截图框是否被限制在图片里面
  1410. fixed: false, //是否开启截图框宽高固定比例
  1411. fixedValue: 'free',
  1412. cropType: '1',
  1413. cropClassify: '1',
  1414. fixedNumber: [1, 1],
  1415. infoTrue: true,
  1416. previewInfo: '',
  1417. cropScale: 100,
  1418. };
  1419. },
  1420. setDefaultData(){
  1421. this.handleData = {
  1422. dpi: 300,
  1423. width: 0,
  1424. height: 0,
  1425. pathType: this.handleData.pathType, // 输出目录类型
  1426. newPath: this.handleData.newPath, // 新路径
  1427. autoRename: false, // 是否自动重命名
  1428. imgFormat: 'JPG', // 转换类型
  1429. quality: 92, // 图片品质
  1430. colorNum: 256, // 颜色数量
  1431. color: '0', // 图片色彩
  1432. sizeType: '1', // 调整尺寸
  1433. scaling: 100, // 缩放比例
  1434. colorValue: 256,
  1435. paintValue: 1, // 油画数值
  1436. brightnessValue: 0, // 亮度
  1437. saturationValue: 0, //饱和度
  1438. hueValue: 0, // 色调
  1439. contrastValue: 0, // 对比度
  1440. rotateValue: 0, // 旋转角度
  1441. opacityValue: 100, // 透明度
  1442. compressScaling:100,
  1443. compressOutType:2,
  1444. watermarkType: '1', // 水印类型 1文字 2图片
  1445. watermarkStyle: '1', // 1 单个 2平铺
  1446. watermarkValue: '', // 水印文字内容
  1447. watermarkColor: '#ff0000',
  1448. watermarkFont: 16,
  1449. watermarkX: 0,
  1450. watermarkY: 0,
  1451. watermarkDensityX: 3, // 平铺水印密度
  1452. watermarkDensityY: 3, // 平铺水印密度
  1453. watermarkImgPath: '', //图片水印路径
  1454. watermarkImgOpactiy: 100, // 水印不透明度
  1455. watermarkImgSize: 100, //水印缩放比例
  1456. watermarkImgRotate:0,
  1457. watermarkPosition: 'Center',
  1458. lineFlag: false,
  1459. lineWidth: 3,
  1460. lineColor: '#ff0000',
  1461. fonts: this.defaultFont.toString(),
  1462. rotate: 30,
  1463. circularFlag: false,
  1464. circularValue: 10,
  1465. hflip: false,
  1466. vflip: false,
  1467. lockScale: true,
  1468. };
  1469. },
  1470. // 选择水印图片
  1471. getImgPath(e) {
  1472. if (e) {
  1473. this.handleData.watermarkImgPath = e.path;
  1474. this.handleImg();
  1475. }
  1476. },
  1477. pickFile(){
  1478. electronApi.call('pickFile', [this.imgFormat.join(','),true]).then(async(files) =>{
  1479. this.pushFileToList(files,0);
  1480. });
  1481. },
  1482. pickDir(){
  1483. electronApi.call('pickDir', []).then((path) =>{
  1484. this.dealDir(path);
  1485. });
  1486. },
  1487. dealDir(currentDirPath){
  1488. let files = fs.readdirSync(currentDirPath)
  1489. for (let i = 0; i < files.length; i++) {
  1490. let name = files[i];
  1491. var filePath = pathMod.join(currentDirPath, name);
  1492. var stat = fs.statSync(filePath);
  1493. if (stat.isFile()) {
  1494. this.pushFileToList([filePath]);
  1495. } else if (stat.isDirectory()) {
  1496. this.dealDir(filePath)
  1497. }
  1498. }
  1499. },
  1500. pushFileToList(files){
  1501. // 直接渲染
  1502. files.map(file => {
  1503. let filename = file.substr(file.lastIndexOf(separator)+1);
  1504. let size = fs.statSync(file).size;
  1505. let imgInfo = {
  1506. name: filename,
  1507. size: this.$utils.handleSize(size),
  1508. width: 0,
  1509. height: 0,
  1510. originalWidth: 0,
  1511. originalHeight: 0,
  1512. path: file,
  1513. type: filename.lastIndexOf('.') == -1 ? '' : filename.substr(filename.lastIndexOf('.')+1),
  1514. loadPercent: 0,
  1515. percent: 0,
  1516. top: 0,
  1517. left: 0
  1518. };
  1519. if(!imgInfo.type){
  1520. this.$message({message: '不是有效的图片文件! - '+ file , type: 'warning'});
  1521. }else{
  1522. if(this.imgFormat.indexOf(imgInfo.type.toUpperCase()) == -1){
  1523. this.$message({message: '不是有效的图片文件! - '+ file , type: 'warning'});
  1524. }else{
  1525. if(imgInfo.type.toUpperCase() == 'GIF'){
  1526. this.isGif = true;
  1527. }
  1528. try {
  1529. let dimensions = sizeOf(file);
  1530. imgInfo.width = dimensions.width;
  1531. imgInfo.height = dimensions.height;
  1532. imgInfo.originalWidth = dimensions.width;
  1533. imgInfo.originalHeight = dimensions.height;
  1534. } catch (error) {
  1535. }
  1536. // 过滤重复图片
  1537. let flag = true;
  1538. if(this.menuIndex != 8 && this.menuIndex != 10) {
  1539. for(let m = 0; m < this.imgList.length; m++){
  1540. if(this.imgList[m].name == imgInfo.name && this.imgList[m].path == imgInfo.path){
  1541. flag = false;
  1542. break;
  1543. }
  1544. }
  1545. }else if(this.menuIndex == 8){
  1546. for(let m = 0; m < this.mergeList.length; m++){
  1547. if(this.mergeList[m].name == imgInfo.name && this.mergeList[m].path == imgInfo.path){
  1548. flag = false;
  1549. break;
  1550. }
  1551. }
  1552. }else{
  1553. for(let m = 0; m < this.cropList.length; m++){
  1554. if(this.cropList[m].name == imgInfo.name && this.cropList[m].path == imgInfo.path){
  1555. flag = false;
  1556. break;
  1557. }
  1558. }
  1559. }
  1560. if(!flag){
  1561. this.$message({message: '该图片已经存在队列中 - '+ file , type: 'warning'});
  1562. }else{
  1563. if(this.menuIndex != 8 && this.menuIndex != 10){
  1564. this.imgList.push(imgInfo);
  1565. }else if(this.menuIndex == 8){
  1566. if(this.mergeList.length < 100){
  1567. this.mergeList.push(imgInfo);
  1568. this.sortChange(this.mergeData.sortType);
  1569. }
  1570. }else{
  1571. this.cropList.push(imgInfo);
  1572. if(this.cropList.length == 1){
  1573. this.selectCropImg(0);
  1574. }
  1575. }
  1576. }
  1577. }
  1578. }
  1579. })
  1580. // 设置第一个为默认图片
  1581. if(this.imgSrc == '' && this.imgList[0]){
  1582. this.setDefaultImgInfo(this.imgList[0])
  1583. }
  1584. if(this.menuIndex == 7){ // 重命名
  1585. this.setChange();
  1586. }
  1587. },
  1588. // 设置默认的图片
  1589. setDefaultImgInfo(info){
  1590. this.imgInfo = info;
  1591. this.handleData.width = this.imgInfo.width;
  1592. this.handleData.height = this.imgInfo.height;
  1593. this.imgLoading = true;
  1594. if([1,2,7,11].indexOf(this.menuIndex) == -1){
  1595. electronApi.fileStream(this.imgInfo.path).then(buffer => {
  1596. this.imgSrc = "data:image/png;base64,"+buffer.toString('base64');
  1597. this.imgLoading = false;
  1598. }).catch(err => {
  1599. this.imgLoading = false;
  1600. })
  1601. }
  1602. if([3,4,5,6,9].indexOf(this.menuIndex) > -1){ // 绑定滚动事件
  1603. setTimeout(() => {
  1604. if(!this.rollFlag){
  1605. this.initRoll();
  1606. }
  1607. }, 600);
  1608. }
  1609. },
  1610. // 选择新路径
  1611. getFolder(e) {
  1612. this.handleData.newPath = e.path;
  1613. this.downloadDir = e.path;
  1614. },
  1615. selectTab(data, index) {
  1616. let currentRow = data.rowIndex > -1 ? this.imgList[data.rowIndex] : data;
  1617. index = index ? 0 : data.rowIndex;
  1618. this.imgInfo = currentRow;
  1619. this.imgInfoIndex = index;
  1620. if([3,6,7,9].indexOf(this.menuIndex) > -1){
  1621. this.imgLoading = true;
  1622. electronApi.fileStream(currentRow.path).then(buffer => {
  1623. this.imgSrc = "data:image/png;base64,"+buffer.toString('base64');
  1624. this.imgLoading = false;
  1625. }).catch(err => {
  1626. this.imgLoading = false;
  1627. })
  1628. this.handleData.width = Number(currentRow.width);
  1629. this.handleData.height = Number(currentRow.height);
  1630. }else if([4,5].indexOf(this.menuIndex) > -1){
  1631. this.handleImg();
  1632. }else if(this.menuIndex == 1){
  1633. this.handleData.imgFormat = 'JPG';
  1634. }
  1635. },
  1636. // 导出
  1637. async exportImg(flag) {
  1638. let authority = this.$refs.headerRef.authority;
  1639. if(!fs.existsSync(this.downloadDir + separator + pjson.softInfo.softName)){
  1640. fs.mkdirSync(this.downloadDir + separator + pjson.softInfo.softName);
  1641. }
  1642. // 图片拼接
  1643. if(this.menuIndex == 8 && this.mergeList.length > 0){
  1644. if (!authority.isAuthority && !flag) {
  1645. this.$refs.headerRef.memberModel = true;
  1646. this.$refs.headerRef.isClick = true;
  1647. return false;
  1648. } else {
  1649. this.$refs.headerRef.memberModel = false;
  1650. }
  1651. this.loading = true;
  1652. setTimeout(()=>{
  1653. this.loading = false;
  1654. }, 1500)
  1655. if(this.mergeData.sortType != 3){
  1656. this.exportMerge2();
  1657. }else{
  1658. this.exportMerge();
  1659. }
  1660. }
  1661. // 图片裁剪
  1662. if(this.menuIndex == 10 && this.cropList.length > 0){
  1663. if (!authority.isAuthority && !flag) {
  1664. this.$refs.headerRef.memberModel = true;
  1665. this.$refs.headerRef.isClick = true;
  1666. return false;
  1667. } else {
  1668. this.$refs.headerRef.memberModel = false;
  1669. }
  1670. this.loading = true;
  1671. setTimeout(()=>{
  1672. this.loading = false;
  1673. }, 1500)
  1674. this.cropImg();
  1675. }
  1676. if (this.imgList.length > 0 && this.menuIndex != 8 && this.menuIndex != 10) {
  1677. if (!authority.isAuthority && !flag) {
  1678. this.$refs.headerRef.memberModel = true;
  1679. this.$refs.headerRef.isClick = true;
  1680. return false;
  1681. } else {
  1682. this.$refs.headerRef.memberModel = false;
  1683. }
  1684. this.loading = true;
  1685. setTimeout(()=>{
  1686. this.loading = false;
  1687. }, 1500)
  1688. if(this.menuIndex == 7){ // 重命名
  1689. this.exportRename();
  1690. return false;
  1691. }
  1692. // 删除水印,防止直接篡改水印图片
  1693. this.deleteSysWtater();
  1694. // 更改尺寸的时候,宽度和高度不允许为0
  1695. if(this.menuIndex == 3 && this.handleData.sizeType != 1){
  1696. if(this.handleData.width <= 0 || this.handleData.height <=0){
  1697. this.$message({message: '请设置缩放的宽度和高度' , type: 'warning'});
  1698. return false
  1699. }
  1700. }
  1701. //percent
  1702. let taskArr = [];
  1703. let newPath = '';
  1704. for(let i=0; i<this.imgList.length; i++){
  1705. let item = this.imgList[i];
  1706. let lastIndex = item.path.lastIndexOf('.');
  1707. let imgType = item.type;
  1708. let suffix = '';
  1709. if(this.menuIndex == 1){
  1710. suffix = this.handleData.imgFormat.toLowerCase();
  1711. }else{
  1712. suffix = item.name.lastIndexOf('.') != -1 ? item.name.substr(item.name.lastIndexOf('.')+1) : imgType.toLowerCase();
  1713. }
  1714. // 图片压缩,输出格式为jpg
  1715. if(this.menuIndex == 2 && this.handleData.compressOutType == 1){
  1716. suffix = 'jpg';
  1717. }
  1718. newPath = this.downloadDir + separator + pjson.softInfo.softName + separator + item.name.slice(0, item.name.lastIndexOf('.')) + '.' +suffix;
  1719. // 处理图像
  1720. let task = this.dealImg(i, item, newPath);
  1721. if(task){
  1722. taskArr.push(task);
  1723. }
  1724. if((i+1) % this.execLimit == 0){
  1725. await Promise.all(taskArr).then(result => {
  1726. taskArr = [];
  1727. }).catch(err => {
  1728. })
  1729. }
  1730. }
  1731. if(taskArr.length > 0){
  1732. await Promise.all(taskArr).then(result => {
  1733. taskArr = [];
  1734. }).catch(err => {
  1735. // 错误文件添加到服务中
  1736. console.log('err',err);
  1737. })
  1738. }
  1739. // 打开文件夹
  1740. if(this.imgList.length > 0){
  1741. this.$message({message: '恭喜你,任务已完成!', type: 'success'});
  1742. electronApi.call('showItemInfolder',[newPath])
  1743. }
  1744. }
  1745. },
  1746. // 操作
  1747. handleImg() {
  1748. if (this.imgInfo.path) {
  1749. this.imgLoading = true;
  1750. this.dealImg(this.imgInfoIndex);
  1751. }
  1752. },
  1753. // 处理图片
  1754. dealImg(index, img, path){
  1755. let reduceFlag = img ? false : true;
  1756. let imgInfo = img ? img : this.imgInfo;
  1757. let newPath = img ? path : this.previewTmpPath;
  1758. let task = '';
  1759. switch (this.menuIndex) {
  1760. case 11: // 修改dpi
  1761. task = new Promise((resolve,reject) => {
  1762. let imgPath = imgInfo.path;
  1763. let cmd = [
  1764. 'convert.exe',
  1765. '-monitor',
  1766. imgPath,
  1767. '-density',
  1768. this.handleData.dpi,
  1769. '-units',
  1770. 'PixelsPerInch',
  1771. newPath
  1772. ];
  1773. electronApi.spawnExec(cmd,{
  1774. stderr:(data) => {
  1775. let str = data.toString();
  1776. const regexDuration = /Load.*?,(.*?)%/;
  1777. const regexDuration2 = /Save.*?,(.*?)%/;
  1778. const res = regexDuration.exec(str);
  1779. const res2 = regexDuration2.exec(str);
  1780. let p1 = 0;
  1781. let p2 = 0;
  1782. if(res && res[1]){
  1783. p1 = parseInt(res[1]);
  1784. if(p1 > 0){
  1785. imgInfo.percent = Math.round(p1/2);
  1786. }
  1787. }else{
  1788. if(res2 && res2[1]){
  1789. p2 = parseInt(res2[1]);
  1790. }
  1791. if(p2 > 0){
  1792. imgInfo.percent = Math.round(50+(p2/2));
  1793. }
  1794. }
  1795. if(this.imgList.indexOf(index)){
  1796. this.imgList.splice(index,1,imgInfo);
  1797. }
  1798. }
  1799. }).then(res => {
  1800. setTimeout(() => {
  1801. if(this.imgList.indexOf(index)){
  1802. imgInfo.percent = 100;
  1803. this.imgList.splice(index, 1, imgInfo);
  1804. }else{
  1805. reject({type:this.menuIndex,index,err:'用户强制终止!'});
  1806. }
  1807. }, 150)
  1808. //未购买 添加系统水印
  1809. this.addWatermark(index,imgInfo,newPath);
  1810. resolve({type:this.menuIndex,index, img});
  1811. }).catch(err => {
  1812. // console.log(err.stderr.toString());
  1813. reject({type:this.menuIndex,index,err});
  1814. });
  1815. });
  1816. break;
  1817. case 1: // 格式转换
  1818. task = new Promise((resolve,reject) => {
  1819. let imgPath = imgInfo.path;
  1820. let gifParams = [];
  1821. if(imgInfo.type.toLowerCase() == 'psd'){
  1822. imgPath = imgInfo.path + '[0]';
  1823. }
  1824. if(imgInfo.type.toLowerCase() == 'gif'){
  1825. if(this.gifChecked){
  1826. gifParams = ['-coalesce'];
  1827. let name = imgInfo.name.slice(0, imgInfo.name.lastIndexOf('.'));
  1828. let gifPath = this.downloadDir + separator + pjson.softInfo.softName + separator + name;
  1829. if(!fs.existsSync(gifPath)){
  1830. fs.mkdirSync(gifPath);
  1831. }
  1832. newPath = gifPath + separator + name + '.' + this.handleData.imgFormat.toLowerCase();
  1833. }else{
  1834. imgPath = imgInfo.path + '[0]';
  1835. }
  1836. }
  1837. let cmd = [
  1838. 'convert.exe',
  1839. '-monitor',
  1840. ...gifParams,
  1841. imgPath,
  1842. newPath
  1843. ];
  1844. electronApi.spawnExec(cmd,{
  1845. stderr:(data) => {
  1846. let str = data.toString();
  1847. const regexDuration = /Load.*?,(.*?)%/;
  1848. let regexDuration2 = /Save.*?,(.*?)%/;
  1849. if(imgInfo.type.toLowerCase() == 'gif'){
  1850. regexDuration2 = /Write.*?,(.*?)%/;
  1851. }
  1852. const res = regexDuration.exec(str);
  1853. const res2 = regexDuration2.exec(str);
  1854. let p1 = 0;
  1855. let p2 = 0;
  1856. if(res && res[1]){
  1857. p1 = parseInt(res[1]);
  1858. if(p1 > 0){
  1859. imgInfo.percent = Math.round(p1/2);
  1860. }
  1861. }else{
  1862. if(res2 && res2[1]){
  1863. p2 = parseInt(res2[1]);
  1864. }
  1865. if(p2 > 0){
  1866. imgInfo.percent = Math.round(50+(p2/2));
  1867. }
  1868. }
  1869. if(this.imgList.indexOf(index)){
  1870. this.imgList.splice(index,1,imgInfo);
  1871. }
  1872. }
  1873. }).then(res => {
  1874. setTimeout(() => {
  1875. if(this.imgList.indexOf(index)){
  1876. imgInfo.percent = 100;
  1877. this.imgList.splice(index, 1, imgInfo);
  1878. }else{
  1879. reject({type:this.menuIndex,index,err:'用户强制终止!'});
  1880. }
  1881. }, 150)
  1882. //未购买 添加系统水印
  1883. this.addWatermark(index,imgInfo,newPath);
  1884. resolve({type:this.menuIndex,index, img});
  1885. }).catch(err => {
  1886. // console.log(err.stderr.toString());
  1887. reject({type:this.menuIndex,index,err});
  1888. });
  1889. });
  1890. break;
  1891. case 2: // 图片压缩
  1892. task = new Promise(async (resolve,reject) => {
  1893. let extraParams = [];
  1894. if(this.handleData.compressOutType == 1 || imgInfo.type.toLowerCase() != 'png'){
  1895. if(this.handleData.compressOutType == 1 || imgInfo.type.toLowerCase() == 'jpg' || imgInfo.type.toLowerCase() == 'JPEG'){
  1896. let sizeOld = fs.statSync(imgInfo.path).size;
  1897. extraParams=['-resize',this.handleData.compressScaling+'%','-define','jpeg:dct-method=fastest','-define','jpeg:extent='+sizeOld,'-sampling-factor','4:2:0','-strip','-interlace','Plane','-background','white','-flatten','-alpha','off','-quality',this.handleData.quality+'%']
  1898. }else{
  1899. extraParams=['+dither','-strip','-colors',256*(this.handleData.quality/90),'-depth',8]
  1900. }
  1901. electronApi.spawnExec(['convert.exe','-monitor',...extraParams,imgInfo.path, newPath],{
  1902. stderr:(data) => {
  1903. let str = data.toString();
  1904. const regexDuration = /Load.*?,(.*?)%/;
  1905. const regexDuration2 = /Save.*?,(.*?)%/;
  1906. const res = regexDuration.exec(str);
  1907. const res2 = regexDuration2.exec(str);
  1908. let p1 = 0;
  1909. let p2 = 0;
  1910. if(res && res[1]){
  1911. p1 = parseInt(res[1]);
  1912. if(p1 > 0){
  1913. imgInfo.percent = Math.round(p1/2);
  1914. }
  1915. }else{
  1916. if(res2 && res2[1]){
  1917. p2 = parseInt(res2[1]);
  1918. }
  1919. if(p2 > 0){
  1920. imgInfo.percent = Math.round(50+(p2/2));
  1921. }
  1922. }
  1923. if(this.imgList[index]){
  1924. this.imgList.splice(index,1,imgInfo);
  1925. }
  1926. }
  1927. }).then(res => {
  1928. setTimeout(() => {
  1929. if(this.imgList[index]){
  1930. imgInfo.percent = 100;
  1931. this.imgList.splice(index, 1, imgInfo);
  1932. }else{
  1933. reject({type:this.menuIndex,index,err:'用户强制终止!'});
  1934. }
  1935. }, 150)
  1936. //未购买 添加系统水印
  1937. this.addWatermark(index,imgInfo,newPath);
  1938. resolve({type:this.menuIndex,index, imgInfo});
  1939. }).catch(err => {
  1940. err.stdout = err.stdout.toString();
  1941. err.stderr = err.stderr.toString();
  1942. reject({type:this.menuIndex,index,err});
  1943. });
  1944. }else{
  1945. // 复制文件到缓存目录 生成结束后输出到目标文件夹
  1946. let tmpPath = os.tmpdir()+separator+'YSI_'+Math.random();
  1947. let tmpPath2 = os.tmpdir()+separator+'YSO_'+Math.random() + '.png';
  1948. fs.copyFileSync(imgInfo.path,tmpPath);
  1949. // 添加系统水印
  1950. await this.addWatermark(index,imgInfo,tmpPath);
  1951. electronApi.spawnExec(['pngquant.exe',tmpPath,'-f','-v','--strip','--quality',this.handleData.quality,'-o',tmpPath2],{
  1952. stderr:(data) => {
  1953. let str = data.toString();
  1954. const regexDuration = /selecting colors...(.*?)%/;
  1955. const res = regexDuration.exec(str);
  1956. if(res && res[1]){
  1957. imgInfo.percent = Math.round(parseInt(res[1])-2);
  1958. }
  1959. if(this.imgList[index]){
  1960. this.imgList.splice(index,1,imgInfo);
  1961. }
  1962. }
  1963. }).then((res) => {
  1964. setTimeout(() => {
  1965. if(this.imgList[index]){
  1966. imgInfo.percent = 100;
  1967. this.imgList.splice(index, 1, imgInfo);
  1968. }else{
  1969. reject({type:this.menuIndex,index,err:'用户强制终止!'});
  1970. }
  1971. }, 150)
  1972. // 复制
  1973. fs.copyFileSync(tmpPath2,newPath);
  1974. resolve({type:this.menuIndex,index, imgInfo});
  1975. }).catch(err => {
  1976. err.stdout = err.stdout.toString();
  1977. err.stderr = err.stderr.toString();
  1978. // 如果失败,重新使用推荐的最小值来转换
  1979. // const regexQ = /\(Q=(.*?)\)/g;
  1980. // const res2 = regexQ.exec(err.stderr);
  1981. // const quality = res2[1];
  1982. this.pngFailedExec(index,tmpPath,tmpPath2,imgInfo,newPath).then(rr => {
  1983. resolve({type:this.menuIndex,index, imgInfo});
  1984. }).catch(err2 => {
  1985. reject({type:this.menuIndex,index,err});
  1986. });
  1987. });
  1988. }
  1989. });
  1990. break;
  1991. case 3: // 更改尺寸
  1992. case 9: // 批量旋转
  1993. task = new Promise((resolve,reject) => {
  1994. let params = [];
  1995. let extraParams = [];
  1996. if(this.handleData.rotateValue != 0){
  1997. extraParams = ['-rotate',this.handleData.rotateValue];
  1998. }
  1999. let vflipParams = [];
  2000. let hflipParams = [];
  2001. if(this.handleData.vflip){
  2002. vflipParams = ['-flip'];
  2003. }
  2004. if(this.handleData.hflip){
  2005. hflipParams = ['-flop'];
  2006. }
  2007. if (this.handleData.sizeType == 1) { // 按照比列缩放
  2008. params = [
  2009. 'convert.exe',
  2010. '-monitor',
  2011. '-resize',
  2012. this.handleData.scaling+'%',
  2013. ...extraParams,
  2014. ...vflipParams,
  2015. ...hflipParams,
  2016. imgInfo.path,
  2017. newPath
  2018. ];
  2019. } else { // 按照尺寸缩放
  2020. params = [
  2021. 'convert.exe',
  2022. '-monitor',
  2023. '-resize',
  2024. `${Number(this.handleData.width)}x${Number(this.handleData.height)}!`,
  2025. ...extraParams,
  2026. ...vflipParams,
  2027. ...hflipParams,
  2028. imgInfo.path,
  2029. newPath
  2030. ];
  2031. }
  2032. electronApi.spawnExec(params,{
  2033. stderr:(data) => {
  2034. let str = data.toString();
  2035. const regexDuration = /Load.*?,(.*?)%/;
  2036. const regexDuration2 = /Save.*?,(.*?)%/;
  2037. const res = regexDuration.exec(str);
  2038. const res2 = regexDuration2.exec(str);
  2039. let p1 = 0;
  2040. let p2 = 0;
  2041. if(res && res[1]){
  2042. p1 = parseInt(res[1]);
  2043. if(p1 > 0){
  2044. imgInfo.percent = Math.round(p1/2);
  2045. }
  2046. }else{
  2047. if(res2 && res2[1]){
  2048. p2 = parseInt(res2[1]);
  2049. }
  2050. if(p2 > 0){
  2051. imgInfo.percent = Math.round(50+(p2/2));
  2052. }
  2053. }
  2054. if(this.imgList[index]){
  2055. this.imgList.splice(index,1,imgInfo);
  2056. }
  2057. }
  2058. }).then(res => {
  2059. setTimeout(() => {
  2060. if(this.imgList[index]){
  2061. imgInfo.percent = 100;
  2062. this.imgList.splice(index, 1, imgInfo);
  2063. }else{
  2064. reject({type:this.menuIndex,index,err:'用户强制终止!'});
  2065. }
  2066. }, 150)
  2067. //未购买 添加系统水印
  2068. this.addWatermark(index,imgInfo,newPath);
  2069. resolve({type:this.menuIndex,index, img});
  2070. }).catch(err => {
  2071. reject({type:this.menuIndex,index,err});
  2072. });
  2073. })
  2074. break;
  2075. case 4: // 美化图片
  2076. task = new Promise((resolve,reject) => {
  2077. let extraParams2 = [];
  2078. let extraParams3 = [];
  2079. let reduceParams = [];
  2080. switch (this.handleData.color){
  2081. case '1': // 黑白
  2082. extraParams2 = ['-type', 'bilevel'];
  2083. break;
  2084. case '2': // 灰色
  2085. extraParams2 = ['-type','grayscale'];
  2086. break;
  2087. case '3': // 反转
  2088. extraParams2 = ['-channel', 'RGB', '-negate'];
  2089. break;
  2090. case '4': // 油画
  2091. extraParams2 = ['-paint', Number(this.handleData.paintValue)-1];
  2092. break;
  2093. }
  2094. if(this.handleData.lineFlag){
  2095. extraParams3 = ['-bordercolor',this.handleData.lineColor,'-border',this.handleData.lineWidth];
  2096. }
  2097. if(reduceFlag){ // 缩小尺寸实现快速渲染???
  2098. //reduceParams = ['-resize','10%'];
  2099. }
  2100. let params2 = [
  2101. 'convert.exe',
  2102. imgInfo.path,
  2103. '-monitor',
  2104. ...reduceParams,
  2105. '-colors',
  2106. this.handleData.colorValue,
  2107. '-brightness-contrast',
  2108. `${Number(this.handleData.brightnessValue)}/${Number(this.handleData.contrastValue)}`,
  2109. '-modulate',
  2110. '100,'+ Number(this.handleData.saturationValue+100) + ',' + Number(this.handleData.hueValue+100),
  2111. '-alpha', 'set', '-channel', 'A', '-evaluate', 'Multiply', this.handleData.opacityValue/100, '+channel',
  2112. ...extraParams2,
  2113. ...extraParams3,
  2114. newPath
  2115. ];
  2116. electronApi.spawnExec(params2,{
  2117. stderr:(data) => {
  2118. let str = data.toString();
  2119. const regexDuration = /Function.*?,(.*?)%/;
  2120. const regexDuration2 = /save.*?,(.*?)%/;
  2121. const res = regexDuration.exec(str);
  2122. const res2 = regexDuration2.exec(str);
  2123. let p1 = 0;
  2124. let p2 = 0;
  2125. if(res && res[1]){
  2126. p1 = parseInt(res[1]);
  2127. if(p1 > 0){
  2128. imgInfo.percent = Math.round(p1/2);
  2129. }
  2130. }else{
  2131. if(res2 && res2[1]){
  2132. p2 = parseInt(res2[1]);
  2133. }
  2134. if(p2 > 0){
  2135. imgInfo.percent = Math.round(50+(p2/2));
  2136. }
  2137. }
  2138. if(this.imgList[index]){
  2139. this.imgList.splice(index,1,imgInfo);
  2140. }
  2141. }
  2142. }).then(res => {
  2143. setTimeout(() => {
  2144. if(this.imgList[index]){
  2145. imgInfo.percent = 100;
  2146. this.imgList.splice(index, 1, imgInfo);
  2147. }else{
  2148. reject({type:this.menuIndex,index,err:'用户强制终止!'});
  2149. }
  2150. }, 150)
  2151. if(!img){ // 预览状态
  2152. electronApi.fileStream(newPath).then(buffer => {
  2153. this.imgSrc = "data:image/png;base64,"+buffer.toString('base64');
  2154. this.imgLoading = false;
  2155. })
  2156. }
  2157. //未购买 添加系统水印
  2158. this.addWatermark(index,imgInfo,newPath);
  2159. resolve({type:this.menuIndex, index, img});
  2160. }).catch(err => {
  2161. reject({type:this.menuIndex, index,err});
  2162. });
  2163. });
  2164. break;
  2165. case 5: // 添加水印
  2166. if (this.handleData.watermarkType == '1') { // 文字水印
  2167. if(this.handleData.fonts == ''){
  2168. this.$message({message: '请选择字体', type: 'warning'});
  2169. this.imgLoading = false;
  2170. break;
  2171. }else{
  2172. task = this.textWatermark(index, imgInfo, newPath,!img);
  2173. }
  2174. } else if (this.handleData.watermarkType == '2') { // 图片水印
  2175. // 平铺功能去掉
  2176. this.handleData.watermarkStyle = 1;
  2177. if(!this.handleData.watermarkImgPath){
  2178. this.$message({message: '请上传图片水印', type: 'warning'});
  2179. this.imgLoading = false;
  2180. break;
  2181. }else{
  2182. task = this.imgWatermark(index, imgInfo, newPath,!img);
  2183. }
  2184. }
  2185. break;
  2186. case 6: // 圆角设置
  2187. task = new Promise((resolve,reject) => {
  2188. let cirPath = newPath;
  2189. if(this.handleData.circularValue > 0){
  2190. cirPath = newPath.substr(0, newPath.lastIndexOf('.')+1) + 'png';
  2191. }
  2192. let extraParams = ['-draw', 'roundrectangle 0,0,'+imgInfo.width+','+imgInfo.height+','+imgInfo.width*this.handleData.circularValue/100+','+imgInfo.width*this.handleData.circularValue/100]
  2193. let params2 = [
  2194. 'convert.exe',
  2195. '-size',
  2196. imgInfo.width+'x'+imgInfo.height,
  2197. 'xc:none',
  2198. '-fill',
  2199. imgInfo.path,
  2200. '-monitor',
  2201. ...extraParams,
  2202. cirPath
  2203. ];
  2204. electronApi.spawnExec(params2,{
  2205. stderr:(data) => {
  2206. let str = data.toString();
  2207. const regexDuration = /Function.*?,(.*?)%/;
  2208. const regexDuration2 = /save.*?,(.*?)%/;
  2209. const res = regexDuration.exec(str);
  2210. const res2 = regexDuration2.exec(str);
  2211. let p1 = 0;
  2212. let p2 = 0;
  2213. if(res && res[1]){
  2214. p1 = parseInt(res[1]);
  2215. if(p1 > 0){
  2216. imgInfo.percent = Math.round(p1/2);
  2217. }
  2218. }else{
  2219. if(res2 && res2[1]){
  2220. p2 = parseInt(res2[1]);
  2221. }
  2222. if(p2 > 0){
  2223. imgInfo.percent = Math.round(50+(p2/2));
  2224. }
  2225. }
  2226. if(this.imgList[index]){
  2227. this.imgList.splice(index,1,imgInfo);
  2228. }
  2229. }
  2230. }).then(res => {
  2231. setTimeout(() => {
  2232. if(this.imgList[index]){
  2233. imgInfo.percent = 100;
  2234. this.imgList.splice(index, 1, imgInfo);
  2235. }else{
  2236. reject({type:this.menuIndex,index,err:'用户强制终止!'});
  2237. }
  2238. }, 150)
  2239. if(!img){ // 预览状态
  2240. electronApi.fileStream(cirPath).then(buffer => {
  2241. this.imgSrc = "data:image/png;base64,"+buffer.toString('base64');
  2242. this.imgLoading = false;
  2243. })
  2244. }
  2245. //未购买 添加系统水印
  2246. this.addWatermark(index,imgInfo,cirPath);
  2247. resolve({type:this.menuIndex, index, img});
  2248. }).catch(err => {
  2249. reject({type:this.menuIndex, index,err});
  2250. });
  2251. });
  2252. break;
  2253. }
  2254. return task;
  2255. },
  2256. //如果转换失败,则使用推荐的Quaity转换图片
  2257. pngFailedExec(index,tmpPath,tmpPath2,imgInfo,newPath){
  2258. return new Promise((resolve,reject) => {
  2259. electronApi.spawnExec(['pngquant.exe',tmpPath,'-f','-v','--strip','-o',tmpPath2],{
  2260. stderr:(data) => {
  2261. let str = data.toString();
  2262. const regexDuration = /selecting colors...(.*?)%/;
  2263. const res = regexDuration.exec(str);
  2264. if(res && res[1]){
  2265. imgInfo.percent = Math.round(parseInt(res[1])-2);
  2266. }
  2267. if(this.imgList[index]){
  2268. this.imgList.splice(index,1,imgInfo);
  2269. }
  2270. }
  2271. }).then((res) => {
  2272. setTimeout(() => {
  2273. if(this.imgList[index]){
  2274. imgInfo.percent = 100;
  2275. this.imgList.splice(index, 1, imgInfo);
  2276. }else{
  2277. reject({type:this.menuIndex,index,err:'用户强制终止!'});
  2278. }
  2279. }, 150)
  2280. // 复制
  2281. fs.copyFileSync(tmpPath2,newPath);
  2282. resolve({type:this.menuIndex,index, imgInfo});
  2283. }).catch(err => {
  2284. err.stdout = err.stdout && err.stdout.toString();
  2285. err.stderr = err.stderr && err.stderr.toString();
  2286. reject({type:this.menuIndex,index,err});
  2287. });
  2288. });
  2289. },
  2290. // scaleWidthChange
  2291. scaleWidthChange(e){
  2292. let scale = Number(this.imgInfo.originalWidth) / Number(this.imgInfo.originalHeight);
  2293. if(this.handleData.lockScale){ // 锁定比例
  2294. this.handleData.height = Math.round(this.handleData.width / scale);
  2295. }
  2296. },
  2297. // scaleHeightChange
  2298. scaleHeightChange(e){
  2299. let scale = Number(this.imgInfo.originalWidth) / Number(this.imgInfo.originalHeight);
  2300. if(this.handleData.lockScale){ // 锁定比例
  2301. this.handleData.width = Math.round(this.handleData.height * scale);
  2302. }
  2303. },
  2304. // 文字水印
  2305. async textWatermark(index, imgInfo, newPath,isPreview=false) {
  2306. let m = this.handleData.watermarkDensityX <= 0 ? 3 : this.handleData.watermarkDensityX;
  2307. let n = this.handleData.watermarkDensityY <= 0 ? 3 : this.handleData.watermarkDensityY;
  2308. return new Promise((resolve,reject) => {
  2309. let tmpPath = os.tmpdir()+separator+'water_font_'+Math.random()+'.png';
  2310. let params = [
  2311. 'convert.exe',
  2312. '-monitor',
  2313. '-background',
  2314. 'none',
  2315. '-fill',
  2316. this.handleData.watermarkColor,
  2317. '-font',
  2318. this.handleData.fonts.toString(),
  2319. '-pointsize',
  2320. this.handleData.watermarkFont,
  2321. '-alpha', 'set', '-channel', 'A', '-evaluate', 'Multiply', this.handleData.watermarkImgOpactiy/100, '+channel', // 透明度
  2322. '-rotate',
  2323. this.handleData.rotate,
  2324. 'label:' + (this.handleData.watermarkValue ? this.handleData.watermarkValue : pjson.softInfo.softName),
  2325. '-gravity',
  2326. 'center',
  2327. '-extent',
  2328. this.handleData.watermarkStyle == 2 ? (imgInfo.width/m)+'x'+(imgInfo.height/n) : '100%',
  2329. tmpPath
  2330. ];
  2331. electronApi.spawnExec(params,{stderr:(data) => { imgInfo.percent = 30;this.imgList.splice(index,1,imgInfo);}}).then(async (res) => {
  2332. // 生成平铺水印图片
  2333. if(this.handleData.watermarkStyle == 2){ // 平铺
  2334. let tmpPath2 = os.tmpdir()+separator+'water_pu_'+Math.random()+'.png';
  2335. let params2 = [
  2336. 'convert.exe',
  2337. '-monitor',
  2338. tmpPath,
  2339. '-write',
  2340. 'mpr:tiler',
  2341. '+delete',
  2342. '-size',
  2343. imgInfo.width+'x'+imgInfo.height,
  2344. 'tile:mpr:tiler',
  2345. tmpPath2
  2346. ];
  2347. await electronApi.spawnExec(params2,{stderr:(data) => { imgInfo.percent=60;this.imgList.splice(index,1,imgInfo);}}).then(async (res2) => {
  2348. await this.waterComposite(index, imgInfo, newPath, tmpPath2);
  2349. if(fs.existsSync(tmpPath)){
  2350. fs.unlinkSync(tmpPath);
  2351. }
  2352. })
  2353. }else{
  2354. await this.waterComposite(index, imgInfo, newPath, tmpPath);
  2355. }
  2356. if(isPreview){ // 预览状态
  2357. electronApi.fileStream(newPath).then(buffer => {
  2358. this.imgSrc = "data:image/png;base64,"+buffer.toString('base64');
  2359. this.imgLoading = false;
  2360. }).catch(err => {
  2361. this.imgLoading = false;
  2362. })
  2363. }
  2364. resolve({type:this.menuIndex, index:index, info:imgInfo});
  2365. }).catch(err => {
  2366. reject({type:this.menuIndex, index:index, err: err});
  2367. });
  2368. });
  2369. },
  2370. // 图片水印
  2371. async imgWatermark(index, imgInfo, newPath,isPreview=false) {
  2372. let m = this.handleData.watermarkDensityX <= 0 ? 3 : this.handleData.watermarkDensityX;
  2373. let n = this.handleData.watermarkDensityY <= 0 ? 3 : this.handleData.watermarkDensityY;
  2374. return new Promise((resolve,reject) => {
  2375. let tmpPath = os.tmpdir()+separator+'water_img_'+Math.random()+'.png';
  2376. let params = [
  2377. 'convert.exe',
  2378. '-monitor',
  2379. '-background',
  2380. 'none',
  2381. '-resize',
  2382. `${Number(this.handleData.watermarkImgSize)}%`,
  2383. '-alpha', 'set', '-channel', 'A', '-evaluate', 'Multiply', this.handleData.watermarkImgOpactiy/100, '+channel', // 透明度
  2384. '-rotate',
  2385. this.handleData.watermarkImgRotate,
  2386. '-gravity',
  2387. 'center',
  2388. '-extent',
  2389. this.handleData.watermarkStyle == 2 ? (imgInfo.width/m)+'x'+(imgInfo.height/n) : '100%',
  2390. this.handleData.watermarkImgPath,
  2391. tmpPath
  2392. ];
  2393. electronApi.spawnExec(params).then(async (res) => {
  2394. // 生成平铺水印图片
  2395. if(this.handleData.watermarkStyle == 2){ // 平铺
  2396. let tmpPath2 = os.tmpdir()+separator+'water_pu_'+Math.random()+'.png';
  2397. let params2 = [
  2398. 'convert.exe',
  2399. '-monitor',
  2400. tmpPath,
  2401. '-write',
  2402. 'mpr:tiler',
  2403. '+delete',
  2404. '-size',
  2405. imgInfo.width+'x'+imgInfo.height,
  2406. 'tile:mpr:tiler',
  2407. tmpPath2
  2408. ];
  2409. await electronApi.spawnExec(params2,{stderr:(data) => { imgInfo.percent=60;this.imgList.splice(index,1,imgInfo);}}).then(async (res2) => {
  2410. await this.waterComposite(index, imgInfo, newPath, tmpPath2);
  2411. if(fs.existsSync(tmpPath)){
  2412. fs.unlinkSync(tmpPath);
  2413. }
  2414. })
  2415. }else{
  2416. await this.waterComposite(index, imgInfo, newPath, tmpPath);
  2417. }
  2418. if(isPreview){ // 预览状态
  2419. electronApi.fileStream(newPath).then(buffer => {
  2420. this.imgSrc = "data:image/png;base64,"+buffer.toString('base64');
  2421. this.imgLoading = false;
  2422. }).catch(err => {
  2423. this.imgLoading = false;
  2424. })
  2425. }
  2426. resolve({type:this.menuIndex, index:index, info:imgInfo});
  2427. }).catch(err => {
  2428. reject({type:this.menuIndex, index:index, err: err});
  2429. });
  2430. });
  2431. },
  2432. async waterComposite(index, imgInfo, newPath,waterImg){
  2433. let params2 = [
  2434. 'convert.exe',
  2435. '-monitor',
  2436. imgInfo.path,
  2437. waterImg,
  2438. '-gravity',
  2439. this.handleData.watermarkStyle == 2 ? 'Center' : this.handleData.watermarkPosition,
  2440. '-geometry',
  2441. '+'+this.handleData.watermarkX+'+'+this.handleData.watermarkY,
  2442. '-composite',
  2443. newPath
  2444. ];
  2445. await electronApi.spawnExec(params2,{
  2446. stderr:(data) => {
  2447. let percent = 0;
  2448. let str = data.toString();
  2449. const regexDuration = /Load.*?,(.*?)%/;
  2450. const regexDuration2 = /Resize.*?,(.*?)%/;
  2451. const res = regexDuration.exec(str);
  2452. const res2 = regexDuration2.exec(str);
  2453. let p1 = 0;
  2454. let p2 = 0;
  2455. if(res && res[1]){
  2456. p1 = parseInt(res[1]);
  2457. if(p1 > 0){
  2458. imgInfo.percent = Math.round(p1/2);
  2459. }
  2460. }else{
  2461. if(res2 && res2[1]){
  2462. p2 = parseInt(res2[1]);
  2463. }
  2464. if(p2 > 0){
  2465. imgInfo.percent = Math.round(50+(p2/2));
  2466. }
  2467. }
  2468. if(this.handleData.watermarkStyle == 2){ // 平铺
  2469. imgInfo.percent = 60 + Math.round(percent*0.4);
  2470. }else{
  2471. imgInfo.percent = percent;
  2472. }
  2473. if(this.imgList[index]){
  2474. this.imgList.splice(index,1,imgInfo);
  2475. }
  2476. },
  2477. }).then(res2 => {
  2478. setTimeout(() => {
  2479. if(this.imgList[index]){
  2480. imgInfo.percent = 100;
  2481. this.imgList.splice(index, 1, imgInfo);
  2482. if(fs.existsSync(waterImg)){
  2483. fs.unlinkSync(waterImg);
  2484. }
  2485. }else{
  2486. reject({type:this.menuIndex,index,err:'用户强制终止!'});
  2487. }
  2488. }, 150)
  2489. //未购买 添加系统水印
  2490. this.addWatermark(index,{...imgInfo,path:newPath},newPath);
  2491. });
  2492. },
  2493. // 初始化系统水印图片
  2494. async initSysWater(imgInfo){
  2495. return new Promise((resolve,reject) => {
  2496. let fontSize = 40;
  2497. let width = imgInfo.width;
  2498. if(this.menuIndex == 3){
  2499. width = width * (this.handleData.scaling / 100);
  2500. }
  2501. if (width < 500) {
  2502. fontSize = 16;
  2503. } else if (width < 1000) {
  2504. fontSize = 28
  2505. }else if(width < 2000){
  2506. fontSize = 40;
  2507. }else if(width < 3000){
  2508. fontSize = 100;
  2509. }else{
  2510. fontSize = 220;
  2511. }
  2512. let sysDefaultTmpPath = os.tmpdir()+separator+'water_xy_'+fontSize+'.png';
  2513. let params = [
  2514. 'convert.exe',
  2515. '-monitor',
  2516. '-background',
  2517. 'none',
  2518. '-fill',
  2519. 'rgba(0,0,0,0.8)',
  2520. '-font',
  2521. this.defaultFont,
  2522. '-pointsize',
  2523. fontSize,
  2524. 'label:https://www.xingyousoft.com',
  2525. sysDefaultTmpPath
  2526. ];
  2527. if(fs.existsSync(sysDefaultTmpPath)){
  2528. resolve(sysDefaultTmpPath)
  2529. }else{
  2530. electronApi.spawnExec(params).then((res) => {
  2531. resolve(sysDefaultTmpPath)
  2532. }).catch(err => {
  2533. reject(err)
  2534. });
  2535. }
  2536. });
  2537. },
  2538. // 添加默认水印
  2539. async addWatermark(index,imgInfo,newPath) {
  2540. return new Promise((resolve,reject) => {
  2541. let authority = this.$refs.headerRef.authority;
  2542. if (authority.isAuthority) {
  2543. // 有权限,则不做任何操作
  2544. resolve(true)
  2545. } else {
  2546. this.initSysWater(imgInfo).then(re => {
  2547. let sysDefaultTmpPath = re;
  2548. // 合并系统水印
  2549. let params2 = [
  2550. 'convert.exe',
  2551. '-monitor',
  2552. newPath,
  2553. sysDefaultTmpPath,
  2554. '-gravity',
  2555. 'center',
  2556. '-composite',
  2557. newPath
  2558. ];
  2559. electronApi.spawnExec(params2).then(result => {
  2560. resolve(result)
  2561. }).catch(err => {
  2562. reject(err)
  2563. });
  2564. }).catch(err2 =>{
  2565. reject({err2})
  2566. });
  2567. }
  2568. })
  2569. },
  2570. deleteSysWtater(){
  2571. let w1 = os.tmpdir()+separator+'water_xy_16.png';
  2572. let w2 = os.tmpdir()+separator+'water_xy_28.png';
  2573. let w3 = os.tmpdir()+separator+'water_xy_40.png';
  2574. let w4 = os.tmpdir()+separator+'water_xy_100.png';
  2575. if(fs.existsSync(w1)){
  2576. fs.unlinkSync(w1);
  2577. }
  2578. if(fs.existsSync(w2)){
  2579. fs.unlinkSync(w2);
  2580. }
  2581. if(fs.existsSync(w3)){
  2582. fs.unlinkSync(w3);
  2583. }
  2584. if(fs.existsSync(w4)){
  2585. fs.unlinkSync(w4);
  2586. }
  2587. },
  2588. // 翻转模式
  2589. flipChange(str){
  2590. if(this.handleData[str]){
  2591. this.handleData[str] = false;
  2592. }else{
  2593. this.handleData[str] = str;
  2594. }
  2595. },
  2596. // 旋转角度
  2597. rotateChange(type){
  2598. let current = this.handleData.rotateValue;
  2599. if(type == 1){ // 逆时针旋转90°
  2600. current -= 90;
  2601. if(current < -360){
  2602. this.handleData.rotateValue = current + 360;
  2603. }else{
  2604. this.handleData.rotateValue = current;
  2605. }
  2606. }else{ // 顺时针旋转90°
  2607. current += 90;
  2608. if(current > 360){
  2609. this.handleData.rotateValue = current - 360;
  2610. }else{
  2611. this.handleData.rotateValue = current;
  2612. }
  2613. }
  2614. },
  2615. // 删除重命名文件
  2616. delImgFile(rowIndex){
  2617. this.$confirm('确认删除这张图片吗?', '提示', {
  2618. confirmButtonText: '确定',
  2619. cancelButtonText: '取消',
  2620. type: 'warning'
  2621. }).then(() => {
  2622. this.imgList.splice(rowIndex, 1);
  2623. if (this.imgList.length == 0) {
  2624. this.clearList();
  2625. }
  2626. }).catch(() => {
  2627. });
  2628. },
  2629. // 重命名操作
  2630. setChange() {
  2631. let list = JSON.parse(JSON.stringify(this.imgList));
  2632. list.map((item, key) => {
  2633. let lastIndex = item.name.lastIndexOf('.');
  2634. let fileName = item.name.substring(0, lastIndex);
  2635. let fileExtend = item.name.substr(lastIndex+1);
  2636. // ------------------文件名---------------------
  2637. let newFilename = '', newExtendname = '';
  2638. let fileNo = (this.handleRename.increment * key) + this.handleRename.startNumber;
  2639. if(fileNo.toString().length < this.handleRename.digit){
  2640. let size = this.handleRename.digit - fileNo.toString().length;
  2641. let digitStr = "";
  2642. for(let i = 0; i < size; i++){
  2643. digitStr += "0";
  2644. }
  2645. fileNo = digitStr + fileNo;
  2646. }
  2647. newFilename = this.handleRename.fileName ? this.handleRename.fileName + fileNo : fileNo;
  2648. // 文件名大小写转换
  2649. newFilename = newFilename.toString();
  2650. switch(this.handleRename.fileCase){
  2651. case "2": // 全部大写
  2652. newFilename = newFilename.toUpperCase();
  2653. break;
  2654. case "3": // 全部小写
  2655. newFilename = newFilename.toLowerCase();
  2656. break;
  2657. case "4": // 首字母大写
  2658. newFilename = newFilename.charAt(0).toUpperCase() + newFilename.slice(1);
  2659. break;
  2660. case "5": // 首字母小写
  2661. newFilename = newFilename.charAt(0).toLowerCase() + newFilename.slice(1);
  2662. break;
  2663. }
  2664. item.newName = newFilename + '.' + fileExtend;
  2665. });
  2666. this.imgList = JSON.parse(JSON.stringify(list));
  2667. },
  2668. // 重命名
  2669. exportRename() {
  2670. let authority = this.$refs.headerRef.authority;
  2671. let tempList = [];
  2672. this.renameLoading = this.$loading({
  2673. lock: true,
  2674. text: '批量操作中,请稍后...',
  2675. spinner: 'el-icon-loading',
  2676. background: 'rgba(0, 0, 0, 0.7)'
  2677. });
  2678. setTimeout(() => {
  2679. this.renameLoading.close();
  2680. this.renameModal = true;
  2681. // this.$alert('重命名成功', '提示', {
  2682. // confirmButtonText: '确定',
  2683. // callback: action => {
  2684. // this.setChange();
  2685. // }
  2686. // });
  2687. this.imgList = JSON.parse(JSON.stringify(tempList));
  2688. }, 3000);
  2689. tempList = JSON.parse(JSON.stringify(this.imgList));
  2690. let size = 999999999;
  2691. if(!authority.isAuthority){
  2692. size = 10;
  2693. }
  2694. setTimeout(()=>{
  2695. for(let index = 0; index < tempList.length; index++) {
  2696. let item = tempList[index];
  2697. item.status = "1";
  2698. let path = pathMod.dirname(item.path) + "\\";
  2699. let newPath = path + item.newName;
  2700. if(index < size) {
  2701. fs.exists(path+item.name, (exists) => {
  2702. if (exists) {
  2703. fs.exists(newPath, (new_exists) => {
  2704. if(!new_exists) {
  2705. fs.rename(path+item.name, newPath, (err) => {
  2706. if(err){
  2707. item.status = "3"; throw err;
  2708. }else{
  2709. item.status = "2"; // 修改成功
  2710. item.name = item.newName;
  2711. item.path = newPath;
  2712. }
  2713. });
  2714. } else {
  2715. item.status = "5"; // 文件已存在
  2716. }
  2717. })
  2718. } else {
  2719. item.status = "4"; // 文件被修改
  2720. }
  2721. });
  2722. }
  2723. }
  2724. }, 200);
  2725. },
  2726. // 拖拽排序
  2727. dragEnd(event){
  2728. this.sortChange(this.mergeData.sortType);
  2729. },
  2730. // 删除拼接图片
  2731. deleteMerge(index, tips){
  2732. this.$confirm('确认删除这张图片吗?', '提示', {
  2733. confirmButtonText: '确定',
  2734. cancelButtonText: '取消',
  2735. type: 'warning'
  2736. }).then(() => {
  2737. if(tips == 'crop'){ // 删除裁剪图片
  2738. this.cropList.splice(index, 1);
  2739. if(this.cropList.length > 0){
  2740. this.cropImgIndex = 0;
  2741. this.cropOptions.img = this.cropList[0].path;
  2742. this.cropOptionsImgInfo = this.cropList[0];
  2743. this.cropImgLoading = false;
  2744. }
  2745. }else{
  2746. this.mergeList.splice(index, 1);
  2747. this.sortChange(this.mergeData.sortType);
  2748. }
  2749. }).catch(() => {
  2750. });
  2751. event.stopPropagation();
  2752. },
  2753. // 移动图片
  2754. move(id){
  2755. let that = this;
  2756. let obj = document.getElementById('merge-imgId-'+id);
  2757. let currentWidth = obj.offsetWidth; // 当前元素的宽
  2758. let currentHeight = obj.offsetHeight; // 当前元素的高
  2759. let parentWidth = obj.parentElement.offsetWidth; // 父元素的宽
  2760. let parentHeight = obj.parentElement.offsetHeight; // 父元素的高
  2761. obj.onmousedown = function(e) { //鼠标按下事件
  2762. e = e || window.event; //事件对象
  2763. let x_down = e.clientX; //鼠标按下X的坐标
  2764. let y_down = e.clientY; //鼠标按下Y的坐标
  2765. let leftDown = this.offsetLeft; //获取盒子的初始left值
  2766. let topDown = this.offsetTop; //获取盒子的初始top值
  2767. obj.parentElement.style.border = "2px solid #ed4014";
  2768. document.onmousemove = function(e) { //鼠标移动事件
  2769. // console.log(e.fromElement, e.toElement);
  2770. e = e || window.event;
  2771. let x_move = e.clientX; //鼠标移动X的坐标
  2772. let y_move = e.clientY; //鼠标移动Y的坐标
  2773. //移动的坐标减去按下的坐标 = 移动的距离
  2774. let x_now = x_move - x_down;
  2775. let y_now = y_move - y_down;
  2776. let top = topDown + y_now;
  2777. let left = leftDown + x_now;
  2778. //赋值给left和top
  2779. obj.style.top = top / parentHeight * 100 + '%'; //top + 'px';
  2780. obj.style.left = left / parentWidth * 100 + '%'; //left + 'px';
  2781. if(top > 0){
  2782. top = 0;
  2783. obj.style.top = 0;
  2784. }
  2785. if(left > 0){
  2786. left = 0;
  2787. obj.style.left = 0;
  2788. }
  2789. if(left < parentWidth - currentWidth ){
  2790. left = parentWidth - currentWidth;
  2791. obj.style.left = (parentWidth - currentWidth) / parentWidth * 100 + '%'; //parentWidth - currentWidth + 'px';
  2792. }
  2793. if(top < parentHeight - currentHeight){
  2794. top = parentHeight - currentHeight;
  2795. obj.style.top = (parentHeight - currentHeight) / parentHeight * 100 + '%'; //parentHeight - currentHeight + 'px';
  2796. }
  2797. that.mergeList[id].top = Math.abs(top / parentHeight);
  2798. that.mergeList[id].left = Math.abs(left / parentWidth);
  2799. }
  2800. document.onmouseup = function() { //鼠标抬起事件
  2801. //清除移动和抬起事件
  2802. obj.parentElement.style.border = "none";
  2803. this.onmousemove = this.onmouseup = null;
  2804. }
  2805. return false //阻止默认事件
  2806. }
  2807. },
  2808. //
  2809. outWidthChange(e){
  2810. let scale = Number(this.mergeData.scale.split(':')[0]) / Number(this.mergeData.scale.split(':')[1]);
  2811. this.mergeData.outHeight = Math.round(this.mergeData.outWidth / scale);
  2812. if(this.mergeData.sortType == 3){
  2813. this.mergeData.height = this.mergeData.outHeight;
  2814. this.mergeData.width = this.mergeData.outWidth;
  2815. }
  2816. },
  2817. //
  2818. outHeightChange(e){
  2819. let scale = Number(this.mergeData.scale.split(':')[0]) / Number(this.mergeData.scale.split(':')[1]);
  2820. this.mergeData.outWidth = Math.round(this.mergeData.outHeight * scale);
  2821. if(this.mergeData.sortType == 3){
  2822. this.mergeData.height = this.mergeData.outHeight;
  2823. this.mergeData.width = this.mergeData.outWidth;
  2824. }
  2825. },
  2826. //
  2827. widthChange(e){
  2828. let scale = Number(this.mergeData.scale.split(':')[0]) / Number(this.mergeData.scale.split(':')[1]);
  2829. if(this.mergeData.lockScale){ // 锁定比例
  2830. this.mergeData.height = Math.round(this.mergeData.width / scale);
  2831. }
  2832. let percent = this.mergeData.height / this.mergeData.width * 50;
  2833. this.mergeData.autoStyle = "padding-top: " + percent + "%;";
  2834. },
  2835. //
  2836. heightChange(e){
  2837. let scale = Number(this.mergeData.scale.split(':')[0]) / Number(this.mergeData.scale.split(':')[1]);
  2838. if(this.mergeData.lockScale){ // 锁定比例
  2839. this.mergeData.width = Math.round(this.mergeData.height * scale);
  2840. }
  2841. let percent = this.mergeData.height / this.mergeData.width * 50;
  2842. this.mergeData.autoStyle = "padding-top: " + percent + "%;";
  2843. },
  2844. //
  2845. sizeChange(e){
  2846. if(this.mergeData.sortType == 1){ // 1、横图 2、竖图
  2847. let spaceReal = this.mergeList[0].height * this.mergeData.space / 500;
  2848. let borderReal = this.mergeList[0].height * this.mergeData.border / 500;
  2849. this.mergeData.width = Number((this.mergeData.contentWidth + spaceReal * (this.mergeList.length - 1) + borderReal * 2).toFixed(0));
  2850. this.mergeData.height = Number((this.mergeData.contentHeight + borderReal * 2).toFixed(0));
  2851. }else if(this.mergeData.sortType == 2){
  2852. let spaceReal = this.mergeList[0].width * this.mergeData.space / 500;
  2853. let borderReal = this.mergeList[0].width * this.mergeData.border / 500;
  2854. this.mergeData.width = Number((this.mergeData.contentWidth + borderReal * 2).toFixed(0));
  2855. this.mergeData.height = Number((this.mergeData.contentHeight + spaceReal * (this.mergeList.length - 1) + borderReal * 2).toFixed(0));
  2856. }
  2857. this.mergeData.scale = this.mergeData.width + ':' + this.mergeData.height;
  2858. let scale = Number(this.mergeData.scale.split(':')[0]) / Number(this.mergeData.scale.split(':')[1]);
  2859. if(this.mergeData.sortType == 1){
  2860. this.mergeData.outWidth = Math.round(this.mergeData.outHeight * scale);
  2861. }else if(this.mergeData.sortType == 2){
  2862. this.mergeData.outHeight = Math.round(this.mergeData.outWidth / scale);
  2863. }
  2864. },
  2865. // 失焦事件
  2866. numBlur(str){
  2867. if(!this.mergeData[str]){
  2868. this.mergeData[str] = 0;
  2869. }
  2870. },
  2871. // 选择排序模式 1、横图 2、竖图 3、自定义
  2872. sortChange(e){
  2873. let canvasWidth = 0;
  2874. let canvasHeight = 0;
  2875. if(e == 1){
  2876. canvasWidth = 0;
  2877. canvasHeight = this.mergeList[0].height;
  2878. this.mergeList.map(item => {
  2879. let width = Number(canvasHeight * (item.width / item.height));
  2880. canvasWidth = canvasWidth + width;
  2881. })
  2882. }else if(e == 2){
  2883. canvasWidth = this.mergeList[0].width;
  2884. canvasHeight = 0;
  2885. this.mergeList.map(item => {
  2886. let height = Number(canvasWidth / (item.width / item.height));
  2887. canvasHeight = canvasHeight + height;
  2888. })
  2889. }else{
  2890. canvasWidth = 1200;
  2891. canvasHeight = 1200;
  2892. this.mergeData.autoStyle = 'padding-top: 50%;';
  2893. }
  2894. this.mergeData.contentWidth = Number(canvasWidth.toFixed(0));
  2895. this.mergeData.contentHeight = Number(canvasHeight.toFixed(0));
  2896. this.mergeData.width = Number(canvasWidth.toFixed(0));
  2897. this.mergeData.height = Number(canvasHeight.toFixed(0));
  2898. this.mergeData.scale = this.mergeData.width + ':' + this.mergeData.height;
  2899. this.mergeData.outWidth = Number(canvasWidth.toFixed(0));
  2900. this.mergeData.outHeight = Number(canvasHeight.toFixed(0));
  2901. this.sizeChange();
  2902. },
  2903. // 缩放
  2904. zoom(flag){
  2905. if(flag == 'reduce'){ // 缩小
  2906. if(this.mergeData.zoom > 0.7){
  2907. this.mergeData.zoom -= 0.1;
  2908. }
  2909. }else{ // 放大
  2910. if(this.mergeData.zoom < 2){
  2911. this.mergeData.zoom += 0.1;
  2912. }
  2913. }
  2914. },
  2915. // 修改画布大小
  2916. canvasChange(e){
  2917. let regex = /([1-9]*:[1-9]*)/g;
  2918. let val = e.match(regex)[0];
  2919. let str = 'padding-top: 50%;';
  2920. let width = 1200;
  2921. let height = 1200;
  2922. switch(val){
  2923. case '1:1': // 1:1 1200:1200
  2924. str = 'padding-top: 50%;';
  2925. width = 1200;
  2926. height = 1200;
  2927. break;
  2928. case '2:3': // 2:3 1200:1800
  2929. str = 'padding-top: 75%;';
  2930. width = 1200;
  2931. height = 1800;
  2932. break;
  2933. case '3:2': // 3:2 1800:1200
  2934. str = 'padding-top: 33.333%;';
  2935. width = 1800;
  2936. height = 1200;
  2937. break;
  2938. case '3:4': // 3:4 1200:1600
  2939. str = 'padding-top: 66.666%;';
  2940. width = 1200;
  2941. height = 1600;
  2942. break;
  2943. case '4:3': // 4:3 1600:1200
  2944. str = 'padding-top: 37.5%;';
  2945. width = 1600;
  2946. height = 1200;
  2947. break;
  2948. case '16:9': // 16:9 1920:1080
  2949. str = 'padding-top: 28.125%;';
  2950. width = 1920;
  2951. height = 1080;
  2952. break;
  2953. case '9:16': // 9:16 1080:1920
  2954. str = 'padding-top: 88.888%;';
  2955. width = 1080;
  2956. height = 1920;
  2957. break;
  2958. }
  2959. this.mergeData.autoStyle = str;
  2960. this.mergeData.width = width;
  2961. this.mergeData.height = height;
  2962. this.mergeData.outWidth= width;
  2963. this.mergeData.outHeight = height;
  2964. this.mergeData.scale = val;
  2965. },
  2966. // 自定义块样式
  2967. blockStyle(flag){
  2968. let str = '';
  2969. let spacePix = this.mergeData.width * (this.mergeData.space / 10 / 100); //间距的宽度 -> 间距的百分比以宽为基数
  2970. let heightSpace = spacePix / this.mergeData.height * 100;
  2971. if(flag == 'height'){
  2972. str = 'height: ' + (100 / this.mergeData.row - (heightSpace * (this.mergeData.row - 1) / this.mergeData.row)) + '%;'
  2973. }else{
  2974. str = 'width:' + (100 / this.mergeData.col - (this.mergeData.space / 10 * (this.mergeData.col - 1) / this.mergeData.col)) + '%;border-radius:'+ this.mergeData.radius / 2 +'%;'
  2975. }
  2976. return str;
  2977. },
  2978. // 行数列数发生变化 图片位置初始化0
  2979. rowColChange(){
  2980. let num = this.mergeData.row * this.mergeData.col;
  2981. this.mergeList.map((item, index) => {
  2982. item.top = 0;
  2983. item.left = 0;
  2984. if(index < num && document.getElementById('merge-imgId-'+index)){
  2985. document.getElementById('merge-imgId-'+index).style.top = 0;
  2986. document.getElementById('merge-imgId-'+index).style.left = 0;
  2987. }
  2988. })
  2989. },
  2990. // 图片自适应宽高
  2991. picStyle(index){
  2992. let imgWidth = this.mergeList[index].width; // 图高
  2993. let imgHeight = this.mergeList[index].height; // 图高
  2994. let blockWidth = this.mergeData.width / this.mergeData.col; // 块宽
  2995. let blockHeight = this.mergeData.height / this.mergeData.row; // 块高
  2996. let str = "width: 100%;";
  2997. let fillType = "width";
  2998. if(imgWidth > imgHeight){
  2999. if(blockWidth <= blockHeight){
  3000. str = "height: 100%";
  3001. fillType = "height";
  3002. }else{
  3003. str = (blockWidth / blockHeight) >= (imgWidth / imgHeight) ? "width:100%;" : "height:100%;";
  3004. fillType = (blockWidth / blockHeight) >= (imgWidth / imgHeight) ? "width" : "height";
  3005. }
  3006. }else{
  3007. if(blockWidth >= blockHeight){
  3008. str = "width: 100%;";
  3009. fillType = "width";
  3010. }else{
  3011. if(imgWidth == imgHeight){
  3012. str = "height:100%;";
  3013. fillType = "height";
  3014. }else{
  3015. str = blockWidth / blockHeight >= imgWidth / imgHeight ? "width:100%;" : "height:100%;";
  3016. fillType = blockWidth / blockHeight >= imgWidth / imgHeight ? "width" : "height";
  3017. }
  3018. }
  3019. }
  3020. this.mergeList[index].fillType = fillType;
  3021. return str;
  3022. },
  3023. // 图片拼接-自定义
  3024. exportMerge(){ // 先按照移动比列裁剪 在拼接图片
  3025. //convert src.jpg -resize 500x500 -crop 100x80+50+30 dest.jpg
  3026. clearInterval(this.mergeInterval);
  3027. this.mergeLoading = this.$loading({
  3028. lock: true,
  3029. text: '图片处理中,请稍后...',
  3030. spinner: 'el-icon-loading',
  3031. background: 'rgba(0, 0, 0, 0.7)'
  3032. });
  3033. setTimeout(()=>{ // 3分钟后加载层消失防止进程出错
  3034. this.mergeLoading.close();
  3035. }, 1000 * 60 * 3);
  3036. let borderWidth = this.mergeData.width * (this.mergeData.border / 10 / 100); // 边框的宽度
  3037. let spaceWidth = this.mergeData.width * (this.mergeData.space / 10 / 100);; // 间距的宽度
  3038. let blockWidth = (this.mergeData.width - borderWidth * 2 - spaceWidth * (this.mergeData.col - 1)) / this.mergeData.col; // 块宽
  3039. let blockHeight = (this.mergeData.height - borderWidth * 2 - spaceWidth * (this.mergeData.row - 1)) / this.mergeData.row; // 块高
  3040. let radiusWidth = this.mergeData.radius / 2 / 100 * blockWidth || 0;
  3041. let newFolderPath = this.handleData.newPath;
  3042. let newTime = new Date().getTime();
  3043. fs.mkdirSync(os.tmpdir() + separator + pjson.softInfo.softMid+newTime);
  3044. newFolderPath = os.tmpdir() + separator + pjson.softInfo.softMid+newTime;
  3045. let dealNum = 0;
  3046. let errorIndex = -1;
  3047. let imgParamsArr = []; // 所有图片的位置参数
  3048. // 生成圆角MASK遮盖层 convert -size "$W"x"$H" xc:none -draw "roundrectangle 0,0,$W,$H,$R,$R" $MASK
  3049. let maskPath = os.tmpdir()+separator+'radius.png';
  3050. let radiusStr = 'roundrectangle 0,0,'+blockWidth+','+blockHeight+','+radiusWidth+','+radiusWidth;
  3051. if(this.mergeData.radius == 0){
  3052. radiusStr = 'rectangle 0,0,'+blockWidth+','+blockHeight;
  3053. }
  3054. let paramsRadius = [
  3055. 'convert.exe',
  3056. '-size',
  3057. blockWidth+'x'+blockHeight,
  3058. 'xc:none',
  3059. '-draw',
  3060. radiusStr,
  3061. maskPath
  3062. ];
  3063. electronApi.spawnExec(paramsRadius).then(res => {
  3064. setTimeout(() => { // 延迟执行
  3065. for(let index = 0; index < this.mergeList.length; index++){
  3066. let item = this.mergeList[index];
  3067. if(index < this.mergeData.row * this.mergeData.col){ // 自定义排序
  3068. let imgRealWidth = 0;
  3069. let imgRealHeight = 0;
  3070. let top = 0;
  3071. let left = 0;
  3072. let cropParams = [];
  3073. if(this.mergeData.mergeType == 1){ // 自适应模式
  3074. if(item.fillType == 'width'){
  3075. imgRealHeight = blockHeight;
  3076. imgRealWidth = imgRealHeight * (item.width / item.height);
  3077. }else{
  3078. imgRealWidth = blockWidth;
  3079. imgRealHeight = imgRealWidth / (item.width / item.height);
  3080. }
  3081. top = (blockHeight - imgRealHeight) / 2;
  3082. left = (blockWidth - imgRealWidth) / 2;
  3083. }else{ // 自定义裁剪模式
  3084. if(item.fillType == 'width'){
  3085. imgRealWidth = blockWidth;
  3086. imgRealHeight = imgRealWidth / (item.width / item.height);
  3087. }else{
  3088. imgRealHeight = blockHeight;
  3089. imgRealWidth = imgRealHeight * (item.width / item.height);
  3090. }
  3091. top = item.top * blockHeight;
  3092. left = item.left * blockWidth;
  3093. cropParams = ['-crop',blockWidth+'x'+blockHeight+'+'+left+'+'+top];
  3094. }
  3095. let newTime2 = new Date().getTime();
  3096. let newPath = newFolderPath + separator + item.name.slice(0, item.name.lastIndexOf('.')) +newTime2+Math.random()+ '.png';
  3097. // convert $SRC -matte $MASK -compose DstIn -composite $TMP_PNG
  3098. let params = [
  3099. 'convert.exe',
  3100. item.path,
  3101. '-resize',
  3102. imgRealWidth+'x'+imgRealHeight,
  3103. ...cropParams,
  3104. '-matte',
  3105. maskPath,
  3106. '-compose',
  3107. 'DstIn',
  3108. '-composite',
  3109. newPath
  3110. ];
  3111. let currentRow = Math.floor(index / this.mergeData.col) + 1;
  3112. let currentCol = index % this.mergeData.col + 1;
  3113. let imgPositionX = borderWidth + blockWidth * (currentCol - 1) + spaceWidth * (currentCol - 1);
  3114. let imgPositionY = borderWidth + blockHeight * (currentRow - 1) + spaceWidth * (currentRow - 1);
  3115. if(this.mergeData.mergeType == 1){ // 自适应
  3116. imgPositionX = imgPositionX + left;
  3117. imgPositionY = imgPositionY + top;
  3118. }
  3119. let imgParams = [newPath, '-geometry', '+'+imgPositionX+'+'+imgPositionY, '-composite'];
  3120. electronApi.spawnExec(params).then(res => {
  3121. dealNum ++;
  3122. imgParamsArr = imgParamsArr.concat(imgParams);
  3123. }).catch(err => {
  3124. this.mergeLoading.close();
  3125. errorIndex = index;
  3126. this.$notify.error({
  3127. title: '第【'+Number(index+1)+'】张图片出错',
  3128. message: '请调整后重试!' + err.stderr.toString()
  3129. });
  3130. });
  3131. }
  3132. }
  3133. this.mergeInterval = setInterval(() => {
  3134. if(this.mergeData.row * this.mergeData.col == dealNum || dealNum == this.mergeList.length){ // 裁剪完成 准备拼接图片
  3135. clearInterval(this.mergeInterval);
  3136. // 拼接命令参数 ['2.jpg', '-geometry', '+256+0', '-composite'];
  3137. let suffix = '.jpg';
  3138. if(Number(this.mergeData.backgroundColor.match(/[\d.]+/g)[3]) < 1){
  3139. suffix = '.png';
  3140. }
  3141. let outPath = this.handleData.newPath+separator+pjson.softInfo.softName+separator+'图片拼接'+this.$utils.formatTime(newTime/1000)+suffix;
  3142. let params2 = [
  3143. 'convert.exe',
  3144. '-size',
  3145. this.mergeData.width+'x'+this.mergeData.height,
  3146. '-strip',
  3147. 'xc:'+this.mergeData.backgroundColor,
  3148. ...imgParamsArr,
  3149. outPath
  3150. ];
  3151. electronApi.spawnExec(params2).then(res => {
  3152. this.mergeLoading.close();
  3153. this.$message({message: '恭喜你,图片拼接完成!', type: 'success'});
  3154. try{
  3155. // 未购买 添加系统水印
  3156. this.addWatermark(0, {width:this.mergeData.width, height: this.mergeData.height}, outPath);
  3157. // 删除裁剪的图片
  3158. fs.readdir(newFolderPath, (err, files) => {
  3159. for (let i = 0; i < files.length; i++) {
  3160. let statFile = newFolderPath+separator+files[i];
  3161. fs.unlinkSync(statFile);
  3162. }
  3163. fs.rmdir(newFolderPath, (err) => {
  3164. if(err){
  3165. console.log(err);
  3166. }
  3167. });
  3168. });
  3169. }catch(e){
  3170. console.log(e);
  3171. }
  3172. setTimeout(() => { // 延迟打开
  3173. electronApi.call('showItemInfolder',[outPath])
  3174. }, 1000);
  3175. }).catch(err => {
  3176. this.mergeLoading.close();
  3177. this.$notify.error({
  3178. title: '图片拼接失败-3',
  3179. message: '请调整后重试!' + err.stderr.toString()
  3180. });
  3181. });
  3182. }else if(errorIndex >= 0){ // 文件处理出错
  3183. clearInterval(this.mergeInterval);
  3184. }
  3185. }, 1000);
  3186. }, 300)
  3187. }).catch(err => {
  3188. this.mergeLoading.close();
  3189. this.$notify.error({
  3190. title: '图片【'+Number(index+1)+'】出错',
  3191. message: '请调整后重试!遮盖层' + err.stderr.toString()
  3192. });
  3193. console.log('圆角遮盖层创建失败',err.stderr.toString())
  3194. });
  3195. },
  3196. // 图片拼接-横图和竖图
  3197. exportMerge2(){ // 先按照移动比列裁剪 在拼接图片
  3198. //convert src.jpg -resize 500x500 -crop 100x80+50+30 dest.jpg
  3199. clearInterval(this.mergeInterval);
  3200. this.mergeLoading = this.$loading({
  3201. lock: true,
  3202. text: '图片处理中,请稍后...',
  3203. spinner: 'el-icon-loading',
  3204. background: 'rgba(0, 0, 0, 0.7)'
  3205. });
  3206. setTimeout(()=>{ // 3分钟后加载层消失防止进程出错
  3207. this.mergeLoading.close();
  3208. }, 1000 * 60 * 3);
  3209. let newFolderPath = this.handleData.newPath;
  3210. let newTime = new Date().getTime();
  3211. fs.mkdirSync(os.tmpdir() + separator + pjson.softInfo.softMid+newTime);
  3212. newFolderPath = os.tmpdir() + separator + pjson.softInfo.softMid+newTime;
  3213. setTimeout(async() => { // 延迟执行
  3214. let contentWidth = 0, contentHeight = 0;
  3215. let dealNum = 0;
  3216. let errorIndex = -1;
  3217. let imgParamsArr = []; // 所有图片的位置参数
  3218. for(let index = 0; index < this.mergeList.length; index++){
  3219. let item = this.mergeList[index];
  3220. let firstItem = this.mergeList[0];
  3221. let borderWidth = 0, spaceWidth = 0, blockWidth = 0, blockHeight = 0, radiusWidth = 0;
  3222. if(this.mergeData.sortType == 1){ // 横版
  3223. borderWidth = firstItem.height * (this.mergeData.border / 500); // 边框的宽度
  3224. spaceWidth = firstItem.height * (this.mergeData.space / 500); // 间距的宽度
  3225. blockWidth = item.width / (item.height / firstItem.height);
  3226. blockHeight = firstItem.height;
  3227. radiusWidth = this.mergeData.radius / 2 / 100 * blockWidth || 0;
  3228. }else if(this.mergeData.sortType == 2){ // 竖版
  3229. borderWidth = firstItem.width * (this.mergeData.border / 500); // 边框的宽度
  3230. spaceWidth = firstItem.width * (this.mergeData.space / 500); // 间距的宽度
  3231. blockHeight = item.height / (item.width / firstItem.width);
  3232. blockWidth = firstItem.width;
  3233. radiusWidth = this.mergeData.radius / 2 / 100 * blockWidth || 0;
  3234. }
  3235. // 生成圆角MASK遮盖层 convert -size "$W"x"$H" xc:none -draw "roundrectangle 0,0,$W,$H,$R,$R" $MASK
  3236. let maskPath = os.tmpdir()+separator+'radius'+index+'.png';
  3237. let radiusStr = 'roundrectangle 0,0,'+blockWidth+','+blockHeight+','+radiusWidth+','+radiusWidth;
  3238. if(this.mergeData.radius == 0){
  3239. radiusStr = 'rectangle 0,0,'+blockWidth+','+blockHeight;
  3240. }
  3241. let paramsRadius = [
  3242. 'convert.exe',
  3243. '-size',
  3244. blockWidth+'x'+blockHeight,
  3245. 'xc:none',
  3246. '-draw',
  3247. radiusStr,
  3248. maskPath
  3249. ];
  3250. await electronApi.spawnExec(paramsRadius).then(async(res) => {
  3251. let newTime2 = new Date().getTime();
  3252. let newPath = newFolderPath + separator + item.name.slice(0, item.name.lastIndexOf('.')) +newTime+Math.random()+ '.png';
  3253. let params = [
  3254. 'convert.exe',
  3255. item.path,
  3256. '-resize',
  3257. blockWidth+'x'+blockHeight,
  3258. '-matte',
  3259. maskPath,
  3260. '-compose',
  3261. 'DstIn',
  3262. '-composite',
  3263. newPath
  3264. ];
  3265. contentWidth += blockWidth;
  3266. contentHeight += blockHeight;
  3267. let imgPositionX = 0;
  3268. let imgPositionY = 0;
  3269. if(this.mergeData.sortType == 1){ // 横版
  3270. imgPositionX = borderWidth + (contentWidth - blockWidth) + spaceWidth * index;
  3271. imgPositionY = borderWidth;
  3272. }else if(this.mergeData.sortType == 2){ // 竖版
  3273. imgPositionX = borderWidth;
  3274. imgPositionY = borderWidth + (contentHeight - blockHeight) + spaceWidth * index;
  3275. }
  3276. let imgParams = [newPath, '-geometry', '+'+imgPositionX+'+'+imgPositionY, '-composite'];
  3277. await electronApi.spawnExec(params).then(res => {
  3278. dealNum ++;
  3279. imgParamsArr = imgParamsArr.concat(imgParams);
  3280. }).catch(err => {
  3281. this.mergeLoading.close();
  3282. errorIndex = index;
  3283. this.$notify.error({
  3284. title: '图片【'+Number(index+1)+'】出错',
  3285. message: '请调整后重试!' + err.stderr.toString()
  3286. });
  3287. });
  3288. }).catch(err => {
  3289. this.mergeLoading.close();
  3290. this.$notify.error({
  3291. title: '图片【'+Number(index+1)+'】出错',
  3292. message: '请调整后重试!遮盖层' + err.stderr.toString()
  3293. });
  3294. console.log('圆角遮盖层创建失败',err.stderr.toString())
  3295. });
  3296. }
  3297. this.mergeInterval = setInterval(() => {
  3298. if(dealNum == this.mergeList.length){ // 裁剪完成 准备拼接图片
  3299. clearInterval(this.mergeInterval);
  3300. // 拼接命令参数 ['2.jpg', '-geometry', '+256+0', '-composite'];
  3301. let suffix = '.jpg';
  3302. if(Number(this.mergeData.backgroundColor.match(/[\d.]+/g)[3]) < 1){
  3303. suffix = '.png';
  3304. }
  3305. let outPath = this.handleData.newPath+separator+pjson.softInfo.softName+separator+'图片拼接'+this.$utils.formatTime(newTime/1000)+suffix;
  3306. let params2 = [
  3307. 'convert.exe',
  3308. '-size',
  3309. this.mergeData.width+'x'+this.mergeData.height,
  3310. '-strip',
  3311. 'xc:'+this.mergeData.backgroundColor,
  3312. ...imgParamsArr,
  3313. '-resize',
  3314. Number(this.mergeData.outWidth / this.mergeData.width) * 100 + '%',
  3315. outPath
  3316. ];
  3317. electronApi.spawnExec(params2).then(res => {
  3318. this.mergeLoading.close();
  3319. this.$message({message: '恭喜你,图片拼接完成!', type: 'success'});
  3320. try{
  3321. // 未购买 添加系统水印
  3322. this.addWatermark(0, {width:this.mergeData.outWidth, height: this.mergeData.outHeight}, outPath);
  3323. // 删除裁剪的图片
  3324. fs.readdir(newFolderPath, (err, files) => {
  3325. for (let i = 0; i < files.length; i++) {
  3326. let statFile = newFolderPath+separator+files[i];
  3327. fs.unlinkSync(statFile);
  3328. }
  3329. fs.rmdir(newFolderPath, (err) => {
  3330. if(err){
  3331. console.log(err);
  3332. }
  3333. });
  3334. });
  3335. }catch(e){
  3336. console.log(e);
  3337. }
  3338. setTimeout(() => { // 延迟打开
  3339. electronApi.call('showItemInfolder',[outPath])
  3340. }, 1000);
  3341. }).catch(err => {
  3342. this.mergeLoading.close();
  3343. this.$notify.error({
  3344. title: '图片拼接失败',
  3345. message: '请调整后重试!' + err.stderr.toString()
  3346. });
  3347. });
  3348. }else if(errorIndex >= 0){ // 文件处理出错
  3349. clearInterval(this.mergeInterval);
  3350. }
  3351. }, 1000);
  3352. }, 300)
  3353. },
  3354. }
  3355. };
  3356. </script>
  3357. <style lang="scss">
  3358. @import '../assets/css/font/iconfont.css';
  3359. @import '../assets/css/home.scss';
  3360. .ivu-input-number-controls-outside-btn i{
  3361. font-weight: 800;
  3362. }
  3363. .update-point{
  3364. display: inline-block;
  3365. width: 8px;
  3366. height: 8px;
  3367. border-radius: 8px;
  3368. background: #ff0000;
  3369. top: 14px;
  3370. position: absolute;
  3371. left: -13px;
  3372. }
  3373. .title-flex{
  3374. display: flex;
  3375. flex-wrap: nowrap;
  3376. justify-content: flex-start;
  3377. }
  3378. .demo-spin-icon-load{
  3379. animation: ani-demo-spin 1s linear infinite;
  3380. }
  3381. .line-density{
  3382. display: inline-block;
  3383. width: calc(100% - 74px);
  3384. }
  3385. .handle-item{
  3386. .handle-label{
  3387. width: 70px;
  3388. }
  3389. .ivu-input-number-handler-wrap{
  3390. opacity: 1;
  3391. }
  3392. }
  3393. .set-height{
  3394. height: 100%;
  3395. }
  3396. .merge-flex{
  3397. padding: 10px;
  3398. height: 100%;
  3399. display: flex;
  3400. flex-wrap: nowrap;
  3401. justify-content: flex-start;
  3402. .merge-content{
  3403. width: calc(100% - 140px);
  3404. height: 100%;
  3405. }
  3406. .merge-top{
  3407. overflow: hidden;
  3408. margin-bottom: 10px;
  3409. display: flex;
  3410. flex-wrap: nowrap;
  3411. justify-content: space-between;
  3412. }
  3413. .action-right{
  3414. width: 70px;
  3415. display: flex;
  3416. flex-wrap: nowrap;
  3417. justify-content: space-between;
  3418. line-height: 1;
  3419. cursor: pointer;
  3420. .action-ritem:hover{
  3421. color: #ce0000;
  3422. }
  3423. .iconfont{
  3424. font-size: 20px;
  3425. }
  3426. }
  3427. .merge-left{
  3428. width: 110px;
  3429. text-align: center;
  3430. height: 100%;
  3431. overflow-y: auto;
  3432. }
  3433. .img-area{
  3434. width: 90px;
  3435. height: 60px;
  3436. text-align: center;
  3437. line-height: 56px;
  3438. border: 1px solid #ddd;
  3439. }
  3440. .merge-scroll{
  3441. display: flex;
  3442. flex-wrap: nowrap;
  3443. overflow: hidden auto;
  3444. position: relative;
  3445. width: 130px;
  3446. flex-direction: column;
  3447. margin-right: 8px;
  3448. }
  3449. .merge-item{
  3450. width: 90px;
  3451. margin-bottom: 10px;
  3452. }
  3453. .merge-imgdel{
  3454. position: absolute;
  3455. right: -8px;
  3456. top: 0px;
  3457. font-size: 12px;
  3458. padding: 2px;
  3459. background-color: #ccc;
  3460. border-radius: 50%;
  3461. color: #fff;
  3462. cursor: pointer;
  3463. &:hover{
  3464. background-color: #ce0000;
  3465. }
  3466. }
  3467. .mergelist-img{
  3468. max-width: 100%;
  3469. max-height: 100%;
  3470. vertical-align: middle;
  3471. }
  3472. .merge-name{
  3473. overflow: hidden;
  3474. text-overflow:ellipsis;
  3475. white-space: nowrap;
  3476. margin-bottom: 5px;
  3477. }
  3478. .mer-title{
  3479. font-weight: 600;
  3480. margin-bottom: 10px;
  3481. }
  3482. }
  3483. ::-webkit-scrollbar {
  3484. /*滚动条整体样式*/
  3485. width: 6px; /*高宽分别对应横竖滚动条的尺寸*/
  3486. height: 6px;
  3487. }
  3488. ::-webkit-scrollbar-thumb {
  3489. /*滚动条里面小方块*/
  3490. border-radius: 10px;
  3491. box-shadow: inset 0 0 5px rgba(97, 184, 179, 0.1);
  3492. background: #666;
  3493. }
  3494. ::-webkit-scrollbar-track {
  3495. /*滚动条里面轨道*/
  3496. box-shadow: inset 0 0 5px rgba(87, 175, 187, 0.1);
  3497. border-radius: 10px;
  3498. background: #ededed;
  3499. }
  3500. .mlist-scroll{
  3501. overflow: auto;
  3502. background-color: #fff;
  3503. padding: 5px;
  3504. height: calc(100% - 45px);
  3505. &.bgmini{
  3506. background: url('../assets/image/bgmini.png');
  3507. }
  3508. .mlist-content{
  3509. width: 50%;
  3510. position: relative;
  3511. box-shadow: 2px 2px 6px #ddd, -2px -2px 6px #ddd;
  3512. margin: auto;
  3513. transform-origin: 50% 0;
  3514. }
  3515. .mlist-area{
  3516. position: absolute;
  3517. top: 0;
  3518. left: 0;
  3519. width: 100%;
  3520. height: 100%;
  3521. display: flex;
  3522. flex-wrap: nowrap;
  3523. flex-direction: column;
  3524. justify-content: space-between;
  3525. }
  3526. .merge-row{
  3527. display: flex;
  3528. flex-wrap: nowrap;
  3529. justify-content: space-between;
  3530. width: 100%;
  3531. }
  3532. .merge-col{
  3533. text-align: center;
  3534. overflow: hidden;
  3535. position: relative;
  3536. &:hover{
  3537. // border: 2px solid #2b83e0;
  3538. }
  3539. }
  3540. .merge-img{
  3541. position: absolute;
  3542. top: 0;
  3543. left: 0;
  3544. cursor:move;
  3545. }
  3546. .merge-img2{
  3547. max-width: 100%;
  3548. max-height: 100%;
  3549. vertical-align: middle;
  3550. position: absolute;
  3551. top: 0 !important;
  3552. left: 0 !important;
  3553. right: 0 !important;
  3554. bottom: 0 !important;
  3555. margin: auto;
  3556. }
  3557. .merge-add{
  3558. font-size: 50px;
  3559. border: 1px solid #ccc;
  3560. height: 100%;
  3561. background-color: #fafafa;
  3562. display: flex;
  3563. align-items: center;
  3564. justify-content: center;
  3565. cursor: pointer;
  3566. &:hover{
  3567. background-color: #f3f3f3;
  3568. }
  3569. }
  3570. }
  3571. .disnone{
  3572. display: none;
  3573. }
  3574. // 横图
  3575. .horizontal-scroll{
  3576. width: 80%;
  3577. margin: auto;
  3578. height: 250px;
  3579. margin-top: 10%;
  3580. box-shadow: 2px 2px 6px #ddd, -2px -2px 6px #ddd;
  3581. overflow: auto;
  3582. box-sizing: content-box;
  3583. }
  3584. .horizontal-content{
  3585. height: 100%;
  3586. display: flex;
  3587. flex-wrap: nowrap;
  3588. justify-content: flex-start;
  3589. .horizontal-item{
  3590. display: flex;
  3591. }
  3592. .horizontal-area{
  3593. display: inline-block;
  3594. height: 100%;
  3595. }
  3596. .horizontal-img{
  3597. height: 100%;
  3598. box-sizing: content-box;
  3599. flex-shrink: 0;
  3600. &:last-child{
  3601. margin-right: 0 !important;
  3602. }
  3603. }
  3604. }
  3605. // 竖图
  3606. .vertical-content{
  3607. width: 250px;
  3608. margin: auto;
  3609. box-shadow: 2px 2px 6px #ddd, -2px -2px 6px #ddd;
  3610. box-sizing: content-box;
  3611. .vertical-img{
  3612. width: 100%;
  3613. display: inherit;
  3614. &:last-child{
  3615. margin-bottom: 0 !important;
  3616. }
  3617. }
  3618. }
  3619. .i-fanzhuan{
  3620. font-size: 25px;
  3621. margin-right: 20px;
  3622. cursor: pointer;
  3623. &:hover,&.active{
  3624. color: #ce0000;
  3625. }
  3626. }
  3627. .flex-crop{
  3628. display: flex;
  3629. flex-wrap: wrap;
  3630. justify-content: space-between;
  3631. .crop-button{
  3632. width: 65px;
  3633. margin: 10px 0 !important;
  3634. }
  3635. }
  3636. .show-preview{
  3637. margin: auto;
  3638. }
  3639. .popper-open{
  3640. text-align: center !important;
  3641. padding: 10px !important;
  3642. background: #303133 !important;
  3643. color: #fff !important;
  3644. min-width: 120px !important;
  3645. opacity: 0.8;
  3646. }
  3647. .popper-open[x-placement^=bottom] .popper__arrow::after{
  3648. border-bottom-color: #303133 !important;
  3649. }
  3650. .el-aside,.el-menu{
  3651. border-right: none !important;
  3652. }
  3653. .vxebtn-del{
  3654. position: absolute !important;
  3655. right: 0;
  3656. top: 10px;
  3657. color: #F56C6C !important;
  3658. z-index: 2;
  3659. }
  3660. .m-image{
  3661. width: 25px;
  3662. margin-right: 5px;
  3663. }
  3664. .el-menu-item.is-active{
  3665. font-weight: 800;
  3666. font-size: 16px;
  3667. }
  3668. .el-menu-item:hover{
  3669. font-weight: 800;
  3670. font-size: 16px;
  3671. }
  3672. </style>