fix: 根据IDE的建议,调整definePage 宏导入顺序,放在import后面
This commit is contained in:
1 parent
094864b73b
commit
eae3a0c6d4
22 files changed
+2902
-3236
No files matched your search
+143
-174
@@ -1,28 +1,15 @@
|
||||
<template>
|
||||
<view class="page page--padding">
|
||||
<view>
|
||||
<wd-search
|
||||
v-model="queryParams.keywords"
|
||||
placeholder="搜索配置名称/键名"
|
||||
hide-cancel
|
||||
@search="handleSearch"
|
||||
/>
|
||||
<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)"
|
||||
>
|
||||
<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)"
|
||||
>
|
||||
<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>
|
||||
@@ -41,12 +28,7 @@
|
||||
</view>
|
||||
|
||||
<!-- 弹窗表单 -->
|
||||
<wd-popup
|
||||
v-model="dialog.visible"
|
||||
position="bottom"
|
||||
custom-class="popup-bottom"
|
||||
@close="closeConfigDialog"
|
||||
>
|
||||
<wd-popup v-model="dialog.visible" position="bottom" custom-class="popup-bottom" @close="closeConfigDialog">
|
||||
<view class="p-4">
|
||||
<view class="popup-title">
|
||||
{{ formData.id ? "编辑配置" : "新增配置" }}
|
||||
@@ -62,12 +44,7 @@
|
||||
<wd-input v-model="formData.configValue" placeholder="请输入配置键值" />
|
||||
</wd-form-item>
|
||||
<wd-form-item prop="remark" title="描述">
|
||||
<wd-textarea
|
||||
v-model="formData.remark"
|
||||
placeholder="请输入配置描述"
|
||||
:maxlength="100"
|
||||
show-word-limit
|
||||
/>
|
||||
<wd-textarea v-model="formData.remark" placeholder="请输入配置描述" :maxlength="100" show-word-limit />
|
||||
</wd-form-item>
|
||||
</wd-form>
|
||||
<view class="popup-actions">
|
||||
@@ -80,186 +57,178 @@
|
||||
</wd-popup>
|
||||
|
||||
<!-- 浮动新增按钮 -->
|
||||
<wd-fab
|
||||
v-if="hasPermission('sys:config:create') && !dialog.visible"
|
||||
:expandable="false"
|
||||
:gap="{ bottom: 32 }"
|
||||
@click="openConfigDialog()"
|
||||
/>
|
||||
<wd-fab v-if="hasPermission('sys:config:create') && !dialog.visible" :expandable="false" :gap="{ bottom: 32 }"
|
||||
@click="openConfigDialog()" />
|
||||
|
||||
<!-- 操作菜单 -->
|
||||
<wd-action-sheet
|
||||
v-model="actionSheetVisible"
|
||||
:actions="actionSheetActions"
|
||||
cancel-text="取消"
|
||||
@select="handleActionSelect"
|
||||
/>
|
||||
<wd-action-sheet v-model="actionSheetVisible" :actions="actionSheetActions" cancel-text="取消" @select="handleActionSelect" />
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
definePage({
|
||||
name: "config",
|
||||
style: { navigationBarTitleText: "系统配置" },
|
||||
});
|
||||
|
||||
import { onLoad, onReachBottom } from "@dcloudio/uni-app";
|
||||
import { LoadMoreState } from "@wot-ui/ui/components/wd-loadmore/types";
|
||||
import { toFormSchema } from "@/utils/form";
|
||||
import { useToast, useDialog } from "@wot-ui/ui";
|
||||
import ConfigAPI, { type ConfigPageQuery, ConfigItem, ConfigForm } from "@/api/config";
|
||||
import { hasPermission } from "@/utils/permission";
|
||||
import { onLoad, onReachBottom } from "@dcloudio/uni-app";
|
||||
import { LoadMoreState } from "@wot-ui/ui/components/wd-loadmore/types";
|
||||
import { toFormSchema } from "@/utils/form";
|
||||
import { useToast, useDialog } from "@wot-ui/ui";
|
||||
import ConfigAPI, { type ConfigPageQuery, ConfigItem, ConfigForm } from "@/api/config";
|
||||
import { hasPermission } from "@/utils/permission";
|
||||
|
||||
const toast = useToast();
|
||||
definePage({
|
||||
name: "config",
|
||||
style: { navigationBarTitleText: "系统配置" },
|
||||
});
|
||||
|
||||
|
||||
const toast = useToast();
|
||||
const { confirm } = useDialog();
|
||||
const loadMoreState = ref<LoadMoreState>("loading");
|
||||
const formRef = ref();
|
||||
const isSubmitting = ref(false);
|
||||
const loadMoreState = ref<LoadMoreState>("loading");
|
||||
const formRef = ref();
|
||||
const isSubmitting = ref(false);
|
||||
|
||||
const queryParams = reactive<ConfigPageQuery>({ pageNum: 1, pageSize: 10, keywords: "" });
|
||||
const total = ref(0);
|
||||
const pageData = ref<ConfigItem[]>([]);
|
||||
const dialog = reactive({ visible: false });
|
||||
const queryParams = reactive<ConfigPageQuery>({ pageNum: 1, pageSize: 10, keywords: "" });
|
||||
const total = ref(0);
|
||||
const pageData = ref<ConfigItem[]>([]);
|
||||
const dialog = reactive({ visible: false });
|
||||
|
||||
const actionSheetVisible = ref(false);
|
||||
const actionSheetActions = ref<{ name: string; color?: string }[]>([]);
|
||||
const currentActionItem = ref<any>(null);
|
||||
const actionSheetVisible = ref(false);
|
||||
const actionSheetActions = ref<{ name: string; color?: string }[]>([]);
|
||||
const currentActionItem = ref<any>(null);
|
||||
|
||||
const initialFormData: ConfigForm = {
|
||||
id: undefined,
|
||||
configName: undefined,
|
||||
configKey: undefined,
|
||||
configValue: undefined,
|
||||
remark: undefined,
|
||||
};
|
||||
const initialFormData: ConfigForm = {
|
||||
id: undefined,
|
||||
configName: undefined,
|
||||
configKey: undefined,
|
||||
configValue: undefined,
|
||||
remark: undefined,
|
||||
};
|
||||
|
||||
const formData = reactive<ConfigForm>({ ...initialFormData });
|
||||
const formData = reactive<ConfigForm>({ ...initialFormData });
|
||||
|
||||
const rules = toFormSchema({
|
||||
configName: [{ required: true, message: "请输入配置名称" }],
|
||||
configKey: [{ required: true, message: "请输入配置键名" }],
|
||||
configValue: [{ required: true, message: "请输入配置键值" }],
|
||||
});
|
||||
const rules = toFormSchema({
|
||||
configName: [{ required: true, message: "请输入配置名称" }],
|
||||
configKey: [{ required: true, message: "请输入配置键名" }],
|
||||
configValue: [{ required: true, message: "请输入配置键值" }],
|
||||
});
|
||||
|
||||
// 搜索触发
|
||||
const handleSearch = () => loadConfigList();
|
||||
// 搜索触发
|
||||
const handleSearch = () => loadConfigList();
|
||||
|
||||
// 加载列表
|
||||
function loadConfigList() {
|
||||
queryParams.pageNum = 1;
|
||||
fetchConfigList();
|
||||
}
|
||||
|
||||
// 分页加载列表
|
||||
function fetchConfigList() {
|
||||
loadMoreState.value = "loading";
|
||||
ConfigAPI.getPage(queryParams)
|
||||
.then((data: any) => {
|
||||
pageData.value = data.list;
|
||||
total.value = data.total;
|
||||
queryParams.pageNum++;
|
||||
})
|
||||
.catch(() => {
|
||||
pageData.value = [];
|
||||
})
|
||||
.finally(() => {
|
||||
loadMoreState.value = "finished";
|
||||
});
|
||||
}
|
||||
|
||||
// 打开弹窗(新增/编辑)
|
||||
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 loadConfigList() {
|
||||
queryParams.pageNum = 1;
|
||||
fetchConfigList();
|
||||
}
|
||||
}
|
||||
|
||||
// 提交表单
|
||||
function submitConfigForm() {
|
||||
formRef.value.validate().then(({ valid }: { valid: boolean }) => {
|
||||
if (!valid) return;
|
||||
isSubmitting.value = true;
|
||||
const action = formData.id ? ConfigAPI.update(formData.id, formData) : ConfigAPI.add(formData);
|
||||
action
|
||||
.then(() => {
|
||||
toast.success("操作成功");
|
||||
closeConfigDialog();
|
||||
loadConfigList();
|
||||
// 分页加载列表
|
||||
function fetchConfigList() {
|
||||
loadMoreState.value = "loading";
|
||||
ConfigAPI.getPage(queryParams)
|
||||
.then((data: any) => {
|
||||
pageData.value = data.list;
|
||||
total.value = data.total;
|
||||
queryParams.pageNum++;
|
||||
})
|
||||
.catch(() => {
|
||||
pageData.value = [];
|
||||
})
|
||||
.finally(() => {
|
||||
isSubmitting.value = false;
|
||||
loadMoreState.value = "finished";
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// 关闭弹窗
|
||||
function closeConfigDialog() {
|
||||
dialog.visible = false;
|
||||
formRef.value?.reset();
|
||||
Object.assign(formData, initialFormData);
|
||||
}
|
||||
// 打开弹窗(新增/编辑)
|
||||
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 handleActionSelect({ item }: { item: any }) {
|
||||
const value = item.name;
|
||||
const configItem = currentActionItem.value;
|
||||
if (value === "编辑") {
|
||||
openConfigDialog(configItem.id);
|
||||
} else if (value === "删除") {
|
||||
confirm({
|
||||
title: "确认删除",
|
||||
msg: `确定要删除配置「${configItem.configName}」吗?`,
|
||||
headerImage: "warning",
|
||||
}).then(async () => {
|
||||
await ConfigAPI.deleteById(configItem.id!);
|
||||
toast.success("删除成功");
|
||||
loadConfigList();
|
||||
// 提交表单
|
||||
function submitConfigForm() {
|
||||
formRef.value.validate().then(({ valid }: { valid: boolean }) => {
|
||||
if (!valid) return;
|
||||
isSubmitting.value = true;
|
||||
const action = formData.id ? ConfigAPI.update(formData.id, formData) : ConfigAPI.add(formData);
|
||||
action
|
||||
.then(() => {
|
||||
toast.success("操作成功");
|
||||
closeConfigDialog();
|
||||
loadConfigList();
|
||||
})
|
||||
.finally(() => {
|
||||
isSubmitting.value = false;
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// 更多操作
|
||||
function showConfigActions(item: ConfigItem) {
|
||||
const actions: { name: string; color?: string }[] = [];
|
||||
|
||||
if (hasPermission("sys:config:update")) {
|
||||
actions.push({ name: "编辑" });
|
||||
// 关闭弹窗
|
||||
function closeConfigDialog() {
|
||||
dialog.visible = false;
|
||||
formRef.value?.reset();
|
||||
Object.assign(formData, initialFormData);
|
||||
}
|
||||
|
||||
if (hasPermission("sys:config:delete")) {
|
||||
actions.push({ name: "删除", color: "var(--color-danger)" });
|
||||
// 操作菜单分发
|
||||
function handleActionSelect({ item }: { item: any }) {
|
||||
const value = item.name;
|
||||
const configItem = currentActionItem.value;
|
||||
if (value === "编辑") {
|
||||
openConfigDialog(configItem.id);
|
||||
} else if (value === "删除") {
|
||||
confirm({
|
||||
title: "确认删除",
|
||||
msg: `确定要删除配置「${configItem.configName}」吗?`,
|
||||
headerImage: "warning",
|
||||
}).then(async () => {
|
||||
await ConfigAPI.deleteById(configItem.id!);
|
||||
toast.success("删除成功");
|
||||
loadConfigList();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (actions.length === 0) {
|
||||
toast.warning("暂无操作权限");
|
||||
return;
|
||||
// 更多操作
|
||||
function showConfigActions(item: ConfigItem) {
|
||||
const actions: { name: string; color?: string }[] = [];
|
||||
|
||||
if (hasPermission("sys:config:update")) {
|
||||
actions.push({ name: "编辑" });
|
||||
}
|
||||
|
||||
if (hasPermission("sys:config:delete")) {
|
||||
actions.push({ name: "删除", color: "var(--color-danger)" });
|
||||
}
|
||||
|
||||
if (actions.length === 0) {
|
||||
toast.warning("暂无操作权限");
|
||||
return;
|
||||
}
|
||||
|
||||
currentActionItem.value = item;
|
||||
actionSheetActions.value = actions;
|
||||
actionSheetVisible.value = true;
|
||||
}
|
||||
|
||||
currentActionItem.value = item;
|
||||
actionSheetActions.value = actions;
|
||||
actionSheetVisible.value = true;
|
||||
}
|
||||
onReachBottom(() => {
|
||||
if (queryParams.pageNum * queryParams.pageSize < total.value) {
|
||||
fetchConfigList();
|
||||
} else {
|
||||
loadMoreState.value = "finished";
|
||||
}
|
||||
});
|
||||
|
||||
onReachBottom(() => {
|
||||
if (queryParams.pageNum * queryParams.pageSize < total.value) {
|
||||
fetchConfigList();
|
||||
} else {
|
||||
loadMoreState.value = "finished";
|
||||
}
|
||||
});
|
||||
|
||||
onLoad(() => {
|
||||
loadConfigList();
|
||||
});
|
||||
onLoad(() => {
|
||||
loadConfigList();
|
||||
});
|
||||
</script>
|
||||
|
||||
<script lang="ts">
|
||||
export default { options: { styleIsolation: "shared" } };
|
||||
export default { options: { styleIsolation: "shared" } };
|
||||
</script>
|
||||
|
||||
|
||||
@@ -87,10 +87,6 @@
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
definePage({
|
||||
name: "dept",
|
||||
style: { navigationBarTitleText: "部门管理" },
|
||||
});
|
||||
|
||||
import { onLoad } from "@dcloudio/uni-app";
|
||||
import { toFormSchema } from "@/utils/form";
|
||||
@@ -99,6 +95,12 @@ import DeptAPI, { type DeptQuery, DeptItem, DeptForm } from "@/api/dept";
|
||||
import { hasPermission } from "@/utils/permission";
|
||||
import CustomTree from "@/components/custom-tree/index.vue";
|
||||
|
||||
definePage({
|
||||
name: "dept",
|
||||
style: { navigationBarTitleText: "部门管理" },
|
||||
});
|
||||
|
||||
|
||||
const toast = useToast();
|
||||
const { confirm } = useDialog();
|
||||
const formRef = ref();
|
||||
|
||||
+158
-185
@@ -1,21 +1,11 @@
|
||||
<template>
|
||||
<view class="page page--padding">
|
||||
<view>
|
||||
<wd-search
|
||||
v-model="queryParams.keywords"
|
||||
placeholder="搜索字典名称/编码"
|
||||
hide-cancel
|
||||
@search="handleSearch"
|
||||
/>
|
||||
<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)"
|
||||
>
|
||||
<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">
|
||||
@@ -30,11 +20,8 @@
|
||||
|
||||
<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)"
|
||||
>
|
||||
<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>
|
||||
@@ -44,12 +31,7 @@
|
||||
<wd-empty v-else-if="total === 0" icon="search" tip="暂无数据" />
|
||||
</view>
|
||||
|
||||
<wd-popup
|
||||
v-model="dialog.visible"
|
||||
position="bottom"
|
||||
custom-class="popup-bottom"
|
||||
@close="closeDictDialog"
|
||||
>
|
||||
<wd-popup v-model="dialog.visible" position="bottom" custom-class="popup-bottom" @close="closeDictDialog">
|
||||
<view class="p-4">
|
||||
<view class="popup-title">
|
||||
{{ formData.id ? "编辑字典" : "新增字典" }}
|
||||
@@ -65,12 +47,7 @@
|
||||
<wd-switch v-model="formData.status" :active-value="1" :inactive-value="0" />
|
||||
</wd-form-item>
|
||||
<wd-form-item prop="remark" title="备注">
|
||||
<wd-textarea
|
||||
v-model="formData.remark"
|
||||
placeholder="请输入备注"
|
||||
:maxlength="100"
|
||||
show-word-limit
|
||||
/>
|
||||
<wd-textarea v-model="formData.remark" placeholder="请输入备注" :maxlength="100" show-word-limit />
|
||||
</wd-form-item>
|
||||
</wd-form>
|
||||
<view class="popup-actions">
|
||||
@@ -80,189 +57,185 @@
|
||||
</view>
|
||||
</wd-popup>
|
||||
|
||||
<wd-action-sheet
|
||||
v-model="actionSheetVisible"
|
||||
:actions="actionSheetActions"
|
||||
cancel-text="取消"
|
||||
@select="handleActionSelect"
|
||||
/>
|
||||
<wd-action-sheet v-model="actionSheetVisible" :actions="actionSheetActions" cancel-text="取消" @select="handleActionSelect" />
|
||||
|
||||
<wd-fab v-if="hasPermission('sys:dict:create') && !dialog.visible" :expandable="false" :gap="{ bottom: 32 }" @click="openDictDialog()" />
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
definePage({
|
||||
name: "dict",
|
||||
style: { navigationBarTitleText: "字典管理" },
|
||||
});
|
||||
|
||||
import { onLoad, onReachBottom } from "@dcloudio/uni-app";
|
||||
import { useRouter } from "uni-mini-router";
|
||||
import { LoadMoreState } from "@wot-ui/ui/components/wd-loadmore/types";
|
||||
import { toFormSchema } from "@/utils/form";
|
||||
import { useToast, useDialog } from "@wot-ui/ui";
|
||||
import DictAPI, { type DictTypeForm, type DictTypePageQuery, type DictTypeItem } from "@/api/dict";
|
||||
import { hasPermission } from "@/utils/permission";
|
||||
|
||||
const router = useRouter();
|
||||
const toast = useToast();
|
||||
const { confirm } = useDialog();
|
||||
const loadMoreState = ref<LoadMoreState>("loading");
|
||||
const formRef = ref();
|
||||
const isSubmitting = ref(false);
|
||||
import { onLoad, onReachBottom } from "@dcloudio/uni-app";
|
||||
import { useRouter } from "uni-mini-router";
|
||||
import { LoadMoreState } from "@wot-ui/ui/components/wd-loadmore/types";
|
||||
import { toFormSchema } from "@/utils/form";
|
||||
import { useToast, useDialog } from "@wot-ui/ui";
|
||||
import DictAPI, { type DictTypeForm, type DictTypePageQuery, type DictTypeItem } from "@/api/dict";
|
||||
import { hasPermission } from "@/utils/permission";
|
||||
|
||||
const queryParams = reactive<DictTypePageQuery>({ pageNum: 1, pageSize: 10, keywords: "" });
|
||||
const total = ref(0);
|
||||
const pageData = ref<DictTypeItem[]>([]);
|
||||
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 = toFormSchema({
|
||||
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: DictTypeItem) {
|
||||
if (!item.dictCode) return;
|
||||
router.push({
|
||||
path: "/pages/work/dict/item/index",
|
||||
query: { dictCode: item.dictCode, title: `【${item.name}】字典数据` },
|
||||
definePage({
|
||||
name: "dict",
|
||||
style: { navigationBarTitleText: "字典管理" },
|
||||
});
|
||||
}
|
||||
|
||||
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 });
|
||||
const router = useRouter();
|
||||
const toast = useToast();
|
||||
const { confirm } = useDialog();
|
||||
const loadMoreState = ref<LoadMoreState>("loading");
|
||||
const formRef = ref();
|
||||
const isSubmitting = ref(false);
|
||||
|
||||
const queryParams = reactive<DictTypePageQuery>({ pageNum: 1, pageSize: 10, keywords: "" });
|
||||
const total = ref(0);
|
||||
const pageData = ref<DictTypeItem[]>([]);
|
||||
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 = toFormSchema({
|
||||
name: [{ required: true, message: "请输入字典名称" }],
|
||||
dictCode: [{ required: true, message: "请输入字典编码" }],
|
||||
});
|
||||
|
||||
const handleSearch = () => loadDictTypeList();
|
||||
|
||||
function loadDictTypeList() {
|
||||
queryParams.pageNum = 1;
|
||||
fetchDictTypeList();
|
||||
}
|
||||
}
|
||||
|
||||
function submitDictForm() {
|
||||
formRef.value.validate().then(({ valid }: { valid: boolean }) => {
|
||||
if (!valid) return;
|
||||
isSubmitting.value = true;
|
||||
const id = formData.id;
|
||||
const action = id ? DictAPI.update(id, formData) : DictAPI.create(formData);
|
||||
action
|
||||
.then(() => {
|
||||
toast.success("操作成功");
|
||||
closeDictDialog();
|
||||
loadDictTypeList();
|
||||
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(() => {
|
||||
isSubmitting.value = false;
|
||||
loadMoreState.value = "finished";
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function closeDictDialog() {
|
||||
dialog.visible = false;
|
||||
formRef.value?.reset();
|
||||
Object.assign(formData, initialFormData);
|
||||
}
|
||||
|
||||
const actionSheetVisible = ref(false);
|
||||
const actionSheetActions = ref<{ name: string; color?: string }[]>([]);
|
||||
const pendingAction = ref<Record<string, () => void>>({});
|
||||
|
||||
function showDictActions(item: DictTypeItem) {
|
||||
const actions: { name: string; color?: string }[] = [];
|
||||
const actionMap: Record<string, () => void> = {};
|
||||
|
||||
actions.push({ name: "字典数据" });
|
||||
actionMap["字典数据"] = () => openDictItemPage(item);
|
||||
|
||||
if (hasPermission("sys:dict:update")) {
|
||||
actions.push({ name: "编辑" });
|
||||
actionMap["编辑"] = () => openDictDialog(item.id);
|
||||
}
|
||||
|
||||
if (hasPermission("sys:dict:delete")) {
|
||||
actions.push({ name: "删除", color: "var(--color-danger)" });
|
||||
actionMap["删除"] = async () => {
|
||||
try {
|
||||
await confirm({
|
||||
title: "确认删除",
|
||||
msg: `确定要删除字典「${item.name}」吗?`,
|
||||
headerImage: "warning",
|
||||
});
|
||||
if (item.id) {
|
||||
await DictAPI.deleteByIds(String(item.id));
|
||||
toast.success("删除成功");
|
||||
function openDictItemPage(item: DictTypeItem) {
|
||||
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;
|
||||
isSubmitting.value = true;
|
||||
const id = formData.id;
|
||||
const action = id ? DictAPI.update(id, formData) : DictAPI.create(formData);
|
||||
action
|
||||
.then(() => {
|
||||
toast.success("操作成功");
|
||||
closeDictDialog();
|
||||
loadDictTypeList();
|
||||
})
|
||||
.finally(() => {
|
||||
isSubmitting.value = false;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function closeDictDialog() {
|
||||
dialog.visible = false;
|
||||
formRef.value?.reset();
|
||||
Object.assign(formData, initialFormData);
|
||||
}
|
||||
|
||||
const actionSheetVisible = ref(false);
|
||||
const actionSheetActions = ref<{ name: string; color?: string }[]>([]);
|
||||
const pendingAction = ref<Record<string, () => void>>({});
|
||||
|
||||
function showDictActions(item: DictTypeItem) {
|
||||
const actions: { name: string; color?: string }[] = [];
|
||||
const actionMap: Record<string, () => void> = {};
|
||||
|
||||
actions.push({ name: "字典数据" });
|
||||
actionMap["字典数据"] = () => openDictItemPage(item);
|
||||
|
||||
if (hasPermission("sys:dict:update")) {
|
||||
actions.push({ name: "编辑" });
|
||||
actionMap["编辑"] = () => openDictDialog(item.id);
|
||||
}
|
||||
|
||||
if (hasPermission("sys:dict:delete")) {
|
||||
actions.push({ name: "删除", color: "var(--color-danger)" });
|
||||
actionMap["删除"] = async () => {
|
||||
try {
|
||||
await confirm({
|
||||
title: "确认删除",
|
||||
msg: `确定要删除字典「${item.name}」吗?`,
|
||||
headerImage: "warning",
|
||||
});
|
||||
if (item.id) {
|
||||
await DictAPI.deleteByIds(String(item.id));
|
||||
toast.success("删除成功");
|
||||
loadDictTypeList();
|
||||
}
|
||||
} catch {
|
||||
// 用户取消操作
|
||||
}
|
||||
} catch {
|
||||
// 用户取消操作
|
||||
}
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
if (actions.length === 0) {
|
||||
toast.warning("暂无操作权限");
|
||||
return;
|
||||
}
|
||||
|
||||
actionSheetActions.value = actions;
|
||||
pendingAction.value = actionMap;
|
||||
actionSheetVisible.value = true;
|
||||
}
|
||||
|
||||
if (actions.length === 0) {
|
||||
toast.warning("暂无操作权限");
|
||||
return;
|
||||
function handleActionSelect({ item }: { item: any }) {
|
||||
pendingAction.value[item.name]?.();
|
||||
}
|
||||
|
||||
actionSheetActions.value = actions;
|
||||
pendingAction.value = actionMap;
|
||||
actionSheetVisible.value = true;
|
||||
}
|
||||
onReachBottom(() => {
|
||||
if (queryParams.pageNum * queryParams.pageSize < total.value) {
|
||||
fetchDictTypeList();
|
||||
} else {
|
||||
loadMoreState.value = "finished";
|
||||
}
|
||||
});
|
||||
|
||||
function handleActionSelect({ item }: { item: any }) {
|
||||
pendingAction.value[item.name]?.();
|
||||
}
|
||||
|
||||
onReachBottom(() => {
|
||||
if (queryParams.pageNum * queryParams.pageSize < total.value) {
|
||||
fetchDictTypeList();
|
||||
} else {
|
||||
loadMoreState.value = "finished";
|
||||
}
|
||||
});
|
||||
|
||||
onLoad(() => {
|
||||
loadDictTypeList();
|
||||
});
|
||||
onLoad(() => {
|
||||
loadDictTypeList();
|
||||
});
|
||||
</script>
|
||||
|
||||
<script lang="ts">
|
||||
export default { options: { styleIsolation: "shared" } };
|
||||
export default { options: { styleIsolation: "shared" } };
|
||||
</script>
|
||||
|
||||
|
||||
+162
-193
@@ -1,21 +1,11 @@
|
||||
<template>
|
||||
<view class="page page--padding">
|
||||
<view>
|
||||
<wd-search
|
||||
v-model="queryParams.keywords"
|
||||
placeholder="搜索字典标签/字典值"
|
||||
hide-cancel
|
||||
@search="handleSearch"
|
||||
/>
|
||||
<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)"
|
||||
>
|
||||
<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">
|
||||
@@ -32,11 +22,8 @@
|
||||
|
||||
<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)"
|
||||
>
|
||||
<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>
|
||||
@@ -46,12 +33,7 @@
|
||||
<wd-empty v-else-if="total === 0" icon="search" tip="暂无数据" />
|
||||
</view>
|
||||
|
||||
<wd-popup
|
||||
v-model="dialog.visible"
|
||||
position="bottom"
|
||||
custom-class="popup-bottom"
|
||||
@close="closeItemDialog"
|
||||
>
|
||||
<wd-popup v-model="dialog.visible" position="bottom" custom-class="popup-bottom" @close="closeItemDialog">
|
||||
<view class="p-4">
|
||||
<view class="popup-title">
|
||||
{{ formData.id ? "编辑字典数据" : "新增字典数据" }}
|
||||
@@ -70,12 +52,7 @@
|
||||
<wd-input-number v-model="formData.sort" :min="0" />
|
||||
</wd-form-item>
|
||||
<wd-form-item prop="remark" title="备注">
|
||||
<wd-textarea
|
||||
v-model="formData.remark"
|
||||
placeholder="请输入备注"
|
||||
:maxlength="100"
|
||||
show-word-limit
|
||||
/>
|
||||
<wd-textarea v-model="formData.remark" placeholder="请输入备注" :maxlength="100" show-word-limit />
|
||||
</wd-form-item>
|
||||
</wd-form>
|
||||
<view class="popup-actions">
|
||||
@@ -85,209 +62,201 @@
|
||||
</view>
|
||||
</wd-popup>
|
||||
|
||||
<wd-action-sheet
|
||||
v-model="actionSheetVisible"
|
||||
:actions="actionSheetActions"
|
||||
cancel-text="取消"
|
||||
@select="handleActionSelect"
|
||||
/>
|
||||
<wd-action-sheet v-model="actionSheetVisible" :actions="actionSheetActions" cancel-text="取消" @select="handleActionSelect" />
|
||||
|
||||
<wd-fab
|
||||
v-if="hasPermission('sys:dict-item:create') && !dialog.visible"
|
||||
:expandable="false"
|
||||
:gap="{ bottom: 32 }"
|
||||
@click="openItemDialog()"
|
||||
/>
|
||||
<wd-fab v-if="hasPermission('sys:dict-item:create') && !dialog.visible" :expandable="false" :gap="{ bottom: 32 }"
|
||||
@click="openItemDialog()" />
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
definePage({
|
||||
name: "dict-item",
|
||||
style: { navigationBarTitleText: "字典数据" },
|
||||
});
|
||||
|
||||
import { onLoad, onReachBottom } from "@dcloudio/uni-app";
|
||||
import { LoadMoreState } from "@wot-ui/ui/components/wd-loadmore/types";
|
||||
import { toFormSchema } from "@/utils/form";
|
||||
import { useToast, useDialog } from "@wot-ui/ui";
|
||||
import DictAPI, { type DictItemForm, type DictItemPageQuery, type DictDataItem } from "@/api/dict";
|
||||
import { hasPermission } from "@/utils/permission";
|
||||
|
||||
const toast = useToast();
|
||||
import { onLoad, onReachBottom } from "@dcloudio/uni-app";
|
||||
import { LoadMoreState } from "@wot-ui/ui/components/wd-loadmore/types";
|
||||
import { toFormSchema } from "@/utils/form";
|
||||
import { useToast, useDialog } from "@wot-ui/ui";
|
||||
import DictAPI, { type DictItemForm, type DictItemPageQuery, type DictDataItem } from "@/api/dict";
|
||||
import { hasPermission } from "@/utils/permission";
|
||||
|
||||
definePage({
|
||||
name: "dict-item",
|
||||
style: { navigationBarTitleText: "字典数据" },
|
||||
});
|
||||
|
||||
const toast = useToast();
|
||||
const { confirm } = useDialog();
|
||||
|
||||
const dictCode = ref<string>("");
|
||||
const pageTitle = ref<string>("字典数据");
|
||||
const dictCode = ref<string>("");
|
||||
const pageTitle = ref<string>("字典数据");
|
||||
|
||||
const loadMoreState = ref<LoadMoreState>("loading");
|
||||
const formRef = ref();
|
||||
const isSubmitting = ref(false);
|
||||
const loadMoreState = ref<LoadMoreState>("loading");
|
||||
const formRef = ref();
|
||||
const isSubmitting = ref(false);
|
||||
|
||||
const queryParams = reactive<DictItemPageQuery>({ pageNum: 1, pageSize: 10, keywords: "" });
|
||||
const total = ref(0);
|
||||
const pageData = ref<DictDataItem[]>([]);
|
||||
const dialog = reactive({ visible: false });
|
||||
const queryParams = reactive<DictItemPageQuery>({ pageNum: 1, pageSize: 10, keywords: "" });
|
||||
const total = ref(0);
|
||||
const pageData = ref<DictDataItem[]>([]);
|
||||
const dialog = reactive({ visible: false });
|
||||
|
||||
const initialFormData: DictItemForm = {
|
||||
id: undefined,
|
||||
dictCode: undefined,
|
||||
label: undefined,
|
||||
value: undefined,
|
||||
sort: 1,
|
||||
status: 1,
|
||||
remark: undefined,
|
||||
};
|
||||
const initialFormData: DictItemForm = {
|
||||
id: undefined,
|
||||
dictCode: undefined,
|
||||
label: undefined,
|
||||
value: undefined,
|
||||
sort: 1,
|
||||
status: 1,
|
||||
remark: undefined,
|
||||
};
|
||||
|
||||
const formData = reactive<DictItemForm>({ ...initialFormData });
|
||||
const formData = reactive<DictItemForm>({ ...initialFormData });
|
||||
|
||||
const rules = toFormSchema({
|
||||
label: [{ required: true, message: "请输入字典项标签" }],
|
||||
value: [{ required: true, message: "请输入字典项值" }],
|
||||
});
|
||||
const rules = toFormSchema({
|
||||
label: [{ required: true, message: "请输入字典项标签" }],
|
||||
value: [{ required: true, message: "请输入字典项值" }],
|
||||
});
|
||||
|
||||
const handleSearch = () => loadItemList();
|
||||
const handleSearch = () => loadItemList();
|
||||
|
||||
function loadItemList() {
|
||||
queryParams.pageNum = 1;
|
||||
fetchItemList();
|
||||
}
|
||||
|
||||
function fetchItemList() {
|
||||
if (!dictCode.value) {
|
||||
pageData.value = [];
|
||||
total.value = 0;
|
||||
loadMoreState.value = "finished";
|
||||
return;
|
||||
function loadItemList() {
|
||||
queryParams.pageNum = 1;
|
||||
fetchItemList();
|
||||
}
|
||||
|
||||
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;
|
||||
function fetchItemList() {
|
||||
if (!dictCode.value) {
|
||||
toast.error("缺少字典编码");
|
||||
pageData.value = [];
|
||||
total.value = 0;
|
||||
loadMoreState.value = "finished";
|
||||
return;
|
||||
}
|
||||
|
||||
isSubmitting.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();
|
||||
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(() => {
|
||||
isSubmitting.value = false;
|
||||
loadMoreState.value = "finished";
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function closeItemDialog() {
|
||||
dialog.visible = false;
|
||||
formRef.value?.reset();
|
||||
Object.assign(formData, initialFormData);
|
||||
}
|
||||
|
||||
const actionSheetVisible = ref(false);
|
||||
const actionSheetActions = ref<{ name: string; color?: string }[]>([]);
|
||||
const pendingAction = ref<Record<string, () => void>>({});
|
||||
|
||||
function showItemActions(item: DictDataItem) {
|
||||
const actions: { name: string; color?: string }[] = [];
|
||||
const actionMap: Record<string, () => void> = {};
|
||||
|
||||
if (hasPermission("sys:dict-item:update")) {
|
||||
actions.push({ name: "编辑" });
|
||||
actionMap["编辑"] = () => openItemDialog(item.id);
|
||||
}
|
||||
|
||||
if (hasPermission("sys:dict-item:delete")) {
|
||||
actions.push({ name: "删除", color: "var(--color-danger)" });
|
||||
actionMap["删除"] = async () => {
|
||||
try {
|
||||
await confirm({
|
||||
title: "确认删除",
|
||||
msg: `确定要删除字典数据「${item.label}」吗?`,
|
||||
headerImage: "warning",
|
||||
});
|
||||
if (item.id) {
|
||||
await DictAPI.deleteItems(dictCode.value, String(item.id));
|
||||
toast.success("删除成功");
|
||||
loadItemList();
|
||||
}
|
||||
} catch {
|
||||
// 用户取消操作
|
||||
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;
|
||||
}
|
||||
};
|
||||
|
||||
isSubmitting.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(() => {
|
||||
isSubmitting.value = false;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
if (actions.length === 0) {
|
||||
toast.warning("暂无操作权限");
|
||||
return;
|
||||
function closeItemDialog() {
|
||||
dialog.visible = false;
|
||||
formRef.value?.reset();
|
||||
Object.assign(formData, initialFormData);
|
||||
}
|
||||
|
||||
actionSheetActions.value = actions;
|
||||
pendingAction.value = actionMap;
|
||||
actionSheetVisible.value = true;
|
||||
}
|
||||
const actionSheetVisible = ref(false);
|
||||
const actionSheetActions = ref<{ name: string; color?: string }[]>([]);
|
||||
const pendingAction = ref<Record<string, () => void>>({});
|
||||
|
||||
function handleActionSelect({ item }: { item: any }) {
|
||||
pendingAction.value[item.name]?.();
|
||||
}
|
||||
function showItemActions(item: DictDataItem) {
|
||||
const actions: { name: string; color?: string }[] = [];
|
||||
const actionMap: Record<string, () => void> = {};
|
||||
|
||||
onReachBottom(() => {
|
||||
if (queryParams.pageNum * queryParams.pageSize < total.value) {
|
||||
fetchItemList();
|
||||
} else {
|
||||
loadMoreState.value = "finished";
|
||||
if (hasPermission("sys:dict-item:update")) {
|
||||
actions.push({ name: "编辑" });
|
||||
actionMap["编辑"] = () => openItemDialog(item.id);
|
||||
}
|
||||
|
||||
if (hasPermission("sys:dict-item:delete")) {
|
||||
actions.push({ name: "删除", color: "var(--color-danger)" });
|
||||
actionMap["删除"] = async () => {
|
||||
try {
|
||||
await confirm({
|
||||
title: "确认删除",
|
||||
msg: `确定要删除字典数据「${item.label}」吗?`,
|
||||
headerImage: "warning",
|
||||
});
|
||||
if (item.id) {
|
||||
await DictAPI.deleteItems(dictCode.value, String(item.id));
|
||||
toast.success("删除成功");
|
||||
loadItemList();
|
||||
}
|
||||
} catch {
|
||||
// 用户取消操作
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
if (actions.length === 0) {
|
||||
toast.warning("暂无操作权限");
|
||||
return;
|
||||
}
|
||||
|
||||
actionSheetActions.value = actions;
|
||||
pendingAction.value = actionMap;
|
||||
actionSheetVisible.value = true;
|
||||
}
|
||||
});
|
||||
|
||||
function handleActionSelect({ item }: { item: any }) {
|
||||
pendingAction.value[item.name]?.();
|
||||
}
|
||||
|
||||
onReachBottom(() => {
|
||||
if (queryParams.pageNum * queryParams.pageSize < total.value) {
|
||||
fetchItemList();
|
||||
} else {
|
||||
loadMoreState.value = "finished";
|
||||
}
|
||||
});
|
||||
|
||||
onLoad((query: any) => {
|
||||
dictCode.value = String((query as any)?.dictCode || "");
|
||||
pageTitle.value = String((query as any)?.title || "字典数据");
|
||||
if (pageTitle.value) {
|
||||
uni.setNavigationBarTitle({ title: pageTitle.value });
|
||||
}
|
||||
loadItemList();
|
||||
});
|
||||
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" } };
|
||||
export default { options: { styleIsolation: "shared" } };
|
||||
</script>
|
||||
|
||||
|
||||
+31
-36
@@ -4,12 +4,7 @@
|
||||
<template v-for="(item, index) in visibleGridList" :key="index">
|
||||
<wd-card :title="item.title">
|
||||
<wd-grid clickable :column="4">
|
||||
<wd-grid-item
|
||||
v-for="(child, childIndex) in item.children"
|
||||
:key="childIndex"
|
||||
use-slot
|
||||
@click="handleNavClick(child)"
|
||||
>
|
||||
<wd-grid-item v-for="(child, childIndex) in item.children" :key="childIndex" use-slot @click="handleNavClick(child)">
|
||||
<view class="work-grid__icon p-2">
|
||||
<image class="w-72rpx h-72rpx rounded-8rpx" :src="child.icon" />
|
||||
</view>
|
||||
@@ -22,39 +17,39 @@
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
definePage({
|
||||
name: "work",
|
||||
style: {
|
||||
navigationStyle: "custom",
|
||||
navigationBarTitleText: "工作台",
|
||||
},
|
||||
layout: "tabbar",
|
||||
});
|
||||
|
||||
import { computed } from "vue";
|
||||
import { useNavbar } from "@/composables/useNavbar";
|
||||
import { useNavigation } from "@/composables/useNavigation";
|
||||
import { menuConfig } from "@/config/menu";
|
||||
import { hasPermission as checkPermission } from "@/utils/permission";
|
||||
import { computed } from "vue";
|
||||
import { useNavbar } from "@/composables/useNavbar";
|
||||
import { useNavigation } from "@/composables/useNavigation";
|
||||
import { menuConfig } from "@/config/menu";
|
||||
import { hasPermission as checkPermission } from "@/utils/permission";
|
||||
|
||||
const navbar = useNavbar();
|
||||
const { handleNavClick } = useNavigation();
|
||||
definePage({
|
||||
name: "work",
|
||||
style: {
|
||||
navigationStyle: "custom",
|
||||
navigationBarTitleText: "工作台",
|
||||
},
|
||||
layout: "tabbar",
|
||||
});
|
||||
|
||||
// 检查是否有权限
|
||||
const hasPermission = (perm: string) => {
|
||||
if (!perm) return true;
|
||||
return checkPermission(perm);
|
||||
};
|
||||
const navbar = useNavbar();
|
||||
const { handleNavClick } = useNavigation();
|
||||
|
||||
// 根据权限过滤后的菜单列表
|
||||
const visibleGridList = computed(() => {
|
||||
return menuConfig
|
||||
.map((group) => ({
|
||||
...group,
|
||||
children: group.children.filter((item) => hasPermission(item.perm)),
|
||||
}))
|
||||
.filter((group) => group.children.length > 0);
|
||||
});
|
||||
// 检查是否有权限
|
||||
const hasPermission = (perm: string) => {
|
||||
if (!perm) return true;
|
||||
return checkPermission(perm);
|
||||
};
|
||||
|
||||
// 根据权限过滤后的菜单列表
|
||||
const visibleGridList = computed(() => {
|
||||
return menuConfig
|
||||
.map((group) => ({
|
||||
...group,
|
||||
children: group.children.filter((item) => hasPermission(item.perm)),
|
||||
}))
|
||||
.filter((group) => group.children.length > 0);
|
||||
});
|
||||
</script>
|
||||
|
||||
|
||||
@@ -1,33 +1,18 @@
|
||||
<template>
|
||||
<view class="page page--padding">
|
||||
<view>
|
||||
<wd-search
|
||||
v-model="queryParams.keywords"
|
||||
placeholder="搜索日志内容"
|
||||
hide-cancel
|
||||
@search="handleSearch"
|
||||
/>
|
||||
<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="openLogDetail(item)"
|
||||
>
|
||||
<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.operatorName }}</text>
|
||||
<wd-tag
|
||||
plain
|
||||
size="small"
|
||||
class="ml-16rpx"
|
||||
:type="item.status === 1 ? 'success' : 'danger'"
|
||||
>
|
||||
<wd-tag plain size="small" class="ml-16rpx" :type="item.status === 1 ? 'success' : 'danger'">
|
||||
{{ item.status === 1 ? "成功" : "失败" }}
|
||||
</wd-tag>
|
||||
</view>
|
||||
@@ -48,11 +33,8 @@
|
||||
<!-- 元信息行 -->
|
||||
<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)"
|
||||
>
|
||||
<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>
|
||||
@@ -63,12 +45,7 @@
|
||||
</view>
|
||||
|
||||
<!-- 详情弹窗 -->
|
||||
<wd-popup
|
||||
v-model="detailDialog.visible"
|
||||
position="bottom"
|
||||
custom-class="popup-bottom"
|
||||
@close="closeLogDetail"
|
||||
>
|
||||
<wd-popup v-model="detailDialog.visible" position="bottom" custom-class="popup-bottom" @close="closeLogDetail">
|
||||
<view class="p-4">
|
||||
<view class="popup-title">日志详情</view>
|
||||
<wd-cell-group border>
|
||||
@@ -101,76 +78,77 @@
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
definePage({
|
||||
name: "log",
|
||||
style: { navigationBarTitleText: "系统日志" },
|
||||
});
|
||||
|
||||
import { onLoad, onReachBottom } from "@dcloudio/uni-app";
|
||||
import { LoadMoreState } from "@wot-ui/ui/components/wd-loadmore/types";
|
||||
import LogAPI, { type LogPageQuery, LogItem } from "@/api/log";
|
||||
import { onLoad, onReachBottom } from "@dcloudio/uni-app";
|
||||
import { LoadMoreState } from "@wot-ui/ui/components/wd-loadmore/types";
|
||||
import LogAPI, { type LogPageQuery, LogItem } from "@/api/log";
|
||||
|
||||
const loadMoreState = ref<LoadMoreState>("loading");
|
||||
definePage({
|
||||
name: "log",
|
||||
style: { navigationBarTitleText: "系统日志" },
|
||||
});
|
||||
|
||||
const queryParams = reactive<LogPageQuery>({ pageNum: 1, pageSize: 10 });
|
||||
const total = ref(0);
|
||||
const pageData = ref<LogItem[]>([]);
|
||||
const loadMoreState = ref<LoadMoreState>("loading");
|
||||
|
||||
const logDetail = ref<LogItem>({});
|
||||
const detailDialog = reactive({ visible: false });
|
||||
const queryParams = reactive<LogPageQuery>({ pageNum: 1, pageSize: 10 });
|
||||
const total = ref(0);
|
||||
const pageData = ref<LogItem[]>([]);
|
||||
|
||||
// 搜索触发
|
||||
const handleSearch = () => loadLogList();
|
||||
const logDetail = ref<LogItem>({});
|
||||
const detailDialog = reactive({ visible: false });
|
||||
|
||||
// 加载列表
|
||||
function loadLogList() {
|
||||
queryParams.pageNum = 1;
|
||||
fetchLogList();
|
||||
}
|
||||
// 搜索触发
|
||||
const handleSearch = () => loadLogList();
|
||||
|
||||
// 分页加载列表
|
||||
function fetchLogList() {
|
||||
loadMoreState.value = "loading";
|
||||
LogAPI.getPage(queryParams)
|
||||
.then((data) => {
|
||||
pageData.value = data.list;
|
||||
total.value = data.total;
|
||||
queryParams.pageNum++;
|
||||
})
|
||||
.catch(() => {
|
||||
pageData.value = [];
|
||||
})
|
||||
.finally(() => {
|
||||
loadMoreState.value = "finished";
|
||||
});
|
||||
}
|
||||
|
||||
// 打开详情弹窗
|
||||
function openLogDetail(item: LogItem) {
|
||||
logDetail.value = item;
|
||||
detailDialog.visible = true;
|
||||
}
|
||||
|
||||
// 关闭详情弹窗
|
||||
function closeLogDetail() {
|
||||
detailDialog.visible = false;
|
||||
}
|
||||
|
||||
onReachBottom(() => {
|
||||
if (queryParams.pageNum * queryParams.pageSize < total.value) {
|
||||
// 加载列表
|
||||
function loadLogList() {
|
||||
queryParams.pageNum = 1;
|
||||
fetchLogList();
|
||||
} else {
|
||||
loadMoreState.value = "finished";
|
||||
}
|
||||
});
|
||||
|
||||
onLoad(() => {
|
||||
loadLogList();
|
||||
});
|
||||
// 分页加载列表
|
||||
function fetchLogList() {
|
||||
loadMoreState.value = "loading";
|
||||
LogAPI.getPage(queryParams)
|
||||
.then((data) => {
|
||||
pageData.value = data.list;
|
||||
total.value = data.total;
|
||||
queryParams.pageNum++;
|
||||
})
|
||||
.catch(() => {
|
||||
pageData.value = [];
|
||||
})
|
||||
.finally(() => {
|
||||
loadMoreState.value = "finished";
|
||||
});
|
||||
}
|
||||
|
||||
// 打开详情弹窗
|
||||
function openLogDetail(item: LogItem) {
|
||||
logDetail.value = item;
|
||||
detailDialog.visible = true;
|
||||
}
|
||||
|
||||
// 关闭详情弹窗
|
||||
function closeLogDetail() {
|
||||
detailDialog.visible = false;
|
||||
}
|
||||
|
||||
onReachBottom(() => {
|
||||
if (queryParams.pageNum * queryParams.pageSize < total.value) {
|
||||
fetchLogList();
|
||||
} else {
|
||||
loadMoreState.value = "finished";
|
||||
}
|
||||
});
|
||||
|
||||
onLoad(() => {
|
||||
loadLogList();
|
||||
});
|
||||
</script>
|
||||
|
||||
<script lang="ts">
|
||||
export default { options: { styleIsolation: "shared" } };
|
||||
export default { options: { styleIsolation: "shared" } };
|
||||
</script>
|
||||
|
||||
|
||||
+254
-282
@@ -1,22 +1,12 @@
|
||||
<template>
|
||||
<view class="page page--padding">
|
||||
<view>
|
||||
<wd-search
|
||||
v-model="queryParams.keywords"
|
||||
placeholder="搜索菜单名称"
|
||||
hide-cancel
|
||||
@search="handleSearch"
|
||||
/>
|
||||
<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"
|
||||
>
|
||||
<custom-tree :data="treeData" :default-expand-all="true" :show-action="true" @action="handleNodeAction">
|
||||
<!-- 自定义节点内容:ID + 名称 + 状态 -->
|
||||
<template #content="{ node }">
|
||||
<view class="menu-node">
|
||||
@@ -26,11 +16,7 @@
|
||||
<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"
|
||||
>
|
||||
<wd-tag class="flex-shrink-0" :type="node.visible === 1 ? 'success' : 'primary'" size="small">
|
||||
{{ node.visible === 1 ? "显示" : "隐藏" }}
|
||||
</wd-tag>
|
||||
</view>
|
||||
@@ -41,12 +27,7 @@
|
||||
</view>
|
||||
|
||||
<!-- 弹窗表单 -->
|
||||
<wd-popup
|
||||
v-model="dialog.visible"
|
||||
position="bottom"
|
||||
custom-class="popup-bottom-scroll"
|
||||
@close="closeMenuDialog"
|
||||
>
|
||||
<wd-popup v-model="dialog.visible" position="bottom" custom-class="popup-bottom-scroll" @close="closeMenuDialog">
|
||||
<view class="p-4">
|
||||
<view class="popup-title">
|
||||
{{ formData.id ? "编辑菜单" : "新增菜单" }}
|
||||
@@ -54,13 +35,8 @@
|
||||
<scroll-view scroll-y class="max-h-60vh">
|
||||
<wd-form ref="formRef" :model="formData" :schema="rules">
|
||||
<wd-form-item prop="parentId" title="上级菜单" required>
|
||||
<wd-cascader
|
||||
v-model="parentSelected"
|
||||
:columns="parentColumns"
|
||||
:column-change="handleParentColumnChange"
|
||||
:display-format="displayParentFormat"
|
||||
@confirm="handleParentConfirm"
|
||||
/>
|
||||
<wd-cascader v-model="parentSelected" :columns="parentColumns" :column-change="handleParentColumnChange"
|
||||
:display-format="displayParentFormat" @confirm="handleParentConfirm" />
|
||||
</wd-form-item>
|
||||
<wd-form-item prop="name" title="菜单名称" required>
|
||||
<wd-input v-model="formData.name" placeholder="请输入菜单名称" />
|
||||
@@ -103,304 +79,300 @@
|
||||
<wd-fab v-if="hasPermission('sys:menu:create') && !dialog.visible" :expandable="false" :gap="{ bottom: 32 }" @click="openMenuDialog()" />
|
||||
|
||||
<!-- 操作菜单 -->
|
||||
<wd-action-sheet
|
||||
v-model="actionSheetVisible"
|
||||
:actions="actionSheetActions"
|
||||
cancel-text="取消"
|
||||
@select="handleActionSelect"
|
||||
/>
|
||||
<wd-action-sheet v-model="actionSheetVisible" :actions="actionSheetActions" cancel-text="取消" @select="handleActionSelect" />
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
definePage({
|
||||
name: "menu",
|
||||
style: { navigationBarTitleText: "菜单管理" },
|
||||
});
|
||||
|
||||
import { onLoad } from "@dcloudio/uni-app";
|
||||
import { toFormSchema } from "@/utils/form";
|
||||
import { useToast, useDialog } from "@wot-ui/ui";
|
||||
import MenuAPI, { type MenuQuery, MenuItem, MenuForm } from "@/api/menu";
|
||||
import { hasPermission } from "@/utils/permission";
|
||||
import CustomTree from "@/components/custom-tree/index.vue";
|
||||
import { onLoad } from "@dcloudio/uni-app";
|
||||
import { toFormSchema } from "@/utils/form";
|
||||
import { useToast, useDialog } from "@wot-ui/ui";
|
||||
import MenuAPI, { type MenuQuery, MenuItem, MenuForm } from "@/api/menu";
|
||||
import { hasPermission } from "@/utils/permission";
|
||||
import CustomTree from "@/components/custom-tree/index.vue";
|
||||
|
||||
const toast = useToast();
|
||||
definePage({
|
||||
name: "menu",
|
||||
style: { navigationBarTitleText: "菜单管理" },
|
||||
});
|
||||
|
||||
const toast = useToast();
|
||||
const { confirm } = useDialog();
|
||||
const formRef = ref();
|
||||
const isSubmitting = ref(false);
|
||||
const formRef = ref();
|
||||
const isSubmitting = ref(false);
|
||||
|
||||
const queryParams = reactive<MenuQuery>({ keywords: "" });
|
||||
const menuList = ref<MenuItem[]>([]);
|
||||
const dialog = reactive({ visible: false });
|
||||
const queryParams = reactive<MenuQuery>({ keywords: "" });
|
||||
const menuList = ref<MenuItem[]>([]);
|
||||
const dialog = reactive({ visible: false });
|
||||
|
||||
const actionSheetVisible = ref(false);
|
||||
const actionSheetActions = ref<{ name: string; color?: string }[]>([]);
|
||||
const currentActionItem = ref<any>(null);
|
||||
const actionSheetVisible = ref(false);
|
||||
const actionSheetActions = ref<{ name: string; color?: string }[]>([]);
|
||||
const currentActionItem = ref<any>(null);
|
||||
|
||||
const initialFormData: MenuForm = {
|
||||
id: undefined,
|
||||
parentId: "0",
|
||||
name: undefined,
|
||||
type: "M",
|
||||
routePath: undefined,
|
||||
component: undefined,
|
||||
perm: undefined,
|
||||
icon: undefined,
|
||||
sort: 1,
|
||||
visible: 1,
|
||||
};
|
||||
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 formData = reactive<MenuForm>({ ...initialFormData });
|
||||
|
||||
// 转换为树组件数据格式
|
||||
// 转换为树组件数据格式
|
||||
const treeData = computed(() => menuList.value.map((menu: MenuItem) => transformMenuToTree(menu)));
|
||||
|
||||
function transformMenuToTree(menu: MenuItem): 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: MenuItem) => transformMenuToTree(child)) || [],
|
||||
function transformMenuToTree(menu: MenuItem): 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: MenuItem) => 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 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 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;
|
||||
}
|
||||
|
||||
function getMenuTypeTag(type?: string | number): "primary" | "success" | "warning" | "danger" {
|
||||
const map: Record<string, "primary" | "success" | "warning" | "danger"> = {
|
||||
C: "warning",
|
||||
M: "success",
|
||||
B: "danger",
|
||||
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 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 handleParentConfirm = ({ value }: any) => {
|
||||
parentSelected.value = value;
|
||||
formData.parentId = String(value[value.length - 1]) || "0";
|
||||
};
|
||||
|
||||
// 上级菜单选择器
|
||||
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 = toFormSchema({
|
||||
name: [{ required: true, message: "请输入菜单名称" }],
|
||||
type: [{ required: true, message: "请选择菜单类型" }],
|
||||
parentId: [{ required: true, message: "请选择上级菜单" }],
|
||||
});
|
||||
|
||||
const handleSearch = () => loadMenuList();
|
||||
|
||||
function loadMenuList() {
|
||||
MenuAPI.getList(queryParams).then((data: any) => {
|
||||
menuList.value = data;
|
||||
const rules = toFormSchema({
|
||||
name: [{ required: true, message: "请输入菜单名称" }],
|
||||
type: [{ required: true, message: "请选择菜单类型" }],
|
||||
parentId: [{ required: true, message: "请选择上级菜单" }],
|
||||
});
|
||||
}
|
||||
|
||||
// 操作菜单分发
|
||||
function handleActionSelect({ item }: { item: any }) {
|
||||
const value = item.name;
|
||||
const menu = currentActionItem.value;
|
||||
if (value === "新增子菜单") {
|
||||
handleAddChild(menu);
|
||||
} else if (value === "编辑") {
|
||||
openMenuDialog(menu);
|
||||
} else if (value === "删除") {
|
||||
confirm({
|
||||
title: "确认删除",
|
||||
msg: `确定要删除菜单「${menu.name}」吗?`,
|
||||
headerImage: "warning",
|
||||
}).then(async () => {
|
||||
await MenuAPI.deleteById(menu.id!);
|
||||
toast.success("删除成功");
|
||||
loadMenuList();
|
||||
const handleSearch = () => loadMenuList();
|
||||
|
||||
function loadMenuList() {
|
||||
MenuAPI.getList(queryParams).then((data: any) => {
|
||||
menuList.value = data;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// 处理节点操作按钮点击
|
||||
function handleNodeAction(node: any) {
|
||||
const menu: MenuItem = {
|
||||
id: node.id,
|
||||
name: node.label,
|
||||
type: node.type,
|
||||
visible: node.visible,
|
||||
children: node.children,
|
||||
} as MenuItem;
|
||||
|
||||
const actions: { name: string; color?: string }[] = [];
|
||||
|
||||
if (hasPermission("sys:menu:create") && node.type !== 3) {
|
||||
actions.push({ name: "新增子菜单" });
|
||||
// 操作菜单分发
|
||||
function handleActionSelect({ item }: { item: any }) {
|
||||
const value = item.name;
|
||||
const menu = currentActionItem.value;
|
||||
if (value === "新增子菜单") {
|
||||
handleAddChild(menu);
|
||||
} else if (value === "编辑") {
|
||||
openMenuDialog(menu);
|
||||
} else if (value === "删除") {
|
||||
confirm({
|
||||
title: "确认删除",
|
||||
msg: `确定要删除菜单「${menu.name}」吗?`,
|
||||
headerImage: "warning",
|
||||
}).then(async () => {
|
||||
await MenuAPI.deleteById(menu.id!);
|
||||
toast.success("删除成功");
|
||||
loadMenuList();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (hasPermission("sys:menu:update")) {
|
||||
actions.push({ name: "编辑" });
|
||||
// 处理节点操作按钮点击
|
||||
function handleNodeAction(node: any) {
|
||||
const menu: MenuItem = {
|
||||
id: node.id,
|
||||
name: node.label,
|
||||
type: node.type,
|
||||
visible: node.visible,
|
||||
children: node.children,
|
||||
} as MenuItem;
|
||||
|
||||
const actions: { name: string; color?: string }[] = [];
|
||||
|
||||
if (hasPermission("sys:menu:create") && node.type !== 3) {
|
||||
actions.push({ name: "新增子菜单" });
|
||||
}
|
||||
|
||||
if (hasPermission("sys:menu:update")) {
|
||||
actions.push({ name: "编辑" });
|
||||
}
|
||||
|
||||
if (hasPermission("sys:menu:delete")) {
|
||||
actions.push({ name: "删除", color: "var(--color-danger)" });
|
||||
}
|
||||
|
||||
if (actions.length === 0) {
|
||||
toast.warning("暂无操作权限");
|
||||
return;
|
||||
}
|
||||
|
||||
currentActionItem.value = menu;
|
||||
actionSheetActions.value = actions;
|
||||
actionSheetVisible.value = true;
|
||||
}
|
||||
|
||||
if (hasPermission("sys:menu:delete")) {
|
||||
actions.push({ name: "删除", color: "var(--color-danger)" });
|
||||
}
|
||||
// 打开弹窗(新增/编辑)
|
||||
async function openMenuDialog(menu?: MenuItem) {
|
||||
formRef.value?.reset();
|
||||
Object.assign(formData, initialFormData);
|
||||
parentSelected.value = [];
|
||||
dialog.visible = true;
|
||||
|
||||
if (actions.length === 0) {
|
||||
toast.warning("暂无操作权限");
|
||||
return;
|
||||
}
|
||||
const data = await MenuAPI.getOptions(true);
|
||||
parentOptions.value = data;
|
||||
const firstColumn: OptionType[] = [{ value: "0", label: "顶级菜单" }, ...data];
|
||||
parentColumns.value = [firstColumn];
|
||||
|
||||
currentActionItem.value = menu;
|
||||
actionSheetActions.value = actions;
|
||||
actionSheetVisible.value = true;
|
||||
}
|
||||
if (menu) {
|
||||
formData.id = menu.id;
|
||||
const form = await MenuAPI.getFormData(menu.id!);
|
||||
Object.assign(formData, form, { id: menu.id });
|
||||
|
||||
// 打开弹窗(新增/编辑)
|
||||
async function openMenuDialog(menu?: MenuItem) {
|
||||
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: any) => String(item.value) === String(path[i]));
|
||||
if (found && found.children && found.children.length > 0) {
|
||||
columns.push(found.children);
|
||||
currentLevel = found.children;
|
||||
} else {
|
||||
break;
|
||||
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: any) => 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)];
|
||||
}
|
||||
parentColumns.value = columns;
|
||||
} else {
|
||||
parentSelected.value = [String(form.parentId)];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 新增子菜单
|
||||
function handleAddChild(menu: MenuItem) {
|
||||
openMenuDialog({ id: undefined, parentId: menu.id } as MenuItem);
|
||||
formData.parentId = menu.id!;
|
||||
parentSelected.value = [menu.id!];
|
||||
}
|
||||
// 新增子菜单
|
||||
function handleAddChild(menu: MenuItem) {
|
||||
openMenuDialog({ id: undefined, parentId: menu.id } as MenuItem);
|
||||
formData.parentId = menu.id!;
|
||||
parentSelected.value = [menu.id!];
|
||||
}
|
||||
|
||||
// 提交表单
|
||||
function submitMenuForm() {
|
||||
formRef.value.validate().then(({ valid }: { valid: boolean }) => {
|
||||
if (!valid) return;
|
||||
isSubmitting.value = true;
|
||||
const action = formData.id ? MenuAPI.update(formData.id, formData) : MenuAPI.add(formData);
|
||||
action
|
||||
.then(() => {
|
||||
toast.success("操作成功");
|
||||
closeMenuDialog();
|
||||
loadMenuList();
|
||||
})
|
||||
.finally(() => {
|
||||
isSubmitting.value = false;
|
||||
});
|
||||
// 提交表单
|
||||
function submitMenuForm() {
|
||||
formRef.value.validate().then(({ valid }: { valid: boolean }) => {
|
||||
if (!valid) return;
|
||||
isSubmitting.value = true;
|
||||
const action = formData.id ? MenuAPI.update(formData.id, formData) : MenuAPI.add(formData);
|
||||
action
|
||||
.then(() => {
|
||||
toast.success("操作成功");
|
||||
closeMenuDialog();
|
||||
loadMenuList();
|
||||
})
|
||||
.finally(() => {
|
||||
isSubmitting.value = false;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// 关闭弹窗
|
||||
function closeMenuDialog() {
|
||||
dialog.visible = false;
|
||||
formRef.value?.reset();
|
||||
Object.assign(formData, initialFormData);
|
||||
}
|
||||
|
||||
onLoad(() => {
|
||||
loadMenuList();
|
||||
});
|
||||
}
|
||||
|
||||
// 关闭弹窗
|
||||
function closeMenuDialog() {
|
||||
dialog.visible = false;
|
||||
formRef.value?.reset();
|
||||
Object.assign(formData, initialFormData);
|
||||
}
|
||||
|
||||
onLoad(() => {
|
||||
loadMenuList();
|
||||
});
|
||||
</script>
|
||||
|
||||
<script lang="ts">
|
||||
export default { options: { styleIsolation: "shared" } };
|
||||
export default { options: { styleIsolation: "shared" } };
|
||||
</script>
|
||||
|
||||
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.menu-node {
|
||||
display: flex;
|
||||
flex: 1;
|
||||
flex-wrap: nowrap;
|
||||
gap: 16rpx;
|
||||
align-items: center;
|
||||
}
|
||||
.menu-node {
|
||||
display: flex;
|
||||
flex: 1;
|
||||
flex-wrap: nowrap;
|
||||
gap: 16rpx;
|
||||
align-items: center;
|
||||
}
|
||||
</style>
|
||||
@@ -5,13 +5,12 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref } from "vue";
|
||||
|
||||
definePage({
|
||||
name: "monitor",
|
||||
style: { navigationBarTitleText: "应用监控" },
|
||||
});
|
||||
|
||||
import { ref } from "vue";
|
||||
|
||||
// SpringBoot Admin 监控地址
|
||||
const monitorUrl = ref("http://localhost:9090/wallboard");
|
||||
</script>
|
||||
|
||||
+289
-325
@@ -1,22 +1,12 @@
|
||||
<template>
|
||||
<view class="page page--padding">
|
||||
<view>
|
||||
<wd-search
|
||||
v-model="queryParams.title"
|
||||
placeholder="搜索通知标题"
|
||||
hide-cancel
|
||||
@search="handleSearch"
|
||||
/>
|
||||
<wd-search v-model="queryParams.title" 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="openNoticeDetail(item)"
|
||||
>
|
||||
<wd-card v-for="item in pageData" :key="item.id" custom-class="item-card" @click="openNoticeDetail(item)">
|
||||
<!-- 主信息行 -->
|
||||
<view class="flex-start">
|
||||
<view class="notice-card__main">
|
||||
@@ -51,11 +41,7 @@
|
||||
<!-- 元信息行 -->
|
||||
<view class="notice-card__footer">
|
||||
<text class="notice-card__time">{{ formatTime(item) }}</text>
|
||||
<view
|
||||
class="notice-card__action"
|
||||
hover-class="notice-card__action--hover"
|
||||
@click.stop="showNoticeActions(item)"
|
||||
>
|
||||
<view class="notice-card__action" hover-class="notice-card__action--hover" @click.stop="showNoticeActions(item)">
|
||||
<wd-icon name="more" size="16" class="color-text-secondary" />
|
||||
</view>
|
||||
</view>
|
||||
@@ -66,12 +52,7 @@
|
||||
</view>
|
||||
|
||||
<!-- 详情弹窗 -->
|
||||
<wd-popup
|
||||
v-model="detailDialog.visible"
|
||||
position="bottom"
|
||||
custom-class="popup-bottom"
|
||||
@close="closeNoticeDetail"
|
||||
>
|
||||
<wd-popup v-model="detailDialog.visible" position="bottom" custom-class="popup-bottom" @close="closeNoticeDetail">
|
||||
<view class="p-4">
|
||||
<view class="popup-title">通知详情</view>
|
||||
<wd-cell-group border>
|
||||
@@ -96,12 +77,7 @@
|
||||
</wd-popup>
|
||||
|
||||
<!-- 新增/编辑弹窗 -->
|
||||
<wd-popup
|
||||
v-model="formDialog.visible"
|
||||
position="bottom"
|
||||
custom-class="popup-bottom"
|
||||
@close="closeNoticeForm"
|
||||
>
|
||||
<wd-popup v-model="formDialog.visible" position="bottom" custom-class="popup-bottom" @close="closeNoticeForm">
|
||||
<view class="p-4">
|
||||
<view class="popup-title">
|
||||
{{ formData.id ? "编辑通知" : "新增通知" }}
|
||||
@@ -124,12 +100,7 @@
|
||||
</wd-radio-group>
|
||||
</wd-form-item>
|
||||
<wd-form-item prop="content" title="内容">
|
||||
<wd-textarea
|
||||
v-model="formData.content"
|
||||
placeholder="请输入通知内容"
|
||||
:maxlength="500"
|
||||
show-word-limit
|
||||
/>
|
||||
<wd-textarea v-model="formData.content" placeholder="请输入通知内容" :maxlength="500" show-word-limit />
|
||||
</wd-form-item>
|
||||
</wd-form>
|
||||
<view class="popup-actions">
|
||||
@@ -141,333 +112,326 @@
|
||||
</view>
|
||||
</wd-popup>
|
||||
|
||||
<wd-action-sheet
|
||||
v-model="actionSheetVisible"
|
||||
:actions="actionSheetActions"
|
||||
cancel-text="取消"
|
||||
@select="handleActionSelect"
|
||||
/>
|
||||
<wd-action-sheet v-model="actionSheetVisible" :actions="actionSheetActions" cancel-text="取消" @select="handleActionSelect" />
|
||||
|
||||
<wd-fab
|
||||
v-if="hasPermission('sys:notice:create') && !formDialog.visible && !detailDialog.visible"
|
||||
:expandable="false"
|
||||
:gap="{ bottom: 32 }"
|
||||
@click="openNoticeForm()"
|
||||
/>
|
||||
<wd-fab v-if="hasPermission('sys:notice:create') && !formDialog.visible && !detailDialog.visible" :expandable="false" :gap="{ bottom: 32 }"
|
||||
@click="openNoticeForm()" />
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
definePage({
|
||||
name: "notice",
|
||||
style: { navigationBarTitleText: "通知公告" },
|
||||
});
|
||||
|
||||
import { onLoad, onReachBottom } from "@dcloudio/uni-app";
|
||||
import { LoadMoreState } from "@wot-ui/ui/components/wd-loadmore/types";
|
||||
import { toFormSchema } from "@/utils/form";
|
||||
import { useToast, useDialog } from "@wot-ui/ui";
|
||||
import NoticeAPI, {
|
||||
type NoticePageQuery,
|
||||
NoticeItem,
|
||||
NoticeDetail,
|
||||
NoticeForm,
|
||||
} from "@/api/notice";
|
||||
import { hasPermission } from "@/utils/permission";
|
||||
import { onLoad, onReachBottom } from "@dcloudio/uni-app";
|
||||
import { LoadMoreState } from "@wot-ui/ui/components/wd-loadmore/types";
|
||||
import { toFormSchema } from "@/utils/form";
|
||||
import { useToast, useDialog } from "@wot-ui/ui";
|
||||
import NoticeAPI, {
|
||||
type NoticePageQuery,
|
||||
NoticeItem,
|
||||
NoticeDetail,
|
||||
NoticeForm,
|
||||
} from "@/api/notice";
|
||||
import { hasPermission } from "@/utils/permission";
|
||||
|
||||
const toast = useToast();
|
||||
|
||||
definePage({
|
||||
name: "notice",
|
||||
style: { navigationBarTitleText: "通知公告" },
|
||||
});
|
||||
|
||||
const toast = useToast();
|
||||
const { confirm } = useDialog();
|
||||
const loadMoreState = ref<LoadMoreState>("loading");
|
||||
const formRef = ref();
|
||||
const isSubmitting = ref(false);
|
||||
const loadMoreState = ref<LoadMoreState>("loading");
|
||||
const formRef = ref();
|
||||
const isSubmitting = ref(false);
|
||||
|
||||
const queryParams = reactive<NoticePageQuery>({ pageNum: 1, pageSize: 10 });
|
||||
const total = ref(0);
|
||||
const pageData = ref<NoticeItem[]>([]);
|
||||
const queryParams = reactive<NoticePageQuery>({ pageNum: 1, pageSize: 10 });
|
||||
const total = ref(0);
|
||||
const pageData = ref<NoticeItem[]>([]);
|
||||
|
||||
const noticeDetail = ref<NoticeDetail>({});
|
||||
const detailDialog = reactive({ visible: false });
|
||||
const noticeDetail = ref<NoticeDetail>({});
|
||||
const detailDialog = reactive({ visible: false });
|
||||
|
||||
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 formRules = toFormSchema({
|
||||
title: [{ required: true, message: "请输入通知标题" }],
|
||||
});
|
||||
|
||||
// 获取状态样式
|
||||
const getStatusType = (
|
||||
status?: number
|
||||
): "default" | "primary" | "danger" | "warning" | "success" => {
|
||||
const map: Record<number, "default" | "primary" | "danger" | "warning" | "success"> = {
|
||||
0: "primary",
|
||||
1: "success",
|
||||
[-1]: "warning",
|
||||
const formDialog = reactive({ visible: false });
|
||||
const initialFormData: NoticeForm = {
|
||||
id: undefined,
|
||||
title: undefined,
|
||||
content: undefined,
|
||||
type: undefined,
|
||||
level: "M",
|
||||
targetType: 1,
|
||||
targetUserIds: undefined,
|
||||
};
|
||||
return status !== undefined ? map[status] || "default" : "default";
|
||||
};
|
||||
const formData = reactive<NoticeForm>({ ...initialFormData });
|
||||
|
||||
// 获取状态文本
|
||||
const getStatusText = (status?: number): string => {
|
||||
const map: Record<number, string> = { 0: "未发布", 1: "已发布", [-1]: "已撤回" };
|
||||
return status !== undefined ? map[status] || "未知" : "-";
|
||||
};
|
||||
const formRules = toFormSchema({
|
||||
title: [{ required: true, message: "请输入通知标题" }],
|
||||
});
|
||||
|
||||
// 获取级别文本
|
||||
const getLevelText = (level?: string | number): string => {
|
||||
const map: Record<string, string> = { L: "低", M: "中", H: "高" };
|
||||
return level ? map[String(level)] || String(level) : "-";
|
||||
};
|
||||
// 获取状态样式
|
||||
const getStatusType = (
|
||||
status?: number
|
||||
): "default" | "primary" | "danger" | "warning" | "success" => {
|
||||
const map: Record<number, "default" | "primary" | "danger" | "warning" | "success"> = {
|
||||
0: "primary",
|
||||
1: "success",
|
||||
[-1]: "warning",
|
||||
};
|
||||
return status !== undefined ? map[status] || "default" : "default";
|
||||
};
|
||||
|
||||
// 格式化时间
|
||||
const formatTime = (item: NoticeItem): string => {
|
||||
if (item.publishStatus === 1 && item.publishTime) {
|
||||
return String(item.publishTime);
|
||||
// 获取状态文本
|
||||
const getStatusText = (status?: number): string => {
|
||||
const map: Record<number, string> = { 0: "未发布", 1: "已发布", [-1]: "已撤回" };
|
||||
return status !== undefined ? map[status] || "未知" : "-";
|
||||
};
|
||||
|
||||
// 获取级别文本
|
||||
const getLevelText = (level?: string | number): string => {
|
||||
const map: Record<string, string> = { L: "低", M: "中", H: "高" };
|
||||
return level ? map[String(level)] || String(level) : "-";
|
||||
};
|
||||
|
||||
// 格式化时间
|
||||
const formatTime = (item: NoticeItem): 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();
|
||||
}
|
||||
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: NoticeItem) {
|
||||
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;
|
||||
isSubmitting.value = true;
|
||||
const id = formData.id;
|
||||
const action = id ? NoticeAPI.update(id, formData) : NoticeAPI.add(formData);
|
||||
action
|
||||
.then(() => {
|
||||
toast.success("操作成功");
|
||||
closeNoticeForm();
|
||||
loadNoticeList();
|
||||
// 分页加载列表
|
||||
function fetchNoticeList() {
|
||||
loadMoreState.value = "loading";
|
||||
NoticeAPI.getPage(queryParams)
|
||||
.then((data) => {
|
||||
pageData.value = data.list;
|
||||
total.value = data.total;
|
||||
queryParams.pageNum++;
|
||||
})
|
||||
.catch(() => {
|
||||
pageData.value = [];
|
||||
})
|
||||
.finally(() => {
|
||||
isSubmitting.value = false;
|
||||
loadMoreState.value = "finished";
|
||||
});
|
||||
}
|
||||
|
||||
// 打开详情弹窗
|
||||
async function openNoticeDetail(item: NoticeItem) {
|
||||
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;
|
||||
isSubmitting.value = true;
|
||||
const id = formData.id;
|
||||
const action = id ? NoticeAPI.update(id, formData) : NoticeAPI.add(formData);
|
||||
action
|
||||
.then(() => {
|
||||
toast.success("操作成功");
|
||||
closeNoticeForm();
|
||||
loadNoticeList();
|
||||
})
|
||||
.finally(() => {
|
||||
isSubmitting.value = false;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// 更多操作
|
||||
const actionSheetVisible = ref(false);
|
||||
const actionSheetActions = ref<{ name: string; color?: string }[]>([]);
|
||||
const pendingAction = ref<Record<string, () => void>>({});
|
||||
|
||||
function showNoticeActions(item: NoticeItem) {
|
||||
const actions: { name: string; color?: string }[] = [{ name: "查看" }];
|
||||
const actionMap: Record<string, () => void> = {
|
||||
查看: () => openNoticeDetail(item),
|
||||
};
|
||||
|
||||
if (item.publishStatus !== 1) {
|
||||
if (hasPermission("sys:notice:update")) {
|
||||
actions.push({ name: "编辑" });
|
||||
actionMap["编辑"] = () => openNoticeForm(Number(item.id));
|
||||
}
|
||||
if (hasPermission("sys:notice:delete")) {
|
||||
actions.push({ name: "删除", color: "var(--color-danger)" });
|
||||
actionMap["删除"] = async () => {
|
||||
try {
|
||||
await confirm({
|
||||
title: "确认删除",
|
||||
msg: `确定要删除通知「${item.title}」吗?`,
|
||||
headerImage: "warning",
|
||||
});
|
||||
await NoticeAPI.deleteByIds(item.id);
|
||||
toast.success("删除成功");
|
||||
loadNoticeList();
|
||||
} catch {
|
||||
// 用户取消操作
|
||||
}
|
||||
};
|
||||
}
|
||||
if (hasPermission("sys:notice:publish")) {
|
||||
actions.push({ name: "发布" });
|
||||
actionMap["发布"] = async () => {
|
||||
try {
|
||||
await confirm({
|
||||
title: "确认发布",
|
||||
msg: `确定要发布通知「${item.title}」吗?`,
|
||||
headerImage: "warning",
|
||||
});
|
||||
await NoticeAPI.publish(Number(item.id));
|
||||
toast.success("发布成功");
|
||||
loadNoticeList();
|
||||
} catch {
|
||||
// 用户取消操作
|
||||
}
|
||||
};
|
||||
}
|
||||
} else {
|
||||
if (hasPermission("sys:notice:revoke")) {
|
||||
actions.push({ name: "撤回", color: "var(--color-warning)" });
|
||||
actionMap["撤回"] = async () => {
|
||||
try {
|
||||
await confirm({
|
||||
title: "确认撤回",
|
||||
msg: `确定要撤回通知「${item.title}」吗?`,
|
||||
headerImage: "warning",
|
||||
});
|
||||
await NoticeAPI.revoke(Number(item.id));
|
||||
toast.success("撤回成功");
|
||||
loadNoticeList();
|
||||
} catch {
|
||||
// 用户取消操作
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
actionSheetActions.value = actions;
|
||||
pendingAction.value = actionMap;
|
||||
actionSheetVisible.value = true;
|
||||
}
|
||||
|
||||
function handleActionSelect({ item }: { item: any }) {
|
||||
pendingAction.value[item.name]?.();
|
||||
}
|
||||
|
||||
onReachBottom(() => {
|
||||
if (queryParams.pageNum * queryParams.pageSize < total.value) {
|
||||
fetchNoticeList();
|
||||
} else {
|
||||
loadMoreState.value = "finished";
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// 更多操作
|
||||
const actionSheetVisible = ref(false);
|
||||
const actionSheetActions = ref<{ name: string; color?: string }[]>([]);
|
||||
const pendingAction = ref<Record<string, () => void>>({});
|
||||
|
||||
function showNoticeActions(item: NoticeItem) {
|
||||
const actions: { name: string; color?: string }[] = [{ name: "查看" }];
|
||||
const actionMap: Record<string, () => void> = {
|
||||
查看: () => openNoticeDetail(item),
|
||||
};
|
||||
|
||||
if (item.publishStatus !== 1) {
|
||||
if (hasPermission("sys:notice:update")) {
|
||||
actions.push({ name: "编辑" });
|
||||
actionMap["编辑"] = () => openNoticeForm(Number(item.id));
|
||||
}
|
||||
if (hasPermission("sys:notice:delete")) {
|
||||
actions.push({ name: "删除", color: "var(--color-danger)" });
|
||||
actionMap["删除"] = async () => {
|
||||
try {
|
||||
await confirm({
|
||||
title: "确认删除",
|
||||
msg: `确定要删除通知「${item.title}」吗?`,
|
||||
type: "warning",
|
||||
});
|
||||
await NoticeAPI.deleteByIds(item.id);
|
||||
toast.success("删除成功");
|
||||
loadNoticeList();
|
||||
} catch {
|
||||
// 用户取消操作
|
||||
}
|
||||
};
|
||||
}
|
||||
if (hasPermission("sys:notice:publish")) {
|
||||
actions.push({ name: "发布" });
|
||||
actionMap["发布"] = async () => {
|
||||
try {
|
||||
await confirm({
|
||||
title: "确认发布",
|
||||
msg: `确定要发布通知「${item.title}」吗?`,
|
||||
type: "warning",
|
||||
});
|
||||
await NoticeAPI.publish(Number(item.id));
|
||||
toast.success("发布成功");
|
||||
loadNoticeList();
|
||||
} catch {
|
||||
// 用户取消操作
|
||||
}
|
||||
};
|
||||
}
|
||||
} else {
|
||||
if (hasPermission("sys:notice:revoke")) {
|
||||
actions.push({ name: "撤回", color: "var(--color-warning)" });
|
||||
actionMap["撤回"] = async () => {
|
||||
try {
|
||||
await confirm({
|
||||
title: "确认撤回",
|
||||
msg: `确定要撤回通知「${item.title}」吗?`,
|
||||
type: "warning",
|
||||
});
|
||||
await NoticeAPI.revoke(Number(item.id));
|
||||
toast.success("撤回成功");
|
||||
loadNoticeList();
|
||||
} catch {
|
||||
// 用户取消操作
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
actionSheetActions.value = actions;
|
||||
pendingAction.value = actionMap;
|
||||
actionSheetVisible.value = true;
|
||||
}
|
||||
|
||||
function handleActionSelect({ item }: { item: any }) {
|
||||
pendingAction.value[item.name]?.();
|
||||
}
|
||||
|
||||
onReachBottom(() => {
|
||||
if (queryParams.pageNum * queryParams.pageSize < total.value) {
|
||||
fetchNoticeList();
|
||||
} else {
|
||||
loadMoreState.value = "finished";
|
||||
}
|
||||
});
|
||||
|
||||
onLoad(() => {
|
||||
loadNoticeList();
|
||||
});
|
||||
onLoad(() => {
|
||||
loadNoticeList();
|
||||
});
|
||||
</script>
|
||||
|
||||
<script lang="ts">
|
||||
export default { options: { styleIsolation: "shared" } };
|
||||
export default { options: { styleIsolation: "shared" } };
|
||||
</script>
|
||||
|
||||
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.notice-card__main {
|
||||
flex: 1;
|
||||
}
|
||||
.notice-card__main {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.notice-card__title {
|
||||
font-weight: 700;
|
||||
font-size: 32rpx;
|
||||
}
|
||||
.notice-card__title {
|
||||
font-weight: 700;
|
||||
font-size: 32rpx;
|
||||
}
|
||||
|
||||
.notice-card__publisher {
|
||||
font-size: 24rpx;
|
||||
color: var(--color-text-secondary);
|
||||
}
|
||||
.notice-card__publisher {
|
||||
font-size: 24rpx;
|
||||
color: var(--color-text-secondary);
|
||||
}
|
||||
|
||||
.notice-card__meta {
|
||||
display: flex;
|
||||
gap: 24rpx;
|
||||
margin-top: 12rpx;
|
||||
}
|
||||
.notice-card__meta {
|
||||
display: flex;
|
||||
gap: 24rpx;
|
||||
margin-top: 12rpx;
|
||||
}
|
||||
|
||||
.notice-card__detail {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
min-width: 0;
|
||||
}
|
||||
.notice-card__detail {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.notice-card__detail-text {
|
||||
margin-left: 8rpx;
|
||||
font-size: 24rpx;
|
||||
color: var(--color-text-secondary);
|
||||
}
|
||||
.notice-card__detail-text {
|
||||
margin-left: 8rpx;
|
||||
font-size: 24rpx;
|
||||
color: var(--color-text-secondary);
|
||||
}
|
||||
|
||||
.notice-card__footer {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-top: 16rpx;
|
||||
}
|
||||
.notice-card__footer {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-top: 16rpx;
|
||||
}
|
||||
|
||||
.notice-card__time {
|
||||
font-size: 24rpx;
|
||||
color: var(--color-text-placeholder);
|
||||
}
|
||||
.notice-card__time {
|
||||
font-size: 24rpx;
|
||||
color: var(--color-text-placeholder);
|
||||
}
|
||||
|
||||
.notice-card__action {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 64rpx;
|
||||
height: 64rpx;
|
||||
border-radius: 50%;
|
||||
}
|
||||
.notice-card__action {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 64rpx;
|
||||
height: 64rpx;
|
||||
border-radius: 50%;
|
||||
}
|
||||
|
||||
.notice-card__action--hover {
|
||||
background: rgba(var(--color-text-placeholder-rgb, 148, 163, 184), 0.16);
|
||||
}
|
||||
.notice-card__action--hover {
|
||||
background: rgba(var(--color-text-placeholder-rgb, 148, 163, 184), 0.16);
|
||||
}
|
||||
</style>
|
||||
+182
-209
@@ -17,47 +17,21 @@
|
||||
|
||||
<!-- 可滚动区域:权限树 -->
|
||||
<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"
|
||||
>
|
||||
<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)'"
|
||||
/>
|
||||
<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
|
||||
>
|
||||
<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>
|
||||
@@ -77,216 +51,215 @@
|
||||
|
||||
<script lang="ts" setup>
|
||||
|
||||
import { onLoad } from "@dcloudio/uni-app";
|
||||
import MenuAPI, { type MenuItem } 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";
|
||||
import { onLoad } from "@dcloudio/uni-app";
|
||||
import MenuAPI, { type MenuItem } 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";
|
||||
|
||||
definePage({
|
||||
name: "role-assign-perm",
|
||||
style: { navigationBarTitleText: "分配权限" },
|
||||
});
|
||||
|
||||
const toast = useToast();
|
||||
const isSubmitting = ref(false);
|
||||
const roleId = ref<number>(0);
|
||||
const roleName = ref("");
|
||||
const menuList = ref<MenuItem[]>([]);
|
||||
const checkedKeys = ref<string[]>([]);
|
||||
const toast = useToast();
|
||||
const isSubmitting = ref(false);
|
||||
const roleId = ref<number>(0);
|
||||
const roleName = ref("");
|
||||
const menuList = ref<MenuItem[]>([]);
|
||||
const checkedKeys = ref<string[]>([]);
|
||||
|
||||
// 转换菜单为树结构
|
||||
const menuTree = computed<TreeOption[]>(() => {
|
||||
if (!menuList.value.length) return [];
|
||||
return transformMenuToTree(menuList.value);
|
||||
});
|
||||
|
||||
// 转换菜单为树组件格式
|
||||
function transformMenuToTree(menus: MenuItem[]): 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,
|
||||
};
|
||||
// 转换菜单为树结构
|
||||
const menuTree = computed<TreeOption[]>(() => {
|
||||
if (!menuList.value.length) return [];
|
||||
return transformMenuToTree(menuList.value);
|
||||
});
|
||||
}
|
||||
|
||||
// 处理选中变化
|
||||
function handleCheck(keys: string[]) {
|
||||
checkedKeys.value = keys;
|
||||
}
|
||||
// 转换菜单为树组件格式
|
||||
function transformMenuToTree(menus: MenuItem[]): 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 handleSelectAll() {
|
||||
const allIds = getAllMenuIds(menuList.value);
|
||||
checkedKeys.value = allIds;
|
||||
}
|
||||
// 处理选中变化
|
||||
function handleCheck(keys: string[]) {
|
||||
checkedKeys.value = keys;
|
||||
}
|
||||
|
||||
// 取消全选
|
||||
function handleClearAll() {
|
||||
checkedKeys.value = [];
|
||||
}
|
||||
// 全选
|
||||
function handleSelectAll() {
|
||||
const allIds = getAllMenuIds(menuList.value);
|
||||
checkedKeys.value = allIds;
|
||||
}
|
||||
|
||||
// 获取所有菜单ID
|
||||
function getAllMenuIds(menus: MenuItem[]): string[] {
|
||||
const ids: string[] = [];
|
||||
function traverse(list: MenuItem[]) {
|
||||
for (const menu of list) {
|
||||
if (menu.id) ids.push(String(menu.id));
|
||||
if (menu.children) traverse(menu.children);
|
||||
// 取消全选
|
||||
function handleClearAll() {
|
||||
checkedKeys.value = [];
|
||||
}
|
||||
|
||||
// 获取所有菜单ID
|
||||
function getAllMenuIds(menus: MenuItem[]): string[] {
|
||||
const ids: string[] = [];
|
||||
function traverse(list: MenuItem[]) {
|
||||
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() {
|
||||
isSubmitting.value = true;
|
||||
try {
|
||||
await RoleAPI.updateRoleMenus(roleId.value, checkedKeys.value.map(Number));
|
||||
toast.success("保存成功");
|
||||
uni.navigateBack();
|
||||
} finally {
|
||||
isSubmitting.value = false;
|
||||
}
|
||||
}
|
||||
traverse(menus);
|
||||
return ids;
|
||||
}
|
||||
|
||||
// 取消
|
||||
function handleCancel() {
|
||||
uni.navigateBack();
|
||||
}
|
||||
|
||||
// 提交
|
||||
async function handleSubmit() {
|
||||
isSubmitting.value = true;
|
||||
try {
|
||||
await RoleAPI.updateRoleMenus(roleId.value, checkedKeys.value.map(Number));
|
||||
toast.success("保存成功");
|
||||
uni.navigateBack();
|
||||
} finally {
|
||||
isSubmitting.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("加载失败");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 加载数据
|
||||
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();
|
||||
}
|
||||
});
|
||||
onLoad((query) => {
|
||||
if (query?.id) {
|
||||
roleId.value = Number(query.id);
|
||||
loadData();
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<script lang="ts">
|
||||
export default { options: { styleIsolation: "shared" } };
|
||||
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);
|
||||
.page {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
height: 100vh;
|
||||
background: var(--color-bg);
|
||||
}
|
||||
|
||||
&__value {
|
||||
flex: 1;
|
||||
overflow: hidden;
|
||||
font-size: 28rpx;
|
||||
font-weight: 600;
|
||||
color: var(--color-text);
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
.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);
|
||||
}
|
||||
}
|
||||
|
||||
.action-bar {
|
||||
&__left {
|
||||
.role-bar {
|
||||
display: flex;
|
||||
gap: 16rpx;
|
||||
}
|
||||
}
|
||||
align-items: center;
|
||||
|
||||
.tree-container {
|
||||
flex: 1;
|
||||
height: 0; // 重要:让 flex + scroll-view 生效
|
||||
background: var(--color-bg);
|
||||
}
|
||||
&__label {
|
||||
font-size: 24rpx;
|
||||
color: var(--color-text-secondary);
|
||||
}
|
||||
|
||||
.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);
|
||||
&__value {
|
||||
flex: 1;
|
||||
overflow: hidden;
|
||||
font-size: 28rpx;
|
||||
font-weight: 600;
|
||||
color: var(--color-text);
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.node-content :deep(.wd-tag) {
|
||||
margin-left: auto;
|
||||
}
|
||||
.action-bar {
|
||||
&__left {
|
||||
display: flex;
|
||||
gap: 16rpx;
|
||||
}
|
||||
}
|
||||
|
||||
.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);
|
||||
}
|
||||
.tree-container {
|
||||
flex: 1;
|
||||
height: 0; // 重要:让 flex + scroll-view 生效
|
||||
background: var(--color-bg);
|
||||
}
|
||||
|
||||
.bottom-bar :deep(.wd-button) {
|
||||
flex: 1;
|
||||
}
|
||||
.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);
|
||||
}
|
||||
|
||||
.bottom-bar :deep(.wd-button) {
|
||||
flex: 1;
|
||||
}
|
||||
</style>
|
||||
|
||||
|
||||
+205
-230
@@ -1,22 +1,12 @@
|
||||
<template>
|
||||
<view class="page page--padding">
|
||||
<view>
|
||||
<wd-search
|
||||
v-model="queryParams.keywords"
|
||||
placeholder="搜索角色名称/编码"
|
||||
hide-cancel
|
||||
@search="handleSearch"
|
||||
/>
|
||||
<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)"
|
||||
>
|
||||
<wd-card v-for="item in pageData" :key="item.id" custom-class="item-card" @click="openRoleDialog(item.id)">
|
||||
<!-- 主信息行 -->
|
||||
<view class="flex-start">
|
||||
<view class="role-card__main">
|
||||
@@ -45,11 +35,7 @@
|
||||
<!-- 元信息行 -->
|
||||
<view class="role-card__footer">
|
||||
<text class="role-card__time">{{ item.createTime }}</text>
|
||||
<view
|
||||
class="role-card__action"
|
||||
hover-class="role-card__action--hover"
|
||||
@click.stop="showRoleActions(item)"
|
||||
>
|
||||
<view class="role-card__action" hover-class="role-card__action--hover" @click.stop="showRoleActions(item)">
|
||||
<wd-icon name="more" size="18" class="color-text-secondary" />
|
||||
</view>
|
||||
</view>
|
||||
@@ -60,12 +46,7 @@
|
||||
</view>
|
||||
|
||||
<!-- 弹窗表单 -->
|
||||
<wd-popup
|
||||
v-model="dialog.visible"
|
||||
position="bottom"
|
||||
custom-class="popup-bottom"
|
||||
@close="closeRoleDialog"
|
||||
>
|
||||
<wd-popup v-model="dialog.visible" position="bottom" custom-class="popup-bottom" @close="closeRoleDialog">
|
||||
<view class="p-4">
|
||||
<view class="popup-title">
|
||||
{{ formData.id ? "编辑角色" : "新增角色" }}
|
||||
@@ -78,10 +59,7 @@
|
||||
<wd-input v-model="formData.code" placeholder="请输入角色编码" />
|
||||
</wd-form-item>
|
||||
<wd-form-item prop="dataScope" title="数据权限" required>
|
||||
<wd-select-picker
|
||||
v-model="formData.dataScope"
|
||||
:columns="dataScopeOptions"
|
||||
/>
|
||||
<wd-select-picker v-model="formData.dataScope" :columns="dataScopeOptions" />
|
||||
</wd-form-item>
|
||||
<wd-form-item prop="status" title="状态">
|
||||
<wd-switch v-model="formData.status" :active-value="1" :inactive-value="0" />
|
||||
@@ -101,259 +79,256 @@
|
||||
<wd-fab v-if="hasPermission('sys:role:create') && !dialog.visible" :expandable="false" :gap="{ bottom: 32 }" @click="openRoleDialog()" />
|
||||
|
||||
<!-- 操作菜单 -->
|
||||
<wd-action-sheet
|
||||
v-model="actionSheetVisible"
|
||||
:actions="actionSheetActions"
|
||||
cancel-text="取消"
|
||||
@select="handleActionSelect"
|
||||
/>
|
||||
<wd-action-sheet v-model="actionSheetVisible" :actions="actionSheetActions" cancel-text="取消" @select="handleActionSelect" />
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
definePage({
|
||||
name: "role",
|
||||
style: { navigationBarTitleText: "角色管理" },
|
||||
});
|
||||
|
||||
import { onLoad, onReachBottom } from "@dcloudio/uni-app";
|
||||
import { LoadMoreState } from "@wot-ui/ui/components/wd-loadmore/types";
|
||||
import { toFormSchema } from "@/utils/form";
|
||||
import { useToast, useDialog } from "@wot-ui/ui";
|
||||
import RoleAPI, { type RolePageQuery, RoleItem, RoleForm } from "@/api/role";
|
||||
import { hasPermission } from "@/utils/permission";
|
||||
import { onLoad, onReachBottom } from "@dcloudio/uni-app";
|
||||
import { LoadMoreState } from "@wot-ui/ui/components/wd-loadmore/types";
|
||||
import { toFormSchema } from "@/utils/form";
|
||||
import { useToast, useDialog } from "@wot-ui/ui";
|
||||
import RoleAPI, { type RolePageQuery, RoleItem, RoleForm } from "@/api/role";
|
||||
import { hasPermission } from "@/utils/permission";
|
||||
|
||||
const toast = useToast();
|
||||
definePage({
|
||||
name: "role",
|
||||
style: { navigationBarTitleText: "角色管理" },
|
||||
});
|
||||
|
||||
|
||||
const toast = useToast();
|
||||
const { confirm } = useDialog();
|
||||
const loadMoreState = ref<LoadMoreState>("loading");
|
||||
const formRef = ref();
|
||||
const isSubmitting = ref(false);
|
||||
const loadMoreState = ref<LoadMoreState>("loading");
|
||||
const formRef = ref();
|
||||
const isSubmitting = ref(false);
|
||||
|
||||
const queryParams = reactive<RolePageQuery>({ pageNum: 1, pageSize: 10, keywords: "" });
|
||||
const total = ref(0);
|
||||
const pageData = ref<RoleItem[]>([]);
|
||||
const dialog = reactive({ visible: false });
|
||||
const queryParams = reactive<RolePageQuery>({ pageNum: 1, pageSize: 10, keywords: "" });
|
||||
const total = ref(0);
|
||||
const pageData = ref<RoleItem[]>([]);
|
||||
const dialog = reactive({ visible: false });
|
||||
|
||||
const actionSheetVisible = ref(false);
|
||||
const actionSheetActions = ref<{ name: string; color?: string }[]>([]);
|
||||
const currentActionItem = ref<any>(null);
|
||||
const actionSheetVisible = ref(false);
|
||||
const actionSheetActions = ref<{ name: string; color?: string }[]>([]);
|
||||
const currentActionItem = ref<any>(null);
|
||||
|
||||
const initialFormData: RoleForm = {
|
||||
id: undefined,
|
||||
name: undefined,
|
||||
code: undefined,
|
||||
dataScope: 1,
|
||||
status: 1,
|
||||
sort: 1,
|
||||
};
|
||||
const initialFormData: RoleForm = {
|
||||
id: undefined,
|
||||
name: undefined,
|
||||
code: undefined,
|
||||
dataScope: 1,
|
||||
status: 1,
|
||||
sort: 1,
|
||||
};
|
||||
|
||||
const formData = reactive<RoleForm>({ ...initialFormData });
|
||||
const formData = reactive<RoleForm>({ ...initialFormData });
|
||||
|
||||
const dataScopeOptions = ref<Record<string, any>[]>([
|
||||
{ label: "全部数据", value: 1 },
|
||||
{ label: "部门及子部门数据", value: 2 },
|
||||
{ label: "本部门数据", value: 3 },
|
||||
{ label: "本人数据", value: 4 },
|
||||
{ label: "自定义部门数据", value: 5 },
|
||||
]);
|
||||
const dataScopeOptions = ref<Record<string, any>[]>([
|
||||
{ label: "全部数据", value: 1 },
|
||||
{ label: "部门及子部门数据", value: 2 },
|
||||
{ label: "本部门数据", value: 3 },
|
||||
{ label: "本人数据", value: 4 },
|
||||
{ label: "自定义部门数据", value: 5 },
|
||||
]);
|
||||
|
||||
const rules = toFormSchema({
|
||||
name: [{ required: true, message: "请输入角色名称" }],
|
||||
code: [{ required: true, message: "请输入角色编码" }],
|
||||
dataScope: [{ required: true, message: "请选择数据权限" }],
|
||||
});
|
||||
const rules = toFormSchema({
|
||||
name: [{ required: true, message: "请输入角色名称" }],
|
||||
code: [{ required: true, message: "请输入角色编码" }],
|
||||
dataScope: [{ required: true, message: "请选择数据权限" }],
|
||||
});
|
||||
|
||||
// 搜索触发
|
||||
const handleSearch = () => loadRoleList();
|
||||
// 搜索触发
|
||||
const handleSearch = () => loadRoleList();
|
||||
|
||||
// 加载列表
|
||||
function loadRoleList() {
|
||||
queryParams.pageNum = 1;
|
||||
fetchRoleList();
|
||||
}
|
||||
|
||||
// 分页加载列表
|
||||
function fetchRoleList() {
|
||||
loadMoreState.value = "loading";
|
||||
RoleAPI.getPage(queryParams)
|
||||
.then((data) => {
|
||||
pageData.value = data.list;
|
||||
total.value = data.total;
|
||||
queryParams.pageNum++;
|
||||
})
|
||||
.catch(() => {
|
||||
pageData.value = [];
|
||||
})
|
||||
.finally(() => {
|
||||
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 loadRoleList() {
|
||||
queryParams.pageNum = 1;
|
||||
fetchRoleList();
|
||||
}
|
||||
}
|
||||
|
||||
// 提交表单
|
||||
function submitRoleForm() {
|
||||
formRef.value.validate().then(({ valid }: { valid: boolean }) => {
|
||||
if (!valid) return;
|
||||
isSubmitting.value = true;
|
||||
const action = formData.id ? RoleAPI.update(formData.id, formData) : RoleAPI.add(formData);
|
||||
action
|
||||
.then(() => {
|
||||
toast.success("操作成功");
|
||||
closeRoleDialog();
|
||||
loadRoleList();
|
||||
// 分页加载列表
|
||||
function fetchRoleList() {
|
||||
loadMoreState.value = "loading";
|
||||
RoleAPI.getPage(queryParams)
|
||||
.then((data) => {
|
||||
pageData.value = data.list;
|
||||
total.value = data.total;
|
||||
queryParams.pageNum++;
|
||||
})
|
||||
.catch(() => {
|
||||
pageData.value = [];
|
||||
})
|
||||
.finally(() => {
|
||||
isSubmitting.value = false;
|
||||
loadMoreState.value = "finished";
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// 关闭弹窗
|
||||
function closeRoleDialog() {
|
||||
dialog.visible = false;
|
||||
formRef.value?.reset();
|
||||
Object.assign(formData, initialFormData);
|
||||
}
|
||||
// 打开弹窗(新增/编辑)
|
||||
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 handleActionSelect({ item }: { item: any }) {
|
||||
const value = item.name;
|
||||
const role = currentActionItem.value;
|
||||
if (value === "编辑") {
|
||||
openRoleDialog(role.id);
|
||||
} else if (value === "分配权限") {
|
||||
handleAssignPerm(role.id);
|
||||
} else if (value === "删除") {
|
||||
confirm({
|
||||
title: "确认删除",
|
||||
msg: `确定要删除角色「${role.name}」吗?`,
|
||||
headerImage: "warning",
|
||||
}).then(async () => {
|
||||
await RoleAPI.deleteByIds(String(item.id));
|
||||
toast.success("删除成功");
|
||||
loadRoleList();
|
||||
// 提交表单
|
||||
function submitRoleForm() {
|
||||
formRef.value.validate().then(({ valid }: { valid: boolean }) => {
|
||||
if (!valid) return;
|
||||
isSubmitting.value = true;
|
||||
const action = formData.id ? RoleAPI.update(formData.id, formData) : RoleAPI.add(formData);
|
||||
action
|
||||
.then(() => {
|
||||
toast.success("操作成功");
|
||||
closeRoleDialog();
|
||||
loadRoleList();
|
||||
})
|
||||
.finally(() => {
|
||||
isSubmitting.value = false;
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// 更多操作
|
||||
function showRoleActions(item: RoleItem) {
|
||||
const actions: { name: string; color?: string }[] = [];
|
||||
|
||||
if (hasPermission("sys:role:update")) {
|
||||
actions.push({ name: "编辑" });
|
||||
// 关闭弹窗
|
||||
function closeRoleDialog() {
|
||||
dialog.visible = false;
|
||||
formRef.value?.reset();
|
||||
Object.assign(formData, initialFormData);
|
||||
}
|
||||
|
||||
if (hasPermission("sys:role:assign")) {
|
||||
actions.push({ name: "分配权限" });
|
||||
// 操作菜单分发
|
||||
function handleActionSelect({ item }: { item: any }) {
|
||||
const value = item.name;
|
||||
const role = currentActionItem.value;
|
||||
if (value === "编辑") {
|
||||
openRoleDialog(role.id);
|
||||
} else if (value === "分配权限") {
|
||||
handleAssignPerm(role.id);
|
||||
} else if (value === "删除") {
|
||||
confirm({
|
||||
title: "确认删除",
|
||||
msg: `确定要删除角色「${role.name}」吗?`,
|
||||
headerImage: "warning",
|
||||
}).then(async () => {
|
||||
await RoleAPI.deleteByIds(String(item.id));
|
||||
toast.success("删除成功");
|
||||
loadRoleList();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (hasPermission("sys:role:delete")) {
|
||||
actions.push({ name: "删除", color: "var(--color-danger)" });
|
||||
// 更多操作
|
||||
function showRoleActions(item: RoleItem) {
|
||||
const actions: { name: string; color?: string }[] = [];
|
||||
|
||||
if (hasPermission("sys:role:update")) {
|
||||
actions.push({ name: "编辑" });
|
||||
}
|
||||
|
||||
if (hasPermission("sys:role:assign")) {
|
||||
actions.push({ name: "分配权限" });
|
||||
}
|
||||
|
||||
if (hasPermission("sys:role:delete")) {
|
||||
actions.push({ name: "删除", color: "var(--color-danger)" });
|
||||
}
|
||||
|
||||
if (actions.length === 0) {
|
||||
toast.warning("暂无操作权限");
|
||||
return;
|
||||
}
|
||||
|
||||
currentActionItem.value = item;
|
||||
actionSheetActions.value = actions;
|
||||
actionSheetVisible.value = true;
|
||||
}
|
||||
|
||||
if (actions.length === 0) {
|
||||
toast.warning("暂无操作权限");
|
||||
return;
|
||||
// 分配权限
|
||||
function handleAssignPerm(id: number) {
|
||||
uni.navigateTo({
|
||||
url: "/pages/work/role/assign-perm?id=" + id,
|
||||
});
|
||||
}
|
||||
|
||||
currentActionItem.value = item;
|
||||
actionSheetActions.value = actions;
|
||||
actionSheetVisible.value = true;
|
||||
}
|
||||
|
||||
// 分配权限
|
||||
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";
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
onReachBottom(() => {
|
||||
if (queryParams.pageNum * queryParams.pageSize < total.value) {
|
||||
fetchRoleList();
|
||||
} else {
|
||||
loadMoreState.value = "finished";
|
||||
}
|
||||
});
|
||||
|
||||
onLoad(() => {
|
||||
loadRoleList();
|
||||
});
|
||||
onLoad(() => {
|
||||
loadRoleList();
|
||||
});
|
||||
</script>
|
||||
|
||||
<script lang="ts">
|
||||
export default { options: { styleIsolation: "shared" } };
|
||||
export default { options: { styleIsolation: "shared" } };
|
||||
</script>
|
||||
|
||||
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.role-card__main {
|
||||
flex: 1;
|
||||
}
|
||||
.role-card__main {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.role-card__name {
|
||||
font-weight: 700;
|
||||
font-size: 32rpx;
|
||||
}
|
||||
.role-card__name {
|
||||
font-weight: 700;
|
||||
font-size: 32rpx;
|
||||
}
|
||||
|
||||
.role-card__code {
|
||||
font-size: 24rpx;
|
||||
color: var(--color-text-secondary);
|
||||
}
|
||||
.role-card__code {
|
||||
font-size: 24rpx;
|
||||
color: var(--color-text-secondary);
|
||||
}
|
||||
|
||||
.role-card__meta {
|
||||
display: flex;
|
||||
gap: 24rpx;
|
||||
margin-top: 12rpx;
|
||||
}
|
||||
.role-card__meta {
|
||||
display: flex;
|
||||
gap: 24rpx;
|
||||
margin-top: 12rpx;
|
||||
}
|
||||
|
||||
.role-card__detail {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
min-width: 0;
|
||||
}
|
||||
.role-card__detail {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.role-card__detail-text {
|
||||
margin-left: 8rpx;
|
||||
font-size: 24rpx;
|
||||
color: var(--color-text-secondary);
|
||||
}
|
||||
.role-card__detail-text {
|
||||
margin-left: 8rpx;
|
||||
font-size: 24rpx;
|
||||
color: var(--color-text-secondary);
|
||||
}
|
||||
|
||||
.role-card__footer {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-top: 16rpx;
|
||||
}
|
||||
.role-card__footer {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-top: 16rpx;
|
||||
}
|
||||
|
||||
.role-card__time {
|
||||
font-size: 24rpx;
|
||||
color: var(--color-text-placeholder);
|
||||
}
|
||||
.role-card__time {
|
||||
font-size: 24rpx;
|
||||
color: var(--color-text-placeholder);
|
||||
}
|
||||
|
||||
.role-card__action {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 88rpx;
|
||||
height: 88rpx;
|
||||
border-radius: 50%;
|
||||
}
|
||||
.role-card__action {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 88rpx;
|
||||
height: 88rpx;
|
||||
border-radius: 50%;
|
||||
}
|
||||
|
||||
.role-card__action--hover {
|
||||
background: rgba(var(--color-text-placeholder-rgb, 148, 163, 184), 0.16);
|
||||
}
|
||||
.role-card__action--hover {
|
||||
background: rgba(var(--color-text-placeholder-rgb, 148, 163, 184), 0.16);
|
||||
}
|
||||
</style>
|
||||
+356
-416
@@ -1,24 +1,14 @@
|
||||
<template>
|
||||
<view class="page page--padding">
|
||||
<view>
|
||||
<wd-search
|
||||
v-model="queryParams.keywords"
|
||||
placeholder="搜索用户名/手机号"
|
||||
hide-cancel
|
||||
@search="handleSearch"
|
||||
/>
|
||||
<wd-search v-model="queryParams.keywords" placeholder="搜索用户名/手机号" hide-cancel @search="handleSearch" />
|
||||
</view>
|
||||
|
||||
<!-- 排序筛选:搜索框→筛选 12rpx -->
|
||||
<view class="filter-bar" @click="closeOutside">
|
||||
<view class="flex-1">
|
||||
<wd-drop-menu>
|
||||
<wd-drop-menu-item
|
||||
v-model="sortValue"
|
||||
title="排序"
|
||||
:options="sortOptions"
|
||||
@change="handleSortChange"
|
||||
/>
|
||||
<wd-drop-menu-item v-model="sortValue" title="排序" :options="sortOptions" @change="handleSortChange" />
|
||||
</wd-drop-menu>
|
||||
</view>
|
||||
<wd-divider vertical />
|
||||
@@ -26,11 +16,7 @@
|
||||
<wd-drop-menu>
|
||||
<wd-drop-menu-item title="筛选" @open="handleFilterOpen">
|
||||
<view class="p-4">
|
||||
<wd-input
|
||||
v-model="queryParams.keywords"
|
||||
label="关键字"
|
||||
placeholder="用户名/昵称/手机号"
|
||||
/>
|
||||
<wd-input v-model="queryParams.keywords" label="关键字" placeholder="用户名/昵称/手机号" />
|
||||
<cu-date-query v-model="queryParams.createTime" label="创建时间" />
|
||||
<view class="popup-actions">
|
||||
<wd-button type="info" variant="plain" @click="resetUserFilter">重置</wd-button>
|
||||
@@ -44,30 +30,15 @@
|
||||
|
||||
<!-- 用户列表:筛选→列表 16rpx -->
|
||||
<view class="mt-16rpx">
|
||||
<wd-card
|
||||
v-for="item in pageData"
|
||||
:key="item.id"
|
||||
custom-class="item-card"
|
||||
@click="openUserDialog(item.id)"
|
||||
>
|
||||
<wd-card v-for="item in pageData" :key="item.id" custom-class="item-card" @click="openUserDialog(item.id)">
|
||||
<!-- 主信息行 -->
|
||||
<view class="flex-start">
|
||||
<image class="user-card__avatar" :src="item.avatar" mode="aspectFill" lazy-load />
|
||||
<view class="user-card__main">
|
||||
<view class="flex-start mt-12rpx">
|
||||
<text class="user-card__name">{{ item.nickname }}</text>
|
||||
<wd-icon
|
||||
v-if="item.gender === 1"
|
||||
name="gender-male"
|
||||
color="var(--color-primary)"
|
||||
class="ml-8rpx"
|
||||
/>
|
||||
<wd-icon
|
||||
v-else-if="item.gender === 2"
|
||||
name="gender-female"
|
||||
color="var(--color-danger)"
|
||||
class="ml-8rpx"
|
||||
/>
|
||||
<wd-icon v-if="item.gender === 1" name="gender-male" color="var(--color-primary)" class="ml-8rpx" />
|
||||
<wd-icon v-else-if="item.gender === 2" name="gender-female" color="var(--color-danger)" class="ml-8rpx" />
|
||||
</view>
|
||||
<text class="user-card__role">{{ item.roleNames }} · {{ item.deptName }}</text>
|
||||
</view>
|
||||
@@ -91,11 +62,7 @@
|
||||
<!-- 元信息行 -->
|
||||
<view class="user-card__footer">
|
||||
<text class="user-card__time">{{ item.createTime }}</text>
|
||||
<view
|
||||
class="user-card__action"
|
||||
hover-class="user-card__action--hover"
|
||||
@click.stop="showUserActions(item)"
|
||||
>
|
||||
<view class="user-card__action" hover-class="user-card__action--hover" @click.stop="showUserActions(item)">
|
||||
<wd-icon name="more" size="18" class="color-text-secondary" />
|
||||
</view>
|
||||
</view>
|
||||
@@ -106,41 +73,24 @@
|
||||
</view>
|
||||
|
||||
<!-- 弹窗表单 -->
|
||||
<wd-popup
|
||||
v-model="dialog.visible"
|
||||
position="bottom"
|
||||
custom-class="popup-bottom"
|
||||
@close="closeUserDialog"
|
||||
>
|
||||
<wd-popup v-model="dialog.visible" position="bottom" custom-class="popup-bottom" @close="closeUserDialog">
|
||||
<view class="p-4">
|
||||
<view class="popup-title">
|
||||
{{ formData.id ? "编辑用户" : "新增用户" }}
|
||||
</view>
|
||||
<wd-form ref="formRef" :model="formData" :schema="rules">
|
||||
<wd-form-item prop="username" title="用户名" required>
|
||||
<wd-input
|
||||
v-model="formData.username"
|
||||
placeholder="请输入用户名"
|
||||
:readonly="!!formData.id"
|
||||
/>
|
||||
<wd-input v-model="formData.username" placeholder="请输入用户名" :readonly="!!formData.id" />
|
||||
</wd-form-item>
|
||||
<wd-form-item prop="nickname" title="昵称" required>
|
||||
<wd-input v-model="formData.nickname" placeholder="请输入昵称" />
|
||||
</wd-form-item>
|
||||
<wd-form-item prop="deptId" title="部门" required>
|
||||
<wd-cascader
|
||||
v-model="deptSelected"
|
||||
:columns="deptColumns"
|
||||
:column-change="handleDeptColumnChange"
|
||||
:display-format="displayDeptFormat"
|
||||
@confirm="handleDeptConfirm"
|
||||
/>
|
||||
<wd-cascader v-model="deptSelected" :columns="deptColumns" :column-change="handleDeptColumnChange"
|
||||
:display-format="displayDeptFormat" @confirm="handleDeptConfirm" />
|
||||
</wd-form-item>
|
||||
<wd-form-item prop="roleIds" title="角色" required>
|
||||
<wd-select-picker
|
||||
v-model="formData.roleIds"
|
||||
:columns="roleOptions"
|
||||
/>
|
||||
<wd-select-picker v-model="formData.roleIds" :columns="roleOptions" />
|
||||
</wd-form-item>
|
||||
<wd-form-item prop="mobile" title="手机号">
|
||||
<wd-input v-model="formData.mobile" placeholder="请输入手机号" />
|
||||
@@ -163,12 +113,7 @@
|
||||
<wd-fab :expandable="false" :gap="{ bottom: 100 }" @click="openUserDialog()" />
|
||||
|
||||
<!-- 操作菜单 -->
|
||||
<wd-action-sheet
|
||||
v-model="actionSheetVisible"
|
||||
:actions="actionSheetActions"
|
||||
cancel-text="取消"
|
||||
@select="handleActionSelect"
|
||||
/>
|
||||
<wd-action-sheet v-model="actionSheetVisible" :actions="actionSheetActions" cancel-text="取消" @select="handleActionSelect" />
|
||||
|
||||
<!-- 重置密码弹窗 -->
|
||||
<wd-popup v-model="resetPwdDialog.visible" position="bottom" custom-class="popup-bottom">
|
||||
@@ -176,19 +121,12 @@
|
||||
<view class="popup-title">重置密码</view>
|
||||
<wd-form ref="resetPwdFormRef" :model="resetPwdForm">
|
||||
<wd-form-item prop="password" title="新密码" required>
|
||||
<wd-input
|
||||
v-model="resetPwdForm.password"
|
||||
placeholder="请输入新密码(至少6位)"
|
||||
/>
|
||||
<wd-input v-model="resetPwdForm.password" placeholder="请输入新密码(至少6位)" />
|
||||
</wd-form-item>
|
||||
</wd-form>
|
||||
<view class="popup-actions">
|
||||
<wd-button type="info" variant="plain" @click="resetPwdDialog.visible = false">取消</wd-button>
|
||||
<wd-button
|
||||
type="primary"
|
||||
:loading="resetPwdDialog.isSubmitting"
|
||||
@click="handleResetPassword"
|
||||
>
|
||||
<wd-button type="primary" :loading="resetPwdDialog.isSubmitting" @click="handleResetPassword">
|
||||
确认
|
||||
</wd-button>
|
||||
</view>
|
||||
@@ -198,402 +136,404 @@
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
definePage({
|
||||
name: "user",
|
||||
style: { navigationBarTitleText: "用户管理" },
|
||||
});
|
||||
|
||||
import { onLoad, onReachBottom } from "@dcloudio/uni-app";
|
||||
import { LoadMoreState } from "@wot-ui/ui/components/wd-loadmore/types";
|
||||
import { toFormSchema } from "@/utils/form";
|
||||
import { useQueue, useToast, useDialog } from "@wot-ui/ui";
|
||||
import UserAPI, { type UserPageQuery, UserItem, UserForm } from "@/api/user";
|
||||
import RoleAPI from "@/api/role";
|
||||
import DeptAPI from "@/api/dept";
|
||||
import { hasPermission } from "@/utils/permission";
|
||||
import { onLoad, onReachBottom } from "@dcloudio/uni-app";
|
||||
import { LoadMoreState } from "@wot-ui/ui/components/wd-loadmore/types";
|
||||
import { toFormSchema } from "@/utils/form";
|
||||
import { useQueue, useToast, useDialog } from "@wot-ui/ui";
|
||||
import UserAPI, { type UserPageQuery, UserItem, UserForm } from "@/api/user";
|
||||
import RoleAPI from "@/api/role";
|
||||
import DeptAPI from "@/api/dept";
|
||||
import { hasPermission } from "@/utils/permission";
|
||||
|
||||
const toast = useToast();
|
||||
definePage({
|
||||
name: "user",
|
||||
style: { navigationBarTitleText: "用户管理" },
|
||||
});
|
||||
|
||||
|
||||
const toast = useToast();
|
||||
const { confirm } = useDialog();
|
||||
const { closeOutside } = useQueue();
|
||||
const loadMoreState = ref<LoadMoreState>("loading");
|
||||
const formRef = ref();
|
||||
const isSubmitting = ref(false);
|
||||
const { closeOutside } = useQueue();
|
||||
const loadMoreState = ref<LoadMoreState>("loading");
|
||||
const formRef = ref();
|
||||
const isSubmitting = ref(false);
|
||||
|
||||
const sortValue = ref(0);
|
||||
const sortOptions = ref([
|
||||
{ label: "默认排序", value: 0 },
|
||||
{ label: "最近创建", value: 1 },
|
||||
{ label: "最近更新", value: 2 },
|
||||
]);
|
||||
const sortValue = ref(0);
|
||||
const sortOptions = ref([
|
||||
{ label: "默认排序", value: 0 },
|
||||
{ label: "最近创建", value: 1 },
|
||||
{ label: "最近更新", value: 2 },
|
||||
]);
|
||||
|
||||
const queryParams = reactive<UserPageQuery>({ pageNum: 1, pageSize: 10, keywords: "" });
|
||||
const total = ref(0);
|
||||
const pageData = ref<UserItem[]>([]);
|
||||
const dialog = reactive({ visible: false });
|
||||
const queryParams = reactive<UserPageQuery>({ pageNum: 1, pageSize: 10, keywords: "" });
|
||||
const total = ref(0);
|
||||
const pageData = ref<UserItem[]>([]);
|
||||
const dialog = reactive({ visible: false });
|
||||
|
||||
const initialFormData: UserForm = {
|
||||
id: undefined,
|
||||
roleIds: [],
|
||||
username: undefined,
|
||||
nickname: undefined,
|
||||
deptId: undefined,
|
||||
mobile: undefined,
|
||||
email: undefined,
|
||||
status: 1,
|
||||
};
|
||||
const initialFormData: UserForm = {
|
||||
id: undefined,
|
||||
roleIds: [],
|
||||
username: undefined,
|
||||
nickname: undefined,
|
||||
deptId: undefined,
|
||||
mobile: undefined,
|
||||
email: undefined,
|
||||
status: 1,
|
||||
};
|
||||
|
||||
const formData = reactive<UserForm>({ ...initialFormData });
|
||||
const roleOptions = ref<Record<string, any>[]>([]);
|
||||
const deptOptions = ref<OptionType[]>([]);
|
||||
const formData = reactive<UserForm>({ ...initialFormData });
|
||||
const roleOptions = ref<Record<string, any>[]>([]);
|
||||
const deptOptions = ref<OptionType[]>([]);
|
||||
|
||||
// 部门多列选择器数据
|
||||
const deptSelected = ref<(string | number)[]>([]);
|
||||
const deptColumns = ref<Record<string, any>[][]>([]);
|
||||
// 部门多列选择器数据
|
||||
const deptSelected = ref<(string | number)[]>([]);
|
||||
const deptColumns = ref<Record<string, any>[][]>([]);
|
||||
|
||||
// 格式化部门展示
|
||||
const displayDeptFormat = (selectedItems: Record<string, any>[]) => {
|
||||
return selectedItems.map((item) => item.label).join("/");
|
||||
};
|
||||
// 格式化部门展示
|
||||
const displayDeptFormat = (selectedItems: Record<string, any>[]) => {
|
||||
return selectedItems.map((item) => item.label).join("/");
|
||||
};
|
||||
|
||||
// 查找部门在树中的完整路径
|
||||
function findDeptPath(data: any[], targetId: string, path: string[] = []): string[] | null {
|
||||
for (const item of data) {
|
||||
const currentPath = [...path, item.value];
|
||||
if (item.value === targetId) {
|
||||
return currentPath;
|
||||
// 查找部门在树中的完整路径
|
||||
function findDeptPath(data: any[], targetId: string, path: string[] = []): string[] | null {
|
||||
for (const item of data) {
|
||||
const currentPath = [...path, item.value];
|
||||
if (item.value === targetId) {
|
||||
return currentPath;
|
||||
}
|
||||
if (item.children && item.children.length > 0) {
|
||||
const found = findDeptPath(item.children, targetId, currentPath);
|
||||
if (found) return found;
|
||||
}
|
||||
}
|
||||
if (item.children && item.children.length > 0) {
|
||||
const found = findDeptPath(item.children, targetId, currentPath);
|
||||
if (found) return found;
|
||||
return null;
|
||||
}
|
||||
|
||||
// 部门列变化(动态加载子部门)
|
||||
const handleDeptColumnChange = ({ selectedItem, resolve, finish }: any) => {
|
||||
const children = selectedItem.children;
|
||||
if (children && children.length > 0) {
|
||||
resolve(children);
|
||||
} else {
|
||||
finish();
|
||||
}
|
||||
};
|
||||
|
||||
// 部门确认选择
|
||||
const handleDeptConfirm = ({ value, selectedItems }: any) => {
|
||||
deptSelected.value = value;
|
||||
// 取最后一个选中的部门ID
|
||||
formData.deptId = value[value.length - 1];
|
||||
};
|
||||
|
||||
const rules = toFormSchema({
|
||||
username: [{ required: true, message: "请输入用户名" }],
|
||||
nickname: [{ required: true, message: "请输入昵称" }],
|
||||
roleIds: [{ required: true, message: "请选择角色" }],
|
||||
deptId: [{ required: true, message: "请选择部门" }],
|
||||
});
|
||||
|
||||
// 排序切换
|
||||
const handleSortChange = ({ value }: { value: string | number }) => {
|
||||
const num = Number(value);
|
||||
if (num === 1) {
|
||||
queryParams.field = "create_time";
|
||||
queryParams.direction = "desc";
|
||||
} else if (num === 2) {
|
||||
queryParams.field = "update_time";
|
||||
queryParams.direction = "desc";
|
||||
} else {
|
||||
queryParams.field = "";
|
||||
queryParams.direction = "";
|
||||
}
|
||||
loadUserList();
|
||||
};
|
||||
|
||||
const handleFilterOpen = () => { };
|
||||
|
||||
// 搜索触发
|
||||
const handleSearch = () => loadUserList();
|
||||
|
||||
// 加载列表
|
||||
function loadUserList() {
|
||||
queryParams.pageNum = 1;
|
||||
fetchUserList();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// 部门列变化(动态加载子部门)
|
||||
const handleDeptColumnChange = ({ selectedItem, resolve, finish }: any) => {
|
||||
const children = selectedItem.children;
|
||||
if (children && children.length > 0) {
|
||||
resolve(children);
|
||||
} else {
|
||||
finish();
|
||||
// 应用筛选并刷新
|
||||
function applyUserFilter() {
|
||||
closeOutside();
|
||||
loadUserList();
|
||||
}
|
||||
};
|
||||
|
||||
// 部门确认选择
|
||||
const handleDeptConfirm = ({ value, selectedItems }: any) => {
|
||||
deptSelected.value = value;
|
||||
// 取最后一个选中的部门ID
|
||||
formData.deptId = value[value.length - 1];
|
||||
};
|
||||
|
||||
const rules = toFormSchema({
|
||||
username: [{ required: true, message: "请输入用户名" }],
|
||||
nickname: [{ required: true, message: "请输入昵称" }],
|
||||
roleIds: [{ required: true, message: "请选择角色" }],
|
||||
deptId: [{ required: true, message: "请选择部门" }],
|
||||
});
|
||||
|
||||
// 排序切换
|
||||
const handleSortChange = ({ value }: { value: string | number }) => {
|
||||
const num = Number(value);
|
||||
if (num === 1) {
|
||||
queryParams.field = "create_time";
|
||||
queryParams.direction = "desc";
|
||||
} else if (num === 2) {
|
||||
queryParams.field = "update_time";
|
||||
queryParams.direction = "desc";
|
||||
} else {
|
||||
// 重置筛选并刷新
|
||||
function resetUserFilter() {
|
||||
queryParams.keywords = "";
|
||||
delete queryParams.createTime;
|
||||
queryParams.field = "";
|
||||
queryParams.direction = "";
|
||||
sortValue.value = 0;
|
||||
applyUserFilter();
|
||||
}
|
||||
loadUserList();
|
||||
};
|
||||
|
||||
const handleFilterOpen = () => {};
|
||||
// 分页加载列表
|
||||
function fetchUserList() {
|
||||
loadMoreState.value = "loading";
|
||||
UserAPI.getPage(queryParams)
|
||||
.then((data: any) => {
|
||||
pageData.value = data.list;
|
||||
total.value = data.total;
|
||||
queryParams.pageNum++;
|
||||
})
|
||||
.catch(() => {
|
||||
pageData.value = [];
|
||||
})
|
||||
.finally(() => {
|
||||
loadMoreState.value = "finished";
|
||||
});
|
||||
}
|
||||
|
||||
// 搜索触发
|
||||
const handleSearch = () => loadUserList();
|
||||
// 打开弹窗(新增/编辑)
|
||||
async function openUserDialog(id?: number) {
|
||||
formRef.value?.reset();
|
||||
Object.assign(formData, initialFormData);
|
||||
deptSelected.value = [];
|
||||
dialog.visible = true;
|
||||
roleOptions.value = await RoleAPI.getOptions();
|
||||
const deptData = await DeptAPI.getOptions();
|
||||
deptOptions.value = deptData;
|
||||
|
||||
// 加载列表
|
||||
function loadUserList() {
|
||||
queryParams.pageNum = 1;
|
||||
fetchUserList();
|
||||
}
|
||||
// 应用筛选并刷新
|
||||
function applyUserFilter() {
|
||||
closeOutside();
|
||||
loadUserList();
|
||||
}
|
||||
// 重置筛选并刷新
|
||||
function resetUserFilter() {
|
||||
queryParams.keywords = "";
|
||||
delete queryParams.createTime;
|
||||
queryParams.field = "";
|
||||
queryParams.direction = "";
|
||||
sortValue.value = 0;
|
||||
applyUserFilter();
|
||||
}
|
||||
|
||||
// 分页加载列表
|
||||
function fetchUserList() {
|
||||
loadMoreState.value = "loading";
|
||||
UserAPI.getPage(queryParams)
|
||||
.then((data: any) => {
|
||||
pageData.value = data.list;
|
||||
total.value = data.total;
|
||||
queryParams.pageNum++;
|
||||
})
|
||||
.catch(() => {
|
||||
pageData.value = [];
|
||||
})
|
||||
.finally(() => {
|
||||
loadMoreState.value = "finished";
|
||||
});
|
||||
}
|
||||
|
||||
// 打开弹窗(新增/编辑)
|
||||
async function openUserDialog(id?: number) {
|
||||
formRef.value?.reset();
|
||||
Object.assign(formData, initialFormData);
|
||||
deptSelected.value = [];
|
||||
dialog.visible = true;
|
||||
roleOptions.value = await RoleAPI.getOptions();
|
||||
const deptData = await DeptAPI.getOptions();
|
||||
deptOptions.value = deptData;
|
||||
|
||||
if (id) {
|
||||
formData.id = id;
|
||||
const data = await UserAPI.getFormData(id);
|
||||
Object.assign(formData, data, { id });
|
||||
// 编辑时回显部门选择(需要完整路径和预加载所有层级数据)
|
||||
if (data.deptId) {
|
||||
const path = findDeptPath(deptData, String(data.deptId));
|
||||
if (path) {
|
||||
deptSelected.value = path;
|
||||
// 预加载所有层级的 columns
|
||||
const columns: any[] = [deptData];
|
||||
let currentLevel = deptData;
|
||||
for (let i = 0; i < path.length - 1; i++) {
|
||||
const found = currentLevel.find((item: any) => item.value === path[i]);
|
||||
if (found && found.children) {
|
||||
columns.push(found.children);
|
||||
currentLevel = found.children;
|
||||
if (id) {
|
||||
formData.id = id;
|
||||
const data = await UserAPI.getFormData(id);
|
||||
Object.assign(formData, data, { id });
|
||||
// 编辑时回显部门选择(需要完整路径和预加载所有层级数据)
|
||||
if (data.deptId) {
|
||||
const path = findDeptPath(deptData, String(data.deptId));
|
||||
if (path) {
|
||||
deptSelected.value = path;
|
||||
// 预加载所有层级的 columns
|
||||
const columns: any[] = [deptData];
|
||||
let currentLevel = deptData;
|
||||
for (let i = 0; i < path.length - 1; i++) {
|
||||
const found = currentLevel.find((item: any) => item.value === path[i]);
|
||||
if (found && found.children) {
|
||||
columns.push(found.children);
|
||||
currentLevel = found.children;
|
||||
}
|
||||
}
|
||||
deptColumns.value = columns;
|
||||
} else {
|
||||
deptSelected.value = [String(data.deptId)];
|
||||
deptColumns.value = [deptData];
|
||||
}
|
||||
deptColumns.value = columns;
|
||||
} else {
|
||||
deptSelected.value = [String(data.deptId)];
|
||||
deptColumns.value = [deptData];
|
||||
}
|
||||
} else {
|
||||
deptColumns.value = [deptData];
|
||||
}
|
||||
} else {
|
||||
deptColumns.value = [deptData];
|
||||
}
|
||||
}
|
||||
|
||||
// 提交表单
|
||||
function submitUserForm() {
|
||||
formRef.value.validate().then(({ valid }: { valid: boolean }) => {
|
||||
if (!valid) return;
|
||||
isSubmitting.value = true;
|
||||
const action = formData.id ? UserAPI.update(formData.id, formData) : UserAPI.add(formData);
|
||||
action
|
||||
.then(() => {
|
||||
toast.success("操作成功");
|
||||
closeUserDialog();
|
||||
loadUserList();
|
||||
})
|
||||
.finally(() => {
|
||||
isSubmitting.value = false;
|
||||
});
|
||||
// 提交表单
|
||||
function submitUserForm() {
|
||||
formRef.value.validate().then(({ valid }: { valid: boolean }) => {
|
||||
if (!valid) return;
|
||||
isSubmitting.value = true;
|
||||
const action = formData.id ? UserAPI.update(formData.id, formData) : UserAPI.add(formData);
|
||||
action
|
||||
.then(() => {
|
||||
toast.success("操作成功");
|
||||
closeUserDialog();
|
||||
loadUserList();
|
||||
})
|
||||
.finally(() => {
|
||||
isSubmitting.value = false;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// 关闭弹窗
|
||||
function closeUserDialog() {
|
||||
dialog.visible = false;
|
||||
formRef.value?.reset();
|
||||
Object.assign(formData, initialFormData);
|
||||
}
|
||||
|
||||
const actionSheetVisible = ref(false);
|
||||
const actionSheetActions = ref<{ name: string; color?: string }[]>([]);
|
||||
const pendingAction = ref<Record<string, () => void>>({});
|
||||
|
||||
const resetPwdDialog = reactive({
|
||||
visible: false,
|
||||
isSubmitting: false,
|
||||
userId: undefined as number | undefined,
|
||||
});
|
||||
}
|
||||
const resetPwdForm = reactive({ password: "" });
|
||||
const resetPwdFormRef = ref();
|
||||
|
||||
// 关闭弹窗
|
||||
function closeUserDialog() {
|
||||
dialog.visible = false;
|
||||
formRef.value?.reset();
|
||||
Object.assign(formData, initialFormData);
|
||||
}
|
||||
// 更多操作
|
||||
function showUserActions(item: UserItem) {
|
||||
const actions: { name: string; color?: string }[] = [];
|
||||
const actionMap: Record<string, () => void> = {};
|
||||
|
||||
const actionSheetVisible = ref(false);
|
||||
const actionSheetActions = ref<{ name: string; color?: string }[]>([]);
|
||||
const pendingAction = ref<Record<string, () => void>>({});
|
||||
// 重置密码
|
||||
if (hasPermission("sys:user:reset-password")) {
|
||||
actions.push({ name: "重置密码" });
|
||||
actionMap["重置密码"] = () => openResetPwdDialog(item);
|
||||
}
|
||||
|
||||
const resetPwdDialog = reactive({
|
||||
visible: false,
|
||||
isSubmitting: false,
|
||||
userId: undefined as number | undefined,
|
||||
});
|
||||
const resetPwdForm = reactive({ password: "" });
|
||||
const resetPwdFormRef = ref();
|
||||
// 编辑
|
||||
if (hasPermission("sys:user:update")) {
|
||||
actions.push({ name: "编辑" });
|
||||
actionMap["编辑"] = () => openUserDialog(item.id);
|
||||
}
|
||||
|
||||
// 更多操作
|
||||
function showUserActions(item: UserItem) {
|
||||
const actions: { name: string; color?: string }[] = [];
|
||||
const actionMap: Record<string, () => void> = {};
|
||||
// 删除
|
||||
if (hasPermission("sys:user:delete")) {
|
||||
actions.push({ name: "删除", color: "var(--color-danger)" });
|
||||
actionMap["删除"] = async () => {
|
||||
try {
|
||||
await confirm({
|
||||
title: "确认删除",
|
||||
msg: `确定要删除用户「${item.nickname}」吗?`,
|
||||
headerImage: "warning",
|
||||
});
|
||||
await UserAPI.deleteByIds(String(item.id));
|
||||
toast.success("删除成功");
|
||||
loadUserList();
|
||||
} catch {
|
||||
// 用户取消操作
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
if (actions.length === 0) {
|
||||
toast.warning("暂无操作权限");
|
||||
return;
|
||||
}
|
||||
|
||||
actionSheetActions.value = actions;
|
||||
pendingAction.value = actionMap;
|
||||
actionSheetVisible.value = true;
|
||||
}
|
||||
|
||||
function handleActionSelect({ item }: { item: any }) {
|
||||
pendingAction.value[item.name]?.();
|
||||
}
|
||||
|
||||
// 打开重置密码弹窗
|
||||
function openResetPwdDialog(item: UserItem) {
|
||||
resetPwdForm.password = "";
|
||||
resetPwdDialog.userId = item.id;
|
||||
resetPwdDialog.visible = true;
|
||||
nextTick(() => {
|
||||
resetPwdFormRef.value?.reset();
|
||||
});
|
||||
}
|
||||
|
||||
// 重置密码
|
||||
if (hasPermission("sys:user:reset-password")) {
|
||||
actions.push({ name: "重置密码" });
|
||||
actionMap["重置密码"] = () => openResetPwdDialog(item);
|
||||
async function handleResetPassword() {
|
||||
const valid = await resetPwdFormRef.value?.validate();
|
||||
if (!valid || valid.valid === false) return;
|
||||
if (!resetPwdDialog.userId) return;
|
||||
|
||||
resetPwdDialog.isSubmitting = true;
|
||||
try {
|
||||
await UserAPI.resetPassword(resetPwdDialog.userId, resetPwdForm.password);
|
||||
toast.success("密码重置成功");
|
||||
resetPwdDialog.visible = false;
|
||||
} catch (error) {
|
||||
// API 已处理错误提示
|
||||
} finally {
|
||||
resetPwdDialog.isSubmitting = false;
|
||||
}
|
||||
}
|
||||
|
||||
// 编辑
|
||||
if (hasPermission("sys:user:update")) {
|
||||
actions.push({ name: "编辑" });
|
||||
actionMap["编辑"] = () => openUserDialog(item.id);
|
||||
}
|
||||
|
||||
// 删除
|
||||
if (hasPermission("sys:user:delete")) {
|
||||
actions.push({ name: "删除", color: "var(--color-danger)" });
|
||||
actionMap["删除"] = async () => {
|
||||
try {
|
||||
await confirm({
|
||||
title: "确认删除",
|
||||
msg: `确定要删除用户「${item.nickname}」吗?`,
|
||||
headerImage: "warning",
|
||||
});
|
||||
await UserAPI.deleteByIds(String(item.id));
|
||||
toast.success("删除成功");
|
||||
loadUserList();
|
||||
} catch {
|
||||
// 用户取消操作
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
if (actions.length === 0) {
|
||||
toast.warning("暂无操作权限");
|
||||
return;
|
||||
}
|
||||
|
||||
actionSheetActions.value = actions;
|
||||
pendingAction.value = actionMap;
|
||||
actionSheetVisible.value = true;
|
||||
}
|
||||
|
||||
function handleActionSelect({ item }: { item: any }) {
|
||||
pendingAction.value[item.name]?.();
|
||||
}
|
||||
|
||||
// 打开重置密码弹窗
|
||||
function openResetPwdDialog(item: UserItem) {
|
||||
resetPwdForm.password = "";
|
||||
resetPwdDialog.userId = item.id;
|
||||
resetPwdDialog.visible = true;
|
||||
nextTick(() => {
|
||||
resetPwdFormRef.value?.reset();
|
||||
onReachBottom(() => {
|
||||
if (queryParams.pageNum * queryParams.pageSize < total.value) {
|
||||
fetchUserList();
|
||||
} else {
|
||||
loadMoreState.value = "finished";
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// 重置密码
|
||||
async function handleResetPassword() {
|
||||
const valid = await resetPwdFormRef.value?.validate();
|
||||
if (!valid || valid.valid === false) return;
|
||||
if (!resetPwdDialog.userId) return;
|
||||
|
||||
resetPwdDialog.isSubmitting = true;
|
||||
try {
|
||||
await UserAPI.resetPassword(resetPwdDialog.userId, resetPwdForm.password);
|
||||
toast.success("密码重置成功");
|
||||
resetPwdDialog.visible = false;
|
||||
} catch (error) {
|
||||
// API 已处理错误提示
|
||||
} finally {
|
||||
resetPwdDialog.isSubmitting = false;
|
||||
}
|
||||
}
|
||||
|
||||
onReachBottom(() => {
|
||||
if (queryParams.pageNum * queryParams.pageSize < total.value) {
|
||||
fetchUserList();
|
||||
} else {
|
||||
loadMoreState.value = "finished";
|
||||
}
|
||||
});
|
||||
|
||||
onLoad(() => {
|
||||
loadUserList();
|
||||
});
|
||||
onLoad(() => {
|
||||
loadUserList();
|
||||
});
|
||||
</script>
|
||||
|
||||
<script lang="ts">
|
||||
export default { options: { styleIsolation: "shared" } };
|
||||
export default { options: { styleIsolation: "shared" } };
|
||||
</script>
|
||||
|
||||
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.user-card__avatar {
|
||||
flex-shrink: 0;
|
||||
width: 80rpx;
|
||||
height: 80rpx;
|
||||
border-radius: 50%;
|
||||
}
|
||||
.user-card__avatar {
|
||||
flex-shrink: 0;
|
||||
width: 80rpx;
|
||||
height: 80rpx;
|
||||
border-radius: 50%;
|
||||
}
|
||||
|
||||
.user-card__main {
|
||||
flex: 1;
|
||||
margin-left: 16rpx;
|
||||
}
|
||||
.user-card__main {
|
||||
flex: 1;
|
||||
margin-left: 16rpx;
|
||||
}
|
||||
|
||||
.user-card__name {
|
||||
font-weight: 700;
|
||||
font-size: 32rpx;
|
||||
}
|
||||
.user-card__name {
|
||||
font-weight: 700;
|
||||
font-size: 32rpx;
|
||||
}
|
||||
|
||||
.user-card__role {
|
||||
font-size: 24rpx;
|
||||
color: var(--color-text-secondary);
|
||||
}
|
||||
.user-card__role {
|
||||
font-size: 24rpx;
|
||||
color: var(--color-text-secondary);
|
||||
}
|
||||
|
||||
.user-card__meta {
|
||||
display: flex;
|
||||
gap: 24rpx;
|
||||
margin-top: 12rpx;
|
||||
}
|
||||
.user-card__meta {
|
||||
display: flex;
|
||||
gap: 24rpx;
|
||||
margin-top: 12rpx;
|
||||
}
|
||||
|
||||
.user-card__contact {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
min-width: 0;
|
||||
}
|
||||
.user-card__contact {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.user-card__contact-text {
|
||||
margin-left: 8rpx;
|
||||
font-size: 24rpx;
|
||||
color: var(--color-text-secondary);
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.user-card__contact-text {
|
||||
margin-left: 8rpx;
|
||||
font-size: 24rpx;
|
||||
color: var(--color-text-secondary);
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.user-card__footer {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-top: 16rpx;
|
||||
}
|
||||
.user-card__footer {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-top: 16rpx;
|
||||
}
|
||||
|
||||
.user-card__time {
|
||||
font-size: 24rpx;
|
||||
color: var(--color-text-placeholder);
|
||||
}
|
||||
.user-card__time {
|
||||
font-size: 24rpx;
|
||||
color: var(--color-text-placeholder);
|
||||
}
|
||||
|
||||
.user-card__action {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 88rpx;
|
||||
height: 88rpx;
|
||||
border-radius: 50%;
|
||||
}
|
||||
.user-card__action {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 88rpx;
|
||||
height: 88rpx;
|
||||
border-radius: 50%;
|
||||
}
|
||||
|
||||
.user-card__action--hover {
|
||||
background: rgba(var(--color-text-placeholder-rgb, 148, 163, 184), 0.16);
|
||||
}
|
||||
.user-card__action--hover {
|
||||
background: rgba(var(--color-text-placeholder-rgb, 148, 163, 184), 0.16);
|
||||
}
|
||||
</style>
|
||||
Reference in new issue
Block a user