refactor: 界面样式重构优化
This commit is contained in:
1 parent
5348ddad36
commit
306d167a55
52 files changed
+3391
-1459
No files matched your search
+191
-280
@@ -1,298 +1,240 @@
|
||||
<template>
|
||||
<view class="work">
|
||||
<!-- 筛选 -->
|
||||
<wd-drop-menu close-on-click-modal class="mb-20rpx mr-20rpx ml-20rpx">
|
||||
<wd-drop-menu-item ref="dropMenu" title="筛选" icon="filter" icon-size="18px">
|
||||
<view>
|
||||
<wd-input
|
||||
v-model="queryParams.keywords"
|
||||
label="关键字"
|
||||
type="text"
|
||||
clearable
|
||||
placeholder="请输入关键字"
|
||||
/>
|
||||
<view class="flex flex-row items-center mb-20rpx">
|
||||
<wd-button class="mt-20rpx mb-20rpx" size="medium" @click="handleQuery()">
|
||||
查询
|
||||
</wd-button>
|
||||
<wd-button size="medium" type="info" @click="handleReset">重置</wd-button>
|
||||
<view class="page page--padding page--pt">
|
||||
<view>
|
||||
<wd-search
|
||||
v-model="queryParams.keywords"
|
||||
placeholder="搜索配置名称/键名"
|
||||
hide-cancel
|
||||
@search="handleSearch"
|
||||
/>
|
||||
</view>
|
||||
|
||||
<view class="mt-16rpx">
|
||||
<wd-card
|
||||
v-for="item in pageData"
|
||||
:key="item.id"
|
||||
custom-class="item-card"
|
||||
@click="openConfigDialog(item.id)"
|
||||
>
|
||||
<view class="flex-between">
|
||||
<text class="font-bold text-32rpx">{{ item.configName }}</text>
|
||||
<view
|
||||
class="w-88rpx h-88rpx flex-center rounded-full"
|
||||
hover-class="bg-[var(--color-text-placeholder)]/16"
|
||||
@click.stop="showConfigActions(item)"
|
||||
>
|
||||
<wd-icon name="more" size="18" class="color-text-secondary" />
|
||||
</view>
|
||||
</view>
|
||||
</wd-drop-menu-item>
|
||||
</wd-drop-menu>
|
||||
|
||||
<view class="data-container">
|
||||
<!-- 列表内容 -->
|
||||
<view v-for="(item, index) in pageData" :key="index" class="mb-20rpx">
|
||||
<wd-card>
|
||||
<template #title>
|
||||
<view class="flex items-center justify-between">
|
||||
<view class="flex-1 text-truncate">{{ item.configName }}</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<wd-cell-group>
|
||||
<wd-cell title="配置键" :value="item.configKey" />
|
||||
<wd-cell title="配置值" :value="item.configValue" />
|
||||
<wd-cell title="备注" :value="item.remark" />
|
||||
<view class="mt-12rpx">
|
||||
<wd-cell-group border>
|
||||
<wd-cell title="配置项" :value="item.configKey" ellipsis />
|
||||
<wd-cell title="配置值" :value="item.configValue" ellipsis />
|
||||
<wd-cell title="描述" :value="item.remark || '暂无描述'" ellipsis />
|
||||
</wd-cell-group>
|
||||
</view>
|
||||
</wd-card>
|
||||
|
||||
<template #footer>
|
||||
<wd-button size="small" plain type="primary" @click="handleAction(item)">
|
||||
操作
|
||||
</wd-button>
|
||||
</template>
|
||||
</wd-card>
|
||||
</view>
|
||||
<wd-loadmore v-if="total > 0" :state="loadMoreState" @reload="fetchConfigList" />
|
||||
<wd-status-tip v-else-if="total === 0" image="search" tip="暂无数据" />
|
||||
</view>
|
||||
|
||||
<!-- 加载更多 -->
|
||||
<wd-loadmore :state="state" @reload="handleQuery" />
|
||||
|
||||
<!-- 底部按钮 -->
|
||||
<view class="fixed bottom-0 w-full flex justify-around items-center p-20rpx bg-#fff">
|
||||
<wd-button size="medium" type="primary" @click="handleOpenDialog">添加</wd-button>
|
||||
<wd-button size="medium" type="success" @click="refreshCache">刷新缓存</wd-button>
|
||||
</view>
|
||||
|
||||
<wd-popup v-model="showEditPopup" position="bottom">
|
||||
<view class="p-20rpx">
|
||||
<wd-form ref="formRef" :model="form">
|
||||
<wd-input
|
||||
v-model="form.configName"
|
||||
label="配置名称"
|
||||
type="text"
|
||||
placeholder="请输入配置名称"
|
||||
:rules="[{ required: true, message: '请填写配置名称' }]"
|
||||
/>
|
||||
<wd-input
|
||||
v-model="form.configKey"
|
||||
label="配置键名"
|
||||
type="text"
|
||||
placeholder="请输入配置键名"
|
||||
:rules="[{ required: true, message: '请填写配置键' }]"
|
||||
/>
|
||||
<wd-input
|
||||
v-model="form.configValue"
|
||||
label="配置键值"
|
||||
type="text"
|
||||
placeholder="请输入配置键值"
|
||||
:rules="[{ required: true, message: '请填写配置值' }]"
|
||||
/>
|
||||
<wd-textarea
|
||||
v-model="form.remark"
|
||||
prop="remark"
|
||||
label="配置描述"
|
||||
label-align="right"
|
||||
clearable
|
||||
:maxlength="100"
|
||||
show-word-limit
|
||||
label-width="100px"
|
||||
placeholder="请输入配置描述"
|
||||
/>
|
||||
<!-- 弹窗表单 -->
|
||||
<wd-popup
|
||||
v-model="dialog.visible"
|
||||
position="bottom"
|
||||
custom-style="border-radius: 24rpx 24rpx 0 0"
|
||||
@close="closeConfigDialog"
|
||||
>
|
||||
<view class="p-4">
|
||||
<view class="text-center font-bold text-32rpx mb-4">
|
||||
{{ formData.id ? "编辑配置" : "新增配置" }}
|
||||
</view>
|
||||
<wd-form ref="formRef" :model="formData" :rules="rules">
|
||||
<wd-cell-group border>
|
||||
<wd-input v-model="formData.configName" label="配置名称" required />
|
||||
<wd-input v-model="formData.configKey" label="配置键名" required />
|
||||
<wd-input v-model="formData.configValue" label="配置键值" required />
|
||||
<wd-textarea
|
||||
v-model="formData.remark"
|
||||
label="描述"
|
||||
placeholder="请输入配置描述"
|
||||
:maxlength="100"
|
||||
show-word-limit
|
||||
/>
|
||||
</wd-cell-group>
|
||||
</wd-form>
|
||||
<view class="flex justify-around mt-20rpx">
|
||||
<wd-button @click="showEditPopup = false">取消</wd-button>
|
||||
<wd-button type="primary" native-type="submit" :loading="loading" @click="submitForm">
|
||||
确定
|
||||
</wd-button>
|
||||
<view class="popup-actions">
|
||||
<wd-button type="info" plain @click="closeConfigDialog">取消</wd-button>
|
||||
<wd-button type="primary" :loading="submitting" @click="submitConfigForm">保存</wd-button>
|
||||
</view>
|
||||
</view>
|
||||
</wd-popup>
|
||||
|
||||
<view
|
||||
v-if="hasPermission('sys:config:create') && !dialog.visible"
|
||||
class="fab-add"
|
||||
@click.stop="openConfigDialog()"
|
||||
>
|
||||
<wd-icon name="add" size="44rpx" />
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import ConfigAPI, { ConfigPageVO, ConfigForm, ConfigPageQuery } from "@/api/config";
|
||||
import { DropMenuItemExpose } from "wot-design-uni/components/wd-drop-menu-item/types";
|
||||
import { onLoad, onReachBottom } from "@dcloudio/uni-app";
|
||||
import { LoadMoreState } from "wot-design-uni/components/wd-loadmore/types";
|
||||
import { FormInstance } from "wot-design-uni/components/wd-form/types";
|
||||
import { debounce } from "@/utils";
|
||||
const state = ref<LoadMoreState>("loading"); // 加载状态 loading, finished:, error
|
||||
import { FormRules } from "wot-design-uni/components/wd-form/types";
|
||||
import { useToast } from "wot-design-uni";
|
||||
import ConfigAPI, { type ConfigPageQuery, ConfigPageVO, ConfigForm } from "@/api/config";
|
||||
import { hasPermission } from "@/utils/permission";
|
||||
|
||||
const toast = useToast();
|
||||
const loadMoreState = ref<LoadMoreState>("loading");
|
||||
const formRef = ref();
|
||||
const submitting = ref(false);
|
||||
|
||||
const queryParams = reactive<ConfigPageQuery>({ pageNum: 1, pageSize: 10, keywords: "" });
|
||||
const total = ref(0);
|
||||
const queryParams = reactive<ConfigPageQuery>({
|
||||
pageNum: 1,
|
||||
pageSize: 10,
|
||||
keywords: "",
|
||||
});
|
||||
// 系统配置表格数据
|
||||
const pageData = ref<ConfigPageVO[]>([]);
|
||||
const formRef = ref<FormInstance>();
|
||||
const dialog = reactive({ visible: false });
|
||||
|
||||
const loading = ref(false);
|
||||
const initialFormData: ConfigForm = {
|
||||
id: undefined,
|
||||
configName: undefined,
|
||||
configKey: undefined,
|
||||
configValue: undefined,
|
||||
remark: undefined,
|
||||
};
|
||||
|
||||
/**
|
||||
* 搜索栏
|
||||
*/
|
||||
const dropMenu = ref<DropMenuItemExpose>();
|
||||
const formData = reactive<ConfigForm>({ ...initialFormData });
|
||||
|
||||
/**
|
||||
* 搜索
|
||||
*/
|
||||
function handleQuery() {
|
||||
pageData.value = [];
|
||||
dropMenu.value?.close();
|
||||
const rules: FormRules = {
|
||||
configName: [{ required: true, message: "请输入配置名称" }],
|
||||
configKey: [{ required: true, message: "请输入配置键名" }],
|
||||
configValue: [{ required: true, message: "请输入配置键值" }],
|
||||
};
|
||||
|
||||
// 搜索触发
|
||||
const handleSearch = () => loadConfigList();
|
||||
|
||||
// 加载列表
|
||||
function loadConfigList() {
|
||||
queryParams.pageNum = 1;
|
||||
loadmore();
|
||||
fetchConfigList();
|
||||
}
|
||||
|
||||
const showEditPopup = ref(false);
|
||||
const form = ref<ConfigForm>({});
|
||||
|
||||
// 修改编辑函数
|
||||
function handleEdit(id: number) {
|
||||
ConfigAPI.getFormData(id).then((data) => {
|
||||
Object.assign(form.value, data);
|
||||
// 显示弹窗
|
||||
showEditPopup.value = true;
|
||||
});
|
||||
// 分页加载列表
|
||||
function fetchConfigList() {
|
||||
loadMoreState.value = "loading";
|
||||
ConfigAPI.getPage(queryParams)
|
||||
.then((data) => {
|
||||
pageData.value = data.list;
|
||||
total.value = data.total;
|
||||
queryParams.pageNum++;
|
||||
})
|
||||
.catch(() => {
|
||||
pageData.value = [];
|
||||
})
|
||||
.finally(() => {
|
||||
loadMoreState.value = "finished";
|
||||
});
|
||||
}
|
||||
|
||||
// 提交表单
|
||||
async function submitForm() {
|
||||
loading.value = true;
|
||||
try {
|
||||
if (formRef.value) {
|
||||
formRef.value!.validate().then(async ({ valid }) => {
|
||||
if (valid) {
|
||||
if (form.value.id) {
|
||||
await ConfigAPI.update(form.value.id, form.value);
|
||||
uni.showToast({ title: "更新成功", icon: "success" });
|
||||
} else {
|
||||
await ConfigAPI.add(form.value);
|
||||
uni.showToast({ title: "添加成功", icon: "success" });
|
||||
}
|
||||
showEditPopup.value = false;
|
||||
handleQuery(); // 刷新列表
|
||||
} else {
|
||||
uni.showToast({ title: "请检查表单", icon: "error" });
|
||||
loading.value = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
} catch {
|
||||
uni.showToast({ title: "操作失败", icon: "error" });
|
||||
loading.value = false;
|
||||
} finally {
|
||||
loading.value = false;
|
||||
// 打开弹窗(新增/编辑)
|
||||
async function openConfigDialog(id?: number) {
|
||||
formRef.value?.reset();
|
||||
Object.assign(formData, initialFormData);
|
||||
dialog.visible = true;
|
||||
if (id) {
|
||||
formData.id = id;
|
||||
const data = await ConfigAPI.getFormData(id);
|
||||
Object.assign(formData, data, { id });
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 重置搜索条件
|
||||
*/
|
||||
function handleReset() {
|
||||
queryParams.pageNum = 1;
|
||||
queryParams.keywords = "";
|
||||
pageData.value = [];
|
||||
dropMenu.value?.close();
|
||||
handleQuery();
|
||||
}
|
||||
|
||||
/**
|
||||
* 触底事件
|
||||
*/
|
||||
onReachBottom(() => {
|
||||
queryParams.pageNum++;
|
||||
handleQuery();
|
||||
});
|
||||
|
||||
/**
|
||||
* 加载更多
|
||||
*/
|
||||
function loadmore() {
|
||||
state.value = "loading";
|
||||
ConfigAPI.getPage(queryParams)
|
||||
.then((data) => {
|
||||
if (queryParams.pageNum === 1) {
|
||||
pageData.value = data.list;
|
||||
} else {
|
||||
pageData.value.push(...data.list);
|
||||
}
|
||||
total.value = data.total;
|
||||
})
|
||||
.finally(() => {
|
||||
state.value = "finished";
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加
|
||||
*/
|
||||
function handleOpenDialog() {
|
||||
form.value.id = undefined;
|
||||
form.value.configName = "";
|
||||
form.value.configKey = "";
|
||||
form.value.configValue = "";
|
||||
form.value.remark = "";
|
||||
showEditPopup.value = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 刷新缓存
|
||||
*/
|
||||
const refreshCache = debounce(() => {
|
||||
ConfigAPI.refreshCache().then(() => {
|
||||
uni.showToast({
|
||||
title: "刷新缓存成功",
|
||||
icon: "success",
|
||||
duration: 1000, // 显示时间,单位为毫秒,设置为 0 则不会自动消失
|
||||
});
|
||||
});
|
||||
}, 1000);
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
function handleDelete(item: ConfigPageVO) {
|
||||
uni.showModal({
|
||||
title: "提示",
|
||||
content: "确定要删除该配置吗?",
|
||||
success: async (res) => {
|
||||
if (res.confirm) {
|
||||
if (item.id) {
|
||||
ConfigAPI.deleteById(item.id).then(() => {
|
||||
uni.showToast({ title: "删除成功", icon: "success" });
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
// 提交表单
|
||||
function submitConfigForm() {
|
||||
formRef.value.validate().then(({ valid }: { valid: boolean }) => {
|
||||
if (!valid) return;
|
||||
submitting.value = true;
|
||||
const action = formData.id ? ConfigAPI.update(formData.id, formData) : ConfigAPI.add(formData);
|
||||
action
|
||||
.then(() => {
|
||||
toast.success("操作成功");
|
||||
closeConfigDialog();
|
||||
loadConfigList();
|
||||
})
|
||||
.finally(() => {
|
||||
submitting.value = false;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 操作
|
||||
*/
|
||||
function handleAction(item: ConfigPageVO) {
|
||||
const actions = ["编辑", "删除"];
|
||||
// 关闭弹窗
|
||||
function closeConfigDialog() {
|
||||
dialog.visible = false;
|
||||
formRef.value?.reset();
|
||||
Object.assign(formData, initialFormData);
|
||||
}
|
||||
|
||||
// 更多操作
|
||||
function showConfigActions(item: ConfigPageVO) {
|
||||
const actions: string[] = [];
|
||||
const actionMap: Record<string, () => void> = {};
|
||||
|
||||
if (hasPermission("sys:config:update")) {
|
||||
actions.push("编辑");
|
||||
actionMap["编辑"] = () => openConfigDialog(item.id);
|
||||
}
|
||||
|
||||
if (hasPermission("sys:config:delete")) {
|
||||
actions.push("删除");
|
||||
actionMap["删除"] = async () => {
|
||||
const { confirm } = await uni.showModal({
|
||||
title: "确认删除",
|
||||
content: `确定要删除配置「${item.configName}」吗?`,
|
||||
});
|
||||
if (confirm) {
|
||||
await ConfigAPI.deleteById(item.id!);
|
||||
toast.success("删除成功");
|
||||
loadConfigList();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
if (actions.length === 0) {
|
||||
toast.warning("暂无操作权限");
|
||||
return;
|
||||
}
|
||||
|
||||
uni.showActionSheet({
|
||||
itemList: actions,
|
||||
success: ({ tapIndex }) => {
|
||||
switch (actions[tapIndex]) {
|
||||
case "编辑":
|
||||
handleEdit(item.id || 0);
|
||||
break;
|
||||
case "删除":
|
||||
handleDelete(item);
|
||||
break;
|
||||
}
|
||||
const action = actions[tapIndex];
|
||||
actionMap[action]?.();
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
handleQuery();
|
||||
onReachBottom(() => {
|
||||
if (queryParams.pageNum * queryParams.pageSize < total.value) {
|
||||
fetchConfigList();
|
||||
} else {
|
||||
loadMoreState.value = "finished";
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* 页面返回回来也要重新加载数据
|
||||
*/
|
||||
onLoad(() => {
|
||||
queryParams.pageNum = 1;
|
||||
handleQuery();
|
||||
loadConfigList();
|
||||
});
|
||||
</script>
|
||||
|
||||
<script lang="ts">
|
||||
export default { options: { styleIsolation: "shared" } };
|
||||
</script>
|
||||
|
||||
<route lang="json">
|
||||
{
|
||||
"name": "config",
|
||||
@@ -301,34 +243,3 @@ onLoad(() => {
|
||||
}
|
||||
}
|
||||
</route>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.data-container {
|
||||
:deep(.wd-cell__wrapper) {
|
||||
padding: 4rpx 0;
|
||||
}
|
||||
|
||||
:deep(.wd-cell) {
|
||||
padding-right: 10rpx;
|
||||
background: #f8f8f8;
|
||||
}
|
||||
|
||||
:deep(.wd-fab__trigger) {
|
||||
width: 80rpx !important;
|
||||
height: 80rpx !important;
|
||||
}
|
||||
|
||||
:deep(.wd-cell__right) {
|
||||
flex: 2;
|
||||
}
|
||||
|
||||
.filter-container {
|
||||
padding: 10rpx;
|
||||
background: #fff;
|
||||
}
|
||||
|
||||
.data-container {
|
||||
margin-top: 20rpx;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
+293
-311
@@ -1,363 +1,345 @@
|
||||
<template>
|
||||
<view class="dept-page">
|
||||
<!-- 搜索栏 -->
|
||||
<view class="search-bar">
|
||||
<view class="page page--padding page--pt">
|
||||
<view>
|
||||
<wd-search
|
||||
v-model="searchText"
|
||||
v-model="queryParams.keywords"
|
||||
placeholder="搜索部门名称"
|
||||
hide-cancel
|
||||
@search="handleSearch"
|
||||
/>
|
||||
</view>
|
||||
|
||||
<!-- 部门列表 -->
|
||||
<scroll-view class="dept-list" scroll-y>
|
||||
<view v-if="filteredDeptList.length > 0" class="dept-tree">
|
||||
<template v-for="dept in filteredDeptList" :key="dept.id">
|
||||
<dept-item
|
||||
:dept="dept"
|
||||
:level="0"
|
||||
@click="handleDeptClick"
|
||||
/>
|
||||
<!-- 部门树形列表 -->
|
||||
<view class="mt-16rpx">
|
||||
<CustomTree
|
||||
:data="treeData"
|
||||
:default-expand-all="true"
|
||||
:show-action="true"
|
||||
@action="handleNodeAction"
|
||||
>
|
||||
<!-- 自定义节点内容:ID + 名称 + 状态 -->
|
||||
<template #content="{ node }">
|
||||
<view class="flex-1 flex items-center gap-16rpx">
|
||||
<text class="w-120rpx text-24rpx color-text-secondary">{{ node.id }}</text>
|
||||
<text class="flex-1 truncate">{{ node.name }}</text>
|
||||
<wd-tag :type="node.status === 1 ? 'success' : 'danger'" size="small">
|
||||
{{ node.status === 1 ? "正常" : "禁用" }}
|
||||
</wd-tag>
|
||||
</view>
|
||||
</template>
|
||||
</view>
|
||||
</CustomTree>
|
||||
|
||||
<!-- 空状态 -->
|
||||
<view v-else class="empty-state">
|
||||
<wd-icon name="folder-open" size="48" color="#d1d5db" />
|
||||
<text class="empty-state__text">暂无部门数据</text>
|
||||
</view>
|
||||
</scroll-view>
|
||||
<wd-status-tip v-if="deptList.length === 0" image="search" tip="暂无数据" />
|
||||
</view>
|
||||
|
||||
<!-- 底部操作栏 -->
|
||||
<view class="action-bar">
|
||||
<wd-button type="primary" block @click="handleAddDept">
|
||||
<wd-icon name="add" size="16" color="#fff" />
|
||||
<text>新增部门</text>
|
||||
</wd-button>
|
||||
<!-- 弹窗表单 -->
|
||||
<wd-popup
|
||||
v-model="dialog.visible"
|
||||
position="bottom"
|
||||
custom-style="border-radius: 24rpx 24rpx 0 0"
|
||||
@close="closeDeptDialog"
|
||||
>
|
||||
<view class="p-4">
|
||||
<view class="text-center font-bold text-32rpx mb-4">
|
||||
{{ formData.id ? "编辑部门" : "新增部门" }}
|
||||
</view>
|
||||
<wd-form ref="formRef" :model="formData" :rules="rules">
|
||||
<wd-cell-group border>
|
||||
<wd-col-picker
|
||||
v-model="parentSelected"
|
||||
label="上级部门"
|
||||
:columns="parentColumns"
|
||||
:column-change="handleParentColumnChange"
|
||||
required
|
||||
:display-format="displayParentFormat"
|
||||
@confirm="handleParentConfirm"
|
||||
/>
|
||||
<wd-input v-model="formData.name" label="部门名称" required />
|
||||
<wd-input v-model="formData.code" label="部门编号" required />
|
||||
<wd-cell title="排序">
|
||||
<wd-input-number v-model="formData.sort" :min="0" />
|
||||
</wd-cell>
|
||||
<wd-cell title="状态">
|
||||
<wd-switch v-model="formData.status" :active-value="1" :inactive-value="0" />
|
||||
</wd-cell>
|
||||
</wd-cell-group>
|
||||
</wd-form>
|
||||
<view class="popup-actions">
|
||||
<wd-button type="info" plain @click="closeDeptDialog">取消</wd-button>
|
||||
<wd-button type="primary" :loading="submitting" @click="submitDeptForm">保存</wd-button>
|
||||
</view>
|
||||
</view>
|
||||
</wd-popup>
|
||||
|
||||
<!-- 浮动新增按钮 -->
|
||||
<view
|
||||
v-if="hasPermission('sys:dept:create') && !dialog.visible"
|
||||
class="fab-add"
|
||||
hover-class="fab-add:active"
|
||||
@click.stop="openDeptDialog()"
|
||||
>
|
||||
<wd-icon name="add" size="44rpx" />
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* 部门管理页面
|
||||
*
|
||||
* 功能说明:
|
||||
* - 展示部门树形结构
|
||||
* - 支持搜索部门
|
||||
* - 新增/编辑/删除部门
|
||||
*
|
||||
* 技术要点:
|
||||
* - 使用 BEM 命名规范
|
||||
* - 支持暗黑模式
|
||||
* - 使用 CSS 变量
|
||||
* - 递归组件实现树形结构
|
||||
*/
|
||||
<script lang="ts" setup>
|
||||
import { onLoad } from "@dcloudio/uni-app";
|
||||
import { FormRules } from "wot-design-uni/components/wd-form/types";
|
||||
import { useToast } from "wot-design-uni";
|
||||
import DeptAPI, { type DeptQuery, DeptVO, DeptForm } from "@/api/dept";
|
||||
import { hasPermission } from "@/utils/permission";
|
||||
import CustomTree from "@/components/custom-tree/index.vue";
|
||||
|
||||
// ============================================================================
|
||||
// 类型定义
|
||||
// ============================================================================
|
||||
const toast = useToast();
|
||||
const formRef = ref();
|
||||
const submitting = ref(false);
|
||||
|
||||
interface DeptNode {
|
||||
id: string
|
||||
label: string
|
||||
userCount?: number
|
||||
children?: DeptNode[]
|
||||
const queryParams = reactive<DeptQuery>({ keywords: "" });
|
||||
const deptList = ref<DeptVO[]>([]);
|
||||
const dialog = reactive({ visible: false });
|
||||
|
||||
const initialFormData: DeptForm = {
|
||||
id: undefined,
|
||||
parentId: 0,
|
||||
name: undefined,
|
||||
code: undefined,
|
||||
sort: 1,
|
||||
status: 1,
|
||||
};
|
||||
|
||||
const formData = reactive<DeptForm>({ ...initialFormData });
|
||||
|
||||
// 转换为树组件数据格式
|
||||
const treeData = computed(() => deptList.value.map((dept) => transformDeptToTree(dept)));
|
||||
|
||||
function transformDeptToTree(dept: DeptVO): any {
|
||||
return {
|
||||
value: String(dept.id),
|
||||
label: dept.name,
|
||||
id: dept.id,
|
||||
name: dept.name,
|
||||
status: dept.status,
|
||||
children: dept.children?.map((child) => transformDeptToTree(child)) || [],
|
||||
};
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// 子组件 - 部门项(支持递归)
|
||||
// ============================================================================
|
||||
// 上级部门选择器
|
||||
const parentSelected = ref<(string | number)[]>([]);
|
||||
const parentColumns = ref<OptionType[][]>([]);
|
||||
const parentOptions = ref<OptionType[]>([]);
|
||||
|
||||
const DeptItem = defineComponent({
|
||||
name: "DeptItem",
|
||||
props: {
|
||||
dept: { type: Object as PropType<DeptNode>, required: true },
|
||||
level: { type: Number, default: 0 },
|
||||
},
|
||||
emits: ["click"],
|
||||
setup(props, { emit }) {
|
||||
const isExpanded = ref(false)
|
||||
const hasChildren = computed(() => props.dept.children && props.dept.children.length > 0)
|
||||
// 格式化上级部门展示
|
||||
const displayParentFormat = (selectedItems: OptionType[]) => {
|
||||
if (!selectedItems || selectedItems.length === 0) return "";
|
||||
return selectedItems
|
||||
.map((item) => item?.label)
|
||||
.filter((label) => !!label)
|
||||
.join("/");
|
||||
};
|
||||
|
||||
function toggleExpand() {
|
||||
if (hasChildren.value) {
|
||||
isExpanded.value = !isExpanded.value
|
||||
}
|
||||
// 查找部门在树中的完整路径
|
||||
function findDeptPath(data: OptionType[], targetId: string, path: string[] = []): string[] | null {
|
||||
for (const item of data) {
|
||||
const currentPath = [...path, String(item.value)];
|
||||
if (String(item.value) === targetId) {
|
||||
return currentPath;
|
||||
}
|
||||
|
||||
function handleClick() {
|
||||
emit("click", props.dept)
|
||||
if (item.children && item.children.length > 0) {
|
||||
const found = findDeptPath(item.children, targetId, currentPath);
|
||||
if (found) return found;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
return {
|
||||
isExpanded,
|
||||
hasChildren,
|
||||
toggleExpand,
|
||||
handleClick,
|
||||
}
|
||||
},
|
||||
template: `
|
||||
<view class="dept-node">
|
||||
<view
|
||||
class="dept-node__item"
|
||||
:class="{ 'dept-node__item--has-children': hasChildren }"
|
||||
:style="{ paddingLeft: level * 32 + 16 + 'rpx' }"
|
||||
>
|
||||
<view class="dept-node__expand" @click="toggleExpand">
|
||||
<wd-icon
|
||||
v-if="hasChildren"
|
||||
name="arrow-right"
|
||||
size="14"
|
||||
class="dept-node__arrow"
|
||||
:class="{ 'dept-node__arrow--expanded': isExpanded }"
|
||||
/>
|
||||
</view>
|
||||
<view class="dept-node__content" @click="handleClick">
|
||||
<wd-icon
|
||||
name="folder"
|
||||
size="18"
|
||||
:color="hasChildren ? 'var(--color-primary)' : 'var(--color-text-secondary)'"
|
||||
/>
|
||||
<text class="dept-node__name">{{ dept.label }}</text>
|
||||
</view>
|
||||
<view class="dept-node__meta" @click="handleClick">
|
||||
<text class="dept-node__count">{{ dept.userCount || 0 }} 人</text>
|
||||
<wd-icon name="arrow-right" size="14" color="var(--color-text-secondary)" />
|
||||
</view>
|
||||
</view>
|
||||
// 上级部门列变化
|
||||
const handleParentColumnChange = ({ selectedItem, resolve, finish }: any) => {
|
||||
if (String(selectedItem?.value) === "0") {
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
const children = selectedItem.children;
|
||||
if (children && children.length > 0) {
|
||||
resolve(children);
|
||||
} else {
|
||||
finish();
|
||||
}
|
||||
};
|
||||
|
||||
<!-- 子节点 -->
|
||||
<view v-if="hasChildren && isExpanded" class="dept-node__children">
|
||||
<DeptItem
|
||||
v-for="child in dept.children"
|
||||
:key="child.id"
|
||||
:dept="child"
|
||||
:level="level + 1"
|
||||
@click="$emit('click', $event)"
|
||||
/>
|
||||
</view>
|
||||
</view>
|
||||
`,
|
||||
})
|
||||
// 上级部门确认选择
|
||||
const handleParentConfirm = ({ value }: any) => {
|
||||
parentSelected.value = value;
|
||||
formData.parentId = Number(value[value.length - 1]) || 0;
|
||||
};
|
||||
|
||||
// ============================================================================
|
||||
// 响应式数据
|
||||
// ============================================================================
|
||||
const rules: FormRules = {
|
||||
name: [{ required: true, message: "请输入部门名称" }],
|
||||
code: [{ required: true, message: "请输入部门编号" }],
|
||||
parentId: [{ required: true, message: "请选择上级部门" }],
|
||||
};
|
||||
|
||||
const searchText = ref("")
|
||||
// 搜索触发
|
||||
const handleSearch = () => loadDeptList();
|
||||
|
||||
// 部门树形数据(示例数据)
|
||||
const deptList = ref<DeptNode[]>([
|
||||
{
|
||||
id: "1",
|
||||
label: "有来技术",
|
||||
userCount: 128,
|
||||
children: [
|
||||
{
|
||||
id: "1-1",
|
||||
label: "研发中心",
|
||||
userCount: 45,
|
||||
children: [
|
||||
{ id: "1-1-1", label: "前端组", userCount: 15 },
|
||||
{ id: "1-1-2", label: "后端组", userCount: 18 },
|
||||
{ id: "1-1-3", label: "测试组", userCount: 12 },
|
||||
],
|
||||
},
|
||||
{
|
||||
id: "1-2",
|
||||
label: "产品中心",
|
||||
userCount: 20,
|
||||
children: [
|
||||
{ id: "1-2-1", label: "产品组", userCount: 12 },
|
||||
{ id: "1-2-2", label: "设计组", userCount: 8 },
|
||||
],
|
||||
},
|
||||
{
|
||||
id: "1-3",
|
||||
label: "运营中心",
|
||||
userCount: 35,
|
||||
},
|
||||
{
|
||||
id: "1-4",
|
||||
label: "行政中心",
|
||||
userCount: 28,
|
||||
},
|
||||
],
|
||||
},
|
||||
])
|
||||
// 加载列表
|
||||
function loadDeptList() {
|
||||
console.log("loadDeptList called");
|
||||
DeptAPI.getList(queryParams)
|
||||
.then((data) => {
|
||||
console.log("deptList data:", data);
|
||||
deptList.value = data;
|
||||
console.log("treeData:", treeData.value);
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error("loadDeptList error:", err);
|
||||
});
|
||||
}
|
||||
|
||||
// 过滤后的部门列表
|
||||
const filteredDeptList = computed(() => {
|
||||
if (!searchText.value) return deptList.value
|
||||
// 处理节点操作按钮点击
|
||||
function handleNodeAction(node: any) {
|
||||
const dept: DeptVO = {
|
||||
id: node.id,
|
||||
name: node.label,
|
||||
status: node.status,
|
||||
children: node.children,
|
||||
} as DeptVO;
|
||||
|
||||
function filterDepts(depts: DeptNode[]): DeptNode[] {
|
||||
return depts.reduce<DeptNode[]>((acc, dept) => {
|
||||
const matched = dept.label.toLowerCase().includes(searchText.value.toLowerCase())
|
||||
const filteredChildren = dept.children ? filterDepts(dept.children) : []
|
||||
const actions: string[] = [];
|
||||
const actionMap: Record<string, () => void> = {};
|
||||
|
||||
if (matched || filteredChildren.length > 0) {
|
||||
acc.push({
|
||||
...dept,
|
||||
children: filteredChildren.length > 0 ? filteredChildren : dept.children,
|
||||
})
|
||||
}
|
||||
return acc
|
||||
}, [])
|
||||
if (hasPermission("sys:dept:create")) {
|
||||
actions.push("新增子部门");
|
||||
actionMap["新增子部门"] = () => handleAddChild(dept);
|
||||
}
|
||||
|
||||
return filterDepts(deptList.value)
|
||||
})
|
||||
if (hasPermission("sys:dept:update")) {
|
||||
actions.push("编辑");
|
||||
actionMap["编辑"] = () => openDeptDialog(dept);
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// 事件处理
|
||||
// ============================================================================
|
||||
if (hasPermission("sys:dept:delete")) {
|
||||
actions.push("删除");
|
||||
actionMap["删除"] = async () => {
|
||||
const { confirm } = await uni.showModal({
|
||||
title: "确认删除",
|
||||
content: `确定要删除部门「${dept.name}」吗?`,
|
||||
});
|
||||
if (confirm) {
|
||||
await DeptAPI.deleteByIds(String(dept.id));
|
||||
toast.success("删除成功");
|
||||
loadDeptList();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/** 搜索 */
|
||||
function handleSearch() {
|
||||
uni.showToast({ title: `搜索: ${searchText.value}`, icon: "none" })
|
||||
if (actions.length === 0) {
|
||||
toast.warning("暂无操作权限");
|
||||
return;
|
||||
}
|
||||
|
||||
uni.showActionSheet({
|
||||
itemList: actions,
|
||||
success: ({ tapIndex }) => {
|
||||
const action = actions[tapIndex];
|
||||
actionMap[action]?.();
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
/** 部门点击 */
|
||||
function handleDeptClick(dept: DeptNode) {
|
||||
uni.showToast({ title: `点击: ${dept.label}`, icon: "none" })
|
||||
// 打开弹窗(新增/编辑)
|
||||
async function openDeptDialog(dept?: DeptVO) {
|
||||
formRef.value?.reset();
|
||||
Object.assign(formData, initialFormData);
|
||||
parentSelected.value = [];
|
||||
dialog.visible = true;
|
||||
|
||||
const data = await DeptAPI.getOptions();
|
||||
parentOptions.value = data;
|
||||
const firstColumn: OptionType[] = [{ value: "0", label: "顶级部门" }, ...data];
|
||||
parentColumns.value = [firstColumn];
|
||||
|
||||
if (dept) {
|
||||
formData.id = dept.id;
|
||||
const form = await DeptAPI.getFormData(dept.id!);
|
||||
Object.assign(formData, form, { id: dept.id });
|
||||
|
||||
if (form.parentId && form.parentId !== 0) {
|
||||
const path = findDeptPath(data, String(form.parentId));
|
||||
if (path) {
|
||||
parentSelected.value = path;
|
||||
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]);
|
||||
if (found && found.children) {
|
||||
columns.push(found.children);
|
||||
currentLevel = found.children;
|
||||
}
|
||||
}
|
||||
parentColumns.value = columns;
|
||||
} else {
|
||||
parentSelected.value = [String(form.parentId)];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** 新增部门 */
|
||||
function handleAddDept() {
|
||||
uni.showToast({ title: "新增部门", icon: "none" })
|
||||
// 新增子部门
|
||||
function handleAddChild(dept: DeptVO) {
|
||||
openDeptDialog({ id: undefined, parentId: dept.id } as DeptVO);
|
||||
formData.parentId = dept.id!;
|
||||
parentSelected.value = [String(dept.id)];
|
||||
}
|
||||
|
||||
// 提交表单
|
||||
function submitDeptForm() {
|
||||
formRef.value.validate().then(({ valid }: { valid: boolean }) => {
|
||||
if (!valid) return;
|
||||
submitting.value = true;
|
||||
const action = formData.id ? DeptAPI.update(formData.id, formData) : DeptAPI.add(formData);
|
||||
action
|
||||
.then(() => {
|
||||
toast.success("操作成功");
|
||||
closeDeptDialog();
|
||||
loadDeptList();
|
||||
})
|
||||
.finally(() => {
|
||||
submitting.value = false;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// 关闭弹窗
|
||||
function closeDeptDialog() {
|
||||
dialog.visible = false;
|
||||
formRef.value?.reset();
|
||||
Object.assign(formData, initialFormData);
|
||||
}
|
||||
|
||||
onLoad(() => {
|
||||
console.log("onLoad triggered");
|
||||
loadDeptList();
|
||||
});
|
||||
</script>
|
||||
|
||||
<script lang="ts">
|
||||
export default { options: { styleIsolation: "shared" } };
|
||||
</script>
|
||||
|
||||
<route lang="json">
|
||||
{
|
||||
"name": "dept",
|
||||
"style": { "navigationBarTitleText": "部门管理" }
|
||||
"style": {
|
||||
"navigationBarTitleText": "部门管理"
|
||||
}
|
||||
}
|
||||
</route>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
// ============================================================================
|
||||
// 页面容器
|
||||
// ============================================================================
|
||||
|
||||
.dept-page {
|
||||
.popup-actions {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
min-height: 100vh;
|
||||
background-color: var(--color-bg-secondary);
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// 搜索栏
|
||||
// ============================================================================
|
||||
|
||||
.search-bar {
|
||||
padding: 16rpx 24rpx;
|
||||
background-color: var(--color-bg);
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// 部门列表
|
||||
// ============================================================================
|
||||
|
||||
.dept-list {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.dept-tree {
|
||||
background-color: var(--color-bg);
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// 部门节点(递归组件样式)
|
||||
// ============================================================================
|
||||
|
||||
.dept-node {
|
||||
&__item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
height: 96rpx;
|
||||
border-bottom: 2rpx solid var(--color-border-light);
|
||||
|
||||
&:active {
|
||||
background-color: var(--color-bg-secondary);
|
||||
}
|
||||
}
|
||||
|
||||
&__expand {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 48rpx;
|
||||
height: 48rpx;
|
||||
}
|
||||
|
||||
&__arrow {
|
||||
color: var(--color-text-secondary);
|
||||
transition: transform 0.2s ease;
|
||||
|
||||
&--expanded {
|
||||
transform: rotate(90deg);
|
||||
}
|
||||
}
|
||||
|
||||
&__content {
|
||||
display: flex;
|
||||
flex: 1;
|
||||
align-items: center;
|
||||
gap: 16rpx;
|
||||
}
|
||||
|
||||
&__name {
|
||||
font-size: 28rpx;
|
||||
color: var(--color-text);
|
||||
}
|
||||
|
||||
&__meta {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8rpx;
|
||||
padding-right: 24rpx;
|
||||
}
|
||||
|
||||
&__count {
|
||||
font-size: 24rpx;
|
||||
color: var(--color-text-secondary);
|
||||
}
|
||||
|
||||
&__children {
|
||||
background-color: var(--color-bg-secondary);
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// 空状态
|
||||
// ============================================================================
|
||||
|
||||
.empty-state {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 100rpx 0;
|
||||
|
||||
&__text {
|
||||
margin-top: 24rpx;
|
||||
font-size: 28rpx;
|
||||
color: var(--color-text-secondary);
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// 底部操作栏
|
||||
// ============================================================================
|
||||
|
||||
.action-bar {
|
||||
padding: 24rpx;
|
||||
padding-bottom: calc(24rpx + env(safe-area-inset-bottom));
|
||||
background-color: var(--color-bg);
|
||||
box-shadow: 0 -4rpx 16rpx rgba(0, 0, 0, 0.05);
|
||||
gap: 24rpx;
|
||||
margin-top: 32rpx;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,255 @@
|
||||
<template>
|
||||
<view class="page page--padding page--pt">
|
||||
<view>
|
||||
<wd-search
|
||||
v-model="queryParams.keywords"
|
||||
placeholder="搜索字典名称/编码"
|
||||
hide-cancel
|
||||
@search="handleSearch"
|
||||
/>
|
||||
</view>
|
||||
|
||||
<view class="mt-16rpx">
|
||||
<wd-card
|
||||
v-for="item in pageData"
|
||||
:key="item.id"
|
||||
custom-class="item-card"
|
||||
@click="openDictItemPage(item)"
|
||||
>
|
||||
<view class="flex-start">
|
||||
<view class="flex-1">
|
||||
<view class="flex-start">
|
||||
<text class="font-bold text-32rpx">{{ item.name }}</text>
|
||||
</view>
|
||||
<text class="text-24rpx color-text-secondary">字典编码:{{ item.dictCode }}</text>
|
||||
</view>
|
||||
<wd-tag :type="item.status === 1 ? 'success' : 'danger'" plain>
|
||||
{{ item.status === 1 ? "启用" : "禁用" }}
|
||||
</wd-tag>
|
||||
</view>
|
||||
|
||||
<view class="flex-between mt-16rpx">
|
||||
<text class="text-24rpx color-text-placeholder">{{ item.remark || "暂无备注" }}</text>
|
||||
<view
|
||||
class="w-88rpx h-88rpx flex-center rounded-full"
|
||||
hover-class="bg-[var(--color-text-placeholder)]/16"
|
||||
@click.stop="showDictActions(item)"
|
||||
>
|
||||
<wd-icon name="more" size="18" class="color-text-secondary" />
|
||||
</view>
|
||||
</view>
|
||||
</wd-card>
|
||||
|
||||
<wd-loadmore v-if="total > 0" :state="loadMoreState" @reload="fetchDictTypeList" />
|
||||
<wd-status-tip v-else-if="total === 0" image="search" tip="暂无数据" />
|
||||
</view>
|
||||
|
||||
<wd-popup
|
||||
v-model="dialog.visible"
|
||||
position="bottom"
|
||||
custom-style="border-radius: 24rpx 24rpx 0 0"
|
||||
@close="closeDictDialog"
|
||||
>
|
||||
<view class="p-4">
|
||||
<view class="text-center font-bold text-32rpx mb-4">
|
||||
{{ formData.id ? "编辑字典" : "新增字典" }}
|
||||
</view>
|
||||
<wd-form ref="formRef" :model="formData" :rules="rules">
|
||||
<wd-cell-group border>
|
||||
<wd-input v-model="formData.name" label="字典名称" required />
|
||||
<wd-input v-model="formData.dictCode" label="字典编码" required />
|
||||
<wd-cell title="状态">
|
||||
<wd-switch v-model="formData.status" :active-value="1" :inactive-value="0" />
|
||||
</wd-cell>
|
||||
<wd-textarea
|
||||
v-model="formData.remark"
|
||||
label="备注"
|
||||
placeholder="请输入备注"
|
||||
:maxlength="100"
|
||||
show-word-limit
|
||||
/>
|
||||
</wd-cell-group>
|
||||
</wd-form>
|
||||
<view class="popup-actions">
|
||||
<wd-button type="info" plain @click="closeDictDialog">取消</wd-button>
|
||||
<wd-button type="primary" :loading="submitting" @click="submitDictForm">保存</wd-button>
|
||||
</view>
|
||||
</view>
|
||||
</wd-popup>
|
||||
|
||||
<view
|
||||
v-if="hasPermission('sys:dict:create') && !dialog.visible"
|
||||
class="fab-add"
|
||||
@click.stop="openDictDialog()"
|
||||
>
|
||||
<wd-icon name="add" size="44rpx" />
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { onLoad, onReachBottom } from "@dcloudio/uni-app";
|
||||
import { useRouter } from "uni-mini-router";
|
||||
import { LoadMoreState } from "wot-design-uni/components/wd-loadmore/types";
|
||||
import { FormRules } from "wot-design-uni/components/wd-form/types";
|
||||
import { useToast } from "wot-design-uni";
|
||||
import DictAPI, {
|
||||
type DictTypeForm,
|
||||
type DictTypePageQuery,
|
||||
type DictTypePageVO,
|
||||
} from "@/api/dict";
|
||||
import { hasPermission } from "@/utils/permission";
|
||||
|
||||
const router = useRouter();
|
||||
const toast = useToast();
|
||||
const loadMoreState = ref<LoadMoreState>("loading");
|
||||
const formRef = ref();
|
||||
const submitting = ref(false);
|
||||
|
||||
const queryParams = reactive<DictTypePageQuery>({ pageNum: 1, pageSize: 10, keywords: "" });
|
||||
const total = ref(0);
|
||||
const pageData = ref<DictTypePageVO[]>([]);
|
||||
const dialog = reactive({ visible: false });
|
||||
|
||||
const initialFormData: DictTypeForm = {
|
||||
id: undefined,
|
||||
name: undefined,
|
||||
dictCode: undefined,
|
||||
status: 1,
|
||||
remark: undefined,
|
||||
};
|
||||
|
||||
const formData = reactive<DictTypeForm>({ ...initialFormData });
|
||||
|
||||
const rules: FormRules = {
|
||||
name: [{ required: true, message: "请输入字典名称" }],
|
||||
dictCode: [{ required: true, message: "请输入字典编码" }],
|
||||
};
|
||||
|
||||
const handleSearch = () => loadDictTypeList();
|
||||
|
||||
function loadDictTypeList() {
|
||||
queryParams.pageNum = 1;
|
||||
fetchDictTypeList();
|
||||
}
|
||||
|
||||
function fetchDictTypeList() {
|
||||
loadMoreState.value = "loading";
|
||||
DictAPI.getPage(queryParams)
|
||||
.then((data: any) => {
|
||||
pageData.value = data.list;
|
||||
total.value = data.total;
|
||||
queryParams.pageNum++;
|
||||
})
|
||||
.catch(() => {
|
||||
pageData.value = [];
|
||||
})
|
||||
.finally(() => {
|
||||
loadMoreState.value = "finished";
|
||||
});
|
||||
}
|
||||
|
||||
function openDictItemPage(item: DictTypePageVO) {
|
||||
if (!item.dictCode) return;
|
||||
router.push({
|
||||
path: "/pages/work/dict/item/index",
|
||||
query: { dictCode: item.dictCode, title: `【${item.name}】字典数据` },
|
||||
});
|
||||
}
|
||||
|
||||
async function openDictDialog(id?: string) {
|
||||
formRef.value?.reset();
|
||||
Object.assign(formData, initialFormData);
|
||||
dialog.visible = true;
|
||||
if (id) {
|
||||
formData.id = id;
|
||||
const data = await DictAPI.getFormData(id);
|
||||
Object.assign(formData, data, { id });
|
||||
}
|
||||
}
|
||||
|
||||
function submitDictForm() {
|
||||
formRef.value.validate().then(({ valid }: { valid: boolean }) => {
|
||||
if (!valid) return;
|
||||
submitting.value = true;
|
||||
const id = formData.id;
|
||||
const action = id ? DictAPI.update(id, formData) : DictAPI.create(formData);
|
||||
action
|
||||
.then(() => {
|
||||
toast.success("操作成功");
|
||||
closeDictDialog();
|
||||
loadDictTypeList();
|
||||
})
|
||||
.finally(() => {
|
||||
submitting.value = false;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function closeDictDialog() {
|
||||
dialog.visible = false;
|
||||
formRef.value?.reset();
|
||||
Object.assign(formData, initialFormData);
|
||||
}
|
||||
|
||||
function showDictActions(item: DictTypePageVO) {
|
||||
const actions: string[] = [];
|
||||
const actionMap: Record<string, () => void> = {};
|
||||
|
||||
actions.push("字典数据");
|
||||
actionMap["字典数据"] = () => openDictItemPage(item);
|
||||
|
||||
if (hasPermission("sys:dict:update")) {
|
||||
actions.push("编辑");
|
||||
actionMap["编辑"] = () => openDictDialog(item.id);
|
||||
}
|
||||
|
||||
if (hasPermission("sys:dict:delete")) {
|
||||
actions.push("删除");
|
||||
actionMap["删除"] = async () => {
|
||||
const { confirm } = await uni.showModal({
|
||||
title: "确认删除",
|
||||
content: `确定要删除字典「${item.name}」吗?`,
|
||||
});
|
||||
if (confirm && item.id) {
|
||||
await DictAPI.deleteByIds(String(item.id));
|
||||
toast.success("删除成功");
|
||||
loadDictTypeList();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
uni.showActionSheet({
|
||||
itemList: actions,
|
||||
success: ({ tapIndex }) => {
|
||||
const action = actions[tapIndex];
|
||||
actionMap[action]?.();
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
onReachBottom(() => {
|
||||
if (queryParams.pageNum * queryParams.pageSize < total.value) {
|
||||
fetchDictTypeList();
|
||||
} else {
|
||||
loadMoreState.value = "finished";
|
||||
}
|
||||
});
|
||||
|
||||
onLoad(() => {
|
||||
loadDictTypeList();
|
||||
});
|
||||
</script>
|
||||
|
||||
<script lang="ts">
|
||||
export default { options: { styleIsolation: "shared" } };
|
||||
</script>
|
||||
|
||||
<route lang="json">
|
||||
{
|
||||
"name": "dict",
|
||||
"style": {
|
||||
"navigationBarTitleText": "字典管理"
|
||||
}
|
||||
}
|
||||
</route>
|
||||
@@ -0,0 +1,280 @@
|
||||
<template>
|
||||
<view class="page page--padding page--pt">
|
||||
<view>
|
||||
<wd-search
|
||||
v-model="queryParams.keywords"
|
||||
placeholder="搜索字典标签/字典值"
|
||||
hide-cancel
|
||||
@search="handleSearch"
|
||||
/>
|
||||
</view>
|
||||
|
||||
<view class="mt-16rpx">
|
||||
<wd-card
|
||||
v-for="item in pageData"
|
||||
:key="item.id"
|
||||
custom-class="item-card"
|
||||
@click="openItemDialog(item.id)"
|
||||
>
|
||||
<view class="flex-start">
|
||||
<view class="flex-1">
|
||||
<view class="flex-start">
|
||||
<text class="font-bold text-32rpx">{{ item.label }}</text>
|
||||
</view>
|
||||
<text class="text-24rpx color-text-secondary">
|
||||
字典值:{{ item.value }} · 排序:{{ item.sort }}
|
||||
</text>
|
||||
</view>
|
||||
<wd-tag :type="item.status === 1 ? 'success' : 'danger'" plain>
|
||||
{{ item.status === 1 ? "启用" : "禁用" }}
|
||||
</wd-tag>
|
||||
</view>
|
||||
|
||||
<view class="flex-between mt-16rpx">
|
||||
<text class="text-24rpx color-text-placeholder">{{ item.remark || "暂无备注" }}</text>
|
||||
<view
|
||||
class="w-88rpx h-88rpx flex-center rounded-full"
|
||||
hover-class="bg-[var(--color-text-placeholder)]/16"
|
||||
@click.stop="showItemActions(item)"
|
||||
>
|
||||
<wd-icon name="more" size="18" class="color-text-secondary" />
|
||||
</view>
|
||||
</view>
|
||||
</wd-card>
|
||||
|
||||
<wd-loadmore v-if="total > 0" :state="loadMoreState" @reload="fetchItemList" />
|
||||
<wd-status-tip v-else-if="total === 0" image="search" tip="暂无数据" />
|
||||
</view>
|
||||
|
||||
<wd-popup
|
||||
v-model="dialog.visible"
|
||||
position="bottom"
|
||||
custom-style="border-radius: 24rpx 24rpx 0 0"
|
||||
@close="closeItemDialog"
|
||||
>
|
||||
<view class="p-4">
|
||||
<view class="text-center font-bold text-32rpx mb-4">
|
||||
{{ formData.id ? "编辑字典数据" : "新增字典数据" }}
|
||||
</view>
|
||||
<wd-form ref="formRef" :model="formData" :rules="rules">
|
||||
<wd-cell-group border>
|
||||
<wd-input v-model="formData.label" label="字典项标签" required />
|
||||
<wd-input v-model="formData.value" label="字典项值" required />
|
||||
<wd-cell title="状态">
|
||||
<wd-switch v-model="formData.status" :active-value="1" :inactive-value="0" />
|
||||
</wd-cell>
|
||||
<wd-cell title="排序">
|
||||
<wd-input-number v-model="formData.sort" :min="0" />
|
||||
</wd-cell>
|
||||
<wd-textarea
|
||||
v-model="formData.remark"
|
||||
label="备注"
|
||||
placeholder="请输入备注"
|
||||
:maxlength="100"
|
||||
show-word-limit
|
||||
/>
|
||||
</wd-cell-group>
|
||||
</wd-form>
|
||||
<view class="popup-actions">
|
||||
<wd-button type="info" plain @click="closeItemDialog">取消</wd-button>
|
||||
<wd-button type="primary" :loading="submitting" @click="submitItemForm">保存</wd-button>
|
||||
</view>
|
||||
</view>
|
||||
</wd-popup>
|
||||
|
||||
<view
|
||||
v-if="hasPermission('sys:dict-item:create') && !dialog.visible"
|
||||
class="fab-add"
|
||||
@click.stop="openItemDialog()"
|
||||
>
|
||||
<wd-icon name="add" size="44rpx" />
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { onLoad, onReachBottom } from "@dcloudio/uni-app";
|
||||
import { LoadMoreState } from "wot-design-uni/components/wd-loadmore/types";
|
||||
import { FormRules } from "wot-design-uni/components/wd-form/types";
|
||||
import { useToast } from "wot-design-uni";
|
||||
import DictAPI, {
|
||||
type DictItemForm,
|
||||
type DictItemPageQuery,
|
||||
type DictItemPageVO,
|
||||
} from "@/api/dict";
|
||||
import { hasPermission } from "@/utils/permission";
|
||||
|
||||
const toast = useToast();
|
||||
|
||||
const dictCode = ref<string>("");
|
||||
const pageTitle = ref<string>("字典数据");
|
||||
|
||||
const loadMoreState = ref<LoadMoreState>("loading");
|
||||
const formRef = ref();
|
||||
const submitting = ref(false);
|
||||
|
||||
const queryParams = reactive<DictItemPageQuery>({ pageNum: 1, pageSize: 10, keywords: "" });
|
||||
const total = ref(0);
|
||||
const pageData = ref<DictItemPageVO[]>([]);
|
||||
const dialog = reactive({ visible: false });
|
||||
|
||||
const initialFormData: DictItemForm = {
|
||||
id: undefined,
|
||||
dictCode: undefined,
|
||||
label: undefined,
|
||||
value: undefined,
|
||||
sort: 1,
|
||||
status: 1,
|
||||
remark: undefined,
|
||||
};
|
||||
|
||||
const formData = reactive<DictItemForm>({ ...initialFormData });
|
||||
|
||||
const rules: FormRules = {
|
||||
label: [{ required: true, message: "请输入字典项标签" }],
|
||||
value: [{ required: true, message: "请输入字典项值" }],
|
||||
};
|
||||
|
||||
const handleSearch = () => loadItemList();
|
||||
|
||||
function loadItemList() {
|
||||
queryParams.pageNum = 1;
|
||||
fetchItemList();
|
||||
}
|
||||
|
||||
function fetchItemList() {
|
||||
if (!dictCode.value) {
|
||||
pageData.value = [];
|
||||
total.value = 0;
|
||||
loadMoreState.value = "finished";
|
||||
return;
|
||||
}
|
||||
|
||||
loadMoreState.value = "loading";
|
||||
DictAPI.getItemPage(dictCode.value, queryParams)
|
||||
.then((data: any) => {
|
||||
pageData.value = data.list;
|
||||
total.value = data.total;
|
||||
queryParams.pageNum++;
|
||||
})
|
||||
.catch(() => {
|
||||
pageData.value = [];
|
||||
})
|
||||
.finally(() => {
|
||||
loadMoreState.value = "finished";
|
||||
});
|
||||
}
|
||||
|
||||
async function openItemDialog(id?: string) {
|
||||
formRef.value?.reset();
|
||||
Object.assign(formData, initialFormData);
|
||||
dialog.visible = true;
|
||||
formData.dictCode = dictCode.value;
|
||||
|
||||
if (id) {
|
||||
formData.id = id;
|
||||
const data = await DictAPI.getItemFormData(dictCode.value, id);
|
||||
Object.assign(formData, data, { id });
|
||||
}
|
||||
}
|
||||
|
||||
function submitItemForm() {
|
||||
formRef.value.validate().then(({ valid }: { valid: boolean }) => {
|
||||
if (!valid) return;
|
||||
if (!dictCode.value) {
|
||||
toast.error("缺少字典编码");
|
||||
return;
|
||||
}
|
||||
|
||||
submitting.value = true;
|
||||
const id = formData.id;
|
||||
const action = id
|
||||
? DictAPI.updateItem(dictCode.value, id, formData)
|
||||
: DictAPI.createItem(dictCode.value, formData);
|
||||
|
||||
action
|
||||
.then(() => {
|
||||
toast.success("操作成功");
|
||||
closeItemDialog();
|
||||
loadItemList();
|
||||
})
|
||||
.finally(() => {
|
||||
submitting.value = false;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function closeItemDialog() {
|
||||
dialog.visible = false;
|
||||
formRef.value?.reset();
|
||||
Object.assign(formData, initialFormData);
|
||||
}
|
||||
|
||||
function showItemActions(item: DictItemPageVO) {
|
||||
const actions: string[] = [];
|
||||
const actionMap: Record<string, () => void> = {};
|
||||
|
||||
if (hasPermission("sys:dict-item:update")) {
|
||||
actions.push("编辑");
|
||||
actionMap["编辑"] = () => openItemDialog(item.id);
|
||||
}
|
||||
|
||||
if (hasPermission("sys:dict-item:delete")) {
|
||||
actions.push("删除");
|
||||
actionMap["删除"] = async () => {
|
||||
const { confirm } = await uni.showModal({
|
||||
title: "确认删除",
|
||||
content: `确定要删除字典数据「${item.label}」吗?`,
|
||||
});
|
||||
if (confirm && item.id) {
|
||||
await DictAPI.deleteItems(dictCode.value, String(item.id));
|
||||
toast.success("删除成功");
|
||||
loadItemList();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
if (actions.length === 0) {
|
||||
toast.warning("暂无操作权限");
|
||||
return;
|
||||
}
|
||||
|
||||
uni.showActionSheet({
|
||||
itemList: actions,
|
||||
success: ({ tapIndex }) => {
|
||||
const action = actions[tapIndex];
|
||||
actionMap[action]?.();
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
onReachBottom(() => {
|
||||
if (queryParams.pageNum * queryParams.pageSize < total.value) {
|
||||
fetchItemList();
|
||||
} else {
|
||||
loadMoreState.value = "finished";
|
||||
}
|
||||
});
|
||||
|
||||
onLoad((query) => {
|
||||
dictCode.value = String((query as any)?.dictCode || "");
|
||||
pageTitle.value = String((query as any)?.title || "字典数据");
|
||||
if (pageTitle.value) {
|
||||
uni.setNavigationBarTitle({ title: pageTitle.value });
|
||||
}
|
||||
loadItemList();
|
||||
});
|
||||
</script>
|
||||
|
||||
<script lang="ts">
|
||||
export default { options: { styleIsolation: "shared" } };
|
||||
</script>
|
||||
|
||||
<route lang="json">
|
||||
{
|
||||
"name": "dict-item",
|
||||
"style": {
|
||||
"navigationBarTitleText": "字典数据"
|
||||
}
|
||||
}
|
||||
</route>
|
||||
@@ -25,6 +25,7 @@ import { computed } from "vue";
|
||||
import { useRouter } from "uni-mini-router";
|
||||
import { useUserStore } from "@/store";
|
||||
import { menuConfig } from "@/config/menu";
|
||||
import { checkLogin, isLoggedIn } from "@/utils/auth";
|
||||
|
||||
const router = useRouter();
|
||||
const userStore = useUserStore();
|
||||
@@ -32,6 +33,9 @@ const userStore = useUserStore();
|
||||
// 用户权限列表
|
||||
const userPerms = computed(() => userStore.userInfo?.perms || []);
|
||||
|
||||
// 是否已登录
|
||||
const isLogged = computed(() => isLoggedIn());
|
||||
|
||||
// 检查是否有权限
|
||||
const hasPermission = (perm: string) => {
|
||||
if (!perm) return true; // 无权限要求则显示
|
||||
@@ -50,7 +54,23 @@ const visibleGridList = computed(() => {
|
||||
|
||||
// 处理导航点击
|
||||
function handleNavClick(item: any) {
|
||||
// 未登录时跳转登录页
|
||||
if (!isLogged.value) {
|
||||
uni.navigateTo({ url: "/pages/login/index" });
|
||||
return;
|
||||
}
|
||||
// 已登录但访问受限时,仍做一次登录校验(防 token 过期)
|
||||
if (!checkLogin()) return;
|
||||
|
||||
try {
|
||||
if (
|
||||
typeof item?.url === "string" &&
|
||||
(item.url.startsWith("http://") || item.url.startsWith("https://"))
|
||||
) {
|
||||
uni.navigateTo({ url: `/pages/webview/index?url=${encodeURIComponent(item.url)}` });
|
||||
return;
|
||||
}
|
||||
|
||||
router.push({ path: item.url });
|
||||
} catch (e) {
|
||||
console.error("[work] router.push failed:", e, item);
|
||||
|
||||
+99
-121
@@ -1,117 +1,113 @@
|
||||
<template>
|
||||
<view class="log">
|
||||
<!-- 筛选 -->
|
||||
<wd-drop-menu close-on-click-modal class="mb-24rpx">
|
||||
<wd-drop-menu-item ref="filterDropMenu" title="筛选" icon="filter" icon-size="18px">
|
||||
<view>
|
||||
<wd-input
|
||||
v-model="queryParams.keywords"
|
||||
label="关键字"
|
||||
type="text"
|
||||
placeholder="请输入关键字"
|
||||
/>
|
||||
<view class="page page--padding page--pt">
|
||||
<view>
|
||||
<wd-search
|
||||
v-model="queryParams.keywords"
|
||||
placeholder="搜索日志内容"
|
||||
hide-cancel
|
||||
@search="handleSearch"
|
||||
/>
|
||||
</view>
|
||||
|
||||
<cu-date-query v-model="queryParams.createTime" :label="'日期选择'" />
|
||||
|
||||
<view class="flex-between py-2">
|
||||
<wd-button class="w-20%" type="info" @click="handleResetQuery">重置</wd-button>
|
||||
<wd-button class="w-70%" @click="handleQuery">查询</wd-button>
|
||||
<!-- 日志列表 -->
|
||||
<view class="mt-16rpx">
|
||||
<wd-card
|
||||
v-for="item in pageData"
|
||||
:key="item.id"
|
||||
custom-class="item-card"
|
||||
@click="openLogDetail(item)"
|
||||
>
|
||||
<!-- 主信息行 -->
|
||||
<view class="flex-start">
|
||||
<view class="flex-1">
|
||||
<view class="flex-start mt-12rpx">
|
||||
<text class="font-bold text-32rpx">{{ item.operator }}</text>
|
||||
<wd-tag plain size="small" class="ml-16rpx">{{ item.module }}</wd-tag>
|
||||
</view>
|
||||
<text class="text-24rpx color-text-secondary truncate">{{ item.content }}</text>
|
||||
</view>
|
||||
</view>
|
||||
</wd-drop-menu-item>
|
||||
</wd-drop-menu>
|
||||
|
||||
<!-- 卡片列表 -->
|
||||
<wd-card v-for="item in pageData" :key="item.id" class="card-list">
|
||||
<template #title>
|
||||
{{ item.operator }}
|
||||
</template>
|
||||
|
||||
<wd-cell-group>
|
||||
<wd-cell title="模块" :value="item.module" />
|
||||
<wd-cell title="内容" :value="item.content" />
|
||||
<wd-cell title="IP" :value="item.ip" />
|
||||
<wd-cell title="地区" :value="item.region" />
|
||||
</wd-cell-group>
|
||||
|
||||
<template #footer>
|
||||
<view class="flex-between">
|
||||
<view class="text-left">
|
||||
<wd-text text="创建时间:" size="small" class="font-bold" />
|
||||
<wd-text :text="item.createTime" size="small" />
|
||||
</view>
|
||||
<view class="text-right">
|
||||
<wd-button type="primary" size="small" plain @click="handleViewDetail(item)">
|
||||
查看详情
|
||||
</wd-button>
|
||||
<!-- 辅助信息行 -->
|
||||
<view class="flex gap-24rpx mt-12rpx">
|
||||
<view class="flex-start min-w-0 flex-1">
|
||||
<wd-icon name="location" size="16" class="color-text-secondary" />
|
||||
<text class="ml-8rpx text-24rpx color-text-secondary">
|
||||
{{ item.ip }} {{ item.region }}
|
||||
</text>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
</wd-card>
|
||||
|
||||
<!-- 元信息行 -->
|
||||
<view class="flex-between mt-16rpx">
|
||||
<text class="text-24rpx color-text-placeholder">{{ item.createTime }}</text>
|
||||
<view
|
||||
class="w-64rpx h-64rpx flex-center rounded-full"
|
||||
hover-class="bg-[var(--color-text-placeholder)]/16"
|
||||
@click.stop="openLogDetail(item)"
|
||||
>
|
||||
<wd-icon name="view" size="16" class="color-text-secondary" />
|
||||
</view>
|
||||
</view>
|
||||
</wd-card>
|
||||
|
||||
<wd-loadmore v-if="total > 0" :state="loadMoreState" @reload="fetchLogList" />
|
||||
<wd-status-tip v-else-if="total === 0" image="search" tip="暂无数据" />
|
||||
</view>
|
||||
|
||||
<!-- 详情弹窗 -->
|
||||
<wd-popup v-model="detailDialogVisible" position="bottom">
|
||||
<wd-cell-group>
|
||||
<wd-cell title="操作人" :value="logDetail.operator" />
|
||||
<wd-cell title="操作时间" :value="logDetail.createTime" />
|
||||
<wd-cell title="模块" :value="logDetail.module" />
|
||||
<wd-cell title="内容" :value="logDetail.content" />
|
||||
<wd-cell title="IP" :value="logDetail.ip" />
|
||||
<wd-cell title="地区" :value="logDetail.region" />
|
||||
<wd-cell title="浏览器" :value="logDetail.browser" />
|
||||
<wd-cell title="终端系统" :value="logDetail.os" />
|
||||
<wd-cell title="耗时(毫秒)" :value="logDetail.executionTime" />
|
||||
</wd-cell-group>
|
||||
<wd-popup
|
||||
v-model="detailDialog.visible"
|
||||
position="bottom"
|
||||
custom-style="border-radius: 24rpx 24rpx 0 0"
|
||||
@close="closeLogDetail"
|
||||
>
|
||||
<view class="p-4">
|
||||
<view class="text-center font-bold text-32rpx mb-4">日志详情</view>
|
||||
<wd-cell-group border>
|
||||
<wd-cell title="操作人" :value="logDetail.operator" />
|
||||
<wd-cell title="操作时间" :value="logDetail.createTime" />
|
||||
<wd-cell title="模块" :value="logDetail.module" />
|
||||
<wd-cell title="内容" :value="logDetail.content" />
|
||||
<wd-cell title="IP" :value="logDetail.ip" />
|
||||
<wd-cell title="地区" :value="logDetail.region" />
|
||||
<wd-cell title="浏览器" :value="logDetail.browser" />
|
||||
<wd-cell title="终端系统" :value="logDetail.os" />
|
||||
<wd-cell title="耗时(毫秒)" :value="String(logDetail.executionTime || 0)" />
|
||||
</wd-cell-group>
|
||||
<view class="popup-actions">
|
||||
<wd-button type="info" plain block @click="closeLogDetail">关闭</wd-button>
|
||||
</view>
|
||||
</view>
|
||||
</wd-popup>
|
||||
|
||||
<!-- 加载更多 -->
|
||||
<wd-loadmore v-if="total > 0" :state="loadMoreState" @reload="loadmore" />
|
||||
<wd-status-tip v-else-if="total == 0" image="search" tip="当前搜索无结果" />
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
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 LogAPI, { type LogPageQuery, LogVO } from "@/api/log";
|
||||
|
||||
import LogAPI, { LogVO, LogPageQuery } from "@/api/log";
|
||||
|
||||
const filterDropMenu = ref<DropMenuItemExpose>();
|
||||
const loadMoreState = ref<LoadMoreState>("loading");
|
||||
|
||||
const queryParams = reactive<LogPageQuery>({
|
||||
pageNum: 1,
|
||||
pageSize: 10,
|
||||
});
|
||||
|
||||
const queryParams = reactive<LogPageQuery>({ pageNum: 1, pageSize: 10 });
|
||||
const total = ref(0);
|
||||
const pageData = ref<LogVO[]>([]);
|
||||
|
||||
const logDetail = ref<LogVO>({});
|
||||
const detailDialogVisible = ref(false);
|
||||
const detailDialog = reactive({ visible: false });
|
||||
|
||||
/**
|
||||
* 搜索栏
|
||||
*/
|
||||
function handleQuery() {
|
||||
filterDropMenu.value?.close();
|
||||
// 搜索触发
|
||||
const handleSearch = () => loadLogList();
|
||||
|
||||
// 加载列表
|
||||
function loadLogList() {
|
||||
queryParams.pageNum = 1;
|
||||
loadmore();
|
||||
fetchLogList();
|
||||
}
|
||||
|
||||
/**
|
||||
* 重置搜索
|
||||
*/
|
||||
function handleResetQuery() {
|
||||
queryParams.keywords = undefined;
|
||||
queryParams.createTime = undefined;
|
||||
handleQuery();
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载更多
|
||||
*/
|
||||
function loadmore() {
|
||||
// 分页加载列表
|
||||
function fetchLogList() {
|
||||
loadMoreState.value = "loading";
|
||||
LogAPI.getPage(queryParams)
|
||||
.then((data) => {
|
||||
@@ -127,30 +123,34 @@ function loadmore() {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 查看详情
|
||||
*/
|
||||
function handleViewDetail(item: LogVO) {
|
||||
detailDialogVisible.value = true;
|
||||
// 打开详情弹窗
|
||||
function openLogDetail(item: LogVO) {
|
||||
logDetail.value = item;
|
||||
detailDialog.visible = true;
|
||||
}
|
||||
|
||||
// 关闭详情弹窗
|
||||
function closeLogDetail() {
|
||||
detailDialog.visible = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 触底事件
|
||||
*/
|
||||
onReachBottom(() => {
|
||||
if (queryParams.pageNum * queryParams.pageSize < total.value) {
|
||||
loadmore();
|
||||
} else if (queryParams.pageNum * queryParams.pageSize >= total.value) {
|
||||
fetchLogList();
|
||||
} else {
|
||||
loadMoreState.value = "finished";
|
||||
}
|
||||
});
|
||||
|
||||
onLoad(() => {
|
||||
handleQuery();
|
||||
loadLogList();
|
||||
});
|
||||
</script>
|
||||
|
||||
<script lang="ts">
|
||||
export default { options: { styleIsolation: "shared" } };
|
||||
</script>
|
||||
|
||||
<route lang="json">
|
||||
{
|
||||
"name": "log",
|
||||
@@ -159,25 +159,3 @@ onLoad(() => {
|
||||
}
|
||||
}
|
||||
</route>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.wd-col {
|
||||
margin-top: 10rpx;
|
||||
}
|
||||
|
||||
::v-deep .wd-drop-menu__item {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
padding: 0 50rpx;
|
||||
}
|
||||
|
||||
.card-list {
|
||||
:deep(.wd-cell__wrapper) {
|
||||
padding: 4rpx 0;
|
||||
}
|
||||
:deep(.wd-cell) {
|
||||
padding-right: 10rpx;
|
||||
background: #f8f8f8;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
+387
-22
@@ -1,39 +1,404 @@
|
||||
<template>
|
||||
<view class="page">
|
||||
<wd-cell-group border>
|
||||
<wd-cell title="菜单管理" is-link to="/pages/work/menu/index" />
|
||||
</wd-cell-group>
|
||||
<view class="placeholder">
|
||||
<text class="placeholder__text">菜单管理功能开发中...</text>
|
||||
<view class="page page--padding page--pt">
|
||||
<view>
|
||||
<wd-search
|
||||
v-model="queryParams.keywords"
|
||||
placeholder="搜索菜单名称"
|
||||
hide-cancel
|
||||
@search="handleSearch"
|
||||
/>
|
||||
</view>
|
||||
|
||||
<!-- 菜单树形列表 -->
|
||||
<view class="mt-16rpx">
|
||||
<custom-tree
|
||||
:data="treeData"
|
||||
:default-expand-all="true"
|
||||
:show-action="true"
|
||||
@action="handleNodeAction"
|
||||
>
|
||||
<!-- 自定义节点内容:ID + 名称 + 状态 -->
|
||||
<template #content="{ node }">
|
||||
<view class="flex-1 flex flex-nowrap items-center gap-16rpx">
|
||||
<text class="w-120rpx text-24rpx color-text-secondary">{{ node.id }}</text>
|
||||
<wd-icon v-if="node.icon" :name="node.icon" size="16" class="color-primary" />
|
||||
<text class="flex-1 truncate">{{ node.name }}</text>
|
||||
<wd-tag class="flex-shrink-0" :type="getMenuTypeTag(node.type)" size="small">
|
||||
{{ getMenuTypeText(node.type) }}
|
||||
</wd-tag>
|
||||
<wd-tag
|
||||
class="flex-shrink-0"
|
||||
:type="node.visible === 1 ? 'success' : 'primary'"
|
||||
size="small"
|
||||
>
|
||||
{{ node.visible === 1 ? "显示" : "隐藏" }}
|
||||
</wd-tag>
|
||||
</view>
|
||||
</template>
|
||||
</custom-tree>
|
||||
|
||||
<wd-status-tip v-if="menuList.length === 0" image="search" tip="暂无数据" />
|
||||
</view>
|
||||
|
||||
<!-- 弹窗表单 -->
|
||||
<wd-popup
|
||||
v-model="dialog.visible"
|
||||
position="bottom"
|
||||
custom-style="border-radius: 24rpx 24rpx 0 0; max-height: 80vh"
|
||||
@close="closeMenuDialog"
|
||||
>
|
||||
<view class="p-4">
|
||||
<view class="text-center font-bold text-32rpx mb-4">
|
||||
{{ formData.id ? "编辑菜单" : "新增菜单" }}
|
||||
</view>
|
||||
<scroll-view scroll-y class="max-h-60vh">
|
||||
<wd-form ref="formRef" :model="formData" :rules="rules">
|
||||
<wd-cell-group border>
|
||||
<wd-col-picker
|
||||
v-model="parentSelected"
|
||||
label="上级菜单"
|
||||
:columns="parentColumns"
|
||||
:column-change="handleParentColumnChange"
|
||||
required
|
||||
:display-format="displayParentFormat"
|
||||
@confirm="handleParentConfirm"
|
||||
/>
|
||||
<wd-input v-model="formData.name" label="菜单名称" required />
|
||||
<wd-cell title="菜单类型" required>
|
||||
<wd-radio-group v-model="formData.type" size="smalll" shape="button" cell>
|
||||
<wd-radio value="C">目录</wd-radio>
|
||||
<wd-radio value="M">菜单</wd-radio>
|
||||
<wd-radio value="B">按钮</wd-radio>
|
||||
</wd-radio-group>
|
||||
</wd-cell>
|
||||
<wd-input
|
||||
v-if="formData.type !== 'B'"
|
||||
v-model="formData.routePath"
|
||||
label="路由路径"
|
||||
placeholder="system 或 /system"
|
||||
/>
|
||||
<wd-input
|
||||
v-if="formData.type === 'M'"
|
||||
v-model="formData.component"
|
||||
label="组件路径"
|
||||
placeholder="system/menu/index"
|
||||
/>
|
||||
<wd-input
|
||||
v-if="formData.type === 'B'"
|
||||
v-model="formData.perm"
|
||||
label="权限标识"
|
||||
placeholder="sys:menu:create"
|
||||
/>
|
||||
<wd-input v-model="formData.icon" label="图标" />
|
||||
<wd-cell title="排序">
|
||||
<wd-input-number v-model="formData.sort!" :min="0" />
|
||||
</wd-cell>
|
||||
<wd-cell title="状态">
|
||||
<wd-switch v-model="formData.visible" :active-value="1" :inactive-value="0" />
|
||||
</wd-cell>
|
||||
</wd-cell-group>
|
||||
</wd-form>
|
||||
</scroll-view>
|
||||
<view class="popup-actions">
|
||||
<wd-button type="info" plain @click="closeMenuDialog">取消</wd-button>
|
||||
<wd-button type="primary" :loading="submitting" @click="submitMenuForm">保存</wd-button>
|
||||
</view>
|
||||
</view>
|
||||
</wd-popup>
|
||||
|
||||
<!-- 浮动新增按钮 -->
|
||||
<view
|
||||
v-if="hasPermission('sys:menu:create') && !dialog.visible"
|
||||
class="fab-add"
|
||||
hover-class="fab-add:active"
|
||||
@click.stop="openMenuDialog()"
|
||||
>
|
||||
<wd-icon name="add" size="44rpx" />
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
<script lang="ts" setup>
|
||||
import { onLoad } from "@dcloudio/uni-app";
|
||||
import { FormRules } from "wot-design-uni/components/wd-form/types";
|
||||
import { useToast } from "wot-design-uni";
|
||||
import MenuAPI, { type MenuQuery, MenuVO, MenuForm } from "@/api/menu";
|
||||
import { hasPermission } from "@/utils/permission";
|
||||
import CustomTree from "@/components/custom-tree/index.vue";
|
||||
|
||||
const toast = useToast();
|
||||
const formRef = ref();
|
||||
const submitting = ref(false);
|
||||
|
||||
const queryParams = reactive<MenuQuery>({ keywords: "" });
|
||||
const menuList = ref<MenuVO[]>([]);
|
||||
const dialog = reactive({ visible: false });
|
||||
|
||||
const initialFormData: MenuForm = {
|
||||
id: undefined,
|
||||
parentId: "0",
|
||||
name: undefined,
|
||||
type: "M",
|
||||
routePath: undefined,
|
||||
component: undefined,
|
||||
perm: undefined,
|
||||
icon: undefined,
|
||||
sort: 1,
|
||||
visible: 1,
|
||||
};
|
||||
|
||||
const formData = reactive<MenuForm>({ ...initialFormData });
|
||||
|
||||
// 转换为树组件数据格式
|
||||
const treeData = computed(() => menuList.value.map((menu) => transformMenuToTree(menu)));
|
||||
|
||||
function transformMenuToTree(menu: MenuVO): any {
|
||||
return {
|
||||
value: menu.id,
|
||||
label: menu.name,
|
||||
id: menu.id,
|
||||
name: menu.name,
|
||||
type: menu.type,
|
||||
icon: menu.icon,
|
||||
visible: menu.visible,
|
||||
perm: menu.perm,
|
||||
children: menu.children?.map((child) => transformMenuToTree(child)) || [],
|
||||
};
|
||||
}
|
||||
|
||||
// 菜单类型标签
|
||||
function normalizeMenuType(type?: string | number) {
|
||||
if (type === 1 || type === "1") return "C";
|
||||
if (type === 2 || type === "2") return "M";
|
||||
if (type === 3 || type === "3") return "B";
|
||||
return type;
|
||||
}
|
||||
|
||||
function getMenuTypeTag(type?: string | number): "primary" | "success" | "warning" | "danger" {
|
||||
const map: Record<string, "primary" | "success" | "warning" | "danger"> = {
|
||||
C: "warning",
|
||||
M: "success",
|
||||
B: "danger",
|
||||
};
|
||||
const key = String(normalizeMenuType(type) || "M");
|
||||
return map[key] || "primary";
|
||||
}
|
||||
|
||||
function getMenuTypeText(type?: string | number) {
|
||||
const map: Record<string, string> = { C: "目录", M: "菜单", B: "按钮" };
|
||||
const key = String(normalizeMenuType(type) || "M");
|
||||
return map[key] || "菜单";
|
||||
}
|
||||
|
||||
// 上级菜单选择器
|
||||
const parentSelected = ref<(string | number)[]>([]);
|
||||
const parentColumns = ref<OptionType[][]>([]);
|
||||
const parentOptions = ref<OptionType[]>([]);
|
||||
|
||||
const displayParentFormat = (selectedItems: Record<string, any>[]) => {
|
||||
if (!selectedItems || selectedItems.length === 0) return "";
|
||||
return selectedItems
|
||||
.map((item) => item?.label)
|
||||
.filter((label) => !!label)
|
||||
.join("/");
|
||||
};
|
||||
|
||||
function findMenuPath(
|
||||
data: Record<string, any>[],
|
||||
targetId: string,
|
||||
path: (string | number)[] = []
|
||||
): (string | number)[] | null {
|
||||
for (const item of data) {
|
||||
const currentPath = [...path, item.value];
|
||||
if (String(item.value) === targetId) {
|
||||
return currentPath;
|
||||
}
|
||||
if (item.children && item.children.length > 0) {
|
||||
const found = findMenuPath(item.children, targetId, currentPath);
|
||||
if (found) return found;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
const handleParentColumnChange = ({ selectedItem, resolve, finish }: any) => {
|
||||
if (String(selectedItem?.value) === "0") {
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
const children = selectedItem.children;
|
||||
if (children && children.length > 0) {
|
||||
resolve(children);
|
||||
} else {
|
||||
finish();
|
||||
}
|
||||
};
|
||||
|
||||
const handleParentConfirm = ({ value }: any) => {
|
||||
parentSelected.value = value;
|
||||
formData.parentId = String(value[value.length - 1]) || "0";
|
||||
};
|
||||
|
||||
const rules: FormRules = {
|
||||
name: [{ required: true, message: "请输入菜单名称" }],
|
||||
type: [{ required: true, message: "请选择菜单类型" }],
|
||||
parentId: [{ required: true, message: "请选择上级菜单" }],
|
||||
};
|
||||
|
||||
const handleSearch = () => loadMenuList();
|
||||
|
||||
function loadMenuList() {
|
||||
MenuAPI.getList(queryParams).then((data) => {
|
||||
menuList.value = data;
|
||||
});
|
||||
}
|
||||
|
||||
// 处理节点操作按钮点击
|
||||
function handleNodeAction(node: any) {
|
||||
const menu: MenuVO = {
|
||||
id: node.id,
|
||||
name: node.label,
|
||||
type: node.type,
|
||||
visible: node.visible,
|
||||
children: node.children,
|
||||
} as MenuVO;
|
||||
|
||||
const actions: string[] = [];
|
||||
const actionMap: Record<string, () => void> = {};
|
||||
|
||||
if (hasPermission("sys:menu:create") && node.type !== 3) {
|
||||
actions.push("新增子菜单");
|
||||
actionMap["新增子菜单"] = () => handleAddChild(menu);
|
||||
}
|
||||
|
||||
if (hasPermission("sys:menu:update")) {
|
||||
actions.push("编辑");
|
||||
actionMap["编辑"] = () => openMenuDialog(menu);
|
||||
}
|
||||
|
||||
if (hasPermission("sys:menu:delete")) {
|
||||
actions.push("删除");
|
||||
actionMap["删除"] = async () => {
|
||||
const { confirm } = await uni.showModal({
|
||||
title: "确认删除",
|
||||
content: `确定要删除菜单「${menu.name}」吗?`,
|
||||
});
|
||||
if (confirm) {
|
||||
await MenuAPI.deleteById(menu.id!);
|
||||
toast.success("删除成功");
|
||||
loadMenuList();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
if (actions.length === 0) {
|
||||
toast.warning("暂无操作权限");
|
||||
return;
|
||||
}
|
||||
|
||||
uni.showActionSheet({
|
||||
itemList: actions,
|
||||
success: ({ tapIndex }) => {
|
||||
const action = actions[tapIndex];
|
||||
actionMap[action]?.();
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
// 打开弹窗(新增/编辑)
|
||||
async function openMenuDialog(menu?: MenuVO) {
|
||||
formRef.value?.reset();
|
||||
Object.assign(formData, initialFormData);
|
||||
parentSelected.value = [];
|
||||
dialog.visible = true;
|
||||
|
||||
const data = await MenuAPI.getOptions(true);
|
||||
parentOptions.value = data;
|
||||
const firstColumn: OptionType[] = [{ value: "0", label: "顶级菜单" }, ...data];
|
||||
parentColumns.value = [firstColumn];
|
||||
|
||||
if (menu) {
|
||||
formData.id = menu.id;
|
||||
const form = await MenuAPI.getFormData(menu.id!);
|
||||
Object.assign(formData, form, { id: menu.id });
|
||||
|
||||
if (form.parentId && String(form.parentId) !== "0") {
|
||||
const path = findMenuPath(data, String(form.parentId));
|
||||
if (path) {
|
||||
parentSelected.value = path;
|
||||
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]));
|
||||
if (found && found.children && found.children.length > 0) {
|
||||
columns.push(found.children);
|
||||
currentLevel = found.children;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
parentColumns.value = columns;
|
||||
} else {
|
||||
parentSelected.value = [String(form.parentId)];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 新增子菜单
|
||||
function handleAddChild(menu: MenuVO) {
|
||||
openMenuDialog({ id: undefined, parentId: menu.id } as MenuVO);
|
||||
formData.parentId = menu.id!;
|
||||
parentSelected.value = [menu.id!];
|
||||
}
|
||||
|
||||
// 提交表单
|
||||
function submitMenuForm() {
|
||||
formRef.value.validate().then(({ valid }: { valid: boolean }) => {
|
||||
if (!valid) return;
|
||||
submitting.value = true;
|
||||
const action = formData.id ? MenuAPI.update(formData.id, formData) : MenuAPI.add(formData);
|
||||
action
|
||||
.then(() => {
|
||||
toast.success("操作成功");
|
||||
closeMenuDialog();
|
||||
loadMenuList();
|
||||
})
|
||||
.finally(() => {
|
||||
submitting.value = false;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// 关闭弹窗
|
||||
function closeMenuDialog() {
|
||||
dialog.visible = false;
|
||||
formRef.value?.reset();
|
||||
Object.assign(formData, initialFormData);
|
||||
}
|
||||
|
||||
onLoad(() => {
|
||||
loadMenuList();
|
||||
});
|
||||
</script>
|
||||
|
||||
<script lang="ts">
|
||||
export default { options: { styleIsolation: "shared" } };
|
||||
</script>
|
||||
|
||||
<route lang="json">
|
||||
{
|
||||
"name": "menu",
|
||||
"style": { "navigationBarTitleText": "菜单管理" }
|
||||
"style": {
|
||||
"navigationBarTitleText": "菜单管理"
|
||||
}
|
||||
}
|
||||
</route>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.page {
|
||||
min-height: 100vh;
|
||||
background-color: #f8fafc;
|
||||
}
|
||||
|
||||
.placeholder {
|
||||
.popup-actions {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
height: 300rpx;
|
||||
|
||||
&__text {
|
||||
font-size: 14px;
|
||||
color: #94a3b8;
|
||||
}
|
||||
gap: 24rpx;
|
||||
margin-top: 32rpx;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,26 @@
|
||||
<template>
|
||||
<view class="page">
|
||||
<web-view :src="monitorUrl" />
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref } from "vue";
|
||||
|
||||
// SpringBoot Admin 监控地址
|
||||
const monitorUrl = ref("http://localhost:9090/wallboard");
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.page {
|
||||
width: 100%;
|
||||
height: 100vh;
|
||||
}
|
||||
</style>
|
||||
|
||||
<route lang="json">
|
||||
{
|
||||
"name": "monitor",
|
||||
"style": { "navigationBarTitleText": "应用监控" }
|
||||
}
|
||||
</route>
|
||||
+339
-251
@@ -1,273 +1,388 @@
|
||||
<template>
|
||||
<view>
|
||||
<!-- 添加搜索栏 -->
|
||||
<wd-drop-menu close-on-click-modal class="mb-20rpx mr-20rpx ml-20rpx">
|
||||
<wd-drop-menu-item ref="dropMenu" title="筛选" icon="filter" icon-size="18px">
|
||||
<view>
|
||||
<wd-input
|
||||
v-model="queryParams.title"
|
||||
label="关键字"
|
||||
type="text"
|
||||
placeholder="请输入关键字"
|
||||
/>
|
||||
|
||||
<view class="flex flex-row items-center mb-20rpx">
|
||||
<wd-button class="mt-20rpx mb-20rpx" size="medium" @click="handleQuery()">
|
||||
查询
|
||||
</wd-button>
|
||||
<wd-button size="medium" type="info" @click="handleReset">重置</wd-button>
|
||||
</view>
|
||||
</view>
|
||||
</wd-drop-menu-item>
|
||||
</wd-drop-menu>
|
||||
|
||||
<!-- 列表内容 -->
|
||||
<view class="data-container">
|
||||
<view v-for="(item, index) in dataList" :key="index" class="mt-20rpx">
|
||||
<wd-card>
|
||||
<template #title>
|
||||
<view class="flex items-center justify-between">
|
||||
<view class="flex-1 text-truncate">{{ item.title }}</view>
|
||||
<wd-tag :type="getStatusType(item.publishStatus)" size="small">
|
||||
{{ getStatusText(item.publishStatus) }}
|
||||
</wd-tag>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<wd-cell-group>
|
||||
<wd-cell title="通告目标类型" :value="item.targetType === 1 ? '指定' : '全体'" />
|
||||
<wd-cell title="紧急程度">
|
||||
<template #default>
|
||||
<text>{{ getLevelText(item.level) }}</text>
|
||||
</template>
|
||||
</wd-cell>
|
||||
<wd-cell title="发布人" :value="item.publisherName || '-'" />
|
||||
</wd-cell-group>
|
||||
<template #footer>
|
||||
<view class="flex-between">
|
||||
<view v-if="item.publishStatus === 1" class="text-left">
|
||||
<wd-text text="发布时间:" size="small" class="font-bold" />
|
||||
<wd-text :text="formatDate(item.publishTime)" size="small" />
|
||||
</view>
|
||||
<view v-else class="text-left">
|
||||
<wd-text text="撤回时间:" size="small" class="font-bold" />
|
||||
<wd-text :text="formatDate(item.revokeTime)" size="small" />
|
||||
</view>
|
||||
<view class="text-right">
|
||||
<wd-button size="small" plain type="primary" @click="handleAction(item)">
|
||||
操作
|
||||
</wd-button>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
</wd-card>
|
||||
</view>
|
||||
<view class="page page--padding page--pt">
|
||||
<view>
|
||||
<wd-search
|
||||
v-model="queryParams.title"
|
||||
placeholder="搜索通知标题"
|
||||
hide-cancel
|
||||
@search="handleSearch"
|
||||
/>
|
||||
</view>
|
||||
|
||||
<!-- 加载更多 -->
|
||||
<wd-loadmore custom-class="loadmore" :state="loadState" />
|
||||
<!-- 通知列表 -->
|
||||
<view class="mt-16rpx">
|
||||
<wd-card
|
||||
v-for="item in pageData"
|
||||
:key="item.id"
|
||||
custom-class="item-card"
|
||||
@click="openNoticeDetail(item)"
|
||||
>
|
||||
<!-- 主信息行 -->
|
||||
<view class="flex-start">
|
||||
<view class="flex-1">
|
||||
<view class="flex-start mt-12rpx">
|
||||
<text class="font-bold text-32rpx">{{ item.title }}</text>
|
||||
</view>
|
||||
<text class="text-24rpx color-text-secondary">
|
||||
{{ item.publisherName || "系统管理员" }}
|
||||
</text>
|
||||
</view>
|
||||
<wd-tag :type="getStatusType(item.publishStatus)" plain>
|
||||
{{ getStatusText(item.publishStatus) }}
|
||||
</wd-tag>
|
||||
</view>
|
||||
|
||||
<!-- 辅助信息行 -->
|
||||
<view class="flex gap-24rpx mt-12rpx">
|
||||
<view class="flex-start min-w-0">
|
||||
<wd-icon name="user" size="16" class="color-text-secondary" />
|
||||
<text class="ml-8rpx text-24rpx color-text-secondary">
|
||||
{{ item.targetType === 1 ? "全体" : "指定用户" }}
|
||||
</text>
|
||||
</view>
|
||||
<view class="flex-start min-w-0">
|
||||
<wd-icon name="warning" size="16" class="color-text-secondary" />
|
||||
<text class="ml-8rpx text-24rpx color-text-secondary">
|
||||
{{ getLevelText(item.level) }}
|
||||
</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 元信息行 -->
|
||||
<view class="flex-between mt-16rpx">
|
||||
<text class="text-24rpx color-text-placeholder">{{ formatTime(item) }}</text>
|
||||
<view
|
||||
class="w-64rpx h-64rpx flex-center rounded-full"
|
||||
hover-class="bg-[var(--color-text-placeholder)]/16"
|
||||
@click.stop="showNoticeActions(item)"
|
||||
>
|
||||
<wd-icon name="more" size="16" class="color-text-secondary" />
|
||||
</view>
|
||||
</view>
|
||||
</wd-card>
|
||||
|
||||
<wd-loadmore v-if="total > 0" :state="loadMoreState" @reload="fetchNoticeList" />
|
||||
<wd-status-tip v-else-if="total === 0" image="search" tip="暂无数据" />
|
||||
</view>
|
||||
|
||||
<!-- 详情弹窗 -->
|
||||
<wd-popup
|
||||
v-model="detailDialog.visible"
|
||||
position="bottom"
|
||||
custom-style="border-radius: 24rpx 24rpx 0 0"
|
||||
@close="closeNoticeDetail"
|
||||
>
|
||||
<view class="p-4">
|
||||
<view class="text-center font-bold text-32rpx mb-4">通知详情</view>
|
||||
<wd-cell-group border>
|
||||
<wd-cell title="标题" :value="noticeDetail.title" />
|
||||
<wd-cell title="发布状态">
|
||||
<template #default>
|
||||
<wd-tag :type="getStatusType(noticeDetail.publishStatus)" size="small">
|
||||
{{ getStatusText(noticeDetail.publishStatus) }}
|
||||
</wd-tag>
|
||||
</template>
|
||||
</wd-cell>
|
||||
<wd-cell title="发布人" :value="noticeDetail.publisherName" />
|
||||
<wd-cell title="发布时间" :value="String(noticeDetail.publishTime || '-')" />
|
||||
</wd-cell-group>
|
||||
<view class="mt-4 p-4 bg-[var(--color-bg-secondary)] rounded-lg">
|
||||
<rich-text :nodes="noticeDetail.content" class="text-28rpx" />
|
||||
</view>
|
||||
<view class="popup-actions">
|
||||
<wd-button type="info" plain block @click="closeNoticeDetail">关闭</wd-button>
|
||||
</view>
|
||||
</view>
|
||||
</wd-popup>
|
||||
|
||||
<!-- 新增/编辑弹窗 -->
|
||||
<wd-popup
|
||||
v-model="formDialog.visible"
|
||||
position="bottom"
|
||||
custom-style="border-radius: 24rpx 24rpx 0 0"
|
||||
@close="closeNoticeForm"
|
||||
>
|
||||
<view class="p-4">
|
||||
<view class="text-center font-bold text-32rpx mb-4">
|
||||
{{ formData.id ? "编辑通知" : "新增通知" }}
|
||||
</view>
|
||||
<wd-form ref="formRef" :model="formData" :rules="formRules">
|
||||
<wd-cell-group border>
|
||||
<wd-input v-model="formData.title" label="标题" required placeholder="请输入通知标题" />
|
||||
<wd-cell title="优先级">
|
||||
<wd-radio-group v-model="formData.level" shape="button">
|
||||
<wd-radio value="L">低</wd-radio>
|
||||
<wd-radio value="M">中</wd-radio>
|
||||
<wd-radio value="H">高</wd-radio>
|
||||
</wd-radio-group>
|
||||
</wd-cell>
|
||||
<wd-cell title="目标类型">
|
||||
<wd-radio-group v-model="formData.targetType" shape="button">
|
||||
<wd-radio :value="1">全体</wd-radio>
|
||||
<wd-radio :value="2">指定用户</wd-radio>
|
||||
</wd-radio-group>
|
||||
</wd-cell>
|
||||
<wd-textarea
|
||||
v-model="formData.content"
|
||||
label="内容"
|
||||
placeholder="请输入通知内容"
|
||||
:maxlength="500"
|
||||
show-word-limit
|
||||
/>
|
||||
</wd-cell-group>
|
||||
</wd-form>
|
||||
<view class="popup-actions">
|
||||
<wd-button type="info" plain @click="closeNoticeForm">取消</wd-button>
|
||||
<wd-button type="primary" :loading="submitting" @click="submitNoticeForm">保存</wd-button>
|
||||
</view>
|
||||
</view>
|
||||
</wd-popup>
|
||||
|
||||
<view
|
||||
v-if="hasPermission('sys:notice:create') && !formDialog.visible && !detailDialog.visible"
|
||||
class="fab-add"
|
||||
@click.stop="openNoticeForm()"
|
||||
>
|
||||
<wd-icon name="add" size="44rpx" />
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
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 NoticeAPI, { NoticePageQuery, NoticePageVO } from "@/api/notice";
|
||||
const loadState = ref<LoadMoreState>("finished");
|
||||
const dataList = ref<NoticePageVO[]>([]);
|
||||
import { FormRules } from "wot-design-uni/components/wd-form/types";
|
||||
import { useToast } from "wot-design-uni";
|
||||
import NoticeAPI, {
|
||||
type NoticePageQuery,
|
||||
NoticePageVO,
|
||||
NoticeDetailVO,
|
||||
NoticeForm,
|
||||
} from "@/api/notice";
|
||||
import { hasPermission } from "@/utils/permission";
|
||||
|
||||
const toast = useToast();
|
||||
const loadMoreState = ref<LoadMoreState>("loading");
|
||||
const formRef = ref();
|
||||
const submitting = ref(false);
|
||||
|
||||
const queryParams = reactive<NoticePageQuery>({ pageNum: 1, pageSize: 10 });
|
||||
const total = ref(0);
|
||||
const pageData = ref<NoticePageVO[]>([]);
|
||||
|
||||
// 修改查询参数
|
||||
const queryParams = ref<NoticePageQuery>({
|
||||
pageNum: 1,
|
||||
pageSize: 10,
|
||||
title: "",
|
||||
});
|
||||
const noticeDetail = ref<NoticeDetailVO>({});
|
||||
const detailDialog = reactive({ visible: false });
|
||||
|
||||
// 添加搜索处理函数
|
||||
const dropMenu = ref<DropMenuItemExpose>();
|
||||
const handleQuery = () => {
|
||||
queryParams.value.pageNum = 1;
|
||||
loadMore();
|
||||
dropMenu.value?.close();
|
||||
const formDialog = reactive({ visible: false });
|
||||
const initialFormData: NoticeForm = {
|
||||
id: undefined,
|
||||
title: undefined,
|
||||
content: undefined,
|
||||
type: undefined,
|
||||
level: "M",
|
||||
targetType: 1,
|
||||
targetUserIds: undefined,
|
||||
};
|
||||
const formData = reactive<NoticeForm>({ ...initialFormData });
|
||||
|
||||
// 重置
|
||||
const handleReset = () => {
|
||||
queryParams.value = { pageNum: 1, pageSize: 10 };
|
||||
dropMenu.value?.close();
|
||||
loadMore();
|
||||
const formRules: FormRules = {
|
||||
title: [{ required: true, message: "请输入通知标题" }],
|
||||
};
|
||||
|
||||
// 获取状态样式
|
||||
const getStatusType = (
|
||||
status: number | undefined
|
||||
status?: number
|
||||
): "default" | "primary" | "danger" | "warning" | "success" => {
|
||||
if (!status) return "default";
|
||||
const statusMap: Record<number, "default" | "primary" | "danger" | "warning" | "success"> = {
|
||||
const map: Record<number, "default" | "primary" | "danger" | "warning" | "success"> = {
|
||||
0: "primary",
|
||||
1: "success",
|
||||
[-1]: "warning",
|
||||
};
|
||||
return statusMap[status] || "default";
|
||||
return status !== undefined ? map[status] || "default" : "default";
|
||||
};
|
||||
|
||||
// 获取状态文本
|
||||
const getStatusText = (status: number | undefined): string => {
|
||||
if (status !== 0 && !status) return "-";
|
||||
const statusMap: Record<number, string> = {
|
||||
0: "未发布",
|
||||
1: "已发布",
|
||||
[-1]: "已撤回",
|
||||
};
|
||||
return statusMap[status] || "未知";
|
||||
const getStatusText = (status?: number): string => {
|
||||
const map: Record<number, string> = { 0: "未发布", 1: "已发布", [-1]: "已撤回" };
|
||||
return status !== undefined ? map[status] || "未知" : "-";
|
||||
};
|
||||
|
||||
// 获取级别文本
|
||||
const getLevelText = (level: string | number | undefined): string => {
|
||||
if (!level) return "-";
|
||||
const levelMap: Record<string, string> = {
|
||||
L: "低",
|
||||
M: "中",
|
||||
H: "高",
|
||||
const getLevelText = (level?: string | number): string => {
|
||||
const map: Record<string, string> = { L: "低", M: "中", H: "高" };
|
||||
return level ? map[String(level)] || String(level) : "-";
|
||||
};
|
||||
|
||||
// 格式化时间
|
||||
const formatTime = (item: NoticePageVO): string => {
|
||||
if (item.publishStatus === 1 && item.publishTime) {
|
||||
return String(item.publishTime);
|
||||
}
|
||||
if (item.publishStatus === -1 && item.revokeTime) {
|
||||
return String(item.revokeTime);
|
||||
}
|
||||
return "-";
|
||||
};
|
||||
|
||||
// 搜索触发
|
||||
const handleSearch = () => loadNoticeList();
|
||||
|
||||
// 加载列表
|
||||
function loadNoticeList() {
|
||||
queryParams.pageNum = 1;
|
||||
fetchNoticeList();
|
||||
}
|
||||
|
||||
// 分页加载列表
|
||||
function fetchNoticeList() {
|
||||
loadMoreState.value = "loading";
|
||||
NoticeAPI.getPage(queryParams)
|
||||
.then((data) => {
|
||||
pageData.value = data.list;
|
||||
total.value = data.total;
|
||||
queryParams.pageNum++;
|
||||
})
|
||||
.catch(() => {
|
||||
pageData.value = [];
|
||||
})
|
||||
.finally(() => {
|
||||
loadMoreState.value = "finished";
|
||||
});
|
||||
}
|
||||
|
||||
// 打开详情弹窗
|
||||
async function openNoticeDetail(item: NoticePageVO) {
|
||||
const detail = await NoticeAPI.getDetail(item.id);
|
||||
noticeDetail.value = detail;
|
||||
detailDialog.visible = true;
|
||||
}
|
||||
|
||||
// 关闭详情弹窗
|
||||
function closeNoticeDetail() {
|
||||
detailDialog.visible = false;
|
||||
}
|
||||
|
||||
// 打开表单弹窗
|
||||
async function openNoticeForm(id?: number) {
|
||||
formRef.value?.reset();
|
||||
Object.assign(formData, initialFormData);
|
||||
formDialog.visible = true;
|
||||
if (id) {
|
||||
formData.id = id;
|
||||
const data = await NoticeAPI.getFormData(id);
|
||||
Object.assign(formData, data, { id });
|
||||
}
|
||||
}
|
||||
|
||||
// 关闭表单弹窗
|
||||
function closeNoticeForm() {
|
||||
formDialog.visible = false;
|
||||
formRef.value?.reset();
|
||||
Object.assign(formData, initialFormData);
|
||||
}
|
||||
|
||||
// 提交表单
|
||||
function submitNoticeForm() {
|
||||
formRef.value.validate().then(({ valid }: { valid: boolean }) => {
|
||||
if (!valid) return;
|
||||
submitting.value = true;
|
||||
const id = formData.id;
|
||||
const action = id ? NoticeAPI.update(id, formData) : NoticeAPI.add(formData);
|
||||
action
|
||||
.then(() => {
|
||||
toast.success("操作成功");
|
||||
closeNoticeForm();
|
||||
loadNoticeList();
|
||||
})
|
||||
.finally(() => {
|
||||
submitting.value = false;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// 更多操作
|
||||
function showNoticeActions(item: NoticePageVO) {
|
||||
const actions: string[] = ["查看"];
|
||||
const actionMap: Record<string, () => void> = {
|
||||
查看: () => openNoticeDetail(item),
|
||||
};
|
||||
return levelMap[String(level)] || String(level);
|
||||
};
|
||||
|
||||
// 格式化日期
|
||||
const formatDate = (date: Date | undefined): string => {
|
||||
return date ? date.toString() : "-";
|
||||
};
|
||||
|
||||
// 加载更多
|
||||
const loadMore = async () => {
|
||||
if (loadState.value === "loading") return;
|
||||
|
||||
loadState.value = "loading";
|
||||
const { list, total: totalCount } = await NoticeAPI.getPage(queryParams.value);
|
||||
|
||||
if (queryParams.value.pageNum === 1) {
|
||||
dataList.value = list;
|
||||
if (item.publishStatus !== 1) {
|
||||
if (hasPermission("sys:notice:update")) {
|
||||
actions.push("编辑");
|
||||
actionMap["编辑"] = () => openNoticeForm(Number(item.id));
|
||||
}
|
||||
if (hasPermission("sys:notice:delete")) {
|
||||
actions.push("删除");
|
||||
actionMap["删除"] = async () => {
|
||||
const { confirm } = await uni.showModal({
|
||||
title: "确认删除",
|
||||
content: `确定要删除通知「${item.title}」吗?`,
|
||||
});
|
||||
if (confirm) {
|
||||
await NoticeAPI.deleteByIds(item.id);
|
||||
toast.success("删除成功");
|
||||
loadNoticeList();
|
||||
}
|
||||
};
|
||||
}
|
||||
if (hasPermission("sys:notice:publish")) {
|
||||
actions.push("发布");
|
||||
actionMap["发布"] = async () => {
|
||||
const { confirm } = await uni.showModal({
|
||||
title: "确认发布",
|
||||
content: `确定要发布通知「${item.title}」吗?`,
|
||||
});
|
||||
if (confirm) {
|
||||
await NoticeAPI.publish(Number(item.id));
|
||||
toast.success("发布成功");
|
||||
loadNoticeList();
|
||||
}
|
||||
};
|
||||
}
|
||||
} else {
|
||||
dataList.value = [...dataList.value, ...list];
|
||||
if (hasPermission("sys:notice:revoke")) {
|
||||
actions.push("撤回");
|
||||
actionMap["撤回"] = async () => {
|
||||
const { confirm } = await uni.showModal({
|
||||
title: "确认撤回",
|
||||
content: `确定要撤回通知「${item.title}」吗?`,
|
||||
});
|
||||
if (confirm) {
|
||||
await NoticeAPI.revoke(Number(item.id));
|
||||
toast.success("撤回成功");
|
||||
loadNoticeList();
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
total.value = totalCount;
|
||||
queryParams.value.pageNum++;
|
||||
|
||||
loadState.value = dataList.value.length >= total.value ? "finished" : "loading";
|
||||
};
|
||||
|
||||
// 查看详情
|
||||
const handleView = (notice: NoticePageVO) => {
|
||||
uni.navigateTo({
|
||||
url: `/pages/work/notice/detail?id=${notice.id}`,
|
||||
});
|
||||
};
|
||||
|
||||
// 操作按钮
|
||||
const handleAction = (notice: NoticePageVO) => {
|
||||
const actions = notice.publishStatus !== 1 ? ["查看", "删除", "发布"] : ["查看", "撤回"];
|
||||
uni.showActionSheet({
|
||||
itemList: actions,
|
||||
success: ({ tapIndex }) => {
|
||||
switch (actions[tapIndex]) {
|
||||
case "查看":
|
||||
handleView(notice);
|
||||
break;
|
||||
case "删除":
|
||||
handleDelete(notice);
|
||||
break;
|
||||
case "发布":
|
||||
handlePublish(notice);
|
||||
break;
|
||||
case "撤回":
|
||||
handleRevoke(notice);
|
||||
break;
|
||||
}
|
||||
const action = actions[tapIndex];
|
||||
actionMap[action]?.();
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
// 删除
|
||||
const handleDelete = (notice: NoticePageVO) => {
|
||||
uni.showModal({
|
||||
title: "提示",
|
||||
content: "确定要删除该通知吗?",
|
||||
success: async (res) => {
|
||||
if (res.confirm) {
|
||||
try {
|
||||
await NoticeAPI.deleteByIds(notice.id);
|
||||
uni.showToast({ title: "删除成功", icon: "success" });
|
||||
// 重新加载第一页
|
||||
queryParams.value.pageNum = 1;
|
||||
loadMore();
|
||||
} catch (error) {
|
||||
uni.showToast({ title: "删除失败" + error, icon: "none" });
|
||||
}
|
||||
}
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
// 发布
|
||||
const handlePublish = (notice: NoticePageVO) => {
|
||||
uni.showModal({
|
||||
title: "提示",
|
||||
content: "确定要发布该通知吗?",
|
||||
success: async (res) => {
|
||||
if (res.confirm) {
|
||||
try {
|
||||
await NoticeAPI.publish(Number(notice.id));
|
||||
uni.showToast({ title: "发布成功", icon: "success" });
|
||||
// 重新加载第一页
|
||||
queryParams.value.pageNum = 1;
|
||||
loadMore();
|
||||
} catch (error) {
|
||||
uni.showToast({ title: "发布失败" + error, icon: "none" });
|
||||
}
|
||||
}
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
// 撤回
|
||||
const handleRevoke = (notice: NoticePageVO) => {
|
||||
uni.showModal({
|
||||
title: "提示",
|
||||
content: "确定要撤回该通知吗?",
|
||||
success: async (res) => {
|
||||
if (res.confirm) {
|
||||
try {
|
||||
await NoticeAPI.revoke(Number(notice.id));
|
||||
uni.showToast({
|
||||
title: "撤回成功",
|
||||
icon: "success",
|
||||
});
|
||||
// 刷新列表
|
||||
queryParams.value.pageNum = 1;
|
||||
loadMore();
|
||||
} catch (error) {
|
||||
uni.showToast({
|
||||
title: "撤回失败" + error,
|
||||
icon: "error",
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
onReachBottom(() => {
|
||||
if (loadState.value === "loading" || loadState.value === "finished") return;
|
||||
loadMore();
|
||||
if (queryParams.pageNum * queryParams.pageSize < total.value) {
|
||||
fetchNoticeList();
|
||||
} else {
|
||||
loadMoreState.value = "finished";
|
||||
}
|
||||
});
|
||||
|
||||
onLoad(() => {
|
||||
loadMore();
|
||||
loadNoticeList();
|
||||
});
|
||||
</script>
|
||||
|
||||
<script lang="ts">
|
||||
export default { options: { styleIsolation: "shared" } };
|
||||
</script>
|
||||
|
||||
<route lang="json">
|
||||
{
|
||||
"name": "notice",
|
||||
@@ -276,30 +391,3 @@ onLoad(() => {
|
||||
}
|
||||
}
|
||||
</route>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.data-container {
|
||||
:deep(.wd-cell__wrapper) {
|
||||
padding: 4rpx 0;
|
||||
}
|
||||
|
||||
:deep(.wd-cell) {
|
||||
padding-right: 10rpx;
|
||||
background: #f8f8f8;
|
||||
}
|
||||
|
||||
:deep(.wd-fab__trigger) {
|
||||
width: 80rpx !important;
|
||||
height: 80rpx !important;
|
||||
}
|
||||
|
||||
.filter-container {
|
||||
padding: 10rpx;
|
||||
background: #fff;
|
||||
}
|
||||
|
||||
.data-container {
|
||||
margin-top: 20rpx;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,294 @@
|
||||
<template>
|
||||
<view class="page">
|
||||
<!-- 固定头部:搜索栏 + 操作栏 -->
|
||||
<view class="header">
|
||||
<view class="role-bar">
|
||||
<text class="role-bar__label">角色</text>
|
||||
<text class="role-bar__value">{{ roleName || "-" }}</text>
|
||||
</view>
|
||||
|
||||
<view class="action-bar">
|
||||
<view class="action-bar__left">
|
||||
<wd-button size="small" plain @click="handleSelectAll">全选</wd-button>
|
||||
<wd-button size="small" plain @click="handleClearAll">取消全选</wd-button>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 可滚动区域:权限树 -->
|
||||
<scroll-view class="tree-container" scroll-y>
|
||||
<custom-tree
|
||||
:data="menuTree"
|
||||
:checkable="true"
|
||||
:checked-keys="checkedKeys"
|
||||
:default-expand-all="true"
|
||||
value-key="id"
|
||||
label-key="name"
|
||||
children-key="children"
|
||||
@check="handleCheck"
|
||||
>
|
||||
<template #content="{ node, checked }">
|
||||
<view class="node-content">
|
||||
<view class="node-content__info">
|
||||
<wd-icon
|
||||
v-if="node.type === 'C'"
|
||||
name="folder"
|
||||
size="18"
|
||||
:color="checked ? 'var(--color-primary)' : 'var(--color-text-secondary)'"
|
||||
/>
|
||||
<wd-icon
|
||||
v-else-if="node.type === 'M'"
|
||||
name="menu"
|
||||
size="18"
|
||||
:color="checked ? 'var(--color-primary)' : 'var(--color-text-secondary)'"
|
||||
/>
|
||||
<wd-icon
|
||||
v-else
|
||||
name="click"
|
||||
size="16"
|
||||
:color="checked ? 'var(--color-primary)' : 'var(--color-text-secondary)'"
|
||||
/>
|
||||
<text class="node-content__label" :class="{ 'is-checked': checked }">
|
||||
{{ node.name }}
|
||||
</text>
|
||||
</view>
|
||||
<wd-tag
|
||||
v-if="node.type"
|
||||
size="small"
|
||||
:type="node.type === 'C' ? 'primary' : node.type === 'M' ? 'success' : 'warning'"
|
||||
plain
|
||||
>
|
||||
{{ node.type === "C" ? "目录" : node.type === "M" ? "菜单" : "按钮" }}
|
||||
</wd-tag>
|
||||
</view>
|
||||
</template>
|
||||
</custom-tree>
|
||||
|
||||
<wd-status-tip v-if="menuTree.length === 0" image="search" tip="暂无菜单数据" />
|
||||
</scroll-view>
|
||||
|
||||
<!-- 固定底部操作栏 -->
|
||||
<view class="bottom-bar">
|
||||
<wd-button type="info" plain @click="handleCancel">取消</wd-button>
|
||||
<wd-button type="primary" :loading="submitting" @click="handleSubmit">保存</wd-button>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { onLoad } from "@dcloudio/uni-app";
|
||||
import { useToast } from "wot-design-uni";
|
||||
import MenuAPI, { type MenuVO } from "@/api/menu";
|
||||
import RoleAPI from "@/api/role";
|
||||
import CustomTree from "@/components/custom-tree/index.vue";
|
||||
import type { TreeOption } from "@/components/custom-tree/index.vue";
|
||||
|
||||
const toast = useToast();
|
||||
const submitting = ref(false);
|
||||
const roleId = ref<number>(0);
|
||||
const roleName = ref("");
|
||||
const menuList = ref<MenuVO[]>([]);
|
||||
const checkedKeys = ref<string[]>([]);
|
||||
|
||||
// 转换菜单为树结构
|
||||
const menuTree = computed<TreeOption[]>(() => {
|
||||
if (!menuList.value.length) return [];
|
||||
return transformMenuToTree(menuList.value);
|
||||
});
|
||||
|
||||
// 转换菜单为树组件格式
|
||||
function transformMenuToTree(menus: MenuVO[]): TreeOption[] {
|
||||
return menus.map((menu) => {
|
||||
const id = String(menu.id);
|
||||
const name = menu.name ?? "";
|
||||
return {
|
||||
value: id,
|
||||
label: name,
|
||||
id,
|
||||
name,
|
||||
type: menu.type,
|
||||
children: menu.children ? transformMenuToTree(menu.children) : undefined,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
// 处理选中变化
|
||||
function handleCheck(keys: string[]) {
|
||||
checkedKeys.value = keys;
|
||||
}
|
||||
|
||||
// 全选
|
||||
function handleSelectAll() {
|
||||
const allIds = getAllMenuIds(menuList.value);
|
||||
checkedKeys.value = allIds;
|
||||
}
|
||||
|
||||
// 取消全选
|
||||
function handleClearAll() {
|
||||
checkedKeys.value = [];
|
||||
}
|
||||
|
||||
// 获取所有菜单ID
|
||||
function getAllMenuIds(menus: MenuVO[]): string[] {
|
||||
const ids: string[] = [];
|
||||
function traverse(list: MenuVO[]) {
|
||||
for (const menu of list) {
|
||||
if (menu.id) ids.push(String(menu.id));
|
||||
if (menu.children) traverse(menu.children);
|
||||
}
|
||||
}
|
||||
traverse(menus);
|
||||
return ids;
|
||||
}
|
||||
|
||||
// 取消
|
||||
function handleCancel() {
|
||||
uni.navigateBack();
|
||||
}
|
||||
|
||||
// 提交
|
||||
async function handleSubmit() {
|
||||
submitting.value = true;
|
||||
try {
|
||||
await RoleAPI.updateRoleMenus(roleId.value, checkedKeys.value.map(Number));
|
||||
toast.success("保存成功");
|
||||
uni.navigateBack();
|
||||
} finally {
|
||||
submitting.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
// 加载数据
|
||||
async function loadData() {
|
||||
try {
|
||||
// 并行加载菜单列表和角色已有权限
|
||||
const [menus, roleMenuIds, roleForm] = await Promise.all([
|
||||
MenuAPI.getList(),
|
||||
RoleAPI.getRoleMenuIds(roleId.value),
|
||||
RoleAPI.getFormData(roleId.value),
|
||||
]);
|
||||
menuList.value = menus;
|
||||
checkedKeys.value = roleMenuIds.map(String);
|
||||
roleName.value = roleForm?.name ?? "";
|
||||
} catch {
|
||||
toast.error("加载失败");
|
||||
}
|
||||
}
|
||||
|
||||
onLoad((query) => {
|
||||
if (query?.id) {
|
||||
roleId.value = Number(query.id);
|
||||
loadData();
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<script lang="ts">
|
||||
export default { options: { styleIsolation: "shared" } };
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.page {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
height: 100vh;
|
||||
background: var(--color-bg);
|
||||
}
|
||||
|
||||
.header {
|
||||
display: flex;
|
||||
flex-shrink: 0;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding: 12rpx 24rpx;
|
||||
background: var(--color-bg);
|
||||
border-bottom: 2rpx solid var(--color-border-light);
|
||||
}
|
||||
|
||||
.role-bar {
|
||||
display: flex;
|
||||
gap: 16rpx;
|
||||
align-items: center;
|
||||
|
||||
&__label {
|
||||
font-size: 24rpx;
|
||||
color: var(--color-text-secondary);
|
||||
}
|
||||
|
||||
&__value {
|
||||
flex: 1;
|
||||
overflow: hidden;
|
||||
font-size: 28rpx;
|
||||
font-weight: 600;
|
||||
color: var(--color-text);
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
}
|
||||
|
||||
.action-bar {
|
||||
&__left {
|
||||
display: flex;
|
||||
gap: 16rpx;
|
||||
}
|
||||
}
|
||||
|
||||
.tree-container {
|
||||
flex: 1;
|
||||
height: 0; // 重要:让 flex + scroll-view 生效
|
||||
background: var(--color-bg);
|
||||
}
|
||||
|
||||
.node-content {
|
||||
display: flex;
|
||||
flex: 1;
|
||||
gap: 16rpx;
|
||||
align-items: center;
|
||||
justify-content: flex-start;
|
||||
min-width: 0;
|
||||
|
||||
&__info {
|
||||
display: flex;
|
||||
gap: 16rpx;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
&__label {
|
||||
overflow: hidden;
|
||||
font-size: 28rpx;
|
||||
color: var(--color-text);
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
|
||||
&.is-checked {
|
||||
color: var(--color-primary);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.node-content :deep(.wd-tag) {
|
||||
margin-left: auto;
|
||||
}
|
||||
|
||||
.bottom-bar {
|
||||
display: flex;
|
||||
flex-shrink: 0;
|
||||
gap: 24rpx;
|
||||
padding: 24rpx;
|
||||
background: var(--color-bg);
|
||||
box-shadow: 0 -2rpx 16rpx rgba(0, 0, 0, 0.05);
|
||||
}
|
||||
|
||||
:deep(.bottom-bar .wd-button) {
|
||||
flex: 1;
|
||||
}
|
||||
</style>
|
||||
|
||||
<route lang="json">
|
||||
{
|
||||
"name": "role-assign-perm",
|
||||
"style": {
|
||||
"navigationBarTitleText": "分配权限"
|
||||
}
|
||||
}
|
||||
</route>
|
||||
+228
-296
@@ -1,309 +1,287 @@
|
||||
<template>
|
||||
<view class="role">
|
||||
<!-- 筛选 -->
|
||||
<wd-drop-menu>
|
||||
<wd-drop-menu-item ref="filterDropMenu" icon="filter" icon-size="18px" title="筛选">
|
||||
<view>
|
||||
<wd-input
|
||||
v-model="queryParams.keywords"
|
||||
label="关键字"
|
||||
type="text"
|
||||
placeholder="请输入关键字"
|
||||
/>
|
||||
<view class="flex-between py-2">
|
||||
<wd-button custom-class="w-20%" type="info" @click="handleResetQuery">重置</wd-button>
|
||||
<wd-button custom-class="w-70%" @click="handleQuery">确定</wd-button>
|
||||
<view class="page page--padding page--pt">
|
||||
<view>
|
||||
<wd-search
|
||||
v-model="queryParams.keywords"
|
||||
placeholder="搜索角色名称/编码"
|
||||
hide-cancel
|
||||
@search="handleSearch"
|
||||
/>
|
||||
</view>
|
||||
|
||||
<!-- 角色列表 -->
|
||||
<view class="mt-16rpx">
|
||||
<wd-card
|
||||
v-for="item in pageData"
|
||||
:key="item.id"
|
||||
custom-class="item-card"
|
||||
@click="openRoleDialog(item.id)"
|
||||
>
|
||||
<!-- 主信息行 -->
|
||||
<view class="flex-start">
|
||||
<view class="flex-1">
|
||||
<view class="flex-start mt-12rpx">
|
||||
<text class="font-bold text-32rpx">{{ item.name }}</text>
|
||||
</view>
|
||||
<text class="text-24rpx color-text-secondary">{{ item.code }}</text>
|
||||
</view>
|
||||
<wd-tag :type="item.status === 1 ? 'success' : 'danger'" plain>
|
||||
{{ item.status === 1 ? "正常" : "禁用" }}
|
||||
</wd-tag>
|
||||
</view>
|
||||
|
||||
<!-- 辅助信息行 -->
|
||||
<view class="flex gap-24rpx mt-12rpx">
|
||||
<view class="flex-start min-w-0">
|
||||
<wd-icon name="view" size="16" class="color-text-secondary" />
|
||||
<text class="ml-8rpx text-24rpx color-text-secondary">{{ item.dataScopeLabel }}</text>
|
||||
</view>
|
||||
<view class="flex-start min-w-0">
|
||||
<wd-icon name="sort" size="16" class="color-text-secondary" />
|
||||
<text class="ml-8rpx text-24rpx color-text-secondary">排序: {{ item.sort }}</text>
|
||||
</view>
|
||||
</view>
|
||||
</wd-drop-menu-item>
|
||||
</wd-drop-menu>
|
||||
<!-- 卡片列表 -->
|
||||
<view class="list-container">
|
||||
<wd-card v-for="item in dataList" :key="item.id" class="role-card">
|
||||
<template #title>
|
||||
<view class="flex-between">
|
||||
<view class="flex-center">
|
||||
<view class="ml-2">
|
||||
<view class="font-bold">
|
||||
{{ item.name }}
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<view>
|
||||
<wd-tag v-if="item.status === 1" type="success" plain>正常</wd-tag>
|
||||
<wd-tag v-else-if="item.status === 0" plain>停用</wd-tag>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<wd-cell-group>
|
||||
<wd-cell title="编码" title-width="150rpx" :value="item.code" />
|
||||
<wd-cell title="排序号" title-width="150rpx" :value="item.sort" />
|
||||
</wd-cell-group>
|
||||
|
||||
<template #footer>
|
||||
<view class="flex-between">
|
||||
<view class="text-left">
|
||||
<wd-text text="创建时间:" size="small" class="font-bold" />
|
||||
<wd-text :text="item.createTime" size="small" />
|
||||
</view>
|
||||
<view class="flex-right">
|
||||
<wd-button size="small" plain @click="handleAction(item)">操作</wd-button>
|
||||
</view>
|
||||
<!-- 元信息行 -->
|
||||
<view class="flex-between mt-16rpx">
|
||||
<text class="text-24rpx color-text-placeholder">{{ item.createTime }}</text>
|
||||
<view
|
||||
class="w-88rpx h-88rpx flex-center rounded-full"
|
||||
hover-class="bg-[var(--color-text-placeholder)]/16"
|
||||
@click.stop="showRoleActions(item)"
|
||||
>
|
||||
<wd-icon name="more" size="18" class="color-text-secondary" />
|
||||
</view>
|
||||
</template>
|
||||
</view>
|
||||
</wd-card>
|
||||
|
||||
<!-- 加载更多 -->
|
||||
<wd-loadmore :state="loadMoreState" @reload="queryPageData" />
|
||||
<wd-loadmore v-if="total > 0" :state="loadMoreState" @reload="fetchRoleList" />
|
||||
<wd-status-tip v-else-if="total === 0" image="search" tip="暂无数据" />
|
||||
</view>
|
||||
<!-- 底部按钮 -->
|
||||
<wd-fab
|
||||
position="left-bottom"
|
||||
:expandable="false"
|
||||
customStyle="width: 1rem; height: 1rem; line-height: 1rem;z-index:9"
|
||||
@click="handleOpenDialog()"
|
||||
/>
|
||||
|
||||
<wd-popup v-model="dialog.visible" position="bottom" custom-class="yl_popup">
|
||||
<wd-form ref="roleFormRef" :model="formData" :rules="rules">
|
||||
<wd-cell-group border>
|
||||
<wd-input v-model="formData.name" label="角色名称" prop="name" />
|
||||
<wd-input v-model="formData.code" label="角色编码" prop="code" />
|
||||
<wd-select-picker
|
||||
v-model="formData.dataScope"
|
||||
type="radio"
|
||||
label="数据权限"
|
||||
:columns="dataScopeOptions"
|
||||
:align-right="true"
|
||||
prop="dataScope"
|
||||
/>
|
||||
<wd-cell title="状态" prop="status">
|
||||
<wd-switch v-model="formData.status" :active-value="1" :inactive-value="0" />
|
||||
</wd-cell>
|
||||
<wd-cell title="排序" prop="sort">
|
||||
<wd-input-number v-model="formData.sort" />
|
||||
</wd-cell>
|
||||
</wd-cell-group>
|
||||
</wd-form>
|
||||
<view class="footer">
|
||||
<wd-button type="primary" block @click="handleSubmit">提交</wd-button>
|
||||
<!-- 弹窗表单 -->
|
||||
<wd-popup
|
||||
v-model="dialog.visible"
|
||||
position="bottom"
|
||||
custom-style="border-radius: 24rpx 24rpx 0 0"
|
||||
@close="closeRoleDialog"
|
||||
>
|
||||
<view class="p-4">
|
||||
<view class="text-center font-bold text-32rpx mb-4">
|
||||
{{ formData.id ? "编辑角色" : "新增角色" }}
|
||||
</view>
|
||||
<wd-form ref="formRef" :model="formData" :rules="rules">
|
||||
<wd-cell-group border>
|
||||
<wd-input v-model="formData.name" label="角色名称" required />
|
||||
<wd-input v-model="formData.code" label="角色编码" required />
|
||||
<wd-select-picker
|
||||
v-model="formData.dataScope"
|
||||
label="数据权限"
|
||||
:columns="dataScopeOptions"
|
||||
required
|
||||
/>
|
||||
<wd-cell title="状态">
|
||||
<wd-switch v-model="formData.status" :active-value="1" :inactive-value="0" />
|
||||
</wd-cell>
|
||||
<wd-cell title="排序">
|
||||
<wd-input-number v-model="formData.sort" :min="0" />
|
||||
</wd-cell>
|
||||
</wd-cell-group>
|
||||
</wd-form>
|
||||
<view class="popup-actions">
|
||||
<wd-button type="info" plain @click="closeRoleDialog">取消</wd-button>
|
||||
<wd-button type="primary" :loading="submitting" @click="submitRoleForm">保存</wd-button>
|
||||
</view>
|
||||
</view>
|
||||
</wd-popup>
|
||||
<wd-message-box />
|
||||
|
||||
<!-- 浮动新增按钮 -->
|
||||
<view
|
||||
v-if="hasPermission('sys:role:create') && !dialog.visible"
|
||||
class="fab-add"
|
||||
hover-class="fab-add:active"
|
||||
@click.stop="openRoleDialog()"
|
||||
>
|
||||
<wd-icon name="add" size="44rpx" />
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import RoleAPI, { RolePageVO, RolePageQuery, RoleForm } from "@/api/role";
|
||||
import { useUserStore } from "@/store";
|
||||
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();
|
||||
import { useToast } from "wot-design-uni";
|
||||
import RoleAPI, { type RolePageQuery, RolePageVO, RoleForm } from "@/api/role";
|
||||
import { hasPermission } from "@/utils/permission";
|
||||
|
||||
const toast = useToast();
|
||||
const loadMoreState = ref<LoadMoreState>("loading");
|
||||
const formRef = ref();
|
||||
const submitting = ref(false);
|
||||
|
||||
const queryParams = reactive<RolePageQuery>({ pageNum: 1, pageSize: 10, keywords: "" });
|
||||
const total = ref(0);
|
||||
const pageData = ref<RolePageVO[]>([]);
|
||||
const dialog = reactive({ visible: false });
|
||||
|
||||
const queryParams = reactive<RolePageQuery>({
|
||||
pageNum: 1,
|
||||
pageSize: 10,
|
||||
});
|
||||
|
||||
/**
|
||||
* 搜索栏
|
||||
*/
|
||||
const filterDropMenu = ref<DropMenuItemExpose>();
|
||||
|
||||
function handleQuery() {
|
||||
filterDropMenu.value?.close();
|
||||
queryParams.pageNum = 1;
|
||||
dataList.value = [];
|
||||
queryPageData();
|
||||
}
|
||||
/**
|
||||
* 重置查询
|
||||
*/
|
||||
const handleResetQuery = () => {
|
||||
filterDropMenu.value?.close();
|
||||
queryParams.keywords = "";
|
||||
queryParams.pageNum = 1;
|
||||
dataList.value = [];
|
||||
queryPageData();
|
||||
const initialFormData: RoleForm = {
|
||||
id: undefined,
|
||||
name: undefined,
|
||||
code: undefined,
|
||||
dataScope: 1,
|
||||
status: 1,
|
||||
sort: 1,
|
||||
};
|
||||
|
||||
// 角色列表数据
|
||||
const dataList = ref<RolePageVO[]>([]);
|
||||
const formData = reactive<RoleForm>({ ...initialFormData });
|
||||
|
||||
/**
|
||||
* 查询分页数据
|
||||
*/
|
||||
function queryPageData() {
|
||||
const dataScopeOptions = ref<Record<string, any>[]>([
|
||||
{ label: "全部数据", value: 1 },
|
||||
{ label: "部门及子部门数据", value: 2 },
|
||||
{ label: "本部门数据", value: 3 },
|
||||
{ label: "本人数据", value: 4 },
|
||||
{ label: "自定义部门数据", value: 5 },
|
||||
]);
|
||||
|
||||
const rules: FormRules = {
|
||||
name: [{ required: true, message: "请输入角色名称" }],
|
||||
code: [{ required: true, message: "请输入角色编码" }],
|
||||
dataScope: [{ required: true, message: "请选择数据权限" }],
|
||||
};
|
||||
|
||||
// 搜索触发
|
||||
const handleSearch = () => loadRoleList();
|
||||
|
||||
// 加载列表
|
||||
function loadRoleList() {
|
||||
queryParams.pageNum = 1;
|
||||
fetchRoleList();
|
||||
}
|
||||
|
||||
// 分页加载列表
|
||||
function fetchRoleList() {
|
||||
loadMoreState.value = "loading";
|
||||
RoleAPI.getPage(queryParams)
|
||||
.then((data) => {
|
||||
dataList.value?.push(...data.list);
|
||||
pageData.value = data.list;
|
||||
total.value = data.total;
|
||||
queryParams.pageNum++;
|
||||
})
|
||||
.catch((e) => {
|
||||
console.log("系统异常", e);
|
||||
.catch(() => {
|
||||
pageData.value = [];
|
||||
})
|
||||
.finally(() => {
|
||||
loadMoreState.value = "finished";
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 触底事件
|
||||
*/
|
||||
onReachBottom(() => {
|
||||
if (queryParams.pageNum * queryParams.pageSize < total.value) {
|
||||
queryParams.pageNum++;
|
||||
queryPageData();
|
||||
} else {
|
||||
loadMoreState.value = "finished";
|
||||
// 打开弹窗(新增/编辑)
|
||||
async function openRoleDialog(id?: number) {
|
||||
formRef.value?.reset();
|
||||
Object.assign(formData, initialFormData);
|
||||
dialog.visible = true;
|
||||
if (id) {
|
||||
formData.id = id;
|
||||
const data = await RoleAPI.getFormData(id);
|
||||
Object.assign(formData, data, { id });
|
||||
}
|
||||
}
|
||||
|
||||
// 提交表单
|
||||
function submitRoleForm() {
|
||||
formRef.value.validate().then(({ valid }: { valid: boolean }) => {
|
||||
if (!valid) return;
|
||||
submitting.value = true;
|
||||
const action = formData.id ? RoleAPI.update(formData.id, formData) : RoleAPI.add(formData);
|
||||
action
|
||||
.then(() => {
|
||||
toast.success("操作成功");
|
||||
closeRoleDialog();
|
||||
loadRoleList();
|
||||
})
|
||||
.finally(() => {
|
||||
submitting.value = false;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// 关闭弹窗
|
||||
function closeRoleDialog() {
|
||||
dialog.visible = false;
|
||||
formRef.value?.reset();
|
||||
Object.assign(formData, initialFormData);
|
||||
}
|
||||
|
||||
// 更多操作
|
||||
function showRoleActions(item: RolePageVO) {
|
||||
const actions: string[] = [];
|
||||
const actionMap: Record<string, () => void> = {};
|
||||
|
||||
// 编辑
|
||||
if (hasPermission("sys:role:update")) {
|
||||
actions.push("编辑");
|
||||
actionMap["编辑"] = () => openRoleDialog(item.id);
|
||||
}
|
||||
|
||||
// 分配权限
|
||||
if (hasPermission("sys:role:assign")) {
|
||||
actions.push("分配权限");
|
||||
actionMap["分配权限"] = () => handleAssignPerm(item.id);
|
||||
}
|
||||
|
||||
// 删除
|
||||
if (hasPermission("sys:role:delete")) {
|
||||
actions.push("删除");
|
||||
actionMap["删除"] = async () => {
|
||||
const { confirm } = await uni.showModal({
|
||||
title: "确认删除",
|
||||
content: `确定要删除角色「${item.name}」吗?`,
|
||||
});
|
||||
if (confirm) {
|
||||
await RoleAPI.deleteByIds(String(item.id));
|
||||
toast.success("删除成功");
|
||||
loadRoleList();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
if (actions.length === 0) {
|
||||
toast.warning("暂无操作权限");
|
||||
return;
|
||||
}
|
||||
});
|
||||
|
||||
// 操作按钮
|
||||
const handleAction = (item: RolePageVO) => {
|
||||
const { roles = [], perms = [] } = useUserStore().userInfo || {};
|
||||
const canAssignPerm = roles.includes("ROOT") || perms.includes("sys:role:assign");
|
||||
const actions = canAssignPerm ? ["编辑", "分配权限", "删除"] : ["编辑", "删除"];
|
||||
uni.showActionSheet({
|
||||
itemList: actions,
|
||||
success: ({ tapIndex }) => {
|
||||
switch (actions[tapIndex]) {
|
||||
case "编辑":
|
||||
handleOpenDialog(item.id);
|
||||
break;
|
||||
case "分配权限":
|
||||
handleAssignPerm(item.id);
|
||||
break;
|
||||
case "删除":
|
||||
handleDelete(item.id);
|
||||
break;
|
||||
}
|
||||
const action = actions[tapIndex];
|
||||
actionMap[action]?.();
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
const dialog = reactive({
|
||||
visible: false,
|
||||
});
|
||||
|
||||
const dataScopeOptions = ref<Record<string, any>[]>([
|
||||
{ label: "全部数据", value: 0 },
|
||||
{ label: "部门及子部门数据", value: 1 },
|
||||
{ label: "本部门数据", value: 2 },
|
||||
{ label: "本人数据", value: 3 },
|
||||
]);
|
||||
|
||||
const formData = reactive<RoleForm>({
|
||||
dataScope: 0,
|
||||
sort: 1,
|
||||
});
|
||||
|
||||
const rules: FormRules = {
|
||||
name: [{ required: true, message: "请输入角色名称", trigger: "blur" }],
|
||||
code: [{ required: true, message: "请输入角色编码", trigger: "blur" }],
|
||||
dataScope: [{ required: true, message: "请选择数据权限", trigger: "blur" }],
|
||||
status: [{ required: true, message: "请选择状态", trigger: "change" }],
|
||||
sort: [{ required: true, message: "请输入排序号", trigger: "change" }],
|
||||
};
|
||||
|
||||
const roleFormRef = ref<FormInstance>();
|
||||
|
||||
/**
|
||||
* 打开弹窗
|
||||
*/
|
||||
async function handleOpenDialog(id?: number) {
|
||||
dialog.visible = true;
|
||||
formData.id = undefined;
|
||||
formData.name = "";
|
||||
formData.code = "";
|
||||
formData.dataScope = 0;
|
||||
formData.status = 1;
|
||||
formData.sort = 1;
|
||||
if (id) {
|
||||
RoleAPI.getFormData(id).then((data) => {
|
||||
Object.assign(formData, { ...data });
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 提交保存
|
||||
*/
|
||||
function handleSubmit() {
|
||||
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();
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*
|
||||
* @param id 用户id
|
||||
*/
|
||||
function handleDelete(id: number) {
|
||||
message
|
||||
.confirm({
|
||||
msg: "确认删除角色吗?",
|
||||
title: "提示",
|
||||
})
|
||||
.then(() => {
|
||||
RoleAPI.deleteByIds(id + "").then(() => {
|
||||
uni.showToast({ title: "删除成功", icon: "success" });
|
||||
queryParams.pageNum = 1;
|
||||
handleQuery();
|
||||
});
|
||||
})
|
||||
.catch(() => {
|
||||
console.log("点击了取消按钮");
|
||||
});
|
||||
}
|
||||
|
||||
// 分配权限
|
||||
function handleAssignPerm(id: number) {
|
||||
uni.navigateTo({
|
||||
url: "/pages/work/role/assign-perm?id=" + id,
|
||||
});
|
||||
}
|
||||
|
||||
onReachBottom(() => {
|
||||
if (queryParams.pageNum * queryParams.pageSize < total.value) {
|
||||
fetchRoleList();
|
||||
} else {
|
||||
loadMoreState.value = "finished";
|
||||
}
|
||||
});
|
||||
|
||||
onLoad(() => {
|
||||
handleQuery();
|
||||
loadRoleList();
|
||||
});
|
||||
</script>
|
||||
|
||||
<script lang="ts">
|
||||
// https://wot-design-uni.pages.dev/guide/common-problems#%E5%B0%8F%E7%A8%8B%E5%BA%8F%E6%A0%B7%E5%BC%8F%E9%9A%94%E7%A6%BB
|
||||
export default {
|
||||
options: {
|
||||
styleIsolation: "shared",
|
||||
},
|
||||
};
|
||||
export default { options: { styleIsolation: "shared" } };
|
||||
</script>
|
||||
|
||||
<route lang="json">
|
||||
@@ -314,49 +292,3 @@ export default {
|
||||
}
|
||||
}
|
||||
</route>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.role {
|
||||
:deep(.wd-drop-menu .wd-drop-menu__item) {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
padding: 0 50rpx;
|
||||
}
|
||||
.list-container {
|
||||
.role-card {
|
||||
margin-top: 20rpx;
|
||||
:deep(.wd-cell__wrapper) {
|
||||
padding: 4rpx 0;
|
||||
}
|
||||
:deep(.wd-cell) {
|
||||
padding-right: 10rpx;
|
||||
background: #f8f8f8;
|
||||
}
|
||||
}
|
||||
}
|
||||
:deep(.wd-cell__wrapper) {
|
||||
padding: 4rpx 0;
|
||||
}
|
||||
|
||||
:deep(.wd-cell) {
|
||||
padding-right: 10rpx;
|
||||
background: #f8f8f8;
|
||||
}
|
||||
|
||||
:deep(.wd-fab__trigger) {
|
||||
width: 80rpx !important;
|
||||
height: 80rpx !important;
|
||||
}
|
||||
.yl_popup {
|
||||
.footer {
|
||||
margin: 30rpx 0;
|
||||
}
|
||||
}
|
||||
:deep(.w-20per) {
|
||||
width: 20%;
|
||||
}
|
||||
:deep(.w-70per) {
|
||||
width: 70%;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -157,17 +157,14 @@
|
||||
</wd-popup>
|
||||
|
||||
<!-- 浮动新增按钮 -->
|
||||
<wd-fab
|
||||
<view
|
||||
v-if="hasPermission('sys:user:create') && !dialog.visible"
|
||||
position="right-bottom"
|
||||
:expandable="false"
|
||||
class="fab-add"
|
||||
hover-class="fab-add:active"
|
||||
@click.stop="openUserDialog()"
|
||||
>
|
||||
<template #trigger>
|
||||
<wd-button custom-class="fab-btn" type="primary" round @click="openUserDialog()">
|
||||
<wd-icon name="add" />
|
||||
</wd-button>
|
||||
</template>
|
||||
</wd-fab>
|
||||
<wd-icon name="add" size="44rpx" />
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
@@ -216,7 +213,7 @@ const deptOptions = ref<OptionType[]>([]);
|
||||
|
||||
// 部门多列选择器数据
|
||||
const deptSelected = ref<(string | number)[]>([]);
|
||||
const deptColumns = ref<Record<string, any>[]>([]);
|
||||
const deptColumns = ref<Record<string, any>[][]>([]);
|
||||
|
||||
// 格式化部门展示
|
||||
const displayDeptFormat = (selectedItems: Record<string, any>[]) => {
|
||||
|
||||
Reference in new issue
Block a user