diff --git a/src/constants/permissions.ts b/src/constants/permissions.ts index 17d7f55..6a02990 100644 --- a/src/constants/permissions.ts +++ b/src/constants/permissions.ts @@ -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; diff --git a/src/pages/login/index.vue b/src/pages/login/index.vue index 8334cf8..4a3afb3 100644 --- a/src/pages/login/index.vue +++ b/src/pages/login/index.vue @@ -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(); const bindMobilePopupRef = ref>(); // 表单状态 diff --git a/src/subPages/mine/account/index.vue b/src/subPages/mine/account/index.vue index e50a82f..3ad6e7a 100644 --- a/src/subPages/mine/account/index.vue +++ b/src/subPages/mine/account/index.vue @@ -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(); const passwordChangeForm = reactive({}); const mobileBindingForm = reactive({}); const emailBindingForm = reactive({}); -const passwordChangeFormRef = ref(); -const mobileBindingFormRef = ref(); -const emailBindingFormRef = ref(); +const passwordChangeFormRef = ref(); +const mobileBindingFormRef = ref(); +const emailBindingFormRef = ref(); 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("邮箱绑定成功"); diff --git a/src/subPages/mine/profile/complete-profile/index.vue b/src/subPages/mine/profile/complete-profile/index.vue index f71e544..5d6a739 100644 --- a/src/subPages/mine/profile/complete-profile/index.vue +++ b/src/subPages/mine/profile/complete-profile/index.vue @@ -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(); // 提交按钮的可用条件:昵称与手机号都已填写 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; diff --git a/src/subPages/mine/profile/index.vue b/src/subPages/mine/profile/index.vue index be3db48..428430b 100644 --- a/src/subPages/mine/profile/index.vue +++ b/src/subPages/mine/profile/index.vue @@ -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({}); -const userProfileFormRef = ref(); +const userProfileFormRef = ref(); // 打开资料编辑弹窗,并用当前资料回填表单 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("账号资料修改成功"); diff --git a/src/subPages/work/config/index.vue b/src/subPages/work/config/index.vue index a60f26f..3a54921 100644 --- a/src/subPages/work/config/index.vue +++ b/src/subPages/work/config/index.vue @@ -92,13 +92,14 @@