Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 

409 rindas
11 KiB

  1. <template>
  2. <view class="page">
  3. <scroll-view
  4. class="scroll"
  5. scroll-y
  6. refresher-enabled
  7. :refresher-triggered="refreshing"
  8. @refresherrefresh="refresh"
  9. @scrolltolower="loadMore"
  10. >
  11. <view class="wrap">
  12. <view class="studio-head">
  13. <view>
  14. <text class="eyebrow">PORTRAIT GALLERY</text>
  15. <text class="page-title">我的形象照</text>
  16. <text class="page-desc">每次生成的照片都会保存,完成后可查看大图、保存原图或继续创作。</text>
  17. </view>
  18. <view class="create-btn" @click="goCreate">生成</view>
  19. </view>
  20. <view class="stats-row">
  21. <view class="stat-card">
  22. <text class="stat-num">{{ total || list.length }}</text>
  23. <text class="stat-label">全部记录</text>
  24. </view>
  25. <view class="stat-card">
  26. <text class="stat-num">{{ pendingCount }}</text>
  27. <text class="stat-label">生成中</text>
  28. </view>
  29. <view class="stat-card">
  30. <text class="stat-num">{{ photoCount }}</text>
  31. <text class="stat-label">已出图</text>
  32. </view>
  33. </view>
  34. <view v-if="list.length" class="gallery">
  35. <view v-for="item in list" :key="item.photo_open_id" class="work-card">
  36. <view class="poster" @click="openItem(item)">
  37. <image v-if="item.cover" class="poster-img" :src="item.cover" mode="aspectFill" />
  38. <view v-else class="poster-empty"></view>
  39. <view class="status-chip" :class="statusClass(item)">{{ item.status_text }}</view>
  40. <view v-if="item.success_count > 1" class="count-chip">{{ item.success_count }}张</view>
  41. <view v-if="isPending(item)" class="progress-mask">
  42. <view class="spinner"></view>
  43. <text>{{ item.success_count || 0 }}/{{ item.count || 0 }} 张</text>
  44. </view>
  45. <view v-else-if="Number(item.status) < 0" class="failed-mask">
  46. <text>{{ item.error_msg || '生成失败' }}</text>
  47. </view>
  48. </view>
  49. <view class="card-info">
  50. <text class="style-name">{{ item.style_name || '形象照' }}</text>
  51. <view class="time-line">
  52. <text>{{ formatTime(item.add_time) }}</text>
  53. <view class="delete-btn" @click.stop="deleteItem(item)">删除</view>
  54. </view>
  55. </view>
  56. </view>
  57. </view>
  58. <view v-if="!list.length && !loading" class="empty-state">
  59. <view class="empty-preview">
  60. <view class="empty-photo"></view>
  61. </view>
  62. <text class="empty-title">还没有形象照</text>
  63. <text class="empty-desc">上传一张人像照片,试试商务形象照或艺术写真。</text>
  64. <view class="empty-action" @click="goCreate">去生成</view>
  65. </view>
  66. <view v-if="loading" class="loading">{{ list.length ? '加载更多...' : '加载中...' }}</view>
  67. <view v-if="list.length && list.length >= total && !loading" class="end-text">已经到底了</view>
  68. </view>
  69. </scroll-view>
  70. </view>
  71. </template>
  72. <script setup>
  73. import { computed, ref } from 'vue'
  74. import { onLoad, onUnload } from '@dcloudio/uni-app'
  75. import dayjs from 'dayjs'
  76. import { portraitApi } from '@/api/index.js'
  77. import { useApp } from '@/utils/useApp.js'
  78. const { toast } = useApp()
  79. const list = ref([])
  80. const page = ref(1)
  81. const total = ref(0)
  82. const loading = ref(false)
  83. const refreshing = ref(false)
  84. let timer = 0
  85. const pendingCount = computed(() => list.value.filter((item) => isPending(item)).length)
  86. const photoCount = computed(() =>
  87. list.value.reduce((sum, item) => sum + Number(item.success_count || 0), 0)
  88. )
  89. onLoad(() => refresh())
  90. onUnload(() => clearTimeout(timer))
  91. function isPending(item) {
  92. return [10, 20].includes(Number(item.status))
  93. }
  94. function formatTime(value) {
  95. if (!value) return ''
  96. return dayjs(Number(value) * 1000).format('YYYY-MM-DD HH:mm')
  97. }
  98. async function fetchList(reset = false) {
  99. if (loading.value) return
  100. loading.value = true
  101. try {
  102. const res = await portraitApi.getList({ page_no: page.value, page_size: 10 })
  103. const rows = res.list || []
  104. total.value = Number((res.data && res.data.total) || rows.length)
  105. list.value = reset ? rows : list.value.concat(rows)
  106. scheduleRefresh()
  107. } catch (e) {
  108. toast((e && e.msg) || '记录加载失败')
  109. } finally {
  110. loading.value = false
  111. refreshing.value = false
  112. }
  113. }
  114. // 有进行中的任务就轮询:后端 getlist 会顺带推进任务状态
  115. function scheduleRefresh() {
  116. clearTimeout(timer)
  117. if (list.value.some((item) => isPending(item))) {
  118. timer = setTimeout(() => refreshSilent(), 3000)
  119. }
  120. }
  121. function refresh() {
  122. refreshing.value = true
  123. refreshSilent()
  124. }
  125. function refreshSilent() {
  126. page.value = 1
  127. fetchList(true)
  128. }
  129. function loadMore() {
  130. if (loading.value) return
  131. if (list.value.length >= total.value) return
  132. page.value += 1
  133. fetchList()
  134. }
  135. function openItem(item) {
  136. if (Number(item.status) < 0) return toast(item.error_msg || '该记录生成失败')
  137. uni.navigateTo({ url: `/pages/tool/portrait-detail?id=${item.photo_open_id}` })
  138. }
  139. function statusClass(item) {
  140. if (isPending(item)) return 'pending'
  141. if (Number(item.status) < 0) return 'failed'
  142. return 'done'
  143. }
  144. function goCreate() {
  145. const delta = getPageStackDelta('pages/tool/portrait-photo')
  146. if (delta > 0) {
  147. uni.navigateBack({ delta })
  148. return
  149. }
  150. uni.navigateTo({ url: '/pages/tool/portrait-photo' })
  151. }
  152. function getPageStackDelta(routeName) {
  153. const pages = getCurrentPages()
  154. const index = pages.findIndex((item) => item.route === routeName)
  155. return index >= 0 ? pages.length - 1 - index : -1
  156. }
  157. function deleteItem(item) {
  158. uni.showModal({
  159. title: '温馨提示',
  160. content: '是否确认删除该记录?',
  161. confirmText: '确认删除',
  162. success: async (res) => {
  163. if (!res.confirm) return
  164. try {
  165. await portraitApi.delete({ photo_open_id: item.photo_open_id })
  166. toast('删除成功')
  167. refresh()
  168. } catch (e) {
  169. toast((e && e.msg) || '删除失败')
  170. }
  171. }
  172. })
  173. }
  174. </script>
  175. <style lang="scss" scoped>
  176. .page,
  177. .scroll {
  178. height: 100vh;
  179. background: #f6f8fc;
  180. }
  181. .wrap { padding: 24rpx 28rpx 70rpx; }
  182. .studio-head {
  183. padding: 30rpx;
  184. border-radius: 26rpx;
  185. background: #ffffff;
  186. display: flex;
  187. align-items: center;
  188. gap: 24rpx;
  189. box-shadow: 0 10rpx 28rpx rgba(31, 52, 86, 0.05);
  190. }
  191. .studio-head > view:first-child { flex: 1; min-width: 0; }
  192. .eyebrow { display: block; color: #1f8cff; font-size: 20rpx; font-weight: 800; }
  193. .page-title {
  194. display: block;
  195. margin-top: 10rpx;
  196. color: #172033;
  197. font-size: 40rpx;
  198. line-height: 1.2;
  199. font-weight: 900;
  200. }
  201. .page-desc { display: block; margin-top: 12rpx; color: #64748b; font-size: 24rpx; line-height: 1.5; }
  202. .create-btn {
  203. width: 112rpx;
  204. height: 68rpx;
  205. border-radius: 999rpx;
  206. color: #ffffff;
  207. background: #1f8cff;
  208. font-size: 26rpx;
  209. line-height: 68rpx;
  210. text-align: center;
  211. font-weight: 800;
  212. box-shadow: 0 12rpx 24rpx rgba(31, 140, 255, 0.22);
  213. flex-shrink: 0;
  214. }
  215. .stats-row {
  216. margin-top: 18rpx;
  217. display: grid;
  218. grid-template-columns: repeat(3, 1fr);
  219. gap: 14rpx;
  220. }
  221. .stat-card {
  222. padding: 20rpx 10rpx;
  223. border-radius: 20rpx;
  224. background: #ffffff;
  225. text-align: center;
  226. box-shadow: 0 8rpx 20rpx rgba(31, 52, 86, 0.04);
  227. }
  228. .stat-num { display: block; color: #172033; font-size: 34rpx; line-height: 1; font-weight: 900; }
  229. .stat-label { display: block; margin-top: 10rpx; color: #7c8a9b; font-size: 22rpx; }
  230. .gallery {
  231. margin-top: 24rpx;
  232. display: grid;
  233. grid-template-columns: repeat(2, minmax(0, 1fr));
  234. gap: 22rpx;
  235. }
  236. .work-card {
  237. border-radius: 24rpx;
  238. background: #ffffff;
  239. overflow: hidden;
  240. box-shadow: 0 10rpx 28rpx rgba(31, 52, 86, 0.06);
  241. }
  242. .poster {
  243. position: relative;
  244. width: 100%;
  245. height: 440rpx;
  246. background: #dfe7f2;
  247. overflow: hidden;
  248. }
  249. .poster-img,
  250. .poster-empty { width: 100%; height: 100%; }
  251. .poster-empty { background: linear-gradient(135deg, #eef4fb, #dbe6f4); }
  252. .status-chip {
  253. position: absolute;
  254. left: 14rpx;
  255. top: 14rpx;
  256. height: 42rpx;
  257. padding: 0 16rpx;
  258. border-radius: 999rpx;
  259. color: #ffffff;
  260. font-size: 22rpx;
  261. line-height: 42rpx;
  262. font-weight: 800;
  263. background: rgba(15, 23, 42, 0.48);
  264. }
  265. .status-chip.done { background: rgba(31, 140, 255, 0.9); }
  266. .status-chip.pending { background: rgba(249, 115, 22, 0.92); }
  267. .status-chip.failed { background: rgba(239, 68, 68, 0.9); }
  268. .count-chip {
  269. position: absolute;
  270. right: 14rpx;
  271. top: 14rpx;
  272. height: 42rpx;
  273. padding: 0 14rpx;
  274. border-radius: 999rpx;
  275. color: #ffffff;
  276. font-size: 21rpx;
  277. line-height: 42rpx;
  278. font-weight: 800;
  279. background: rgba(15, 23, 42, 0.48);
  280. }
  281. .progress-mask,
  282. .failed-mask {
  283. position: absolute;
  284. left: 0;
  285. right: 0;
  286. top: 0;
  287. bottom: 0;
  288. padding: 24rpx;
  289. display: flex;
  290. flex-direction: column;
  291. align-items: center;
  292. justify-content: center;
  293. color: #ffffff;
  294. font-size: 26rpx;
  295. text-align: center;
  296. background: rgba(15, 23, 42, 0.52);
  297. }
  298. .failed-mask { background: rgba(127, 29, 29, 0.72); font-size: 24rpx; }
  299. .spinner {
  300. width: 48rpx;
  301. height: 48rpx;
  302. margin-bottom: 18rpx;
  303. border: 6rpx solid rgba(255, 255, 255, 0.45);
  304. border-top-color: #ffffff;
  305. border-radius: 50%;
  306. animation: spin 0.8s linear infinite;
  307. }
  308. .card-info { padding: 18rpx; }
  309. .style-name {
  310. display: block;
  311. margin-bottom: 10rpx;
  312. color: #172033;
  313. font-size: 25rpx;
  314. font-weight: 800;
  315. }
  316. .time-line { display: flex; align-items: center; gap: 12rpx; color: #64748b; font-size: 22rpx; }
  317. .time-line text { flex: 1; min-width: 0; }
  318. .delete-btn {
  319. width: 74rpx;
  320. height: 44rpx;
  321. border-radius: 999rpx;
  322. color: #ef4444;
  323. background: #fff1f2;
  324. font-size: 22rpx;
  325. line-height: 44rpx;
  326. text-align: center;
  327. flex-shrink: 0;
  328. }
  329. .empty-state {
  330. margin-top: 86rpx;
  331. padding: 56rpx 34rpx;
  332. border-radius: 28rpx;
  333. background: #ffffff;
  334. display: flex;
  335. flex-direction: column;
  336. align-items: center;
  337. text-align: center;
  338. box-shadow: 0 10rpx 28rpx rgba(31, 52, 86, 0.05);
  339. }
  340. .empty-preview {
  341. width: 150rpx;
  342. height: 200rpx;
  343. border-radius: 32rpx;
  344. background: linear-gradient(135deg, #edf6ff, #eef2ff);
  345. display: flex;
  346. align-items: center;
  347. justify-content: center;
  348. }
  349. .empty-photo {
  350. width: 88rpx;
  351. height: 108rpx;
  352. border-radius: 14rpx;
  353. border: 6rpx solid #1f8cff;
  354. background: linear-gradient(180deg, #c9d8ef 40%, #2f4468 40%);
  355. }
  356. .empty-title { margin-top: 28rpx; color: #172033; font-size: 32rpx; font-weight: 900; }
  357. .empty-desc { margin-top: 12rpx; color: #64748b; font-size: 25rpx; line-height: 1.5; }
  358. .empty-action {
  359. margin-top: 28rpx;
  360. width: 220rpx;
  361. height: 72rpx;
  362. border-radius: 999rpx;
  363. color: #ffffff;
  364. background: #1f8cff;
  365. font-size: 28rpx;
  366. line-height: 72rpx;
  367. font-weight: 800;
  368. }
  369. .loading,
  370. .end-text { padding: 46rpx 0 20rpx; color: #7c8a9b; font-size: 24rpx; text-align: center; }
  371. @keyframes spin {
  372. to { transform: rotate(360deg); }
  373. }
  374. </style>