wip: 临时提交

This commit is contained in:
ray committed 2025-05-28 08:21:01 +08:00
1 parent 54ab9f6f44
commit b2333e8b70
58 files changed
+5078 -4337

No files matched your search

+512
View File
@@ -0,0 +1,512 @@
<template>
<view class="complete-profile-container">
<!-- 头部标题 -->
<view class="header">
<view class="title">完善个人信息</view>
<view class="subtitle">为了给您提供更好的服务,请完善以下信息</view>
</view>
<!-- 表单区域 -->
<view class="form-container">
<wd-form ref="profileFormRef" :model="profileForm">
<!-- 微信小程序专用头像昵称组件 -->
<!-- #ifdef MP-WEIXIN -->
<view class="form-section">
<view class="section-title">基本信息</view>
<WechatProfile v-model="wechatProfileData" @change="onWechatProfileChange" />
</view>
<!-- #endif -->
<!-- 其他平台的头像上传 -->
<!-- #ifndef MP-WEIXIN -->
<!-- 头像上传 -->
<view class="form-section">
<view class="section-title">头像</view>
<view class="avatar-upload" @click="chooseAvatar">
<view v-if="!profileForm.avatar" class="avatar-placeholder">
<wd-icon name="camera" size="40" color="#999" />
<text class="placeholder-text">点击上传头像</text>
</view>
<image v-else :src="profileForm.avatar" class="avatar-preview" mode="aspectFill" />
</view>
</view>
<!-- 昵称输入 -->
<view class="form-section">
<view class="section-title">
昵称
<text class="required">*</text>
</view>
<wd-input
v-model="profileForm.nickname"
placeholder="请输入昵称"
prop="nickname"
:rules="rules.nickname"
custom-class="nickname-input"
/>
</view>
<!-- 性别选择 -->
<view class="form-section">
<view class="section-title">性别</view>
<wd-radio-group v-model="profileForm.gender" shape="button" class="gender-group">
<wd-radio :value="1" class="gender-radio">男</wd-radio>
<wd-radio :value="2" class="gender-radio">女</wd-radio>
</wd-radio-group>
</view>
<!-- #endif -->
<!-- 手机号授权 -->
<view class="form-section">
<view class="section-title">
手机号
<text class="required">*</text>
</view>
<view v-if="!profileForm.mobile" class="phone-auth">
<button
class="phone-auth-btn"
open-type="getPhoneNumber"
:disabled="phoneAuthLoading"
@getphonenumber="onGetPhoneNumber"
>
<wd-icon name="phone" size="20" color="#165DFF" />
<text class="auth-text">{{ phoneAuthLoading ? "授权中..." : "授权获取手机号" }}</text>
</button>
</view>
<view v-else class="phone-display">
<wd-icon name="phone" size="20" color="#52c41a" />
<text class="phone-number">{{ formatPhoneNumber(profileForm.mobile) }}</text>
<text class="change-phone" @click="changePhone">更换</text>
</view>
</view>
</wd-form>
</view>
<!-- 底部按钮 -->
<view class="footer">
<wd-button
class="complete-btn"
type="primary"
size="large"
block
:disabled="!canComplete || loading"
:loading="loading"
@click="handleComplete"
>
完成
</wd-button>
<view class="skip-btn" @click="handleSkip">
<text>暂时跳过</text>
</view>
</view>
<!-- 头像裁剪 -->
<wd-img-cropper
v-model="cropperVisible"
:img-src="originalImageSrc"
@confirm="handleAvatarConfirm"
/>
<wd-toast />
</view>
</template>
<script lang="ts" setup>
import { ref, reactive, computed } from "vue";
import { onLoad } from "@dcloudio/uni-app";
import { useToast } from "wot-design-uni";
import { useUserStore } from "@/store/modules/user";
import UserAPI, { type UserProfileForm } from "@/api/user";
import FileAPI, { type FileInfo } from "@/api/file";
import WechatProfile from "@/components/WechatProfile.vue";
const toast = useToast();
const userStore = useUserStore();
// 页面参数
const redirect = ref("/pages/index/index");
// 表单数据
const profileForm = reactive<UserProfileForm & { mobile?: string }>({
nickname: "",
avatar: "",
gender: 1,
mobile: "",
});
// 微信头像昵称数据
const wechatProfileData = ref({
avatar: "",
nickname: "",
gender: 1,
});
// 表单验证规则
const rules = {
nickname: [
{ required: true, message: "请输入昵称" },
{ required: true, min: 2, max: 20, message: "昵称长度为2-20个字符" },
],
};
// 状态管理
const loading = ref(false);
const phoneAuthLoading = ref(false);
const cropperVisible = ref(false);
const originalImageSrc = ref("");
const profileFormRef = ref();
// 计算属性
const canComplete = computed(() => {
return profileForm.nickname && profileForm.mobile;
});
// 页面加载
onLoad((options: any) => {
if (options?.redirect) {
redirect.value = decodeURIComponent(options.redirect);
}
// 如果用户已有部分信息,预填充
const userInfo = userStore.userInfo;
if (userInfo) {
profileForm.nickname = userInfo.nickname || "";
profileForm.avatar = userInfo.avatar || "";
// 注意:UserInfo接口可能没有gender字段,这里需要安全访问
profileForm.gender = (userInfo as any).gender || 1;
}
});
// 选择头像
const chooseAvatar = () => {
// #ifdef MP-WEIXIN
// 微信小程序使用头像昵称填写能力
uni.chooseMedia({
count: 1,
mediaType: ["image"],
sourceType: ["album", "camera"],
success: (res) => {
originalImageSrc.value = res.tempFiles[0].tempFilePath;
cropperVisible.value = true;
},
fail: (err) => {
console.error("选择图片失败:", err);
toast.error("选择图片失败");
},
});
// #endif
// #ifndef MP-WEIXIN
uni.chooseImage({
count: 1,
sourceType: ["album", "camera"],
success: (res) => {
originalImageSrc.value = res.tempFilePaths[0];
cropperVisible.value = true;
},
fail: (err) => {
console.error("选择图片失败:", err);
toast.error("选择图片失败");
},
});
// #endif
};
// 头像裁剪确认
const handleAvatarConfirm = async (event: any) => {
try {
const { tempFilePath } = event;
toast.loading("上传中...");
const fileInfo: FileInfo = await FileAPI.upload(tempFilePath);
profileForm.avatar = fileInfo.url;
toast.success("头像上传成功");
} catch (error) {
console.error("头像上传失败:", error);
toast.error("头像上传失败");
}
};
// 获取手机号授权
const onGetPhoneNumber = async (e: any) => {
console.log("手机号授权回调:", e);
if (e.detail.errMsg === "getPhoneNumber:ok") {
phoneAuthLoading.value = true;
try {
// 调用后端接口解析手机号
const phoneData = await UserAPI.getPhoneNumber({
code: e.detail.code,
encryptedData: e.detail.encryptedData,
iv: e.detail.iv,
});
profileForm.mobile = phoneData.phoneNumber;
toast.success("手机号授权成功");
} catch (error: any) {
console.error("手机号授权失败:", error);
toast.error(error?.message || "手机号授权失败");
} finally {
phoneAuthLoading.value = false;
}
} else {
toast.error("手机号授权失败");
}
};
// 更换手机号
const changePhone = () => {
profileForm.mobile = "";
};
// 格式化手机号显示
const formatPhoneNumber = (phone: string) => {
if (!phone) return "";
return phone.replace(/(\d{3})\d{4}(\d{4})/, "$1****$2");
};
// 完成信息填写
const handleComplete = async () => {
try {
// 表单验证
const { valid } = await profileFormRef.value.validate();
if (!valid) return;
if (!profileForm.mobile) {
toast.error("请先授权获取手机号");
return;
}
loading.value = true;
// 更新用户信息
await UserAPI.updateProfile({
nickname: profileForm.nickname,
avatar: profileForm.avatar,
gender: profileForm.gender,
});
// 如果有手机号,绑定手机号
if (profileForm.mobile) {
await UserAPI.bindMobile({
mobile: profileForm.mobile,
});
}
// 重新获取用户信息
await userStore.getInfo();
toast.success("信息完善成功");
// 跳转到目标页面
setTimeout(() => {
uni.reLaunch({
url: redirect.value,
});
}, 1000);
} catch (error: any) {
console.error("完善信息失败:", error);
toast.error(error?.message || "完善信息失败");
} finally {
loading.value = false;
}
};
// 跳过完善信息
const handleSkip = () => {
uni.showModal({
title: "提示",
content: "跳过信息完善可能会影响部分功能使用,确定要跳过吗?",
success: (res) => {
if (res.confirm) {
uni.reLaunch({
url: redirect.value,
});
}
},
});
};
// 微信头像昵称变化处理
const onWechatProfileChange = (data: { avatar?: string; nickname?: string; gender?: number }) => {
profileForm.avatar = data.avatar || "";
profileForm.nickname = data.nickname || "";
profileForm.gender = data.gender || 1;
};
</script>
<style lang="scss" scoped>
.complete-profile-container {
min-height: 100vh;
padding: 40rpx 30rpx;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}
.header {
margin-bottom: 60rpx;
text-align: center;
.title {
margin-bottom: 20rpx;
font-size: 48rpx;
font-weight: bold;
color: #fff;
}
.subtitle {
font-size: 28rpx;
line-height: 1.5;
color: rgba(255, 255, 255, 0.8);
}
}
.form-container {
padding: 40rpx;
margin-bottom: 40rpx;
background: #fff;
border-radius: 24rpx;
box-shadow: 0 8rpx 40rpx rgba(0, 0, 0, 0.1);
}
.form-section {
margin-bottom: 40rpx;
&:last-child {
margin-bottom: 0;
}
}
.section-title {
margin-bottom: 20rpx;
font-size: 32rpx;
font-weight: 600;
color: #333;
.required {
color: #ff4757;
}
}
.avatar-upload {
display: flex;
justify-content: center;
.avatar-placeholder {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
width: 160rpx;
height: 160rpx;
background: #f8f9fa;
border: 2rpx dashed #ddd;
border-radius: 50%;
.placeholder-text {
margin-top: 10rpx;
font-size: 24rpx;
color: #999;
}
}
.avatar-preview {
width: 160rpx;
height: 160rpx;
border: 4rpx solid #f0f0f0;
border-radius: 50%;
}
}
.nickname-input {
:deep(.wd-input__inner) {
padding: 24rpx 20rpx;
background: #f8f9fa;
border: 1rpx solid #e9ecef;
border-radius: 12rpx;
}
}
.gender-group {
display: flex;
gap: 20rpx;
.gender-radio {
flex: 1;
:deep(.wd-radio) {
justify-content: center;
width: 100%;
}
}
}
.phone-auth {
.phone-auth-btn {
display: flex;
gap: 12rpx;
align-items: center;
justify-content: center;
width: 100%;
height: 88rpx;
font-size: 28rpx;
color: #fff;
background: linear-gradient(90deg, #165dff, #4080ff);
border: none;
border-radius: 12rpx;
&[disabled] {
opacity: 0.6;
}
.auth-text {
font-size: 28rpx;
}
}
}
.phone-display {
display: flex;
gap: 12rpx;
align-items: center;
padding: 24rpx 20rpx;
background: #f0f9ff;
border: 1rpx solid #bae6fd;
border-radius: 12rpx;
.phone-number {
flex: 1;
font-size: 28rpx;
color: #333;
}
.change-phone {
font-size: 26rpx;
color: #165dff;
}
}
.footer {
.complete-btn {
margin-bottom: 30rpx;
:deep(.wd-button) {
height: 88rpx;
font-size: 32rpx;
font-weight: 600;
border-radius: 44rpx;
}
}
.skip-btn {
text-align: center;
text {
font-size: 28rpx;
color: rgba(255, 255, 255, 0.8);
text-decoration: underline;
}
}
}
</style>
+58 -21
View File
@@ -166,29 +166,66 @@ const handleWechatLogin = async () => {
provider: "weixin",
});
// 调用后端接口进行登录认证
const result = await userStore.loginByWechat(code);
// 尝试使用增强的微信登录接口
try {
const result = await userStore.loginByWechatMini({
code: code,
});
if (result) {
// 获取用户信息
await userStore.getInfo();
toast.success("登录成功");
if (result) {
// 获取用户信息
await userStore.getInfo();
toast.success("登录成功");
// 检查用户信息是否完整
if (!userStore.isUserInfoComplete()) {
// 如果信息不完整,跳转到完善信息页面
setTimeout(() => {
uni.navigateTo({
url: `/pages/login/complete-profile?redirect=${encodeURIComponent(redirect.value)}`,
});
}, 1000);
} else {
// 否则直接跳转到重定向页面
setTimeout(() => {
uni.reLaunch({
url: redirect.value,
});
}, 1000);
// 检查是否为新用户或信息不完整
const wechatResult = result as any; // 类型断言
if (
wechatResult.isNewUser ||
!wechatResult.isProfileComplete ||
!userStore.isUserInfoComplete()
) {
// 如果信息不完整,跳转到完善信息页面
setTimeout(() => {
uni.navigateTo({
url: `/pages/login/complete-profile?redirect=${encodeURIComponent(redirect.value)}`,
});
}, 1000);
} else {
// 否则直接跳转到重定向页面
setTimeout(() => {
uni.reLaunch({
url: redirect.value,
});
}, 1000);
}
}
} catch (enhancedError) {
// 如果增强接口失败,回退到原始接口
console.log("增强微信登录失败,回退到原始接口:", enhancedError);
const result = await userStore.loginByWechat(code);
if (result) {
// 获取用户信息
await userStore.getInfo();
toast.success("登录成功");
// 检查用户信息是否完整
if (!userStore.isUserInfoComplete()) {
// 如果信息不完整,跳转到完善信息页面
setTimeout(() => {
uni.navigateTo({
url: `/pages/login/complete-profile?redirect=${encodeURIComponent(redirect.value)}`,
});
}, 1000);
} else {
// 否则直接跳转到重定向页面
setTimeout(() => {
uni.reLaunch({
url: redirect.value,
});
}, 1000);
}
}
}
// #endif
+2 -2
View File
@@ -63,8 +63,8 @@
</view>
</template>
<script setup lang="ts">
import UserAPI, { type UserProfileVO, UserProfileForm } from "@/api/system/user";
import FileAPI, { type FileInfo } from "@/api/file";
import UserAPI, { type UserProfileVO, UserProfileForm } from "@/api/user";
import FileAPI, { type FileInfo } from "@/api";
import { checkLogin } from "@/utils/auth";
const originalSrc = ref<string>(""); //选取的原图路径
+1 -1
View File
@@ -157,7 +157,7 @@ import UserAPI, {
MobileBindingForm,
EmailBindingForm,
UserProfileVO,
} from "@/api/system/user";
} from "@/api/user";
const validatorConfirmPassword = (value: string) => {
if (!value) {
+450 -202
View File
@@ -1,150 +1,275 @@
<template>
<view class="theme-settings-container">
<view class="title">主题色设置</view>
<view class="color-palette">
<view class="subtitle">选择主题色</view>
<view class="color-grid">
<view
v-for="(color, index) in themeColors"
:key="index"
class="color-item"
:style="{ backgroundColor: color }"
@click="handleSelectColor(color)"
>
<wd-icon v-if="themeStore.primaryColor === color" name="check" color="#fff" size="16" />
</view>
</view>
<!-- 页面标题 -->
<view class="page-header">
<text class="page-title">主题设置</text>
<text class="page-subtitle">个性化您的应用外观</text>
</view>
<view class="custom-color">
<view class="subtitle">自定义主题色</view>
<view class="color-picker">
<view class="color-preview" :style="{ backgroundColor: customColor }"></view>
<input
v-model="customColor"
type="text"
placeholder="请输入十六进制颜色值,如 #165DFF"
class="color-input"
maxlength="7"
/>
<!-- 暗黑模式设置 -->
<view class="setting-section">
<view class="section-header">
<wd-icon name="moon" size="20" :color="isDark ? '#FFD700' : '#666'" />
<text class="section-title">外观模式</text>
</view>
<button class="apply-btn" @click="applyCustomColor">应用</button>
<wd-cell title="暗黑模式" :value="isDark ? '已开启' : '已关闭'">
<wd-switch v-model="isDark" @change="toggleDarkMode" />
</wd-cell>
</view>
<view class="preview-section">
<view class="subtitle">预览效果</view>
<view class="preview-container">
<view class="preview-item">
<view class="preview-button" :style="{ backgroundColor: themeStore.primaryColor }">
按钮
<!-- 主题色设置 -->
<view class="setting-section">
<view class="section-header">
<wd-icon name="palette" size="20" color="#666" />
<text class="section-title">主题色彩</text>
</view>
<!-- 预设颜色选择 -->
<view class="color-section">
<view class="color-label">预设主题色</view>
<view class="color-grid">
<view
v-for="(color, index) in extendedThemeColors"
:key="index"
class="color-item"
:class="{ active: currentThemeColor === color.value }"
:style="{ backgroundColor: color.value }"
@click="handleSelectColor(color.value)"
>
<wd-icon v-if="currentThemeColor === color.value" name="check" color="#fff" size="16" />
</view>
</view>
</view>
<!-- 当前主题色显示 -->
<wd-cell title="当前主题色" :value="currentThemeColor">
<view class="current-color-preview" :style="{ backgroundColor: currentThemeColor }"></view>
</wd-cell>
<!-- 自定义颜色 -->
<wd-cell title="自定义颜色" is-link @click="showCustomInput">
<wd-icon name="edit" size="16" color="#999" />
</wd-cell>
</view>
<!-- 预览区域 -->
<view class="setting-section">
<view class="section-header">
<wd-icon name="eye" size="20" color="#666" />
<text class="section-title">效果预览</text>
</view>
<view class="preview-container">
<view class="preview-item">
<view class="preview-text" :style="{ color: themeStore.primaryColor }">文本颜色</view>
<wd-button type="primary" size="small">主要按钮</wd-button>
</view>
<view class="preview-item">
<view class="preview-border" :style="{ borderColor: themeStore.primaryColor }">边框</view>
<text class="preview-text" :style="{ color: currentThemeColor }">主题色文本</text>
</view>
<view class="preview-item">
<view class="preview-border" :style="{ borderColor: currentThemeColor }">主题色边框</view>
</view>
<view class="preview-item">
<wd-tag type="primary" size="small">标签</wd-tag>
</view>
</view>
</view>
<button class="reset-btn" @click="resetTheme">恢复默认主题色</button>
<!-- 操作按钮 -->
<view class="action-section">
<wd-button type="info" size="large" block @click="resetTheme">重置为默认主题</wd-button>
</view>
<!-- 自定义颜色输入弹窗 -->
<wd-popup v-model="showCustomColorInput" position="bottom" :safe-area-inset-bottom="true">
<view class="custom-color-popup">
<view class="popup-header">
<text class="popup-title">自定义主题色</text>
<wd-icon name="close" size="20" color="#999" @click="showCustomColorInput = false" />
</view>
<view class="color-input-section">
<view class="input-label">请输入十六进制颜色值</view>
<view class="input-container">
<view class="color-preview-small" :style="{ backgroundColor: customColor }"></view>
<input
v-model="customColor"
type="text"
placeholder="例如: #165DFF"
class="color-input"
maxlength="7"
/>
</view>
<view class="input-tip">支持格式:#RGB 或 #RRGGBB</view>
</view>
<view class="popup-actions">
<wd-button type="info" size="large" @click="showCustomColorInput = false">取消</wd-button>
<wd-button type="primary" size="large" @click="applyCustomColor">应用</wd-button>
</view>
</view>
</wd-popup>
</view>
</template>
<script lang="ts" setup>
import { onLoad, onShow } from "@dcloudio/uni-app";
import { useThemeStore } from "@/store";
import { useTheme } from "@/composables/theme/theme";
import { useThemeStore } from "@/store/modules/theme";
import { applyThemeOnPageShow } from "@/utils/theme";
import { ref, computed, watch, onMounted } from "vue";
const { toggleTheme, themeVars, theme, setThemeColor } = useTheme();
const themeStore = useThemeStore();
// 预设主题色
const themeColors = [
"#165DFF", // Arco蓝色
"#0FC6C2", // 青绿色
"#722ED1", // 紫色
"#F5222D", // 红色
"#FA8C16", // 橙色
"#FADB14", // 黄色
"#52C41A", // 绿色
"#EB2F96", // 粉色
// 暗黑模式状态
const isDark = ref(false);
// 自定义颜色输入
const customColor = ref("");
const showCustomColorInput = ref(false);
// 扩展的预设主题色
const extendedThemeColors = [
{ value: "#165DFF", label: "蓝色" },
{ value: "#0FC6C2", label: "青绿色" },
{ value: "#722ED1", label: "紫色" },
{ value: "#F5222D", label: "红色" },
{ value: "#FA8C16", label: "橙色" },
{ value: "#FADB14", label: "黄色" },
{ value: "#52C41A", label: "绿色" },
{ value: "#EB2F96", label: "粉色" },
{ value: "#13C2C2", label: "青色" },
{ value: "#1890FF", label: "天蓝色" },
{ value: "#CD5C5C", label: "经典红" },
{ value: "#228B22", label: "自然绿" },
];
// 自定义颜色
const customColor = ref("#165DFF");
// 当前选中的主题色
const currentThemeColor = computed(() => {
return themeVars.value.colorTheme || themeStore.primaryColor || extendedThemeColors[0].value;
});
// 监听暗黑模式变化
watch(theme, (newTheme) => {
isDark.value = newTheme === "dark";
});
// 暗黑模式切换
const toggleDarkMode = () => {
toggleTheme();
};
// 选择预设颜色
const handleSelectColor = (color: string) => {
// 同时更新两个store的主题色
if (setThemeColor) {
setThemeColor(color);
} else {
themeVars.value.colorTheme = color;
}
themeStore.setPrimaryColor(color);
customColor.value = color;
// 保存设置
saveThemeSettings();
// 提示
uni.showToast({
title: "主题色已更新",
icon: "success",
duration: 1500,
});
};
// 显示自定义颜色输入
const showCustomInput = () => {
showCustomColorInput.value = true;
customColor.value = currentThemeColor.value;
};
// 应用自定义颜色
const applyCustomColor = () => {
// 验证颜色格式
const colorRegex = /^#([0-9A-F]{6})$/i;
const colorRegex = /^#([0-9A-F]{6}|[0-9A-F]{3})$/i;
if (!colorRegex.test(customColor.value)) {
uni.showToast({
title: "请输入有效的颜色值",
icon: "none",
duration: 2000,
});
return;
}
themeStore.setPrimaryColor(customColor.value);
// 转换3位颜色值为6位
let color = customColor.value;
if (color.length === 4) {
color = "#" + color[1] + color[1] + color[2] + color[2] + color[3] + color[3];
}
// 保存设置
saveThemeSettings();
// 同时更新两个store的主题色
if (setThemeColor) {
setThemeColor(color);
} else {
themeVars.value.colorTheme = color;
}
themeStore.setPrimaryColor(color);
showCustomColorInput.value = false;
// 提示
uni.showToast({
title: "自定义主题色已应用",
icon: "success",
duration: 1500,
});
};
// 重置为默认主题色
// 重置为默认主题
const resetTheme = () => {
const defaultColor = "#165DFF"; // Arco蓝色
themeStore.setPrimaryColor(defaultColor);
customColor.value = defaultColor;
uni.showModal({
title: "确认重置",
content: "确定要重置为默认主题吗?",
success: (res) => {
if (res.confirm) {
const defaultColor = extendedThemeColors[0].value;
// 保存设置
saveThemeSettings();
// 同时更新两个store的主题色
if (setThemeColor) {
setThemeColor(defaultColor);
} else {
themeVars.value.colorTheme = defaultColor;
}
themeStore.setPrimaryColor(defaultColor);
customColor.value = defaultColor;
// 提示
uni.showToast({
title: "已恢复默认主题色",
icon: "success",
// 重置为浅色模式
if (theme.value === "dark") {
toggleTheme("light");
}
uni.showToast({
title: "已重置为默认主题",
icon: "success",
duration: 1500,
});
}
},
});
};
// 保存主题设置
const saveThemeSettings = () => {
// 主题store已经处理了持久化,这里不需要额外操作
};
onLoad(() => {
// 初始化自定义颜色输入框
customColor.value = themeStore.primaryColor;
customColor.value = currentThemeColor.value;
});
onMounted(() => {
// 初始化暗黑模式状态
isDark.value = theme.value === "dark";
customColor.value = currentThemeColor.value;
});
// 页面显示时重新应用主题(解决小程序环境问题)
onShow(() => {
// 在小程序环境中,页面显示时重新应用主题
if (typeof document === "undefined") {
applyThemeOnPageShow(themeStore.primaryColor);
applyThemeOnPageShow(currentThemeColor.value);
// 为了确保样式应用,我们可以在页面中设置内联样式
// 这样可以绕过小程序的CSS变量限制
@@ -159,146 +284,269 @@ onShow(() => {
<style lang="scss" scoped>
.theme-settings-container {
min-height: 100vh;
padding: 20rpx;
background-color: #f8f9fa;
transition: background-color 0.3s ease;
}
.page-header {
padding: 40rpx 20rpx;
margin-bottom: 30rpx;
text-align: center;
background: linear-gradient(135deg, #165dff 0%, #667eea 100%);
border-radius: 16rpx;
}
.page-title {
display: block;
margin-bottom: 10rpx;
font-size: 36rpx;
font-weight: bold;
color: #fff;
}
.page-subtitle {
font-size: 26rpx;
color: rgba(255, 255, 255, 0.8);
}
.setting-section {
margin-bottom: 30rpx;
overflow: hidden;
background: #fff;
border-radius: 16rpx;
box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.05);
transition: background-color 0.3s ease;
}
.section-header {
display: flex;
align-items: center;
padding: 30rpx 30rpx 20rpx;
border-bottom: 1rpx solid #f0f0f0;
}
.section-title {
margin-left: 12rpx;
font-size: 32rpx;
font-weight: 600;
color: #333;
}
.color-section {
padding: 30rpx;
}
.title {
margin-bottom: 30rpx;
font-size: 36rpx;
font-weight: bold;
color: #333;
.color-label {
margin-bottom: 20rpx;
font-size: 28rpx;
color: #666;
}
.color-grid {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 20rpx;
}
.color-item {
position: relative;
display: flex;
align-items: center;
justify-content: center;
width: 80rpx;
height: 80rpx;
cursor: pointer;
border-radius: 12rpx;
box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.1);
transition: all 0.3s ease;
}
.color-item.active {
box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.2);
transform: scale(1.1);
}
.color-item:active {
transform: scale(0.95);
}
.current-color-preview {
width: 40rpx;
height: 40rpx;
border: 2rpx solid #f0f0f0;
border-radius: 8rpx;
}
.preview-container {
display: flex;
flex-direction: column;
gap: 20rpx;
padding: 30rpx;
}
.preview-item {
display: flex;
align-items: center;
justify-content: center;
padding: 20rpx;
background: #f8f9fa;
border-radius: 12rpx;
}
.preview-text {
font-size: 28rpx;
font-weight: 500;
}
.preview-border {
display: flex;
align-items: center;
justify-content: center;
width: 200rpx;
height: 60rpx;
font-size: 26rpx;
color: #666;
border: 2rpx solid;
border-radius: 8rpx;
}
.action-section {
padding: 30rpx;
background: #fff;
border-radius: 16rpx;
box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.05);
}
.custom-color-popup {
padding: 40rpx 30rpx;
background: #fff;
border-radius: 20rpx 20rpx 0 0;
}
.popup-header {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 30rpx;
}
.popup-title {
font-size: 32rpx;
font-weight: 600;
color: #333;
}
.color-input-section {
margin-bottom: 40rpx;
}
.input-label {
margin-bottom: 20rpx;
font-size: 28rpx;
color: #666;
}
.input-container {
display: flex;
gap: 20rpx;
align-items: center;
margin-bottom: 10rpx;
}
.color-preview-small {
flex-shrink: 0;
width: 60rpx;
height: 60rpx;
border: 2rpx solid #f0f0f0;
border-radius: 8rpx;
}
.color-input {
flex: 1;
height: 60rpx;
padding: 0 20rpx;
font-size: 28rpx;
background: #fff;
border: 2rpx solid #e0e0e0;
border-radius: 8rpx;
}
.color-input:focus {
border-color: #165dff;
}
.input-tip {
margin-left: 80rpx;
font-size: 24rpx;
color: #999;
}
.popup-actions {
display: flex;
gap: 20rpx;
}
/* 响应式布局 */
@media (max-width: 750rpx) {
.color-grid {
grid-template-columns: repeat(3, 1fr);
}
}
@media (max-width: 600rpx) {
.color-grid {
grid-template-columns: repeat(2, 1fr);
}
}
/* 暗黑模式适配 */
:deep(.wd-config-provider[data-theme="dark"]) {
.theme-settings-container {
background-color: #1a1a1a;
}
.subtitle {
margin-bottom: 20rpx;
font-size: 30rpx;
font-weight: 500;
color: #333;
}
.setting-section {
background: #2a2a2a;
.color-palette {
padding: 30rpx;
margin-bottom: 40rpx;
background-color: #fff;
border-radius: 12rpx;
box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.05);
.section-header {
border-bottom-color: #404040;
.color-grid {
display: flex;
flex-wrap: wrap;
gap: 20rpx;
.color-item {
display: flex;
align-items: center;
justify-content: center;
width: 80rpx;
height: 80rpx;
border-radius: 12rpx;
box-shadow: 0 2rpx 6rpx rgba(0, 0, 0, 0.1);
transition: transform 0.2s;
&:active {
transform: scale(0.95);
}
}
}
}
.custom-color {
padding: 30rpx;
margin-bottom: 40rpx;
background-color: #fff;
border-radius: 12rpx;
box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.05);
.color-picker {
display: flex;
align-items: center;
margin-bottom: 30rpx;
.color-preview {
width: 60rpx;
height: 60rpx;
margin-right: 20rpx;
border-radius: 8rpx;
box-shadow: 0 2rpx 6rpx rgba(0, 0, 0, 0.1);
}
.color-input {
flex: 1;
height: 80rpx;
padding: 0 20rpx;
font-size: 28rpx;
border: 1px solid #e0e0e0;
border-radius: 8rpx;
}
}
.apply-btn {
width: 100%;
height: 80rpx;
font-size: 28rpx;
line-height: 80rpx;
color: #fff;
background-color: var(--primary-color);
border: none;
border-radius: 8rpx;
}
}
.preview-section {
padding: 30rpx;
margin-bottom: 40rpx;
background-color: #fff;
border-radius: 12rpx;
box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.05);
.preview-container {
display: flex;
flex-direction: column;
gap: 20rpx;
.preview-item {
display: flex;
align-items: center;
justify-content: center;
}
.preview-button {
width: 100%;
height: 80rpx;
line-height: 80rpx;
.section-title {
color: #fff;
text-align: center;
border-radius: 8rpx;
}
.preview-text {
font-size: 32rpx;
font-weight: 500;
}
.preview-border {
width: 100%;
height: 80rpx;
line-height: 80rpx;
text-align: center;
background-color: #f5f5f5;
border: 2px solid;
border-radius: 8rpx;
}
}
}
.reset-btn {
width: 100%;
height: 80rpx;
font-size: 28rpx;
line-height: 80rpx;
color: #333;
background-color: #f5f5f5;
border: none;
border-radius: 8rpx;
.preview-container .preview-item {
background: #404040;
}
.action-section {
background: #2a2a2a;
}
.custom-color-popup {
background: #2a2a2a;
.popup-title {
color: #fff;
}
.input-label {
color: #ccc;
}
.color-input {
color: #fff;
background: #404040;
border-color: #606060;
&:focus {
border-color: #165dff;
}
}
}
}
</style>
-273
View File
@@ -1,273 +0,0 @@
<template>
<view class="todo-container">
<view class="page-header">
<text class="page-title">待办事项</text>
<wd-button size="small" type="primary" icon="add" @click="showAddTodoPopup = true">
新建待办
</wd-button>
</view>
<view class="filter-tabs">
<wd-tabs v-model="activeTab" sticky>
<wd-tab title="全部" name="all" />
<wd-tab title="未完成" name="active" />
<wd-tab title="已完成" name="completed" />
</wd-tabs>
</view>
<TodoList :todos="filteredTodos" @update="handleUpdateTodo" @delete="handleDeleteTodo" />
<!-- 新增待办弹窗 -->
<wd-popup
v-model="showAddTodoPopup"
position="bottom"
close-on-click-modal
:style="{ height: '65%' }"
>
<view class="popup-header">
<text class="popup-title">新建待办</text>
<wd-icon name="close" @click="showAddTodoPopup = false" />
</view>
<view class="popup-form">
<wd-input
v-model="newTodo.title"
placeholder="请输入待办标题"
:rules="[{ required: true, message: '请输入标题' }]"
/>
<wd-textarea
v-model="newTodo.description"
placeholder="请输入详细描述"
rows="3"
autosize
class="mt-20"
/>
<wd-cell title="截止日期" is-link @click="showDatePicker = true">
<text v-if="newTodo.deadline">{{ formatDate(newTodo.deadline) }}</text>
<text v-else class="text-placeholder">请选择</text>
</wd-cell>
<wd-cell title="优先级">
<wd-radio-group v-model="newTodo.priority" shape="button">
<wd-radio value="low">低</wd-radio>
<wd-radio value="medium">中</wd-radio>
<wd-radio value="high">高</wd-radio>
</wd-radio-group>
</wd-cell>
<view class="form-actions">
<wd-button
block
type="primary"
:loading="loading"
:disabled="!newTodo.title"
@click="handleAddTodo"
>
保存
</wd-button>
</view>
</view>
</wd-popup>
<!-- 日期选择器 -->
<wd-datetime-picker
v-model="showDatePicker"
v-model:value="newTodo.deadline"
label="截止日期"
type="date"
confirm-button-text="确认"
cancel-button-text="取消"
title="选择截止日期"
/>
<wd-toast />
</view>
</template>
<script lang="ts" setup>
import { ref, computed } from "vue";
import { useToast } from "wot-design-uni";
import { Todo } from "@/types/todo";
import TodoList from "@/components/todo/TodoList.vue";
const toast = useToast();
const loading = ref(false);
const showAddTodoPopup = ref(false);
const showDatePicker = ref(false);
const activeTab = ref("all");
// 待办列表
const todos = ref<Todo[]>([
{
id: "1",
title: "完成个人资料填写",
description: "包括上传头像、填写基本信息等",
completed: false,
priority: "high",
createdAt: new Date().toISOString(),
},
{
id: "2",
title: "阅读使用指南",
description: "熟悉系统功能和操作流程",
completed: true,
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString(),
},
]);
// 新增待办表单
const newTodo = ref<Partial<Todo>>({
title: "",
description: "",
priority: "medium",
deadline: "",
});
// 根据标签筛选待办
const filteredTodos = computed(() => {
switch (activeTab.value) {
case "active":
return todos.value.filter((todo) => !todo.completed);
case "completed":
return todos.value.filter((todo) => todo.completed);
default:
return todos.value;
}
});
// 格式化日期
const formatDate = (date: string) => {
const d = new Date(date);
const year = d.getFullYear();
const month = String(d.getMonth() + 1).padStart(2, "0");
const day = String(d.getDate()).padStart(2, "0");
return `${year}-${month}-${day}`;
};
// 生成唯一ID
const generateId = () => {
return Date.now().toString(36) + Math.random().toString(36).substring(2);
};
// 添加待办
const handleAddTodo = () => {
if (!newTodo.value.title) {
toast.error("请输入待办标题");
return;
}
loading.value = true;
// 模拟API调用
setTimeout(() => {
const now = new Date().toISOString();
const todo: Todo = {
id: generateId(),
title: newTodo.value.title!,
description: newTodo.value.description,
completed: false,
deadline: newTodo.value.deadline,
priority: newTodo.value.priority as "low" | "medium" | "high",
createdAt: now,
};
todos.value.unshift(todo);
resetForm();
loading.value = false;
showAddTodoPopup.value = false;
toast.success("待办创建成功");
}, 500);
};
// 更新待办
const handleUpdateTodo = (todo: Todo) => {
const index = todos.value.findIndex((item) => item.id === todo.id);
if (index !== -1) {
todos.value[index] = {
...todo,
updatedAt: new Date().toISOString(),
};
toast.success(todo.completed ? "已完成" : "已取消完成");
}
};
// 删除待办
const handleDeleteTodo = (id: string) => {
uni.showModal({
title: "提示",
content: "确认删除该待办事项?",
success: (res) => {
if (res.confirm) {
todos.value = todos.value.filter((todo) => todo.id !== id);
toast.success("删除成功");
}
},
});
};
// 重置表单
const resetForm = () => {
newTodo.value = {
title: "",
description: "",
priority: "medium",
deadline: "",
};
};
</script>
<style lang="scss" scoped>
.todo-container {
min-height: 100vh;
padding: 30rpx;
background-color: #f5f7fa;
.page-header {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 30rpx;
.page-title {
font-size: 36rpx;
font-weight: 600;
color: #333;
}
}
.filter-tabs {
margin-bottom: 20rpx;
overflow: hidden;
background-color: #fff;
border-radius: 12rpx;
}
.popup-header {
display: flex;
align-items: center;
justify-content: space-between;
padding: 30rpx;
border-bottom: 1rpx solid #eee;
.popup-title {
font-size: 32rpx;
font-weight: 600;
color: #333;
}
}
.popup-form {
padding: 30rpx;
.form-actions {
margin-top: 40rpx;
}
}
.text-placeholder {
color: #999;
}
.mt-20 {
margin-top: 20rpx;
}
}
</style>
-324
View File
@@ -1,324 +0,0 @@
<template>
<view class="work">
<!-- 筛选 -->
<wd-drop-menu close-on-click-modal class="mb-20rpx mr-20rpx ml-20rpx">
<wd-drop-menu-item ref="dropMenu" title="筛选" icon="filter" icon-size="18px">
<view>
<wd-input
v-model="queryParams.keywords"
label="关键字"
type="text"
clearable
placeholder="请输入关键字"
/>
<view class="flex flex-row items-center mb-20rpx">
<wd-button class="mt-20rpx mb-20rpx" size="medium" @click="handleQuery()">
查询
</wd-button>
<wd-button size="medium" type="info" @click="handleReset">重置</wd-button>
</view>
</view>
</wd-drop-menu-item>
</wd-drop-menu>
<view class="data-container">
<!-- 列表内容 -->
<view v-for="(item, index) in pageData" :key="index" class="mb-20rpx">
<wd-card>
<template #title>
<view class="flex items-center justify-between">
<view class="flex-1 text-truncate">{{ item.configName }}</view>
</view>
</template>
<wd-cell-group>
<wd-cell title="配置键" :value="item.configKey" />
<wd-cell title="配置值" :value="item.configValue" />
<wd-cell title="备注" :value="item.remark" />
</wd-cell-group>
<template #footer>
<wd-button size="small" plain type="primary" @click="handleAction(item)">
操作
</wd-button>
</template>
</wd-card>
</view>
</view>
<!-- 加载更多 -->
<wd-loadmore :state="state" @reload="handleQuery" />
<!-- 底部按钮 -->
<view class="fixed bottom-0 w-full flex justify-around items-center p-20rpx bg-#fff">
<wd-button size="medium" type="primary" @click="handleOpenDialog">添加</wd-button>
<wd-button size="medium" type="success" @click="refreshCache">刷新缓存</wd-button>
</view>
<wd-popup v-model="showEditPopup" position="bottom">
<view class="p-20rpx">
<wd-form ref="formRef" :model="form">
<wd-input
v-model="form.configName"
label="配置名称"
type="text"
placeholder="请输入配置名称"
:rules="[{ required: true, message: '请填写配置名称' }]"
/>
<wd-input
v-model="form.configKey"
label="配置键名"
type="text"
placeholder="请输入配置键名"
:rules="[{ required: true, message: '请填写配置键' }]"
/>
<wd-input
v-model="form.configValue"
label="配置键值"
type="text"
placeholder="请输入配置键值"
:rules="[{ required: true, message: '请填写配置值' }]"
/>
<wd-textarea
v-model="form.remark"
prop="remark"
label="配置描述"
label-align="right"
clearable
:maxlength="100"
show-word-limit
label-width="100px"
placeholder="请输入配置描述"
/>
</wd-form>
<view class="flex justify-around mt-20rpx">
<wd-button @click="showEditPopup = false">取消</wd-button>
<wd-button type="primary" native-type="submit" :loading="loading" @click="submitForm">
确定
</wd-button>
</view>
</view>
</wd-popup>
</view>
</template>
<script lang="ts" setup>
import ConfigAPI, { ConfigPageVO, ConfigForm, ConfigPageQuery } from "@/api/system/config";
import { DropMenuItemExpose } from "wot-design-uni/components/wd-drop-menu-item/types";
import { LoadMoreState } from "wot-design-uni/components/wd-loadmore/types";
import { FormInstance } from "wot-design-uni/components/wd-form/types";
import { debounce } from "@/utils";
const state = ref<LoadMoreState>("loading"); // 加载状态 loading, finished:, error
const total = ref(0);
const queryParams = reactive<ConfigPageQuery>({
pageNum: 1,
pageSize: 10,
keywords: "",
});
// 系统配置表格数据
const pageData = ref<ConfigPageVO[]>([]);
const formRef = ref<FormInstance>();
const loading = ref(false);
/**
* 搜索栏
*/
const dropMenu = ref<DropMenuItemExpose>();
/**
* 搜索
*/
function handleQuery() {
pageData.value = [];
dropMenu.value?.close();
queryParams.pageNum = 1;
loadmore();
}
const showEditPopup = ref(false);
const form = ref<ConfigForm>({});
// 修改编辑函数
function handleEdit(id: number) {
ConfigAPI.getFormData(id).then((data) => {
Object.assign(form.value, data);
// 显示弹窗
showEditPopup.value = true;
});
}
// 提交表单
async function submitForm() {
loading.value = true;
try {
if (formRef.value) {
formRef.value!.validate().then(async ({ valid }) => {
if (valid) {
if (form.value.id) {
await ConfigAPI.update(form.value.id, form.value);
uni.showToast({ title: "更新成功", icon: "success" });
} else {
await ConfigAPI.add(form.value);
uni.showToast({ title: "添加成功", icon: "success" });
}
showEditPopup.value = false;
handleQuery(); // 刷新列表
} else {
uni.showToast({ title: "请检查表单", icon: "error" });
loading.value = false;
}
});
}
} catch {
uni.showToast({ title: "操作失败", icon: "error" });
loading.value = false;
} finally {
loading.value = false;
}
}
/**
* 重置搜索条件
*/
function handleReset() {
queryParams.pageNum = 1;
queryParams.keywords = "";
pageData.value = [];
dropMenu.value?.close();
handleQuery();
}
/**
* 触底事件
*/
onReachBottom(() => {
queryParams.pageNum++;
handleQuery();
});
/**
* 加载更多
*/
function loadmore() {
state.value = "loading";
ConfigAPI.getPage(queryParams)
.then((data) => {
if (queryParams.pageNum === 1) {
pageData.value = data.list;
} else {
pageData.value.push(...data.list);
}
total.value = data.total;
})
.finally(() => {
state.value = "finished";
});
}
/**
* 添加
*/
function handleOpenDialog() {
form.value.id = undefined;
form.value.configName = "";
form.value.configKey = "";
form.value.configValue = "";
form.value.remark = "";
showEditPopup.value = true;
}
/**
* 刷新缓存
*/
const refreshCache = debounce(() => {
ConfigAPI.refreshCache().then(() => {
uni.showToast({
title: "刷新缓存成功",
icon: "success",
duration: 1000, // 显示时间,单位为毫秒,设置为 0 则不会自动消失
});
});
}, 1000);
/**
* 删除
*/
function handleDelete(item: ConfigPageVO) {
uni.showModal({
title: "提示",
content: "确定要删除该配置吗?",
success: async (res) => {
if (res.confirm) {
if (item.id) {
ConfigAPI.deleteById(item.id).then(() => {
uni.showToast({ title: "删除成功", icon: "success" });
});
}
}
},
});
}
/**
* 操作
*/
function handleAction(item: ConfigPageVO) {
const actions = ["编辑", "删除"];
uni.showActionSheet({
itemList: actions,
success: ({ tapIndex }) => {
switch (actions[tapIndex]) {
case "编辑":
handleEdit(item.id || 0);
break;
case "删除":
handleDelete(item);
break;
}
},
});
}
onMounted(() => {
handleQuery();
});
/**
* 页面返回回来也要重新加载数据
*/
onLoad(() => {
queryParams.pageNum = 1;
handleQuery();
});
</script>
<style lang="scss" scoped>
.data-container {
:deep(.wd-cell__wrapper) {
padding: 4rpx 0;
}
:deep(.wd-cell) {
padding-right: 10rpx;
background: #f8f8f8;
}
:deep(.wd-fab__trigger) {
width: 80rpx !important;
height: 80rpx !important;
}
:deep(.wd-cell__right) {
flex: 2;
}
.filter-container {
padding: 10rpx;
background: #fff;
}
.data-container {
margin-top: 20rpx;
}
}
</style>
-81
View File
@@ -1,81 +0,0 @@
<template>
<view class="work">
<template v-for="(item, index) in gridList" :key="index">
<wd-card :title="item.title">
<wd-grid clickable :column="4">
<wd-grid-item
v-for="(child, index) in item.children"
:key="index"
:v-has-perm="child.prem"
use-slot
link-type="navigateTo"
:url="child.url"
>
<view class="p-2">
<image class="w-72rpx h-72rpx rounded-8rpx" :src="child.icon" />
</view>
<view class="text">{{ child.title }}</view>
</wd-grid-item>
</wd-grid>
</wd-card>
</template>
</view>
</template>
<script lang="ts" setup>
const gridList = reactive([
{
title: "系统管理",
children: [
{
icon: "/static/icons/user.png",
title: "用户管理",
url: "/pages/work/user/index",
prem: "sys:user:query",
},
{
icon: "/static/icons/role.png",
title: "角色管理",
url: "/pages/work/role/index",
prem: "sys:role:query",
},
{
icon: "/static/icons/notice.png",
title: "通知公告",
url: "/pages/work/notice/index",
prem: "sys:notice:query",
},
{
icon: "/static/icons/setting.png",
title: "系统配置",
url: "/pages/work/config/index",
prem: "sys:config:query",
},
],
},
{
title: "系统监控",
children: [
{
icon: "/static/icons/log.png",
title: "系统日志",
url: "/pages/work/log/index",
prem: "sys:log:query",
},
],
},
]);
</script>
<style lang="scss" scoped>
/* stylelint-disable selector-type-no-unknown */
page {
background: #f8f8f8;
}
/* stylelint-enable selector-type-no-unknown */
.work {
padding: 40rpx 0;
}
</style>
-174
View File
@@ -1,174 +0,0 @@
<template>
<view class="log">
<!-- 筛选 -->
<wd-drop-menu close-on-click-modal class="mb-24rpx">
<wd-drop-menu-item ref="filterDropMenu" title="筛选" icon="filter" icon-size="18px">
<view>
<wd-input
v-model="queryParams.keywords"
label="关键字"
type="text"
placeholder="请输入关键字"
/>
<cu-date-query v-model="queryParams.createTime" :label="'日期选择'" />
<view class="flex-between py-2">
<wd-button class="w-20%" type="info" @click="handleResetQuery">重置</wd-button>
<wd-button class="w-70%" @click="handleQuery">查询</wd-button>
</view>
</view>
</wd-drop-menu-item>
</wd-drop-menu>
<!-- 卡片列表 -->
<wd-card v-for="item in pageData" :key="item.id" class="card-list">
<template #title>
{{ item.operator }}
</template>
<wd-cell-group>
<wd-cell title="模块" :value="item.module" />
<wd-cell title="内容" :value="item.content" />
<wd-cell title="IP" :value="item.ip" />
<wd-cell title="地区" :value="item.region" />
</wd-cell-group>
<template #footer>
<view class="flex-between">
<view class="text-left">
<wd-text text="创建时间:" size="small" class="font-bold" />
<wd-text :text="item.createTime" size="small" />
</view>
<view class="text-right">
<wd-button type="primary" size="small" plain @click="handleViewDetail(item)">
查看详情
</wd-button>
</view>
</view>
</template>
</wd-card>
<!-- 详情弹窗 -->
<wd-popup v-model="detailDialogVisible" position="bottom">
<wd-cell-group>
<wd-cell title="操作人" :value="logDetail.operator" />
<wd-cell title="操作时间" :value="logDetail.createTime" />
<wd-cell title="模块" :value="logDetail.module" />
<wd-cell title="内容" :value="logDetail.content" />
<wd-cell title="IP" :value="logDetail.ip" />
<wd-cell title="地区" :value="logDetail.region" />
<wd-cell title="浏览器" :value="logDetail.region" />
<wd-cell title="终端系统" :value="logDetail.os" />
<wd-cell title="耗时(毫秒)" :value="logDetail.executionTime" />
</wd-cell-group>
</wd-popup>
<!-- 加载更多 -->
<wd-loadmore v-if="total > 0" :state="loadMoreState" @reload="loadmore" />
<wd-status-tip v-else-if="total == 0" image="search" tip="当前搜索无结果" />
</view>
</template>
<script lang="ts" setup>
import { onLoad, onReachBottom } from "@dcloudio/uni-app";
import { LoadMoreState } from "wot-design-uni/components/wd-loadmore/types";
import { DropMenuItemExpose } from "wot-design-uni/components/wd-drop-menu-item/types";
import LogAPI, { LogVO, LogPageQuery } from "@/api/system/log";
const filterDropMenu = ref<DropMenuItemExpose>();
const loadMoreState = ref<LoadMoreState>("loading");
const queryParams = reactive<LogPageQuery>({
pageNum: 1,
pageSize: 10,
});
const total = ref(0);
const pageData = ref<LogVO[]>([]);
const logDetail = ref<LogVO>({});
const detailDialogVisible = ref(false);
/**
* 搜索栏
*/
function handleQuery() {
filterDropMenu.value?.close();
queryParams.pageNum = 1;
loadmore();
}
/**
* 重置搜索
*/
function handleResetQuery() {
queryParams.keywords = undefined;
queryParams.createTime = undefined;
handleQuery();
}
/**
* 加载更多
*/
function loadmore() {
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 handleViewDetail(item: LogVO) {
detailDialogVisible.value = true;
logDetail.value = item;
}
/**
* 触底事件
*/
onReachBottom(() => {
if (queryParams.pageNum * queryParams.pageSize < total.value) {
loadmore();
} else if (queryParams.pageNum * queryParams.pageSize >= total.value) {
loadMoreState.value = "finished";
}
});
onLoad(() => {
handleQuery();
});
</script>
<style lang="scss" scoped>
.wd-col {
margin-top: 10rpx;
}
::v-deep .wd-drop-menu__item {
display: flex;
justify-content: flex-end;
padding: 0 50rpx;
}
.card-list {
:deep(.wd-cell__wrapper) {
padding: 4rpx 0;
}
:deep(.wd-cell) {
padding-right: 10rpx;
background: #f8f8f8;
}
}
</style>
-117
View File
@@ -1,117 +0,0 @@
<template>
<div class="notice-detail">
<wd-cell-group>
<div class="notice-header">
<h2 class="notice-title">
<wd-icon name="prompt" size="20px" class="title-icon" />
{{ noticeDetail.title }}
</h2>
<div class="notice-meta">
<div class="meta-row">
优先级:
<cu-dict-label code="notice_level" :model-value="noticeDetail.level" />
</div>
<div class="meta-row">发布人:{{ noticeDetail.publisherName }}</div>
<div class="meta-row">发布时间:{{ noticeDetail.publishTime }}</div>
</div>
</div>
<wd-divider />
<div class="notice-content" v-html="noticeDetail.content" />
</wd-cell-group>
</div>
</template>
<script setup lang="ts">
import NoticeAPI, { NoticeDetailVO } from "@/api/system/notice";
const noticeDetail = ref<NoticeDetailVO>({});
/**
* 获取通知详情
* @param id 通知ID
*/
const getNoticeDetail = async (id: string) => {
try {
const res = await NoticeAPI.getDetail(id);
noticeDetail.value = res;
} catch (error) {
console.error("获取通知详情失败:", error);
}
};
// 页面加载
onLoad((options: any) => {
if (options && options.id) {
getNoticeDetail(options.id as string);
} else {
uni.showToast({
title: "通知不存在",
icon: "none",
});
}
});
</script>
<style scoped>
.notice-detail {
padding: 12px;
background: #f7f8fa;
}
.notice-header {
padding: 16px;
background: #fff;
border-radius: 8px;
}
.notice-title {
display: flex;
gap: 8px;
align-items: center;
justify-content: center;
margin-bottom: 12px;
font-size: 18px;
font-weight: 500;
line-height: 1.4;
text-align: center;
}
.title-icon {
color: #666;
}
.notice-meta {
display: flex;
flex-direction: column;
gap: 8px;
align-items: center;
margin-bottom: 12px;
font-size: 13px;
color: #666;
}
.meta-row {
display: flex;
flex-wrap: nowrap;
gap: 8px;
align-items: center;
}
.priority-wrapper {
display: inline-flex;
gap: 4px;
align-items: center;
}
.notice-content {
padding: 16px;
font-size: 15px;
line-height: 1.6;
background: #fff;
border-radius: 8px;
}
:deep(.wd-divider) {
margin: 0 8px;
}
</style>
-284
View File
@@ -1,284 +0,0 @@
<template>
<view>
<!-- 添加搜索栏 -->
<wd-drop-menu close-on-click-modal class="mb-20rpx mr-20rpx ml-20rpx">
<wd-drop-menu-item ref="dropMenu" title="筛选" icon="filter" icon-size="18px">
<view>
<wd-input
v-model="queryParams.title"
label="关键字"
type="text"
placeholder="请输入关键字"
/>
<view class="flex flex-row items-center mb-20rpx">
<wd-button class="mt-20rpx mb-20rpx" size="medium" @click="handleQuery()">
查询
</wd-button>
<wd-button size="medium" type="info" @click="handleReset">重置</wd-button>
</view>
</view>
</wd-drop-menu-item>
</wd-drop-menu>
<!-- 列表内容 -->
<view class="data-container">
<view v-for="(item, index) in dataList" :key="index" class="mt-20rpx">
<wd-card>
<template #title>
<view class="flex items-center justify-between">
<view class="flex-1 text-truncate">{{ item.title }}</view>
<wd-tag :type="getStatusType(item.publishStatus)" size="small">
{{ getStatusText(item.publishStatus) }}
</wd-tag>
</view>
</template>
<wd-cell-group>
<wd-cell title="通告目标类型" :value="item.targetType === 1 ? '指定' : '全体'" />
<wd-cell title="紧急程度">
<template #default>
<cu-dict-label code="notice_level" :model-value="item.level" />
</template>
</wd-cell>
<wd-cell title="发布人" :value="item.publisherName || '-'" />
</wd-cell-group>
<template #footer>
<view class="flex-between">
<view v-if="item.publishStatus === 1" class="text-left">
<wd-text text="发布时间:" size="small" class="font-bold" />
<wd-text :text="formatDate(item.publishTime)" size="small" />
</view>
<view v-else class="text-left">
<wd-text text="撤回时间:" size="small" class="font-bold" />
<wd-text :text="formatDate(item.revokeTime)" size="small" />
</view>
<view class="text-right">
<wd-button size="small" plain type="primary" @click="handleAction(item)">
操作
</wd-button>
</view>
</view>
</template>
</wd-card>
</view>
</view>
<!-- 加载更多 -->
<wd-loadmore custom-class="loadmore" :state="loadState" />
</view>
</template>
<script lang="ts" setup>
import { LoadMoreState } from "wot-design-uni/components/wd-loadmore/types";
import { DropMenuItemExpose } from "wot-design-uni/components/wd-drop-menu-item/types";
import NoticeAPI, { NoticePageQuery, NoticePageVO } from "@/api/system/notice";
const loadState = ref<LoadMoreState>("finished");
const dataList = ref<NoticePageVO[]>([]);
const total = ref(0);
// 修改查询参数
const queryParams = ref<NoticePageQuery>({
pageNum: 1,
pageSize: 10,
title: "",
});
// 添加搜索处理函数
const dropMenu = ref<DropMenuItemExpose>();
const handleQuery = () => {
queryParams.value.pageNum = 1;
loadMore();
dropMenu.value?.close();
};
// 重置
const handleReset = () => {
queryParams.value = { pageNum: 1, pageSize: 10 };
dropMenu.value?.close();
loadMore();
};
// 获取状态样式
const getStatusType = (
status: number | undefined
): "default" | "primary" | "danger" | "warning" | "success" => {
if (!status) return "default";
const statusMap: Record<number, "default" | "primary" | "danger" | "warning" | "success"> = {
0: "primary",
1: "success",
[-1]: "warning",
};
return statusMap[status] || "default";
};
// 获取状态文本
const getStatusText = (status: number | undefined): string => {
if (status !== 0 && !status) return "-";
const statusMap: Record<number, string> = {
0: "未发布",
1: "已发布",
[-1]: "已撤回",
};
return statusMap[status] || "未知";
};
// 格式化日期
const formatDate = (date: Date | undefined): string => {
return date ? date.toString() : "-";
};
// 加载更多
const loadMore = async () => {
if (loadState.value === "loading") return;
loadState.value = "loading";
const { list, total: totalCount } = await NoticeAPI.getPage(queryParams.value);
if (queryParams.value.pageNum === 1) {
dataList.value = list;
} else {
dataList.value = [...dataList.value, ...list];
}
total.value = totalCount;
queryParams.value.pageNum++;
loadState.value = dataList.value.length >= total.value ? "finished" : "loading";
};
// 查看详情
const handleView = (notice: NoticePageVO) => {
uni.navigateTo({
url: `/pages/work/notice/detail?id=${notice.id}`,
});
};
// 操作按钮
const handleAction = (notice: NoticePageVO) => {
const actions = notice.publishStatus !== 1 ? ["查看", "删除", "发布"] : ["查看", "撤回"];
uni.showActionSheet({
itemList: actions,
success: ({ tapIndex }) => {
switch (actions[tapIndex]) {
case "查看":
handleView(notice);
break;
case "删除":
handleDelete(notice);
break;
case "发布":
handlePublish(notice);
break;
case "撤回":
handleRevoke(notice);
break;
}
},
});
};
// 删除
const handleDelete = (notice: NoticePageVO) => {
uni.showModal({
title: "提示",
content: "确定要删除该通知吗?",
success: async (res) => {
if (res.confirm) {
try {
await NoticeAPI.deleteByIds(notice.id);
uni.showToast({ title: "删除成功", icon: "success" });
// 重新加载第一页
queryParams.value.pageNum = 1;
loadMore();
} catch (error) {
uni.showToast({ title: "删除失败" + error, icon: "none" });
}
}
},
});
};
// 发布
const handlePublish = (notice: NoticePageVO) => {
uni.showModal({
title: "提示",
content: "确定要发布该通知吗?",
success: async (res) => {
if (res.confirm) {
try {
await NoticeAPI.publish(Number(notice.id));
uni.showToast({ title: "发布成功", icon: "success" });
// 重新加载第一页
queryParams.value.pageNum = 1;
loadMore();
} catch (error) {
uni.showToast({ title: "发布失败" + error, icon: "none" });
}
}
},
});
};
// 撤回
const handleRevoke = (notice: NoticePageVO) => {
uni.showModal({
title: "提示",
content: "确定要撤回该通知吗?",
success: async (res) => {
if (res.confirm) {
try {
await NoticeAPI.revoke(Number(notice.id));
uni.showToast({
title: "撤回成功",
icon: "success",
});
// 刷新列表
queryParams.value.pageNum = 1;
loadMore();
} catch (error) {
uni.showToast({
title: "撤回失败" + error,
icon: "error",
});
}
}
},
});
};
onReachBottom(() => {
if (loadState.value === "loading" || loadState.value === "finished") return;
loadMore();
});
onLoad(() => {
loadMore();
});
</script>
<style lang="scss" scoped>
.data-container {
:deep(.wd-cell__wrapper) {
padding: 4rpx 0;
}
:deep(.wd-cell) {
padding-right: 10rpx;
background: #f8f8f8;
}
:deep(.wd-fab__trigger) {
width: 80rpx !important;
height: 80rpx !important;
}
.filter-container {
padding: 10rpx;
background: #fff;
}
.data-container {
margin-top: 20rpx;
}
}
</style>
-109
View File
@@ -1,109 +0,0 @@
<template>
<view>
<view class="p-l-8 p-b-20">
<DaTree
ref="DaTreeRef"
:data="menuPermOptions"
:defaultExpandAll="true"
:showCheckbox="true"
/>
</view>
<wd-fab v-model:active="showFab" type="primary" position="right-top" direction="bottom">
<wd-button custom-class="custom-button" type="primary" @click="doCheckedTree(rootKeys, true)">
全 选
</wd-button>
<wd-button custom-class="custom-button" type="error" @click="doCheckedTree(rootKeys, false)">
全不选
</wd-button>
<wd-button custom-class="custom-button" type="success" @click="doExpandTree('all', true)">
全展开
</wd-button>
<wd-button custom-class="custom-button" type="warning" @click="doExpandTree('all', false)">
全收起
</wd-button>
</wd-fab>
<!-- 底部按钮 -->
<view class="footer-buttons" style="">
<wd-button size="medium" type="primary" block @click="handleAssignPermSubmit">
确 定
</wd-button>
</view>
</view>
</template>
<script lang="ts" setup>
import RoleAPI from "@/api/system/role";
import MenuAPI from "@/api/system/menu";
import DaTree from "@/components/da-tree/index.vue";
let roleId = ref<number>(); // 操作的角色ID
const menuPermOptions = ref<OptionType[]>([]); // 所有菜单
let rootKeys = ref<number[]>([]); // 根节点数组
const DaTreeRef = ref(); // 树引用
const showFab = ref(); // 悬浮按钮是否展开
/**
* 分配菜单权限页面数据初始化
*/
async function initAssignPerm() {
// 获取所有的菜单
menuPermOptions.value = await MenuAPI.getOptions(false);
rootKeys.value = menuPermOptions.value.map((item) => item.value as number);
// 回显角色已拥有的菜单
RoleAPI.getRoleMenuIds(roleId.value!).then((data) => {
const checkedMenuIds = data;
if (checkedMenuIds && checkedMenuIds.length > 0) {
DaTreeRef.value?.setCheckedKeys(checkedMenuIds, true);
}
});
}
// 展开/收起树节点
function doExpandTree(keys: number[] | string, expand: boolean) {
DaTreeRef.value?.setExpandedKeys(keys, expand);
showFab.value = false;
}
// 选中/取消树节点
function doCheckedTree(keys: number[], checked: boolean) {
DaTreeRef.value?.setCheckedKeys(keys, checked);
showFab.value = false;
}
// 分配菜单权限提交
function handleAssignPermSubmit() {
if (roleId.value) {
const checkedMenuIds: number[] = DaTreeRef.value?.getCheckedKeys();
RoleAPI.updateRoleMenus(roleId.value, checkedMenuIds).then(() => {
uni.showToast({ title: "分配权限成功", icon: "success" });
uni.navigateBack({ delta: 1 });
});
}
}
onLoad((options: any) => {
if (options && options.id) {
roleId.value = options.id;
}
initAssignPerm();
});
</script>
<style lang="scss" scoped>
.footer-buttons {
position: fixed;
right: 0;
bottom: 0;
left: 0;
z-index: 100;
padding: 20rpx;
background-color: #fff;
}
:deep(.custom-button) {
box-sizing: border-box;
width: 64px !important;
min-width: auto !important;
height: 32px !important;
margin: 8rpx;
border-radius: 16px !important;
}
</style>
-356
View File
@@ -1,356 +0,0 @@
<template>
<view class="role">
<!-- 筛选 -->
<wd-drop-menu>
<wd-drop-menu-item ref="filterDropMenu" icon="filter" icon-size="18px" title="筛选">
<view>
<wd-input
v-model="queryParams.keywords"
label="关键字"
type="text"
placeholder="请输入关键字"
/>
<view class="flex-between py-2">
<wd-button custom-class="w-20%" type="info" @click="handleResetQuery">重置</wd-button>
<wd-button custom-class="w-70%" @click="handleQuery">确定</wd-button>
</view>
</view>
</wd-drop-menu-item>
</wd-drop-menu>
<!-- 卡片列表 -->
<view class="list-container">
<wd-card v-for="item in dataList" :key="item.id" class="role-card">
<template #title>
<view class="flex-between">
<view class="flex-center">
<view class="ml-2">
<view class="font-bold">
{{ item.name }}
</view>
</view>
</view>
<view>
<wd-tag v-if="item.status === 1" type="success" plain>正常</wd-tag>
<wd-tag v-else-if="item.status === 0" plain>停用</wd-tag>
</view>
</view>
</template>
<wd-cell-group>
<wd-cell title="编码" title-width="150rpx" :value="item.code" />
<wd-cell title="排序号" title-width="150rpx" :value="item.sort" />
</wd-cell-group>
<template #footer>
<view class="flex-between">
<view class="text-left">
<wd-text text="创建时间:" size="small" class="font-bold" />
<wd-text :text="item.createTime" size="small" />
</view>
<view class="flex-right">
<wd-button size="small" plain @click="handleAction(item)">操作</wd-button>
</view>
</view>
</template>
</wd-card>
<!-- 加载更多 -->
<wd-loadmore :state="loadMoreState" @reload="queryPageData" />
</view>
<!-- 底部按钮 -->
<wd-fab
position="left-bottom"
:expandable="false"
customStyle="width: 1rem; height: 1rem; line-height: 1rem;z-index:9"
@click="handleOpenDialog()"
/>
<wd-popup v-model="dialog.visible" position="bottom" custom-class="yl-popup">
<wd-form ref="roleFormRef" :model="formData" :rules="rules">
<wd-cell-group border>
<wd-input v-model="formData.name" label="角色名称" prop="name" />
<wd-input v-model="formData.code" label="角色编码" prop="code" />
<wd-select-picker
v-model="formData.dataScope"
type="radio"
label="数据权限"
:columns="dataScopeOptions"
:align-right="true"
prop="dataScope"
/>
<wd-cell title="状态" prop="status">
<wd-switch v-model="formData.status" :active-value="1" :inactive-value="0" />
</wd-cell>
<wd-cell title="排序" prop="sort">
<wd-input-number v-model="formData.sort" />
</wd-cell>
</wd-cell-group>
</wd-form>
<view class="footer">
<wd-button type="primary" block @click="handleSubmit">提交</wd-button>
</view>
</wd-popup>
<wd-message-box />
</view>
</template>
<script lang="ts" setup>
import RoleAPI, { RolePageVO, RolePageQuery, RoleForm } from "@/api/system/role";
import { onLoad, onReachBottom } from "@dcloudio/uni-app";
import { LoadMoreState } from "wot-design-uni/components/wd-loadmore/types";
import { DropMenuItemExpose } from "wot-design-uni/components/wd-drop-menu-item/types";
import { FormInstance } from "wot-design-uni/components/wd-form/types";
import { FormRules } from "wot-design-uni/components/wd-form/types";
import { useMessage } from "wot-design-uni";
const message = useMessage();
const loadMoreState = ref<LoadMoreState>("loading");
const total = ref(0);
const queryParams = reactive<RolePageQuery>({
pageNum: 1,
pageSize: 10,
});
/**
* 搜索栏
*/
const filterDropMenu = ref<DropMenuItemExpose>();
function handleQuery() {
filterDropMenu.value?.close();
queryParams.pageNum = 1;
dataList.value = [];
queryPageData();
}
/**
* 重置查询
*/
const handleResetQuery = () => {
filterDropMenu.value?.close();
queryParams.keywords = "";
queryParams.pageNum = 1;
dataList.value = [];
queryPageData();
};
// 角色列表数据
const dataList = ref<RolePageVO[]>([]);
/**
* 查询分页数据
*/
function queryPageData() {
loadMoreState.value = "loading";
RoleAPI.getPage(queryParams)
.then((data) => {
dataList.value?.push(...data.list);
total.value = data.total;
})
.catch((e) => {
console.log("系统异常", e);
})
.finally(() => {
loadMoreState.value = "finished";
});
}
/**
* 触底事件
*/
onReachBottom(() => {
if (queryParams.pageNum * queryParams.pageSize < total.value) {
queryParams.pageNum++;
queryPageData();
} else {
loadMoreState.value = "finished";
}
});
// 操作按钮
const handleAction = (item: RolePageVO) => {
const actions = ["编辑", "分配权限", "删除"];
uni.showActionSheet({
itemList: actions,
success: ({ tapIndex }) => {
switch (actions[tapIndex]) {
case "编辑":
handleOpenDialog(item.id);
break;
case "分配权限":
handleAssignPerm(item.id);
break;
case "删除":
handleDelete(item.id);
break;
}
},
});
};
const dialog = reactive({
visible: false,
});
const dataScopeOptions = ref<Record<string, any>[]>([
{ label: "全部数据", value: 0 },
{ label: "部门及子部门数据", value: 1 },
{ label: "本部门数据", value: 2 },
{ label: "本人数据", value: 3 },
]);
const formData = reactive<RoleForm>({
dataScope: 0,
sort: 1,
});
const rules: FormRules = {
name: [{ required: true, message: "请输入角色名称", trigger: "blur" }],
code: [{ required: true, message: "请输入角色编码", trigger: "blur" }],
dataScope: [{ required: true, message: "请选择数据权限", trigger: "blur" }],
status: [{ required: true, message: "请选择状态", trigger: "change" }],
sort: [{ required: true, message: "请输入排序号", trigger: "change" }],
};
const roleFormRef = ref<FormInstance>();
/**
* 打开弹窗
*/
async function handleOpenDialog(id?: number) {
dialog.visible = true;
formData.id = undefined;
formData.name = "";
formData.code = "";
formData.dataScope = 0;
formData.status = 1;
formData.sort = 1;
if (id) {
RoleAPI.getFormData(id).then((data) => {
Object.assign(formData, { ...data });
});
}
}
/**
* 提交保存
*/
function handleSubmit() {
if (roleFormRef.value) {
roleFormRef.value.validate().then(({ valid }) => {
if (valid) {
const roleId = formData.id;
if (roleId) {
RoleAPI.update(roleId, formData).then(() => {
uni.showToast({ title: "修改成功", icon: "success" });
dialog.visible = false;
queryParams.pageNum = 1;
handleQuery();
});
} else {
RoleAPI.add(formData).then(() => {
uni.showToast({ title: "添加成功", icon: "success" });
dialog.visible = false;
queryParams.pageNum = 1;
handleQuery();
});
}
}
});
}
}
/**
* 删除
*
* @param id 用户id
*/
function handleDelete(id: number) {
message
.confirm({
msg: "确认删除角色吗?",
title: "提示",
})
.then(() => {
RoleAPI.deleteByIds(id + "").then(() => {
uni.showToast({ title: "删除成功", icon: "success" });
queryParams.pageNum = 1;
handleQuery();
});
})
.catch(() => {
console.log("点击了取消按钮");
});
}
function handleAssignPerm(id: number) {
uni.navigateTo({
url: "/pages/work/role/assign-perm?id=" + id,
});
}
onLoad(() => {
handleQuery();
});
</script>
<script lang="ts">
// https://wot-design-uni.pages.dev/guide/common-problems#%E5%B0%8F%E7%A8%8B%E5%BA%8F%E6%A0%B7%E5%BC%8F%E9%9A%94%E7%A6%BB
export default {
options: {
styleIsolation: "shared",
},
};
</script>
<style lang="scss" scoped>
.role {
:deep(.wd-drop-menu .wd-drop-menu__item) {
display: flex;
justify-content: flex-end;
padding: 0 50rpx;
}
.list-container {
.role-card {
margin-top: 20rpx;
:deep(.wd-cell__wrapper) {
padding: 4rpx 0;
}
:deep(.wd-cell) {
padding-right: 10rpx;
background: #f8f8f8;
}
}
}
:deep(.wd-cell__wrapper) {
padding: 4rpx 0;
}
:deep(.wd-cell) {
padding-right: 10rpx;
background: #f8f8f8;
}
:deep(.wd-fab__trigger) {
width: 80rpx !important;
height: 80rpx !important;
}
.yl-popup {
.footer {
margin: 30rpx 0;
}
}
/**
* wot组件直接写class,在小程序上无效
* wot组件提供的custom-class属性也不能写unocss的写法
* 故wot组件只能使用custom-class属性并在vue文件中自己写样式
* 并且custom-class的类名需要使用:deep包裹,否则在小程序上也没有效果
*/
:deep(.w-20per) {
width: 20%;
}
:deep(.w-70per) {
width: 70%;
}
}
</style>
-426
View File
@@ -1,426 +0,0 @@
<template>
<!-- 自定义导航栏的占位 -->
<view style="width: 100%; height: var(--status-bar-height)" />
<view class="user-container">
<!-- 自定义导航栏 -->
<wd-navbar title="用户管理">
<template #left>
<wd-icon name="thin-arrow-left" @click="handleNavigateback()" />
</template>
</wd-navbar>
<!-- 排序筛选 -->
<view class="filter-container">
<wd-drop-menu>
<wd-drop-menu-item
v-model="sortValue"
:options="sortOptions"
title="排序"
icon="unfold-more"
@change="handleSortChange"
/>
<wd-drop-menu-item ref="filterDropMenu" title="筛选" icon="filter">
<view>
<wd-input
v-model="queryParams.keywords"
label="关键字"
placeholder="用户名/昵称/手机号"
/>
<cu-date-query v-model="queryParams.createTime" label="创建时间" />
<view class="flex-between py-2">
<wd-button type="info" @click="handleResetQuery">重置</wd-button>
<wd-button @click="handleQuery">查询</wd-button>
</view>
</view>
</wd-drop-menu-item>
</wd-drop-menu>
</view>
<!-- 数据列表 -->
<view class="data-container">
<wd-card v-for="item in pageData" :key="item.id">
<template #title>
<view class="flex-between">
<view class="flex-center">
<wd-img :width="50" :height="50" round :src="item.avatar" />
<view class="ml-2">
<view class="font-bold">
{{ item.nickname }}
<wd-icon v-if="item.gender == 1" name="gender-male" class="color-#4D80F0" />
<wd-icon
v-else-if="item.gender == 2"
name="gender-female"
class="color-#FA4350"
/>
</view>
<view class="mt-1"><wd-text :text="item.deptName" size="12px" /></view>
</view>
</view>
<view>
<wd-tag v-if="item.status === 1" type="success" plain>正常</wd-tag>
<wd-tag v-else-if="item.status === 0" plain>禁用</wd-tag>
</view>
</view>
</template>
<wd-cell-group>
<wd-cell title="用户名" :value="item.username" icon="user" />
<wd-cell title="角色" :value="item.roleNames" icon="usergroup" />
<wd-cell title="手机号码" :value="item.mobile" icon="mobile" />
<wd-cell title="邮箱" :value="item.email" icon="mail" />
</wd-cell-group>
<template #footer>
<view class="flex-between">
<view class="text-left">
<wd-text text="创建时间:" size="small" class="font-bold" />
<wd-text :text="item.createTime" size="small" />
</view>
<view class="text-right">
<wd-button
type="primary"
size="small"
plain
:v-has-perm="'sys:user:edit'"
@click="handleOpenDialog(item.id)"
>
编辑
</wd-button>
&nbsp;
<wd-button
type="error"
size="small"
plain
:v-has-perm="'sys:user:delete'"
@click="handleDelete(item.id)"
>
删除
</wd-button>
</view>
</view>
</template>
</wd-card>
<wd-loadmore v-if="total > 0" :state="loadMoreState" @reload="loadmore" />
<wd-status-tip v-else-if="total == 0" image="search" tip="当前搜索无结果" />
</view>
<!-- 弹窗表单 -->
<wd-popup v-model="dialog.visible" position="bottom" @close="hancleCloseDialog">
<wd-form ref="userFormRef" :model="formData" :rules="rules">
<wd-cell-group border>
<wd-input v-model="formData.username" label="用户名" :readonly="!formData.id" required />
<wd-input v-model="formData.nickname" label="昵称" required />
<wd-select-picker
v-model="formData.roleIds"
label="角色"
:columns="roleOptions"
required
/>
<CuPicker
v-model="formData.deptId"
v-model:data="deptOptions"
label="部门"
:required="true"
/>
<wd-input v-model="formData.mobile" label="手机号" prop="mobile" />
<wd-input v-model="formData.email" label="邮箱" prop="email" />
<wd-cell title="状态">
<wd-switch v-model="formData.status" :active-value="1" :inactive-value="0" required />
</wd-cell>
</wd-cell-group>
</wd-form>
<view class="popup-footer">
<wd-button type="primary" block @click="handleSubmit">提交</wd-button>
</view>
</wd-popup>
<!-- 悬浮操作按钮 -->
<wd-fab
:v-has-perm="'sys:user:add'"
position="left-bottom"
:expandable="false"
custom-style="z-index: 9"
@click="handleOpenDialog"
/>
<wd-message-box />
</view>
</template>
<script lang="ts" setup>
import { onLoad, onReachBottom } from "@dcloudio/uni-app";
import { LoadMoreState } from "wot-design-uni/components/wd-loadmore/types";
import { FormRules } from "wot-design-uni/components/wd-form/types";
import { useMessage } from "wot-design-uni";
import UserAPI, { type UserPageQuery, UserPageVO, UserForm } from "@/api/system/user";
import RoleAPI from "@/api/system/role";
import DeptAPI from "@/api/system/dept";
const message = useMessage();
const loadMoreState = ref<LoadMoreState>("loading");
const filterDropMenu = ref();
const userFormRef = ref();
const sortValue = ref(0);
const sortOptions = ref<Record<string, any>[]>([
{ label: "默认排序", value: 0 },
{ label: "最近创建", value: 1 },
{ label: "最近更新", value: 2 },
]);
let queryParams: UserPageQuery = {
pageNum: 1,
pageSize: 10,
};
const total = ref(0);
const pageData = ref<UserPageVO[]>([]);
const dialog = reactive({
visible: false,
});
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 rules: FormRules = {
username: [{ required: true, message: "请输入用户名" }],
nickname: [{ required: true, message: "请输入昵称" }],
roleIds: [{ required: true, message: "请选择角色" }],
deptId: [{ required: true, message: "请选择部门" }],
status: [{ required: true, message: "请选择状态" }],
mobile: [
{
required: false,
message: "手机号格式不正确",
validator: (value) => {
if (!value) {
return Promise.resolve();
}
if (!/^1[3456789]\d{9}$/.test(value)) {
return Promise.reject("手机号格式不正确");
} else {
return Promise.resolve();
}
},
},
],
email: [
{
required: false,
message: "邮箱格式不正确",
validator: (value) => {
if (!value) {
return Promise.resolve();
}
if (!/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/.test(value)) {
return Promise.reject("邮箱格式不正确");
} else {
return Promise.resolve();
}
},
},
],
};
/**
* 排序改变
*/
const handleSortChange = ({ value }: { value: number }) => {
if (value === 1) {
queryParams.field = "create_time";
queryParams.direction = "DESC";
} else if (value === 2) {
queryParams.field = "update_time";
queryParams.direction = "DESC";
} else {
queryParams.field = "";
queryParams.direction = "";
}
handleQuery();
};
/**
* 查询
*/
const handleQuery = () => {
filterDropMenu.value?.close();
queryParams.pageNum = 1;
loadmore();
console.log("queryParams", queryParams);
};
/**
* 重置查询
*/
const handleResetQuery = () => {
queryParams = {
pageNum: 1,
pageSize: 10,
};
handleQuery();
};
/**
* 加载更多
*/
function loadmore() {
loadMoreState.value = "loading";
UserAPI.getPage(queryParams)
.then((data) => {
pageData.value = data.list;
total.value = data.total;
queryParams.pageNum++;
})
.catch((e) => {
pageData.value = [];
})
.finally(() => {
loadMoreState.value = "finished";
});
}
/**
* 打开弹窗
*/
async function handleOpenDialog(id?: number) {
dialog.visible = true;
roleOptions.value = await RoleAPI.getOptions();
deptOptions.value = await DeptAPI.getOptions();
if (id) {
UserAPI.getFormData(id).then((data) => {
Object.assign(formData, { ...data });
});
}
}
/**
* 提交保存
*/
function handleSubmit() {
hancleCloseDialog();
userFormRef.value.validate().then(({ valid }: { valid: boolean }) => {
if (valid) {
const userId = formData.id;
if (userId) {
UserAPI.update(userId, formData).then(() => {
message.show("修改成功");
hancleCloseDialog();
handleQuery();
});
} else {
UserAPI.add(formData).then(() => {
message.show("添加成功");
hancleCloseDialog();
handleQuery();
});
}
}
});
}
// 重置表单
function resetForm() {
userFormRef.value.reset();
Object.assign(formData, initialFormData);
}
// 关闭弹窗
function hancleCloseDialog() {
dialog.visible = false;
resetForm();
}
/**
* 删除
*
* @param id 用户id
*/
function handleDelete(id: number) {
message
.confirm({
msg: "确认删除用户吗?",
title: "提示",
})
.then(() => {
UserAPI.deleteByIds(id + "").then(() => {
message.show("删除成功");
handleQuery();
});
});
}
/**
* 返回
*/
function handleNavigateback() {
uni.navigateBack();
}
// 触底事件
onReachBottom(() => {
if (queryParams.pageNum * queryParams.pageSize < total.value) {
loadmore();
} else if (queryParams.pageNum * queryParams.pageSize >= total.value) {
loadMoreState.value = "finished";
}
});
onLoad(() => {
handleQuery();
});
</script>
<script lang="ts">
// https://wot-design-uni.pages.dev/guide/common-problems#%E5%B0%8F%E7%A8%8B%E5%BA%8F%E6%A0%B7%E5%BC%8F%E9%9A%94%E7%A6%BB
export default {
options: {
styleIsolation: "shared",
},
};
</script>
<style lang="scss" scoped>
.user-container {
:deep(.wd-cell__wrapper) {
padding: 4rpx 0;
}
:deep(.wd-cell) {
padding-right: 10rpx;
background: #f8f8f8;
}
:deep(.wd-fab__trigger) {
width: 80rpx !important;
height: 80rpx !important;
}
.filter-container {
padding: 10rpx;
background: #fff;
}
.data-container {
margin-top: 20rpx;
}
}
</style>