| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378 |
- <template>
- <div class="setting-container">
- <div class="setting-card">
- <div class="card-header">
- <h2 class="title">{{t('network_settings.title')}}</h2>
- <p class="subtitle">{{t('network_settings.description')}}</p>
- </div>
- <div class="content">
- <el-form
- ref="settingFormRef"
- :hide-required-asterisk="true"
- label-position="left"
- label-width="125px"
- :model="settingFormData"
- :rules="settingFormRules"
- @keyup.enter="handleSave"
- >
- <!-- 自动获取DHCP -->
- <div class="dhcp-section">
- <div class="dhcp-header">
- <span class="dhcp-label">{{t('network_settings.dhcp')}}</span>
- <el-switch
- v-model="settingFormData.enableDHCP"
- :active-value="1"
- :inactive-value="0"
- active-color="#409eff"
- inactive-color="#dcdfe4"
- @change="switchChange($event)"
- />
- </div>
- <p class="dhcp-tip">{{t('network_settings.dhcp_tip')}}</p>
- </div>
- <!-- IP版本 -->
- <el-form-item :label="t('network_settings.ip_version')" prop="IP_version" class="form-item-custom">
- <el-input v-model="IP_version" disabled></el-input>
- </el-form-item>
- <!-- IP地址 -->
- <el-form-item :label="t('network_settings.ip_address')" prop="IP" class="form-item-custom">
- <IPInputBox
- :disabled="settingFormData.enableDHCP"
- :ip-val="settingFormData.ipAddress"
- @update:ip-val="(updateVal) => (settingFormData.ipAddress = updateVal)"
- />
- </el-form-item>
- <!-- 子网掩码 -->
- <el-form-item :label="t('network_settings.subnet_mask')" prop="mask" class="form-item-custom">
- <IPInputBox
- :disabled="settingFormData.enableDHCP"
- :ip-val="settingFormData.subNetAddress"
- @update:ip-val="(updateVal) => (settingFormData.subNetAddress = updateVal)"
- />
- </el-form-item>
- <!-- 默认网关 -->
- <el-form-item :label="t('network_settings.gateway')" prop="gateway" class="form-item-custom">
- <IPInputBox
- :disabled="settingFormData.enableDHCP"
- :ip-val="settingFormData.gateWayAddress"
- @update:ip-val="(updateVal) => (settingFormData.gateWayAddress = updateVal)"
- />
- </el-form-item>
- <!-- 物理地址 -->
- <el-form-item :label="t('network_settings.mac_address')" class="form-item-custom">
- <el-input
- v-model="settingFormData.deviceMac"
- disabled
- class="mac-input"
- />
- </el-form-item>
- <!-- 操作按钮 -->
- <div class="button-group">
- <el-button
- :loading="loading"
- size="large"
- type="primary"
- @click="handleSave()"
- class="save-button"
- >
- <span v-if="!loading">{{t('common.save')}}</span>
- <span v-else>Saving...</span>
- </el-button>
- </div>
- </el-form>
- </div>
- </div>
- </div>
- </template>
- <script lang="ts" setup>
- import {
- type FormInstance,
- type FormRules,
- ElMessage,
- ElMessageBox
- } from 'element-plus'
- import { getUserSettingApi, putUserSettingApi } from '@/api/setting'
- import { type UpdateSettingRequestData } from '@/api/types/setting'
- import IPInputBox from './components/IPInputBox.vue'
- import {useI18n} from "vue-i18n";
- const { t } = useI18n();
- const IP_version = ref('IPV4')
- const options = [
- {
- value: 'IPV4',
- label: 'IPV4'
- }
- ]
- /** 按钮 Loading */
- const loading = ref(false)
- /** 表单数据 */
- const settingFormData: UpdateSettingRequestData = reactive({
- NIC: 1,
- enableDHCP: 0,
- ipAddress: '',
- subNetAddress: '',
- gateWayAddress: '',
- deviceMac: ''
- })
- /** 表单元素的引用 */
- const settingFormRef = ref<FormInstance | null>(null)
- /** 表单校验规则 */
- const settingFormRules: FormRules = {
- IP: [
- {
- validator: (rule, value, callback) => {
- if (settingFormData.ipAddress) {
- callback()
- } else {
- callback(new Error('Please enter the IP'))
- }
- },
- trigger: 'blur'
- }
- ],
- mask: [
- {
- validator: (rule, value, callback) => {
- if (settingFormData.subNetAddress) {
- callback()
- } else {
- callback(new Error('Please enter the subnet mask'))
- }
- },
- trigger: 'blur'
- }
- ],
- gateway: [
- {
- validator: (rule, value, callback) => {
- if (settingFormData.gateWayAddress) {
- callback()
- } else {
- callback(new Error('Please enter the default gateway'))
- }
- },
- trigger: 'blur'
- }
- ]
- }
- const switchChange = ($event: number) => {
- if ($event === 1) {
- settingFormRef.value?.clearValidate()
- }
- }
- const param = {
- NIC: 1
- }
- /** 获取表单数据 */
- const fetchData = () => {
- getUserSettingApi(param.NIC).then((res) => {
- settingFormData.enableDHCP = res.data.enableDHCP
- settingFormData.ipAddress = res.data.ipAddress
- settingFormData.subNetAddress = res.data.subNetAddress
- settingFormData.gateWayAddress = res.data.gateWayAddress
- settingFormData.deviceMac = res.data.deviceMac
- settingFormData.firstDNSAddress = res.data.firstDNSAddress
- settingFormData.secondDNSAddress = res.data.secondDNSAddress
- })
- }
- fetchData()
- /** 保存逻辑 */
- const handleSave = () => {
- settingFormRef.value?.validate((valid: boolean, fields) => {
- if (valid) {
- ElMessageBox.confirm(t('popup.network_tips'), t('popup.note'), {
- confirmButtonText: t('popup.confirm'),
- cancelButtonText: t('popup.cancel'),
- type: 'warning',
- confirmButtonClass: 'el-button--danger'
- }).then(() => {
- loading.value = true
- putUserSettingApi(param.NIC, settingFormData)
- .then(() => {
- ElMessage.success('Operation successful')
- })
- .finally(() => {
- loading.value = false
- })
- })
- }
- })
- }
- </script>
- <style lang="scss" scoped>
- .setting-container {
- padding: 20px;
- //background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
- min-height: 85vh;
- display: flex;
- //align-items: flex-start;
- justify-content: center;
- align-items: center;
- }
- .setting-card {
- width: 100%;
- max-width: 510px;
- //background: white;
- border-radius: 12px;
- box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
- overflow: hidden;
- transition: all 0.3s ease;
- &:hover {
- box-shadow: 0 8px 30px rgba(0, 0, 0, 0.12);
- }
- }
- .card-header {
- //background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
- color: #000104;
- padding: 20px 20px 0 20px;
- text-align: center;
- .title {
- margin: 0;
- font-size: 24px;
- font-weight: 600;
- margin-bottom: 8px;
- }
- .subtitle {
- margin: 0;
- font-size: 14px;
- opacity: 0.9;
- }
- }
- .content {
- padding: 30px;
- }
- .dhcp-section {
- background: #f0f9ff;
- border-left: 4px solid #409eff;
- padding: 16px;
- border-radius: 6px;
- margin-bottom: 24px;
- .dhcp-header {
- display: flex;
- justify-content: space-between;
- align-items: center;
- margin-bottom: 8px;
- .dhcp-label {
- font-size: 14px;
- font-weight: 500;
- color: #333;
- }
- }
- .dhcp-tip {
- margin: 0;
- font-size: 12px;
- color: #909399;
- }
- }
- .form-item-custom {
- margin-bottom: 20px;
- :deep(.el-form-item__label) {
- color: #606266;
- font-weight: 500;
- padding-right: 12px;
- }
- }
- .mac-input {
- :deep(.el-input__wrapper) {
- background-color: #f5f7fa !important;
- }
- }
- .button-group {
- display: flex;
- gap: 12px;
- margin-top: 32px;
- padding-top: 20px;
- border-top: 1px solid #ebeef5;
- }
- .save-button {
- flex: 1;
- height: 40px;
- font-size: 16px;
- font-weight: 500;
- border-radius: 6px;
- transition: all 0.3s ease;
- &:hover {
- transform: translateY(-2px);
- box-shadow: 0 6px 16px rgba(64, 158, 255, 0.4);
- }
- &:active {
- transform: translateY(0);
- }
- }
- // 响应式设计
- @media (max-width: 600px) {
- .setting-container {
- padding: 12px;
- }
- .setting-card {
- max-width: 100%;
- }
- .content {
- padding: 20px;
- }
- .card-header {
- padding: 20px 16px;
- .title {
- font-size: 20px;
- }
- .subtitle {
- font-size: 12px;
- }
- }
- }
- // 深色主题支持(可选)
- @media (prefers-color-scheme: dark) {
- .setting-card {
- background: #1e1e1e;
- }
- .content {
- color: #e0e0e0;
- }
- .form-item-custom {
- :deep(.el-form-item__label) {
- color: #b0b0b0;
- }
- :deep(.el-input__wrapper) {
- background-color: #2a2a2a;
- border-color: #404040;
- }
- }
- }
- </style>
|