listItem.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561
  1. <template>
  2. <div class="listMain">
  3. <div style="margin: 0 0 1em 0">
  4. <el-button
  5. color="#840800"
  6. size="small"
  7. type="danger"
  8. :icon="Delete"
  9. @click="dialogVisible = true"
  10. >
  11. 删除全部
  12. </el-button>
  13. <!-- <el-button
  14. color="rgb(75,77,81)"
  15. size="small"
  16. :icon="Download"
  17. @click="zipconfig.show = true"
  18. >
  19. 下载图片
  20. </el-button> -->
  21. <div style="float: right">
  22. <!-- <el-button
  23. color="rgb(107,119,225)"
  24. size="small"
  25. :icon="Upload"
  26. ></el-button> -->
  27. <el-tooltip effect="dark" placement="bottom-start">
  28. <template #content>
  29. <div class="jin">
  30. <div class="bg" ref="jindutiao">
  31. <div class="jined" :style="'width:' + jindu / 2 + '%'">
  32. <div class="jinart"></div>
  33. </div>
  34. <div
  35. style="
  36. position: absolute;
  37. top: 0;
  38. right: 0;
  39. bottom: 0;
  40. left: 0;
  41. "
  42. @mousemove="mousemove"
  43. @mousedown="mousedown"
  44. @mouseout="mouseout"
  45. @mouseup="mouseup"
  46. ></div>
  47. </div>
  48. <div
  49. style="
  50. width: 3em;
  51. overflow: hidden;
  52. padding-left: 0.5em;
  53. border-radius: 3px;
  54. display: inline-block;
  55. "
  56. >
  57. <input
  58. type="number"
  59. v-model="jindu"
  60. @input="change"
  61. :max="200"
  62. />
  63. </div>
  64. %
  65. </div>
  66. </template>
  67. <el-button
  68. color="rgb(75,77,81)"
  69. size="small"
  70. :icon="Search"
  71. ></el-button>
  72. </el-tooltip>
  73. </div>
  74. </div>
  75. <p v-if="!downlist.length" style="margin: 1em 0">键入提示并按下“生成图片”按钮。</p>
  76. <p v-if="!downlist.length" style="margin: 1em 0">如果你想引导人工智能,你可以设置一个“初始图片”。</p>
  77. <p v-if="!downlist.length" style="margin: 1em 0">点击“图像设置”以设置生成的图像数量。</p>
  78. <p v-if="!downlist.length" >享受!:)</p>
  79. <!-- <el-empty
  80. description="请选择左侧选项进行生成图片哦"
  81. v-if="!downlist.length"
  82. >
  83. <template #image>
  84. <el-icon :size="50"><WarningFilled /></el-icon>
  85. </template>
  86. </el-empty> -->
  87. <div class="listItem" v-for="(item, index) in downlist" :key="index">
  88. <div class="listHead">
  89. <h4 style="font-size: 14pt">
  90. <el-icon><Grid /></el-icon>
  91. <div
  92. class="status"
  93. v-if="item.statusImg"
  94. v-text="item.statusImg"
  95. ></div>
  96. {{ item.prompt || '' }}
  97. <div class="btngroup" v-if="!item.statusImg">
  98. <el-button
  99. color="rgb(75,77,81)"
  100. size="small"
  101. :icon="Tools"
  102. @click="() => setConfig(item)"
  103. >
  104. 使用这些设置
  105. </el-button>
  106. <el-button
  107. color="#840800"
  108. size="small"
  109. type="danger"
  110. :icon="Delete"
  111. @click="() => removeItem(index + '')"
  112. >
  113. 删除
  114. </el-button>
  115. </div>
  116. </h4>
  117. <div style="margin: 0.5em 0">
  118. <img
  119. :src="item.init_image.fileResult"
  120. alt=""
  121. style="width: 50px; display: inline-block; vertical-align: middle"
  122. />
  123. <small v-if="item.list.length" style="font-size: 10pt; color: #aaa">
  124. 尺寸: {{ item.height }}x{{ item.width }}
  125. </small>
  126. </div>
  127. <div class="loading" v-if="item.statusImg"></div>
  128. <div class="imagelist">
  129. <div class="imgbg" v-for="(v, i) in item.list" :key="'son' + i">
  130. <el-icon
  131. @click="() => removeItem(index, i)"
  132. :size="30"
  133. class="close"
  134. ><CircleClose
  135. /></el-icon>
  136. <el-image
  137. :style="{ width: jindu / 2 + 'vh', height: jindu / 2 + 'vh' }"
  138. :src="v.image"
  139. :zoom-rate="1.2"
  140. :preview-src-list="getimgeList(item.list)"
  141. :initial-index="i"
  142. fit="cover"
  143. />
  144. <div v-if="item.list.length" class="baseText">
  145. {{ item.list[0].height }}x{{ item.list[0].width }}
  146. </div>
  147. <div class="topRight">
  148. <div
  149. style="
  150. display: inline-block;
  151. border-radius: 3px;
  152. padding: 2px;
  153. margin: 2px 0;
  154. background-color: #00000060;
  155. "
  156. >
  157. 种子:{{ v.seed }}
  158. </div>
  159. <div style="margin: 5px 0">
  160. <el-button
  161. color="#202225"
  162. size="small"
  163. @click="() => downimg(v.image)"
  164. >下载图片</el-button
  165. >
  166. <el-button
  167. color="#202225"
  168. size="small"
  169. @click="() => downjson(v)"
  170. >下载json</el-button
  171. >
  172. </div>
  173. <el-button
  174. color="#202225"
  175. size="small"
  176. @click="() => makeimg(item)"
  177. >
  178. 制作相似图片
  179. </el-button>
  180. </div>
  181. </div>
  182. </div>
  183. </div>
  184. </div>
  185. <el-dialog
  186. v-model="dialogVisible"
  187. class="dark"
  188. title="清除此窗口中的所有结果和任务?"
  189. width="30%"
  190. :center="true"
  191. >
  192. <template #footer>
  193. <span class="dialog-footer">
  194. <el-button @click="clearAll">是的</el-button>
  195. <el-button @click="dialogVisible = false"> 取消 </el-button>
  196. </span>
  197. </template>
  198. </el-dialog>
  199. <el-dialog class="dark" v-model="zipconfig.show" title="下载所有图片">
  200. <div class="zipconfig">
  201. <div class="zipitem">
  202. <div style="line-height: 40px">
  203. <el-icon :size="25"><Folder /></el-icon>
  204. </div>
  205. <div style="flex: 3; text-align: left">
  206. <div>下载为 ZIP 文件</div>
  207. <small style="font-size: 12px; color: #999999">
  208. 无需下载单个文件,而是生成一个包含所有图像的 zip 文件
  209. </small>
  210. </div>
  211. <div>
  212. <el-switch v-model="zipconfig.isZip" />
  213. </div>
  214. </div>
  215. <div
  216. class="zipitem"
  217. style="
  218. border-top: 1px solid #202225;
  219. border-bottom: 1px solid #202225;
  220. "
  221. >
  222. <div style="line-height: 40px">
  223. <el-icon style="background-color: #ffffff00" :size="25"
  224. ><Share
  225. /></el-icon>
  226. </div>
  227. <div style="flex: 3; text-align: left">
  228. <div>添加每个作业文件夹</div>
  229. <small style="font-size: 12px; color: #999999">
  230. 无需下载单个文件,而是生成一个包含所有图像的 zip 文件
  231. </small>
  232. </div>
  233. <div>
  234. <el-switch v-model="zipconfig.isZip" />
  235. </div>
  236. </div>
  237. <div class="zipitem">
  238. <div style="line-height: 40px">
  239. <el-icon style="background-color: #ffffff00" :size="25"
  240. ><Operation
  241. /></el-icon>
  242. </div>
  243. <div style="flex: 3; text-align: left">
  244. <div>添加元数据文件</div>
  245. <small style="font-size: 12px; color: #999999">
  246. 对于每个映像,还要下载一个 JSON
  247. 文件,其中包含用于生成映像的所有设置
  248. </small>
  249. </div>
  250. <div>
  251. <el-switch v-model="zipconfig.isZip" />
  252. </div>
  253. </div>
  254. </div>
  255. <el-button
  256. type="primary"
  257. size="small"
  258. style="display: block; margin: 0 auto"
  259. >
  260. 开始下载
  261. </el-button>
  262. </el-dialog>
  263. </div>
  264. </template>
  265. <script setup>
  266. import { Delete, Tools, Search } from '@element-plus/icons-vue';
  267. import { ref, defineProps, defineEmits } from 'vue';
  268. const jindutiao = ref(null);
  269. const dialogVisible = ref(false);
  270. const jindu = ref(50);
  271. const emit = defineEmits(['removeItem', 'setconfig', 'makeimg']);
  272. const props = defineProps({
  273. downlist: Array,
  274. });
  275. const change = e => {
  276. if (e.target.value > 200) {
  277. jindu.value = 200;
  278. return;
  279. }
  280. if (e.target.value < 10) {
  281. jindu.value = 10;
  282. return;
  283. }
  284. };
  285. const zipconfig = ref({
  286. isZip: true,
  287. iswenjian: true,
  288. isjson: true,
  289. show: false,
  290. });
  291. const setConfig = item => {
  292. emit('setconfig', item);
  293. };
  294. const getimgeList = list => {
  295. return list.map(v => v.image);
  296. };
  297. const removeItem = (i, index) => {
  298. let t = i;
  299. index !== undefined && (t += '-' + index);
  300. emit('removeItem', t);
  301. };
  302. let isdown = false;
  303. const mousemove = e => {
  304. if (!isdown) return;
  305. let m = Math.ceil((e.offsetX / jindutiao.value.clientWidth) * 200);
  306. m < 10 && (m = 10);
  307. jindu.value = m;
  308. };
  309. const mousedown = () => {
  310. isdown = true;
  311. };
  312. const mouseup = () => {
  313. isdown = false;
  314. };
  315. const mouseout = () => {
  316. isdown = false;
  317. };
  318. const clearAll = () => {
  319. dialogVisible.value = false;
  320. for (let i = 0; i < props.downlist.length; i++) {
  321. emit('removeItem', i + '');
  322. }
  323. };
  324. const downimg = base => {
  325. let base64 = base; // imgSrc 就是base64哈
  326. let byteCharacters = atob(
  327. base64.replace(/^data:image\/(png|jpeg|jpg);base64,/, '')
  328. );
  329. let byteNumbers = new Array(byteCharacters.length);
  330. for (let i = 0; i < byteCharacters.length; i++) {
  331. byteNumbers[i] = byteCharacters.charCodeAt(i);
  332. }
  333. let byteArray = new Uint8Array(byteNumbers);
  334. let blob = new Blob([byteArray], {
  335. type: undefined,
  336. });
  337. let aLink = document.createElement('a');
  338. aLink.download = Date.now() + '.jpg'; //这里写保存时的图片名称
  339. aLink.href = URL.createObjectURL(blob);
  340. aLink.click();
  341. };
  342. const downjson = item => {
  343. const data = JSON.parse(JSON.stringify(item));
  344. delete data.image;
  345. const fileText = JSON.stringify(data, undefined, 4);
  346. let blob = new Blob([fileText], { type: 'text/json' });
  347. let e = document.createEvent('MouseEvents');
  348. let a = document.createElement('a');
  349. a.download = Date.now() + '.json';
  350. a.href = window.URL.createObjectURL(blob);
  351. a.dataset.downloadurl = ['text/json', a.download, a.href].join(':');
  352. e.initMouseEvent(
  353. 'click',
  354. true,
  355. false,
  356. window,
  357. 0,
  358. 0,
  359. 0,
  360. 0,
  361. 0,
  362. false,
  363. false,
  364. false,
  365. false,
  366. 0,
  367. null
  368. );
  369. a.dispatchEvent(e);
  370. };
  371. const makeimg = item => {
  372. emit('makeimg', item);
  373. };
  374. </script>
  375. <style scoped>
  376. .listMain {
  377. padding: 1em 0;
  378. }
  379. .listItem {
  380. border: 1px solid var(--background-color2);
  381. margin-bottom: 10pt;
  382. padding: 5pt;
  383. border-radius: 5pt;
  384. box-shadow: 0 20px 28px 0 rgba(0, 0, 0, 0.15),
  385. 0 6px 20px 0 rgba(0, 0, 0, 0.15);
  386. }
  387. .listHead {
  388. line-height: 1.5em;
  389. }
  390. .btngroup {
  391. float: right;
  392. }
  393. .jin {
  394. height: 1.5em;
  395. width: 15em;
  396. }
  397. .jin .bg {
  398. display: inline-block;
  399. margin-top: 0.5em;
  400. border-radius: 2em;
  401. width: 10em;
  402. height: 0.6em;
  403. background-color: #fff;
  404. position: relative;
  405. }
  406. .jined {
  407. border-radius: 2em;
  408. height: 0.6em;
  409. background-color: #0011cc;
  410. }
  411. .jinart {
  412. background-color: #0011cc;
  413. margin-top: -0.3em;
  414. border-radius: 50%;
  415. width: 1.2em;
  416. height: 1.2em;
  417. float: right;
  418. }
  419. input {
  420. background-color: #202225;
  421. outline: none;
  422. border: none;
  423. height: 1.5em;
  424. width: 4em;
  425. color: #fff;
  426. }
  427. .imgbg {
  428. position: relative;
  429. display: inline-block;
  430. margin-right: 20px;
  431. margin-bottom: 5px;
  432. }
  433. .close {
  434. display: none;
  435. position: absolute;
  436. right: -15px;
  437. top: -15px;
  438. z-index: 1;
  439. background-color: #202225;
  440. border-radius: 50%;
  441. }
  442. .imagelist {
  443. padding: 0 1em;
  444. }
  445. .baseText {
  446. display: none;
  447. position: absolute;
  448. right: 0;
  449. bottom: 0;
  450. background-color: #00000060;
  451. font-size: 12px;
  452. padding: 2px;
  453. text-shadow: 0px 0px 4px black;
  454. }
  455. .topRight {
  456. display: none;
  457. position: absolute;
  458. right: 0;
  459. top: 0;
  460. font-size: 12px;
  461. padding: 2px;
  462. text-shadow: 0px 0px 4px black;
  463. padding: 3px;
  464. text-align: right;
  465. }
  466. .imgbg:hover .topRight,
  467. .imgbg:hover .close,
  468. .imgbg:hover .baseText {
  469. display: block;
  470. }
  471. .zipconfig {
  472. border-radius: 12px;
  473. font-size: 14px;
  474. color: #eee;
  475. overflow: hidden;
  476. }
  477. .zipitem {
  478. line-height: 1.5em;
  479. background: #2f3136;
  480. padding: 0 1.5em;
  481. display: flex;
  482. }
  483. .zipitem > div {
  484. flex: 1;
  485. background: #ffffff00;
  486. padding: 5px 0;
  487. text-align: center;
  488. }
  489. .zipitem > div * {
  490. background: #ffffff00;
  491. }
  492. .loading {
  493. background: repeating-linear-gradient(
  494. -65deg,
  495. #2f3136,
  496. #2f3136 4px,
  497. #292b2f 5px,
  498. #292b2f 9px,
  499. #2f3136 10px
  500. );
  501. background-size: 200% auto;
  502. background-position: 0 100%;
  503. animation: progress-anim 40s infinite;
  504. animation-fill-mode: forwards;
  505. animation-timing-function: linear;
  506. height: 1em;
  507. border-radius: 3px;
  508. margin: 5px 0;
  509. }
  510. @keyframes progress-anim {
  511. 100% {
  512. background-position: -100% 0;
  513. }
  514. }
  515. .status {
  516. background: #805900;
  517. border: 1px solid #6b4b00;
  518. color: #fff2d3;
  519. display: inline-block;
  520. padding: 3px 5px;
  521. font-size: 14px;
  522. border-radius: 5px;
  523. }
  524. </style>
  525. <style scoped>
  526. .el-input__inner{
  527. color: #ffffff!important;
  528. }
  529. </style>