feat: 多选框支持全选
This commit is contained in:
@@ -12,7 +12,7 @@ export namespace LicenseApi {
|
|||||||
projectId?: number; // 项目ID
|
projectId?: number; // 项目ID
|
||||||
sn?: string; // sn
|
sn?: string; // sn
|
||||||
expirationTime: Dayjs | string; // 到期时间
|
expirationTime: Dayjs | string; // 到期时间
|
||||||
neSwitch: string; // 网元开关
|
neSwitch: number[]; // 网元开关
|
||||||
userNum: number; // 用户数
|
userNum: number; // 用户数
|
||||||
baseStationNum: number; // 基站数
|
baseStationNum: number; // 基站数
|
||||||
activationCode: string; // 激活码
|
activationCode: string; // 激活码
|
||||||
|
|||||||
@@ -13,5 +13,6 @@
|
|||||||
"remark": "Remark",
|
"remark": "Remark",
|
||||||
"creationTime": "Creation Time",
|
"creationTime": "Creation Time",
|
||||||
"operation": "Operation",
|
"operation": "Operation",
|
||||||
"list": "License List"
|
"list": "License List",
|
||||||
|
"checkAll": "Check All"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,5 +13,6 @@
|
|||||||
"remark": "备注",
|
"remark": "备注",
|
||||||
"creationTime": "创建时间",
|
"creationTime": "创建时间",
|
||||||
"operation": "操作",
|
"operation": "操作",
|
||||||
"list": "License列表"
|
"list": "License列表",
|
||||||
|
"checkAll": "全选"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -102,19 +102,23 @@ export function useFormSchema(): VbenFormSchema[] {
|
|||||||
fieldName: 'neSwitch',
|
fieldName: 'neSwitch',
|
||||||
label: $t('license.neSwitch'),
|
label: $t('license.neSwitch'),
|
||||||
component: 'CheckboxGroup',
|
component: 'CheckboxGroup',
|
||||||
componentProps: {
|
modelPropName: 'modelValue',
|
||||||
options: getDictOptions(DICT_TYPE.LIC_NE_SWITCH, 'number'),
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
fieldName: 'userNum',
|
fieldName: 'userNum',
|
||||||
label: $t('license.userNum'),
|
label: $t('license.userNum'),
|
||||||
component: 'Input',
|
component: 'InputNumber',
|
||||||
|
componentProps: {
|
||||||
|
min: 0,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
fieldName: 'baseStationNum',
|
fieldName: 'baseStationNum',
|
||||||
label: $t('license.baseStationNum'),
|
label: $t('license.baseStationNum'),
|
||||||
component: 'Input',
|
component: 'InputNumber',
|
||||||
|
componentProps: {
|
||||||
|
min: 0,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
fieldName: 'activationCode',
|
fieldName: 'activationCode',
|
||||||
@@ -196,10 +200,19 @@ export function useGridFormSchema(): VbenFormSchema[] {
|
|||||||
allowClear: true,
|
allowClear: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
// {
|
{
|
||||||
// fieldName: 'neSwitch',
|
fieldName: 'neSwitch',
|
||||||
// label: $t('license.neSwitch'),
|
label: $t('license.neSwitch'),
|
||||||
// },
|
component: 'Select',
|
||||||
|
componentProps: {
|
||||||
|
allowClear: true,
|
||||||
|
mode: 'multiple',
|
||||||
|
options: getDictOptions(DICT_TYPE.LIC_NE_SWITCH, 'number'),
|
||||||
|
showSearch: true,
|
||||||
|
filterOption: (input: string, option: any) =>
|
||||||
|
option.label.toLowerCase().includes(input.toLowerCase()),
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
fieldName: 'userNum',
|
fieldName: 'userNum',
|
||||||
label: $t('license.userNum'),
|
label: $t('license.userNum'),
|
||||||
@@ -310,7 +323,7 @@ export function useGridColumns(
|
|||||||
title: $t('license.neSwitch'),
|
title: $t('license.neSwitch'),
|
||||||
minWidth: 120,
|
minWidth: 120,
|
||||||
cellRender: {
|
cellRender: {
|
||||||
name: 'CellDict',
|
name: 'CellDictGroup',
|
||||||
props: { type: DICT_TYPE.LIC_NE_SWITCH },
|
props: { type: DICT_TYPE.LIC_NE_SWITCH },
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import type { LicenseApi } from '#/api/license/license';
|
import type { LicenseApi } from '#/api/license/license';
|
||||||
|
|
||||||
import { computed, ref } from 'vue';
|
import { computed, reactive, ref, watch } from 'vue';
|
||||||
|
|
||||||
import { useVbenModal } from '@vben/common-ui';
|
import { useVbenModal } from '@vben/common-ui';
|
||||||
|
|
||||||
@@ -14,11 +14,20 @@ import {
|
|||||||
updateLicense,
|
updateLicense,
|
||||||
} from '#/api/license/license';
|
} from '#/api/license/license';
|
||||||
import { $t } from '#/locales';
|
import { $t } from '#/locales';
|
||||||
|
import { DICT_TYPE, getDictOptions } from '#/utils';
|
||||||
|
|
||||||
import { useFormSchema } from '../data';
|
import { useFormSchema } from '../data';
|
||||||
|
|
||||||
const emit = defineEmits(['success']);
|
const emit = defineEmits(['success']);
|
||||||
|
const neSwitchOptions = getDictOptions(DICT_TYPE.LIC_NE_SWITCH, 'number');
|
||||||
const formData = ref<LicenseApi.License>();
|
const formData = ref<LicenseApi.License>();
|
||||||
|
|
||||||
|
const state = reactive({
|
||||||
|
indeterminate: false,
|
||||||
|
checkAll: false,
|
||||||
|
checkedList: [] as number[],
|
||||||
|
});
|
||||||
|
|
||||||
const getTitle = computed(() => {
|
const getTitle = computed(() => {
|
||||||
return formData.value?.id
|
return formData.value?.id
|
||||||
? $t('ui.actionTitle.edit', ['License'])
|
? $t('ui.actionTitle.edit', ['License'])
|
||||||
@@ -38,6 +47,23 @@ const [Form, formApi] = useVbenForm({
|
|||||||
showDefaultActions: false,
|
showDefaultActions: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const onCheckAllChange = (e: any) => {
|
||||||
|
Object.assign(state, {
|
||||||
|
checkedList: e.target.checked
|
||||||
|
? neSwitchOptions.map((option) => option.value)
|
||||||
|
: [],
|
||||||
|
indeterminate: false,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
watch(
|
||||||
|
() => state.checkedList,
|
||||||
|
(val) => {
|
||||||
|
state.indeterminate = val.length > 0 && val.length < neSwitchOptions.length;
|
||||||
|
state.checkAll = val.length === neSwitchOptions.length;
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
const [Modal, modalApi] = useVbenModal({
|
const [Modal, modalApi] = useVbenModal({
|
||||||
async onConfirm() {
|
async onConfirm() {
|
||||||
const { valid } = await formApi.validate();
|
const { valid } = await formApi.validate();
|
||||||
@@ -47,6 +73,7 @@ const [Modal, modalApi] = useVbenModal({
|
|||||||
modalApi.lock();
|
modalApi.lock();
|
||||||
// 提交表单
|
// 提交表单
|
||||||
const data = (await formApi.getValues()) as LicenseApi.License;
|
const data = (await formApi.getValues()) as LicenseApi.License;
|
||||||
|
data.neSwitch = state.checkedList;
|
||||||
try {
|
try {
|
||||||
await (formData.value?.id ? updateLicense(data) : createLicense(data));
|
await (formData.value?.id ? updateLicense(data) : createLicense(data));
|
||||||
// 关闭并提示
|
// 关闭并提示
|
||||||
@@ -77,6 +104,7 @@ const [Modal, modalApi] = useVbenModal({
|
|||||||
}
|
}
|
||||||
// 设置到 values
|
// 设置到 values
|
||||||
formData.value = data;
|
formData.value = data;
|
||||||
|
state.checkedList = data.neSwitch || [];
|
||||||
await formApi.setValues(formData.value);
|
await formApi.setValues(formData.value);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@@ -84,6 +112,26 @@ const [Modal, modalApi] = useVbenModal({
|
|||||||
|
|
||||||
<template>
|
<template>
|
||||||
<Modal :title="getTitle">
|
<Modal :title="getTitle">
|
||||||
<Form class="mx-4" />
|
<Form class="mx-4">
|
||||||
|
<template #neSwitch="slotProps">
|
||||||
|
<a-row>
|
||||||
|
<div>
|
||||||
|
<a-checkbox
|
||||||
|
v-model:checked="state.checkAll"
|
||||||
|
:indeterminate="state.indeterminate"
|
||||||
|
@change="onCheckAllChange"
|
||||||
|
>
|
||||||
|
{{ $t('license.checkAll') }}
|
||||||
|
</a-checkbox>
|
||||||
|
</div>
|
||||||
|
<a-divider style="margin: 10px 0" />
|
||||||
|
<a-checkbox-group
|
||||||
|
v-bind="slotProps"
|
||||||
|
v-model:value="state.checkedList"
|
||||||
|
:options="neSwitchOptions"
|
||||||
|
/>
|
||||||
|
</a-row>
|
||||||
|
</template>
|
||||||
|
</Form>
|
||||||
</Modal>
|
</Modal>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
Reference in New Issue
Block a user