提交
This commit is contained in:
1 parent
c87732fcd5
commit
058811ae77
107 files changed
+16983
-12758
No files matched your search
@@ -0,0 +1,308 @@
|
||||
<!-- 登录页面 -->
|
||||
<template>
|
||||
<div class="login-container">
|
||||
<!-- 左侧品牌区域 -->
|
||||
<div class="login-left">
|
||||
<div class="brand-content">
|
||||
<div class="logo">
|
||||
<img class="logo-img" src="/logo1.jpg" alt="陇耘鲜达" />
|
||||
</div>
|
||||
<h1 class="slogan">专业生鲜配送管理平台</h1>
|
||||
<p class="description">
|
||||
高效 · 智能 · 可信赖
|
||||
</p>
|
||||
<div class="features">
|
||||
<div class="feature-item">
|
||||
<i class="el-icon-present"></i>
|
||||
<span>订单管理</span>
|
||||
</div>
|
||||
<div class="feature-item">
|
||||
<i class="el-icon-truck"></i>
|
||||
<span>配送调度</span>
|
||||
</div>
|
||||
<div class="feature-item">
|
||||
<i class="el-icon-data-analysis"></i>
|
||||
<span>数据统计</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 右侧登录表单区域 -->
|
||||
<div class="login-right">
|
||||
<div class="form-container">
|
||||
<div class="form-header">
|
||||
<h2>欢迎登录</h2>
|
||||
<p>请输入您的账号信息</p>
|
||||
</div>
|
||||
|
||||
<el-form
|
||||
ref="formRef"
|
||||
:model="formData"
|
||||
:rules="rules"
|
||||
@keyup.enter="handleSubmit"
|
||||
class="login-form"
|
||||
>
|
||||
<el-form-item prop="username">
|
||||
<el-input
|
||||
v-model.trim="formData.username"
|
||||
placeholder="请输入用户名"
|
||||
size="large"
|
||||
:prefix-icon="User"
|
||||
/>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item prop="password">
|
||||
<el-input
|
||||
v-model.trim="formData.password"
|
||||
type="password"
|
||||
placeholder="请输入密码"
|
||||
size="large"
|
||||
:prefix-icon="Lock"
|
||||
show-password
|
||||
autocomplete="off"
|
||||
/>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item>
|
||||
<el-button
|
||||
type="primary"
|
||||
size="large"
|
||||
:loading="loading"
|
||||
class="login-btn"
|
||||
@click="handleSubmit"
|
||||
>
|
||||
登 录
|
||||
</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
|
||||
<div class="form-footer">
|
||||
<span class="copyright">陇耘鲜达 © {{ currentYear }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { useUserStore } from '@/store/modules/user'
|
||||
import { fetchLogin } from '@/api/auth'
|
||||
import { ElNotification, type FormInstance, type FormRules } from 'element-plus'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { User, Lock } from '@element-plus/icons-vue'
|
||||
|
||||
defineOptions({ name: 'Login' })
|
||||
|
||||
const currentYear = new Date().getFullYear()
|
||||
|
||||
const userStore = useUserStore()
|
||||
const router = useRouter()
|
||||
const route = useRoute()
|
||||
|
||||
const formRef = ref<FormInstance>()
|
||||
|
||||
const formData = reactive({
|
||||
username: '',
|
||||
password: ''
|
||||
})
|
||||
|
||||
const rules: FormRules = {
|
||||
username: [{ required: true, message: '请输入用户名', trigger: 'blur' }],
|
||||
password: [{ required: true, message: '请输入密码', trigger: 'blur' }]
|
||||
}
|
||||
|
||||
const loading = ref(false)
|
||||
|
||||
// 登录
|
||||
const handleSubmit = async () => {
|
||||
if (!formRef.value) return
|
||||
|
||||
try {
|
||||
const valid = await formRef.value.validate()
|
||||
if (!valid) return
|
||||
|
||||
loading.value = true
|
||||
|
||||
const { token, refreshToken, userInfo } = await fetchLogin({
|
||||
username: formData.username,
|
||||
password: formData.password
|
||||
})
|
||||
|
||||
if (!token) {
|
||||
throw new Error('登录失败:未收到令牌')
|
||||
}
|
||||
|
||||
// 存储 token 和登录状态
|
||||
userStore.setToken(token, refreshToken)
|
||||
userStore.setLoginStatus(true)
|
||||
userStore.setUserInfo(userInfo)
|
||||
|
||||
ElNotification({
|
||||
title: '登录成功',
|
||||
type: 'success',
|
||||
duration: 2500,
|
||||
message: `欢迎回来,${userInfo.realName || userInfo.username}!`
|
||||
})
|
||||
|
||||
// 获取 redirect 参数,如果存在则跳转到指定页面,否则跳转到首页
|
||||
const redirect = route.query.redirect as string
|
||||
router.push(redirect || '/')
|
||||
} catch (error: any) {
|
||||
ElMessage.error(error?.message || '登录失败,请稍后重试')
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.login-container {
|
||||
display: flex;
|
||||
width: 100%;
|
||||
height: 100vh;
|
||||
background: #f5f7fa;
|
||||
}
|
||||
|
||||
.login-left {
|
||||
flex: 1;
|
||||
background: linear-gradient(135deg, #1989fa 0%, #07c160 100%);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 40px;
|
||||
|
||||
@media (max-width: 768px) {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
|
||||
.brand-content {
|
||||
color: #fff;
|
||||
text-align: center;
|
||||
max-width: 400px;
|
||||
}
|
||||
|
||||
.logo {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
margin-bottom: 48px;
|
||||
}
|
||||
|
||||
.logo-img {
|
||||
width: min(200px, 55vw);
|
||||
height: auto;
|
||||
object-fit: contain;
|
||||
border-radius: 12px;
|
||||
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
|
||||
}
|
||||
|
||||
.slogan {
|
||||
font-size: 32px;
|
||||
font-weight: 600;
|
||||
margin: 0 0 16px 0;
|
||||
}
|
||||
|
||||
.description {
|
||||
font-size: 18px;
|
||||
opacity: 0.9;
|
||||
margin: 0 0 48px 0;
|
||||
}
|
||||
|
||||
.features {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
gap: 40px;
|
||||
}
|
||||
|
||||
.feature-item {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
|
||||
i {
|
||||
font-size: 32px;
|
||||
}
|
||||
|
||||
span {
|
||||
font-size: 14px;
|
||||
opacity: 0.9;
|
||||
}
|
||||
}
|
||||
|
||||
.login-right {
|
||||
width: 480px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background: #fff;
|
||||
padding: 40px;
|
||||
|
||||
@media (max-width: 768px) {
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
|
||||
.form-container {
|
||||
width: 100%;
|
||||
max-width: 360px;
|
||||
}
|
||||
|
||||
.form-header {
|
||||
margin-bottom: 40px;
|
||||
text-align: center;
|
||||
|
||||
h2 {
|
||||
font-size: 28px;
|
||||
font-weight: 600;
|
||||
color: #303133;
|
||||
margin: 0 0 12px 0;
|
||||
}
|
||||
|
||||
p {
|
||||
font-size: 14px;
|
||||
color: #909399;
|
||||
margin: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.login-form {
|
||||
:deep(.el-form-item) {
|
||||
margin-bottom: 24px;
|
||||
}
|
||||
|
||||
:deep(.el-input__wrapper) {
|
||||
padding: 8px 16px;
|
||||
border-radius: 8px;
|
||||
}
|
||||
|
||||
:deep(.el-input__inner) {
|
||||
height: 44px;
|
||||
}
|
||||
}
|
||||
|
||||
.login-btn {
|
||||
width: 100%;
|
||||
height: 48px;
|
||||
font-size: 16px;
|
||||
border-radius: 8px;
|
||||
background: linear-gradient(135deg, #1989fa 0%, #07c160 100%);
|
||||
border: none;
|
||||
|
||||
&:hover {
|
||||
opacity: 0.9;
|
||||
}
|
||||
}
|
||||
|
||||
.form-footer {
|
||||
margin-top: 40px;
|
||||
text-align: center;
|
||||
|
||||
.copyright {
|
||||
font-size: 12px;
|
||||
color: #c0c4cc;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,38 @@
|
||||
@reference '@styles/core/tailwind.css';
|
||||
|
||||
/* 授权页右侧区域 */
|
||||
.auth-right-wrap {
|
||||
@apply absolute inset-0 w-[440px] h-[650px] py-[5px] m-auto overflow-hidden
|
||||
max-sm:px-7 max-sm:w-full
|
||||
animate-[slideInRight_0.6s_cubic-bezier(0.25,0.46,0.45,0.94)_forwards]
|
||||
max-md:animate-none;
|
||||
|
||||
.form {
|
||||
@apply h-full py-[40px];
|
||||
}
|
||||
|
||||
.title {
|
||||
@apply text-g-900 text-4xl font-semibold max-md:text-3xl max-sm:pt-10;
|
||||
}
|
||||
|
||||
.sub-title {
|
||||
@apply mt-[10px] text-g-600 text-sm;
|
||||
}
|
||||
|
||||
.custom-height {
|
||||
@apply !h-[40px];
|
||||
}
|
||||
}
|
||||
|
||||
/* 滑入动画 */
|
||||
@keyframes slideInRight {
|
||||
from {
|
||||
opacity: 0;
|
||||
transform: translateX(30px);
|
||||
}
|
||||
|
||||
to {
|
||||
opacity: 1;
|
||||
transform: translateX(0);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
<!-- 精简工作台:无业务统计接口,仅作入口与 UI 规范说明 -->
|
||||
<template>
|
||||
<div class="console-container console-lite">
|
||||
<div class="page-head">
|
||||
<h1>工作台</h1>
|
||||
<p class="page-desc">以下为固定参考页,新增管理端界面请对照布局与类名;视觉以文档为准。</p>
|
||||
</div>
|
||||
|
||||
<section class="panel">
|
||||
<div class="panel-top">
|
||||
<h2 class="title-bar-heading">快速入口</h2>
|
||||
</div>
|
||||
<div class="console-lite__body">
|
||||
<p class="console-lite__hint">详见仓库根目录 `.cursorrules` 中「页面级 UI 模板(固定五页)」。</p>
|
||||
<div class="console-lite__links">
|
||||
<el-button
|
||||
v-for="item in links"
|
||||
:key="item.path"
|
||||
class="btn-main"
|
||||
type="primary"
|
||||
@click="go(item.path)"
|
||||
>
|
||||
{{ item.label }}
|
||||
</el-button>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { useRouter } from 'vue-router'
|
||||
|
||||
defineOptions({ name: 'Console' })
|
||||
|
||||
const router = useRouter()
|
||||
|
||||
const links = [
|
||||
{ label: '商品单位', path: '/demo/unit' },
|
||||
{ label: '订单列表', path: '/demo/order' },
|
||||
{ label: '商品管理', path: '/demo/product' },
|
||||
{ label: '商品分类', path: '/demo/category' },
|
||||
{ label: '用户管理', path: '/demo/user' }
|
||||
]
|
||||
|
||||
const go = (path: string) => {
|
||||
router.push(path)
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
.console-lite__body {
|
||||
padding: 20px 24px 24px;
|
||||
}
|
||||
|
||||
.console-lite__hint {
|
||||
margin: 0 0 16px;
|
||||
font-size: 13px;
|
||||
line-height: 1.5;
|
||||
color: var(--art-text-gray-600, #64748b);
|
||||
}
|
||||
|
||||
.console-lite__links {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 12px;
|
||||
}
|
||||
</style>
|
||||
@@ -1,36 +1,42 @@
|
||||
<!-- 外链 iframe 占位(动态路由中 isIframe 时使用) -->
|
||||
<template>
|
||||
<div class="iframe-page">
|
||||
<iframe v-if="src" class="iframe-page__frame" :src="src" title="external" />
|
||||
<p v-else class="iframe-page__empty">未配置链接</p>
|
||||
<div class="box-border w-full h-full" v-loading="isLoading">
|
||||
<iframe
|
||||
ref="iframeRef"
|
||||
:src="iframeUrl"
|
||||
frameborder="0"
|
||||
class="w-full h-full min-h-[calc(100vh-120px)] border-none"
|
||||
@load="handleIframeLoad"
|
||||
></iframe>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue'
|
||||
import { useRoute } from 'vue-router'
|
||||
import { IframeRouteManager } from '@/router/core'
|
||||
|
||||
defineOptions({ name: 'IframePage' })
|
||||
defineOptions({ name: 'IframeView' })
|
||||
|
||||
const route = useRoute()
|
||||
const src = computed(() => (route.meta?.link as string) || '')
|
||||
const isLoading = ref(true)
|
||||
const iframeUrl = ref('')
|
||||
const iframeRef = ref<HTMLIFrameElement | null>(null)
|
||||
|
||||
/**
|
||||
* 初始化 iframe URL
|
||||
* 从路由配置中获取对应的外部链接地址
|
||||
*/
|
||||
onMounted(() => {
|
||||
const iframeRoute = IframeRouteManager.getInstance().findByPath(route.path)
|
||||
|
||||
if (iframeRoute?.meta) {
|
||||
iframeUrl.value = iframeRoute.meta.link || ''
|
||||
}
|
||||
})
|
||||
|
||||
/**
|
||||
* 处理 iframe 加载完成事件
|
||||
* 隐藏加载状态
|
||||
*/
|
||||
const handleIframeLoad = (): void => {
|
||||
isLoading.value = false
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
.iframe-page {
|
||||
height: 100%;
|
||||
min-height: 400px;
|
||||
}
|
||||
|
||||
.iframe-page__frame {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
min-height: 400px;
|
||||
border: none;
|
||||
}
|
||||
|
||||
.iframe-page__empty {
|
||||
padding: 24px;
|
||||
color: var(--el-text-color-secondary);
|
||||
}
|
||||
</style>
|
||||
File diff suppressed because it is too large.
Load diff
@@ -1,205 +0,0 @@
|
||||
<!-- 登录页布局样式参考(不请求后端) -->
|
||||
<template>
|
||||
<div class="login-container">
|
||||
<div class="login-left">
|
||||
<div class="brand-content">
|
||||
<div class="logo">
|
||||
<img class="logo-img" src="/logo1.jpg" alt="中科兴皖一体化门户" />
|
||||
</div>
|
||||
<h1 class="slogan">一体化业务管理与服务平台</h1>
|
||||
<p class="description">本页仅作布局与配色参考</p>
|
||||
<div class="features">
|
||||
<div class="feature-item"><span>面板</span></div>
|
||||
<div class="feature-item"><span>表格</span></div>
|
||||
<div class="feature-item"><span>表单</span></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="login-right">
|
||||
<div class="form-container">
|
||||
<div class="form-header">
|
||||
<h2>欢迎登录</h2>
|
||||
<p>演示表单,提交不会调用接口</p>
|
||||
</div>
|
||||
<el-form ref="formRef" :model="formData" :rules="rules" class="login-form">
|
||||
<el-form-item prop="username">
|
||||
<el-input v-model.trim="formData.username" placeholder="用户名" size="large" :prefix-icon="User" />
|
||||
</el-form-item>
|
||||
<el-form-item prop="password">
|
||||
<el-input
|
||||
v-model.trim="formData.password"
|
||||
type="password"
|
||||
placeholder="密码"
|
||||
size="large"
|
||||
:prefix-icon="Lock"
|
||||
show-password
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button type="primary" size="large" class="login-btn" @click="onSubmit">登 录</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<div class="form-footer">
|
||||
<span class="copyright">中科兴皖一体化门户 © {{ currentYear }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, reactive } from 'vue'
|
||||
import { User, Lock } from '@element-plus/icons-vue'
|
||||
import type { FormInstance, FormRules } from 'element-plus'
|
||||
import { ElMessage } from 'element-plus'
|
||||
|
||||
defineOptions({ name: 'LoginSample' })
|
||||
|
||||
const currentYear = new Date().getFullYear()
|
||||
const formRef = ref<FormInstance>()
|
||||
const formData = reactive({ username: '', password: '' })
|
||||
const rules: FormRules = {
|
||||
username: [{ required: true, message: '请输入用户名', trigger: 'blur' }],
|
||||
password: [{ required: true, message: '请输入密码', trigger: 'blur' }]
|
||||
}
|
||||
|
||||
const onSubmit = async () => {
|
||||
if (!formRef.value) return
|
||||
await formRef.value.validate().catch(() => {})
|
||||
ElMessage.info('样式参考页:未连接后端')
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.login-container {
|
||||
display: flex;
|
||||
width: 100%;
|
||||
min-height: 100%;
|
||||
background: #f5f7fa;
|
||||
}
|
||||
|
||||
.login-left {
|
||||
flex: 1;
|
||||
background: linear-gradient(135deg, #10b981 0%, #059669 100%);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 40px;
|
||||
|
||||
@media (max-width: 768px) {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
|
||||
.brand-content {
|
||||
color: #fff;
|
||||
text-align: center;
|
||||
max-width: 400px;
|
||||
}
|
||||
|
||||
.logo {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
margin-bottom: 48px;
|
||||
}
|
||||
|
||||
.logo-img {
|
||||
width: min(200px, 55vw);
|
||||
height: auto;
|
||||
object-fit: contain;
|
||||
border-radius: 12px;
|
||||
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
|
||||
}
|
||||
|
||||
.slogan {
|
||||
font-size: 32px;
|
||||
font-weight: 600;
|
||||
margin: 0 0 16px 0;
|
||||
}
|
||||
|
||||
.description {
|
||||
font-size: 16px;
|
||||
opacity: 0.95;
|
||||
margin: 0 0 48px 0;
|
||||
}
|
||||
|
||||
.features {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
gap: 40px;
|
||||
}
|
||||
|
||||
.feature-item span {
|
||||
font-size: 14px;
|
||||
opacity: 0.95;
|
||||
}
|
||||
|
||||
.login-right {
|
||||
width: 480px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background: #fff;
|
||||
padding: 40px;
|
||||
|
||||
@media (max-width: 768px) {
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
|
||||
.form-container {
|
||||
width: 100%;
|
||||
max-width: 360px;
|
||||
}
|
||||
|
||||
.form-header {
|
||||
margin-bottom: 40px;
|
||||
text-align: center;
|
||||
|
||||
h2 {
|
||||
font-size: 28px;
|
||||
font-weight: 600;
|
||||
color: #303133;
|
||||
margin: 0 0 12px 0;
|
||||
}
|
||||
|
||||
p {
|
||||
font-size: 14px;
|
||||
color: #909399;
|
||||
margin: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.login-form {
|
||||
:deep(.el-form-item) {
|
||||
margin-bottom: 24px;
|
||||
}
|
||||
|
||||
:deep(.el-input__wrapper) {
|
||||
padding: 8px 16px;
|
||||
border-radius: 8px;
|
||||
}
|
||||
|
||||
:deep(.el-input__inner) {
|
||||
height: 44px;
|
||||
}
|
||||
}
|
||||
|
||||
.login-btn {
|
||||
width: 100%;
|
||||
height: 48px;
|
||||
font-size: 16px;
|
||||
border-radius: 8px;
|
||||
}
|
||||
|
||||
.form-footer {
|
||||
margin-top: 40px;
|
||||
text-align: center;
|
||||
|
||||
.copyright {
|
||||
font-size: 12px;
|
||||
color: #c0c4cc;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -1,98 +0,0 @@
|
||||
<!-- Fresh Mint 设计 Token 与面板片段参考(无接口) -->
|
||||
<template>
|
||||
<div class="page-container mint-tokens-page">
|
||||
<header class="page-head">
|
||||
<h1>Mint Token 与面板</h1>
|
||||
<p class="page-desc">与全局 SCSS 变量、Element 主色链对齐的局部示意,便于新页面拷贝结构。</p>
|
||||
</header>
|
||||
|
||||
<section class="panel">
|
||||
<div class="panel-top">
|
||||
<h2 class="title-bar-heading">色板</h2>
|
||||
</div>
|
||||
<div class="token-grid">
|
||||
<div v-for="t in tokens" :key="t.name" class="token-card">
|
||||
<div class="token-swatch" :style="{ background: t.value }" />
|
||||
<div class="token-meta">
|
||||
<div class="token-name">{{ t.name }}</div>
|
||||
<div class="token-value">{{ t.value }}</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="panel">
|
||||
<div class="panel-top">
|
||||
<h2 class="title-bar-heading">按钮</h2>
|
||||
</div>
|
||||
<div class="btn-row">
|
||||
<el-button type="primary">主按钮</el-button>
|
||||
<el-button>次要</el-button>
|
||||
<el-button plain>描边</el-button>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
defineOptions({ name: 'MintTokensSample' })
|
||||
|
||||
const tokens = [
|
||||
{ name: '--primary', value: '#10b981' },
|
||||
{ name: '--primary-dark', value: '#059669' },
|
||||
{ name: '--primary-bg', value: '#ecfdf5' },
|
||||
{ name: '--text', value: '#1e293b' },
|
||||
{ name: '--text-muted', value: '#64748b' },
|
||||
{ name: '--border', value: '#d9e8e2' }
|
||||
]
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
.mint-tokens-page {
|
||||
padding-bottom: 24px;
|
||||
}
|
||||
|
||||
.token-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
|
||||
gap: 12px;
|
||||
padding: 16px;
|
||||
}
|
||||
|
||||
.token-card {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
padding: 12px;
|
||||
border: 1px solid var(--default-border-color, #d9e8e2);
|
||||
border-radius: 10px;
|
||||
background: #fff;
|
||||
}
|
||||
|
||||
.token-swatch {
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
border-radius: 8px;
|
||||
border: 1px solid rgba(0, 0, 0, 0.06);
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.token-name {
|
||||
font-size: 13px;
|
||||
font-weight: 600;
|
||||
color: #1e293b;
|
||||
}
|
||||
|
||||
.token-value {
|
||||
font-size: 12px;
|
||||
color: #64748b;
|
||||
font-family: ui-monospace, monospace;
|
||||
}
|
||||
|
||||
.btn-row {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 10px;
|
||||
padding: 16px;
|
||||
}
|
||||
</style>
|
||||
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,327 @@
|
||||
<!-- 租户管理(系统管理) -->
|
||||
<!-- eslint-disable vue/no-v-model-argument -->
|
||||
<template>
|
||||
<div class="page-container">
|
||||
<header class="page-head">
|
||||
<h1>租户管理</h1>
|
||||
<p class="page-desc">维护多租户编号与名称;编号「{{ DEFAULT_TENANT_NO }}」为平台默认租户,不可删除且不可改编号。</p>
|
||||
</header>
|
||||
|
||||
<section class="panel">
|
||||
<div class="panel-top">
|
||||
<h2 class="title-bar-heading">租户列表</h2>
|
||||
</div>
|
||||
|
||||
<div class="filter-block">
|
||||
<el-form :model="searchForm" class="filter-form" @submit.prevent>
|
||||
<div class="filter-grid">
|
||||
<el-form-item label="关键词">
|
||||
<el-input v-model="searchForm.keyword" placeholder="租户编号/名称" clearable />
|
||||
</el-form-item>
|
||||
</div>
|
||||
<div class="filter-actions-row">
|
||||
<span class="filter-hint">按租户编号、名称模糊查询。</span>
|
||||
<div class="filter-actions-end">
|
||||
<el-button class="btn-ghost" @click="handleReset">重置</el-button>
|
||||
<el-button class="btn-main" type="primary" @click="handleSearch">搜索</el-button>
|
||||
</div>
|
||||
</div>
|
||||
</el-form>
|
||||
</div>
|
||||
|
||||
<div class="list-toolbar">
|
||||
<div class="list-toolbar-row">
|
||||
<div class="list-toolbar-selected">
|
||||
已选 <span class="sel-num">{{ selectedRows.length }}</span> 项
|
||||
</div>
|
||||
<el-button class="btn-main" type="primary" @click="handleAdd">
|
||||
<el-icon><Plus /></el-icon>
|
||||
新增租户
|
||||
</el-button>
|
||||
<el-button
|
||||
class="btn-ghost"
|
||||
type="danger"
|
||||
:disabled="deletableSelection.length === 0"
|
||||
@click="handleBatchDelete"
|
||||
>
|
||||
批量删除
|
||||
</el-button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="list-body list-wrap">
|
||||
<el-table
|
||||
class="list-table"
|
||||
:data="tableData"
|
||||
v-loading="loading"
|
||||
stripe
|
||||
row-key="id"
|
||||
@selection-change="handleSelectionChange"
|
||||
>
|
||||
<el-table-column type="selection" width="55" align="center" header-align="center" :selectable="rowSelectable" />
|
||||
<el-table-column
|
||||
type="index"
|
||||
label="序号"
|
||||
width="68"
|
||||
align="center"
|
||||
header-align="center"
|
||||
:index="(index) => (pagination.page - 1) * pagination.pageSize + index + 1"
|
||||
/>
|
||||
<el-table-column prop="tenantNo" label="租户编号" min-width="120" align="center" header-align="center">
|
||||
<template #default="{ row }">
|
||||
<span>{{ row.tenantNo }}</span>
|
||||
<el-tag v-if="isDefaultTenantRow(row)" class="tag muted" size="small" style="margin-left: 8px">默认</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="tenantName" label="租户名称" min-width="160" align="center" header-align="center" />
|
||||
<el-table-column prop="contactName" label="联系人" min-width="100" align="center" header-align="center" />
|
||||
<el-table-column prop="contactPhone" label="联系电话" min-width="120" align="center" header-align="center" />
|
||||
<el-table-column prop="orderNum" label="排序" width="80" align="center" header-align="center" />
|
||||
<el-table-column prop="createTime" label="创建时间" min-width="160" align="center" header-align="center" />
|
||||
<el-table-column label="操作" width="260" fixed="right" align="center" header-align="center">
|
||||
<template #default="{ row }">
|
||||
<el-button class="btn-op-item primary" @click="handleEdit(row)">编辑</el-button>
|
||||
<el-button class="btn-op-item" :disabled="isDefaultTenantRow(row)" @click="handleDelete(row)">删除</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
<div class="pagination list-pager-bar">
|
||||
<el-pagination
|
||||
:current-page="pagination.page"
|
||||
:page-size="pagination.pageSize"
|
||||
:total="pagination.total"
|
||||
:page-sizes="[10, 20, 50]"
|
||||
layout="total, sizes, prev, pager, next"
|
||||
@size-change="(val) => ((pagination.page = 1), (pagination.pageSize = val), loadData())"
|
||||
@current-change="(val) => ((pagination.page = val), loadData())"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<el-dialog v-model="dialogVisible" :title="dialogTitle" width="560px">
|
||||
<el-form
|
||||
ref="formRef"
|
||||
:model="formData"
|
||||
:rules="formRules"
|
||||
label-position="top"
|
||||
class="tenant-dialog-form"
|
||||
scroll-to-error
|
||||
>
|
||||
<div class="form-grid-2">
|
||||
<el-form-item label="租户编号" prop="tenantNo">
|
||||
<el-input
|
||||
v-model="formData.tenantNo"
|
||||
placeholder="业务唯一编码,如 demo01"
|
||||
:disabled="isEdit && isDefaultTenantNo(formData.tenantNo)"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="租户名称" prop="tenantName">
|
||||
<el-input v-model="formData.tenantName" placeholder="展示名称" />
|
||||
</el-form-item>
|
||||
<el-form-item label="联系人">
|
||||
<el-input v-model="formData.contactName" placeholder="可选" />
|
||||
</el-form-item>
|
||||
<el-form-item label="联系电话">
|
||||
<el-input v-model="formData.contactPhone" placeholder="可选" />
|
||||
</el-form-item>
|
||||
<el-form-item label="排序">
|
||||
<div class="sort-field">
|
||||
<el-input-number v-model="formData.orderNum" :min="0" :max="9999" controls-position="right" />
|
||||
<span class="form-tip">数值越小越靠前</span>
|
||||
</div>
|
||||
</el-form-item>
|
||||
<el-form-item label="备注" style="grid-column: 1 / -1">
|
||||
<el-input v-model="formData.remark" type="textarea" :rows="2" placeholder="可选" />
|
||||
</el-form-item>
|
||||
</div>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<el-button class="btn-ghost" @click="dialogVisible = false">
|
||||
<el-icon><Close /></el-icon>
|
||||
取消
|
||||
</el-button>
|
||||
<el-button class="btn-main" type="primary" @click="handleSubmit" :loading="submitLoading">
|
||||
<el-icon><Check /></el-icon>
|
||||
确定
|
||||
</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</section>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, reactive, onMounted, computed } from 'vue'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
import { Plus, Close, Check } from '@element-plus/icons-vue'
|
||||
import { fetchTenantList, fetchCreateTenant, fetchUpdateTenant, fetchDeleteTenant } from '@/api/admin'
|
||||
|
||||
/** 与后端 `settings.DEFAULT_TENANT_NO` 一致 */
|
||||
const DEFAULT_TENANT_NO = 'zkxw'
|
||||
|
||||
defineOptions({ name: 'SystemTenant' })
|
||||
|
||||
const searchForm = reactive<{ keyword: string }>({ keyword: '' })
|
||||
const tableData = ref<Api.Tenant.TenantItem[]>([])
|
||||
const selectedRows = ref<Api.Tenant.TenantItem[]>([])
|
||||
const loading = ref(false)
|
||||
const pagination = reactive({ page: 1, pageSize: 10, total: 0 })
|
||||
const dialogVisible = ref(false)
|
||||
const dialogTitle = ref('新增租户')
|
||||
const isEdit = ref(false)
|
||||
const submitLoading = ref(false)
|
||||
const formRef = ref()
|
||||
const editingId = ref<string | null>(null)
|
||||
|
||||
const formData = reactive({
|
||||
tenantNo: '',
|
||||
tenantName: '',
|
||||
contactName: '',
|
||||
contactPhone: '',
|
||||
orderNum: 0,
|
||||
remark: ''
|
||||
})
|
||||
|
||||
const formRules = {
|
||||
tenantNo: [{ required: true, message: '请输入租户编号', trigger: 'blur' }],
|
||||
tenantName: [{ required: true, message: '请输入租户名称', trigger: 'blur' }]
|
||||
}
|
||||
|
||||
const deletableSelection = computed(() => selectedRows.value.filter((r) => !isDefaultTenantRow(r)))
|
||||
|
||||
function isDefaultTenantNo(no: string) {
|
||||
return (no || '').trim() === DEFAULT_TENANT_NO
|
||||
}
|
||||
|
||||
function isDefaultTenantRow(row: Api.Tenant.TenantItem) {
|
||||
return isDefaultTenantNo(row.tenantNo)
|
||||
}
|
||||
|
||||
function rowSelectable(row: Api.Tenant.TenantItem) {
|
||||
return !isDefaultTenantRow(row)
|
||||
}
|
||||
|
||||
const handleSelectionChange = (rows: Api.Tenant.TenantItem[]) => {
|
||||
selectedRows.value = rows
|
||||
}
|
||||
|
||||
async function loadData() {
|
||||
loading.value = true
|
||||
try {
|
||||
const res = await fetchTenantList({
|
||||
page: pagination.page,
|
||||
pageSize: pagination.pageSize,
|
||||
keyword: searchForm.keyword || undefined
|
||||
})
|
||||
tableData.value = res.list || []
|
||||
pagination.total = res.total ?? 0
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function handleSearch() {
|
||||
pagination.page = 1
|
||||
loadData()
|
||||
}
|
||||
|
||||
function handleReset() {
|
||||
searchForm.keyword = ''
|
||||
pagination.page = 1
|
||||
loadData()
|
||||
}
|
||||
|
||||
function resetForm() {
|
||||
formData.tenantNo = ''
|
||||
formData.tenantName = ''
|
||||
formData.contactName = ''
|
||||
formData.contactPhone = ''
|
||||
formData.orderNum = 0
|
||||
formData.remark = ''
|
||||
editingId.value = null
|
||||
}
|
||||
|
||||
function handleAdd() {
|
||||
isEdit.value = false
|
||||
dialogTitle.value = '新增租户'
|
||||
resetForm()
|
||||
dialogVisible.value = true
|
||||
formRef.value?.clearValidate?.()
|
||||
}
|
||||
|
||||
function handleEdit(row: Api.Tenant.TenantItem) {
|
||||
isEdit.value = true
|
||||
dialogTitle.value = '编辑租户'
|
||||
editingId.value = row.id
|
||||
formData.tenantNo = row.tenantNo
|
||||
formData.tenantName = row.tenantName
|
||||
formData.contactName = row.contactName || ''
|
||||
formData.contactPhone = row.contactPhone || ''
|
||||
formData.orderNum = row.orderNum ?? 0
|
||||
formData.remark = row.remark || ''
|
||||
dialogVisible.value = true
|
||||
formRef.value?.clearValidate?.()
|
||||
}
|
||||
|
||||
async function handleSubmit() {
|
||||
await formRef.value?.validate?.()
|
||||
submitLoading.value = true
|
||||
try {
|
||||
const payload = {
|
||||
tenantNo: formData.tenantNo.trim(),
|
||||
tenantName: formData.tenantName.trim(),
|
||||
contactName: formData.contactName?.trim() || undefined,
|
||||
contactPhone: formData.contactPhone?.trim() || undefined,
|
||||
orderNum: formData.orderNum,
|
||||
remark: formData.remark?.trim() || undefined
|
||||
}
|
||||
if (isEdit.value && editingId.value) {
|
||||
await fetchUpdateTenant(editingId.value, payload)
|
||||
} else {
|
||||
await fetchCreateTenant(payload)
|
||||
}
|
||||
dialogVisible.value = false
|
||||
await loadData()
|
||||
} catch {
|
||||
/* 校验或接口错误已由全局处理 */
|
||||
} finally {
|
||||
submitLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function handleDelete(row: Api.Tenant.TenantItem) {
|
||||
if (isDefaultTenantRow(row)) {
|
||||
ElMessage.warning('默认租户不可删除')
|
||||
return
|
||||
}
|
||||
await ElMessageBox.confirm(`确定删除租户「${row.tenantName}」吗?`, '提示', { type: 'warning' })
|
||||
await fetchDeleteTenant(row.id)
|
||||
await loadData()
|
||||
}
|
||||
|
||||
async function handleBatchDelete() {
|
||||
const ids = deletableSelection.value.map((r) => r.id)
|
||||
if (!ids.length) {
|
||||
ElMessage.warning('所选中含默认租户或无可删项,请重新选择')
|
||||
return
|
||||
}
|
||||
await ElMessageBox.confirm(`确定删除选中的 ${ids.length} 个租户吗?`, '提示', { type: 'warning' })
|
||||
for (const id of ids) {
|
||||
await fetchDeleteTenant(id)
|
||||
}
|
||||
selectedRows.value = []
|
||||
await loadData()
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
loadData()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
.tenant-dialog-form {
|
||||
:deep(.el-form-item) {
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,434 @@
|
||||
<!-- 商品单位管理 -->
|
||||
<!-- eslint-disable vue/no-v-model-argument -->
|
||||
<template>
|
||||
<div class="page-container">
|
||||
<header class="page-head">
|
||||
<h1>单位管理</h1>
|
||||
<p class="page-desc">统一维护商品计量单位与排序规则。</p>
|
||||
</header>
|
||||
|
||||
<section class="panel">
|
||||
<div class="panel-top">
|
||||
<h2 class="title-bar-heading">单位列表</h2>
|
||||
</div>
|
||||
|
||||
<div class="filter-block">
|
||||
<el-form :model="searchForm" class="filter-form" @submit.prevent>
|
||||
<div class="filter-grid">
|
||||
<el-form-item label="关键词">
|
||||
<el-input v-model="searchForm.keyword" placeholder="单位名称/编码" clearable />
|
||||
</el-form-item>
|
||||
<el-form-item label="状态">
|
||||
<el-select v-model="searchForm.isActive" placeholder="请选择状态" clearable>
|
||||
<el-option label="全部" value="" />
|
||||
<el-option label="启用" :value="true" />
|
||||
<el-option label="禁用" :value="false" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</div>
|
||||
<div class="filter-actions-row">
|
||||
<span class="filter-hint">按名称、编码与状态过滤单位数据。</span>
|
||||
<div class="filter-actions-end">
|
||||
<el-button class="btn-ghost" @click="handleReset">重置</el-button>
|
||||
<el-button class="btn-main" type="primary" @click="handleSearch">搜索</el-button>
|
||||
</div>
|
||||
</div>
|
||||
</el-form>
|
||||
</div>
|
||||
|
||||
<div class="list-toolbar">
|
||||
<div class="list-toolbar-row">
|
||||
<div class="list-toolbar-selected">
|
||||
已选 <span class="sel-num">{{ selectedRows.length }}</span> 项
|
||||
</div>
|
||||
<el-button class="btn-main" type="primary" @click="handleAdd"><el-icon><Plus /></el-icon>新增单位</el-button>
|
||||
|
||||
<el-button class="btn-ghost" type="danger" :disabled="selectedRows.length === 0" @click="handleBatchDelete">
|
||||
批量删除
|
||||
</el-button>
|
||||
|
||||
<ArtExcelExport
|
||||
:data="batchExportData"
|
||||
:list-total="pagination.total"
|
||||
:load-all-data="loadAllUnitsForExport"
|
||||
:filename="unitExportFilename"
|
||||
sheetName="单位数据"
|
||||
:columns="unitExportColumns"
|
||||
>
|
||||
批量导出
|
||||
</ArtExcelExport>
|
||||
|
||||
<ArtExcelExport
|
||||
:data="unitImportTemplateData"
|
||||
:filename="unitImportTemplateFilename"
|
||||
sheetName="单位导入模板"
|
||||
:columns="unitImportTemplateColumns"
|
||||
:showSuccessMessage="false"
|
||||
:showErrorMessage="false"
|
||||
>
|
||||
下载导入模板
|
||||
</ArtExcelExport>
|
||||
|
||||
<ArtExcelImport @import-success="handleUnitImportSuccess" @import-error="handleExcelImportError">
|
||||
<el-button class="btn-ghost">批量导入</el-button>
|
||||
</ArtExcelImport>
|
||||
</div>
|
||||
</div>
|
||||
<div class="list-body list-wrap">
|
||||
<el-table class="list-table" :data="tableData" v-loading="loading" stripe row-key="id" @selection-change="handleSelectionChange">
|
||||
<el-table-column type="selection" width="55" align="center" header-align="center" />
|
||||
<el-table-column
|
||||
type="index"
|
||||
label="序号"
|
||||
width="68"
|
||||
align="center"
|
||||
header-align="center"
|
||||
:index="index => (pagination.page - 1) * pagination.pageSize + index + 1"
|
||||
/>
|
||||
<el-table-column prop="name" label="单位名称" min-width="150" align="center" header-align="center" />
|
||||
<el-table-column prop="code" label="单位编码" min-width="120" align="center" header-align="center" />
|
||||
<el-table-column prop="isActive" label="状态" min-width="80" align="center" header-align="center">
|
||||
<template #default="{ row }">
|
||||
<el-tag :type="row.isActive ? 'success' : 'info'" size="small">{{ row.isActive ? '启用' : '禁用' }}</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="排序号" width="90" align="center" header-align="center">
|
||||
<template #default="{ row }">
|
||||
{{ row.sortOrder ?? row.sort_order ?? 0 }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="操作" width="260" fixed="right" align="center" header-align="center">
|
||||
<template #default="{ row }">
|
||||
<el-button class="btn-op-item primary" @click="handleEdit(row)">编辑</el-button>
|
||||
<el-button class="btn-op-item" @click="handleDelete(row)">删除</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
<div class="pagination list-pager-bar">
|
||||
<el-pagination
|
||||
:current-page="pagination.page"
|
||||
:page-size="pagination.pageSize"
|
||||
:total="pagination.total"
|
||||
:page-sizes="[10, 20, 50]"
|
||||
layout="total, sizes, prev, pager, next"
|
||||
@size-change="val => (pagination.page = 1, pagination.pageSize = val, loadData())"
|
||||
@current-change="val => (pagination.page = val, loadData())"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<el-dialog v-model="dialogVisible" :title="dialogTitle" width="560px">
|
||||
<el-form
|
||||
ref="formRef"
|
||||
:model="formData"
|
||||
:rules="formRules"
|
||||
label-position="top"
|
||||
class="unit-dialog-form"
|
||||
>
|
||||
<div class="form-grid-2">
|
||||
<el-form-item label="单位名称" prop="name">
|
||||
<el-input v-model="formData.name" placeholder="如:斤、kg、个" />
|
||||
</el-form-item>
|
||||
<el-form-item label="单位编码" prop="code">
|
||||
<el-input v-model="formData.code" placeholder="如:jin、kg、ge" />
|
||||
</el-form-item>
|
||||
<el-form-item label="排序">
|
||||
<div class="sort-field">
|
||||
<el-input-number v-model="formData.sortOrder" :min="0" :max="9999" controls-position="right" />
|
||||
<span class="form-tip">数值越小越靠前</span>
|
||||
</div>
|
||||
</el-form-item>
|
||||
<el-form-item label="状态" v-if="isEdit"><el-switch v-model="formData.isActive" /></el-form-item>
|
||||
</div>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<el-button class="btn-ghost" @click="dialogVisible = false">
|
||||
<el-icon><Close /></el-icon>
|
||||
取消
|
||||
</el-button>
|
||||
<el-button class="btn-main" type="primary" @click="handleSubmit" :loading="submitLoading">
|
||||
<el-icon><Check /></el-icon>
|
||||
确定
|
||||
</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</section>
|
||||
</div>
|
||||
</template>
|
||||
<script setup lang="ts">
|
||||
import { ref, reactive, onMounted, computed } from 'vue'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
import { withFullscreenLoading, fullscreenLoadingText } from '@/utils/fullscreen-loading'
|
||||
import { Plus, Close, Check } from '@element-plus/icons-vue'
|
||||
import { fetchUnitList, fetchCreateUnit, fetchUpdateUnit, fetchDeleteUnit } from '../../../api/admin'
|
||||
import { fetchNextSortOrder } from '../../../utils/sort-order'
|
||||
import { fetchAllPagedRecords } from '../../../utils/fetch-paged-list'
|
||||
defineOptions({ name: 'ProductUnit' })
|
||||
const searchForm = reactive<{ keyword: string; isActive: boolean | '' }>({ keyword: '', isActive: '' })
|
||||
const tableData = ref<any[]>([])
|
||||
const selectedRows = ref<any[]>([])
|
||||
const loading = ref(false)
|
||||
const pagination = reactive({ page: 1, pageSize: 10, total: 0 })
|
||||
const dialogVisible = ref(false)
|
||||
const dialogTitle = ref('新增单位')
|
||||
const isEdit = ref(false)
|
||||
const submitLoading = ref(false)
|
||||
const formRef = ref()
|
||||
const handleSelectionChange = (rows: any[]) => {
|
||||
selectedRows.value = rows
|
||||
}
|
||||
|
||||
const unitExportFilename = 'base_unit_batch_export'
|
||||
const unitImportTemplateFilename = 'base_unit_import_template'
|
||||
|
||||
const unitExportColumns = {
|
||||
id: { title: 'id' },
|
||||
name: { title: '单位名称' },
|
||||
code: { title: '单位编码' },
|
||||
sortOrder: { title: '排序' },
|
||||
isActive: { title: '状态' }
|
||||
} as const
|
||||
|
||||
const unitImportTemplateColumns = {
|
||||
id: { title: 'id' },
|
||||
name: { title: '单位名称' },
|
||||
code: { title: '单位编码' },
|
||||
sortOrder: { title: '排序' },
|
||||
isActive: { title: '状态' }
|
||||
} as const
|
||||
|
||||
const unitImportTemplateData = [
|
||||
{
|
||||
id: '',
|
||||
name: '',
|
||||
code: '',
|
||||
sortOrder: 0,
|
||||
isActive: true
|
||||
}
|
||||
]
|
||||
|
||||
const mapUnitExportRow = (row: any) => ({
|
||||
id: row.id,
|
||||
name: row.name,
|
||||
code: row.code,
|
||||
sortOrder: row.sortOrder ?? row.sort_order ?? 0,
|
||||
isActive: row.isActive
|
||||
})
|
||||
|
||||
const batchExportData = computed(() => {
|
||||
const sel = selectedRows.value || []
|
||||
if (sel.length === 0) return []
|
||||
return sel.map(mapUnitExportRow)
|
||||
})
|
||||
|
||||
const loadAllUnitsForExport = async () => {
|
||||
const all = await fetchAllPagedRecords((page, pageSize) =>
|
||||
fetchUnitList({
|
||||
page,
|
||||
pageSize,
|
||||
keyword: searchForm.keyword || undefined,
|
||||
isActive: searchForm.isActive === '' ? undefined : searchForm.isActive
|
||||
})
|
||||
)
|
||||
return all.map(mapUnitExportRow)
|
||||
}
|
||||
|
||||
// ======================
|
||||
// 批量删除
|
||||
// ======================
|
||||
const handleBatchDelete = async () => {
|
||||
if (selectedRows.value.length === 0) return
|
||||
try {
|
||||
await ElMessageBox.confirm(`确定要删除选中的 ${selectedRows.value.length} 条单位吗?`, '提示', {
|
||||
confirmButtonText: '确定',
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning'
|
||||
})
|
||||
|
||||
await withFullscreenLoading(async () => {
|
||||
for (const row of selectedRows.value) {
|
||||
await fetchDeleteUnit(row.id)
|
||||
}
|
||||
ElMessage.success('批量删除成功')
|
||||
selectedRows.value = []
|
||||
loadData()
|
||||
}, fullscreenLoadingText.batchDelete)
|
||||
} catch (error: any) {
|
||||
if (error !== 'cancel') console.error('批量删除失败:', error)
|
||||
}
|
||||
}
|
||||
|
||||
// ======================
|
||||
// Excel 导入
|
||||
// ======================
|
||||
const importLoading = ref(false)
|
||||
|
||||
const parseNumber = (v: any, defaultValue: number) => {
|
||||
if (v === null || v === undefined || v === '') return defaultValue
|
||||
const n = Number(v)
|
||||
return Number.isFinite(n) ? n : defaultValue
|
||||
}
|
||||
|
||||
const parseBool = (v: any, defaultValue: boolean) => {
|
||||
if (v === null || v === undefined || v === '') return defaultValue
|
||||
if (typeof v === 'boolean') return v
|
||||
const s = String(v).trim().toLowerCase()
|
||||
if (['1', 'true', 'yes', '启用', 'enabled'].includes(s)) return true
|
||||
if (['0', 'false', 'no', '禁用', 'disabled'].includes(s)) return false
|
||||
return defaultValue
|
||||
}
|
||||
|
||||
const getExcelValue = (row: any, keys: string[]) => {
|
||||
for (const k of keys) {
|
||||
const v = row?.[k]
|
||||
if (v !== undefined && v !== null && String(v).trim() !== '') return v
|
||||
}
|
||||
return undefined
|
||||
}
|
||||
|
||||
const handleExcelImportError = (error: Error) => {
|
||||
ElMessage.error(`导入失败:${error.message}`)
|
||||
}
|
||||
|
||||
const handleUnitImportSuccess = async (rows: Array<Record<string, unknown>>) => {
|
||||
if (importLoading.value) return
|
||||
importLoading.value = true
|
||||
|
||||
try {
|
||||
if (!Array.isArray(rows) || rows.length === 0) {
|
||||
ElMessage.warning('没有可导入的数据')
|
||||
return
|
||||
}
|
||||
|
||||
let successCount = 0
|
||||
let failCount = 0
|
||||
|
||||
for (const raw of rows) {
|
||||
const id = String(getExcelValue(raw, ['id', 'ID']) ?? '').trim()
|
||||
const name = String(getExcelValue(raw, ['name', '单位名称']) ?? '').trim()
|
||||
const code = String(getExcelValue(raw, ['code', '单位编码']) ?? '').trim()
|
||||
const sortOrder = parseNumber(getExcelValue(raw, ['sortOrder', '排序', 'sort_order']) as any, 0)
|
||||
const isActive = parseBool(getExcelValue(raw, ['isActive', '状态', 'is_active']) as any, true)
|
||||
|
||||
if (!name || !code) {
|
||||
failCount++
|
||||
continue
|
||||
}
|
||||
|
||||
const payload: any = { name, code, sortOrder, isActive }
|
||||
|
||||
if (id) {
|
||||
await fetchUpdateUnit(id, payload)
|
||||
} else {
|
||||
await fetchCreateUnit(payload)
|
||||
}
|
||||
|
||||
successCount++
|
||||
}
|
||||
|
||||
ElMessage.success(`导入完成:成功 ${successCount} 条,失败 ${failCount} 条`)
|
||||
selectedRows.value = []
|
||||
loadData()
|
||||
} catch (error: any) {
|
||||
console.error('导入单位失败:', error)
|
||||
ElMessage.error(`导入单位失败:${error?.message || error}`)
|
||||
} finally {
|
||||
importLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const formData = reactive({ id: '', name: '', code: '', isActive: true, sortOrder: 0 })
|
||||
const formRules = {
|
||||
name: [{ required: true, message: '请输入单位名称', trigger: 'blur' }],
|
||||
code: [{ required: true, message: '请输入单位编码', trigger: 'blur' }]
|
||||
}
|
||||
const loadData = async () => {
|
||||
selectedRows.value = []
|
||||
loading.value = true
|
||||
try {
|
||||
const res = await fetchUnitList({
|
||||
page: pagination.page,
|
||||
pageSize: pagination.pageSize,
|
||||
keyword: searchForm.keyword || undefined,
|
||||
isActive: searchForm.isActive === '' ? undefined : searchForm.isActive
|
||||
})
|
||||
const list = res.list || []
|
||||
tableData.value = list.map((item: any) => ({
|
||||
...item,
|
||||
sortOrder: item.sortOrder ?? item.sort_order ?? 0
|
||||
}))
|
||||
pagination.total = res.total
|
||||
} catch (error) { console.error('加载数据失败:', error) } finally { loading.value = false }
|
||||
}
|
||||
const handleSearch = () => { pagination.page = 1; loadData() }
|
||||
const handleReset = () => { Object.assign(searchForm, { keyword: '', isActive: '' }); loadData() }
|
||||
const handleAdd = async () => {
|
||||
dialogTitle.value = '新增单位'
|
||||
isEdit.value = false
|
||||
const next = await fetchNextSortOrder(params =>
|
||||
fetchUnitList({ ...params, keyword: undefined, isActive: undefined })
|
||||
)
|
||||
Object.assign(formData, { id: '', name: '', code: '', isActive: true, sortOrder: next })
|
||||
dialogVisible.value = true
|
||||
}
|
||||
const handleEdit = (row: any) => { dialogTitle.value = '编辑单位'; isEdit.value = true; Object.assign(formData, row); dialogVisible.value = true }
|
||||
const handleDelete = async (row: any) => {
|
||||
try {
|
||||
await ElMessageBox.confirm('确定要删除该单位吗?', '提示', { type: 'warning' })
|
||||
await withFullscreenLoading(async () => {
|
||||
await fetchDeleteUnit(row.id)
|
||||
}, fullscreenLoadingText.delete)
|
||||
ElMessage.success('删除成功')
|
||||
loadData()
|
||||
} catch (error: any) {
|
||||
if (error !== 'cancel') console.error('删除失败:', error)
|
||||
}
|
||||
}
|
||||
const handleSubmit = async () => {
|
||||
if (!formRef.value) return
|
||||
try {
|
||||
await formRef.value.validate()
|
||||
submitLoading.value = true
|
||||
await withFullscreenLoading(async () => {
|
||||
if (isEdit.value) {
|
||||
const updateData: any = { name: formData.name, code: formData.code, sort_order: formData.sortOrder }
|
||||
updateData.is_active = formData.isActive
|
||||
await fetchUpdateUnit(formData.id, updateData)
|
||||
} else {
|
||||
await fetchCreateUnit({ name: formData.name, code: formData.code, sortOrder: formData.sortOrder, isActive: formData.isActive } as any)
|
||||
}
|
||||
ElMessage.success(isEdit.value ? '更新成功' : '创建成功')
|
||||
dialogVisible.value = false
|
||||
loadData()
|
||||
}, fullscreenLoadingText.save)
|
||||
} catch (error) {
|
||||
console.error('提交失败:', error)
|
||||
} finally {
|
||||
submitLoading.value = false
|
||||
}
|
||||
}
|
||||
onMounted(() => loadData())
|
||||
</script>
|
||||
<style lang="scss" scoped>
|
||||
.unit-dialog-form {
|
||||
:deep(.el-form-item__label) {
|
||||
font-size: 11px;
|
||||
font-weight: 500;
|
||||
color: var(--mint-text-muted);
|
||||
padding: 0 0 4px;
|
||||
line-height: 1.2;
|
||||
}
|
||||
}
|
||||
|
||||
.form-grid-2 {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
gap: 12px 20px;
|
||||
}
|
||||
|
||||
.sort-field {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.form-tip { margin-left: 8px; color: #909399; font-size: 12px; }
|
||||
</style>
|
||||
@@ -0,0 +1,797 @@
|
||||
<!-- 用户详情页面 -->
|
||||
<template>
|
||||
<div class="page-container">
|
||||
<!-- 返回按钮 -->
|
||||
<div class="back-bar">
|
||||
<el-button @click="goBack" type="primary" plain>
|
||||
<el-icon><ArrowLeft /></el-icon>
|
||||
返回列表
|
||||
</el-button>
|
||||
</div>
|
||||
|
||||
<!-- 基本信息卡片 -->
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<span class="card-title">基本信息</span>
|
||||
<div class="header-actions">
|
||||
<el-button @click="handleResetPassword" type="warning" size="small">重置密码</el-button>
|
||||
<el-button @click="handleToggleStatus" :type="userData.isActive ? 'danger' : 'success'" size="small">
|
||||
{{ userData.isActive ? '禁用账号' : '启用账号' }}
|
||||
</el-button>
|
||||
<el-button @click="handleEdit" type="primary" size="small">编辑</el-button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 用户头像和信息 -->
|
||||
<div class="profile-section">
|
||||
<el-avatar :size="80" :src="detailAvatarUrl" class="detail-user-avatar">
|
||||
{{ getAvatarInitial }}
|
||||
</el-avatar>
|
||||
<div class="profile-info">
|
||||
<div class="profile-name">{{ userData.realName }}</div>
|
||||
<div class="profile-tags">
|
||||
<el-tag :type="getRoleTagType(userData.role)" size="small">{{ getRoleText(userData.role) }}</el-tag>
|
||||
<el-tag :type="userData.isActive ? 'success' : 'danger'" size="small">{{ userData.isActive ? '启用' : '禁用' }}</el-tag>
|
||||
<el-tag v-if="userData.regionName" size="small">{{ userData.regionName }}</el-tag>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 基本信息网格 -->
|
||||
<div class="info-grid">
|
||||
<div class="info-item">
|
||||
<div class="info-label">用户名</div>
|
||||
<div class="info-value">{{ userData.username }}</div>
|
||||
</div>
|
||||
<div class="info-item">
|
||||
<div class="info-label">姓名</div>
|
||||
<div class="info-value">{{ userData.realName }}</div>
|
||||
</div>
|
||||
<div class="info-item">
|
||||
<div class="info-label">手机号</div>
|
||||
<div class="info-value">{{ userData.phone }}</div>
|
||||
</div>
|
||||
<div class="info-item">
|
||||
<div class="info-label">角色</div>
|
||||
<div class="info-value">{{ getRoleText(userData.role) }}</div>
|
||||
</div>
|
||||
<div class="info-item">
|
||||
<div class="info-label">所属区域</div>
|
||||
<div class="info-value">{{ userData.regionName || '-' }}</div>
|
||||
</div>
|
||||
<div class="info-item">
|
||||
<div class="info-label">账号状态</div>
|
||||
<div class="info-value" :style="{ color: userData.isActive ? '#059669' : '#dc2626' }">
|
||||
{{ userData.isActive ? '正常' : '已禁用' }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="info-item">
|
||||
<div class="info-label">创建时间</div>
|
||||
<div class="info-value">{{ userData.createAt }}</div>
|
||||
</div>
|
||||
<div class="info-item">
|
||||
<div class="info-label">最后登录</div>
|
||||
<div class="info-value">{{ userData.lastLoginTime || '-' }}</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 供应商/客户专属信息 -->
|
||||
<div v-if="userData.role === 'supplier'" class="address-section">
|
||||
<div class="address-title">取货地址</div>
|
||||
<div class="address-row">
|
||||
<span class="address-label">联系人</span>
|
||||
<span class="address-value">{{ supplierData.contactPerson || '-' }}</span>
|
||||
</div>
|
||||
<div class="address-row">
|
||||
<span class="address-label">联系电话</span>
|
||||
<span class="address-value">{{ supplierData.contactPhone || '-' }}</span>
|
||||
</div>
|
||||
<div class="address-row">
|
||||
<span class="address-label">详细地址</span>
|
||||
<span class="address-value">{{ supplierData.address || '-' }}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="userData.role === 'client'" class="address-section">
|
||||
<div class="address-title">
|
||||
<span>收货地址</span>
|
||||
<el-button @click="handleAddAddress" type="primary" link size="small">+ 添加地址</el-button>
|
||||
</div>
|
||||
<div v-if="clientAddresses.length > 0" class="address-list">
|
||||
<div v-for="addr in clientAddresses" :key="addr.id" class="address-item">
|
||||
<div class="address-info">
|
||||
<div class="address-contact">
|
||||
{{ addr.contactPerson }} {{ addr.contactPhone }}
|
||||
<el-tag v-if="addr.isDefault" size="small" type="success" class="ml-2">默认</el-tag>
|
||||
</div>
|
||||
<div class="address-detail">{{ addr.province }}{{ addr.city }}{{ addr.district }}{{ addr.detailAddress }}</div>
|
||||
</div>
|
||||
<div class="address-actions">
|
||||
<el-button type="primary" link @click="handleEditAddress(addr)">编辑</el-button>
|
||||
<el-button type="danger" link @click="handleDeleteAddress(addr)">删除</el-button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<el-empty v-else description="暂无收货地址" :image-size="60" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 业务统计卡片 -->
|
||||
<div v-if="userData.role === 'supplier'" class="card">
|
||||
<div class="card-header">
|
||||
<span class="card-title">业务统计</span>
|
||||
</div>
|
||||
<div class="stats-grid">
|
||||
<div class="stat-card">
|
||||
<div class="stat-num">{{ supplierStats.quotationCount }}</div>
|
||||
<div class="stat-label">报价次数</div>
|
||||
</div>
|
||||
<div class="stat-card">
|
||||
<div class="stat-num">{{ supplierStats.selectedCount }}</div>
|
||||
<div class="stat-label">被选中次数</div>
|
||||
</div>
|
||||
<div class="stat-card">
|
||||
<div class="stat-num">{{ supplierStats.orderCount }}</div>
|
||||
<div class="stat-label">供货订单数</div>
|
||||
</div>
|
||||
<div class="stat-card">
|
||||
<div class="stat-num amount">¥{{ formatAmount(supplierStats.totalAmount) }}</div>
|
||||
<div class="stat-label">累计供货金额(元)</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="userData.role === 'client'" class="card">
|
||||
<div class="card-header">
|
||||
<span class="card-title">订单统计</span>
|
||||
</div>
|
||||
<div class="stats-grid">
|
||||
<div class="stat-card">
|
||||
<div class="stat-num">{{ clientStats.totalOrders }}</div>
|
||||
<div class="stat-label">总订单数</div>
|
||||
</div>
|
||||
<div class="stat-card">
|
||||
<div class="stat-num">{{ clientStats.completedOrders }}</div>
|
||||
<div class="stat-label">已完成</div>
|
||||
</div>
|
||||
<div class="stat-card">
|
||||
<div class="stat-num">{{ clientStats.pendingOrders }}</div>
|
||||
<div class="stat-label">进行中</div>
|
||||
</div>
|
||||
<div class="stat-card">
|
||||
<div class="stat-num amount" style="color: #dc2626;">¥{{ formatAmount(clientStats.pendingAmount) }}</div>
|
||||
<div class="stat-label">待结算金额(元)</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 登录记录 -->
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<span class="card-title">最近登录记录</span>
|
||||
</div>
|
||||
<el-table :data="loginLogs" stripe max-height="300">
|
||||
<el-table-column type="index" label="序号" width="68" align="center" header-align="center" :index="index => index + 1" />
|
||||
<el-table-column prop="loginTime" label="登录时间" min-width="180" />
|
||||
<el-table-column prop="ipAddress" label="IP地址" min-width="150" />
|
||||
<el-table-column prop="loginLocation" label="登录地点" min-width="150" />
|
||||
<el-table-column prop="device" label="设备" min-width="120" />
|
||||
<el-table-column prop="result" label="结果" min-width="100" align="center">
|
||||
<template #default="{ row }">
|
||||
<el-tag :type="row.result === 'success' ? 'success' : 'danger'" size="small">
|
||||
{{ row.result === 'success' ? '成功' : '失败' }}
|
||||
</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="failReason" label="失败原因" min-width="150">
|
||||
<template #default="{ row }">
|
||||
<span v-if="row.result === 'fail'" style="color: #dc2626;">{{ row.failReason }}</span>
|
||||
<span v-else>-</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
</div>
|
||||
|
||||
<!-- 编辑用户弹窗 -->
|
||||
<el-dialog v-model="editVisible" title="编辑用户" width="600px" destroy-on-close>
|
||||
<el-form ref="editFormRef" :model="editForm" :rules="editFormRules" label-width="100px">
|
||||
<el-form-item label="姓名" prop="realName">
|
||||
<el-input v-model="editForm.realName" placeholder="请输入姓名" />
|
||||
</el-form-item>
|
||||
<el-form-item label="手机号" prop="phone">
|
||||
<el-input v-model="editForm.phone" placeholder="请输入手机号" />
|
||||
</el-form-item>
|
||||
<el-form-item label="所属区域" prop="regionId">
|
||||
<el-select v-model="editForm.regionId" placeholder="请选择区域">
|
||||
<el-option v-for="r in regionList" :key="r.id" :label="r.name" :value="r.id" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="状态">
|
||||
<el-switch v-model="editForm.isActive" />
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<el-button @click="editVisible = false">取消</el-button>
|
||||
<el-button type="primary" @click="confirmEdit" :loading="submitLoading">确定</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
|
||||
<!-- 地址编辑弹窗 -->
|
||||
<el-dialog v-model="addressVisible" :title="addressForm.id ? '编辑地址' : '添加地址'" width="600px" destroy-on-close>
|
||||
<el-form ref="addressFormRef" :model="addressForm" :rules="addressFormRules" label-width="100px">
|
||||
<el-form-item label="联系人" prop="contactPerson">
|
||||
<el-input v-model="addressForm.contactPerson" placeholder="请输入联系人" />
|
||||
</el-form-item>
|
||||
<el-form-item label="联系电话" prop="contactPhone">
|
||||
<el-input v-model="addressForm.contactPhone" placeholder="请输入联系电话" />
|
||||
</el-form-item>
|
||||
<el-form-item label="省份" prop="province">
|
||||
<el-input v-model="addressForm.province" placeholder="请输入省份" />
|
||||
</el-form-item>
|
||||
<el-form-item label="城市" prop="city">
|
||||
<el-input v-model="addressForm.city" placeholder="请输入城市" />
|
||||
</el-form-item>
|
||||
<el-form-item label="区县" prop="district">
|
||||
<el-input v-model="addressForm.district" placeholder="请输入区县" />
|
||||
</el-form-item>
|
||||
<el-form-item label="详细地址" prop="detailAddress">
|
||||
<el-input v-model="addressForm.detailAddress" type="textarea" :rows="2" placeholder="请输入详细地址" />
|
||||
</el-form-item>
|
||||
<el-form-item label="设为默认">
|
||||
<el-switch v-model="addressForm.isDefault" />
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<el-button @click="addressVisible = false">取消</el-button>
|
||||
<el-button type="primary" @click="confirmAddress" :loading="submitLoading">确定</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, reactive, computed, onMounted, watch } from 'vue'
|
||||
import { useRouter, useRoute } from 'vue-router'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
import { withFullscreenLoading, fullscreenLoadingText } from '@/utils/fullscreen-loading'
|
||||
import { ArrowLeft } from '@element-plus/icons-vue'
|
||||
import { fetchUserDetail, fetchUpdateUser, fetchActiveRegions } from '@/api/admin'
|
||||
import { resolveUserAvatarUrl } from '@/utils/user-avatar'
|
||||
import type { FormInstance, FormRules } from 'element-plus'
|
||||
|
||||
defineOptions({ name: 'UserDetail' })
|
||||
|
||||
const router = useRouter()
|
||||
const route = useRoute()
|
||||
|
||||
// 用户基本信息
|
||||
const userData = ref<any>({
|
||||
username: '',
|
||||
realName: '',
|
||||
phone: '',
|
||||
avatarUrl: '',
|
||||
role: '',
|
||||
regionName: '',
|
||||
isActive: true,
|
||||
createAt: '',
|
||||
lastLoginTime: ''
|
||||
})
|
||||
|
||||
// 供应商专属数据
|
||||
const supplierData = ref({
|
||||
contactPerson: '',
|
||||
contactPhone: '',
|
||||
address: ''
|
||||
})
|
||||
|
||||
const supplierStats = reactive({
|
||||
quotationCount: 0,
|
||||
selectedCount: 0,
|
||||
orderCount: 0,
|
||||
totalAmount: 0
|
||||
})
|
||||
|
||||
// 客户专属数据
|
||||
const clientAddresses = ref<any[]>([])
|
||||
|
||||
const clientStats = reactive({
|
||||
totalOrders: 0,
|
||||
completedOrders: 0,
|
||||
pendingOrders: 0,
|
||||
pendingAmount: 0
|
||||
})
|
||||
|
||||
// 登录记录
|
||||
const loginLogs = ref<any[]>([])
|
||||
|
||||
// 区域列表
|
||||
const regionList = ref<any[]>([])
|
||||
|
||||
// 编辑弹窗
|
||||
const editVisible = ref(false)
|
||||
const editFormRef = ref<FormInstance>()
|
||||
const submitLoading = ref(false)
|
||||
const editForm = reactive({
|
||||
id: '',
|
||||
realName: '',
|
||||
phone: '',
|
||||
regionId: '',
|
||||
isActive: true
|
||||
})
|
||||
|
||||
const editFormRules: FormRules = {
|
||||
realName: [{ required: true, message: '请输入姓名', trigger: 'blur' }],
|
||||
phone: [{ required: true, message: '请输入手机号', trigger: 'blur' }]
|
||||
}
|
||||
|
||||
// 地址编辑弹窗
|
||||
const addressVisible = ref(false)
|
||||
const addressFormRef = ref<FormInstance>()
|
||||
const addressForm = reactive({
|
||||
id: '',
|
||||
contactPerson: '',
|
||||
contactPhone: '',
|
||||
province: '',
|
||||
city: '',
|
||||
district: '',
|
||||
detailAddress: '',
|
||||
isDefault: false
|
||||
})
|
||||
|
||||
const addressFormRules: FormRules = {
|
||||
contactPerson: [{ required: true, message: '请输入联系人', trigger: 'blur' }],
|
||||
contactPhone: [{ required: true, message: '请输入联系电话', trigger: 'blur' }],
|
||||
detailAddress: [{ required: true, message: '请输入详细地址', trigger: 'blur' }]
|
||||
}
|
||||
|
||||
const detailAvatarUrl = computed(() =>
|
||||
resolveUserAvatarUrl(userData.value.avatarUrl, userData.value.role)
|
||||
)
|
||||
|
||||
const getAvatarInitial = computed(() => {
|
||||
return userData.value.realName?.charAt(0) || '?'
|
||||
})
|
||||
|
||||
// 获取角色相关
|
||||
const getRoleTagType = (role: string) => {
|
||||
const typeMap: Record<string, string> = {
|
||||
admin: 'primary',
|
||||
supplier: 'warning',
|
||||
client: 'success',
|
||||
deliver: 'info'
|
||||
}
|
||||
return typeMap[role] || 'info'
|
||||
}
|
||||
|
||||
const getRoleText = (role: string) => {
|
||||
const textMap: Record<string, string> = {
|
||||
admin: '运营管理员',
|
||||
supplier: '供应商',
|
||||
client: '客户',
|
||||
deliver: '配送员'
|
||||
}
|
||||
return textMap[role] || role
|
||||
}
|
||||
|
||||
// 格式化金额
|
||||
const formatAmount = (amount: number | string) => {
|
||||
const num = typeof amount === 'string' ? parseFloat(amount) : amount
|
||||
return isNaN(num) ? '0.00' : num.toLocaleString('zh-CN', { minimumFractionDigits: 2, maximumFractionDigits: 2 })
|
||||
}
|
||||
|
||||
// 返回列表
|
||||
const goBack = () => {
|
||||
router.push('/demo/user')
|
||||
}
|
||||
|
||||
// 加载数据
|
||||
const loadData = async () => {
|
||||
const userId = route.query.id as string
|
||||
if (!userId) {
|
||||
ElMessage.error('用户ID不能为空')
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
const res = await fetchUserDetail(userId)
|
||||
userData.value = {
|
||||
...res,
|
||||
regionName: res.regionName || (regionList.value.find(r => r.id === res.regionId)?.name || '')
|
||||
}
|
||||
|
||||
// 根据角色加载专属数据
|
||||
if (res.role === 'supplier') {
|
||||
supplierData.value = res.supplierInfo || {
|
||||
contactPerson: '张伟',
|
||||
contactPhone: '13800138001',
|
||||
address: '城东区XX路XX号 XX仓库'
|
||||
}
|
||||
supplierStats.quotationCount = res.quotationCount || 28
|
||||
supplierStats.selectedCount = res.selectedCount || 15
|
||||
supplierStats.orderCount = res.orderCount || 86
|
||||
supplierStats.totalAmount = res.totalAmount || 125680
|
||||
}
|
||||
|
||||
if (res.role === 'client') {
|
||||
clientAddresses.value = res.addresses || [
|
||||
{
|
||||
id: '1',
|
||||
contactPerson: '王小明',
|
||||
contactPhone: '13900009999',
|
||||
province: '浙江省',
|
||||
city: '杭州市',
|
||||
district: '西湖区',
|
||||
detailAddress: 'XX路XX号 XX餐厅',
|
||||
isDefault: true
|
||||
}
|
||||
]
|
||||
clientStats.totalOrders = res.totalOrders || 156
|
||||
clientStats.completedOrders = res.completedOrders || 128
|
||||
clientStats.pendingOrders = res.pendingOrders || 28
|
||||
clientStats.pendingAmount = res.pendingAmount || 12560
|
||||
}
|
||||
|
||||
// 加载登录记录
|
||||
loginLogs.value = res.loginLogs || [
|
||||
{ loginTime: '2026-03-19 09:15:30', ipAddress: '192.168.1.100', loginLocation: '浙江省杭州市', device: 'iOS', result: 'success' },
|
||||
{ loginTime: '2026-03-18 14:22:15', ipAddress: '192.168.1.100', loginLocation: '浙江省杭州市', device: 'Windows', result: 'success' },
|
||||
{ loginTime: '2026-03-17 08:45:00', ipAddress: '192.168.1.101', loginLocation: '浙江省杭州市', device: 'Android', result: 'fail', failReason: '密码错误' },
|
||||
{ loginTime: '2026-03-16 16:30:22', ipAddress: '192.168.1.100', loginLocation: '浙江省杭州市', device: 'Windows', result: 'success' }
|
||||
]
|
||||
} catch (error) {
|
||||
console.error('加载用户详情失败:', error)
|
||||
ElMessage.error('加载用户详情失败')
|
||||
}
|
||||
}
|
||||
|
||||
// 加载区域
|
||||
const loadRegions = async () => {
|
||||
try {
|
||||
const res = await fetchActiveRegions()
|
||||
regionList.value = res
|
||||
} catch (error) {
|
||||
console.error('加载区域失败:', error)
|
||||
}
|
||||
}
|
||||
|
||||
// 编辑用户
|
||||
const handleEdit = () => {
|
||||
editForm.id = userData.value.id
|
||||
editForm.realName = userData.value.realName
|
||||
editForm.phone = userData.value.phone
|
||||
editForm.regionId = userData.value.regionId
|
||||
editForm.isActive = userData.value.isActive
|
||||
editVisible.value = true
|
||||
}
|
||||
|
||||
const confirmEdit = async () => {
|
||||
if (!editFormRef.value) return
|
||||
try {
|
||||
await editFormRef.value.validate()
|
||||
submitLoading.value = true
|
||||
await withFullscreenLoading(async () => {
|
||||
await fetchUpdateUser(editForm.id, {
|
||||
realName: editForm.realName,
|
||||
phone: editForm.phone,
|
||||
regionId: editForm.regionId || undefined,
|
||||
isActive: editForm.isActive
|
||||
})
|
||||
ElMessage.success('更新成功')
|
||||
editVisible.value = false
|
||||
loadData()
|
||||
}, fullscreenLoadingText.save)
|
||||
} catch (error) {
|
||||
console.error('更新失败:', error)
|
||||
} finally {
|
||||
submitLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// 重置密码
|
||||
const handleResetPassword = async () => {
|
||||
try {
|
||||
await ElMessageBox.confirm(
|
||||
`确定要重置用户「${userData.value.realName}」的密码吗?重置后密码将恢复为默认密码。`,
|
||||
'重置密码',
|
||||
{
|
||||
confirmButtonText: '确认重置',
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning'
|
||||
}
|
||||
)
|
||||
ElMessage.success('密码已重置,默认密码为:123456')
|
||||
} catch (error) {
|
||||
// 取消操作
|
||||
}
|
||||
}
|
||||
|
||||
// 切换账号状态
|
||||
const handleToggleStatus = async () => {
|
||||
const action = userData.value.isActive ? '禁用' : '启用'
|
||||
try {
|
||||
await ElMessageBox.confirm(
|
||||
`确定要${action}用户「${userData.value.realName}」的账号吗?`,
|
||||
`${action}账号`,
|
||||
{
|
||||
confirmButtonText: '确认',
|
||||
cancelButtonText: '取消',
|
||||
type: userData.value.isActive ? 'warning' : 'success'
|
||||
}
|
||||
)
|
||||
await withFullscreenLoading(async () => {
|
||||
await fetchUpdateUser(userData.value.id, { isActive: !userData.value.isActive })
|
||||
ElMessage.success(`${action}成功`)
|
||||
userData.value.isActive = !userData.value.isActive
|
||||
}, fullscreenLoadingText.save)
|
||||
} catch (error) {
|
||||
// 取消操作
|
||||
}
|
||||
}
|
||||
|
||||
// 添加地址
|
||||
const handleAddAddress = () => {
|
||||
addressForm.id = ''
|
||||
addressForm.contactPerson = ''
|
||||
addressForm.contactPhone = ''
|
||||
addressForm.province = ''
|
||||
addressForm.city = ''
|
||||
addressForm.district = ''
|
||||
addressForm.detailAddress = ''
|
||||
addressForm.isDefault = false
|
||||
addressVisible.value = true
|
||||
}
|
||||
|
||||
// 编辑地址
|
||||
const handleEditAddress = (addr: any) => {
|
||||
Object.assign(addressForm, addr)
|
||||
addressVisible.value = true
|
||||
}
|
||||
|
||||
// 删除地址
|
||||
const handleDeleteAddress = async (addr: any) => {
|
||||
try {
|
||||
await ElMessageBox.confirm('确定要删除该地址吗?', '删除地址', {
|
||||
confirmButtonText: '确认',
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning'
|
||||
})
|
||||
ElMessage.success('删除成功')
|
||||
clientAddresses.value = clientAddresses.value.filter(a => a.id !== addr.id)
|
||||
} catch (error) {
|
||||
// 取消操作
|
||||
}
|
||||
}
|
||||
|
||||
// 确认地址
|
||||
const confirmAddress = async () => {
|
||||
if (!addressFormRef.value) return
|
||||
try {
|
||||
await addressFormRef.value.validate()
|
||||
submitLoading.value = true
|
||||
if (addressForm.id) {
|
||||
const index = clientAddresses.value.findIndex(a => a.id === addressForm.id)
|
||||
if (index > -1) {
|
||||
clientAddresses.value[index] = { ...addressForm }
|
||||
}
|
||||
ElMessage.success('更新成功')
|
||||
} else {
|
||||
const newAddr = { ...addressForm, id: `addr_${Date.now()}` }
|
||||
clientAddresses.value.push(newAddr)
|
||||
ElMessage.success('添加成功')
|
||||
}
|
||||
addressVisible.value = false
|
||||
} catch (error) {
|
||||
console.error('保存失败:', error)
|
||||
} finally {
|
||||
submitLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
watch(
|
||||
() => editVisible.value,
|
||||
(visible) => {
|
||||
if (visible) void loadRegions()
|
||||
}
|
||||
)
|
||||
|
||||
onMounted(() => {
|
||||
loadRegions()
|
||||
loadData()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.page-container {
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.back-bar {
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
|
||||
.card {
|
||||
background: #fff;
|
||||
border-radius: 12px;
|
||||
padding: 20px;
|
||||
margin-bottom: 16px;
|
||||
box-shadow: 0 2px 12px rgba(0, 0, 0, 0.05);
|
||||
}
|
||||
|
||||
.card-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 20px;
|
||||
padding-bottom: 16px;
|
||||
border-bottom: 1px solid #ebeef5;
|
||||
|
||||
.card-title {
|
||||
font-size: 16px;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.header-actions {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
}
|
||||
}
|
||||
|
||||
.profile-section {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 20px;
|
||||
margin-bottom: 24px;
|
||||
padding: 20px;
|
||||
background: #f5f7fa;
|
||||
border-radius: 12px;
|
||||
}
|
||||
|
||||
.detail-user-avatar {
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.profile-info {
|
||||
flex: 1;
|
||||
|
||||
.profile-name {
|
||||
font-size: 20px;
|
||||
font-weight: 600;
|
||||
color: #303133;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.profile-tags {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
}
|
||||
}
|
||||
|
||||
.info-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(4, 1fr);
|
||||
gap: 16px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.info-item {
|
||||
.info-label {
|
||||
font-size: 13px;
|
||||
color: #909399;
|
||||
margin-bottom: 4px;
|
||||
}
|
||||
|
||||
.info-value {
|
||||
font-size: 14px;
|
||||
color: #303133;
|
||||
font-weight: 500;
|
||||
}
|
||||
}
|
||||
|
||||
.address-section {
|
||||
margin-top: 20px;
|
||||
padding: 16px;
|
||||
background: #f5f7fa;
|
||||
border-radius: 8px;
|
||||
|
||||
.address-title {
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
color: #606266;
|
||||
margin-bottom: 12px;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
}
|
||||
}
|
||||
|
||||
.address-row {
|
||||
display: flex;
|
||||
gap: 16px;
|
||||
padding: 8px 0;
|
||||
font-size: 14px;
|
||||
|
||||
.address-label {
|
||||
color: #909399;
|
||||
width: 70px;
|
||||
}
|
||||
|
||||
.address-value {
|
||||
color: #303133;
|
||||
flex: 1;
|
||||
}
|
||||
}
|
||||
|
||||
.address-list {
|
||||
.address-item {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 12px;
|
||||
background: #fff;
|
||||
border-radius: 8px;
|
||||
margin-bottom: 8px;
|
||||
|
||||
&:last-child {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
.address-info {
|
||||
flex: 1;
|
||||
|
||||
.address-contact {
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
margin-bottom: 4px;
|
||||
|
||||
.ml-2 {
|
||||
margin-left: 8px;
|
||||
}
|
||||
}
|
||||
|
||||
.address-detail {
|
||||
font-size: 13px;
|
||||
color: #909399;
|
||||
}
|
||||
}
|
||||
|
||||
.address-actions {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.stats-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(4, 1fr);
|
||||
gap: 16px;
|
||||
margin-top: 20px;
|
||||
}
|
||||
|
||||
.stat-card {
|
||||
background: #f5f7fa;
|
||||
border-radius: 12px;
|
||||
padding: 20px;
|
||||
text-align: center;
|
||||
|
||||
.stat-num {
|
||||
font-size: 28px;
|
||||
font-weight: 700;
|
||||
color: #059669;
|
||||
|
||||
&.amount {
|
||||
font-size: 22px;
|
||||
}
|
||||
}
|
||||
|
||||
.stat-label {
|
||||
font-size: 13px;
|
||||
color: #909399;
|
||||
margin-top: 8px;
|
||||
}
|
||||
}
|
||||
|
||||
.ml-2 {
|
||||
margin-left: 8px;
|
||||
}
|
||||
</style>
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,176 @@
|
||||
<template>
|
||||
<ElDialog
|
||||
v-model="dialogVisible"
|
||||
:title="dialogType === 'add' ? '添加用户' : '编辑用户'"
|
||||
width="720px"
|
||||
class="user-dialog"
|
||||
align-center
|
||||
>
|
||||
<ElForm ref="formRef" :model="formData" :rules="rules" label-position="top" class="user-form-grid">
|
||||
<ElFormItem label="用户名" prop="username">
|
||||
<ElInput v-model="formData.username" placeholder="请输入用户名" />
|
||||
</ElFormItem>
|
||||
<ElFormItem label="手机号" prop="phone">
|
||||
<ElInput v-model="formData.phone" placeholder="请输入手机号" />
|
||||
</ElFormItem>
|
||||
<ElFormItem label="性别" prop="gender">
|
||||
<ElSelect v-model="formData.gender">
|
||||
<ElOption label="男" value="男" />
|
||||
<ElOption label="女" value="女" />
|
||||
</ElSelect>
|
||||
</ElFormItem>
|
||||
<ElFormItem label="角色" prop="role">
|
||||
<ElSelect v-model="formData.role" multiple>
|
||||
<ElOption
|
||||
v-for="role in roleList"
|
||||
:key="role.roleCode"
|
||||
:value="role.roleCode"
|
||||
:label="role.roleName"
|
||||
/>
|
||||
</ElSelect>
|
||||
</ElFormItem>
|
||||
</ElForm>
|
||||
<template #footer>
|
||||
<div class="dialog-footer">
|
||||
<ElButton class="btn-ghost" @click="dialogVisible = false">取消</ElButton>
|
||||
<ElButton class="btn-main" type="primary" @click="handleSubmit">提交</ElButton>
|
||||
</div>
|
||||
</template>
|
||||
</ElDialog>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { fetchGetRoleList } from '@/api/admin'
|
||||
import type { FormInstance, FormRules } from 'element-plus'
|
||||
|
||||
interface Props {
|
||||
visible: boolean
|
||||
type: string
|
||||
userData?: Partial<Api.SystemManage.UserListItem>
|
||||
}
|
||||
|
||||
interface Emits {
|
||||
(e: 'update:visible', value: boolean): void
|
||||
(e: 'submit'): void
|
||||
}
|
||||
|
||||
const props = defineProps<Props>()
|
||||
const emit = defineEmits<Emits>()
|
||||
|
||||
// 角色列表数据
|
||||
const roleList = ref<Array<{ roleName: string; roleCode: string }>>([])
|
||||
|
||||
// 加载角色列表
|
||||
const loadRoleList = async () => {
|
||||
try {
|
||||
const roles = await fetchGetRoleList()
|
||||
roleList.value = roles.map((r: any) => ({
|
||||
roleName: r.label,
|
||||
roleCode: r.value
|
||||
}))
|
||||
} catch (error) {
|
||||
console.error('加载角色列表失败:', error)
|
||||
}
|
||||
}
|
||||
|
||||
// 对话框显示控制
|
||||
const dialogVisible = computed({
|
||||
get: () => props.visible,
|
||||
set: (value) => emit('update:visible', value)
|
||||
})
|
||||
|
||||
const dialogType = computed(() => props.type)
|
||||
|
||||
// 表单实例
|
||||
const formRef = ref<FormInstance>()
|
||||
|
||||
// 表单数据
|
||||
const formData = reactive({
|
||||
username: '',
|
||||
phone: '',
|
||||
gender: '男',
|
||||
role: [] as string[]
|
||||
})
|
||||
|
||||
// 表单验证规则
|
||||
const rules: FormRules = {
|
||||
username: [
|
||||
{ required: true, message: '请输入用户名', trigger: 'blur' },
|
||||
{ min: 2, max: 20, message: '长度在 2 到 20 个字符', trigger: 'blur' }
|
||||
],
|
||||
phone: [
|
||||
{ required: true, message: '请输入手机号', trigger: 'blur' },
|
||||
{ pattern: /^1[3-9]\d{9}$/, message: '请输入正确的手机号格式', trigger: 'blur' }
|
||||
],
|
||||
gender: [{ required: true, message: '请选择性别', trigger: 'blur' }],
|
||||
role: [{ required: true, message: '请选择角色', trigger: 'blur' }]
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化表单数据
|
||||
* 根据对话框类型(新增/编辑)填充表单
|
||||
*/
|
||||
const initFormData = () => {
|
||||
const isEdit = props.type === 'edit' && props.userData
|
||||
const row = props.userData
|
||||
|
||||
Object.assign(formData, {
|
||||
username: isEdit && row ? row.userName || '' : '',
|
||||
phone: isEdit && row ? row.userPhone || '' : '',
|
||||
gender: isEdit && row ? row.userGender || '男' : '男',
|
||||
role: isEdit && row ? (Array.isArray(row.userRoles) ? row.userRoles : []) : []
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 监听对话框状态变化
|
||||
* 当对话框打开时初始化表单数据并清除验证状态
|
||||
*/
|
||||
watch(
|
||||
() => [props.visible, props.type, props.userData],
|
||||
([visible]) => {
|
||||
if (visible) {
|
||||
void loadRoleList()
|
||||
initFormData()
|
||||
nextTick(() => {
|
||||
formRef.value?.clearValidate()
|
||||
})
|
||||
}
|
||||
},
|
||||
{ immediate: true }
|
||||
)
|
||||
|
||||
/**
|
||||
* 提交表单
|
||||
* 验证通过后触发提交事件
|
||||
*/
|
||||
const handleSubmit = async () => {
|
||||
if (!formRef.value) return
|
||||
|
||||
await formRef.value.validate((valid) => {
|
||||
if (valid) {
|
||||
ElMessage.success(dialogType.value === 'add' ? '添加成功' : '更新成功')
|
||||
dialogVisible.value = false
|
||||
emit('submit')
|
||||
}
|
||||
})
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
.user-form-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
gap: 12px 20px;
|
||||
|
||||
:deep(.el-form-item) {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 640px) {
|
||||
.user-form-grid {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,112 @@
|
||||
<template>
|
||||
<ArtSearchBar
|
||||
ref="searchBarRef"
|
||||
v-model="formData"
|
||||
:items="formItems"
|
||||
:rules="rules"
|
||||
@reset="handleReset"
|
||||
@search="handleSearch"
|
||||
>
|
||||
</ArtSearchBar>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
interface Props {
|
||||
modelValue: Api.SystemManage.UserSearchParams
|
||||
}
|
||||
interface Emits {
|
||||
(e: 'update:modelValue', value: Api.SystemManage.UserSearchParams): void
|
||||
(e: 'search', params: Api.SystemManage.UserSearchParams): void
|
||||
(e: 'reset'): void
|
||||
}
|
||||
const props = defineProps<Props>()
|
||||
const emit = defineEmits<Emits>()
|
||||
|
||||
// 表单数据双向绑定
|
||||
const searchBarRef = ref()
|
||||
const formData = computed({
|
||||
get: () => props.modelValue,
|
||||
set: (val) => emit('update:modelValue', val)
|
||||
})
|
||||
|
||||
// 校验规则
|
||||
const rules = {
|
||||
// userName: [{ required: true, message: '请输入用户名', trigger: 'blur' }]
|
||||
}
|
||||
|
||||
// 动态 options
|
||||
const statusOptions = ref<{ label: string; value: string; disabled?: boolean }[]>([])
|
||||
|
||||
// 模拟接口返回状态数据
|
||||
function fetchStatusOptions(): Promise<typeof statusOptions.value> {
|
||||
return new Promise((resolve) => {
|
||||
setTimeout(() => {
|
||||
resolve([
|
||||
{ label: '在线', value: '1' },
|
||||
{ label: '离线', value: '2' },
|
||||
{ label: '异常', value: '3' },
|
||||
{ label: '注销', value: '4' }
|
||||
])
|
||||
}, 1000)
|
||||
})
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
statusOptions.value = await fetchStatusOptions()
|
||||
})
|
||||
|
||||
// 表单配置
|
||||
const formItems = computed(() => [
|
||||
{
|
||||
label: '用户名',
|
||||
key: 'userName',
|
||||
type: 'input',
|
||||
placeholder: '请输入用户名',
|
||||
clearable: true
|
||||
},
|
||||
{
|
||||
label: '手机号',
|
||||
key: 'userPhone',
|
||||
type: 'input',
|
||||
props: { placeholder: '请输入手机号', maxlength: '11' }
|
||||
},
|
||||
{
|
||||
label: '邮箱',
|
||||
key: 'userEmail',
|
||||
type: 'input',
|
||||
props: { placeholder: '请输入邮箱' }
|
||||
},
|
||||
{
|
||||
label: '状态',
|
||||
key: 'status',
|
||||
type: 'select',
|
||||
props: {
|
||||
placeholder: '请选择状态',
|
||||
options: statusOptions.value
|
||||
}
|
||||
},
|
||||
{
|
||||
label: '性别',
|
||||
key: 'userGender',
|
||||
type: 'radiogroup',
|
||||
props: {
|
||||
options: [
|
||||
{ label: '男', value: '1' },
|
||||
{ label: '女', value: '2' }
|
||||
]
|
||||
}
|
||||
}
|
||||
])
|
||||
|
||||
// 事件
|
||||
function handleReset() {
|
||||
console.log('重置表单')
|
||||
emit('reset')
|
||||
}
|
||||
|
||||
async function handleSearch(params: Api.SystemManage.UserSearchParams) {
|
||||
await searchBarRef.value.validate()
|
||||
emit('search', params)
|
||||
console.log('表单数据', params)
|
||||
}
|
||||
</script>
|
||||
Reference in new issue
Block a user