KycAuthDialog.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419
  1. <template>
  2. <uni-popup ref="kycRef" type="center" background-color="#fff" style="z-index: 999">
  3. <view class="dialog-container">
  4. <view class="dialog-header">
  5. <text class="dialog-title">{{ t('blockchain.item2') }}</text>
  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">{{ t('ApplicationDialog.Des11') }}</view>
  13. <!-- 二维码 -->
  14. <view class="qrcode-wrapper" v-if="qrCodeUrl">
  15. <QrCode v-if="qrCodeUrl" :text="qrCodeUrl"></QrCode>
  16. <view class="qrcode-url">
  17. <view class="url-text cursor-pointer" @click="openExternalUrl(qrCodeUrl)">{{ qrCodeUrl }}
  18. </view>
  19. <cwg-icon name="copy" class="cursor-pointer" :size="20" @click="copyUrl" />
  20. </view>
  21. </view>
  22. <!-- 说明 -->
  23. <view class="notice">
  24. <view class="notice-title">
  25. <text class="icon">ⓘ</text>
  26. <text>{{ t('PersonalManagement.KYCVerify.NoticeTitle') }}</text>
  27. </view>
  28. <view class="notice-list">
  29. <text v-for="(item, index) in noticeItems" :key="index" class="notice-item">
  30. {{ index + 1 }}. {{ item }}
  31. </text>
  32. </view>
  33. </view>
  34. <!-- 演示视频 -->
  35. <cwg-video-player :video-url="videoUrl"></cwg-video-player>
  36. </view>
  37. </view>
  38. </view>
  39. </uni-popup>
  40. </template>
  41. <script setup lang="ts">
  42. import { ref, computed, nextTick } from 'vue'
  43. import { useI18n } from 'vue-i18n'
  44. import { customApi } from '@/service/custom';
  45. import QrCode from "@/components/QrCode.vue";
  46. import { openExternalUrl } from '@/utils/openExternalUrl';
  47. const { t, locale } = useI18n()
  48. // 二维码链接
  49. const qrCodeUrl = ref("");
  50. // 复制链接
  51. const copyUrl = () => {
  52. uni.setClipboardData({
  53. data: qrCodeUrl.value,
  54. success: () => {
  55. uni.showToast({
  56. title: t('Btn.item8'),
  57. icon: "success",
  58. });
  59. },
  60. });
  61. };
  62. // API 响应码
  63. const responseCode = ref(200);
  64. // 设备元信息
  65. const metaInfo = ref<Record<string, any> | null>(null);
  66. /**
  67. * 获取设备元信息
  68. */
  69. function getMetaInfo() {
  70. try {
  71. // 安全获取 metaInfo,兼容不同环境
  72. if (typeof window !== "undefined" && (window as any).getMetaInfo) {
  73. metaInfo.value = (window as any).getMetaInfo();
  74. metaInfo.value = { ...metaInfo.value, deviceType: "h5" };
  75. } else {
  76. // 默认值
  77. metaInfo.value = { deviceType: "h5" };
  78. }
  79. } catch (error) {
  80. // console.warn("获取设备信息失败:", error);
  81. metaInfo.value = { deviceType: "h5" };
  82. }
  83. }
  84. /**
  85. * 获取 WebSDK 链接
  86. * @param cardId 卡片ID
  87. */
  88. async function getWebsdkLink(bankId) {
  89. if (!bankId) {
  90. console.warn("bankId 为空,无法获取 WebSDK 链接");
  91. return;
  92. }
  93. try {
  94. // 获取设备信息
  95. getMetaInfo();
  96. // 调用 API
  97. const res = await customApi.getWebsdkLink2({
  98. bankId,
  99. metaInfo: metaInfo.value,
  100. });
  101. responseCode.value = res.code || 201;
  102. if (res.code === 200 && res.data) {
  103. try {
  104. // 安全解析 JSON
  105. const data = typeof res.data === "string" ? JSON.parse(res.data) : res.data;
  106. qrCodeUrl.value = data.url || data.link || "";
  107. } catch (parseError) {
  108. console.error("解析响应数据失败:", parseError);
  109. responseCode.value = 201;
  110. }
  111. } else {
  112. qrCodeUrl.value = "";
  113. }
  114. } catch (error: any) {
  115. console.error("获取 WebSDK 链接失败:", error);
  116. responseCode.value = 201;
  117. qrCodeUrl.value = "";
  118. }
  119. }
  120. // 视频URL
  121. const videoUrl = computed(() => {
  122. const lang = locale.value || 'en'
  123. const videos = {
  124. cn: "https://player.vimeo.com/video/1153328212?badge=0&autopause=0&player_id=0&app_id=58479",
  125. zh: "https://player.vimeo.com/video/1153328237?badge=0&autopause=0&player_id=0&app_id=58479",
  126. en: "https://player.vimeo.com/video/1153328184?badge=0&autopause=0&player_id=0&app_id=58479"
  127. }
  128. return videos[lang] || videos.en
  129. })
  130. // 说明项
  131. const noticeItems = computed(() => [
  132. t('PersonalManagement.KYCVerify.NoticeItem1'),
  133. t('PersonalManagement.KYCVerify.NoticeItem2'),
  134. t('PersonalManagement.KYCVerify.NoticeItem3'),
  135. t('PersonalManagement.KYCVerify.NoticeItem4'),
  136. t('PersonalManagement.KYCVerify.NoticeItem5'),
  137. t('PersonalManagement.KYCVerify.NoticeItem6')
  138. ])
  139. // 视频错误处理
  140. const onVideoError = (e) => {
  141. console.error('视频加载失败', e)
  142. uni.showToast({
  143. title: '视频加载失败',
  144. icon: 'none'
  145. })
  146. }
  147. const kycRef = ref(null)
  148. // 打开弹窗
  149. const open = async (e) => {
  150. await nextTick();
  151. getWebsdkLink(e)
  152. kycRef.value?.open();
  153. };
  154. // 关闭弹窗
  155. const close = () => {
  156. kycRef.value?.close();
  157. };
  158. // 暴露方法
  159. defineExpose({
  160. open,
  161. close
  162. });
  163. </script>
  164. <style lang="scss" scoped>
  165. @import "@/uni.scss";
  166. .dialog-container {
  167. width: 90vw;
  168. max-width: px2rpx(800);
  169. max-height: 85vh;
  170. background: #fff;
  171. overflow: hidden;
  172. display: flex;
  173. flex-direction: column;
  174. .dialog-header {
  175. display: flex;
  176. justify-content: space-between;
  177. align-items: center;
  178. padding: px2rpx(20) px2rpx(24);
  179. background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  180. flex-shrink: 0;
  181. .dialog-title {
  182. font-size: px2rpx(20);
  183. font-weight: 700;
  184. color: #fff;
  185. letter-spacing: 0.5px;
  186. }
  187. .dialog-close {
  188. width: px2rpx(36);
  189. height: px2rpx(36);
  190. display: flex;
  191. align-items: center;
  192. justify-content: center;
  193. font-size: px2rpx(32);
  194. color: rgba(255, 255, 255, 0.9);
  195. cursor: pointer;
  196. transition: all 0.3s;
  197. border-radius: 50%;
  198. background: rgba(255, 255, 255, 0.1);
  199. &:hover {
  200. background: rgba(255, 255, 255, 0.2);
  201. transform: rotate(90deg);
  202. }
  203. &:active {
  204. transform: rotate(90deg) scale(0.9);
  205. }
  206. }
  207. }
  208. }
  209. .qrcode-page {
  210. flex: 1;
  211. overflow-y: auto;
  212. background: #f8f9fa;
  213. .container {
  214. padding: px2rpx(32);
  215. .title {
  216. font-size: px2rpx(18);
  217. font-weight: 600;
  218. color: #2c3e50;
  219. text-align: center;
  220. margin-bottom: px2rpx(24);
  221. padding-bottom: px2rpx(16);
  222. border-bottom: 2px solid #e9ecef;
  223. }
  224. .qrcode-wrapper {
  225. display: flex;
  226. justify-content: center;
  227. align-items: center;
  228. flex-direction: column;
  229. gap: px2rpx(12);
  230. margin-bottom: px2rpx(32);
  231. padding: px2rpx(24);
  232. background: #fff;
  233. border-radius: px2rpx(12);
  234. box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
  235. .qrcode {
  236. width: px2rpx(240);
  237. height: px2rpx(240);
  238. }
  239. .qrcode-url {
  240. display: flex;
  241. justify-content: center;
  242. align-items: center;
  243. gap: px2rpx(8);
  244. .url-text {
  245. max-width: px2rpx(300);
  246. font-size: px2rpx(14);
  247. color: #495057;
  248. line-height: 1.6;
  249. text-align: center;
  250. overflow-wrap: break-word;
  251. text-overflow: ellipsis;
  252. white-space: nowrap;
  253. overflow: hidden;
  254. }
  255. }
  256. }
  257. .notice {
  258. background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
  259. border-radius: px2rpx(12);
  260. padding: px2rpx(24);
  261. margin-bottom: px2rpx(32);
  262. box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
  263. border-left: 4px solid #667eea;
  264. .notice-title {
  265. display: flex;
  266. align-items: center;
  267. gap: px2rpx(8);
  268. font-size: px2rpx(16);
  269. font-weight: 700;
  270. color: #2c3e50;
  271. margin-bottom: px2rpx(16);
  272. .icon {
  273. width: px2rpx(24);
  274. height: px2rpx(24);
  275. display: flex;
  276. align-items: center;
  277. justify-content: center;
  278. background: #667eea;
  279. color: var(--bs-emphasis-color);
  280. border-radius: 50%;
  281. font-size: px2rpx(16);
  282. font-weight: bold;
  283. }
  284. }
  285. .notice-list {
  286. .notice-item {
  287. display: block;
  288. font-size: px2rpx(14);
  289. color: #495057;
  290. line-height: 1.8;
  291. margin-bottom: px2rpx(10);
  292. padding-left: px2rpx(8);
  293. position: relative;
  294. &:last-child {
  295. margin-bottom: 0;
  296. }
  297. &::before {
  298. content: '';
  299. position: absolute;
  300. left: 0;
  301. top: px2rpx(10);
  302. width: px2rpx(4);
  303. height: px2rpx(4);
  304. background: #667eea;
  305. border-radius: 50%;
  306. }
  307. }
  308. }
  309. }
  310. .video-section {
  311. background: #fff;
  312. border-radius: px2rpx(12);
  313. padding: px2rpx(24);
  314. box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
  315. .video-title {
  316. font-size: px2rpx(16);
  317. font-weight: 600;
  318. color: #2c3e50;
  319. margin-bottom: px2rpx(16);
  320. display: flex;
  321. align-items: center;
  322. gap: px2rpx(8);
  323. &::before {
  324. content: '';
  325. width: px2rpx(4);
  326. height: px2rpx(18);
  327. background: linear-gradient(180deg, #667eea 0%, #764ba2 100%);
  328. border-radius: px2rpx(2);
  329. }
  330. }
  331. .video-wrapper {
  332. width: 100%;
  333. border-radius: px2rpx(8);
  334. overflow: hidden;
  335. background: #000;
  336. box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  337. video {
  338. width: 100%;
  339. height: px2rpx(300);
  340. display: block;
  341. }
  342. }
  343. }
  344. }
  345. }
  346. /* 移动端优化 */
  347. @media screen and (max-width: 768px) {
  348. .dialog-container {
  349. width: 95vw;
  350. max-height: 90vh;
  351. }
  352. .qrcode-page .container {
  353. padding: px2rpx(20);
  354. .qrcode-wrapper .qrcode {
  355. width: px2rpx(200);
  356. height: px2rpx(200);
  357. }
  358. .video-section .video-wrapper video {
  359. height: px2rpx(240);
  360. }
  361. }
  362. }
  363. /* 滚动条美化 */
  364. .qrcode-page::-webkit-scrollbar {
  365. width: px2rpx(6);
  366. }
  367. .qrcode-page::-webkit-scrollbar-track {
  368. background: #f1f1f1;
  369. }
  370. .qrcode-page::-webkit-scrollbar-thumb {
  371. background: #c1c1c1;
  372. border-radius: px2rpx(3);
  373. &:hover {
  374. background: #a8a8a8;
  375. }
  376. }
  377. </style>