新增统一弹窗外壳与样式: - 新增 TaskPanelDialog.vue(自绘标题+副标题 / 可滚动内容区 / 底部提示+操作区), 默认点遮罩不关闭,内容区 max-height 内部滚动 - 新增 styles/task-panel.css 并在 main.ts 引入:section 分组、栅格字段行 (88px 标签 + 控件)、提示条、表格区、底部按钮区(small / gap 6) - 新增 ReasonPromptDialog.vue:替换 ElMessageBox.prompt,用于作废 / 取消 / 手工标记推送失败等需填原因的操作,支持必填校验、多行、按钮类型与提示 页面改造(el-dialog / el-drawer → TaskPanelDialog + task-panel 栅格): - 订单、发货单、状态面板、订单同步、入库单(列表/新建)、出库单(列表/新建)、 库存单据、导出任务、导出按钮、商品查询、单据选择、商品(新增/编辑/批量导入, 抽屉改弹窗)、店铺、店铺商品、组合商品、自定义快递、外接 API、 外接打印平台/快递接口、组织(集团设置/下属公司)、权限角色组、主体、主体用户、 商品属性、用户资料 交互与样式统一: - ElMessageBox.confirm 统一挂 customClass="app-confirm-box"(App.vue 中定义按钮 高度/内边距/间距),状态面板封装 ElMessageBox 别名统一注入 - 侧边栏 BasicLayout:加 contain: layout、菜单内部 overflow 滚动、 关闭子菜单折叠过渡,避免展开时逐帧重排扩散到主内容区
470 lines
15 KiB
Vue
470 lines
15 KiB
Vue
<script setup lang="ts">
|
||
import { onMounted, onUnmounted, reactive, ref } from 'vue'
|
||
import { ElMessage, ElMessageBox, type FormInstance, type FormRules } from 'element-plus'
|
||
import { Loading } from '@element-plus/icons-vue'
|
||
import { useAuthStore } from '@/store/auth'
|
||
import { updateProfile, changePassword } from '@/api/user'
|
||
import { formatDateTime } from '@/utils/datetime'
|
||
import QrCode from '@/components/QrCode.vue'
|
||
import TaskPanelDialog from '@/components/TaskPanelDialog.vue'
|
||
import {
|
||
createWechatBindCode,
|
||
getWechatBind,
|
||
getWechatBindStatus,
|
||
getWechatEnabled,
|
||
unbindWechat,
|
||
type WechatBindInfo,
|
||
type WechatQrcode,
|
||
} from '@/api/wechat'
|
||
|
||
const auth = useAuthStore()
|
||
|
||
const formRef = ref<FormInstance>()
|
||
const submitting = ref(false)
|
||
const form = reactive({ email: '', phone: '' })
|
||
const rules: FormRules = {
|
||
email: [{ type: 'email', message: '邮箱格式不正确', trigger: 'blur' }],
|
||
phone: [{ pattern: /^1[3-9]\d{9}$|^[\d-+()\s]{6,20}$/, message: '手机号格式不正确', trigger: 'blur' }],
|
||
}
|
||
|
||
/** 用当前登录用户信息回填表单 */
|
||
function fillForm() {
|
||
const u = auth.user
|
||
if (!u) return
|
||
form.email = u.email || ''
|
||
form.phone = u.phone || ''
|
||
}
|
||
|
||
onMounted(async () => {
|
||
if (!auth.user) await auth.fetchProfile()
|
||
fillForm()
|
||
await loadWechat()
|
||
})
|
||
|
||
async function submitProfile() {
|
||
if (!formRef.value) return
|
||
await formRef.value.validate(async (valid) => {
|
||
if (!valid) return
|
||
submitting.value = true
|
||
try {
|
||
await updateProfile({ ...form })
|
||
ElMessage.success('资料已更新')
|
||
// 同步刷新账号信息,顶栏昵称等即时生效
|
||
await auth.fetchProfile()
|
||
fillForm()
|
||
} catch {
|
||
// 错误已由响应拦截器统一提示
|
||
} finally {
|
||
submitting.value = false
|
||
}
|
||
})
|
||
}
|
||
|
||
// 修改密码
|
||
const pwdVisible = ref(false)
|
||
const pwdSubmitting = ref(false)
|
||
const pwdFormRef = ref<FormInstance>()
|
||
const pwdForm = reactive({ old_password: '', password: '', confirm: '' })
|
||
const pwdRules: FormRules = {
|
||
old_password: [{ required: true, message: '请输入原密码', trigger: 'blur' }],
|
||
password: [
|
||
{ required: true, message: '请输入新密码', trigger: 'blur' },
|
||
{ min: 6, message: '新密码长度不少于 6 位', trigger: 'blur' },
|
||
],
|
||
confirm: [
|
||
{ required: true, message: '请再次输入新密码', trigger: 'blur' },
|
||
{
|
||
validator: (_rule: unknown, value: string, callback: (e?: string | Error) => void) => {
|
||
if (value !== pwdForm.password) callback(new Error('两次输入的密码不一致'))
|
||
else callback()
|
||
},
|
||
trigger: 'blur',
|
||
},
|
||
],
|
||
}
|
||
|
||
function openPwd() {
|
||
pwdForm.old_password = ''
|
||
pwdForm.password = ''
|
||
pwdForm.confirm = ''
|
||
pwdVisible.value = true
|
||
}
|
||
|
||
async function submitPwd() {
|
||
if (!pwdFormRef.value) return
|
||
await pwdFormRef.value.validate(async (valid) => {
|
||
if (!valid) return
|
||
pwdSubmitting.value = true
|
||
try {
|
||
await changePassword({ old_password: pwdForm.old_password, password: pwdForm.password })
|
||
ElMessage.success('密码已修改,请牢记新密码')
|
||
pwdVisible.value = false
|
||
} catch {
|
||
// 拦截器已提示
|
||
} finally {
|
||
pwdSubmitting.value = false
|
||
}
|
||
})
|
||
}
|
||
|
||
/* -------------------- 微信绑定 -------------------- */
|
||
/** 微信扫码轮询间隔(毫秒) */
|
||
const WECHAT_POLL_INTERVAL = 2000
|
||
|
||
const wechatEnabled = ref(false)
|
||
const wechatBind = ref<WechatBindInfo>({
|
||
bound: false,
|
||
openid: '',
|
||
unionid: '',
|
||
bind_scene: '',
|
||
bound_at: null,
|
||
last_login_at: null,
|
||
})
|
||
const wechatVisible = ref(false)
|
||
const wechatQr = ref<WechatQrcode | null>(null)
|
||
const wechatLoading = ref(false)
|
||
const wechatHint = ref('')
|
||
const wechatPollTimer: { value?: ReturnType<typeof setInterval> } = { value: undefined }
|
||
|
||
/** 读取网关是否可用 + 当前账号的绑定状态 */
|
||
async function loadWechat() {
|
||
try {
|
||
const [enabledRes, bindRes] = await Promise.all([getWechatEnabled(), getWechatBind()])
|
||
wechatEnabled.value = enabledRes.enabled
|
||
wechatBind.value = bindRes
|
||
} catch {
|
||
// 错误已由响应拦截器统一提示
|
||
}
|
||
}
|
||
|
||
function stopWechatPolling() {
|
||
if (wechatPollTimer.value) clearInterval(wechatPollTimer.value)
|
||
wechatPollTimer.value = undefined
|
||
}
|
||
|
||
/** 轮询绑定结果:成功即刷新绑定信息并关闭弹窗,冲突 / 失败则提示原因 */
|
||
function startWechatPolling(state: string) {
|
||
wechatPollTimer.value = setInterval(async () => {
|
||
try {
|
||
const res = await getWechatBindStatus(state)
|
||
if (res.status === 'pending') return
|
||
stopWechatPolling()
|
||
wechatQr.value = null
|
||
if (res.status === 'success') {
|
||
ElMessage.success('微信绑定成功')
|
||
wechatVisible.value = false
|
||
await loadWechat()
|
||
return
|
||
}
|
||
wechatHint.value = res.message || '绑定失败,请刷新二维码重试'
|
||
} catch {
|
||
// 二维码过期等错误已由拦截器提示
|
||
stopWechatPolling()
|
||
wechatQr.value = null
|
||
wechatHint.value = '二维码已失效,请刷新'
|
||
}
|
||
}, WECHAT_POLL_INTERVAL)
|
||
}
|
||
|
||
/** 申请绑定二维码(scene=bind,扫码确认后绑定到当前登录账号) */
|
||
async function refreshWechatQrcode() {
|
||
stopWechatPolling()
|
||
wechatQr.value = null
|
||
wechatHint.value = ''
|
||
wechatLoading.value = true
|
||
try {
|
||
const res = await createWechatBindCode()
|
||
wechatQr.value = res
|
||
startWechatPolling(res.state)
|
||
} catch (error) {
|
||
const err = error as { response?: { data?: { message?: string } }; message?: string }
|
||
wechatHint.value = err?.response?.data?.message || err?.message || '获取微信二维码失败'
|
||
} finally {
|
||
wechatLoading.value = false
|
||
}
|
||
}
|
||
|
||
function openWechatBind() {
|
||
wechatVisible.value = true
|
||
void refreshWechatQrcode()
|
||
}
|
||
|
||
async function handleUnbind() {
|
||
try {
|
||
await ElMessageBox.confirm('解绑后将无法使用微信扫码登录,确定解绑?', '解绑微信', {
|
||
type: 'warning',
|
||
confirmButtonText: '确定解绑',
|
||
cancelButtonText: '取消',
|
||
customClass: 'app-confirm-box',
|
||
})
|
||
} catch {
|
||
return
|
||
}
|
||
try {
|
||
await unbindWechat()
|
||
ElMessage.success('已解绑微信')
|
||
await loadWechat()
|
||
} catch {
|
||
// 错误已由响应拦截器统一提示
|
||
}
|
||
}
|
||
|
||
onUnmounted(stopWechatPolling)
|
||
</script>
|
||
|
||
<template>
|
||
<el-card class="profile-card">
|
||
<template #header>
|
||
<div class="page-header">
|
||
<span>我的</span>
|
||
<div class="page-actions">
|
||
<el-button size="small" @click="openPwd">修改密码</el-button>
|
||
<el-button size="small" type="primary" :loading="submitting" @click="submitProfile">保存资料</el-button>
|
||
</div>
|
||
</div>
|
||
</template>
|
||
|
||
<div class="profile-body">
|
||
<el-form ref="formRef" :model="form" :rules="rules" class="task-panel__form" scroll-to-error @submit.prevent>
|
||
<div class="task-panel__section">账号信息</div>
|
||
<div class="task-panel__grid">
|
||
<div class="task-panel__field">
|
||
<span class="task-panel__field-label">登录账号</span>
|
||
<strong class="task-panel__field-value">{{ auth.user?.username || '-' }}</strong>
|
||
</div>
|
||
<div class="task-panel__field">
|
||
<span class="task-panel__field-label">用户ID</span>
|
||
<strong class="task-panel__field-value">{{ auth.user?.id ?? '-' }}</strong>
|
||
</div>
|
||
<div class="task-panel__field">
|
||
<span class="task-panel__field-label">状态</span>
|
||
<span class="task-panel__field-value">
|
||
<el-tag :type="auth.user?.status === 1 ? 'success' : 'info'" size="small">
|
||
{{ auth.user?.status === 1 ? '启用' : '禁用' }}
|
||
</el-tag>
|
||
</span>
|
||
</div>
|
||
<div class="task-panel__field">
|
||
<span class="task-panel__field-label">最后登录</span>
|
||
<strong class="task-panel__field-value">
|
||
{{ auth.user?.last_login_at ? formatDateTime(auth.user.last_login_at) : '暂无' }}
|
||
</strong>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="task-panel__section">联系方式</div>
|
||
<div class="task-panel__grid">
|
||
<div class="task-panel__field task-panel__field--input">
|
||
<span class="task-panel__field-label">邮箱</span>
|
||
<div class="task-panel__field-form">
|
||
<el-form-item prop="email">
|
||
<el-input v-model="form.email" placeholder="选填" />
|
||
</el-form-item>
|
||
</div>
|
||
</div>
|
||
<div class="task-panel__field task-panel__field--input">
|
||
<span class="task-panel__field-label">手机号</span>
|
||
<div class="task-panel__field-form">
|
||
<el-form-item prop="phone">
|
||
<el-input v-model="form.phone" placeholder="选填" />
|
||
</el-form-item>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<p class="task-panel__form-tip">邮箱与手机号用于接收通知与账号找回,填写后点击右上角「保存资料」生效。</p>
|
||
</el-form>
|
||
|
||
<div class="task-panel__form">
|
||
<div class="task-panel__section">微信绑定</div>
|
||
<div class="task-panel__field wechat-bind">
|
||
<span class="task-panel__field-label">微信</span>
|
||
<div class="wechat-info">
|
||
<el-tag v-if="wechatBind.bound" type="success" size="small">已绑定</el-tag>
|
||
<el-tag v-else type="info" size="small">未绑定</el-tag>
|
||
<span v-if="wechatBind.bound" class="wechat-openid">{{ wechatBind.openid }}</span>
|
||
<span class="wechat-sub">
|
||
{{
|
||
wechatBind.bound
|
||
? `绑定时间 ${wechatBind.bound_at ? formatDateTime(wechatBind.bound_at) : '-'}`
|
||
: wechatEnabled
|
||
? '绑定后可直接在登录页微信扫码登录'
|
||
: '管理员尚未配置微信登录网关,暂不可用'
|
||
}}
|
||
</span>
|
||
</div>
|
||
<el-button
|
||
v-if="!wechatBind.bound"
|
||
size="small"
|
||
type="primary"
|
||
:disabled="!wechatEnabled"
|
||
@click="openWechatBind"
|
||
>
|
||
绑定微信
|
||
</el-button>
|
||
<el-button v-else size="small" type="danger" plain @click="handleUnbind">解绑微信</el-button>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<TaskPanelDialog
|
||
v-model="wechatVisible"
|
||
title="绑定微信"
|
||
subtitle="使用微信扫码并在手机上确认后绑定到当前账号"
|
||
width="min(420px, 92vw)"
|
||
body-max-height="60vh"
|
||
@closed="stopWechatPolling"
|
||
>
|
||
<div class="wechat-dialog">
|
||
<div class="wechat-qr">
|
||
<QrCode v-if="wechatQr" :value="wechatQr.page_url" :size="180" />
|
||
<div v-else class="wechat-qr-empty">
|
||
<el-icon v-if="wechatLoading" class="is-loading"><Loading /></el-icon>
|
||
<span v-else>{{ wechatHint || '正在准备二维码…' }}</span>
|
||
</div>
|
||
</div>
|
||
<p class="wechat-hint">请使用微信扫描二维码,并在手机上确认绑定</p>
|
||
</div>
|
||
<template #hint>绑定成功后窗口会自动关闭</template>
|
||
<template #actions>
|
||
<el-button size="small" :loading="wechatLoading" @click="refreshWechatQrcode">刷新二维码</el-button>
|
||
<el-button size="small" @click="wechatVisible = false">关闭</el-button>
|
||
</template>
|
||
</TaskPanelDialog>
|
||
|
||
<TaskPanelDialog
|
||
v-model="pwdVisible"
|
||
title="修改密码"
|
||
subtitle="需验证原密码;修改成功后原密码立即失效"
|
||
width="min(480px, 92vw)"
|
||
body-max-height="56vh"
|
||
>
|
||
<el-form
|
||
ref="pwdFormRef"
|
||
:model="pwdForm"
|
||
:rules="pwdRules"
|
||
class="task-panel__form"
|
||
scroll-to-error
|
||
@submit.prevent
|
||
>
|
||
<div class="task-panel__grid task-panel__grid--single">
|
||
<div class="task-panel__field task-panel__field--input">
|
||
<span class="task-panel__field-label is-required">原密码</span>
|
||
<div class="task-panel__field-form">
|
||
<el-form-item prop="old_password">
|
||
<el-input v-model="pwdForm.old_password" type="password" show-password placeholder="请输入当前密码" />
|
||
</el-form-item>
|
||
</div>
|
||
</div>
|
||
<div class="task-panel__field task-panel__field--input">
|
||
<span class="task-panel__field-label is-required">新密码</span>
|
||
<div class="task-panel__field-form">
|
||
<el-form-item prop="password">
|
||
<el-input v-model="pwdForm.password" type="password" show-password placeholder="不少于 6 位" />
|
||
</el-form-item>
|
||
</div>
|
||
</div>
|
||
<div class="task-panel__field task-panel__field--input">
|
||
<span class="task-panel__field-label is-required">确认密码</span>
|
||
<div class="task-panel__field-form">
|
||
<el-form-item prop="confirm">
|
||
<el-input v-model="pwdForm.confirm" type="password" show-password placeholder="再次输入新密码" />
|
||
</el-form-item>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<p class="task-panel__form-tip">新密码长度不少于 6 位;修改成功后下次登录请使用新密码。</p>
|
||
</el-form>
|
||
<template #hint>修改成功后当前登录状态仍然有效</template>
|
||
<template #actions>
|
||
<el-button size="small" @click="pwdVisible = false">取消</el-button>
|
||
<el-button size="small" type="primary" :loading="pwdSubmitting" @click="submitPwd">确定</el-button>
|
||
</template>
|
||
</TaskPanelDialog>
|
||
</el-card>
|
||
</template>
|
||
|
||
<style scoped>
|
||
.page-header {
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: space-between;
|
||
font-weight: 600;
|
||
}
|
||
.page-actions {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 6px;
|
||
}
|
||
/* 页面型表单:分组之间留出比弹窗更大的间距 */
|
||
.profile-body {
|
||
display: flex;
|
||
flex-direction: column;
|
||
gap: 4px;
|
||
max-width: 880px;
|
||
}
|
||
.profile-body .task-panel__section {
|
||
margin-top: 12px;
|
||
}
|
||
.profile-body .task-panel__section:first-child {
|
||
margin-top: 0;
|
||
}
|
||
|
||
.wechat-bind {
|
||
gap: 12px;
|
||
}
|
||
.wechat-info {
|
||
flex: 1;
|
||
min-width: 0;
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 8px;
|
||
flex-wrap: wrap;
|
||
}
|
||
.wechat-openid {
|
||
font-family: var(--el-font-family);
|
||
font-size: 13px;
|
||
color: var(--el-text-color-regular);
|
||
}
|
||
.wechat-sub {
|
||
font-size: 12px;
|
||
color: var(--el-text-color-secondary);
|
||
}
|
||
|
||
.wechat-dialog {
|
||
display: flex;
|
||
flex-direction: column;
|
||
align-items: center;
|
||
gap: 8px;
|
||
}
|
||
|
||
.wechat-qr {
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
width: 196px;
|
||
height: 196px;
|
||
border: 1px solid var(--el-border-color-lighter);
|
||
border-radius: 6px;
|
||
background: #fff;
|
||
}
|
||
|
||
.wechat-qr-empty {
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
width: 100%;
|
||
height: 100%;
|
||
padding: 0 12px;
|
||
text-align: center;
|
||
font-size: 13px;
|
||
line-height: 1.6;
|
||
color: var(--el-text-color-secondary);
|
||
}
|
||
|
||
.wechat-hint {
|
||
margin: 0;
|
||
font-size: 13px;
|
||
color: var(--el-text-color-regular);
|
||
}
|
||
</style>
|