bind.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  1. <template>
  2. <view class="page">
  3. <NavBar title="绑定微信" />
  4. <view class="content" v-if="!bound">
  5. <view class="icon-section">
  6. <view class="bind-icon">
  7. <view class="icon-wechat"></view>
  8. </view>
  9. </view>
  10. <text class="title">绑定补货员微信</text>
  11. <text class="subtitle">请确认以下绑定码,点击按钮完成微信绑定</text>
  12. <view class="code-card">
  13. <text class="code-label">绑定码</text>
  14. <text class="code-value">{{ displayCode }}</text>
  15. <text class="code-expire">有效期24小时,过期请重新生成</text>
  16. </view>
  17. <view class="bind-info">
  18. <view class="info-item">
  19. <view class="info-icon done"></view>
  20. <text class="info-text">后台已创建补货员账号</text>
  21. </view>
  22. <view class="info-item">
  23. <view class="info-icon done"></view>
  24. <text class="info-text">管理员已生成一次性绑定码</text>
  25. </view>
  26. <view class="info-item">
  27. <view class="info-icon active"></view>
  28. <text class="info-text">点击下方按钮完成微信绑定</text>
  29. </view>
  30. </view>
  31. <button class="bind-btn" :loading="bindLoading" :disabled="bindLoading" @click="handleBind">
  32. <text v-if="!bindLoading">绑定微信</text>
  33. <text v-else>绑定中...</text>
  34. </button>
  35. <text class="back-link" @click="goToLogin">返回登录页</text>
  36. </view>
  37. <view class="content success-section" v-else>
  38. <view class="success-icon">
  39. <text class="success-check">✓</text>
  40. </view>
  41. <text class="success-title">绑定成功</text>
  42. <text class="success-desc">即将进入补货首页...</text>
  43. </view>
  44. </view>
  45. </template>
  46. <script setup lang="ts">
  47. import { ref, computed, onMounted } from 'vue';
  48. import NavBar from '@/components/NavBar.vue';
  49. const bindingCode = ref('');
  50. const bindLoading = ref(false);
  51. const bound = ref(false);
  52. const displayCode = computed(() => {
  53. const code = bindingCode.value;
  54. if (!code) return '---';
  55. // 每4位一组显示
  56. return code.replace(/(.{4})/g, '$1 ').trim();
  57. });
  58. onMounted(() => {
  59. // 获取绑定码
  60. const pages = getCurrentPages();
  61. const currentPage = pages[pages.length - 1] as any;
  62. if (currentPage && currentPage.options) {
  63. bindingCode.value = currentPage.options.code || currentPage.options.bindingCode || '';
  64. }
  65. if (!bindingCode.value) {
  66. uni.showToast({ title: '缺少绑定码参数', icon: 'none' });
  67. }
  68. });
  69. const goToLogin = () => {
  70. uni.reLaunch({ url: '/pages/login/login' });
  71. };
  72. const handleBind = async () => {
  73. if (!bindingCode.value) {
  74. uni.showToast({ title: '绑定码无效', icon: 'none' });
  75. return;
  76. }
  77. bindLoading.value = true;
  78. try {
  79. // 1. 微信授权
  80. const loginRes = await new Promise<any>((resolve, reject) => {
  81. uni.login({
  82. provider: 'weixin',
  83. success: (res) => resolve(res),
  84. fail: (err) => reject(err)
  85. });
  86. });
  87. if (!loginRes.code) {
  88. uni.showToast({ title: '微信授权失败', icon: 'none' });
  89. return;
  90. }
  91. // 2. 调用绑定接口
  92. const { bindWechat } = await import('@/api/replenish');
  93. await bindWechat({
  94. bindingCode: bindingCode.value.trim().toUpperCase(),
  95. code: loginRes.code
  96. });
  97. // 3. 显示成功状态
  98. bound.value = true;
  99. setTimeout(() => {
  100. uni.reLaunch({ url: '/pages/replenish/index' });
  101. }, 1500);
  102. } catch (error: any) {
  103. uni.showToast({ title: error.message || '绑定失败', icon: 'none' });
  104. } finally {
  105. bindLoading.value = false;
  106. }
  107. };
  108. </script>
  109. <style lang="scss" scoped>
  110. .page {
  111. min-height: 100vh;
  112. background: #f8fafc;
  113. }
  114. .content {
  115. padding: 40rpx 32rpx;
  116. display: flex;
  117. flex-direction: column;
  118. align-items: center;
  119. }
  120. /* 图标区域 */
  121. .icon-section {
  122. margin: 40rpx 0 32rpx;
  123. .bind-icon {
  124. width: 160rpx;
  125. height: 160rpx;
  126. background: #ecfdf5;
  127. border-radius: 40rpx;
  128. display: flex;
  129. align-items: center;
  130. justify-content: center;
  131. .icon-wechat {
  132. width: 64rpx;
  133. height: 54rpx;
  134. background: #07c160;
  135. border-radius: 12rpx;
  136. position: relative;
  137. &::before {
  138. content: '';
  139. position: absolute;
  140. top: 12rpx;
  141. left: 50%;
  142. transform: translateX(-50%);
  143. width: 24rpx;
  144. height: 16rpx;
  145. border: 4rpx solid #fff;
  146. border-top: none;
  147. border-right: none;
  148. transform: translateX(-50%) rotate(-45deg);
  149. }
  150. &::after {
  151. content: '';
  152. position: absolute;
  153. bottom: 12rpx;
  154. left: 50%;
  155. transform: translateX(-50%);
  156. width: 28rpx;
  157. height: 16rpx;
  158. border: 4rpx solid #fff;
  159. border-bottom: none;
  160. border-right: none;
  161. transform: translateX(-50%) rotate(45deg);
  162. }
  163. }
  164. }
  165. }
  166. .title {
  167. font-size: 36rpx;
  168. font-weight: 700;
  169. color: #1e293b;
  170. margin-bottom: 12rpx;
  171. }
  172. .subtitle {
  173. font-size: 26rpx;
  174. color: #64748b;
  175. margin-bottom: 40rpx;
  176. text-align: center;
  177. }
  178. /* 绑定码卡片 */
  179. .code-card {
  180. width: 100%;
  181. background: #ffffff;
  182. border: 2rpx solid #10b981;
  183. border-radius: 20rpx;
  184. padding: 32rpx;
  185. text-align: center;
  186. margin-bottom: 32rpx;
  187. .code-label {
  188. display: block;
  189. font-size: 24rpx;
  190. color: #94a3b8;
  191. margin-bottom: 16rpx;
  192. }
  193. .code-value {
  194. display: block;
  195. font-size: 36rpx;
  196. font-weight: 700;
  197. color: #1e293b;
  198. letter-spacing: 6rpx;
  199. font-family: 'Courier New', monospace;
  200. margin-bottom: 16rpx;
  201. }
  202. .code-expire {
  203. font-size: 22rpx;
  204. color: #94a3b8;
  205. }
  206. }
  207. /* 绑定流程说明 */
  208. .bind-info {
  209. width: 100%;
  210. background: #ffffff;
  211. border: 1rpx solid #e2e8f0;
  212. border-radius: 16rpx;
  213. padding: 24rpx;
  214. margin-bottom: 40rpx;
  215. .info-item {
  216. display: flex;
  217. align-items: center;
  218. margin-bottom: 20rpx;
  219. &:last-child {
  220. margin-bottom: 0;
  221. }
  222. .info-icon {
  223. width: 32rpx;
  224. height: 32rpx;
  225. border-radius: 50%;
  226. margin-right: 16rpx;
  227. flex-shrink: 0;
  228. display: flex;
  229. align-items: center;
  230. justify-content: center;
  231. &.done {
  232. background: #10b981;
  233. &::after {
  234. content: '';
  235. width: 10rpx;
  236. height: 16rpx;
  237. border: 3rpx solid #fff;
  238. border-top: none;
  239. border-left: none;
  240. transform: rotate(45deg) translateY(-2rpx);
  241. }
  242. }
  243. &.active {
  244. background: #10b981;
  245. animation: pulse 2s infinite;
  246. &::after {
  247. content: '';
  248. width: 8rpx;
  249. height: 8rpx;
  250. background: #fff;
  251. border-radius: 50%;
  252. }
  253. }
  254. }
  255. .info-text {
  256. font-size: 26rpx;
  257. color: #475569;
  258. }
  259. }
  260. }
  261. @keyframes pulse {
  262. 0%, 100% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.4); }
  263. 50% { box-shadow: 0 0 0 12rpx rgba(16, 185, 129, 0); }
  264. }
  265. /* 绑定按钮 */
  266. .bind-btn {
  267. width: 100%;
  268. height: 100rpx;
  269. background: #10b981;
  270. color: #fff;
  271. font-size: 32rpx;
  272. font-weight: 600;
  273. border-radius: 16rpx;
  274. border: none;
  275. display: flex;
  276. align-items: center;
  277. justify-content: center;
  278. &::after {
  279. border: none;
  280. }
  281. &:active {
  282. background: #059669;
  283. }
  284. &[disabled] {
  285. opacity: 0.6;
  286. }
  287. }
  288. .back-link {
  289. display: block;
  290. margin-top: 28rpx;
  291. font-size: 26rpx;
  292. color: #94a3b8;
  293. }
  294. /* 成功状态 */
  295. .success-section {
  296. justify-content: center;
  297. min-height: 70vh;
  298. .success-icon {
  299. width: 140rpx;
  300. height: 140rpx;
  301. background: #ecfdf5;
  302. border-radius: 50%;
  303. display: flex;
  304. align-items: center;
  305. justify-content: center;
  306. margin-bottom: 28rpx;
  307. .success-check {
  308. font-size: 64rpx;
  309. color: #10b981;
  310. font-weight: 700;
  311. }
  312. }
  313. .success-title {
  314. font-size: 36rpx;
  315. font-weight: 700;
  316. color: #1e293b;
  317. margin-bottom: 12rpx;
  318. }
  319. .success-desc {
  320. font-size: 28rpx;
  321. color: #64748b;
  322. }
  323. }
  324. </style>