refactor: ♻️ 解决TS类型错误

This commit is contained in:
zhangyuanpeng
2024-12-13 16:45:42 +08:00
parent d5b522b8e9
commit fa7a6aba8e
5 changed files with 42 additions and 40 deletions

View File

@@ -116,9 +116,9 @@ export interface RolePageVO {
/** 角色状态 */
status?: number;
/** 创建时间 */
createTime?: Date;
createTime?: string;
/** 修改时间 */
updateTime?: Date;
updateTime?: string;
}
/** 角色表单对象 */
@@ -128,7 +128,7 @@ export interface RoleForm {
/** 角色编码 */
code?: string;
/** 数据权限 */
dataScope?: number;
dataScope: number;
/** 角色名称 */
name?: string;
/** 排序 */

View File

@@ -238,7 +238,7 @@ export interface UserProfileVO {
roleNames?: string;
/** 创建时间 */
createTime?: Date;
createTime?: string;
}
/** 个人中心用户信息表单 */

View File

@@ -91,7 +91,7 @@ function avatarUpload() {
});
}
// 头像裁剪完成
function handleAvatarConfirm(event) {
function handleAvatarConfirm(event: any) {
const { tempFilePath } = event;
FileAPI.upload(tempFilePath).then((fileInfo: FileInfo) => {
const avatarForm: UserProfileForm = {
@@ -131,7 +131,7 @@ const handleOpenDialog = () => {
// 提交表单
function handleSubmit() {
userProfileFormRef.value.validate().then(({ valid }) => {
userProfileFormRef.value.validate().then(({ valid }: { valid: boolean }) => {
if (valid) {
UserAPI.updateProfile(userProfileForm).then(() => {
uni.showToast({ title: "账号资料修改成功", icon: "none" });
@@ -158,13 +158,13 @@ onBeforeUnmount(() => {
// #endif
});
// 禁用浏览器双指缩放,使头像裁剪时双指缩放能够起作用
function touchstartListener(event) {
function touchstartListener(event: TouchEvent) {
if (event.touches.length > 1) {
event.preventDefault();
}
}
// 禁用浏览器下拉刷新,使头像裁剪时能够移动图片
function touchmoveListener(event) {
function touchmoveListener(event: TouchEvent) {
event.preventDefault();
}
</script>

View File

@@ -34,10 +34,8 @@
import RoleAPI from "@/api/system/role";
import MenuAPI from "@/api/system/menu";
import DaTree from "@/components/da-tree/index.vue";
import { useMessage } from "wot-design-uni";
const message = useMessage();
let roleId = ref<number>(null); // 操作的角色ID
let roleId = ref<number>(); // 操作的角色ID
const menuPermOptions = ref<OptionType[]>([]); // 所有菜单
let rootKeys = ref<number[]>([]); // 根节点数组
const DaTreeRef = ref(); // 树引用
@@ -49,12 +47,10 @@ const showFab = ref(); // 悬浮按钮是否展开
async function initAssignPerm() {
// 获取所有的菜单
menuPermOptions.value = await MenuAPI.getOptions(false);
console.log("menuPermOptions.value", menuPermOptions.value);
rootKeys.value = menuPermOptions.value.map((item) => item.value);
rootKeys.value = menuPermOptions.value.map((item) => item.value as number);
// 回显角色已拥有的菜单
RoleAPI.getRoleMenuIds(roleId.value).then((data) => {
RoleAPI.getRoleMenuIds(roleId.value!).then((data) => {
const checkedMenuIds = data;
console.log("checkedMenuIds=", checkedMenuIds);
if (checkedMenuIds && checkedMenuIds.length > 0) {
DaTreeRef.value?.setCheckedKeys(checkedMenuIds, true);
}
@@ -62,12 +58,12 @@ async function initAssignPerm() {
}
// 展开/收起树节点
function doExpandTree(keys, expand) {
function doExpandTree(keys: number[] | string, expand: boolean) {
DaTreeRef.value?.setExpandedKeys(keys, expand);
showFab.value = false;
}
// 选中/取消树节点
function doCheckedTree(keys, checked) {
function doCheckedTree(keys: number[], checked: boolean) {
DaTreeRef.value?.setCheckedKeys(keys, checked);
showFab.value = false;
}
@@ -76,7 +72,7 @@ function doCheckedTree(keys, checked) {
function handleAssignPermSubmit() {
if (roleId.value) {
const checkedMenuIds: number[] = DaTreeRef.value?.getCheckedKeys();
RoleAPI.updateRoleMenus(roleId.value, JSON.stringify(checkedMenuIds)).then(() => {
RoleAPI.updateRoleMenus(roleId.value, checkedMenuIds).then(() => {
uni.showToast({ title: "分配权限成功", icon: "success" });
uni.navigateBack({ delta: 1 });
});

View File

@@ -98,6 +98,7 @@ import RoleAPI, { RolePageVO, RolePageQuery, RoleForm } from "@/api/system/role"
import { onLoad, onReachBottom } from "@dcloudio/uni-app";
import { LoadMoreState } from "wot-design-uni/components/wd-loadmore/types";
import { DropMenuItemExpose } from "wot-design-uni/components/wd-drop-menu-item/types";
import { FormInstance } from "wot-design-uni/components/wd-form/types";
import { FormRules } from "wot-design-uni/components/wd-form/types";
import { useMessage } from "wot-design-uni";
const message = useMessage();
@@ -198,7 +199,10 @@ const dataScopeOptions = ref<Record<string, any>[]>([
{ label: "本人数据", value: 3 },
]);
const formData = reactive<RoleForm>({});
const formData = reactive<RoleForm>({
dataScope: 0,
sort: 1,
});
const rules: FormRules = {
name: [{ required: true, message: "请输入角色名称", trigger: "blur" }],
@@ -208,14 +212,14 @@ const rules: FormRules = {
sort: [{ required: true, message: "请输入排序号", trigger: "change" }],
};
const roleFormRef = ref();
const roleFormRef = ref<FormInstance>();
/**
* 打开弹窗
*/
async function handleOpenDialog(id?: number) {
dialog.visible = true;
formData.id = null;
formData.id = undefined;
formData.name = "";
formData.code = "";
formData.dataScope = 0;
@@ -232,26 +236,28 @@ async function handleOpenDialog(id?: number) {
* 提交保存
*/
function handleSubmit() {
roleFormRef.value.validate().then(({ valid }: { valid: boolean }) => {
if (valid) {
const roleId = formData.id;
if (roleId) {
RoleAPI.update(roleId, formData).then(() => {
uni.showToast({ title: "修改成功", icon: "success" });
dialog.visible = false;
queryParams.pageNum = 1;
handleQuery();
});
} else {
RoleAPI.add(formData).then(() => {
uni.showToast({ title: "添加成功", icon: "success" });
dialog.visible = false;
queryParams.pageNum = 1;
handleQuery();
});
if (roleFormRef.value) {
roleFormRef.value.validate().then(({ valid }) => {
if (valid) {
const roleId = formData.id;
if (roleId) {
RoleAPI.update(roleId, formData).then(() => {
uni.showToast({ title: "修改成功", icon: "success" });
dialog.visible = false;
queryParams.pageNum = 1;
handleQuery();
});
} else {
RoleAPI.add(formData).then(() => {
uni.showToast({ title: "添加成功", icon: "success" });
dialog.visible = false;
queryParams.pageNum = 1;
handleQuery();
});
}
}
}
});
});
}
}
/**