KycAuthDialog.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425
  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. t('PersonalManagement.KYCVerify.NoticeItem7'),
  139. ])
  140. // 视频错误处理
  141. const onVideoError = (e) => {
  142. console.error('视频加载失败', e)
  143. uni.showToast({
  144. title: '视频加载失败',
  145. icon: 'none'
  146. })
  147. }
  148. const kycRef = ref(null)
  149. // 打开弹窗
  150. const open = async (e) => {
  151. await nextTick();
  152. getWebsdkLink(e)
  153. kycRef.value?.open();
  154. };
  155. // 关闭弹窗
  156. const close = () => {
  157. kycRef.value?.close();
  158. };
  159. // 暴露方法
  160. defineExpose({
  161. open,
  162. close
  163. });
  164. </script>
  165. <style lang="scss" scoped>
  166. @import "@/uni.scss";
  167. .dialog-container {
  168. width: 90vw;
  169. max-width: px2rpx(800);
  170. max-height: 85vh;
  171. background: #fff;
  172. overflow: hidden;
  173. display: flex;
  174. flex-direction: column;
  175. .dialog-header {
  176. display: flex;
  177. justify-content: space-between;
  178. align-items: center;
  179. padding: px2rpx(20) px2rpx(24);
  180. background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  181. flex-shrink: 0;
  182. .dialog-title {
  183. font-size: px2rpx(20);
  184. font-weight: 700;
  185. color: #fff;
  186. letter-spacing: 0.5px;
  187. }
  188. .dialog-close {
  189. width: px2rpx(36);
  190. height: px2rpx(36);
  191. display: flex;
  192. align-items: center;
  193. justify-content: center;
  194. font-size: px2rpx(32);
  195. color: rgba(255, 255, 255, 0.9);
  196. cursor: pointer;
  197. transition: all 0.3s;
  198. border-radius: 50%;
  199. background: rgba(255, 255, 255, 0.1);
  200. &:hover {
  201. background: rgba(255, 255, 255, 0.2);
  202. transform: rotate(90deg);
  203. }
  204. &:active {
  205. transform: rotate(90deg) scale(0.9);
  206. }
  207. }
  208. }
  209. }
  210. .qrcode-page {
  211. flex: 1;
  212. overflow-y: auto;
  213. background: #f8f9fa;
  214. .container {
  215. padding: px2rpx(32);
  216. .title {
  217. font-size: px2rpx(18);
  218. font-weight: 600;
  219. color: #2c3e50;
  220. text-align: center;
  221. margin-bottom: px2rpx(24);
  222. padding-bottom: px2rpx(16);
  223. border-bottom: 2px solid #e9ecef;
  224. }
  225. .qrcode-wrapper {
  226. display: flex;
  227. justify-content: center;
  228. align-items: center;
  229. flex-direction: column;
  230. gap: px2rpx(12);
  231. margin-bottom: px2rpx(32);
  232. padding: px2rpx(24);
  233. background: #fff;
  234. border-radius: px2rpx(12);
  235. box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
  236. .qrcode {
  237. width: px2rpx(240);
  238. height: px2rpx(240);
  239. }
  240. .qrcode-url {
  241. display: flex;
  242. justify-content: center;
  243. align-items: center;
  244. gap: px2rpx(8);
  245. .url-text {
  246. max-width: px2rpx(300);
  247. font-size: px2rpx(14);
  248. color: #495057;
  249. line-height: 1.6;
  250. text-align: center;
  251. overflow-wrap: break-word;
  252. text-overflow: ellipsis;
  253. white-space: nowrap;
  254. overflow: hidden;
  255. }
  256. @media screen and (max-width: 768px) {
  257. .url-text {
  258. max-width: px2rpx(200);
  259. }
  260. }
  261. }
  262. }
  263. .notice {
  264. background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
  265. border-radius: px2rpx(12);
  266. padding: px2rpx(24);
  267. margin-bottom: px2rpx(32);
  268. box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
  269. border-left: 4px solid #667eea;
  270. .notice-title {
  271. display: flex;
  272. align-items: center;
  273. gap: px2rpx(8);
  274. font-size: px2rpx(16);
  275. font-weight: 700;
  276. color: #2c3e50;
  277. margin-bottom: px2rpx(16);
  278. .icon {
  279. width: px2rpx(24);
  280. height: px2rpx(24);
  281. display: flex;
  282. align-items: center;
  283. justify-content: center;
  284. background: #667eea;
  285. color: var(--bs-emphasis-color);
  286. border-radius: 50%;
  287. font-size: px2rpx(16);
  288. font-weight: bold;
  289. }
  290. }
  291. .notice-list {
  292. .notice-item {
  293. display: block;
  294. font-size: px2rpx(14);
  295. color: #495057;
  296. line-height: 1.8;
  297. margin-bottom: px2rpx(10);
  298. padding-left: px2rpx(8);
  299. position: relative;
  300. &:last-child {
  301. margin-bottom: 0;
  302. }
  303. &::before {
  304. content: '';
  305. position: absolute;
  306. left: 0;
  307. top: px2rpx(10);
  308. width: px2rpx(4);
  309. height: px2rpx(4);
  310. background: #667eea;
  311. border-radius: 50%;
  312. }
  313. }
  314. }
  315. }
  316. .video-section {
  317. background: #fff;
  318. border-radius: px2rpx(12);
  319. padding: px2rpx(24);
  320. box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
  321. .video-title {
  322. font-size: px2rpx(16);
  323. font-weight: 600;
  324. color: #2c3e50;
  325. margin-bottom: px2rpx(16);
  326. display: flex;
  327. align-items: center;
  328. gap: px2rpx(8);
  329. &::before {
  330. content: '';
  331. width: px2rpx(4);
  332. height: px2rpx(18);
  333. background: linear-gradient(180deg, #667eea 0%, #764ba2 100%);
  334. border-radius: px2rpx(2);
  335. }
  336. }
  337. .video-wrapper {
  338. width: 100%;
  339. border-radius: px2rpx(8);
  340. overflow: hidden;
  341. background: #000;
  342. box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  343. video {
  344. width: 100%;
  345. height: px2rpx(300);
  346. display: block;
  347. }
  348. }
  349. }
  350. }
  351. }
  352. /* 移动端优化 */
  353. @media screen and (max-width: 768px) {
  354. .dialog-container {
  355. width: 95vw;
  356. max-height: 90vh;
  357. }
  358. .qrcode-page .container {
  359. padding: px2rpx(20);
  360. .qrcode-wrapper .qrcode {
  361. width: px2rpx(200);
  362. height: px2rpx(200);
  363. }
  364. .video-section .video-wrapper video {
  365. height: px2rpx(240);
  366. }
  367. }
  368. }
  369. /* 滚动条美化 */
  370. .qrcode-page::-webkit-scrollbar {
  371. width: px2rpx(6);
  372. }
  373. .qrcode-page::-webkit-scrollbar-track {
  374. background: #f1f1f1;
  375. }
  376. .qrcode-page::-webkit-scrollbar-thumb {
  377. background: #c1c1c1;
  378. border-radius: px2rpx(3);
  379. &:hover {
  380. background: #a8a8a8;
  381. }
  382. }
  383. </style>