CardAuthDialog.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562
  1. <template>
  2. <uni-popup ref="cardRef" type="center" background-color="#fff" style="z-index: 9999;">
  3. <view class="dialog-container">
  4. <view class="dialog-header">
  5. <text class="dialog-title" v-t="'PersonalManagement.CardVerify.Title'" />
  6. <view class="dialog-close" @click="close">
  7. <text>×</text>
  8. </view>
  9. </view>
  10. <view class="qrcode-page">
  11. <view class="container">
  12. <view class="title" v-t="'PersonalManagement.CardVerify.UploadTitle'"></view>
  13. <!-- 说明 -->
  14. <uni-file-picker limit="9" :title="t('PersonalManagement.CardVerify.UploadTip')"
  15. @select="fileSelect" @delete="fileDelete"></uni-file-picker>
  16. <!-- 邮箱验证码部分 -->
  17. <view>
  18. <view class="code-input-wrapper">
  19. <view class="code-input">
  20. <cwg-input v-model:value="cardEmailCode" :label="t('newSignup.item9')"
  21. fkey="cardEmailCode" type="text" :required="true" rulesKey="cardEmailCode"
  22. :placeholder="t('newSignup.item10')" @change="handleChange" />
  23. </view>
  24. <view class="get-code-btn1">
  25. <view class="ok-button">
  26. <u-button type="primary" block>{{ getCodeString }}</u-button>
  27. </view>
  28. </view>
  29. <view class="get-code-btn">
  30. <view class="cwg-button">
  31. <u-button type="primary" block @click="handleGetCode">{{ getCodeString }}</u-button>
  32. </view>
  33. </view>
  34. </view>
  35. </view>
  36. <view class="notice">
  37. <view class="notice-title">
  38. <text class="icon">ⓘ</text>
  39. <text>{{ t('PersonalManagement.CardVerify.NoticeTitle') }}</text>
  40. </view>
  41. <view class="notice-list">
  42. <text v-for="(item, index) in noticeItems" :key="index" class="notice-item">
  43. {{ index + 1 }}. {{ item }}
  44. </text>
  45. </view>
  46. </view>
  47. <!-- 演示视频 -->
  48. <cwg-video-player :video-url="videoUrl"></cwg-video-player>
  49. </view>
  50. </view>
  51. <view class="dialog-footer">
  52. <view class="btn btn-cancel" @click="close">{{ t('Btn.Cancel') }}</view>
  53. <view class="btn btn-confirm" @click="submit">{{ t('Btn.Confirm') }}</view>
  54. </view>
  55. </view>
  56. </uni-popup>
  57. </template>
  58. <script setup lang="ts">
  59. import { ref, computed, nextTick } from 'vue'
  60. import { useI18n } from 'vue-i18n'
  61. import { customApi } from '@/service/custom';
  62. import { showToast } from "@/utils/toast";
  63. import config from '@/config';
  64. import { userToken } from '@/composables/config'
  65. import { useEmailCountdown } from '@/hooks/useEmailCountdown';
  66. const {
  67. time,
  68. text: getCodeString,
  69. canSend,
  70. start,
  71. restore
  72. } = useEmailCountdown()
  73. const { t, locale } = useI18n()
  74. const cardEmailCode = ref('')
  75. const form = ref({
  76. bankId: null,
  77. email: ''
  78. })
  79. const emit = defineEmits(["success"]);
  80. // 发送邮箱验证码
  81. async function sendEmailCode() {
  82. try {
  83. if (!form.value.bankId) {
  84. showToast(t("PersonalManagement.CardVerify.MissingBankId"));
  85. return false;
  86. }
  87. const res = await customApi.customBankCardSendCode({
  88. bankId: form.value.bankId
  89. });
  90. if (res.code === 200) {
  91. if (res.data && (res.data.emailCode || res.data.code)) {
  92. cardEmailCode.value = res.data.emailCode || res.data.code;
  93. }
  94. start()
  95. return true;
  96. } else {
  97. showToast(t("Msg.CodeFail"));
  98. return false;
  99. }
  100. } catch (error: any) {
  101. console.log(error, 12);
  102. showToast(t("Msg.CodeFail"));
  103. return false;
  104. }
  105. }
  106. async function handleGetCode() {
  107. if (!canSend.value) return
  108. await sendEmailCode();
  109. }
  110. // 视频URL
  111. const videoUrl = computed(() => {
  112. const lang = locale.value || 'en'
  113. const videos = {
  114. cn: "https://player.vimeo.com/video/1152417528?badge=0&autopause=0&player_id=0&app_id=58479",
  115. zhHant: "https://player.vimeo.com/video/1152417614?badge=0&autopause=0&player_id=0&app_id=58479",
  116. en: "https://player.vimeo.com/video/1152417671?badge=0&autopause=0&player_id=0&app_id=58479",
  117. }
  118. return videos[lang] || videos.en
  119. })
  120. // uni-file-picker 相关
  121. const selectedFiles = ref([]) // 选择的文件列表
  122. const uploadedFiles = ref([]) // 上传成功的文件列表
  123. // 选择文件
  124. const fileSelect = async (e) => {
  125. selectedFiles.value = e.tempFiles
  126. for (const file of e.tempFiles) {
  127. await uploadFile(file)
  128. }
  129. }
  130. // 上传文件
  131. const uploadFile = (file) => {
  132. return new Promise((resolve, reject) => {
  133. const tempFile = file.path || file.url
  134. uni.uploadFile({
  135. url: config.Host80 + '/custom/bank/upload',
  136. filePath: tempFile,
  137. name: 'file',
  138. header: {
  139. 'Access-Token': userToken.value
  140. },
  141. success: (uploadRes) => {
  142. const data = JSON.parse(uploadRes.data)
  143. console.log(data, 1111);
  144. if (data.code === 200) {
  145. // 保存上传成功后的文件信息
  146. uploadedFiles.value.push(data.data)
  147. resolve(data)
  148. } else {
  149. uni.showToast({
  150. title: data.msg || '上传失败',
  151. icon: 'none'
  152. })
  153. reject(new Error(data.msg))
  154. }
  155. },
  156. fail: (err) => {
  157. uni.showToast({
  158. title: '上传失败',
  159. icon: 'none'
  160. })
  161. reject(err)
  162. }
  163. })
  164. })
  165. }
  166. // 删除文件
  167. const fileDelete = (e) => {
  168. const index = uploadedFiles.value.findIndex(f => f.uuid === e.tempFile.uuid)
  169. if (index !== -1) {
  170. uploadedFiles.value.splice(index, 1)
  171. }
  172. }
  173. // 说明项
  174. const noticeItems = computed(() => [
  175. t('PersonalManagement.CardVerify.NoticeItem1'),
  176. t('PersonalManagement.CardVerify.NoticeItem2'),
  177. t('PersonalManagement.CardVerify.NoticeItem3'),
  178. t('PersonalManagement.CardVerify.NoticeItem4'),
  179. t('PersonalManagement.CardVerify.NoticeItem5'),
  180. t('PersonalManagement.CardVerify.NoticeItem6'),
  181. t('PersonalManagement.CardVerify.NoticeItem7')
  182. ])
  183. const cardRef = ref(null)
  184. // 打开弹窗
  185. const open = async (e, item) => {
  186. form.value = { ...item, bankId: item.id }
  187. console.log(item, 2222);
  188. await nextTick();
  189. restore()
  190. cardRef.value?.open();
  191. };
  192. // 关闭弹窗
  193. const close = () => {
  194. cardRef.value?.close();
  195. };
  196. const submit = async () => {
  197. if (!cardEmailCode.value) {
  198. showToast(t("vaildate.emailCode.empty"));
  199. return;
  200. }
  201. try {
  202. const res = await customApi.customBankCardVerify({
  203. bankId: form.value.bankId,
  204. emailCode: cardEmailCode.value,
  205. fileList: uploadedFiles.value
  206. });
  207. if (res.code === 200) {
  208. showToast(res.msg);
  209. close();
  210. emit("success");
  211. } else {
  212. showToast(res.msg || t("common.error"));
  213. }
  214. } catch (error) {
  215. showToast(t("common.error"));
  216. }
  217. };
  218. // 暴露方法
  219. defineExpose({
  220. open,
  221. close
  222. });
  223. </script>
  224. <style lang="scss" scoped>
  225. .dialog-container {
  226. width: 90vw;
  227. max-width: px2rpx(800);
  228. max-height: 85vh;
  229. background: #fff;
  230. overflow: hidden;
  231. display: flex;
  232. flex-direction: column;
  233. .dialog-header {
  234. display: flex;
  235. justify-content: space-between;
  236. align-items: center;
  237. padding: px2rpx(20) px2rpx(24);
  238. background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  239. flex-shrink: 0;
  240. .dialog-title {
  241. font-size: px2rpx(20);
  242. font-weight: 700;
  243. color: #fff;
  244. letter-spacing: 0.5px;
  245. }
  246. .dialog-close {
  247. width: px2rpx(36);
  248. height: px2rpx(36);
  249. display: flex;
  250. align-items: center;
  251. justify-content: center;
  252. font-size: px2rpx(32);
  253. color: rgba(255, 255, 255, 0.9);
  254. cursor: pointer;
  255. transition: all 0.3s;
  256. border-radius: 50%;
  257. background: rgba(255, 255, 255, 0.1);
  258. &:hover {
  259. background: rgba(255, 255, 255, 0.2);
  260. transform: rotate(90deg);
  261. }
  262. &:active {
  263. transform: rotate(90deg) scale(0.9);
  264. }
  265. }
  266. }
  267. .dialog-footer {
  268. display: flex;
  269. gap: px2rpx(12);
  270. justify-content: space-around;
  271. padding: px2rpx(16);
  272. border-top: 1px solid #f3f4f6;
  273. .btn {
  274. min-width: px2rpx(120);
  275. padding: px2rpx(12) px2rpx(24);
  276. border-radius: px2rpx(6);
  277. font-size: px2rpx(14);
  278. font-weight: 600;
  279. border: none;
  280. box-sizing: border-box;
  281. cursor: pointer;
  282. text-align: center;
  283. transition: all 0.3s;
  284. display: flex;
  285. align-items: center;
  286. justify-content: center;
  287. &.btn-cancel {
  288. background: #f3f4f6;
  289. color: #6b7280;
  290. &:hover {
  291. background: #e5e7eb;
  292. }
  293. &:active {
  294. background: #d1d5db;
  295. }
  296. }
  297. &.btn-confirm {
  298. background: #ea2027;
  299. color: #fff;
  300. &:hover {
  301. background: #d11920;
  302. }
  303. &:active {
  304. background: #c01819;
  305. }
  306. }
  307. }
  308. }
  309. }
  310. .qrcode-page {
  311. flex: 1;
  312. overflow-y: auto;
  313. background: #f8f9fa;
  314. .container {
  315. padding: px2rpx(32);
  316. .title {
  317. font-size: px2rpx(18);
  318. font-weight: 600;
  319. color: #2c3e50;
  320. text-align: center;
  321. margin-bottom: px2rpx(24);
  322. padding-bottom: px2rpx(16);
  323. border-bottom: 2px solid #e9ecef;
  324. }
  325. .qrcode-wrapper {
  326. display: flex;
  327. justify-content: center;
  328. align-items: center;
  329. margin-bottom: px2rpx(32);
  330. padding: px2rpx(24);
  331. background: #fff;
  332. border-radius: px2rpx(12);
  333. box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
  334. .qrcode {
  335. width: px2rpx(240);
  336. height: px2rpx(240);
  337. }
  338. }
  339. .notice {
  340. background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
  341. border-radius: px2rpx(12);
  342. padding: px2rpx(24);
  343. margin-bottom: px2rpx(32);
  344. box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
  345. border-left: 4px solid #667eea;
  346. .notice-title {
  347. display: flex;
  348. align-items: center;
  349. gap: px2rpx(8);
  350. font-size: px2rpx(16);
  351. font-weight: 700;
  352. color: #2c3e50;
  353. margin-bottom: px2rpx(16);
  354. .icon {
  355. width: px2rpx(24);
  356. height: px2rpx(24);
  357. display: flex;
  358. align-items: center;
  359. justify-content: center;
  360. background: #667eea;
  361. color: #fff;
  362. border-radius: 50%;
  363. font-size: px2rpx(16);
  364. font-weight: bold;
  365. }
  366. }
  367. .notice-list {
  368. .notice-item {
  369. display: block;
  370. font-size: px2rpx(14);
  371. color: #495057;
  372. line-height: 1.8;
  373. margin-bottom: px2rpx(10);
  374. padding-left: px2rpx(8);
  375. position: relative;
  376. &:last-child {
  377. margin-bottom: 0;
  378. }
  379. &::before {
  380. content: '';
  381. position: absolute;
  382. left: 0;
  383. top: px2rpx(10);
  384. width: px2rpx(4);
  385. height: px2rpx(4);
  386. background: #667eea;
  387. border-radius: 50%;
  388. }
  389. }
  390. }
  391. }
  392. .video-section {
  393. background: #fff;
  394. border-radius: px2rpx(12);
  395. padding: px2rpx(24);
  396. box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
  397. .video-title {
  398. font-size: px2rpx(16);
  399. font-weight: 600;
  400. color: #2c3e50;
  401. margin-bottom: px2rpx(16);
  402. display: flex;
  403. align-items: center;
  404. gap: px2rpx(8);
  405. &::before {
  406. content: '';
  407. width: px2rpx(4);
  408. height: px2rpx(18);
  409. background: linear-gradient(180deg, #667eea 0%, #764ba2 100%);
  410. border-radius: px2rpx(2);
  411. }
  412. }
  413. .video-wrapper {
  414. width: 100%;
  415. border-radius: px2rpx(8);
  416. overflow: hidden;
  417. background: #000;
  418. box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  419. video {
  420. width: 100%;
  421. height: px2rpx(300);
  422. display: block;
  423. }
  424. }
  425. }
  426. }
  427. }
  428. // 验证码区域
  429. .code-input-label {
  430. font-size: var(--font-size-16);
  431. line-height: px2rpx(44);
  432. letter-spacing: px2rpx(1);
  433. color: #474747;
  434. }
  435. .code-input-wrapper {
  436. position: relative;
  437. display: flex;
  438. align-items: center;
  439. }
  440. .code-input {
  441. flex: 1;
  442. }
  443. .get-code-btn1 {
  444. min-width: px2rpx(100);
  445. margin-left: px2rpx(8);
  446. .ok-button {
  447. .u-button {
  448. background-color: var(--color-white);
  449. opacity: 0;
  450. }
  451. }
  452. }
  453. .get-code-btn {
  454. position: absolute;
  455. right: 0;
  456. bottom: px2rpx(12);
  457. min-width: px2rpx(100);
  458. z-index: 1;
  459. margin-left: px2rpx(8);
  460. .cwg-button {
  461. margin: 0;
  462. }
  463. .cwg-button .u-button {
  464. border-radius: px2rpx(8);
  465. height: px2rpx(46) !important;
  466. }
  467. }
  468. /* 移动端优化 */
  469. @media screen and (max-width: 768px) {
  470. .dialog-container {
  471. width: 95vw;
  472. max-height: 90vh;
  473. }
  474. .qrcode-page .container {
  475. padding: px2rpx(20);
  476. .qrcode-wrapper .qrcode {
  477. width: px2rpx(200);
  478. height: px2rpx(200);
  479. }
  480. .video-section .video-wrapper video {
  481. height: px2rpx(240);
  482. }
  483. }
  484. }
  485. /* 滚动条美化 */
  486. .qrcode-page::-webkit-scrollbar {
  487. width: px2rpx(6);
  488. }
  489. .qrcode-page::-webkit-scrollbar-track {
  490. background: #f1f1f1;
  491. }
  492. .qrcode-page::-webkit-scrollbar-thumb {
  493. background: #c1c1c1;
  494. border-radius: px2rpx(3);
  495. &:hover {
  496. background: #a8a8a8;
  497. }
  498. }
  499. </style>