index.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. <template>
  2. <view class="page">
  3. <!-- 顶部导航栏 -->
  4. <view class="nav-bar">
  5. <view class="nav-content">
  6. <view class="nav-left" @click="goBack">
  7. <text class="back-icon">←</text>
  8. </view>
  9. <text class="page-title">支付结果</text>
  10. </view>
  11. </view>
  12. <!-- 支付结果内容 -->
  13. <view class="result-container">
  14. <!-- 成功状态 -->
  15. <view v-if="status === 'success'" class="result-card success">
  16. <text class="result-icon">✓</text>
  17. <text class="result-title">支付成功</text>
  18. <text class="result-desc">感谢您的支持,您的会员权益已生效</text>
  19. <view class="order-info">
  20. <text class="info-label">订单号</text>
  21. <text class="info-value">{{ orderNo || '-' }}</text>
  22. </view>
  23. </view>
  24. <!-- 失败状态 -->
  25. <view v-else-if="status === 'failed'" class="result-card failed">
  26. <text class="result-icon">✕</text>
  27. <text class="result-title">支付失败</text>
  28. <text class="result-desc">{{ errorMsg || '支付未能完成,请稍后重试' }}</text>
  29. </view>
  30. <!-- 待支付状态 -->
  31. <view v-else-if="status === 'pending'" class="result-card pending">
  32. <text class="result-icon">⏳</text>
  33. <text class="result-title">等待支付</text>
  34. <text class="result-desc">请在支付宝中完成支付</text>
  35. </view>
  36. <!-- 未知状态 -->
  37. <view v-else class="result-card unknown">
  38. <text class="result-icon">?</text>
  39. <text class="result-title">状态未知</text>
  40. <text class="result-desc">未能获取支付状态,请联系客服</text>
  41. </view>
  42. <!-- 操作按钮 -->
  43. <view class="action-buttons">
  44. <button class="btn-primary" @click="goToMember">
  45. <text>返回会员中心</text>
  46. </button>
  47. <button class="btn-secondary" @click="goBack">
  48. <text>返回上页</text>
  49. </button>
  50. </view>
  51. <!-- 提示信息 -->
  52. <view class="tips">
  53. <text class="tips-title">温馨提示</text>
  54. <text class="tips-text">
  55. • 支付结果通常会在1-3分钟内到账
  56. </text>
  57. <text class="tips-text">
  58. • 如支付成功但权益未生效,请稍后刷新页面
  59. </text>
  60. <text class="tips-text">
  61. • 如有问题请联系客服
  62. </text>
  63. </view>
  64. </view>
  65. </view>
  66. </template>
  67. <script setup lang="ts">
  68. import { ref, onMounted } from 'vue';
  69. const status = ref<'success' | 'failed' | 'pending' | 'unknown'>('unknown');
  70. const orderNo = ref('');
  71. const errorMsg = ref('');
  72. onMounted(() => {
  73. // 从 URL 参数获取支付结果
  74. const pages = getCurrentPages();
  75. const currentPage = pages[pages.length - 1] as any;
  76. // #ifdef APP-PLUS
  77. const options = currentPage?.$page?.options || {};
  78. // #endif
  79. // #ifndef APP-PLUS
  80. const options = currentPage?.options || {};
  81. // #endif
  82. // 支付宝同步返回参数
  83. if (options.trade_status) {
  84. // 支付宝同步返回
  85. if (options.trade_status === 'TRADE_SUCCESS' || options.trade_status === 'TRADE_FINISHED') {
  86. status.value = 'success';
  87. } else if (options.trade_status === 'WAIT_BUYER_PAY') {
  88. status.value = 'pending';
  89. } else {
  90. status.value = 'failed';
  91. errorMsg.value = options.memo || options.errorMsg || '支付未完成';
  92. }
  93. } else if (options.status) {
  94. // 自定义状态参数
  95. status.value = options.status;
  96. }
  97. // 订单号
  98. if (options.out_trade_no) {
  99. orderNo.value = options.out_trade_no;
  100. } else if (options.orderNo) {
  101. orderNo.value = options.orderNo;
  102. }
  103. // 错误信息
  104. if (options.error_msg) {
  105. errorMsg.value = decodeURIComponent(options.error_msg);
  106. }
  107. });
  108. function goBack() {
  109. const pages = getCurrentPages();
  110. if (pages.length > 1) {
  111. uni.navigateBack();
  112. } else {
  113. uni.switchTab({ url: '/pages/mine/index' });
  114. }
  115. }
  116. function goToMember() {
  117. uni.switchTab({ url: '/pages/mine/index' });
  118. }
  119. </script>
  120. <style scoped>
  121. .page {
  122. min-height: 100vh;
  123. background: #f5f5f5;
  124. }
  125. .nav-bar {
  126. position: fixed;
  127. top: 0;
  128. left: 0;
  129. right: 0;
  130. height: 88rpx;
  131. padding-top: env(safe-area-inset-top);
  132. background: #ffffff;
  133. border-bottom: 1px solid #e5e7eb;
  134. z-index: 100;
  135. }
  136. .nav-content {
  137. height: 100%;
  138. display: flex;
  139. align-items: center;
  140. padding: 0 24rpx;
  141. }
  142. .nav-left {
  143. width: 80rpx;
  144. display: flex;
  145. align-items: center;
  146. }
  147. .back-icon {
  148. font-size: 36rpx;
  149. color: #333;
  150. }
  151. .page-title {
  152. flex: 1;
  153. text-align: center;
  154. font-size: 32rpx;
  155. font-weight: 500;
  156. color: #333;
  157. margin-right: 80rpx;
  158. }
  159. .result-container {
  160. padding-top: calc(120rpx + env(safe-area-inset-top));
  161. padding-left: 32rpx;
  162. padding-right: 32rpx;
  163. }
  164. .result-card {
  165. background: #ffffff;
  166. border-radius: 24rpx;
  167. padding: 60rpx 40rpx;
  168. text-align: center;
  169. margin-bottom: 32rpx;
  170. }
  171. .result-card.success {
  172. border: 2rpx solid #10b981;
  173. }
  174. .result-card.failed {
  175. border: 2rpx solid #ef4444;
  176. }
  177. .result-card.pending {
  178. border: 2rpx solid #f59e0b;
  179. }
  180. .result-card.unknown {
  181. border: 2rpx solid #9ca3af;
  182. }
  183. .result-icon {
  184. font-size: 100rpx;
  185. display: block;
  186. margin-bottom: 24rpx;
  187. }
  188. .success .result-icon {
  189. color: #10b981;
  190. }
  191. .failed .result-icon {
  192. color: #ef4444;
  193. }
  194. .pending .result-icon {
  195. color: #f59e0b;
  196. }
  197. .unknown .result-icon {
  198. color: #9ca3af;
  199. }
  200. .result-title {
  201. font-size: 36rpx;
  202. font-weight: 600;
  203. color: #1f2937;
  204. display: block;
  205. margin-bottom: 16rpx;
  206. }
  207. .result-desc {
  208. font-size: 28rpx;
  209. color: #6b7280;
  210. display: block;
  211. margin-bottom: 24rpx;
  212. }
  213. .order-info {
  214. background: #f9fafb;
  215. border-radius: 12rpx;
  216. padding: 24rpx;
  217. display: flex;
  218. justify-content: space-between;
  219. align-items: center;
  220. }
  221. .info-label {
  222. font-size: 26rpx;
  223. color: #9ca3af;
  224. }
  225. .info-value {
  226. font-size: 26rpx;
  227. color: #1f2937;
  228. font-family: monospace;
  229. }
  230. .action-buttons {
  231. display: flex;
  232. flex-direction: column;
  233. gap: 24rpx;
  234. margin-bottom: 48rpx;
  235. }
  236. .btn-primary,
  237. .btn-secondary {
  238. height: 88rpx;
  239. border-radius: 44rpx;
  240. display: flex;
  241. align-items: center;
  242. justify-content: center;
  243. border: none;
  244. font-size: 30rpx;
  245. }
  246. .btn-primary {
  247. background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
  248. color: #ffffff;
  249. }
  250. .btn-secondary {
  251. background: #ffffff;
  252. color: #4f46e5;
  253. border: 2rpx solid #4f46e5;
  254. }
  255. .tips {
  256. background: #fef3c7;
  257. border-radius: 16rpx;
  258. padding: 32rpx;
  259. margin-bottom: 48rpx;
  260. }
  261. .tips-title {
  262. font-size: 28rpx;
  263. font-weight: 600;
  264. color: #92400e;
  265. display: block;
  266. margin-bottom: 16rpx;
  267. }
  268. .tips-text {
  269. font-size: 24rpx;
  270. color: #78350f;
  271. display: block;
  272. margin-bottom: 8rpx;
  273. }
  274. .tips-text:last-child {
  275. margin-bottom: 0;
  276. }
  277. </style>