update 重构 彻底删除proxy用法 改为vue3官方推荐写法

This commit is contained in:
疯狂的狮子Li
2026-04-10 13:07:37 +08:00
parent eb62402423
commit 9acf52e8a7
144 changed files with 1264 additions and 1082 deletions
+6 -5
View File
@@ -54,7 +54,7 @@
<el-table-column label="权限字符" align="center" prop="roleKey" />
<el-table-column label="创建时间" align="center" prop="createTime" width="180">
<template #default="scope">
<span>{{ proxy.parseTime(scope.row.createTime) }}</span>
<span>{{ parseTime(scope.row.createTime) }}</span>
</template>
</el-table-column>
</el-table>
@@ -64,14 +64,15 @@
</template>
<script setup name="AuthRole" lang="ts">
import { RouteLocationNormalized } from 'vue-router';
import { RoleVO } from '@/api/system/role/types';
import { getAuthRole, updateAuthRole } from '@/api/system/user';
import { UserForm } from '@/api/system/user/types';
import { RouteLocationNormalized } from 'vue-router';
import modal from '@/plugins/modal';
import tab from '@/plugins/tab';
import { parseTime } from '@/utils/ruoyi';
const route = useRoute();
const { proxy } = getCurrentInstance() as ComponentInternalInstance;
const loading = ref(true);
const total = ref(0);
@@ -119,14 +120,14 @@ const close = () => {
redirectedFrom: undefined,
path: '/system/user'
};
proxy?.$tab.closeOpenPage(obj);
tab.closeOpenPage(obj as any);
};
/** 提交按钮 */
const submitForm = async () => {
const userId = form.value.userId;
const rIds = roleIds.value.join(',');
await updateAuthRole({ userId: userId as string, roleIds: rIds });
proxy?.$modal.msgSuccess('授权成功');
modal.msgSuccess('授权成功');
close();
};
+33 -24
View File
@@ -451,22 +451,27 @@
</template>
<script setup name="User" lang="ts">
import TreePanel from '@/components/TreePanel/index.vue';
import { to } from 'await-to-js';
import { useRouter } from 'vue-router';
import { getConfigKey } from '@/api/system/config';
import { DeptTreeVO, DeptVO } from '@/api/system/dept/types';
import { optionselect } from '@/api/system/post';
import { PostVO } from '@/api/system/post/types';
import { RoleVO } from '@/api/system/role/types';
import api from '@/api/system/user';
import { UserForm, UserQuery, UserVO } from '@/api/system/user/types';
import { DeptTreeVO, DeptVO } from '@/api/system/dept/types';
import { RoleVO } from '@/api/system/role/types';
import { PostVO } from '@/api/system/post/types';
import { globalHeaders } from '@/utils/request';
import { to } from 'await-to-js';
import { optionselect } from '@/api/system/post';
import { checkPermi } from '@/utils/permission';
import TreePanel from '@/components/TreePanel/index.vue';
import modal from '@/plugins/modal';
import { useUserStore } from '@/store/modules/user';
import { useDict } from '@/utils/dict';
import { checkPermi } from '@/utils/permission';
import { globalHeaders } from '@/utils/request';
import { download as requestDownload } from '@/utils/request';
import { addDateRange } from '@/utils/ruoyi';
import UserViewDrawer from './view.vue';
const router = useRouter();
const { proxy } = getCurrentInstance() as ComponentInternalInstance;
const { sys_normal_disable, sys_user_gender } = toRefs<any>(proxy?.useDict('sys_normal_disable', 'sys_user_gender'));
const { sys_normal_disable, sys_user_gender } = toRefs<any>(useDict('sys_normal_disable', 'sys_user_gender'));
const userList = ref<UserVO[]>();
const loading = ref(true);
const showSearch = ref(true);
@@ -474,7 +479,7 @@ const ids = ref<Array<number | string>>([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);
const dateRange = ref<[DateModelType, DateModelType]>(['', '']);
const dateRange = ref<any>(['', '']);
const treeCollapsed = ref(false);
const deptOptions = ref<DeptTreeVO[]>([]);
const enabledDeptOptions = ref<DeptTreeVO[]>([]);
@@ -564,7 +569,11 @@ const initData: PageData<UserForm, UserQuery> = {
message: '用户密码长度必须介于 5 和 20 之间',
trigger: 'blur'
},
{ pattern: /^[^<>"'|\\]+$/, message: '不能包含非法字符:< > " \' \\ |', trigger: 'blur' }
{
pattern: /^[^<>"'|\\]+$/,
message: '不能包含非法字符:< > " \' \\ |',
trigger: 'blur'
}
],
email: [
{
@@ -590,7 +599,7 @@ const { queryParams, form, rules } = toRefs<PageData<UserForm, UserQuery>>(data)
/** 查询用户列表 */
const getList = async () => {
loading.value = true;
const res = await api.listUser(proxy?.addDateRange(queryParams.value, dateRange.value));
const res = await api.listUser(addDateRange(queryParams.value, dateRange.value));
loading.value = false;
userList.value = res.data?.rows;
total.value = res.data?.total;
@@ -640,21 +649,21 @@ const resetQuery = () => {
/** 删除按钮操作 */
const handleDelete = async (row?: UserVO) => {
const userIds = row?.userId || ids.value;
const [err] = await to(proxy?.$modal.confirm('是否确认删除用户编号为"' + userIds + '"的数据项?') as any);
const [err] = await to(modal.confirm('是否确认删除用户编号为"' + userIds + '"的数据项?') as any);
if (!err) {
await api.delUser(userIds);
await getList();
proxy?.$modal.msgSuccess('删除成功');
modal.msgSuccess('删除成功');
}
};
/** 解锁按钮操作 */
const handleUnlock = async () => {
const userId = ids.value[0];
const [err] = await to(proxy?.$modal.confirm('是否确认解锁用户编号为"' + userId + '"的数据项?') as any);
const [err] = await to(modal.confirm('是否确认解锁用户编号为"' + userId + '"的数据项?') as any);
if (!err) {
await api.unlockUser(userId);
proxy?.$modal.msgSuccess('用户编号"' + userId + '"解锁成功');
modal.msgSuccess('用户编号"' + userId + '"解锁成功');
}
};
@@ -662,9 +671,9 @@ const handleUnlock = async () => {
const handleStatusChange = async (row: UserVO) => {
const text = row.status === '0' ? '启用' : '停用';
try {
await proxy?.$modal.confirm('确认要"' + text + '""' + row.userName + '"用户吗?');
await modal.confirm('确认要"' + text + '""' + row.userName + '"用户吗?');
await api.changeUserStatus(row.userId, row.status);
proxy?.$modal.msgSuccess(text + '成功');
modal.msgSuccess(text + '成功');
} catch (err) {
row.status = row.status === '0' ? '1' : '0';
}
@@ -693,7 +702,7 @@ const handleResetPwd = async (row: UserVO) => {
);
if (!err && res) {
await api.resetUserPwd(row.userId, res.value);
proxy?.$modal.msgSuccess('修改成功,新密码是:' + res.value);
modal.msgSuccess('修改成功,新密码是:' + res.value);
}
};
@@ -716,7 +725,7 @@ const handleImport = () => {
};
/** 导出按钮操作 */
const handleExport = () => {
proxy?.download(
requestDownload(
'system/user/export',
{
...queryParams.value
@@ -726,7 +735,7 @@ const handleExport = () => {
};
/** 下载模板操作 */
const importTemplate = () => {
proxy?.download('system/user/importTemplate', {}, `user_template_${new Date().getTime()}.xlsx`);
requestDownload('system/user/importTemplate', {}, `user_template_${new Date().getTime()}.xlsx`);
};
/**文件上传中处理 */
@@ -811,7 +820,7 @@ const submitForm = () => {
} else {
await api.addUser(form.value);
}
proxy?.$modal.msgSuccess('操作成功');
modal.msgSuccess('操作成功');
dialog.visible = false;
await getList();
}
@@ -839,7 +848,7 @@ const resetForm = () => {
onMounted(() => {
getDeptTree(); // 初始化部门数据
getList(); // 初始化列表数据
proxy?.getConfigKey('sys.user.initPassword').then(response => {
getConfigKey('sys.user.initPassword').then(response => {
initPassword.value = response.data;
});
});
+6 -6
View File
@@ -93,15 +93,15 @@
</template>
<script setup name="Profile" lang="ts">
import UserAvatar from './userAvatar.vue';
import UserInfo from './userInfo.vue';
import ResetPwd from './resetPwd.vue';
import ThirdParty from './thirdParty.vue';
import OnlineDevice from './onlineDevice.vue';
import { getOnline } from '@/api/monitor/online';
import { getAuthList } from '@/api/system/social/auth';
import { getUserProfile } from '@/api/system/user';
import { getOnline } from '@/api/monitor/online';
import { UserVO } from '@/api/system/user/types';
import OnlineDevice from './onlineDevice.vue';
import ResetPwd from './resetPwd.vue';
import ThirdParty from './thirdParty.vue';
import UserAvatar from './userAvatar.vue';
import UserInfo from './userInfo.vue';
const activeTab = ref('userinfo');
interface State {
@@ -12,7 +12,7 @@
<el-table-column label="浏览器" align="center" prop="browser" :show-overflow-tooltip="true" />
<el-table-column label="登录时间" align="center" prop="loginTime" width="180">
<template #default="scope">
<span>{{ proxy.parseTime(scope.row.loginTime) }}</span>
<span>{{ parseTime(scope.row.loginTime) }}</span>
</template>
</el-table-column>
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
@@ -28,10 +28,13 @@
<script setup name="Online" lang="ts">
import { delOnline } from '@/api/monitor/online';
import modal from '@/plugins/modal';
import tab from '@/plugins/tab';
import { useDict } from '@/utils/dict';
import { propTypes } from '@/utils/propTypes';
import { parseTime } from '@/utils/ruoyi';
const { proxy } = getCurrentInstance() as ComponentInternalInstance;
const { sys_device_type } = toRefs<any>(proxy?.useDict('sys_device_type'));
const { sys_device_type } = toRefs<any>(useDict('sys_device_type'));
const props = defineProps({
devices: propTypes.any.isRequired
@@ -46,10 +49,10 @@ const handldDelOnline = (row: any) => {
})
.then((res: any) => {
if (res.code === 200) {
proxy?.$modal.msgSuccess('删除成功');
proxy?.$tab.refreshPage();
modal.msgSuccess('删除成功');
tab.refreshPage();
} else {
proxy?.$modal.msgError(res.msg);
modal.msgError(res.msg);
}
})
.catch(() => {});
+10 -5
View File
@@ -17,10 +17,11 @@
</template>
<script setup lang="ts">
import { updateUserPwd } from '@/api/system/user';
import type { ResetPwdForm } from '@/api/system/user/types';
import { updateUserPwd } from '@/api/system/user';
import modal from '@/plugins/modal';
import tab from '@/plugins/tab';
const { proxy } = getCurrentInstance() as ComponentInternalInstance;
const pwdRef = ref<ElFormInstance>();
const user = ref<ResetPwdForm>({
oldPassword: '',
@@ -45,7 +46,11 @@ const rules = ref({
message: '长度在 6 到 20 个字符',
trigger: 'blur'
},
{ pattern: /^[^<>"'|\\]+$/, message: '不能包含非法字符:< > " \' \\ |', trigger: 'blur' }
{
pattern: /^[^<>"'|\\]+$/,
message: '不能包含非法字符:< > " \' \\ |',
trigger: 'blur'
}
],
confirmPassword: [
{ required: true, message: '确认密码不能为空', trigger: 'blur' },
@@ -62,13 +67,13 @@ const submit = () => {
pwdRef.value?.validate(async (valid: boolean) => {
if (valid) {
await updateUserPwd(user.value.oldPassword, user.value.newPassword);
proxy?.$modal.msgSuccess('修改成功');
modal.msgSuccess('修改成功');
}
});
};
/** 关闭按钮 */
const close = () => {
proxy?.$tab.closePage();
tab.closePage();
};
</script>
+6 -6
View File
@@ -62,10 +62,10 @@
<script setup lang="ts">
import { authUnlock, authRouterUrl } from '@/api/system/social/auth';
import modal from '@/plugins/modal';
import tab from '@/plugins/tab';
import { propTypes } from '@/utils/propTypes';
const { proxy } = getCurrentInstance() as ComponentInternalInstance;
const props = defineProps({
auths: propTypes.any.isRequired
});
@@ -78,10 +78,10 @@ const unlockAuth = (row: any) => {
})
.then((res: any) => {
if (res.code === 200) {
proxy?.$modal.msgSuccess('解绑成功');
proxy?.$tab.refreshPage();
modal.msgSuccess('解绑成功');
tab.refreshPage();
} else {
proxy?.$modal.msgError(res.msg);
modal.msgError(res.msg);
}
})
.catch(() => {});
@@ -92,7 +92,7 @@ const authUrl = (source: string) => {
if (res.code === 200) {
window.location.href = res.data;
} else {
proxy?.$modal.msgError(res.msg);
modal.msgError(res.msg);
}
});
};
+4 -4
View File
@@ -57,10 +57,11 @@
<script setup lang="ts">
import 'vue-cropper/dist/index.css';
import { UploadRawFile } from 'element-plus';
import { VueCropper } from 'vue-cropper';
import { uploadAvatar } from '@/api/system/user';
import modal from '@/plugins/modal';
import { useUserStore } from '@/store/modules/user';
import { UploadRawFile } from 'element-plus';
interface Options {
img: string | any; // 裁剪图片的地址
@@ -75,7 +76,6 @@ interface Options {
}
const userStore = useUserStore();
const { proxy } = getCurrentInstance() as ComponentInternalInstance;
const open = ref(false);
const visible = ref(false);
@@ -121,7 +121,7 @@ const changeScale = (num: number) => {
/** 上传预处理 */
const beforeUpload = (file: UploadRawFile): any => {
if (file.type.indexOf('image/') == -1) {
proxy?.$modal.msgError('文件格式错误,请上传图片类型,如:JPG,PNG后缀的文件。');
modal.msgError('文件格式错误,请上传图片类型,如:JPG,PNG后缀的文件。');
} else {
const reader = new FileReader();
reader.readAsDataURL(file);
@@ -140,7 +140,7 @@ const uploadImg = async () => {
open.value = false;
options.img = res.data.imgUrl;
userStore.setAvatar(options.img);
proxy?.$modal.msgSuccess('修改成功');
modal.msgSuccess('修改成功');
visible.value = false;
});
};
+9 -4
View File
@@ -24,13 +24,14 @@
<script setup lang="ts">
import { updateUserProfile } from '@/api/system/user';
import modal from '@/plugins/modal';
import tab from '@/plugins/tab';
import { propTypes } from '@/utils/propTypes';
const props = defineProps({
user: propTypes.any.isRequired
});
const userForm = computed(() => props.user);
const { proxy } = getCurrentInstance() as ComponentInternalInstance;
const userRef = ref<ElFormInstance>();
const rule: ElFormRules = {
nickName: [{ required: true, message: '用户昵称不能为空', trigger: 'blur' }],
@@ -48,7 +49,11 @@ const rule: ElFormRules = {
message: '手机号码不能为空',
trigger: 'blur'
},
{ pattern: /^1[3456789][0-9]\d{8}$/, message: '请输入正确的手机号码', trigger: 'blur' }
{
pattern: /^1[3456789][0-9]\d{8}$/,
message: '请输入正确的手机号码',
trigger: 'blur'
}
]
};
const rules = ref<ElFormRules>(rule);
@@ -58,13 +63,13 @@ const submit = () => {
userRef.value?.validate(async (valid: boolean) => {
if (valid) {
await updateUserProfile(props.user);
proxy?.$modal.msgSuccess('修改成功');
modal.msgSuccess('修改成功');
}
});
};
/** 关闭按钮 */
const close = () => {
proxy?.$tab.closePage();
tab.closePage();
};
</script>
+24 -12
View File
@@ -1,18 +1,29 @@
<template>
<el-drawer v-model="visible" title="用户信息详情" :size="680" append-to-body :close-on-click-modal="true" @closed="info = null">
<el-drawer
v-model="visible"
title="用户信息详情"
:size="680"
append-to-body
:close-on-click-modal="true"
@closed="info = null"
>
<el-descriptions v-if="info" v-loading="loading" :column="2" border>
<el-descriptions-item label="用户名称">{{ info.nickName }}</el-descriptions-item>
<el-descriptions-item label="归属部门">{{ info.deptName || (info.dept && info.dept.deptName) || '-' }}</el-descriptions-item>
<el-descriptions-item label="归属部门">
{{ info.deptName || (info.dept && info.dept.deptName) || '-' }}
</el-descriptions-item>
<el-descriptions-item label="手机号码">{{ info.phoneNumber || '-' }}</el-descriptions-item>
<el-descriptions-item label="邮箱">{{ info.email || '-' }}</el-descriptions-item>
<el-descriptions-item label="登录账号">{{ info.userName }}</el-descriptions-item>
<el-descriptions-item label="用户状态">
<el-tag :type="info.status === '0' ? 'success' : 'danger'">
{{ proxy?.selectDictLabel(sys_normal_disable, info.status) }}
{{ selectDictLabel(sys_normal_disable, info.status) }}
</el-tag>
</el-descriptions-item>
<el-descriptions-item label="岗位">{{ postNames || '-' }}</el-descriptions-item>
<el-descriptions-item label="用户性别">{{ proxy?.selectDictLabel(sys_user_gender, info.gender) || '-' }}</el-descriptions-item>
<el-descriptions-item label="用户性别">
{{ selectDictLabel(sys_user_gender, info.gender) || '-' }}
</el-descriptions-item>
<el-descriptions-item label="角色" :span="2">{{ roleNames || '-' }}</el-descriptions-item>
</el-descriptions>
@@ -29,13 +40,14 @@
</template>
<script setup lang="ts">
import api from '@/api/system/user';
import type { UserVO } from '@/api/system/user/types';
import type { PostVO } from '@/api/system/post/types';
import type { RoleVO } from '@/api/system/role/types';
import type { UserVO } from '@/api/system/user/types';
import api from '@/api/system/user';
import { useDict } from '@/utils/dict';
import { selectDictLabel } from '@/utils/ruoyi';
const { proxy } = getCurrentInstance() as ComponentInternalInstance;
const { sys_normal_disable, sys_user_gender } = toRefs<any>(proxy?.useDict('sys_normal_disable', 'sys_user_gender'));
const { sys_normal_disable, sys_user_gender } = toRefs<any>(useDict('sys_normal_disable', 'sys_user_gender'));
const visible = ref(false);
const loading = ref(false);
@@ -48,16 +60,16 @@ const roleIds = ref<string[]>([]);
const postNames = computed(() => {
if (!postOptions.value.length || !postIds.value.length) return '';
return postOptions.value
.filter((p) => postIds.value.includes(String(p.postId)))
.map((p) => p.postName)
.filter(p => postIds.value.includes(String(p.postId)))
.map(p => p.postName)
.join('、');
});
const roleNames = computed(() => {
if (!roleOptions.value.length || !roleIds.value.length) return '';
return roleOptions.value
.filter((r) => roleIds.value.includes(String(r.roleId)))
.map((r) => r.roleName)
.filter(r => roleIds.value.includes(String(r.roleId)))
.map(r => r.roleName)
.join('、');
});