Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.
 
 
 

463 рядки
12 KiB

  1. <template>
  2. <view class="page">
  3. <scroll-view class="scroll" scroll-y>
  4. <view class="wrap">
  5. <!-- 处理中 / 失败 -->
  6. <view v-if="isLoadingState" class="state-card">
  7. <view v-if="isPending" class="spinner"></view>
  8. <text class="state-title">{{ isPending ? (Number(detail.status) === 10 ? '排队中,请耐心等待' : 'AI 正在修复上色') : '修复失败' }}</text>
  9. <text v-if="isPending && countDown > 0" class="count">{{ countDown }} S</text>
  10. <text v-if="!isPending" class="error">{{ detail.error_msg || '本次未扣点,可以换一张更清晰的照片重试' }}</text>
  11. </view>
  12. <!-- 成品:默认直接看修复后的图 -->
  13. <view v-else class="image-card" @click="preview">
  14. <image class="work-img" :src="detail.result_url" mode="widthFix" />
  15. <view class="compare-entry" @click.stop="openCompare">查看对比</view>
  16. </view>
  17. <view class="info-card">
  18. <view class="title">修复信息</view>
  19. <view class="cell">
  20. <text class="cell-label">修复档位:</text>
  21. <text class="cell-content">{{ detail.mode_name || '-' }}</text>
  22. </view>
  23. <view class="cell">
  24. <text class="cell-label">当前状态:</text>
  25. <text class="cell-content">{{ detail.status_text || '-' }}</text>
  26. </view>
  27. <view v-if="detail.source_width && detail.source_height" class="cell">
  28. <text class="cell-label">原图尺寸:</text>
  29. <text class="cell-content">{{ detail.source_width }} × {{ detail.source_height }}px</text>
  30. </view>
  31. <view v-if="Number(detail.refine) === 1" class="cell">
  32. <text class="cell-label">清晰度:</text>
  33. <text class="cell-content">已做高清增强</text>
  34. </view>
  35. <view class="cell">
  36. <text class="cell-label">创建时间:</text>
  37. <text class="cell-content">{{ formatTime(detail.add_time) }}</text>
  38. </view>
  39. <view class="cell">
  40. <text class="cell-label">功能来源:</text>
  41. <text class="link" @click="createAgain">老照片修复 / 上色</text>
  42. </view>
  43. <text class="note">AI 会重绘上色,五官可能出现轻微变化,建议对照原图确认。</text>
  44. </view>
  45. </view>
  46. </scroll-view>
  47. <view v-if="!isLoadingState" class="bottom-bar">
  48. <view class="delete-btn" @click="deleteRecord">删除</view>
  49. <view class="bar-btn" @click="download">保存</view>
  50. <view class="bar-btn" @click="openCompare">对比</view>
  51. <view class="main-btn" @click="createAgain">再修一张</view>
  52. </view>
  53. <!-- 前后对比:样式与动漫头像一致 -->
  54. <view v-if="compareVisible" class="compare-modal">
  55. <view class="compare-backdrop" @click="closeCompare"></view>
  56. <view class="compare-panel">
  57. <view class="compare-panel-head">
  58. <text>效果对比</text>
  59. <view class="close-btn" @click="closeCompare">×</view>
  60. </view>
  61. <view
  62. class="large-compare"
  63. @touchstart.stop="onCompareTouch"
  64. @touchmove.stop.prevent="onCompareTouch"
  65. @click.stop="onCompareTouch"
  66. >
  67. <image class="compare-img" :src="detail.result_url" mode="aspectFit" />
  68. <view class="compare-before" :style="{ width: comparePercent + '%' }">
  69. <image class="compare-img" :src="detail.source_url" mode="aspectFit" />
  70. </view>
  71. <view class="compare-line large" :style="{ left: comparePercent + '%' }">
  72. <view class="compare-handle large">
  73. <text>‹</text>
  74. <text>›</text>
  75. </view>
  76. </view>
  77. <view class="compare-tag left">原图</view>
  78. <view class="compare-tag right">修复后</view>
  79. </view>
  80. <text class="compare-guide">左右滑动中间按钮查看变化</text>
  81. </view>
  82. </view>
  83. </view>
  84. </template>
  85. <script setup>
  86. import { computed, ref } from 'vue'
  87. import { onLoad, onUnload } from '@dcloudio/uni-app'
  88. import dayjs from 'dayjs'
  89. import { oldPhotoApi } from '@/api/index.js'
  90. import { useApp } from '@/utils/useApp.js'
  91. const { toast } = useApp()
  92. const id = ref('')
  93. const detail = ref({ status: 10 })
  94. const countDown = ref(0)
  95. const compareVisible = ref(false)
  96. const comparePercent = ref(50)
  97. let timer = 0
  98. let countTimer = 0
  99. const isPending = computed(() => [10, 20].includes(Number(detail.value.status)))
  100. const isLoadingState = computed(() => Number(detail.value.status) !== 30)
  101. onLoad((options) => {
  102. id.value = (options && options.id) || ''
  103. loadDetail()
  104. })
  105. onUnload(() => {
  106. clearTimeout(timer)
  107. clearInterval(countTimer)
  108. })
  109. async function loadDetail() {
  110. if (!id.value) return
  111. try {
  112. const res = await oldPhotoApi.getDetail({ photo_open_id: id.value })
  113. detail.value = res.data || {}
  114. if (isPending.value) waitNext()
  115. } catch (e) {
  116. toast((e && e.msg) || '记录加载失败')
  117. }
  118. }
  119. // 处理中就 3 秒拉一次,后端会在这一步推进任务并转存结果
  120. function waitNext() {
  121. clearTimeout(timer)
  122. clearInterval(countTimer)
  123. countDown.value = 3
  124. countTimer = setInterval(() => {
  125. countDown.value -= 1
  126. if (countDown.value <= 0) clearInterval(countTimer)
  127. }, 1000)
  128. timer = setTimeout(loadDetail, 3000)
  129. }
  130. function formatTime(value) {
  131. if (!value) return '-'
  132. return dayjs(Number(value) * 1000).format('YYYY-MM-DD HH:mm')
  133. }
  134. function preview() {
  135. if (!detail.value.result_url) return
  136. uni.previewImage({ urls: [detail.value.result_url], current: detail.value.result_url })
  137. }
  138. function download() {
  139. if (!detail.value.result_url) return
  140. uni.showLoading({ title: '保存中...', mask: true })
  141. uni.downloadFile({
  142. url: detail.value.result_url,
  143. success: (res) => {
  144. uni.saveImageToPhotosAlbum({
  145. filePath: res.tempFilePath,
  146. success: () => toast('已保存到相册'),
  147. fail: () => toast('保存失败,请检查相册权限')
  148. })
  149. },
  150. fail: () => toast('图片下载失败'),
  151. complete: () => uni.hideLoading()
  152. })
  153. }
  154. function deleteRecord() {
  155. if (!id.value) return
  156. uni.showModal({
  157. title: '删除记录',
  158. content: '删除后将不再展示该老照片记录,是否继续?',
  159. confirmText: '删除',
  160. confirmColor: '#f04438',
  161. success: async (res) => {
  162. if (!res.confirm) return
  163. try {
  164. await oldPhotoApi.delete({ photo_open_id: id.value })
  165. toast('删除成功')
  166. const pages = getCurrentPages()
  167. if (pages.length > 1) {
  168. uni.navigateBack()
  169. } else {
  170. uni.redirectTo({ url: '/pages/works/works' })
  171. }
  172. } catch (e) {
  173. toast((e && e.msg) || '删除失败')
  174. }
  175. }
  176. })
  177. }
  178. function openCompare() {
  179. if (!detail.value.result_url || !detail.value.source_url) return
  180. comparePercent.value = 50
  181. compareVisible.value = true
  182. }
  183. function closeCompare() {
  184. compareVisible.value = false
  185. }
  186. function onCompareTouch(e) {
  187. const touch = (e.touches && e.touches[0]) || (e.changedTouches && e.changedTouches[0]) || e
  188. const x = touch.clientX || 0
  189. uni.createSelectorQuery()
  190. .select('.large-compare')
  191. .boundingClientRect((rect) => {
  192. if (!rect || !rect.width) return
  193. const percent = ((x - rect.left) / rect.width) * 100
  194. comparePercent.value = Math.max(6, Math.min(94, Number(percent.toFixed(1))))
  195. })
  196. .exec()
  197. }
  198. function createAgain() {
  199. const delta = getPageStackDelta('pages/tool/old-photo')
  200. if (delta > 0) {
  201. uni.navigateBack({ delta })
  202. return
  203. }
  204. uni.navigateTo({ url: '/pages/tool/old-photo' })
  205. }
  206. function getPageStackDelta(routeName) {
  207. const pages = getCurrentPages()
  208. const index = pages.findIndex((item) => item.route === routeName)
  209. return index >= 0 ? pages.length - 1 - index : -1
  210. }
  211. </script>
  212. <style lang="scss" scoped>
  213. .page {
  214. height: 100vh;
  215. background: #f4f7fb;
  216. display: flex;
  217. flex-direction: column;
  218. overflow: hidden;
  219. }
  220. .scroll { flex: 1; height: 0; }
  221. /* 底栏是 fixed 的,留够 300rpx */
  222. .wrap { padding: 28rpx 28rpx 300rpx; }
  223. .state-card,
  224. .image-card,
  225. .info-card {
  226. background: #fff;
  227. border-radius: 18rpx;
  228. overflow: hidden;
  229. }
  230. .state-card {
  231. min-height: 540rpx;
  232. display: flex;
  233. flex-direction: column;
  234. align-items: center;
  235. justify-content: center;
  236. color: #172033;
  237. font-size: 30rpx;
  238. }
  239. .spinner {
  240. width: 72rpx;
  241. height: 72rpx;
  242. margin-bottom: 28rpx;
  243. border: 8rpx solid #e9edf5;
  244. border-top-color: #0b8cff;
  245. border-radius: 50%;
  246. animation: spin 0.8s linear infinite;
  247. }
  248. .count,
  249. .error { margin-top: 18rpx; color: #7f8896; font-size: 26rpx; }
  250. .error { color: #f04438; padding: 0 40rpx; text-align: center; }
  251. .image-card { position: relative; }
  252. .work-img { width: 100%; display: block; }
  253. .compare-entry {
  254. position: absolute;
  255. right: 18rpx;
  256. bottom: 18rpx;
  257. height: 56rpx;
  258. padding: 0 22rpx;
  259. border-radius: 999rpx;
  260. color: #fff;
  261. font-size: 24rpx;
  262. font-weight: 800;
  263. line-height: 56rpx;
  264. background: rgba(15, 23, 42, 0.55);
  265. }
  266. .info-card { margin-top: 24rpx; padding: 28rpx; }
  267. .title { margin-bottom: 16rpx; color: #172033; font-size: 32rpx; font-weight: 700; }
  268. .cell {
  269. padding: 10rpx 0;
  270. display: flex;
  271. color: #7f8896;
  272. font-size: 27rpx;
  273. line-height: 1.6;
  274. }
  275. .cell-label { flex-shrink: 0; }
  276. .cell-content { flex: 1; min-width: 0; color: #172033; }
  277. .link { color: #0b8cff; }
  278. .note {
  279. display: block;
  280. margin-top: 16rpx;
  281. padding-top: 16rpx;
  282. border-top: 2rpx solid #f1f5fa;
  283. color: #8a95a6;
  284. font-size: 23rpx;
  285. line-height: 1.5;
  286. }
  287. .bottom-bar {
  288. position: fixed;
  289. left: 0;
  290. right: 0;
  291. bottom: 0;
  292. padding: 18rpx 28rpx calc(18rpx + env(safe-area-inset-bottom));
  293. background: #fff;
  294. display: flex;
  295. gap: 18rpx;
  296. box-shadow: 0 -8rpx 24rpx rgba(35, 55, 90, 0.08);
  297. }
  298. .bar-btn,
  299. .delete-btn,
  300. .main-btn {
  301. height: 82rpx;
  302. border-radius: 42rpx;
  303. font-size: 29rpx;
  304. display: flex;
  305. align-items: center;
  306. justify-content: center;
  307. }
  308. .bar-btn { width: 136rpx; color: #0b8cff; background: #eef6ff; }
  309. .delete-btn { width: 136rpx; color: #f04438; background: #fff1f0; }
  310. .main-btn { flex: 1; color: #fff; background: #0b8cff; }
  311. /* 对比弹层:与动漫头像保持一致 */
  312. .compare-modal {
  313. position: fixed;
  314. left: 0;
  315. right: 0;
  316. top: 0;
  317. bottom: 0;
  318. z-index: 120;
  319. }
  320. .compare-backdrop {
  321. position: absolute;
  322. left: 0;
  323. right: 0;
  324. top: 0;
  325. bottom: 0;
  326. background: rgba(15, 23, 42, 0.58);
  327. }
  328. .compare-panel {
  329. position: absolute;
  330. left: 36rpx;
  331. right: 36rpx;
  332. top: 50%;
  333. transform: translateY(-50%);
  334. padding: 24rpx;
  335. border-radius: 28rpx;
  336. background: #ffffff;
  337. }
  338. .compare-panel-head {
  339. margin-bottom: 20rpx;
  340. display: flex;
  341. align-items: center;
  342. justify-content: space-between;
  343. color: #172033;
  344. font-size: 32rpx;
  345. font-weight: 800;
  346. }
  347. .close-btn {
  348. width: 56rpx;
  349. height: 56rpx;
  350. border-radius: 50%;
  351. color: #64748b;
  352. background: #f1f5f9;
  353. font-size: 42rpx;
  354. line-height: 50rpx;
  355. text-align: center;
  356. font-weight: 300;
  357. }
  358. .large-compare {
  359. position: relative;
  360. width: 100%;
  361. height: 900rpx;
  362. max-height: 70vh;
  363. border-radius: 22rpx;
  364. background: #dfe8f4;
  365. overflow: hidden;
  366. }
  367. .compare-img { width: 100%; height: 100%; }
  368. .compare-before {
  369. position: absolute;
  370. left: 0;
  371. top: 0;
  372. bottom: 0;
  373. overflow: hidden;
  374. }
  375. .large-compare .compare-before .compare-img { width: calc(100vw - 120rpx); }
  376. .compare-line {
  377. position: absolute;
  378. top: 0;
  379. bottom: 0;
  380. width: 4rpx;
  381. margin-left: -2rpx;
  382. background: rgba(255, 255, 255, 0.94);
  383. box-shadow: 0 0 12rpx rgba(20, 37, 66, 0.22);
  384. }
  385. .compare-line.large { width: 6rpx; margin-left: -3rpx; }
  386. .compare-handle {
  387. position: absolute;
  388. left: 50%;
  389. top: 50%;
  390. width: 38rpx;
  391. height: 58rpx;
  392. margin-left: -19rpx;
  393. margin-top: -29rpx;
  394. border-radius: 999rpx;
  395. background: #ffffff;
  396. box-shadow: 0 8rpx 18rpx rgba(20, 37, 66, 0.22);
  397. display: flex;
  398. align-items: center;
  399. justify-content: center;
  400. gap: 1rpx;
  401. color: #1f8cff;
  402. font-size: 24rpx;
  403. font-weight: 900;
  404. }
  405. .compare-handle.large {
  406. width: 54rpx;
  407. height: 78rpx;
  408. margin-left: -27rpx;
  409. margin-top: -39rpx;
  410. font-size: 32rpx;
  411. }
  412. .compare-tag {
  413. position: absolute;
  414. top: 12rpx;
  415. padding: 6rpx 12rpx;
  416. border-radius: 999rpx;
  417. color: #ffffff;
  418. background: rgba(15, 23, 42, 0.46);
  419. font-size: 20rpx;
  420. font-weight: 700;
  421. }
  422. .compare-tag.left { left: 12rpx; }
  423. .compare-tag.right { right: 12rpx; }
  424. .compare-guide {
  425. display: block;
  426. margin-top: 18rpx;
  427. color: #64748b;
  428. font-size: 24rpx;
  429. text-align: center;
  430. }
  431. @keyframes spin {
  432. to { transform: rotate(360deg); }
  433. }
  434. </style>