detail.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724
  1. <template>
  2. <headerBar title="主图与详情生成" :menu="[
  3. {
  4. type: 'setting'
  5. }
  6. ]" />
  7. <div class="detail-container">
  8. <div>
  9. <!-- 主图LOGO部分 -->
  10. <div class="logo-section flex left top">
  11. <div class="section-title">
  12. <img src="@/assets/images/Photography/zhuangshi.png" style="width: 32px; height: 32px;" />
  13. 主图LOGO:
  14. </div>
  15. <upload :value="form.logo_path" @input="onInput"></upload>
  16. </div>
  17. <el-divider />
  18. <!-- 图片抠图与货号图生成 -->
  19. <div class="section">
  20. <div class="section-title">
  21. <img src="@/assets/images/Photography/zhuangshi.png" style="width: 32px; height: 32px;" />
  22. 图片抠图与货号图生成
  23. </div>
  24. <div class="section-content">
  25. <div v-if="showTips" class="instruction-out flex top left">
  26. <img style="fill: #000" src="@/assets/images/xinxi.svg" />
  27. <ol class="instruction-list">
  28. <li>请在下方确认图片拍摄过程中的顺序,确保所有拍摄的图片的顺序一致。</li>
  29. <li>使用中英文语号分隔。</li>
  30. <li>图片的名称不能随意修改,否则无法正常生成详情页。</li>
  31. <li>现有图片名称有:俯视、侧视、后视、鞋底、内里</li>
  32. </ol>
  33. <el-icon @click="showTips = false" class="close-icon">
  34. <Close />
  35. </el-icon>
  36. </div>
  37. <!-- 货号文件夹 -->
  38. <!-- <div class="form-item">
  39. <div class="label">货号文件夹:</div>
  40. <div class="folder-warp">
  41. <div class="folder-input">
  42. <el-input style="width: 60%;" v-model="folderPath" type="textarea" :rows="2" readonly
  43. placeholder="请选择货号文件夹" />
  44. <el-button class="check-button" type="primary" @click="selectFolder">
  45. <img src="@/assets/images/Photography/wenjian.png" style="width: 14px; " />
  46. 选择目标文件夹</el-button>
  47. </div>
  48. <div class="hint">
  49. <el-icon>
  50. <Warning />
  51. </el-icon> <text>选择货号的上级文件夹</text>
  52. </div>
  53. </div>
  54. </div>
  55. -->
  56. </div>
  57. </div>
  58. <el-divider />
  59. <!-- 选择详情模板部分 -->
  60. <div class="template-section ">
  61. <div class="flex between">
  62. <div class="section-title">
  63. <img src="@/assets/images/Photography/zhuangshi.png" style="width: 32px; height: 32px;" />
  64. 选择详情模版
  65. </div>
  66. <div class="template-pagination">
  67. <el-pagination background layout="prev, pager, next" v-model:current-page="queryParams.current"
  68. v-model:page-size.sync="queryParams.size" :total="totalPage" @current-change="onCurrentChange"
  69. @size-change="onSizeChange" />
  70. </div>
  71. </div>
  72. <div class="template-list">
  73. <div v-for="(template, index) in visibleTemplates" :key="index" class="template-item"
  74. @click="form.selectTemplate = template">
  75. <el-image :src="template.template_cover_image" fit="contain" class="cur-p"
  76. style="width: 100%; display: block;" />
  77. <div class="select-warp" :class="form.selectTemplate.id == template.id ? 'active' : ''">
  78. <el-icon color="#FFFFFF">
  79. <Select />
  80. </el-icon>
  81. </div>
  82. <div class="template-info">
  83. <span class="mar-left-10 chaochu_1">{{ template.template_name }}</span>
  84. <div class="template-view" @click="viewTemplate(template)">查看</div>
  85. </div>
  86. </div>
  87. </div>
  88. </div>
  89. <el-divider />
  90. <!-- 详情高级配置 -->
  91. <div class="section">
  92. <div class="section-title">
  93. <img src="@/assets/images/Photography/zhuangshi.png" style="width: 32px; height: 32px;" />
  94. 详情高级配置
  95. </div>
  96. <div class="section-content">
  97. <!-- 图片顺序 -->
  98. <div class="form-item">
  99. <div class="label">图片顺序:</div>
  100. <el-input v-model="imageOrder" placeholder="请输入图片顺序" class="specific-page-input">
  101. <template #append>
  102. <el-button class="explain-btn" link type="primary">说明</el-button>
  103. </template>
  104. </el-input>
  105. </div>
  106. <!-- 同款检验 -->
  107. <!-- <div class="form-item">
  108. <div class="label">同款检验:</div>
  109. <el-checkbox v-model="checkSimilar">同款下货号必须齐全</el-checkbox>
  110. </div>
  111. -->
  112. <!-- 可指定页面独修改 -->
  113. <!-- <div class="form-item">
  114. <div class="label">可指定页面独修改:</div>
  115. <el-input v-model="specificPage" placeholder="请输入入需要单独修改的页面,示例:4:1 (需修改模版的编号:第一张)"
  116. class="specific-page-input">
  117. <template #append>
  118. <el-button class="explain-btn" link type="primary">说明</el-button>
  119. </template>
  120. </el-input>
  121. </div>
  122. -->
  123. </div>
  124. </div>
  125. <el-divider />
  126. <!-- 详情资料准备部分 -->
  127. <div class="data-prep-section">
  128. <div class="flex-item left">
  129. <div class="section-title">
  130. <img src="@/assets/images/Photography/zhuangshi.png" style="width: 32px; height: 32px;" />
  131. 详情资料准备 (2选1)
  132. </div>
  133. </div>
  134. <div class="flex-item left">
  135. <el-radio-group v-model="form.dataType" class="ml-4">
  136. <el-radio label="1" size="large">EXCEL文件选择</el-radio>
  137. <el-radio label="2" size="large">系统对接(和业务员联系)</el-radio>
  138. </el-radio-group>
  139. </div>
  140. <div v-if="form.dataType == '1'" class="excel-upload">
  141. <div class="flex bottom between">
  142. <div style="max-width: 160px;" class="mar-left-20">商品基础资料EXCEL文件选择:</div>
  143. <div class="flex bottom mar-left-20" style="flex-grow: 1;">
  144. <el-input type="textarea" v-model="form.excelFilePath" />
  145. </div>
  146. <el-button class="select-button button--primary1 mar-left-20" type="primary" @click="selectExcel">
  147. <img src="@/assets/images/Photography/wenjian.png" style="width: 16px; margin-right: 4px;" />
  148. 选择</el-button>
  149. </div>
  150. </div>
  151. </div>
  152. </div>
  153. <!-- 底部按钮 -->
  154. <div class="footer">
  155. <!-- <el-button class="button--primary1 footer-button" type="primary" @click="saveConfig">保存配置</el-button> -->
  156. <!-- <el-button class="button--primary1 footer-button" type="primary" @click="startProcess">开始处理</el-button> -->
  157. <el-button class="button--primary1 footer-button" type="primary" @click="generate">开始生成</el-button>
  158. </div>
  159. </div>
  160. <loading-dialog v-model="loadingDialogVisible" :progress="progress" :message="message" :show-button="showButton"
  161. @button-click="handleComplete">
  162. <template v-if="partErrList && partErrList.length > 0" #errList>
  163. <div v-for="(item, idx) in partErrList" :key="idx">
  164. <span>{{ item.goods_art_no }}</span>:<span>{{ item.info }}</span>
  165. </div>
  166. </template>
  167. </loading-dialog>
  168. <el-dialog v-model="dialogVisible">
  169. <img style="width: 100%;" :src="dialogImageUrl" alt="Preview Image" />
  170. </el-dialog>
  171. </template>
  172. <script lang="ts" setup>
  173. import { getCompanyTemplatesApi } from '@/apis/other'
  174. import tokenInfo from '@/stores/modules/token';
  175. import useUserInfo from "@/stores/modules/user";
  176. import { useRoute, useRouter } from 'vue-router'
  177. import { ElMessage, ElMessageBox } from 'element-plus'
  178. import headerBar from '@/components/header-bar/index.vue'
  179. import { ref, computed, reactive, onMounted } from 'vue';
  180. import { Select } from '@element-plus/icons-vue'
  181. import upload from '@/components/upload'
  182. import client from "@/stores/modules/client";
  183. import icpList from '@/utils/ipc'
  184. const clientStore = client();
  185. import { getRouterUrl } from '@/utils/appfun'
  186. import { Close, Warning } from '@element-plus/icons-vue'
  187. import LoadingDialog from '@/views/Photography/components/LoadingDialog.vue'
  188. import { useCheckInfo } from '@/composables/useCheckInfo';
  189. useCheckInfo();
  190. const showTips = ref(true)
  191. const folderPath = ref('') //货号文件夹
  192. // const reportMode = ref('normal') // 抠图模式
  193. const imageOrder = ref('俯视、侧视、后跟、鞋底、内里、组合、组合2、组合3') // 图片顺序
  194. const checkSimilar = ref(false) // 同款检验
  195. const specificPage = ref('') // 可指定页面独修改
  196. // 路由和状态管理初始化
  197. const route = useRoute();
  198. const router = useRouter();
  199. // 完成目录
  200. const completeDirectory = ref('')
  201. const loadingDialogVisible = ref(false)
  202. const progress = ref(0)
  203. const message = ref('正在为您处理,请稍后')
  204. const showButton = ref(true)
  205. let templates = ref([])
  206. let goods_art_nos = ref([])
  207. let partErrList = ref([])
  208. // 定义一个定时器变量
  209. const INTERVAL = ref<number | NodeJS.Timeout | null>(null);
  210. // 状态变量
  211. const totalPage = ref(0);
  212. const itemsPerPage = 4; // 每页显示的模板数量
  213. const dialogVisible = ref(false);
  214. const dialogImageUrl = ref('');
  215. const queryParams = reactive({ // 分页查询参数
  216. size: 1,
  217. current: 1,
  218. })
  219. const form = reactive({
  220. selectTemplate: {}, //选中的模板
  221. dataType: '1', // 1: 选择excel文件 2: 系统对接
  222. logo_path: '', // 主图LOGO
  223. excelFilePath: 'D:\\MyDocuments\\PythonCode\\MyPython\\red_dragonfly\\deal_pics\\auto_capture_V2\\auto_photo', // 商品基础资料EXCEL文件选择
  224. })
  225. onMounted(() => {
  226. const goods_art_data = route.query.goods_art_nos
  227. goods_art_nos.value = Array.isArray(goods_art_data) ? goods_art_data : [goods_art_data]
  228. getCompanyTemplates()
  229. })
  230. // 计算属性,获取当前页可见的模板
  231. const visibleTemplates = computed(() => {
  232. const startIndex = (queryParams.current - 1) * itemsPerPage;
  233. const data = templates.value.slice(startIndex, startIndex + itemsPerPage);
  234. return data
  235. });
  236. // 查看模板详情
  237. const viewTemplate = (template) => {
  238. // 展示大图
  239. dialogVisible.value = true
  240. dialogImageUrl.value = template.template_preview_image
  241. };
  242. // 获取模版列表
  243. const getCompanyTemplates = async () => {
  244. const { data } = await getCompanyTemplatesApi()
  245. templates.value = data.list
  246. // 默认选中第一个模板
  247. if (templates.value.length > 0) {
  248. form.selectTemplate = templates.value[0]
  249. }
  250. // 计算总页数
  251. totalPage.value = Math.ceil(templates.value.length / itemsPerPage);
  252. }
  253. const onCurrentChange = (page) => {
  254. queryParams.current = page;
  255. };
  256. const onSizeChange = (data) => {
  257. };
  258. // 开始生成操作
  259. const generate = async function () {
  260. const tokenInfoStore = tokenInfo();
  261. const token = tokenInfoStore.getToken; // 使用 getToken() 获取 token
  262. let temp_list = []
  263. templates.value.map(item => {
  264. temp_list.push({
  265. template_id: item.template_id,
  266. template_local_classes: item.template_local_classes,
  267. })
  268. })
  269. const params = {
  270. goods_art_no: JSON.parse(JSON.stringify(goods_art_nos.value)),
  271. logo_path: form.logo_path,
  272. temp_name: form.selectTemplate.template_id,
  273. excel_path: '',
  274. template_image_order: form.selectTemplate.template_image_order,
  275. temp_list,
  276. token,
  277. }
  278. // 开启进度弹窗
  279. progress.value = 0
  280. openLoadingDialog(20)
  281. console.log("%c Line:324 🍆 params", "color:#3f7cff", params);
  282. clientStore.ipc.removeAllListeners(icpList.generate.generatePhotoDetail);
  283. clientStore.ipc.send(icpList.generate.generatePhotoDetail, params);
  284. clientStore.ipc.on(icpList.generate.generatePhotoDetail, (event, result) => {
  285. console.log('result', result)
  286. partErrList.value = []
  287. clientStore.ipc.removeAllListeners(icpList.generate.generatePhotoDetail);
  288. clearInterval(INTERVAL.value)
  289. if (result.code === 0) {
  290. const { output_folder, list } = result.data
  291. // 若out_put_dir为空,说明全部生成失败,走失败处理
  292. if (output_folder === '') {
  293. console.log('全部生成失败')
  294. handleFail('生成失败! 请联系管理员处理, 或稍后重试')
  295. } else {
  296. // 判断 result.data.list 中 是否存在 success 为fals的 若存在 则走部分成功处理 否则走全部成功处理
  297. let hasFail = false
  298. list.map(item => {
  299. if (!item.success) {
  300. hasFail = true
  301. }
  302. })
  303. // 部分成功
  304. if (hasFail) {
  305. console.log('部分成功')
  306. handlePartSuccess(output_folder, list)
  307. } else { // 全部成功
  308. console.log('全部成功')
  309. handleSuccess(output_folder, '全部生成成功')
  310. }
  311. }
  312. } else {
  313. console.log('code全部生成失败')
  314. handleFail(result.msg)
  315. }
  316. //生成失败
  317. function handleFail(errorMsg: string) {
  318. loadingDialogVisible.value = false
  319. showButton.value = false
  320. if (errorMsg) {
  321. ElMessage.error(errorMsg)
  322. }
  323. }
  324. // 部分成功
  325. function handlePartSuccess(output_folder: string, partSuccessList) {
  326. // 错误list展示 失败的货号整理成字符串,用逗号分隔
  327. let errorList = []
  328. partSuccessList.map(item => {
  329. if (!item.success) {
  330. errorList.push(item)
  331. }
  332. })
  333. console.log("%c Line:376 🍖 errorList", "color:#2eafb0", errorList);
  334. partErrList.value = errorList
  335. handleSuccess(output_folder, '部分货号生成失败',)
  336. }
  337. // 全部生成成功
  338. function handleSuccess(href, loadingMsg) {
  339. completeDirectory.value = href
  340. progress.value = 100
  341. showButton.value = false
  342. message.value = loadingMsg
  343. }
  344. });
  345. }
  346. const openLoadingDialog = (timer: number) => {
  347. loadingDialogVisible.value = true
  348. showButton.value = true
  349. // 根据传入的秒数计算每次增加的进度值
  350. const step = 100 / timer
  351. INTERVAL.value = setInterval(() => {
  352. if (progress.value < 100) {
  353. progress.value = Math.round(progress.value + step)
  354. }
  355. }, 1000)
  356. }
  357. const onInput = (value) => {
  358. form.logo_path = value
  359. }
  360. function selectExcel() {
  361. clientStore.ipc.removeAllListeners(icpList.utils.openFile);
  362. clientStore.ipc.send(icpList.utils.openFile, {
  363. filters: [
  364. { name: '支持xls,xlsx', extensions: ['xlsx', 'xls'] }
  365. ],
  366. title: "选择基础文件资料"
  367. });
  368. clientStore.ipc.on(icpList.utils.openFile, async (event, result) => {
  369. form.excelFilePath = result
  370. clientStore.ipc.removeAllListeners(icpList.utils.openFile);
  371. })
  372. }
  373. const Router = useRouter()
  374. //打开主图详情
  375. function openPhotographySeniorDetail() {
  376. const { href } = Router.resolve({
  377. name: 'PhotographySeniorDetail'
  378. })
  379. clientStore.ipc.removeAllListeners(icpList.utils.openMain);
  380. let params = {
  381. title: '详情高级配置',
  382. width: 1000,
  383. height: 630,
  384. frame: true,
  385. id: "PhotographySeniorDetail",
  386. url: getRouterUrl(href)
  387. }
  388. clientStore.ipc.send(icpList.utils.openMain, params);
  389. }
  390. const handleComplete = () => {
  391. loadingDialogVisible.value = false
  392. // 这里可以添加打开目录的逻辑
  393. clientStore.ipc.removeAllListeners(icpList.utils.openDirectory);
  394. clientStore.ipc.removeAllListeners(icpList.utils.shellFun);
  395. let params = {
  396. action: 'openPath',
  397. params: completeDirectory.value
  398. }
  399. clientStore.ipc.send(icpList.utils.shellFun, params);
  400. }
  401. const selectFolder = () => {
  402. clientStore.ipc.removeAllListeners(icpList.utils.openDirectory);
  403. clientStore.ipc.send(icpList.utils.openDirectory);
  404. clientStore.ipc.on(icpList.utils.openDirectory, async (event, result) => {
  405. folderPath.value = result
  406. clientStore.ipc.removeAllListeners(icpList.utils.openDirectory);
  407. })
  408. }
  409. </script>
  410. <style lang="scss" scoped>
  411. .detail-container {
  412. background-color: #EAECED;
  413. width: 100%;
  414. min-width: 600px;
  415. padding: 20px;
  416. overflow: hidden;
  417. }
  418. .logo-section,
  419. .template-section,
  420. .data-prep-section {
  421. margin-bottom: 20px;
  422. }
  423. .logo-upload {
  424. border: 1px dashed #ccc;
  425. border-radius: 5px;
  426. padding: 50px 0;
  427. text-align: center;
  428. cursor: pointer;
  429. }
  430. .template-pagination button {
  431. margin-right: 5px;
  432. }
  433. .template-pagination span {
  434. display: inline-block;
  435. width: 20px;
  436. height: 20px;
  437. line-height: 20px;
  438. text-align: center;
  439. border: 1px solid #ccc;
  440. border-radius: 5px;
  441. margin-right: 5px;
  442. cursor: pointer;
  443. }
  444. .template-list {
  445. display: flex;
  446. flex-wrap: wrap;
  447. gap: 20px;
  448. margin-top: 10px;
  449. .template-item {
  450. width: calc(25% - 18px);
  451. border: 1px solid #ccc;
  452. border-radius: 10px;
  453. cursor: pointer;
  454. background: #f0f0f0;
  455. position: relative;
  456. overflow: hidden;
  457. .template-info {
  458. position: absolute;
  459. bottom: 0;
  460. left: 0;
  461. background: rgba($color: #000000, $alpha: .3);
  462. width: 100%;
  463. height: 36px;
  464. line-height: 36px;
  465. color: #eee;
  466. display: flex;
  467. align-items: center;
  468. justify-content: space-between;
  469. .template-view {
  470. background: #DFE2E3;
  471. color: #3366FF;
  472. height: 30px;
  473. line-height: 30px;
  474. padding: 0 10px;
  475. border-radius: 4px;
  476. margin-right: 10px;
  477. font-size: 14px;
  478. }
  479. }
  480. }
  481. }
  482. .excel-upload {
  483. width: 100%;
  484. background: #F7F7F7;
  485. padding: 20px 0;
  486. }
  487. .generate-button {
  488. padding: 10px 20px;
  489. color: white;
  490. border: none;
  491. border-radius: 5px;
  492. cursor: pointer;
  493. }
  494. .select-button {
  495. background: #DFE2E3 !important;
  496. color: #3366FF !important;
  497. height: 30px;
  498. line-height: 30px;
  499. padding: 0 10px;
  500. border-radius: 4px;
  501. margin-right: 10px;
  502. font-size: 14px;
  503. font-weight: 550;
  504. }
  505. .select-warp {
  506. width: 18px;
  507. height: 18px;
  508. border-radius: 4px;
  509. background-color: #fff;
  510. position: absolute;
  511. top: 10px;
  512. left: 10px;
  513. &.active {
  514. background-color: #1677FF;
  515. }
  516. }
  517. .section-title {
  518. display: flex;
  519. align-items: center;
  520. gap: 8px;
  521. font-weight: bold;
  522. margin-bottom: 16px;
  523. color: #474747;
  524. }
  525. .section {
  526. margin-bottom: 24px;
  527. .section-title {
  528. display: flex;
  529. align-items: center;
  530. gap: 8px;
  531. font-weight: bold;
  532. margin-bottom: 16px;
  533. color: #474747;
  534. }
  535. .section-content {
  536. padding-left: 16px;
  537. }
  538. }
  539. .instruction-out {
  540. background: #EAF3FF;
  541. border-radius: 4px;
  542. border: 1px solid #CBE1FF;
  543. padding: 10px 20px;
  544. width: 80%;
  545. position: relative;
  546. .instruction-list {
  547. margin: 0px 0 0 10px;
  548. padding-left: 20px;
  549. padding-right: 40px;
  550. width: 100%;
  551. li {
  552. margin-bottom: 4px;
  553. text-align: left;
  554. font-size: 14px;
  555. }
  556. }
  557. .close-icon {
  558. position: absolute;
  559. top: 12px;
  560. right: 19px;
  561. }
  562. }
  563. .form-item {
  564. margin: 16px 0;
  565. display: flex;
  566. .label {
  567. min-width: 120px;
  568. margin-right: 12px;
  569. }
  570. .folder-warp {
  571. width: 100%;
  572. display: flex;
  573. flex-direction: column;
  574. .folder-input {
  575. flex: 1;
  576. display: flex;
  577. align-items: center;
  578. .check-button {
  579. background: #DFE2E3;
  580. border-radius: 6px;
  581. padding: 6px 12px;
  582. color: #2957FF;
  583. margin-left: 20px;
  584. }
  585. }
  586. }
  587. .hint {
  588. text-align: left;
  589. color: #999;
  590. margin-top: 6px;
  591. font-size: 14px;
  592. color: #FF4C00;
  593. font-style: normal;
  594. }
  595. .specific-page-input {
  596. flex: 1;
  597. }
  598. }
  599. .image-order {
  600. flex: 1;
  601. display: flex;
  602. justify-content: space-between;
  603. align-items: center;
  604. }
  605. .footer {
  606. display: flex;
  607. justify-content: center;
  608. margin-top: 24px;
  609. .footer-button {
  610. padding: 10px 20px;
  611. }
  612. }
  613. .explain-btn {
  614. padding-left: 20px;
  615. padding-right: 20px;
  616. color: #2957FF !important;
  617. }
  618. </style>