refactor: 表单引用类型化并收敛权限码常量
- 12 处表单 ref 统一为 WdFormRef 结构化类型,校验调用补可选链 - 权限码字面量收敛为 PERM 常量,取值与后端菜单表一致 - 表单校验器参数收窄为 unknown
This commit is contained in:
1 parent
ac58ec49cb
commit
7cc36dd731
13 files changed
+141
-64
No files matched your search
@@ -5,3 +5,62 @@ export const ROLE_ROOT = "ROOT";
|
||||
|
||||
/** 全部权限标识 */
|
||||
export const PERM_ALL = "*:*:*";
|
||||
|
||||
/** 按钮权限码,取值来自后端菜单表的 perm 字段 */
|
||||
export const PERM = {
|
||||
user: {
|
||||
list: "sys:user:list",
|
||||
create: "sys:user:create",
|
||||
update: "sys:user:update",
|
||||
delete: "sys:user:delete",
|
||||
resetPassword: "sys:user:reset-password",
|
||||
},
|
||||
role: {
|
||||
list: "sys:role:list",
|
||||
create: "sys:role:create",
|
||||
update: "sys:role:update",
|
||||
delete: "sys:role:delete",
|
||||
assign: "sys:role:assign",
|
||||
},
|
||||
dept: {
|
||||
list: "sys:dept:list",
|
||||
create: "sys:dept:create",
|
||||
update: "sys:dept:update",
|
||||
delete: "sys:dept:delete",
|
||||
},
|
||||
menu: {
|
||||
list: "sys:menu:list",
|
||||
create: "sys:menu:create",
|
||||
update: "sys:menu:update",
|
||||
delete: "sys:menu:delete",
|
||||
},
|
||||
dict: {
|
||||
list: "sys:dict:list",
|
||||
create: "sys:dict:create",
|
||||
update: "sys:dict:update",
|
||||
delete: "sys:dict:delete",
|
||||
},
|
||||
dictItem: {
|
||||
list: "sys:dict-item:list",
|
||||
create: "sys:dict-item:create",
|
||||
update: "sys:dict-item:update",
|
||||
delete: "sys:dict-item:delete",
|
||||
},
|
||||
config: {
|
||||
list: "sys:config:list",
|
||||
create: "sys:config:create",
|
||||
update: "sys:config:update",
|
||||
delete: "sys:config:delete",
|
||||
},
|
||||
notice: {
|
||||
list: "sys:notice:list",
|
||||
create: "sys:notice:create",
|
||||
update: "sys:notice:update",
|
||||
delete: "sys:notice:delete",
|
||||
publish: "sys:notice:publish",
|
||||
revoke: "sys:notice:revoke",
|
||||
},
|
||||
log: {
|
||||
list: "sys:log:list",
|
||||
},
|
||||
} as const;
|
||||
@@ -210,6 +210,7 @@
|
||||
import { onLoad } from "@dcloudio/uni-app";
|
||||
import { useToast, useDialog } from "@wot-ui/ui";
|
||||
import type { FormSchema } from "@wot-ui/ui/components/wd-form/types";
|
||||
import type { WdFormRef } from "@/utils/form-schema";
|
||||
|
||||
import { useUserStore } from "@/store/modules/user";
|
||||
import { useSmsLoginCode, isValidMobile } from "@/composables/useSmsLoginCode";
|
||||
@@ -226,7 +227,7 @@ definePage({
|
||||
const toast = useToast();
|
||||
const dialog = useDialog("policy-box");
|
||||
const userStore = useUserStore();
|
||||
const loginFormRef = ref();
|
||||
const loginFormRef = ref<WdFormRef>();
|
||||
const bindMobilePopupRef = ref<InstanceType<typeof BindMobilePopup>>();
|
||||
|
||||
// 表单状态
|
||||
|
||||
@@ -147,7 +147,7 @@ import { onMounted, reactive, ref } from "vue";
|
||||
import { useToast, useDialog } from "@wot-ui/ui";
|
||||
import { useCountdown } from "@/composables/useCountdown";
|
||||
import { getErrorMessage } from "@/utils/error";
|
||||
import { toFormSchema } from "@/utils/form-schema";
|
||||
import { toFormSchema, type WdFormRef } from "@/utils/form-schema";
|
||||
import UserAPI, {
|
||||
PasswordChangeForm,
|
||||
MobileBindingForm,
|
||||
@@ -209,9 +209,9 @@ const userProfile = ref<UserProfile>();
|
||||
const passwordChangeForm = reactive<PasswordChangeForm>({});
|
||||
const mobileBindingForm = reactive<MobileBindingForm>({});
|
||||
const emailBindingForm = reactive<EmailBindingForm>({});
|
||||
const passwordChangeFormRef = ref();
|
||||
const mobileBindingFormRef = ref();
|
||||
const emailBindingFormRef = ref();
|
||||
const passwordChangeFormRef = ref<WdFormRef>();
|
||||
const mobileBindingFormRef = ref<WdFormRef>();
|
||||
const emailBindingFormRef = ref<WdFormRef>();
|
||||
|
||||
const { remainingSeconds: mobileCountdown, start: startMobileCountdown } = useCountdown(60);
|
||||
const { remainingSeconds: emailCountdown, start: startEmailCountdown } = useCountdown(60);
|
||||
@@ -263,14 +263,14 @@ const handleOpenPopup = (type: SecurityAction) => {
|
||||
const handleSendVerificationCode = async (contactType: string) => {
|
||||
try {
|
||||
if (contactType === "MOBILE") {
|
||||
const { valid } = await mobileBindingFormRef.value.validate("mobile");
|
||||
const { valid } = (await mobileBindingFormRef.value?.validate("mobile")) ?? { valid: false };
|
||||
if (valid) {
|
||||
await UserAPI.sendVerificationCode(mobileBindingForm.mobile!, "MOBILE");
|
||||
toast.info("验证码已发送");
|
||||
startMobileCountdown();
|
||||
}
|
||||
} else if (contactType === "EMAIL") {
|
||||
const { valid } = await emailBindingFormRef.value.validate("email");
|
||||
const { valid } = (await emailBindingFormRef.value?.validate("email")) ?? { valid: false };
|
||||
if (valid) {
|
||||
await UserAPI.sendVerificationCode(emailBindingForm.email!, "EMAIL");
|
||||
toast.info("验证码已发送");
|
||||
@@ -286,14 +286,14 @@ const handleSendVerificationCode = async (contactType: string) => {
|
||||
async function handleSecuritySubmit() {
|
||||
try {
|
||||
if (popup.type === SecurityAction.PASSWORD) {
|
||||
const { valid } = await passwordChangeFormRef.value.validate();
|
||||
const { valid } = (await passwordChangeFormRef.value?.validate()) ?? { valid: false };
|
||||
if (valid) {
|
||||
await UserAPI.changePassword(passwordChangeForm);
|
||||
toast.info("密码修改成功");
|
||||
popup.visible = false;
|
||||
}
|
||||
} else if (popup.type === SecurityAction.MOBILE) {
|
||||
const { valid } = await mobileBindingFormRef.value.validate();
|
||||
const { valid } = (await mobileBindingFormRef.value?.validate()) ?? { valid: false };
|
||||
if (valid) {
|
||||
await UserAPI.bindMobile(mobileBindingForm);
|
||||
toast.info("手机号绑定成功");
|
||||
@@ -301,7 +301,7 @@ async function handleSecuritySubmit() {
|
||||
loadUserProfile();
|
||||
}
|
||||
} else if (popup.type === SecurityAction.EMAIL) {
|
||||
const { valid } = await emailBindingFormRef.value.validate();
|
||||
const { valid } = (await emailBindingFormRef.value?.validate()) ?? { valid: false };
|
||||
if (valid) {
|
||||
await UserAPI.bindEmail(emailBindingForm);
|
||||
toast.info("邮箱绑定成功");
|
||||
|
||||
@@ -129,7 +129,7 @@ import { onLoad } from "@dcloudio/uni-app";
|
||||
import { useDialog, useToast } from "@wot-ui/ui";
|
||||
import { useUserStore } from "@/store";
|
||||
import { getErrorMessage } from "@/utils/error";
|
||||
import { toFormSchema } from "@/utils/form-schema";
|
||||
import { toFormSchema, type WdFormRef } from "@/utils/form-schema";
|
||||
import UserAPI, { type UserProfileForm } from "@/api/user";
|
||||
import FileAPI, { type FileInfo } from "@/api/file";
|
||||
|
||||
@@ -163,7 +163,7 @@ const formRules = toFormSchema({
|
||||
const isLoading = ref(false);
|
||||
const isCropperVisible = ref(false);
|
||||
const originalImageSrc = ref("");
|
||||
const profileFormRef = ref();
|
||||
const profileFormRef = ref<WdFormRef>();
|
||||
|
||||
// 提交按钮的可用条件:昵称与手机号都已填写
|
||||
const canComplete = computed(() => {
|
||||
@@ -233,7 +233,10 @@ const handleAvatarConfirm = async (event: ImgCropperConfirmEvent) => {
|
||||
// 提交完善信息:先写资料再绑手机号,成功后回跳来源页面
|
||||
const handleComplete = async () => {
|
||||
try {
|
||||
const { valid, errors } = await profileFormRef.value.validate();
|
||||
const { valid, errors } = (await profileFormRef.value?.validate()) ?? {
|
||||
valid: false,
|
||||
errors: [],
|
||||
};
|
||||
if (!valid) {
|
||||
toast.error(errors[0]?.message || "请完善表单信息");
|
||||
return;
|
||||
|
||||
@@ -76,7 +76,7 @@ import UserAPI, { type UserProfile, UserProfileForm } from "@/api/user";
|
||||
import FileAPI, { type FileInfo } from "@/api/file";
|
||||
import { ensureAuthenticated } from "@/utils/auth";
|
||||
import { getErrorMessage } from "@/utils/error";
|
||||
import { toFormSchema } from "@/utils/form-schema";
|
||||
import { toFormSchema, type WdFormRef } from "@/utils/form-schema";
|
||||
|
||||
definePage({
|
||||
name: "profile",
|
||||
@@ -138,7 +138,7 @@ const popup = reactive({
|
||||
});
|
||||
|
||||
const userProfileForm = reactive<UserProfileForm>({});
|
||||
const userProfileFormRef = ref();
|
||||
const userProfileFormRef = ref<WdFormRef>();
|
||||
|
||||
// 打开资料编辑弹窗,并用当前资料回填表单
|
||||
const openProfilePopup = () => {
|
||||
@@ -149,7 +149,7 @@ const openProfilePopup = () => {
|
||||
|
||||
// 提交表单
|
||||
function handleSubmit() {
|
||||
userProfileFormRef.value.validate().then(({ valid }: { valid: boolean }) => {
|
||||
userProfileFormRef.value?.validate().then(({ valid }: { valid: boolean }) => {
|
||||
if (valid) {
|
||||
UserAPI.updateProfile(userProfileForm).then(() => {
|
||||
toast.info("账号资料修改成功");
|
||||
|
||||
@@ -92,13 +92,14 @@
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { onLoad } from "@dcloudio/uni-app";
|
||||
import { toFormSchema } from "@/utils/form-schema";
|
||||
import { toFormSchema, type WdFormRef } from "@/utils/form-schema";
|
||||
import { useToast } from "@wot-ui/ui";
|
||||
import ActionSheet, { type ActionSheetCommand } from "@/subPages/work/components/ActionSheet.vue";
|
||||
import { useConfirmAction } from "@/composables/useConfirmAction";
|
||||
import { usePagedList } from "@/composables/usePagedList";
|
||||
import ConfigAPI, { type ConfigPageQuery, ConfigItem, ConfigForm } from "@/api/config";
|
||||
import { hasPermission } from "@/utils/permission";
|
||||
import { PERM } from "@/constants/permissions";
|
||||
|
||||
definePage({
|
||||
name: "config",
|
||||
@@ -108,7 +109,7 @@ definePage({
|
||||
const toast = useToast();
|
||||
const { confirmAction } = useConfirmAction();
|
||||
const actionSheetRef = ref<InstanceType<typeof ActionSheet>>();
|
||||
const formRef = ref();
|
||||
const formRef = ref<WdFormRef>();
|
||||
const isSubmitting = ref(false);
|
||||
|
||||
const queryParams = reactive<ConfigPageQuery>({ pageNum: 1, pageSize: 10, keywords: "" });
|
||||
@@ -161,7 +162,7 @@ async function openConfigDialog(id?: number) {
|
||||
|
||||
// 提交表单
|
||||
function submitConfigForm() {
|
||||
formRef.value.validate().then(({ valid }: { valid: boolean }) => {
|
||||
formRef.value?.validate().then(({ valid }: { valid: boolean }) => {
|
||||
if (!valid) return;
|
||||
isSubmitting.value = true;
|
||||
const action = formData.id
|
||||
@@ -190,11 +191,11 @@ function closeConfigDialog() {
|
||||
function openConfigActions(item: ConfigItem) {
|
||||
const commands: ActionSheetCommand[] = [];
|
||||
|
||||
if (hasPermission("sys:config:update")) {
|
||||
if (hasPermission(PERM.config.update)) {
|
||||
commands.push({ id: "edit", label: "编辑", execute: () => openConfigDialog(item.id!) });
|
||||
}
|
||||
|
||||
if (hasPermission("sys:config:delete")) {
|
||||
if (hasPermission(PERM.config.delete)) {
|
||||
commands.push({
|
||||
id: "delete",
|
||||
label: "删除",
|
||||
|
||||
@@ -101,7 +101,7 @@
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { onLoad } from "@dcloudio/uni-app";
|
||||
import { toFormSchema } from "@/utils/form-schema";
|
||||
import { toFormSchema, type WdFormRef } from "@/utils/form-schema";
|
||||
import { findOptionChain, toTree } from "@/utils/tree";
|
||||
import { useToast } from "@wot-ui/ui";
|
||||
import type { CascaderOption } from "@wot-ui/ui/components/wd-cascader/types";
|
||||
@@ -110,6 +110,7 @@ import { useConfirmAction } from "@/composables/useConfirmAction";
|
||||
import DeptAPI, { type DeptQuery, DeptItem, DeptForm } from "@/api/dept";
|
||||
import { getErrorMessage } from "@/utils/error";
|
||||
import { hasPermission } from "@/utils/permission";
|
||||
import { PERM } from "@/constants/permissions";
|
||||
import TreeView, { type TreeOption } from "@/subPages/work/components/TreeView.vue";
|
||||
|
||||
definePage({
|
||||
@@ -120,7 +121,7 @@ definePage({
|
||||
const toast = useToast();
|
||||
const { confirmAction } = useConfirmAction();
|
||||
const actionSheetRef = ref<InstanceType<typeof ActionSheet>>();
|
||||
const formRef = ref();
|
||||
const formRef = ref<WdFormRef>();
|
||||
const isSubmitting = ref(false);
|
||||
|
||||
const queryParams = reactive<DeptQuery>({ keywords: "" });
|
||||
@@ -211,7 +212,7 @@ function handleNodeAction(node: DeptTreeOption) {
|
||||
|
||||
const commands: ActionSheetCommand[] = [];
|
||||
|
||||
if (hasPermission("sys:dept:create")) {
|
||||
if (hasPermission(PERM.dept.create)) {
|
||||
commands.push({
|
||||
id: "add-child",
|
||||
label: "新增子部门",
|
||||
@@ -219,11 +220,11 @@ function handleNodeAction(node: DeptTreeOption) {
|
||||
});
|
||||
}
|
||||
|
||||
if (hasPermission("sys:dept:update")) {
|
||||
if (hasPermission(PERM.dept.update)) {
|
||||
commands.push({ id: "edit", label: "编辑", execute: () => openDeptDialog(dept) });
|
||||
}
|
||||
|
||||
if (hasPermission("sys:dept:delete")) {
|
||||
if (hasPermission(PERM.dept.delete)) {
|
||||
commands.push({
|
||||
id: "delete",
|
||||
label: "删除",
|
||||
@@ -285,7 +286,7 @@ function openChildDeptDialog(dept: DeptItem) {
|
||||
|
||||
// 提交表单
|
||||
function submitDeptForm() {
|
||||
formRef.value.validate().then(({ valid }: { valid: boolean }) => {
|
||||
formRef.value?.validate().then(({ valid }: { valid: boolean }) => {
|
||||
if (!valid) return;
|
||||
isSubmitting.value = true;
|
||||
const action = formData.id ? DeptAPI.update(formData.id, formData) : DeptAPI.create(formData);
|
||||
|
||||
@@ -92,14 +92,14 @@
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { onLoad } from "@dcloudio/uni-app";
|
||||
import { useRouter } from "uni-mini-router";
|
||||
import { toFormSchema } from "@/utils/form-schema";
|
||||
import { toFormSchema, type WdFormRef } from "@/utils/form-schema";
|
||||
import { useToast } from "@wot-ui/ui";
|
||||
import ActionSheet, { type ActionSheetCommand } from "@/subPages/work/components/ActionSheet.vue";
|
||||
import { useConfirmAction } from "@/composables/useConfirmAction";
|
||||
import { usePagedList } from "@/composables/usePagedList";
|
||||
import DictAPI, { type DictTypeForm, type DictTypePageQuery, type DictTypeItem } from "@/api/dict";
|
||||
import { hasPermission } from "@/utils/permission";
|
||||
import { PERM } from "@/constants/permissions";
|
||||
import { getErrorMessage } from "@/utils/error";
|
||||
|
||||
definePage({
|
||||
@@ -107,11 +107,10 @@ definePage({
|
||||
style: { navigationBarTitleText: "字典管理", enablePullDownRefresh: true },
|
||||
});
|
||||
|
||||
const router = useRouter();
|
||||
const toast = useToast();
|
||||
const { confirmAction } = useConfirmAction();
|
||||
const actionSheetRef = ref<InstanceType<typeof ActionSheet>>();
|
||||
const formRef = ref();
|
||||
const formRef = ref<WdFormRef>();
|
||||
const isSubmitting = ref(false);
|
||||
|
||||
const queryParams = reactive<DictTypePageQuery>({ pageNum: 1, pageSize: 10, keywords: "" });
|
||||
@@ -151,9 +150,10 @@ function loadDictTypeList() {
|
||||
// 跳转字典数据页
|
||||
function navigateToDictItem(item: DictTypeItem) {
|
||||
if (!item.dictCode) return;
|
||||
router.push({
|
||||
path: "/subPages/work/dict/item/index",
|
||||
query: { dictCode: item.dictCode, title: `【${item.name}】字典数据` },
|
||||
uni.navigateTo({
|
||||
url: `/subPages/work/dict/item/index?dictCode=${item.dictCode}&title=${encodeURIComponent(
|
||||
`【${item.name}】字典数据`
|
||||
)}`,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -169,7 +169,7 @@ async function openDictDialog(id?: string) {
|
||||
}
|
||||
|
||||
function submitDictForm() {
|
||||
formRef.value.validate().then(({ valid }: { valid: boolean }) => {
|
||||
formRef.value?.validate().then(({ valid }: { valid: boolean }) => {
|
||||
if (!valid) return;
|
||||
isSubmitting.value = true;
|
||||
const id = formData.id;
|
||||
@@ -200,11 +200,11 @@ function openDictActions(item: DictTypeItem) {
|
||||
{ id: "dict-item", label: "字典数据", execute: () => navigateToDictItem(item) },
|
||||
];
|
||||
|
||||
if (hasPermission("sys:dict:update")) {
|
||||
if (hasPermission(PERM.dict.update)) {
|
||||
commands.push({ id: "edit", label: "编辑", execute: () => openDictDialog(item.id) });
|
||||
}
|
||||
|
||||
if (hasPermission("sys:dict:delete")) {
|
||||
if (hasPermission(PERM.dict.delete)) {
|
||||
commands.push({
|
||||
id: "delete",
|
||||
label: "删除",
|
||||
|
||||
@@ -112,13 +112,14 @@
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { onLoad } from "@dcloudio/uni-app";
|
||||
import { toFormSchema } from "@/utils/form-schema";
|
||||
import { toFormSchema, type WdFormRef } from "@/utils/form-schema";
|
||||
import { useToast } from "@wot-ui/ui";
|
||||
import ActionSheet, { type ActionSheetCommand } from "@/subPages/work/components/ActionSheet.vue";
|
||||
import { useConfirmAction } from "@/composables/useConfirmAction";
|
||||
import { usePagedList } from "@/composables/usePagedList";
|
||||
import DictAPI, { type DictItemForm, type DictItemPageQuery, type DictItem } from "@/api/dict";
|
||||
import { hasPermission } from "@/utils/permission";
|
||||
import { PERM } from "@/constants/permissions";
|
||||
import { getErrorMessage } from "@/utils/error";
|
||||
import type { TagType } from "@wot-ui/ui/components/wd-tag/types";
|
||||
|
||||
@@ -134,7 +135,7 @@ const actionSheetRef = ref<InstanceType<typeof ActionSheet>>();
|
||||
const dictCode = ref<string>("");
|
||||
const pageTitle = ref<string>("字典数据");
|
||||
|
||||
const formRef = ref();
|
||||
const formRef = ref<WdFormRef>();
|
||||
const isSubmitting = ref(false);
|
||||
|
||||
const queryParams = reactive<DictItemPageQuery>({ pageNum: 1, pageSize: 10, keywords: "" });
|
||||
@@ -220,7 +221,7 @@ async function openItemDialog(id?: string) {
|
||||
}
|
||||
|
||||
function submitItemForm() {
|
||||
formRef.value.validate().then(({ valid }: { valid: boolean }) => {
|
||||
formRef.value?.validate().then(({ valid }: { valid: boolean }) => {
|
||||
if (!valid) return;
|
||||
if (!dictCode.value) {
|
||||
toast.error("缺少字典编码");
|
||||
@@ -257,11 +258,11 @@ function closeItemDialog() {
|
||||
function openItemActions(item: DictItem) {
|
||||
const commands: ActionSheetCommand[] = [];
|
||||
|
||||
if (hasPermission("sys:dict-item:update")) {
|
||||
if (hasPermission(PERM.dictItem.update)) {
|
||||
commands.push({ id: "edit", label: "编辑", execute: () => openItemDialog(item.id) });
|
||||
}
|
||||
|
||||
if (hasPermission("sys:dict-item:delete")) {
|
||||
if (hasPermission(PERM.dictItem.delete)) {
|
||||
commands.push({
|
||||
id: "delete",
|
||||
label: "删除",
|
||||
@@ -283,7 +284,7 @@ function openItemActions(item: DictItem) {
|
||||
|
||||
onLoad((query) => {
|
||||
dictCode.value = String(query?.dictCode || "");
|
||||
pageTitle.value = String(query?.title || "字典数据");
|
||||
pageTitle.value = String(query?.title ? decodeURIComponent(query.title) : "字典数据");
|
||||
if (pageTitle.value) {
|
||||
uni.setNavigationBarTitle({ title: pageTitle.value });
|
||||
}
|
||||
|
||||
@@ -151,7 +151,7 @@
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { onLoad } from "@dcloudio/uni-app";
|
||||
import { toFormSchema } from "@/utils/form-schema";
|
||||
import { toFormSchema, type WdFormRef } from "@/utils/form-schema";
|
||||
import { useToast } from "@wot-ui/ui";
|
||||
import ActionSheet, { type ActionSheetCommand } from "@/subPages/work/components/ActionSheet.vue";
|
||||
import { useConfirmAction } from "@/composables/useConfirmAction";
|
||||
@@ -163,6 +163,7 @@ import NoticeAPI, {
|
||||
NoticeForm,
|
||||
} from "@/api/notice";
|
||||
import { hasPermission } from "@/utils/permission";
|
||||
import { PERM } from "@/constants/permissions";
|
||||
|
||||
definePage({
|
||||
name: "notice",
|
||||
@@ -172,7 +173,7 @@ definePage({
|
||||
const toast = useToast();
|
||||
const { confirmAction } = useConfirmAction();
|
||||
const actionSheetRef = ref<InstanceType<typeof ActionSheet>>();
|
||||
const formRef = ref();
|
||||
const formRef = ref<WdFormRef>();
|
||||
const isSubmitting = ref(false);
|
||||
|
||||
const queryParams = reactive<NoticePageQuery>({ pageNum: 1, pageSize: 10 });
|
||||
@@ -281,7 +282,7 @@ function closeNoticeDialog() {
|
||||
|
||||
// 提交表单
|
||||
function submitNoticeForm() {
|
||||
formRef.value.validate().then(({ valid }: { valid: boolean }) => {
|
||||
formRef.value?.validate().then(({ valid }: { valid: boolean }) => {
|
||||
if (!valid) return;
|
||||
isSubmitting.value = true;
|
||||
const id = formData.id;
|
||||
@@ -305,14 +306,14 @@ function openNoticeActions(item: NoticeItem) {
|
||||
];
|
||||
|
||||
if (item.publishStatus !== 1) {
|
||||
if (hasPermission("sys:notice:update")) {
|
||||
if (hasPermission(PERM.notice.update)) {
|
||||
commands.push({
|
||||
id: "edit",
|
||||
label: "编辑",
|
||||
execute: () => openNoticeDialog(Number(item.id)),
|
||||
});
|
||||
}
|
||||
if (hasPermission("sys:notice:delete")) {
|
||||
if (hasPermission(PERM.notice.delete)) {
|
||||
commands.push({
|
||||
id: "delete",
|
||||
label: "删除",
|
||||
@@ -327,7 +328,7 @@ function openNoticeActions(item: NoticeItem) {
|
||||
}),
|
||||
});
|
||||
}
|
||||
if (hasPermission("sys:notice:publish")) {
|
||||
if (hasPermission(PERM.notice.publish)) {
|
||||
commands.push({
|
||||
id: "publish",
|
||||
label: "发布",
|
||||
@@ -343,7 +344,7 @@ function openNoticeActions(item: NoticeItem) {
|
||||
}),
|
||||
});
|
||||
}
|
||||
} else if (hasPermission("sys:notice:revoke")) {
|
||||
} else if (hasPermission(PERM.notice.revoke)) {
|
||||
commands.push({
|
||||
id: "revoke",
|
||||
label: "撤回",
|
||||
|
||||
@@ -121,13 +121,14 @@
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { onLoad } from "@dcloudio/uni-app";
|
||||
import { toFormSchema } from "@/utils/form-schema";
|
||||
import { toFormSchema, type WdFormRef } from "@/utils/form-schema";
|
||||
import { useToast } from "@wot-ui/ui";
|
||||
import ActionSheet, { type ActionSheetCommand } from "@/subPages/work/components/ActionSheet.vue";
|
||||
import { useConfirmAction } from "@/composables/useConfirmAction";
|
||||
import { usePagedList } from "@/composables/usePagedList";
|
||||
import RoleAPI, { type RolePageQuery, RoleItem, RoleForm } from "@/api/role";
|
||||
import { hasPermission } from "@/utils/permission";
|
||||
import { PERM } from "@/constants/permissions";
|
||||
|
||||
definePage({
|
||||
name: "role",
|
||||
@@ -137,7 +138,7 @@ definePage({
|
||||
const toast = useToast();
|
||||
const { confirmAction } = useConfirmAction();
|
||||
const actionSheetRef = ref<InstanceType<typeof ActionSheet>>();
|
||||
const formRef = ref();
|
||||
const formRef = ref<WdFormRef>();
|
||||
const isSubmitting = ref(false);
|
||||
|
||||
const queryParams = reactive<RolePageQuery>({ pageNum: 1, pageSize: 10, keywords: "" });
|
||||
@@ -206,7 +207,7 @@ async function openRoleDialog(id?: number) {
|
||||
|
||||
// 提交表单
|
||||
function submitRoleForm() {
|
||||
formRef.value.validate().then(({ valid }: { valid: boolean }) => {
|
||||
formRef.value?.validate().then(({ valid }: { valid: boolean }) => {
|
||||
if (!valid) return;
|
||||
isSubmitting.value = true;
|
||||
const action = formData.id ? RoleAPI.update(formData.id, formData) : RoleAPI.create(formData);
|
||||
@@ -233,11 +234,11 @@ function closeRoleDialog() {
|
||||
function openRoleActions(item: RoleItem) {
|
||||
const commands: ActionSheetCommand[] = [];
|
||||
|
||||
if (hasPermission("sys:role:update")) {
|
||||
if (hasPermission(PERM.role.update)) {
|
||||
commands.push({ id: "edit", label: "编辑", execute: () => openRoleDialog(item.id) });
|
||||
}
|
||||
|
||||
if (hasPermission("sys:role:assign")) {
|
||||
if (hasPermission(PERM.role.assign)) {
|
||||
commands.push({
|
||||
id: "assign-perm",
|
||||
label: "分配权限",
|
||||
@@ -245,7 +246,7 @@ function openRoleActions(item: RoleItem) {
|
||||
});
|
||||
}
|
||||
|
||||
if (hasPermission("sys:role:delete")) {
|
||||
if (hasPermission(PERM.role.delete)) {
|
||||
commands.push({
|
||||
id: "delete",
|
||||
label: "删除",
|
||||
|
||||
@@ -230,7 +230,7 @@
|
||||
import { onLoad } from "@dcloudio/uni-app";
|
||||
import dayjs from "dayjs";
|
||||
import type { CascaderOption } from "@wot-ui/ui/components/wd-cascader/types";
|
||||
import { toFormSchema } from "@/utils/form-schema";
|
||||
import { toFormSchema, type WdFormRef } from "@/utils/form-schema";
|
||||
import { findOptionChain } from "@/utils/tree";
|
||||
import { useQueue, useToast } from "@wot-ui/ui";
|
||||
import ActionSheet, { type ActionSheetCommand } from "@/subPages/work/components/ActionSheet.vue";
|
||||
@@ -241,6 +241,7 @@ import RoleAPI from "@/api/role";
|
||||
import DeptAPI from "@/api/dept";
|
||||
import { getErrorMessage } from "@/utils/error";
|
||||
import { hasPermission } from "@/utils/permission";
|
||||
import { PERM } from "@/constants/permissions";
|
||||
|
||||
definePage({
|
||||
name: "user",
|
||||
@@ -251,7 +252,7 @@ const toast = useToast();
|
||||
const { closeOutside } = useQueue();
|
||||
const { confirmAction } = useConfirmAction();
|
||||
const actionSheetRef = ref<InstanceType<typeof ActionSheet>>();
|
||||
const formRef = ref();
|
||||
const formRef = ref<WdFormRef>();
|
||||
const isSubmitting = ref(false);
|
||||
|
||||
const sortValue = ref(0);
|
||||
@@ -412,7 +413,7 @@ async function openUserDialog(user?: UserItem) {
|
||||
|
||||
// 提交表单
|
||||
function submitUserForm() {
|
||||
formRef.value.validate().then(({ valid }: { valid: boolean }) => {
|
||||
formRef.value?.validate().then(({ valid }: { valid: boolean }) => {
|
||||
if (!valid) return;
|
||||
isSubmitting.value = true;
|
||||
const action = formData.id ? UserAPI.update(formData.id, formData) : UserAPI.create(formData);
|
||||
@@ -444,7 +445,7 @@ const resetPwdDialog = reactive({
|
||||
userId: undefined as number | undefined,
|
||||
});
|
||||
const resetPwdForm = reactive({ password: "" });
|
||||
const resetPwdFormRef = ref();
|
||||
const resetPwdFormRef = ref<WdFormRef>();
|
||||
|
||||
const resetPwdRules = toFormSchema({
|
||||
password: [
|
||||
@@ -458,7 +459,7 @@ function openUserActions(item: UserItem) {
|
||||
const commands: ActionSheetCommand[] = [];
|
||||
|
||||
// 重置密码
|
||||
if (hasPermission("sys:user:reset-password")) {
|
||||
if (hasPermission(PERM.user.resetPassword)) {
|
||||
commands.push({
|
||||
id: "reset-password",
|
||||
label: "重置密码",
|
||||
@@ -467,12 +468,12 @@ function openUserActions(item: UserItem) {
|
||||
}
|
||||
|
||||
// 编辑
|
||||
if (hasPermission("sys:user:update")) {
|
||||
if (hasPermission(PERM.user.update)) {
|
||||
commands.push({ id: "edit", label: "编辑", execute: () => openUserDialog(item) });
|
||||
}
|
||||
|
||||
// 删除
|
||||
if (hasPermission("sys:user:delete")) {
|
||||
if (hasPermission(PERM.user.delete)) {
|
||||
commands.push({
|
||||
id: "delete",
|
||||
label: "删除",
|
||||
|
||||
@@ -16,7 +16,7 @@ export interface FormRule {
|
||||
* 自定义校验:返回 true 表示通过;返回 false 按 message 提示;
|
||||
* 返回字符串则以该文案提示
|
||||
*/
|
||||
validator?: (value: any, model: Record<string, any>) => boolean | string;
|
||||
validator?: (value: unknown, model: Record<string, unknown>) => boolean | string;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -78,3 +78,11 @@ export function toFormSchema(rules: Record<string, FormRule[]>): FormSchema {
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
/** wd-form 实例引用,仅声明本项目用到的方法 */
|
||||
export interface WdFormRef {
|
||||
/** 校验表单,传字段名时只校验对应字段 */
|
||||
validate(field?: string): Promise<{ valid: boolean; errors: { message: string }[] }>;
|
||||
/** 重置校验状态 */
|
||||
reset(): void;
|
||||
}
|
||||
Reference in new issue
Block a user