杂务:更新 YumiNail 工作区
This commit is contained in:
@@ -31,7 +31,7 @@
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<div class="admin-filter-bar">
|
||||
<AdminFilterPanel :active-count="activeMobileFilterCount">
|
||||
<a-select
|
||||
v-model:value="shopFilter"
|
||||
:allow-clear="currentUserType === 4"
|
||||
@@ -72,7 +72,7 @@
|
||||
<a-select-option value="false">无订单</a-select-option>
|
||||
</a-select>
|
||||
<a-button @click="resetFilters">重置筛选</a-button>
|
||||
</div>
|
||||
</AdminFilterPanel>
|
||||
|
||||
<a-table
|
||||
v-if="!isMobile"
|
||||
@@ -81,6 +81,7 @@
|
||||
:loading="loading"
|
||||
:pagination="pagination"
|
||||
row-key="id"
|
||||
:scroll="{ x: 'max-content' }"
|
||||
@change="handleTableChange"
|
||||
>
|
||||
<template #bodyCell="{ column, record }">
|
||||
@@ -242,10 +243,61 @@
|
||||
@input="handlePhoneInput"
|
||||
/>
|
||||
</a-form-item>
|
||||
<a-form-item v-if="!isEdit" label="密码" name="password">
|
||||
<a-input-password v-model:value="formState.password" placeholder="请输入密码" />
|
||||
<a-form-item label="生日" name="birthday">
|
||||
<a-date-picker
|
||||
v-model:value="formState.birthday"
|
||||
value-format="YYYY-MM-DD"
|
||||
format="YYYY-MM-DD"
|
||||
placeholder="请选择生日"
|
||||
class="user-date-picker"
|
||||
popup-class-name="yumi-date-picker-panel"
|
||||
/>
|
||||
</a-form-item>
|
||||
<a-form-item label="所属店铺" name="shopIds">
|
||||
<a-form-item
|
||||
label="微信号"
|
||||
name="wechatId"
|
||||
:required="[2, 3].includes(Number(formState.type))"
|
||||
>
|
||||
<a-input v-model:value="formState.wechatId" placeholder="店长和美甲师必填" />
|
||||
</a-form-item>
|
||||
<a-form-item label="微信二维码" name="wechatQrCode">
|
||||
<div class="wechat-qr-field">
|
||||
<a-upload
|
||||
accept="image/*"
|
||||
:show-upload-list="false"
|
||||
:before-upload="beforeUploadWechatQr"
|
||||
:custom-request="handleWechatQrUpload"
|
||||
>
|
||||
<img
|
||||
v-if="formState.wechatQrCode"
|
||||
:src="formState.wechatQrCode"
|
||||
alt="微信二维码"
|
||||
class="wechat-qr-preview"
|
||||
/>
|
||||
<a-button v-else :loading="wechatQrUploading">上传二维码</a-button>
|
||||
</a-upload>
|
||||
<a-button v-if="formState.wechatQrCode" type="link" danger size="small" @click="formState.wechatQrCode = ''">
|
||||
删除二维码
|
||||
</a-button>
|
||||
</div>
|
||||
</a-form-item>
|
||||
<a-form-item
|
||||
v-if="!isEdit"
|
||||
label="密码"
|
||||
name="password"
|
||||
extra="留空则使用参数管理中配置的后台新增用户默认密码"
|
||||
>
|
||||
<a-input-password
|
||||
v-model:value="formState.password"
|
||||
placeholder="不填则使用默认密码"
|
||||
autocomplete="new-password"
|
||||
/>
|
||||
</a-form-item>
|
||||
<a-form-item
|
||||
label="所属店铺"
|
||||
name="shopIds"
|
||||
:required="Number(formState.type) !== 4"
|
||||
>
|
||||
<a-select
|
||||
v-model:value="formState.shopIds"
|
||||
mode="multiple"
|
||||
@@ -284,6 +336,13 @@
|
||||
@cancel="viewModalVisible = false"
|
||||
>
|
||||
<a-descriptions bordered :column="1" size="small">
|
||||
<a-descriptions-item label="联系电话">{{ viewRecord?.contactPhone || '-' }}</a-descriptions-item>
|
||||
<a-descriptions-item label="生日">{{ viewRecord?.birthday || '-' }}</a-descriptions-item>
|
||||
<a-descriptions-item label="微信号">{{ viewRecord?.wechatId || '-' }}</a-descriptions-item>
|
||||
<a-descriptions-item label="微信二维码">
|
||||
<img v-if="viewRecord?.wechatQrCode" :src="viewRecord.wechatQrCode" alt="微信二维码" class="wechat-qr-preview" />
|
||||
<span v-else>-</span>
|
||||
</a-descriptions-item>
|
||||
<a-descriptions-item label="账号">{{ viewRecord?.account || '-' }}</a-descriptions-item>
|
||||
<a-descriptions-item label="昵称">{{ viewRecord?.nickname || '-' }}</a-descriptions-item>
|
||||
<a-descriptions-item label="手机号">{{ viewRecord?.phone || '-' }}</a-descriptions-item>
|
||||
@@ -449,7 +508,7 @@
|
||||
:pagination="false"
|
||||
size="small"
|
||||
row-key="id"
|
||||
:scroll="{ y: 320 }"
|
||||
:scroll="{ x: 'max-content', y: 320 }"
|
||||
>
|
||||
<template #bodyCell="{ column, record }">
|
||||
<template v-if="column.key === 'amount'">
|
||||
@@ -489,7 +548,7 @@
|
||||
* UsersView page script.
|
||||
* Call guide: the template binds the reactive state below, and the methods are triggered by button clicks, lifecycle hooks, or router events.
|
||||
*/
|
||||
import { computed, onMounted, reactive, ref } from 'vue'
|
||||
import { computed, h, onMounted, reactive, ref } from 'vue'
|
||||
import { message, Modal } from 'ant-design-vue'
|
||||
import type { FormInstance } from 'ant-design-vue'
|
||||
import { PlusOutlined } from '@ant-design/icons-vue'
|
||||
@@ -503,7 +562,9 @@ import { buildDraftStorageKey, clearDraftRecord, loadDraftRecord, saveDraftRecor
|
||||
*/
|
||||
import { userApi, type AvailabilityCheckResponse } from '@/api/user'
|
||||
import {
|
||||
adminFileApi,
|
||||
adminShopApi,
|
||||
adminSystemParameterConfigApi,
|
||||
adminUserApi,
|
||||
adminVipRechargePlanApi,
|
||||
type AdminUserBalanceChangeRequest,
|
||||
@@ -520,10 +581,12 @@ import { runWithGlobalLoading } from '@/utils/action-loading'
|
||||
import { useAdminViewport } from '@/composables/useAdminViewport'
|
||||
import AdminMobileCardList from '@/components/admin/AdminMobileCardList.vue'
|
||||
import AdminMobileFab from '@/components/admin/AdminMobileFab.vue'
|
||||
import AdminFilterPanel from '@/components/admin/AdminFilterPanel.vue'
|
||||
import AdminResponsiveModal from '@/components/admin/AdminResponsiveModal.vue'
|
||||
|
||||
const { hasPermission, hasAnyPermission, loadUserPermissions } = usePermission()
|
||||
const { isMobile } = useAdminViewport()
|
||||
const FALLBACK_ADMIN_DEFAULT_PASSWORD = 'YumiNail@123'
|
||||
|
||||
/** currentUserInfo is a local helper used by this page script. */
|
||||
const currentUserInfo = (() => {
|
||||
@@ -536,6 +599,51 @@ const currentUserInfo = (() => {
|
||||
}
|
||||
})()
|
||||
|
||||
const copyTextToClipboard = async (value: string) => {
|
||||
try {
|
||||
if (navigator.clipboard?.writeText) {
|
||||
await navigator.clipboard.writeText(value)
|
||||
} else {
|
||||
const textarea = document.createElement('textarea')
|
||||
textarea.value = value
|
||||
textarea.setAttribute('readonly', 'readonly')
|
||||
textarea.style.position = 'fixed'
|
||||
textarea.style.left = '-9999px'
|
||||
document.body.appendChild(textarea)
|
||||
textarea.select()
|
||||
document.execCommand('copy')
|
||||
document.body.removeChild(textarea)
|
||||
}
|
||||
message.success('默认密码已复制')
|
||||
} catch (error) {
|
||||
console.error('复制默认密码失败:', error)
|
||||
message.warning('复制失败,请手动复制')
|
||||
}
|
||||
}
|
||||
|
||||
const resolveAdminDefaultPasswordForNotice = async () => {
|
||||
try {
|
||||
const response = await adminSystemParameterConfigApi.getUserDefaultPassword()
|
||||
return response?.password?.trim() || FALLBACK_ADMIN_DEFAULT_PASSWORD
|
||||
} catch (error) {
|
||||
console.error('获取后台默认密码失败:', error)
|
||||
return FALLBACK_ADMIN_DEFAULT_PASSWORD
|
||||
}
|
||||
}
|
||||
|
||||
const showDefaultPasswordCreateNotice = async () => {
|
||||
const password = await resolveAdminDefaultPasswordForNotice()
|
||||
Modal.success({
|
||||
title: '用户创建成功',
|
||||
content: h('div', { class: 'default-password-notice' }, [
|
||||
h('p', '本次使用后台默认密码,请提醒用户首次登录后修改。'),
|
||||
h('div', { class: 'default-password-notice__value' }, password)
|
||||
]),
|
||||
okText: '一键复制密码',
|
||||
onOk: () => copyTextToClipboard(password)
|
||||
})
|
||||
}
|
||||
|
||||
/** normalizeUserType is a local helper used by this page script. */
|
||||
const normalizeUserType = (value: unknown) => {
|
||||
const type = Number(value)
|
||||
@@ -700,12 +808,33 @@ const canDeleteUser = computed(() =>
|
||||
const canUnbindUser = computed(() =>
|
||||
hasPermission('user:unbind')
|
||||
)
|
||||
/** activeMobileFilterCount summarizes applied filters while the mobile panel is collapsed. */
|
||||
const activeMobileFilterCount = computed(() => {
|
||||
const values = [
|
||||
currentUserType.value === 4 ? shopFilter.value : undefined,
|
||||
typeFilter.value,
|
||||
vipLevelFilter.value,
|
||||
statusFilter.value,
|
||||
createdRange.value,
|
||||
hasPhoneFilter.value,
|
||||
hasOrderFilter.value
|
||||
]
|
||||
return values.filter(isActiveFilterValue).length
|
||||
})
|
||||
/**
|
||||
* Purpose: PHONE_REGEX supports UsersView.vue by holding or executing the phone regex page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const PHONE_REGEX = /^1[3-9]\d{9}$/
|
||||
|
||||
/** isActiveFilterValue is a local helper used by the mobile filter summary. */
|
||||
const isActiveFilterValue = (value: unknown) => {
|
||||
if (Array.isArray(value)) {
|
||||
return value.some(item => item !== undefined && item !== null && item !== '')
|
||||
}
|
||||
return value !== undefined && value !== null && value !== ''
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: pagination supports UsersView.vue by holding or executing the pagination page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
@@ -727,11 +856,18 @@ const formState = reactive({
|
||||
account: '',
|
||||
nickname: '',
|
||||
phone: '',
|
||||
contactPhone: '',
|
||||
birthday: '',
|
||||
wechatId: '',
|
||||
wechatQrCode: '',
|
||||
password: '',
|
||||
type: 0,
|
||||
shopIds: [] as string[]
|
||||
})
|
||||
|
||||
/** wechatQrUploading tracks QR upload state in the user modal. */
|
||||
const wechatQrUploading = ref(false)
|
||||
|
||||
/** handleAccountInput is a local helper used by this page script. */
|
||||
const handleAccountInput = () => {
|
||||
const normalized = sanitizeAccountInput(formState.account)
|
||||
@@ -746,6 +882,39 @@ const handlePhoneInput = () => {
|
||||
if (normalized !== formState.phone) {
|
||||
formState.phone = normalized
|
||||
}
|
||||
formState.contactPhone = formState.phone
|
||||
}
|
||||
|
||||
/** beforeUploadWechatQr validates QR image files before upload. */
|
||||
const beforeUploadWechatQr = (file: File) => {
|
||||
const isImage = file.type.startsWith('image/')
|
||||
const isLt10M = file.size / 1024 / 1024 < 10
|
||||
if (!isImage) {
|
||||
message.error('只能上传图片文件')
|
||||
}
|
||||
if (!isLt10M) {
|
||||
message.error('图片大小不能超过 10MB')
|
||||
}
|
||||
return isImage && isLt10M
|
||||
}
|
||||
|
||||
/** handleWechatQrUpload uploads a QR image through admin object storage and stores the signed URL. */
|
||||
const handleWechatQrUpload = async (options: any) => {
|
||||
const { file, onSuccess, onError } = options
|
||||
wechatQrUploading.value = true
|
||||
try {
|
||||
const uploaded = await adminFileApi.uploadFile(file as File)
|
||||
const signedUrl = await adminFileApi.getSignedUrl(uploaded.id)
|
||||
formState.wechatQrCode = signedUrl as unknown as string
|
||||
onSuccess?.(uploaded)
|
||||
message.success('微信二维码上传成功')
|
||||
} catch (error) {
|
||||
console.error('微信二维码上传失败:', error)
|
||||
message.error((error as Error)?.message || '微信二维码上传失败')
|
||||
onError?.(error)
|
||||
} finally {
|
||||
wechatQrUploading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/** validatePhoneUniqueness is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
@@ -773,6 +942,25 @@ const validatePhoneUniqueness = async (value: string) => {
|
||||
}
|
||||
}
|
||||
|
||||
const validateOptionalPasswordStrength = (value?: string) => {
|
||||
const password = value?.trim()
|
||||
if (!password) {
|
||||
return
|
||||
}
|
||||
if (password.length < 8 || password.length > 32) {
|
||||
throw new Error('密码长度需为 8-32 位')
|
||||
}
|
||||
const categoryCount = [
|
||||
/\d/.test(password),
|
||||
/[a-z]/.test(password),
|
||||
/[A-Z]/.test(password),
|
||||
/[!@#$%^&*()_+\-=[\]{};':"\\|,.<>/?]/.test(password)
|
||||
].filter(Boolean).length
|
||||
if (categoryCount < 3) {
|
||||
throw new Error('密码需至少包含数字、小写字母、大写字母、特殊符号中的 3 类')
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: balanceForm supports UsersView.vue by holding or executing the balance form page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
@@ -893,7 +1081,22 @@ const formRules = {
|
||||
trigger: 'blur'
|
||||
}
|
||||
],
|
||||
password: [{ required: true, message: '请输入密码', trigger: 'blur' }],
|
||||
wechatId: [{
|
||||
validator: async (_rule: unknown, value: string) => {
|
||||
if ([2, 3].includes(Number(formState.type)) && !value?.trim()) {
|
||||
return Promise.reject('店长和美甲师必须填写微信号')
|
||||
}
|
||||
return Promise.resolve()
|
||||
},
|
||||
trigger: ['blur', 'change']
|
||||
}],
|
||||
password: [{
|
||||
validator: async (_rule: unknown, value: string) => {
|
||||
validateOptionalPasswordStrength(value)
|
||||
return Promise.resolve()
|
||||
},
|
||||
trigger: 'blur'
|
||||
}],
|
||||
shopIds: [{
|
||||
validator: async (_rule: unknown, value: string[]) => {
|
||||
if (Number(formState.type) === 4) {
|
||||
@@ -1170,6 +1373,10 @@ const resetFormState = () => {
|
||||
account: '',
|
||||
nickname: '',
|
||||
phone: '',
|
||||
contactPhone: '',
|
||||
birthday: '',
|
||||
wechatId: '',
|
||||
wechatQrCode: '',
|
||||
password: '',
|
||||
type: defaultUserType ?? 0,
|
||||
shopIds: currentUserType.value !== 4 && currentUserInfo?.shopId
|
||||
@@ -1186,6 +1393,10 @@ const buildDraftPayload = () => ({
|
||||
account: formState.account,
|
||||
nickname: formState.nickname,
|
||||
phone: formState.phone,
|
||||
contactPhone: formState.phone,
|
||||
birthday: formState.birthday,
|
||||
wechatId: formState.wechatId,
|
||||
wechatQrCode: formState.wechatQrCode,
|
||||
password: formState.password,
|
||||
type: formState.type,
|
||||
shopIds: [...formState.shopIds]
|
||||
@@ -1200,6 +1411,10 @@ const restoreDraft = () => {
|
||||
}
|
||||
|
||||
Object.assign(formState, draft.payload)
|
||||
if (!formState.phone && formState.contactPhone) {
|
||||
formState.phone = formState.contactPhone
|
||||
}
|
||||
formState.contactPhone = formState.phone
|
||||
draftSavedAt.value = draft.savedAt
|
||||
message.success('已恢复暂存内容')
|
||||
}
|
||||
@@ -1249,7 +1464,11 @@ const showEditModal = (record: any) => {
|
||||
Object.assign(formState, {
|
||||
account: record.account,
|
||||
nickname: record.nickname,
|
||||
phone: record.phone || '',
|
||||
phone: record.phone || record.contactPhone || '',
|
||||
contactPhone: record.phone || record.contactPhone || '',
|
||||
birthday: record.birthday || '',
|
||||
wechatId: record.wechatId || '',
|
||||
wechatQrCode: record.wechatQrCode || '',
|
||||
password: '',
|
||||
type: record.type,
|
||||
shopIds: resolveEditableShopIds(record)
|
||||
@@ -1323,14 +1542,24 @@ const handleAssetModalCancel = () => {
|
||||
/** handleModalOk is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
|
||||
const handleModalOk = async () => {
|
||||
try {
|
||||
if (wechatQrUploading.value) {
|
||||
message.warning('微信二维码上传完成前不可保存')
|
||||
return
|
||||
}
|
||||
await formRef.value?.validate()
|
||||
modalLoading.value = true
|
||||
await runWithGlobalLoading(async () => {
|
||||
const requestShopIds = Number(formState.type) === 4 ? [] : formState.shopIds
|
||||
const usedDefaultPassword = !isEdit.value && !formState.password.trim()
|
||||
const primaryPhone = formState.phone.trim()
|
||||
const requestData: Record<string, unknown> = {
|
||||
account: formState.account.trim(),
|
||||
nickname: formState.nickname.trim(),
|
||||
phone: formState.phone.trim(),
|
||||
phone: primaryPhone,
|
||||
contactPhone: primaryPhone,
|
||||
birthday: formState.birthday || undefined,
|
||||
wechatId: formState.wechatId.trim(),
|
||||
wechatQrCode: formState.wechatQrCode,
|
||||
type: formState.type,
|
||||
shopIds: requestShopIds,
|
||||
shopId: requestShopIds.length ? requestShopIds[0] : undefined,
|
||||
@@ -1347,7 +1576,11 @@ const handleModalOk = async () => {
|
||||
message.success('更新成功')
|
||||
} else {
|
||||
await adminUserApi.createUser(requestData)
|
||||
message.success('创建成功')
|
||||
if (usedDefaultPassword) {
|
||||
await showDefaultPasswordCreateNotice()
|
||||
} else {
|
||||
message.success('创建成功')
|
||||
}
|
||||
}
|
||||
|
||||
handleClearDraft(false)
|
||||
@@ -1393,7 +1626,7 @@ const handleStatusChange = async (record: any, checked: boolean) => {
|
||||
const handleResetPassword = (record: any) => {
|
||||
Modal.confirm({
|
||||
title: '确认重置密码',
|
||||
content: `确定要将用户 ${record.nickname} 的密码重置为 888888 吗?`,
|
||||
content: `确定要将用户 ${record.nickname} 的密码重置为后台默认密码吗?`,
|
||||
async onOk() {
|
||||
try {
|
||||
await runWithGlobalLoading(async () => {
|
||||
@@ -1621,13 +1854,6 @@ onMounted(async () => {
|
||||
gap: 16px;
|
||||
}
|
||||
|
||||
.admin-filter-bar {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 10px;
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
|
||||
.mobile-user-head {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
@@ -1635,6 +1861,24 @@ onMounted(async () => {
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.wechat-qr-field {
|
||||
display: grid;
|
||||
justify-items: start;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.user-date-picker {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.wechat-qr-preview {
|
||||
width: 88px;
|
||||
height: 88px;
|
||||
border: 1px solid var(--admin-mobile-border);
|
||||
border-radius: 8px;
|
||||
object-fit: cover;
|
||||
}
|
||||
|
||||
.asset-summary,
|
||||
.asset-actions,
|
||||
.history-card {
|
||||
@@ -1649,14 +1893,14 @@ onMounted(async () => {
|
||||
|
||||
.summary-sub {
|
||||
margin-top: 8px;
|
||||
color: #666;
|
||||
color: var(--text-secondary);
|
||||
font-size: 12px;
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
.vip-note {
|
||||
margin-top: 12px;
|
||||
color: #666;
|
||||
color: var(--text-secondary);
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
@@ -1669,4 +1913,51 @@ onMounted(async () => {
|
||||
color: #ff4d4f;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
@media (max-width: 960px) {
|
||||
.asset-summary,
|
||||
.asset-actions {
|
||||
row-gap: 12px;
|
||||
}
|
||||
|
||||
.asset-summary :deep(.ant-col),
|
||||
.asset-actions :deep(.ant-col) {
|
||||
flex: 0 0 100%;
|
||||
max-width: 100%;
|
||||
}
|
||||
|
||||
.asset-actions :deep(.ant-space) {
|
||||
width: 100%;
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 8px !important;
|
||||
}
|
||||
|
||||
.asset-actions :deep(.ant-space-item) {
|
||||
max-width: 100%;
|
||||
}
|
||||
}
|
||||
|
||||
:global(.default-password-notice) {
|
||||
display: grid;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
:global(.default-password-notice p) {
|
||||
margin: 0;
|
||||
color: var(--text-secondary);
|
||||
line-height: 1.7;
|
||||
}
|
||||
|
||||
:global(.default-password-notice__value) {
|
||||
padding: 12px 14px;
|
||||
border: 1px solid var(--theme-border);
|
||||
border-radius: 8px;
|
||||
background: var(--theme-primary-soft);
|
||||
color: var(--text-primary);
|
||||
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
|
||||
font-size: 15px;
|
||||
font-weight: 700;
|
||||
overflow-wrap: break-word;
|
||||
}
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user