fix: 统一账号角色校验与默认首页

- 创建与导入账号时强制校验启用角色

- 按启用角色返回默认首页并过滤禁用角色
This commit is contained in:
2026-08-03 14:48:39 +08:00
parent 219e4f7eff
commit 866688b92f
9 changed files with 697 additions and 42 deletions

View File

@@ -1,19 +1,20 @@
<script setup lang="ts">
import type {FormInstance} from 'element-plus';
import {ElForm, ElFormItem, ElInput, ElMessage} from 'element-plus';
import type { FormInstance } from 'element-plus';
import {onMounted, ref, watch} from 'vue';
import { onMounted, ref, watch } from 'vue';
import {EasyFlowFormModal, EasyFlowInputPassword} from '@easyflow/common-ui';
import { EasyFlowFormModal, EasyFlowInputPassword } from '@easyflow/common-ui';
import {getCredentialKeyApi} from '#/api';
import {api} from '#/api/request';
import { ElForm, ElFormItem, ElInput, ElMessage } from 'element-plus';
import { getCredentialKeyApi } from '#/api';
import { api } from '#/api/request';
import DictSelect from '#/components/dict/DictSelect.vue';
// import Cropper from '#/components/upload/Cropper.vue';
import UploadAvatar from '#/components/upload/UploadAvatar.vue';
import {$t} from '#/locales';
import {encryptCredentialPayload} from '#/utils/credential-encryption';
import {isStrongPassword} from '#/utils/password-policy';
import { $t } from '#/locales';
import { encryptCredentialPayload } from '#/utils/credential-encryption';
import { isStrongPassword } from '#/utils/password-policy';
const emit = defineEmits(['reload']);
// vue
@@ -71,6 +72,21 @@ const validateConfirmPassword = (_rule: any, value: string, callback: any) => {
}
callback();
};
const validateRoles = (_rule: any, value: unknown, callback: any) => {
if (!isAdd.value) {
callback();
return;
}
if (
!Array.isArray(value) ||
value.filter((roleId) => roleId !== null && roleId !== undefined).length ===
0
) {
callback(new Error($t('message.required')));
return;
}
callback();
};
const btnLoading = ref(false);
const rules = ref({
deptId: [
@@ -82,6 +98,7 @@ const rules = ref({
nickname: [
{ required: true, message: $t('message.required'), trigger: 'blur' },
],
roleIds: [{ validator: validateRoles, trigger: 'change' }],
password: [
{ required: true, validator: validateStrongPassword, trigger: 'blur' },
],
@@ -222,7 +239,11 @@ watch(
<ElFormItem prop="remark" :label="$t('sysAccount.remark')">
<ElInput v-model.trim="entity.remark" />
</ElFormItem>
<ElFormItem prop="roleIds" :label="$t('sysAccount.roleIds')">
<ElFormItem
prop="roleIds"
:label="$t('sysAccount.roleIds')"
:required="isAdd"
>
<DictSelect multiple v-model="entity.roleIds" dict-code="sysRole" />
</ElFormItem>
<ElFormItem prop="positionIds" :label="$t('sysAccount.positionIds')">