feat: 新增设备切卡模式
All checks were successful
构建并部署前端到测试环境 / build-and-deploy (push) Successful in 3m57s

This commit is contained in:
sexygoat
2026-04-18 16:40:41 +08:00
parent fd583e81e0
commit c5ee690ccd
16 changed files with 557 additions and 55 deletions

View File

@@ -379,6 +379,7 @@
<!-- 设备操作按钮 -->
<div v-else class="device-operations" style="margin-top: 16px; text-align: right">
<ElButton type="info" @click="handleShowSwitchMode">设置切卡模式</ElButton>
<ElButton type="primary" @click="handleRebootDevice"> 重启设备 </ElButton>
<ElButton type="warning" @click="handleResetDevice"> 恢复出厂 </ElButton>
<ElButton type="success" @click="handleShowSwitchCard"> 切换SIM卡 </ElButton>
@@ -506,6 +507,7 @@
(e: 'resetDevice'): void
(e: 'showSpeedLimit'): void
(e: 'showSwitchCard'): void
(e: 'showSwitchMode'): void
(e: 'show-set-wifi'): void
(e: 'enableBindingCard', payload: { card: BindingCard }): void
(e: 'disableBindingCard', payload: { card: BindingCard }): void
@@ -600,6 +602,10 @@
emit('showSwitchCard')
}
const handleShowSwitchMode = () => {
emit('showSwitchMode')
}
const handleShowSetWiFi = () => {
emit('show-set-wifi')
}

View File

@@ -0,0 +1,94 @@
<template>
<ElDialog v-model="visible" title="设置切卡模式" width="500px">
<ElForm ref="formRef" :model="form" :rules="rules" label-width="120px">
<ElFormItem label="设备标识">
<span style="font-weight: bold; color: #409eff">{{ deviceIdentifier }}</span>
</ElFormItem>
<ElFormItem label="当前模式">
<ElTag :type="currentMode === 0 ? 'success' : 'warning'">
{{ currentMode === 0 ? '自动切卡' : '手动切卡' }}
</ElTag>
</ElFormItem>
<ElFormItem label="切卡模式" prop="switch_mode">
<ElRadioGroup v-model="form.switch_mode">
<ElRadio :value="0">自动切卡</ElRadio>
<ElRadio :value="1">手动切卡</ElRadio>
</ElRadioGroup>
</ElFormItem>
<ElFormItem>
<div style="font-size: 12px; color: #909399; line-height: 1.6">
<p>说明</p>
<p> <strong>自动切卡</strong>设备根据信号强度自动切换到最优的SIM卡</p>
<p> <strong>手动切卡</strong>需要手动触发切换SIM卡操作</p>
</div>
</ElFormItem>
</ElForm>
<template #footer>
<ElButton @click="handleCancel">取消</ElButton>
<ElButton type="primary" @click="handleConfirm" :loading="confirmLoading">确认设置</ElButton>
</template>
</ElDialog>
</template>
<script setup lang="ts">
import { ref, reactive, computed, watch } from 'vue'
import { ElDialog, ElForm, ElFormItem, ElRadioGroup, ElRadio, ElTag } from 'element-plus'
import type { FormInstance, FormRules } from 'element-plus'
interface Props {
modelValue: boolean
deviceIdentifier: string
currentMode?: number
}
interface Emits {
(e: 'update:modelValue', value: boolean): void
(e: 'confirm', data: { switch_mode: number }): void
}
const props = withDefaults(defineProps<Props>(), {
currentMode: 0
})
const emit = defineEmits<Emits>()
const formRef = ref<FormInstance>()
const confirmLoading = ref(false)
const form = reactive({
switch_mode: 0
})
const rules: FormRules = {
switch_mode: [{ required: true, message: '请选择切卡模式', trigger: 'change' }]
}
const visible = computed({
get: () => props.modelValue,
set: (value) => emit('update:modelValue', value)
})
const currentMode = computed(() => props.currentMode ?? 0)
watch(visible, (newVal) => {
if (newVal) {
form.switch_mode = props.currentMode ?? 0
}
})
const handleCancel = () => {
visible.value = false
}
const handleConfirm = async () => {
if (!formRef.value) return
try {
await formRef.value.validate()
emit('confirm', { switch_mode: form.switch_mode })
} catch (error) {
console.error('表单验证失败:', error)
}
}
</script>
<style lang="scss" scoped></style>

View File

@@ -1,5 +1,6 @@
export { default as SpeedLimitDialog } from './SpeedLimitDialog.vue'
export { default as SwitchCardDialog } from './SwitchCardDialog.vue'
export { default as SwitchModeDialog } from './SwitchModeDialog.vue'
export { default as WiFiConfigDialog } from './WiFiConfigDialog.vue'
export { default as PackageRechargeDialog } from './PackageRechargeDialog.vue'
export { default as DailyRecordsDialog } from './DailyRecordsDialog.vue'

View File

@@ -23,6 +23,7 @@
@reboot-device="handleRebootDevice"
@reset-device="handleResetDevice"
@show-switch-card="showSwitchCardDialog"
@show-switch-mode="showSwitchModeDialog"
@show-set-wifi="showSetWiFiDialog"
@enable-binding-card="handleEnableBindingCard"
@disable-binding-card="handleDisableBindingCard"
@@ -88,6 +89,12 @@
:cards="cardInfo?.cards"
@confirm="handleConfirmSwitchCard"
/>
<SwitchModeDialog
v-model="switchModeDialogVisible"
:device-identifier="cardInfo?.virtual_no || ''"
:current-mode="cardInfo?.switch_mode as number"
@confirm="handleConfirmSwitchMode"
/>
<WiFiConfigDialog
v-model="setWiFiDialogVisible"
:card-no="deviceRealtime?.current_iccid"
@@ -127,6 +134,7 @@
// 引入对话框组件
import {
SwitchCardDialog,
SwitchModeDialog,
WiFiConfigDialog,
PackageRechargeDialog,
DailyRecordsDialog,
@@ -183,6 +191,7 @@
// ========== 对话框状态 ==========
const switchCardDialogVisible = ref(false)
const switchModeDialogVisible = ref(false)
const setWiFiDialogVisible = ref(false)
const rechargeDialogVisible = ref(false)
const dailyRecordsDialogVisible = ref(false)
@@ -292,6 +301,33 @@
switchCardDialogVisible.value = false
}
/**
* 显示切换模式对话框
*/
const showSwitchModeDialog = () => {
switchModeDialogVisible.value = true
}
/**
* 确认切换模式
*/
const handleConfirmSwitchMode = async (form: { switch_mode: number }) => {
try {
const { DeviceService } = await import('@/api/modules')
const identifier = cardInfo.value?.virtual_no || ''
const res = await DeviceService.setSwitchMode(identifier, form.switch_mode)
if (res.code === 0) {
ElMessage.success('设置切卡模式成功')
switchModeDialogVisible.value = false
await refreshAsset(cardInfo.value!.identifier, cardInfo.value!.asset_type)
} else {
ElMessage.error(res.msg || '设置切卡模式失败')
}
} catch (error: any) {
console.error('设置切卡模式失败:', error)
}
}
/**
* 显示WiFi配置对话框
*/

View File

@@ -554,6 +554,44 @@
</ElButton>
</template>
</ElDialog>
<!-- 设置切卡模式对话框 -->
<ElDialog v-model="switchModeDialogVisible" title="设置切卡模式" width="500px">
<ElForm
ref="switchModeFormRef"
:model="switchModeForm"
:rules="switchModeRules"
label-width="120px"
>
<ElFormItem label="设备标识">
<span style="font-weight: bold; color: #409eff">{{ currentOperatingDeviceIdentifier }}</span>
</ElFormItem>
<ElFormItem label="当前模式">
<ElTag :type="currentDeviceSwitchMode === 0 ? 'success' : 'warning'">
{{ currentDeviceSwitchMode === 0 ? '自动切卡' : '手动切卡' }}
</ElTag>
</ElFormItem>
<ElFormItem label="切卡模式" prop="switch_mode">
<ElRadioGroup v-model="switchModeForm.switch_mode">
<ElRadio :value="0">自动切卡</ElRadio>
<ElRadio :value="1">手动切卡</ElRadio>
</ElRadioGroup>
</ElFormItem>
<ElFormItem>
<div style="font-size: 12px; color: #909399; line-height: 1.6">
<p>说明</p>
<p> <strong>自动切卡</strong>设备根据信号强度自动切换到最优的SIM卡</p>
<p> <strong>手动切卡</strong>需要手动触发切换SIM卡操作</p>
</div>
</ElFormItem>
</ElForm>
<template #footer>
<ElButton @click="switchModeDialogVisible = false">取消</ElButton>
<ElButton type="primary" @click="handleConfirmSwitchMode" :loading="switchModeLoading">
确认设置
</ElButton>
</template>
</ElDialog>
</ElCard>
</div>
</ArtTableFullScreen>
@@ -704,6 +742,19 @@
]
})
// 切换模式相关
const switchModeDialogVisible = ref(false)
const switchModeLoading = ref(false)
const switchModeFormRef = ref<FormInstance>()
const currentOperatingDeviceIdentifier = ref<string>('')
const currentDeviceSwitchMode = ref<number>(0)
const switchModeForm = reactive({
switch_mode: 0
})
const switchModeRules = reactive<FormRules>({
switch_mode: [{ required: true, message: '请选择切卡模式', trigger: 'change' }]
})
// 搜索表单初始值
const initialSearchState = {
virtual_no: '',
@@ -1547,6 +1598,9 @@
case 'clear-series':
await handleClearDeviceSeries(deviceNo)
break
case 'switch-mode':
showSwitchModeDialog(deviceNo, device?.switch_mode)
break
}
}
@@ -1758,6 +1812,42 @@
})
}
// 显示切换模式对话框
const showSwitchModeDialog = (deviceIdentifier: string, currentMode?: number) => {
currentOperatingDeviceIdentifier.value = deviceIdentifier
currentDeviceSwitchMode.value = currentMode ?? 0
switchModeForm.switch_mode = currentMode ?? 0
switchModeDialogVisible.value = true
}
// 确认切换模式
const handleConfirmSwitchMode = async () => {
if (!switchModeFormRef.value) return
await switchModeFormRef.value.validate(async (valid) => {
if (valid) {
switchModeLoading.value = true
try {
const res = await DeviceService.setSwitchMode(
currentOperatingDeviceIdentifier.value,
switchModeForm.switch_mode
)
if (res.code === 0) {
ElMessage.success('设置切卡模式成功')
switchModeDialogVisible.value = false
await getTableData()
} else {
ElMessage.error(res.msg || '设置切卡模式失败')
}
} catch (error: any) {
console.error('设置切卡模式失败:', error)
} finally {
switchModeLoading.value = false
}
}
})
}
// 设备操作菜单项配置
// 表格操作列配置
const getActions = (row: Device) => {
@@ -1783,6 +1873,14 @@
})
}
if (hasAuth('device:switch_mode')) {
moreActions.push({
label: '设置切卡模式',
handler: () => handleDeviceOperation('switch-mode', row.virtual_no, row),
type: 'primary'
})
}
if (hasAuth('device:reboot')) {
moreActions.push({
label: '重启设备',

View File

@@ -75,14 +75,7 @@
placeholder="请选择支付方式"
style="width: 100%"
>
<!-- 所有用户都显示微信在线支付 -->
<ElOption label="微信在线支付" value="wechat" />
<!-- 平台用户额外显示线下转账 -->
<ElOption
v-if="userStore.info.user_type === 1 || userStore.info.user_type === 2"
label="线下转账"
value="offline"
/>
<ElOption label="线下转账" value="offline" />
</ElSelect>
</ElFormItem>
<ElFormItem label="店铺" prop="shop_id">
@@ -97,6 +90,26 @@
@change="handleShopChange"
/>
</ElFormItem>
<ElFormItem
v-if="createForm.payment_method === 'offline'"
label="支付凭证"
prop="payment_voucher_key"
>
<ElUpload
ref="uploadRef"
:auto-upload="false"
:on-change="handleVoucherFileChange"
:on-remove="handleRemoveVoucher"
accept="image/*"
list-type="picture-card"
:limit="1"
>
<el-icon><Plus /></el-icon>
<template #tip>
<div class="el-upload__tip">支持 jpgpng 格式文件大小不超过 5MB</div>
</template>
</ElUpload>
</ElFormItem>
</ElForm>
<template #footer>
<div class="dialog-footer">
@@ -131,7 +144,7 @@
<ElInput
v-model="confirmPayForm.operation_password"
type="password"
placeholder="请输入操作密码"
placeholder="请输入超级管理员统一设置的操作密码"
show-password
/>
</ElFormItem>
@@ -153,8 +166,19 @@
<script setup lang="ts">
import { h } from 'vue'
import { useRouter } from 'vue-router'
import { AgentRechargeService, ShopService } from '@/api/modules'
import { ElMessage, ElTag, ElTreeSelect, ElButton, ElCascader } from 'element-plus'
import { AgentRechargeService, ShopService, StorageService } from '@/api/modules'
import {
ElMessage,
ElTag,
ElTreeSelect,
ElButton,
ElCascader,
ElInputNumber,
ElSelect,
ElOption,
ElUpload
} from 'element-plus'
import { Plus } from '@element-plus/icons-vue'
import type { FormInstance, FormRules } from 'element-plus'
import type {
AgentRecharge,
@@ -298,21 +322,36 @@
const createFormRef = ref<FormInstance>()
const confirmPayFormRef = ref<FormInstance>()
const uploadRef = ref()
const createRules = reactive<FormRules>({
amount: [{ required: true, message: '请输入充值金额', trigger: 'blur' }],
payment_method: [{ required: true, message: '请选择支付方式', trigger: 'change' }],
shop_id: [{ required: true, message: '请选择目标店铺', trigger: 'change' }]
const createRules = computed<FormRules>(() => {
const rules: FormRules = {
amount: [{ required: true, message: '请输入充值金额', trigger: 'blur' }],
payment_method: [{ required: true, message: '请选择支付方式', trigger: 'change' }],
shop_id: [{ required: true, message: '请选择目标店铺', trigger: 'change' }]
}
if (createForm.payment_method === 'offline') {
rules.payment_voucher_key = [{ required: true, message: '请上传支付凭证', trigger: 'change' }]
}
return rules
})
const confirmPayRules = reactive<FormRules>({
operation_password: [{ required: true, message: '请输入操作密码', trigger: 'blur' }]
operation_password: [
{ required: true, message: '请输入超级管理员统一设置的操作密码', trigger: 'blur' }
]
})
const createForm = reactive<{ amount: number; payment_method: string; shop_id: number | null }>({
const createForm = reactive<{
amount: number
payment_method: string
shop_id: number | null
payment_voucher_key?: string
}>({
amount: 100,
payment_method: '',
shop_id: null
shop_id: null,
payment_voucher_key: undefined
})
const confirmPayForm = reactive<ConfirmOfflinePaymentRequest>({
@@ -564,8 +603,7 @@
const showCreateDialog = async () => {
// 重新加载店铺列表,确保获取最新数据
await loadShops()
// 所有用户默认微信支付
createForm.payment_method = 'wechat'
createForm.payment_method = ''
createDialogVisible.value = true
}
@@ -575,6 +613,55 @@
createForm.amount = 100
createForm.payment_method = ''
createForm.shop_id = null
createForm.payment_voucher_key = undefined
uploadRef.value?.clearFiles()
}
// 支付凭证文件变化
const handleVoucherFileChange = async (file: any) => {
const isImage = file.raw.type.startsWith('image/')
const isLt5M = file.raw.size / 1024 / 1024 < 5
if (!isImage) {
ElMessage.error('只能上传图片文件')
uploadRef.value?.clearFiles()
return
}
if (!isLt5M) {
ElMessage.error('图片大小不能超过 5MB')
uploadRef.value?.clearFiles()
return
}
try {
const uploadUrlRes = await StorageService.getUploadUrl({
file_name: file.name,
content_type: file.raw.type,
purpose: 'attachment'
})
if (uploadUrlRes.code !== 0) {
ElMessage.error(uploadUrlRes.msg || '获取上传地址失败')
uploadRef.value?.clearFiles()
return
}
const { upload_url, file_key } = uploadUrlRes.data
await StorageService.uploadFile(upload_url, file.raw, file.raw.type)
createForm.payment_voucher_key = file_key
ElMessage.success('上传成功')
} catch (error: any) {
console.error('上传失败:', error)
createForm.payment_voucher_key = undefined
uploadRef.value?.clearFiles()
}
}
// 删除支付凭证
const handleRemoveVoucher = () => {
createForm.payment_voucher_key = undefined
}
// 创建充值订单
@@ -591,6 +678,10 @@
shop_id: createForm.shop_id!
}
if (createForm.payment_method === 'offline' && createForm.payment_voucher_key) {
data.payment_voucher_key = createForm.payment_voucher_key
}
await AgentRechargeService.createAgentRecharge(data)
ElMessage.success('充值订单创建成功')
createDialogVisible.value = false

View File

@@ -0,0 +1,139 @@
<template>
<ArtTableFullScreen>
<div class="operation-password-page" id="table-full-screen">
<ElCard shadow="never" class="art-table-card">
<ElTabs v-model="activeTab" type="card" class="setting-tabs">
<ElTabPane label="操作密码" name="operation-password">
<ElCard shadow="never">
<div class="setting-card">
<ElForm :model="opPwdForm" class="form" label-width="80">
<ElFormItem label="状态">
<ElTag :type="opPwdForm.is_set ? 'primary' : 'info'">
{{ opPwdForm.is_set ? '已设置' : '未设置' }}
</ElTag>
</ElFormItem>
<ElFormItem label="操作密码" prop="password">
<ElInput
v-model="opPwdForm.password"
type="password"
show-password
placeholder="请输入操作密码"
style="width: 300px"
/>
</ElFormItem>
<ElFormItem label="确认密码" prop="confirm_password">
<ElInput
v-model="opPwdForm.confirm_password"
type="password"
show-password
placeholder="请再次输入操作密码"
style="width: 300px"
/>
</ElFormItem>
<ElFormItem>
<ElButton
type="primary"
@click="handleSetOperationPassword"
:loading="opPwdLoading"
>
{{ opPwdForm.is_set ? '重置密码' : '设置密码' }}
</ElButton>
</ElFormItem>
</ElForm>
</div>
</ElCard>
</ElTabPane>
</ElTabs>
</ElCard>
</div>
</ArtTableFullScreen>
</template>
<script setup lang="ts">
import { useUserStore } from '@/store/modules/user'
import { ElForm, ElInput, ElTag, ElButton, ElMessage, ElTabs, ElTabPane } from 'element-plus'
import { SuperAdminService } from '@/api/modules'
defineOptions({ name: 'OperationPasswordSettings' })
const userStore = useUserStore()
const isSuperAdmin = computed(() => userStore.info.user_type === 1)
const activeTab = ref('operation-password')
const opPwdForm = reactive({
password: '',
confirm_password: '',
is_set: false
})
const opPwdLoading = ref(false)
const handleSetOperationPassword = async () => {
if (!opPwdForm.password) {
ElMessage.warning('请输入操作密码')
return
}
if (!opPwdForm.confirm_password) {
ElMessage.warning('请输入确认密码')
return
}
if (opPwdForm.password !== opPwdForm.confirm_password) {
ElMessage.warning('两次输入的密码不一致')
return
}
opPwdLoading.value = true
try {
await SuperAdminService.setOperationPassword({
password: opPwdForm.password,
confirm_password: opPwdForm.confirm_password
})
ElMessage.success(opPwdForm.is_set ? '操作密码重置成功' : '操作密码设置成功')
opPwdForm.password = ''
opPwdForm.confirm_password = ''
await fetchOperationPasswordStatus()
} catch (error) {
console.error(error)
} finally {
opPwdLoading.value = false
}
}
const fetchOperationPasswordStatus = async () => {
if (!isSuperAdmin.value) return
try {
const res = await SuperAdminService.getOperationPasswordStatus()
if (res.code === 0) {
opPwdForm.is_set = res.data.is_set
}
} catch (error) {
console.error(error)
}
}
onMounted(() => {
fetchOperationPasswordStatus()
})
</script>
<style scoped lang="scss">
.operation-password-page {
height: 100%;
:deep(.setting-tabs) {
.el-tabs__header {
margin: 0;
}
.el-tabs__nav-wrap::after {
display: none;
}
}
.setting-card {
}
}
</style>

View File

@@ -103,30 +103,6 @@
</div>
</ElForm>
</div>
<div class="info box-style" style="margin-top: 20px">
<h1 class="title">更改密码</h1>
<ElForm :model="pwdForm" class="form" label-width="86px" label-position="top">
<ElFormItem label="当前密码" prop="password">
<ElInput v-model="pwdForm.password" type="password" :disabled="!isEditPwd" />
</ElFormItem>
<ElFormItem label="新密码" prop="newPassword">
<ElInput v-model="pwdForm.newPassword" type="password" :disabled="!isEditPwd" />
</ElFormItem>
<ElFormItem label="确认新密码" prop="confirmPassword">
<ElInput v-model="pwdForm.confirmPassword" type="password" :disabled="!isEditPwd" />
</ElFormItem>
<div class="el-form-item-right">
<ElButton type="primary" style="width: 90px" v-ripple @click="editPwd">
{{ isEditPwd ? '保存' : '编辑' }}
</ElButton>
</div>
</ElForm>
</div>
</div>
</div>
</div>
@@ -142,7 +118,6 @@
const userInfo = computed(() => userStore.getUserInfo)
const isEdit = ref(false)
const isEditPwd = ref(false)
const date = ref('')
const form = reactive({
realName: 'John Snow',
@@ -154,12 +129,6 @@
des: 'Art Design Pro 是一款漂亮的后台管理系统模版.'
})
const pwdForm = reactive({
password: '123456',
newPassword: '123456',
confirmPassword: '123456'
})
const ruleFormRef = ref<FormInstance>()
const rules = reactive<FormRules>({
@@ -220,9 +189,9 @@
isEdit.value = !isEdit.value
}
const editPwd = () => {
isEditPwd.value = !isEditPwd.value
}
onMounted(() => {
getDate()
})
</script>
<style lang="scss">