processImage.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717
  1. <template>
  2. <headerBar
  3. title="处理图像"
  4. showUser
  5. :menu="menu"
  6. />
  7. <hardware-check/>
  8. <ImagePreview
  9. :visible="previewVisible"
  10. :list="previewList"
  11. :initial-index="previewInitialIndex"
  12. @close="previewVisible = false"
  13. />
  14. <div class="photography-page flex-col bg-F5F6F7 ">
  15. <div class="main-container page—wrap max-w-full">
  16. <div class="history-section flex-col koutu-section">
  17. <div class="search-bar">
  18. <el-input
  19. v-model="searchGoodsArtNo"
  20. placeholder="搜索货号"
  21. clearable
  22. style="width: 300px"
  23. @keyup.enter="handleSearch"
  24. >
  25. <template #append>
  26. <el-button @click="handleSearch">搜索</el-button>
  27. </template>
  28. </el-input>
  29. </div>
  30. <div class="history-warp" ref="containerRef">
  31. <div v-if="!goodsList.length" class="fs-14 c-666 mar-top-50">
  32. {{ loading ? '数据正在加载中,请稍候...' : '暂无数据,请先进行拍摄'}}
  33. </div>
  34. <div v-else class="history-item" v-for="item in goodsList" :key="item.goods_art_no" >
  35. <div class="history-item-header">
  36. <div class="history-item-left">
  37. <el-checkbox
  38. :model-value="selectedGoods.has(item.goods_art_no)"
  39. @change="toggleGoods(item.goods_art_no)"
  40. class="goods-checkbox"
  41. />
  42. <span class="goods-art-no">{{ item.goods_art_no }}</span>
  43. <div class="history-item-meta ">
  44. <span class="action-time flex left">
  45. <img src="@/assets/images/processImage.vue/riq.png" />
  46. {{ getTime(item.action_time) }}</span>
  47. <span class="image-count mar-left-10 flex left">
  48. <img src="@/assets/images/processImage.vue/tup.png" />
  49. {{ item.items?.length || 0 }}张图片</span>
  50. </div>
  51. </div>
  52. <div class="history-item-right">
  53. <el-dropdown :disabled="runLoading || takePictureLoading" trigger="click">
  54. <el-button :disabled="runLoading || takePictureLoading" size="small" plain>高级生成</el-button>
  55. <template #dropdown>
  56. <el-dropdown-menu>
  57. <el-dropdown-item
  58. v-for="menu in generate.children"
  59. @click.native="onGenerateCLick(menu,item)">{{ menu.name }}</el-dropdown-item>
  60. </el-dropdown-menu>
  61. </template>
  62. </el-dropdown>
  63. <el-button style="color: #FF4C00" size="small" class="mar-left-10" :disabled="runLoading || takePictureLoading" @click="delGoods({goods_art_nos:[item.goods_art_no]})" v-log="{ describe: { action: '删除货号', goods_art_no: item.goods_art_no } }">删除</el-button>
  64. </div>
  65. </div>
  66. <div class="history-item-images" >
  67. <div
  68. v-for="(image, index) in item.items"
  69. :key="image.action_id || image.action_name"
  70. class="history-item_image"
  71. v-loading="!image.PhotoRecord.image_path && runAction.goods_art_no == item.goods_art_no"
  72. >
  73. <span class="tag" v-if="!image.PhotoRecord.image_path">{{ image.action_name }}</span>
  74. <el-image
  75. v-if="image.PhotoRecord.image_path"
  76. :src="thumbnailMap[image.PhotoRecord.image_path] || getFilePath(image.PhotoRecord.image_path)"
  77. class="preview-image"
  78. fit="contain"
  79. lazy
  80. @click="openPreview(item, index)"
  81. >
  82. <template #placeholder>
  83. <span class="tag">{{ image.action_name }}</span>
  84. </template>
  85. <template #error>
  86. <div class="image-slot">
  87. <span class="tag">{{ image.action_name }}</span>
  88. </div>
  89. </template>
  90. </el-image>
  91. <div v-else class="image-placeholder">
  92. <span class="tag">{{ image.action_name }}</span>
  93. </div>
  94. </div>
  95. </div>
  96. </div>
  97. </div>
  98. <div class="footer-controls">
  99. <div class="footer-left">
  100. <el-checkbox
  101. :model-value="isSelectAll"
  102. :indeterminate="isIndeterminate"
  103. @change="toggleSelectAll"
  104. class="select-all-checkbox"
  105. >
  106. 全选
  107. </el-checkbox>
  108. <span class="image-count-text">
  109. 已选择 <span style="color: #2957FF">{{ selectedImageCount }}</span> 张图片 共 <span style="color: #2957FF">{{ totalImageCount }}</span> 张图片
  110. </span>
  111. </div>
  112. <div class="footer-right">
  113. <el-pagination
  114. :page-count="totalPages"
  115. :current-page="currentPage"
  116. @current-change="(page) => getPhotoRecords({ page })"
  117. layout="prev, pager, next"
  118. :page-size="pageSize"
  119. />
  120. <el-button
  121. :disabled="selectedGoods.size === 0 || runLoading || takePictureLoading"
  122. @click="deleteSelected"
  123. v-log="{ describe: { action: '删除选中货号' } }"
  124. >
  125. 删除
  126. </el-button>
  127. <el-button
  128. :disabled="!goodsList.length || runLoading || takePictureLoading"
  129. @click="handleDeleteAll"
  130. style="color: #FF4C00"
  131. v-log="{ describe: { action: '删除所有货号' } }"
  132. >
  133. 删除所有
  134. </el-button>
  135. <el-button
  136. type="primary"
  137. :disabled="!goodsList.length || runLoading || takePictureLoading"
  138. @click="openPhotographyDetail()"
  139. v-log="{ describe: { action: '点击开始生成' } }"
  140. >
  141. <img src="@/assets/images/processImage.vue/sc.png" />
  142. 开始生成
  143. <img src="@/assets/images/processImage.vue/go.png" class="go"/>
  144. </el-button>
  145. </div>
  146. </div>
  147. </div>
  148. </div>
  149. </div>
  150. </template>
  151. <script setup lang="ts">
  152. import headerBar from '@/components/header-bar/index.vue'
  153. import { onMounted, onBeforeUnmount, ref, computed, nextTick, watch } from 'vue'
  154. import HardwareCheck from '@/components/check/index.vue'
  155. import usePhotography from './mixin/usePhotography'
  156. import { useThumbnails } from './composables/useThumbnails'
  157. import ImagePreview, { PreviewItem } from '@/components/PreviewImage/index.vue'
  158. import generate from '@/utils/menus/generate'
  159. import { ElMessageBox } from 'element-plus'
  160. import client from "@/stores/modules/client";
  161. import icpList from '@/utils/ipc'
  162. // logging helpers not needed here
  163. const clientStore = client();
  164. const {
  165. loading,
  166. runLoading,
  167. takePictureLoading,
  168. goodsList,
  169. runAction,
  170. menu,
  171. getTime,
  172. getFilePath,
  173. getPhotoRecords,
  174. delGoods,
  175. del,
  176. openPhotographyDetail,
  177. onGenerateCLick,
  178. initEventListeners,
  179. cleanupEventListeners,
  180. pageSize,
  181. currentPage,
  182. totalPages,
  183. importDirs,
  184. deleteAllGoods,
  185. searchGoodsArtNo,
  186. } = usePhotography()
  187. // 搜索货号
  188. const handleSearch = () => {
  189. getPhotoRecords({ page: 1, goods_art_no: searchGoodsArtNo.value })
  190. }
  191. // thumbnails
  192. const containerRef = ref<HTMLElement | null>(null)
  193. const { thumbnailMap, observe, stop } = useThumbnails(getFilePath)
  194. // router/client variables not needed here
  195. // 覆盖 openPhotographyDetail 方法,只传递选中的货号
  196. /*const openPhotographyDetail = () => {
  197. if (selectedGoods.value.size === 0) {
  198. ElMessage.error('请选择要生成的货号')
  199. return;
  200. }
  201. // 埋点:开始生成
  202. clickLog({ describe: { action: '开始生成', goods_count: selectedGoods.value.size, goods_art_nos: Array.from(selectedGoods.value) } }, route);
  203. console.log(Array.from(selectedGoods.value));
  204. console.log(selectedGoods.value);
  205. const { href } = Router.resolve({
  206. name: 'PhotographyDetail',
  207. query: {
  208. goods_art_nos: Array.from(selectedGoods.value),
  209. }
  210. })
  211. clientStore.ipc.removeAllListeners(icpList.utils.openMain);
  212. let params = {
  213. title: '主图与详情生成',
  214. width: 3840,
  215. height: 2160,
  216. frame: true,
  217. id: "PhotographyDetail",
  218. url: getRouterUrl(href)
  219. }
  220. clientStore.ipc.send(icpList.utils.openMain, params);
  221. }*/
  222. // 选中的货号列表
  223. const selectedGoods = ref<Set<string>>(new Set())
  224. // 全选状态
  225. const isSelectAll = computed(() => {
  226. return goodsList.value.length > 0 && selectedGoods.value.size === goodsList.value.length
  227. })
  228. // 是否半选状态
  229. const isIndeterminate = computed(() => {
  230. return selectedGoods.value.size > 0 && selectedGoods.value.size < goodsList.value.length
  231. })
  232. // 切换单个货号的选中状态
  233. const toggleGoods = (goodsArtNo: string) => {
  234. if (selectedGoods.value.has(goodsArtNo)) {
  235. selectedGoods.value.delete(goodsArtNo)
  236. } else {
  237. selectedGoods.value.add(goodsArtNo)
  238. }
  239. }
  240. // 全选/取消全选
  241. const toggleSelectAll = () => {
  242. if (isSelectAll.value) {
  243. selectedGoods.value.clear()
  244. } else {
  245. goodsList.value.forEach((item: any) => {
  246. selectedGoods.value.add(item.goods_art_no)
  247. })
  248. }
  249. }
  250. // 计算已选择的图片数量
  251. const selectedImageCount = computed(() => {
  252. let count = 0
  253. goodsList.value.forEach((item: any) => {
  254. if (selectedGoods.value.has(item.goods_art_no)) {
  255. count += item.items?.length || 0
  256. }
  257. })
  258. return count
  259. })
  260. // 计算总图片数量
  261. const totalImageCount = computed(() => {
  262. let count = 0
  263. goodsList.value.forEach((item: any) => {
  264. count += item.items?.length || 0
  265. })
  266. return count
  267. })
  268. // 删除选中的货号
  269. const deleteSelected = async () => {
  270. if (selectedGoods.value.size === 0) {
  271. return
  272. }
  273. try {
  274. await ElMessageBox.confirm(
  275. `确定要删除选中的 ${selectedGoods.value.size} 个货号的拍摄数据吗?`,
  276. '提示',
  277. {
  278. confirmButtonText: '确定',
  279. cancelButtonText: '取消',
  280. }
  281. )
  282. const goodsArtNos = Array.from(selectedGoods.value)
  283. await del({ goods_art_nos: goodsArtNos })
  284. // 删除成功后清空选中状态
  285. selectedGoods.value.clear()
  286. } catch (e) {
  287. // 用户取消
  288. }
  289. }
  290. // 获取预览图片列表(只包含有图片路径的,保持原始顺序),携带 action_name 用于大图预览展示
  291. const getPreviewImageList = (item: any): PreviewItem[] => {
  292. if (!item || !item.items) return []
  293. return item.items
  294. .filter((img: any) => img.PhotoRecord?.image_path)
  295. .map((img: any) => ({
  296. url: getFilePath(img.PhotoRecord.image_path),
  297. action_name: img.action_name,
  298. }))
  299. }
  300. // 获取当前图片在预览列表中的索引
  301. const getPreviewIndex = (item: any, currentIndex: number): number => {
  302. if (!item || !item.items) return 0
  303. // 计算当前图片在过滤后的预览列表中的索引
  304. let previewIndex = 0
  305. for (let i = 0; i <= currentIndex; i++) {
  306. if (item.items[i]?.PhotoRecord?.image_path) {
  307. if (i === currentIndex) break
  308. previewIndex++
  309. }
  310. }
  311. return previewIndex
  312. }
  313. // 大图预览状态
  314. const previewVisible = ref(false)
  315. const previewList = ref<PreviewItem[]>([])
  316. const previewInitialIndex = ref(0)
  317. // 打开大图预览
  318. const openPreview = (item: any, index: number) => {
  319. previewList.value = getPreviewImageList(item)
  320. previewInitialIndex.value = getPreviewIndex(item, index)
  321. previewVisible.value = true
  322. }
  323. // 打开目录选择器并导入图片
  324. const handleImportImage = () => {
  325. clientStore.ipc.removeAllListeners(icpList.utils.openDirectory);
  326. clientStore.ipc.send(icpList.utils.openDirectory);
  327. clientStore.ipc.on(icpList.utils.openDirectory, async (event, result) => {
  328. clientStore.ipc.removeAllListeners(icpList.utils.openDirectory);
  329. if (result) {
  330. importDirs(result);
  331. }
  332. });
  333. }
  334. // 删除所有货号
  335. const handleDeleteAll = async () => {
  336. try {
  337. await ElMessageBox.confirm(
  338. '确定要删除所有货号的拍摄数据吗?',
  339. '提示',
  340. {
  341. confirmButtonText: '确定',
  342. cancelButtonText: '取消',
  343. }
  344. )
  345. deleteAllGoods()
  346. } catch (e) {
  347. // 用户取消
  348. }
  349. }
  350. onMounted(async () => {
  351. await getPhotoRecords()
  352. initEventListeners()
  353. nextTick(() => {
  354. observe(containerRef, goodsList)
  355. })
  356. })
  357. onBeforeUnmount(() => {
  358. cleanupEventListeners()
  359. stop()
  360. })
  361. // 当 goodsList 变化时(翻页或刷新),重新挂载 observer
  362. watch(goodsList, () => {
  363. nextTick(() => {
  364. observe(containerRef, goodsList)
  365. })
  366. })
  367. </script>
  368. <style lang="scss">
  369. .koutu-image-popper {
  370. width: calc(100vw - 470px) !important;
  371. right: 70px !important;
  372. top: 100px !important;
  373. height: calc(100vh - 170px) !important;
  374. transform: translate(0px, 0px) !important;
  375. .el-image {
  376. width: 100%;
  377. height:100%;
  378. display: block;
  379. .el-image__inner {
  380. width: 100%;
  381. height:100%;
  382. display: block;
  383. }
  384. }
  385. }
  386. </style>
  387. <style scoped lang="scss">
  388. .photography-page {
  389. position: relative;
  390. .main-container {
  391. position: relative;
  392. display: flex;
  393. }
  394. }
  395. .history-section {
  396. width: 100%;
  397. min-height: calc(100vh - 30px);
  398. display: flex;
  399. flex-direction: column;
  400. padding: 20px;
  401. .search-bar {
  402. margin-bottom: 15px;
  403. display: flex;
  404. justify-content: flex-start;
  405. }
  406. ::v-deep {
  407. .el-checkbox__input {
  408. transform: scale(1.4);
  409. }
  410. }
  411. .history-warp {
  412. flex: 1;
  413. .history-item {
  414. background: #FFFFFF;
  415. box-shadow: 0px 2px 4px 0px rgba(23,33,71,0.1);
  416. border-radius: 10px;
  417. border: 1px solid #D9DEE6;
  418. margin-bottom: 20px;
  419. .history-item-header {
  420. display: flex;
  421. justify-content: space-between;
  422. align-items: center;
  423. height: 40px;
  424. padding: 0 10px;
  425. background: linear-gradient( 90deg, #F4ECFF 0%, #DFEDFF 100%);
  426. border-radius: 10px 10px 0px 0px;
  427. .history-item-left {
  428. display: flex;
  429. align-items: center;
  430. gap: 10px;
  431. .goods-checkbox {
  432. margin-right: 0;
  433. }
  434. .goods-art-no {
  435. font-size: 16px;
  436. font-weight: 500;
  437. color: #333;
  438. }
  439. }
  440. .history-item-right {
  441. display: flex;
  442. align-items: center;
  443. ::v-deep {
  444. .el-button { height: 30px; line-height: 30px;}
  445. }
  446. }
  447. }
  448. .history-item-meta {
  449. display: flex;
  450. justify-content: space-between;
  451. align-items: center;
  452. font-size: 12px;
  453. color: #666;
  454. img {
  455. height: 14px;
  456. margin-right: 2px;
  457. }
  458. .action-time {
  459. color: #666;
  460. }
  461. .image-count {
  462. color: #666;
  463. }
  464. }
  465. .history-item-images {
  466. display: grid;
  467. grid-template-columns: repeat(5, 1fr);
  468. gap: 10px;
  469. padding: 15px;
  470. border-top: 1px solid #f0f0f0;
  471. overflow-x: auto;
  472. // 如果图片数量超过5个,允许横向滚动
  473. @media (min-width: 1200px) {
  474. grid-template-columns: repeat(5, 1fr);
  475. }
  476. // 响应式:小屏幕时每行3个
  477. @media (max-width: 768px) {
  478. grid-template-columns: repeat(3, 1fr);
  479. }
  480. }
  481. .history-item_image_wrap {
  482. padding-bottom: 0;
  483. border-bottom: none;
  484. }
  485. .history-item_image {
  486. position: relative;
  487. width: 100%;
  488. aspect-ratio: 1;
  489. background: #F7F7F7;
  490. border-radius: 10px;
  491. overflow: hidden;
  492. cursor: pointer;
  493. border: 1px solid #D9DEE6;
  494. transition: all 0.3s;
  495. .tag {
  496. color: #bbb;
  497. position: absolute;
  498. left: 0;
  499. right: 0;
  500. top: 50%;
  501. margin-top: -10px;
  502. line-height: 20px;
  503. text-align: center;
  504. font-size: 12px;
  505. z-index: 1;
  506. pointer-events: none;
  507. }
  508. .preview-image {
  509. width: 100%;
  510. height: 100%;
  511. :deep(.el-image__inner) {
  512. width: 100%;
  513. height: 100%;
  514. object-fit: cover;
  515. }
  516. }
  517. .image-placeholder {
  518. width: 100%;
  519. height: 100%;
  520. display: flex;
  521. align-items: center;
  522. justify-content: center;
  523. background: #F7F7F7;
  524. }
  525. .image-slot {
  526. width: 100%;
  527. height: 100%;
  528. display: flex;
  529. align-items: center;
  530. justify-content: center;
  531. background: #F7F7F7;
  532. }
  533. &:hover {
  534. border-color: #409eff;
  535. transform: scale(1.02);
  536. box-shadow: 0 2px 8px rgba(64, 158, 255, 0.2);
  537. }
  538. &.el-loading-parent--relative{
  539. ::v-deep {
  540. .el-loading-mask { display: none}
  541. }
  542. }
  543. }
  544. .el-image_view {
  545. display: flex;
  546. width: 100%;
  547. height: 100%;
  548. .reset-button {
  549. width: 40px;
  550. text-align: center;
  551. height: 20px;
  552. position: absolute;
  553. left:50%;
  554. top:50%;
  555. padding: 0px;
  556. margin-left:-20px;
  557. margin-top:-10px;
  558. color: #ffffff;
  559. font-size: 14px;
  560. background: rgba(0,0,0,0.6);
  561. border-radius: 12px;
  562. display: none;
  563. cursor: pointer;
  564. }
  565. &:hover {
  566. .reset-button {
  567. display: block;
  568. }
  569. }
  570. }
  571. p:first-of-type {
  572. ::v-deep {
  573. .el-loading-mask { display: block !important;}
  574. }
  575. }
  576. }
  577. }
  578. .footer-controls {
  579. display: flex;
  580. justify-content: space-between;
  581. align-items: center;
  582. padding: 0px 20px;
  583. border-top: 1px solid #D9DEE6;
  584. background-color: #fff;
  585. min-height: 50px;
  586. flex-shrink: 0;
  587. position: fixed;
  588. bottom:0;
  589. left: 0;
  590. right: 0;
  591. font-size: 14px;
  592. z-index: 100;
  593. img {
  594. height: 12px;
  595. margin: 0 5px;
  596. }
  597. .go {
  598. height: 12px;
  599. opacity: .8;
  600. }
  601. ::v-deep {
  602. .el-button {
  603. border-radius: 10px;
  604. height: 40px;
  605. line-height: 40px;
  606. }
  607. }
  608. .footer-left {
  609. display: flex;
  610. align-items: center;
  611. gap: 10px;
  612. .select-all-checkbox {
  613. margin-right: 0;
  614. ::v-deep {
  615. .el-checkbox__label {
  616. font-size: 14px;
  617. color: #666;
  618. }
  619. }
  620. }
  621. .image-count-text {
  622. font-size: 14px;
  623. color: #333;
  624. margin-left: 0;
  625. }
  626. }
  627. .footer-right {
  628. display: flex;
  629. align-items: center;
  630. gap: 10px;
  631. }
  632. }
  633. }
  634. </style>