优化平台端租户端

This commit is contained in:
2026-09-09 00:30:44 +08:00
parent 672c22d9b6
commit 34b2449462
20 changed files with 847 additions and 42 deletions
@@ -35,11 +35,17 @@
</el-tag>
</template>
</el-table-column>
<el-table-column label="操作" width="140" align="center" fixed="right">
<el-table-column label="操作" width="260" align="center" fixed="right">
<template #default="{ row }">
<el-button text type="primary" @click="openPasswordDialog(row)">
修改密码
<el-button text type="primary" @click="openPasswordDialog(row)">修改密码</el-button>
<el-button
text
:type="Number(row.status) === 1 ? 'warning' : 'success'"
@click="handleToggleStatus(row)"
>
{{ Number(row.status) === 1 ? "禁用" : "启用" }}
</el-button>
<el-button text type="danger" @click="handleDelete(row)">删除</el-button>
</template>
</el-table-column>
</el-table>
@@ -65,9 +71,13 @@
<script setup lang="ts">
import { ref, reactive, watch } from "vue";
import { ElMessage } from "element-plus";
import { ElMessage, ElMessageBox } from "element-plus";
import { Plus } from "@element-plus/icons-vue";
import { getAllUsers, changePassword } from "@/api/user";
import {
getTenantUserList,
editTenantUser,
deleteTenantUser,
} from "@/api/tenantUser";
import AddUser from "./adduser.vue";
const props = defineProps<{
@@ -119,7 +129,7 @@ const refreshTenantUsers = async () => {
if (id == null) return;
usersLoading.value = true;
try {
const usersRes = await getAllUsers(buildTenantUserQuery(id));
const usersRes = await getTenantUserList(buildTenantUserQuery(id));
if (usersRes?.code === 200) {
tenantUsers.value = usersRes?.data?.list || usersRes?.data || [];
} else {
@@ -135,7 +145,7 @@ const refreshTenantUsers = async () => {
const loadUsersForTid = async (tid: number) => {
usersLoading.value = true;
try {
const usersRes = await getAllUsers({ tid });
const usersRes = await getTenantUserList({ tid });
if (usersRes?.code === 200) {
tenantUsers.value = usersRes?.data?.list || usersRes?.data || [];
} else {
@@ -194,7 +204,9 @@ const submitPassword = async () => {
passwordSubmitting.value = true;
try {
const res = await changePassword(currentTenantUserId.value, { newPassword: passwordForm.password });
const res = await editTenantUser(currentTenantUserId.value, {
password: passwordForm.password,
});
if (res.code === 200) {
ElMessage.success("密码修改成功");
passwordDialogVisible.value = false;
@@ -206,6 +218,52 @@ const submitPassword = async () => {
}
};
const handleToggleStatus = async (row: any) => {
const next = Number(row.status) === 1 ? 0 : 1;
const actionText = next === 0 ? "禁用" : "启用";
const name = row.name || row.account || `ID ${row.id}`;
try {
await ElMessageBox.confirm(`确定要${actionText}用户「${name}」吗?`, "提示", {
type: "warning",
});
} catch {
return;
}
try {
const res = await editTenantUser(row.id, { status: next });
if (res.code === 200) {
ElMessage.success(`${actionText}成功`);
refreshTenantUsers();
} else {
ElMessage.error(res.msg || `${actionText}失败`);
}
} catch (e: any) {
ElMessage.error(e?.message || `${actionText}失败`);
}
};
const handleDelete = async (row: any) => {
const name = row.name || row.account || `ID ${row.id}`;
try {
await ElMessageBox.confirm(`确定要删除用户「${name}」吗?删除后不可恢复。`, "警告", {
type: "warning",
});
} catch {
return;
}
try {
const res = await deleteTenantUser(row.id);
if (res.code === 200) {
ElMessage.success("删除成功");
refreshTenantUsers();
} else {
ElMessage.error(res.msg || "删除失败");
}
} catch (e: any) {
ElMessage.error(e?.message || "删除失败");
}
};
defineExpose({
refreshTenantUsers,
});
@@ -43,7 +43,7 @@
*/
import { ref, reactive } from 'vue';
import { ElMessage } from 'element-plus';
import { addUser } from '@/api/user';
import { createTenantUser } from '@/api/tenantUser';
const emit = defineEmits(['success']);
const visible = ref(false);
@@ -123,7 +123,7 @@ const submitForm = async () => {
};
// 提交时不需要把确认密码发给后端
delete (submitData as any).password2;
const res = await addUser(submitData);
const res = await createTenantUser(submitData);
if (res.code === 200) {
ElMessage.success('添加成功');
visible.value = false;