diff --git a/src/components.d.ts b/src/components.d.ts index dee0f14..5d0f239 100644 --- a/src/components.d.ts +++ b/src/components.d.ts @@ -27,6 +27,7 @@ declare module 'vue' { ElScrollbar: typeof import('element-plus/es')['ElScrollbar'] ElSelect: typeof import('element-plus/es')['ElSelect'] ElSlider: typeof import('element-plus/es')['ElSlider'] + ElSwitch: typeof import('element-plus/es')['ElSwitch'] ElTable: typeof import('element-plus/es')['ElTable'] ElTableColumn: typeof import('element-plus/es')['ElTableColumn'] ElTimePicker: typeof import('element-plus/es')['ElTimePicker'] diff --git a/src/views/SystemSettings/index.vue b/src/views/SystemSettings/index.vue index 1fb4a91..9f6c9a4 100644 --- a/src/views/SystemSettings/index.vue +++ b/src/views/SystemSettings/index.vue @@ -67,6 +67,12 @@
修改操作密码
+
+
+
启用密码保护
+ +
+
原密码
@@ -208,6 +214,45 @@ const changePassword = async () => { } } +// ─── 密码保护开关 ───────────────────────────────── +const passwordEnabled = ref(false) + +const getPasswordStatus = async () => { + try { + const res = await RPC.post('/m9z/password/status', {}) + passwordEnabled.value = res?.enabled || false + } catch (e) { + // 错误由 rpc.js 处理 + } +} + +const handlePasswordEnableChange = async (val) => { + const actionText = val ? '开启' : '关闭' + try { + await ElMessageBox.confirm( + `确认要${actionText}密码保护功能吗?`, + '提示', + { + confirmButtonText: '确定', + cancelButtonText: '取消', + type: 'warning', + } + ) + + const method = val ? '/m9z/password/enable' : '/m9z/password/disable' + try { + await RPC.post(method, {}) + ElMessage.success(`${actionText}密码保护成功`) + } catch (e) { + // 如果接口失败,回滚状态 + passwordEnabled.value = !val + } + } catch (e) { + // 用户取消,回滚状态 + passwordEnabled.value = !val + } +} + const goBack = () => { router.push('/') } @@ -217,6 +262,7 @@ onMounted(() => { updateTime() timeInterval = setInterval(updateTime, 1000) getSystemTime() + getPasswordStatus() }) onUnmounted(() => { if (timeInterval) clearInterval(timeInterval)