fix:bug scan
All checks were successful
构建并部署前端到生产环境 / build-and-deploy (push) Successful in 55s

This commit is contained in:
luo
2026-06-26 14:59:15 +08:00
parent 60fa91ea25
commit 4dc86889c5
5 changed files with 183 additions and 15 deletions

View File

@@ -1,11 +1,12 @@
import request from '@/utils/request.js'; import request from '@/utils/request.js';
export const realnameApi = { export const realnameApi = {
getLink(identifier, iccid) { getLink(identifier, iccid, options = {}) {
return request({ return request({
url: '/api/c/v1/realname/link', url: '/api/c/v1/realname/link',
method: 'GET', method: 'GET',
data: { identifier, iccid } data: { identifier, iccid },
...options
}); });
} }
}; };

View File

@@ -6,6 +6,7 @@
<title></title> <title></title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/misans@4.1.0/lib/Normal/MiSans-Regular.min.css"/> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/misans@4.1.0/lib/Normal/MiSans-Regular.min.css"/>
<script src="https://res.wx.qq.com/open/js/jweixin-1.6.0.js"></script> <script src="https://res.wx.qq.com/open/js/jweixin-1.6.0.js"></script>
<script>window.__WX_ENTRY_URL__ = window.location.href.split('#')[0]</script>
</head> </head>
<body> <body>
<div id="app"><!--app-html--></div> <div id="app"><!--app-html--></div>

View File

@@ -114,22 +114,25 @@
}; };
const doRealName = async () => { const doRealName = async () => {
const iccid = currentModalIccid.value;
closeModal();
try { try {
const data = await realnameApi.getLink(userStore.state.identifier, currentModalIccid.value); const data = await realnameApi.getLink(userStore.state.identifier, iccid, { showError: false });
if (data.realname_url) { if (data.realname_url) {
uni.setClipboardData({ uni.setClipboardData({
data: currentModalIccid.value, data: iccid,
success: () => { success: () => {
uni.showToast({ title: 'ICCID已复制', icon: 'success' }); uni.showToast({ title: 'ICCID已复制', icon: 'success' });
} }
}); });
closeModal();
setTimeout(() => { setTimeout(() => {
window.location.href = data.realname_url; window.location.href = data.realname_url;
}, 1500); }, 1500);
} }
} catch (e) { } catch (e) {
console.error('获取实名链接失败', e); console.error('获取实名链接失败', e);
uni.showToast({ title: e?.msg || '获取实名链接失败', icon: 'none' });
} }
}; };

View File

@@ -35,6 +35,20 @@
<up-button class="btn-apple btn-success" v-else type="success" @tap="switchOperator(item)" :loading="switching"> <up-button class="btn-apple btn-success" v-else type="success" @tap="switchOperator(item)" :loading="switching">
切换此运营商 切换此运营商
</up-button> </up-button>
<up-button class="btn-apple btn-success" v-if="item.real_name_status !== 1" type="success" @tap="toReal(item)">
去实名
</up-button>
</view>
</view>
<view class="modal-overlay" v-if="showIccidModal" @tap="closeModal">
<view class="modal-content" @tap.stop>
<view class="modal-close" @tap="closeModal"></view>
<view class="modal-body">
<view class="modal-title">实名认证</view>
<view class="iccid-value">{{ currentModalIccid }}</view>
<view class="modal-button" @tap="doRealName">点击复制ICCID并跳转实名</view>
</view>
</view> </view>
</view> </view>
</view> </view>
@@ -42,7 +56,7 @@
<script setup> <script setup>
import { reactive, ref, onMounted } from 'vue'; import { reactive, ref, onMounted } from 'vue';
import { assetApi, deviceApi } from '@/api/index.js'; import { assetApi, deviceApi, realnameApi } from '@/api/index.js';
import { useUserStore } from '@/store/index.js'; import { useUserStore } from '@/store/index.js';
const userStore = useUserStore(); const userStore = useUserStore();
@@ -50,6 +64,8 @@
let mchList = reactive([]); let mchList = reactive([]);
let loading = ref(false); let loading = ref(false);
let switching = ref(false); let switching = ref(false);
let showIccidModal = ref(false);
let currentModalIccid = ref('');
let opratorList = reactive([ let opratorList = reactive([
{ category: '124', logo: 'https://img2.baidu.com/it/u=139558247,3893370039&fm=253&fmt=auto?w=529&h=500', name: '中国电信' }, { category: '124', logo: 'https://img2.baidu.com/it/u=139558247,3893370039&fm=253&fmt=auto?w=529&h=500', name: '中国电信' },
@@ -120,6 +136,38 @@
switching.value = false; switching.value = false;
}; };
const toReal = (card) => {
currentModalIccid.value = card.iccid;
showIccidModal.value = true;
};
const closeModal = () => {
showIccidModal.value = false;
};
const doRealName = async () => {
const iccid = currentModalIccid.value;
closeModal();
try {
const data = await realnameApi.getLink(userStore.state.identifier, iccid, { showError: false });
if (data.realname_url) {
uni.setClipboardData({
data: iccid,
success: () => {
uni.showToast({ title: 'ICCID已复制', icon: 'success' });
}
});
setTimeout(() => {
window.location.href = data.realname_url;
}, 1500);
}
} catch (e) {
console.error('获取实名链接失败', e);
uni.showToast({ title: e?.msg || '获取实名链接失败', icon: 'none' });
}
};
onMounted(() => { onMounted(() => {
loadCards(); loadCards();
}); });
@@ -153,12 +201,83 @@
background: var(--gray-100); background: var(--gray-100);
color: var(--text-primary); color: var(--text-primary);
&.btn-primary {
background: var(--primary);
color: var(--text-inverse);
}
&.btn-success { &.btn-success {
background: var(--success); background: var(--success);
color: var(--text-inverse); color: var(--text-inverse);
} }
} }
.modal-overlay {
position: fixed;
top: 0; left: 0; right: 0; bottom: 0;
background: rgba(0, 0, 0, 0.5);
display: flex;
align-items: center;
justify-content: center;
z-index: 9999;
}
.modal-content {
background: var(--bg-primary);
border-radius: var(--radius-large);
width: 620rpx;
max-width: 90%;
overflow: hidden;
position: relative;
}
.modal-close {
position: absolute;
top: 24rpx; left: 24rpx;
width: 48rpx; height: 48rpx;
display: flex;
align-items: center;
justify-content: center;
font-size: 36rpx;
color: var(--gray-600);
cursor: pointer;
}
.modal-body {
padding: 60rpx 32rpx 32rpx;
display: flex;
flex-direction: column;
align-items: center;
gap: 32rpx;
}
.modal-title {
font-size: 32rpx;
font-weight: 600;
color: var(--text-primary);
text-align: center;
}
.iccid-value {
font-size: 40rpx;
font-weight: bold;
color: var(--primary);
text-align: center;
word-break: break-all;
line-height: 1.4;
}
.modal-button {
padding: 24rpx 32rpx;
background: var(--success);
color: var(--text-inverse);
font-size: 28rpx;
font-weight: 500;
text-align: center;
border-radius: var(--radius-small);
cursor: pointer;
}
.empty-state { .empty-state {
display: flex; display: flex;
flex-direction: column; flex-direction: column;

View File

@@ -1,16 +1,47 @@
// utils/wxsdk.js —— 封装微信扫一扫 不用旧的了 // utils/wxsdk.js —— 封装微信扫一扫 不用旧的了
import { wechatApi } from '@/api/index.js' import { wechatApi } from '@/api/index.js'
const wx = window.jWeixin const getWx = () => window.jWeixin || window.wx
const entryUrl = window.__WX_ENTRY_URL__ || window.location.href.split('#')[0]
let configPromise = null
let configUrl = ''
let configReady = false
const isIOS = () => /iphone|ipad|ipod/i.test(navigator.userAgent)
const getConfigUrl = () => {
// iOS 微信 WebView 的 JS-SDK 签名 URL 需要使用 SPA 首次进入的地址。
if (isIOS()) {
return entryUrl
}
return window.location.href.split('#')[0]
}
/** /**
* 初始化微信 JS-SDK * 初始化微信 JS-SDK
*/ */
export async function initWxConfig() { export async function initWxConfig() {
const url = window.location.href.split('#')[0] const wx = getWx()
if (!wx) {
throw new Error('微信 SDK 未加载')
}
const url = getConfigUrl()
console.log(url); console.log(url);
try {
const data = await wechatApi.getJssdkConfig(url) if (configReady && configUrl === url) {
return
}
if (configPromise && configUrl === url) {
return configPromise
}
configUrl = url
configReady = false
configPromise = wechatApi.getJssdkConfig(url).then((data) => {
const { app_id, timestamp, nonce_str, signature } = data const { app_id, timestamp, nonce_str, signature } = data
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
@@ -24,24 +55,37 @@ export async function initWxConfig() {
}) })
wx.ready(() => { wx.ready(() => {
console.log('微信 SDK 就绪') console.log('微信 SDK 就绪')
configReady = true
resolve() resolve()
}) })
wx.error((err) => { wx.error((err) => {
console.error('wx.config 失败', err) console.error('wx.config 失败', err)
configReady = false
configPromise = null
reject(err) reject(err)
}) })
}) })
} catch (e) { }).catch((e) => {
console.error('获取微信签名失败', e) console.error('获取微信签名失败', e)
configPromise = null
configReady = false
throw e throw e
} })
return configPromise
} }
/** /**
* 调起微信扫一扫 * 调起微信扫一扫
* @returns {Promise<string>} 扫码结果字符串 * @returns {Promise<string>} 扫码结果字符串
*/ */
export function wxScan() { export async function wxScan() {
await initWxConfig()
const wx = getWx()
if (!wx) {
throw new Error('微信 SDK 未加载')
}
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
wx.scanQRCode({ wx.scanQRCode({
needResult: 1, needResult: 1,