Files
device-voice-h5/pages/switch/switch.vue
luo 49175f8a73
All checks were successful
构建并部署前端到生产环境 / build-and-deploy (push) Successful in 1m2s
fix: ui
2026-07-30 14:22:20 +08:00

402 lines
9.6 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<template>
<view class="container">
<view v-if="mchList.length === 0 && !loading" class="empty-state">
<image class="empty-icon" src="/static/change.png" mode="aspectFit" alt="切换运营商"></image>
<view class="empty-title">运营商列表为空</view>
<view class="empty-desc">当前设备暂无可切换的运营商</view>
</view>
<view class="card carrier-card" v-for="item in mchList" :key="item.iccid">
<view class="carrier-main">
<view class="carrier-left">
<view class="carrier-logo">
<image :src="getCarrier(item.carrier_type).logo" mode="aspectFit"></image>
</view>
<view class="carrier-name">{{ getCarrier(item.carrier_type).name }}</view>
<view class="carrier-iccid">
<text class="field-label">ICCID</text>
<text class="iccid-value-text">{{ item.iccid }}</text>
</view>
<view class="carrier-statuses">
<up-tag :type="item.real_name_status === 1 ? 'primary' : 'success'" size="mini">
{{ item.real_name_status === 1 ? '已实名' : '未实名' }}
</up-tag>
<up-tag v-if="item.network_status" type="info" size="mini">{{ item.network_status }}</up-tag>
</view>
</view>
<view class="carrier-right">
<view class="slot-panel">
<image class="slot-icon" :src="getSlotIcon(item.slot_position)" mode="aspectFit"></image>
<text class="slot-label">卡槽 {{ item.slot_position || '-' }}</text>
</view>
<view class="card-actions">
<button v-if="item.is_current" class="btn-apple btn-primary action-button" disabled>当前使用</button>
<button v-else class="btn-apple btn-primary action-button" :disabled="switching" @tap="switchOperator(item)">
切换此运营商
</button>
<button v-if="item.real_name_status !== 1" class="btn-apple btn-secondary action-button" @tap="toReal(item)">
去实名
</button>
</view>
</view>
</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>
</template>
<script setup>
import { reactive, ref, onMounted } from 'vue';
import { assetApi, deviceApi, realnameApi } from '@/api/index.js';
import { useUserStore } from '@/store/index.js';
const userStore = useUserStore();
let mchList = reactive([]);
let loading = ref(false);
let switching = ref(false);
let showIccidModal = ref(false);
let currentModalIccid = ref('');
const carrierMap = {
CMCC: '中国移动',
CUCC: '中国联通',
CTCC: '中国电信',
CBN: '中国广电'
};
const carrierLogoMap = {
CMCC: '/static/中国移动.png',
CUCC: '/static/中国联通.png',
CTCC: '/static/中国电信.png',
CBN: '/static/中国广电.png'
};
const slotIconMap = {
1: '/static/卡槽1.png',
2: '/static/卡槽2.png',
3: '/static/卡槽3.png'
};
const getCarrier = (carrierType) => {
return {
name: carrierMap[carrierType] || '-',
logo: carrierLogoMap[carrierType] || carrierLogoMap.CMCC
};
};
const getSlotIcon = (slotPosition) => slotIconMap[Number(slotPosition)] || slotIconMap[1];
const loadCards = async () => {
loading.value = true;
try {
const assetData = await assetApi.getInfo(userStore.state.identifier);
// 判断是否为设备
if (assetData.asset_type === 'device') {
// 是设备,调用设备卡列表接口
const data = await deviceApi.getCards(userStore.state.identifier);
if (data.cards && data.cards.length > 0) {
mchList.splice(0, mchList.length, ...data.cards.map(card => ({
iccid: card.iccid,
carrier_type: card.carrier_type,
carrier_name: card.carrier_name,
is_current: card.is_active,
real_name_status: card.real_name_status,
network_status: card.network_status,
slot_position: card.slot_position
})));
}
} else {
// 不是设备(单卡),直接使用 asset info 数据,只有一个卡
if (assetData.identifier) {
mchList.splice(0, mchList.length, {
iccid: assetData.identifier,
carrier_type: assetData.carrier_type,
carrier_name: assetData.carrier_name,
is_current: true,
real_name_status: assetData.real_name_status,
network_status: assetData.network_status,
slot_position: 1
});
}
}
} catch (e) {
console.error('加载卡列表失败', e);
}
loading.value = false;
};
const switchOperator = async (item) => {
switching.value = true;
try {
await deviceApi.switchCard(userStore.state.identifier, item.iccid);
uni.showToast({ title: '切换成功3-5分钟后生效', icon: 'success' });
loadCards();
} catch (e) {
console.error('切换运营商失败', e);
}
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(() => {
loadCards();
});
</script>
<style lang="scss" scoped>
.container {
.carrier-card {
padding: 28rpx;
}
.carrier-main {
display: flex;
align-items: stretch;
justify-content: space-between;
gap: 24rpx;
}
.carrier-left {
flex: 1;
min-width: 0;
display: flex;
flex-direction: column;
align-items: flex-start;
}
.carrier-logo {
width: 112rpx;
height: 112rpx;
padding: 10rpx;
box-sizing: border-box;
border-radius: 24rpx;
background: var(--up-primary-light);
image { width: 100%; height: 100%; }
}
.carrier-name {
margin-top: 16rpx;
color: var(--text-primary);
font-size: 30rpx;
font-weight: 600;
line-height: 1.3;
}
.carrier-iccid {
width: 100%;
display: flex;
align-items: flex-start;
gap: 12rpx;
margin-top: 14rpx;
}
.field-label,
.slot-label {
color: var(--text-tertiary);
font-size: 24rpx;
}
.iccid-value-text {
flex: 1;
min-width: 0;
color: var(--text-secondary);
font-size: 24rpx;
line-height: 1.35;
word-break: break-all;
}
.carrier-statuses {
display: flex;
align-items: center;
flex-wrap: wrap;
gap: 10rpx;
margin-top: 14rpx;
}
.carrier-right {
width: 190rpx;
flex-shrink: 0;
display: flex;
flex-direction: column;
align-items: center;
justify-content: space-between;
gap: 20rpx;
}
.slot-panel {
display: flex;
flex-direction: column;
align-items: center;
gap: 8rpx;
}
.slot-icon {
width: 96rpx;
height: 96rpx;
}
.card-actions {
width: 100%;
display: flex;
flex-direction: column;
gap: 12rpx;
}
.action-button {
width: 100%;
height: 64rpx;
padding: 0 12rpx;
font-size: 24rpx;
line-height: 64rpx;
box-sizing: border-box;
&::after { border: none; }
}
}
.btn-apple {
display: inline-flex;
align-items: center;
justify-content: center;
border: none;
border-radius: var(--radius-small);
font-weight: 500;
font-size: 26rpx;
line-height: 1;
cursor: pointer;
padding: 20rpx;
background: var(--gray-100);
color: var(--text-primary);
&.btn-primary {
background: var(--primary);
color: var(--text-inverse);
}
&.btn-success {
background: var(--success);
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 {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
padding: 120rpx 40rpx;
min-height: 400rpx;
.empty-icon { width: 120rpx; height: 120rpx; margin-bottom: 30rpx; opacity: 0.6; }
.empty-title { font-size: 32rpx; font-weight: 600; color: var(--text-primary); margin-bottom: 16rpx; }
.empty-desc { font-size: 26rpx; color: var(--text-tertiary); text-align: center; }
}
</style>