KycAuthDialog.vue 11 KB

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