refactor: 替换 messageBox 为 confirm 并补充类型注解

This commit is contained in:
Mickey wu
2026-05-24 17:14:51 +08:00
parent 2def31cc14
commit 094864b73b
9 changed files with 38 additions and 37 deletions

View File

@@ -111,7 +111,7 @@ import ConfigAPI, { type ConfigPageQuery, ConfigItem, ConfigForm } from "@/api/c
import { hasPermission } from "@/utils/permission";
const toast = useToast();
const { messageBox } = useDialog();
const { confirm } = useDialog();
const loadMoreState = ref<LoadMoreState>("loading");
const formRef = ref();
const isSubmitting = ref(false);
@@ -154,7 +154,7 @@ function loadConfigList() {
function fetchConfigList() {
loadMoreState.value = "loading";
ConfigAPI.getPage(queryParams)
.then((data) => {
.then((data: any) => {
pageData.value = data.list;
total.value = data.total;
queryParams.pageNum++;
@@ -211,10 +211,10 @@ function handleActionSelect({ item }: { item: any }) {
if (value === "编辑") {
openConfigDialog(configItem.id);
} else if (value === "删除") {
messageBox({
confirm({
title: "确认删除",
msg: `确定要删除配置「${configItem.configName}」吗?`,
type: "warning",
headerImage: "warning",
}).then(async () => {
await ConfigAPI.deleteById(configItem.id!);
toast.success("删除成功");

View File

@@ -100,7 +100,7 @@ import { hasPermission } from "@/utils/permission";
import CustomTree from "@/components/custom-tree/index.vue";
const toast = useToast();
const { messageBox } = useDialog();
const { confirm } = useDialog();
const formRef = ref();
const isSubmitting = ref(false);
@@ -215,10 +215,10 @@ function handleActionSelect({ item }: { item: any }) {
} else if (value === "编辑") {
openDeptDialog(dept);
} else if (value === "删除") {
messageBox({
confirm({
title: "确认删除",
msg: `确定要删除部门「${dept.name}」吗?`,
type: "warning",
headerImage: "warning",
}).then(async () => {
await DeptAPI.deleteByIds(String(dept.id));
toast.success("删除成功");
@@ -284,7 +284,7 @@ async function openDeptDialog(dept?: DeptItem) {
const columns: OptionType[][] = [firstColumn];
let currentLevel = data;
for (let i = 0; i < path.length - 1; i++) {
const found = currentLevel.find((item) => String(item.value) === path[i]);
const found = currentLevel.find((item: any) => String(item.value) === path[i]);
if (found && found.children) {
columns.push(found.children);
currentLevel = found.children;

View File

@@ -107,7 +107,7 @@ import { hasPermission } from "@/utils/permission";
const router = useRouter();
const toast = useToast();
const { messageBox } = useDialog();
const { confirm } = useDialog();
const loadMoreState = ref<LoadMoreState>("loading");
const formRef = ref();
const isSubmitting = ref(false);
@@ -218,10 +218,10 @@ function showDictActions(item: DictTypeItem) {
actions.push({ name: "删除", color: "var(--color-danger)" });
actionMap["删除"] = async () => {
try {
await messageBox({
await confirm({
title: "确认删除",
msg: `确定要删除字典「${item.name}」吗?`,
type: "warning",
headerImage: "warning",
});
if (item.id) {
await DictAPI.deleteByIds(String(item.id));

View File

@@ -115,7 +115,7 @@ import DictAPI, { type DictItemForm, type DictItemPageQuery, type DictDataItem }
import { hasPermission } from "@/utils/permission";
const toast = useToast();
const { messageBox } = useDialog();
const { confirm } = useDialog();
const dictCode = ref<string>("");
const pageTitle = ref<string>("字典数据");
@@ -238,10 +238,10 @@ function showItemActions(item: DictDataItem) {
actions.push({ name: "删除", color: "var(--color-danger)" });
actionMap["删除"] = async () => {
try {
await messageBox({
await confirm({
title: "确认删除",
msg: `确定要删除字典数据「${item.label}」吗?`,
type: "warning",
headerImage: "warning",
});
if (item.id) {
await DictAPI.deleteItems(dictCode.value, String(item.id));
@@ -276,7 +276,7 @@ onReachBottom(() => {
}
});
onLoad((query) => {
onLoad((query: any) => {
dictCode.value = String((query as any)?.dictCode || "");
pageTitle.value = String((query as any)?.title || "字典数据");
if (pageTitle.value) {

View File

@@ -126,7 +126,7 @@ import { hasPermission } from "@/utils/permission";
import CustomTree from "@/components/custom-tree/index.vue";
const toast = useToast();
const { messageBox } = useDialog();
const { confirm } = useDialog();
const formRef = ref();
const isSubmitting = ref(false);
@@ -154,7 +154,7 @@ const initialFormData: MenuForm = {
const formData = reactive<MenuForm>({ ...initialFormData });
// 转换为树组件数据格式
const treeData = computed(() => menuList.value.map((menu) => transformMenuToTree(menu)));
const treeData = computed(() => menuList.value.map((menu: MenuItem) => transformMenuToTree(menu)));
function transformMenuToTree(menu: MenuItem): any {
return {
@@ -166,7 +166,7 @@ function transformMenuToTree(menu: MenuItem): any {
icon: menu.icon,
visible: menu.visible,
perm: menu.perm,
children: menu.children?.map((child) => transformMenuToTree(child)) || [],
children: menu.children?.map((child: MenuItem) => transformMenuToTree(child)) || [],
};
}
@@ -252,7 +252,7 @@ const rules = toFormSchema({
const handleSearch = () => loadMenuList();
function loadMenuList() {
MenuAPI.getList(queryParams).then((data) => {
MenuAPI.getList(queryParams).then((data: any) => {
menuList.value = data;
});
}
@@ -266,10 +266,10 @@ function handleActionSelect({ item }: { item: any }) {
} else if (value === "编辑") {
openMenuDialog(menu);
} else if (value === "删除") {
messageBox({
confirm({
title: "确认删除",
msg: `确定要删除菜单「${menu.name}」吗?`,
type: "warning",
headerImage: "warning",
}).then(async () => {
await MenuAPI.deleteById(menu.id!);
toast.success("删除成功");
@@ -336,7 +336,7 @@ async function openMenuDialog(menu?: MenuItem) {
const columns: OptionType[][] = [firstColumn];
let currentLevel = data;
for (let i = 0; i < path.length - 1; i++) {
const found = currentLevel.find((item) => String(item.value) === String(path[i]));
const found = currentLevel.find((item: any) => String(item.value) === String(path[i]));
if (found && found.children && found.children.length > 0) {
columns.push(found.children);
currentLevel = found.children;

View File

@@ -176,7 +176,7 @@ import NoticeAPI, {
import { hasPermission } from "@/utils/permission";
const toast = useToast();
const { messageBox } = useDialog();
const { confirm } = useDialog();
const loadMoreState = ref<LoadMoreState>("loading");
const formRef = ref();
const isSubmitting = ref(false);
@@ -335,7 +335,7 @@ function showNoticeActions(item: NoticeItem) {
actions.push({ name: "删除", color: "var(--color-danger)" });
actionMap["删除"] = async () => {
try {
await messageBox({
await confirm({
title: "确认删除",
msg: `确定要删除通知「${item.title}」吗?`,
type: "warning",
@@ -352,7 +352,7 @@ function showNoticeActions(item: NoticeItem) {
actions.push({ name: "发布" });
actionMap["发布"] = async () => {
try {
await messageBox({
await confirm({
title: "确认发布",
msg: `确定要发布通知「${item.title}」吗?`,
type: "warning",
@@ -370,7 +370,7 @@ function showNoticeActions(item: NoticeItem) {
actions.push({ name: "撤回", color: "var(--color-warning)" });
actionMap["撤回"] = async () => {
try {
await messageBox({
await confirm({
title: "确认撤回",
msg: `确定要撤回通知「${item.title}」吗?`,
type: "warning",

View File

@@ -76,10 +76,6 @@
</template>
<script lang="ts" setup>
definePage({
name: "role-assign-perm",
style: { navigationBarTitleText: "分配权限" },
});
import { onLoad } from "@dcloudio/uni-app";
import MenuAPI, { type MenuItem } from "@/api/menu";
@@ -87,6 +83,11 @@ import RoleAPI from "@/api/role";
import CustomTree from "@/components/custom-tree/index.vue";
import type { TreeOption } from "@/components/custom-tree/index.vue";
definePage({
name: "role-assign-perm",
style: { navigationBarTitleText: "分配权限" },
});
const toast = useToast();
const isSubmitting = ref(false);
const roleId = ref<number>(0);

View File

@@ -124,7 +124,7 @@ import RoleAPI, { type RolePageQuery, RoleItem, RoleForm } from "@/api/role";
import { hasPermission } from "@/utils/permission";
const toast = useToast();
const { messageBox } = useDialog();
const { confirm } = useDialog();
const loadMoreState = ref<LoadMoreState>("loading");
const formRef = ref();
const isSubmitting = ref(false);
@@ -235,10 +235,10 @@ function handleActionSelect({ item }: { item: any }) {
} else if (value === "分配权限") {
handleAssignPerm(role.id);
} else if (value === "删除") {
messageBox({
confirm({
title: "确认删除",
msg: `确定要删除角色「${role.name}」吗?`,
type: "warning",
headerImage: "warning",
}).then(async () => {
await RoleAPI.deleteByIds(String(item.id));
toast.success("删除成功");

View File

@@ -213,7 +213,7 @@ import DeptAPI from "@/api/dept";
import { hasPermission } from "@/utils/permission";
const toast = useToast();
const { messageBox } = useDialog();
const { confirm } = useDialog();
const { closeOutside } = useQueue();
const loadMoreState = ref<LoadMoreState>("loading");
const formRef = ref();
@@ -339,7 +339,7 @@ function resetUserFilter() {
function fetchUserList() {
loadMoreState.value = "loading";
UserAPI.getPage(queryParams)
.then((data) => {
.then((data: any) => {
pageData.value = data.list;
total.value = data.total;
queryParams.pageNum++;
@@ -453,10 +453,10 @@ function showUserActions(item: UserItem) {
actions.push({ name: "删除", color: "var(--color-danger)" });
actionMap["删除"] = async () => {
try {
await messageBox({
await confirm({
title: "确认删除",
msg: `确定要删除用户「${item.nickname}」吗?`,
type: "warning",
headerImage: "warning",
});
await UserAPI.deleteByIds(String(item.id));
toast.success("删除成功");