Files
JayuCloud/FD-Frontend/src/views/admin/NailArtistsView.vue
T
2026-06-15 15:53:55 +08:00

709 lines
27 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<template>
<div class="nail-artists">
<a-page-header v-if="!isMobile" title="美甲师管理" sub-title="管理美甲师详细信息" />
<section v-else class="admin-page-intro">
<span class="admin-page-intro__eyebrow">经营</span>
<h1 class="admin-page-intro__title">美甲师管理</h1>
<p class="admin-page-intro__subtitle">
把状态、技能和作品挂载关系收成单列卡片,手机端可以直接查看和编辑。
</p>
<div class="admin-page-intro__meta">
<span class="admin-page-chip">美甲师 {{ nailArtistList.length }}</span>
</div>
</section>
<a-card :bordered="false">
<template #title v-if="isMobile">
美甲师列表
</template>
<template #extra>
<div class="admin-toolbar" :class="{ 'admin-toolbar--stacked': isMobile }">
<a-input-search
v-model:value="searchText"
placeholder="搜索美甲师姓名"
:style="isMobile ? { width: '100%' } : { width: '250px' }"
@search="handleSearch"
/>
</div>
</template>
<a-table
v-if="!isMobile"
:columns="columns"
:data-source="nailArtistList"
:loading="loading"
:pagination="pagination"
@change="handleTableChange"
row-key="userId"
:scroll="{ x: 'max-content' }"
>
<template #bodyCell="{ column, record }">
<template v-if="column.key === 'status'">
<a-tag :color="getStatusColor(record.status)">
{{ getStatusText(record.status) }}
</a-tag>
</template>
<template v-else-if="column.key === 'userTypeName'">
<a-tag :color="record.userType === 2 ? 'gold' : 'blue'">
{{ record.userTypeName || (record.userType === 2 ? '店长' : '美甲师') }}
</a-tag>
</template>
<template v-else-if="column.key === 'participateProduction'">
<a-tag :color="record.participateProduction === 1 ? 'green' : 'default'">
{{ record.participateProduction === 1 ? '参与制作' : '不参与' }}
</a-tag>
</template>
<template v-else-if="column.key === 'workTime'">
{{ formatWorkTime(record) }}
</template>
<template v-else-if="column.key === 'actions'">
<a-space>
<a-button v-if="hasPermission('nail_artist:view')" type="link" size="small" @click="showViewModal(record)">
查看
</a-button>
<a-button v-if="hasPermission('nail_artist:edit')" type="link" size="small" @click="showEditModal(record)">
编辑
</a-button>
</a-space>
</template>
</template>
</a-table>
<AdminMobileCardList v-else :items="nailArtistList" item-key="userId" empty-description="暂无美甲师数据">
<template #item="{ item }">
<article class="admin-mobile-card">
<div class="admin-mobile-card__head">
<div class="admin-mobile-card__body">
<div class="admin-mobile-card__title">{{ item.nickname }}</div>
<div class="admin-mobile-card__subtitle">{{ item.shopName || '未绑定店铺' }}</div>
</div>
<a-tag :color="getStatusColor(item.status)">{{ getStatusText(item.status) }}</a-tag>
</div>
<div class="admin-mobile-card__rows">
<div class="admin-mobile-card__row">
<span>身份</span>
<strong>{{ item.identity || '--' }}</strong>
</div>
<div class="admin-mobile-card__row">
<span>从业年限</span>
<strong>{{ item.experience ?? '--' }}</strong>
</div>
<div class="admin-mobile-card__row">
<span>评分</span>
<strong>{{ item.rating || '--' }}</strong>
</div>
</div>
<div class="admin-mobile-card__actions">
<a-button v-if="hasPermission('nail_artist:view')" size="small" @click="showViewModal(item)">查看</a-button>
<a-button v-if="hasPermission('nail_artist:edit')" size="small" @click="showEditModal(item)">编辑</a-button>
</div>
</article>
</template>
</AdminMobileCardList>
</a-card>
<!-- 编辑美甲师信息模态框 -->
<AdminResponsiveModal
v-model:open="modalVisible"
title="编辑美甲师信息"
@ok="handleModalOk"
@cancel="handleModalCancel"
:confirmLoading="modalLoading"
:desktop-width="800"
>
<DraftActions
:saved-at="draftSavedAt"
@save="handleSaveDraft"
@clear="handleClearDraft"
/>
<a-form
ref="formRef"
:model="formState"
:rules="formRules"
:label-col="{ span: 6 }"
:wrapper-col="{ span: 16 }"
>
<a-form-item label="美甲师姓名" name="nickname">
<a-input v-model:value="formState.nickname" :disabled="true" />
</a-form-item>
<a-form-item label="身份" name="identity">
<a-input
v-model:value="formState.identity"
placeholder="请输入身份"
:disabled="!isShopOwner"
/>
</a-form-item>
<a-form-item label="从业年限" name="experience">
<a-input-number
v-model:value="formState.experience"
:min="0"
placeholder="请输入从业年限"
:disabled="!isShopOwner"
/>
</a-form-item>
<a-form-item label="技能标签" name="skills">
<a-select
v-model:value="formState.skills"
mode="multiple"
placeholder="请选择技能标签"
:loading="tagLoading"
>
<a-select-option
v-for="tag in tagList"
:key="tag.id"
:value="tag.id.toString()"
>
{{ tag.tagName }}
</a-select-option>
</a-select>
</a-form-item>
<a-form-item label="状态" name="status">
<a-select
v-model:value="formState.status"
placeholder="请选择状态"
:disabled="!isShopOwner"
>
<a-select-option :value="1">营业中</a-select-option>
<a-select-option :value="0">休息中</a-select-option>
</a-select>
</a-form-item>
<a-form-item label="参与制作" name="participateProduction">
<a-switch
v-model:checked="formState.participateProduction"
:checked-value="1"
:un-checked-value="0"
:disabled="!isShopOwner"
/>
</a-form-item>
<a-form-item label="工作时间">
<a-input v-model:value="formState.workStartTime" type="time" placeholder="开始" />
<span class="time-separator">至</span>
<a-input v-model:value="formState.workEndTime" type="time" placeholder="结束" />
</a-form-item>
<a-form-item label="作品" name="portfolio">
<a-select
v-model:value="formState.portfolio"
mode="multiple"
placeholder="请选择作品作品"
:loading="productLoading"
>
<a-select-option
v-for="product in productList"
:key="product.id"
:value="product.id.toString()"
>
{{ product.title }}
</a-select-option>
</a-select>
</a-form-item>
<a-form-item label="评分">
<a-input v-model:value="formState.rating" :disabled="true" />
</a-form-item>
</a-form>
</AdminResponsiveModal>
<!-- 查看美甲师详情模态框 -->
<AdminResponsiveModal
v-model:open="viewModalVisible"
title="查看美甲师详情"
:footer="null"
@cancel="handleViewModalCancel"
:desktop-width="600"
>
<a-form
:model="viewFormState"
:label-col="{ span: 6 }"
:wrapper-col="{ span: 16 }"
>
<a-form-item label="美甲师姓名">
<a-input v-model:value="viewFormState.nickname" :disabled="true" />
</a-form-item>
<a-form-item label="所属店铺">
<a-input v-model:value="viewFormState.shopName" :disabled="true" />
</a-form-item>
<a-form-item label="身份">
<a-input v-model:value="viewFormState.identity" :disabled="true" />
</a-form-item>
<a-form-item label="从业年限">
<a-input v-model:value="viewFormState.experience" :disabled="true" />
</a-form-item>
<a-form-item label="技能标签">
<a-input v-model:value="viewFormState.skillsText" :disabled="true" />
</a-form-item>
<a-form-item label="状态">
<a-input v-model:value="viewFormState.statusText" :disabled="true" />
</a-form-item>
<a-form-item label="人员类型">
<a-input v-model:value="viewFormState.userTypeName" :disabled="true" />
</a-form-item>
<a-form-item label="工作时间">
<a-input v-model:value="viewFormState.workTime" :disabled="true" />
</a-form-item>
<a-form-item label="评分">
<a-input v-model:value="viewFormState.rating" :disabled="true" />
</a-form-item>
<a-form-item label="作品">
<a-input v-model:value="viewFormState.portfolioText" :disabled="true" />
</a-form-item>
</a-form>
</AdminResponsiveModal>
</div>
</template>
<script setup lang="ts">
/**
* NailArtistsView 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 { ref, reactive, onMounted } from 'vue'
import { message } from 'ant-design-vue'
import type { FormInstance } from 'ant-design-vue'
import DraftActions from '@/components/DraftActions.vue'
/**
* Purpose: NailArtistInfoVO supports NailArtistsView.vue by holding or executing the nail artist info vo page or API role.
* Usage: import, call, read, or update this type from the owning page/module while preserving the surrounding loading and permission flow.
*/
import { adminNailArtistApi, type NailArtistInfoVO } from '@/api/admin'
/**
* Purpose: Tag supports NailArtistsView.vue by holding or executing the tag page or API role.
* Usage: import, call, read, or update this type from the owning page/module while preserving the surrounding loading and permission flow.
*/
import { adminTagApi, type Tag } from '@/api/admin'
/**
* Purpose: Product supports NailArtistsView.vue by holding or executing the product page or API role.
* Usage: import, call, read, or update this type from the owning page/module while preserving the surrounding loading and permission flow.
*/
import { adminProductApi, type Product } from '@/api/admin'
import { buildDraftStorageKey, clearDraftRecord, loadDraftRecord, saveDraftRecord } from '@/utils/form-draft'
import { usePermission } from '@/utils/permission'
import { runWithGlobalLoading } from '@/utils/action-loading'
import { useAdminViewport } from '@/composables/useAdminViewport'
import AdminMobileCardList from '@/components/admin/AdminMobileCardList.vue'
import AdminResponsiveModal from '@/components/admin/AdminResponsiveModal.vue'
const { hasPermission, loadUserPermissions } = usePermission()
const { isMobile } = useAdminViewport()
/** getCurrentUserInfo is a local helper used by this page script. */
const getCurrentUserInfo = () => {
try {
const userInfoStr = localStorage.getItem('adminUserInfo')
if (userInfoStr) {
const userInfo = JSON.parse(userInfoStr)
isAdmin.value = userInfo.type === 4
isShopOwner.value = userInfo.type === 2
return userInfo
}
} catch (error: any) {
console.error('获取当前用户信息失败', error)
}
return null
}
/** loading is a reactive state variable used by the template and event handlers. */
const loading = ref(false)
/** tagLoading is a reactive state variable used by the template and event handlers. */
const tagLoading = ref(false)
/** productLoading is a reactive state variable used by the template and event handlers. */
const productLoading = ref(false)
/** searchText is a reactive state variable used by the template and event handlers. */
const searchText = ref('')
/**
* Purpose: nailArtistList supports NailArtistsView.vue by holding or executing the nail artist list 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 nailArtistList = ref<NailArtistInfoVO[]>([])
/**
* Purpose: tagList supports NailArtistsView.vue by holding or executing the tag list 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 tagList = ref<Tag[]>([])
/**
* Purpose: productList supports NailArtistsView.vue by holding or executing the product list 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 productList = ref<Product[]>([])
/** modalVisible is a reactive state variable used by the template and event handlers. */
const modalVisible = ref(false)
/** modalLoading is a reactive state variable used by the template and event handlers. */
const modalLoading = ref(false)
/** viewModalVisible is a reactive state variable used by the template and event handlers. */
const viewModalVisible = ref(false)
/** isAdmin is a reactive state variable used by the template and event handlers. */
const isAdmin = ref(false)
/** isShopOwner is a reactive state variable used by the template and event handlers. */
const isShopOwner = ref(false)
/**
* Purpose: formRef supports NailArtistsView.vue by holding or executing the form ref 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 formRef = ref<FormInstance>()
/**
* Purpose: currentNailArtist supports NailArtistsView.vue by holding or executing the current nail artist 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 currentNailArtist = ref<NailArtistInfoVO | null>(null)
/**
* Purpose: currentUserInfo supports NailArtistsView.vue by holding or executing the current user info 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 currentUserInfo = getCurrentUserInfo()
/**
* Purpose: draftSavedAt supports NailArtistsView.vue by holding or executing the draft saved at 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 draftSavedAt = ref<number | null>(null)
/**
* Purpose: viewFormState supports NailArtistsView.vue by holding or executing the view form state 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 viewFormState = reactive({
nickname: '',
shopName: '',
identity: '',
experience: '',
skillsText: '',
statusText: '',
userTypeName: '',
workTime: '',
rating: '',
portfolioText: ''
})
/**
* Purpose: pagination supports NailArtistsView.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.
*/
const pagination = reactive({
current: 1,
pageSize: 10,
total: 0,
showSizeChanger: true,
showQuickJumper: true,
showTotal: (total: number) => `共 ${total} 条`
})
/**
* Purpose: formState supports NailArtistsView.vue by holding or executing the form state 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 formState = reactive({
userId: 0,
identity: '',
experience: 0,
skills: [] as string[],
rating: 0,
status: 1,
participateProduction: 1,
workStartTime: '',
workEndTime: '',
portfolio: [] as string[],
nickname: ''
})
/** getDraftKey is a local helper used by this page script. */
const getDraftKey = () => buildDraftStorageKey('admin-nail-artists', 'edit', currentNailArtist.value?.userId ?? formState.userId ?? 'unknown')
/** buildDraftPayload is a local helper used by this page script. */
const buildDraftPayload = () => ({
identity: formState.identity,
experience: formState.experience,
skills: [...formState.skills],
status: formState.status,
participateProduction: formState.participateProduction,
workStartTime: formState.workStartTime,
workEndTime: formState.workEndTime,
portfolio: [...formState.portfolio]
})
/** restoreDraft is a local helper used by this page script. */
const restoreDraft = () => {
const draft = loadDraftRecord<ReturnType<typeof buildDraftPayload>>(getDraftKey())
if (!draft) {
draftSavedAt.value = null
return
}
Object.assign(formState, {
identity: draft.payload.identity ?? formState.identity,
experience: typeof draft.payload.experience === 'number' ? draft.payload.experience : formState.experience,
skills: Array.isArray(draft.payload.skills) ? draft.payload.skills : formState.skills,
status: typeof draft.payload.status === 'number'
? (draft.payload.status === 0 ? 0 : 1)
: formState.status,
participateProduction: typeof draft.payload.participateProduction === 'number'
? (draft.payload.participateProduction === 1 ? 1 : 0)
: formState.participateProduction,
workStartTime: draft.payload.workStartTime ?? formState.workStartTime,
workEndTime: draft.payload.workEndTime ?? formState.workEndTime,
portfolio: Array.isArray(draft.payload.portfolio) ? draft.payload.portfolio : formState.portfolio
})
draftSavedAt.value = draft.savedAt
message.success('已恢复暂存内容')
}
/** handleSaveDraft is a local helper used by this page script. */
const handleSaveDraft = () => {
const draft = saveDraftRecord(getDraftKey(), buildDraftPayload())
draftSavedAt.value = draft.savedAt
message.success('已暂存到本地')
}
/** handleClearDraft is a local helper used by this page script. */
const handleClearDraft = (showMessage = true) => {
clearDraftRecord(getDraftKey())
draftSavedAt.value = null
if (showMessage) {
message.success('已清除暂存')
}
}
/**
* Purpose: formRules supports NailArtistsView.vue by holding or executing the form rules 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 formRules = {
identity: [{ required: true, message: '请输入身份', trigger: 'blur' }],
experience: [{ required: true, message: '请输入从业年限', trigger: 'blur' }],
skills: [{ required: true, message: '请选择技能标签', trigger: 'change' }],
status: [{ required: true, message: '请选择状态', trigger: 'change' }],
portfolio: [{ required: true, message: '请选择作品作品', trigger: 'change' }]
} as any
/**
* Purpose: columns supports NailArtistsView.vue by holding or executing the columns 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 columns = [
{ title: '美甲师姓名', dataIndex: 'nickname', key: 'nickname' },
{ title: '所属店铺', dataIndex: 'shopName', key: 'shopName' },
{ title: '人员类型', key: 'userTypeName', width: 110 },
{ title: '参与制作', key: 'participateProduction', width: 120 },
{ title: '工作时间', key: 'workTime', width: 150 },
{ title: '身份', dataIndex: 'identity', key: 'identity' },
{ title: '从业年限', dataIndex: 'experience', key: 'experience' },
{ title: '评分', dataIndex: 'rating', key: 'rating' },
{ title: '状态', key: 'status', width: 100 },
{ title: '操作', key: 'actions', width: 150, fixed: 'right' as const }
]
/** getStatusText is a local helper used by this page script. */
const getStatusText = (status: number) => {
return status === 1 ? '营业中' : '休息中'
}
/** getStatusColor is a local helper used by this page script. */
const getStatusColor = (status: number) => {
return status === 1 ? 'green' : 'default'
}
/** formatWorkTime is a local helper used by this page script. */
const formatWorkTime = (record: Partial<NailArtistInfoVO>) => {
const start = record.workStartTime ? String(record.workStartTime).slice(0, 5) : ''
const end = record.workEndTime ? String(record.workEndTime).slice(0, 5) : ''
return start && end ? `${start} - ${end}` : '--'
}
/** normalizeTime is a local helper used by this page script. */
const normalizeTime = (value?: string) => value ? (String(value).length === 5 ? `${value}:00` : String(value)) : undefined
/** fetchTagList is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
const fetchTagList = async () => {
tagLoading.value = true
try {
const res = await adminTagApi.listAllTags() as unknown as Tag[]
tagList.value = res || []
} catch (error) {
console.error('获取标签列表失败:', error)
} finally {
tagLoading.value = false
}
}
/** fetchProductList is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
const fetchProductList = async () => {
productLoading.value = true
try {
const params: any = {
page: 1,
size: 1000
}
if (currentUserInfo && currentUserInfo.type !== 4 && currentUserInfo.shopId) {
params.shopId = currentUserInfo.shopId
}
const res = await adminProductApi.listProducts(params) as unknown as { list: Product[] }
productList.value = res.list || []
} catch (error) {
console.error('获取作品列表失败:', error)
} finally {
productLoading.value = false
}
}
/** fetchNailArtistList is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
const fetchNailArtistList = async () => {
loading.value = true
try {
const res = await adminNailArtistApi.listNailArtists() as unknown as NailArtistInfoVO[]
let filteredList = res || []
// 按搜索词过滤
if (searchText.value) {
filteredList = filteredList.filter((item: NailArtistInfoVO) =>
item.nickname?.includes(searchText.value)
)
}
nailArtistList.value = filteredList
pagination.total = filteredList.length || 0
} catch (error) {
message.error('获取美甲师列表失败')
} finally {
loading.value = false
}
}
/** handleSearch is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
const handleSearch = async () => {
pagination.current = 1
await runWithGlobalLoading(() => fetchNailArtistList())
}
/** handleTableChange is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
const handleTableChange = async (pag: any) => {
pagination.current = pag.current
pagination.pageSize = pag.pageSize
await runWithGlobalLoading(() => fetchNailArtistList())
}
/** showEditModal is a local helper used by this page script. */
const showEditModal = (record: Record<string, any>) => {
currentNailArtist.value = record as NailArtistInfoVO
const lockedFields = {
userId: record.userId,
rating: record.rating || 0,
nickname: record.nickname || ''
}
Object.assign(formState, {
identity: record.identity || '',
experience: record.experience || 0,
skills: record.skills ? record.skills.split(',').filter(Boolean) : [],
status: record.status || 1,
participateProduction: record.participateProduction ?? (record.userType === 3 ? 1 : 0),
workStartTime: record.workStartTime || '',
workEndTime: record.workEndTime || '',
portfolio: record.portfolio ? record.portfolio.split(',').filter(Boolean) : [],
...lockedFields
})
restoreDraft()
Object.assign(formState, lockedFields)
modalVisible.value = true
}
/** showViewModal is a local helper used by this page script. */
const showViewModal = (record: Record<string, any>) => {
const nailArtist = record as NailArtistInfoVO
// 构建技能标签文本
const skillsArray = nailArtist.skills ? nailArtist.skills.split(',').filter(Boolean) : []
const skillsText = skillsArray.map(skillId => {
const tag = tagList.value.find(t => t.id.toString() === skillId)
return tag ? tag.tagName : skillId
}).join(', ')
// 构建作品文本
const portfolioArray = nailArtist.portfolio ? nailArtist.portfolio.split(',').filter(Boolean) : []
const portfolioText = portfolioArray.map(productId => {
const product = productList.value.find(p => p.id.toString() === productId)
return product ? product.title : productId
}).join(', ')
Object.assign(viewFormState, {
nickname: nailArtist.nickname || '',
shopName: nailArtist.shopName || '',
identity: nailArtist.identity || '',
experience: (nailArtist.experience || 0).toString(),
skillsText: skillsText,
statusText: getStatusText(nailArtist.status || 1),
userTypeName: nailArtist.userTypeName || (nailArtist.userType === 2 ? '店长' : '美甲师'),
workTime: formatWorkTime(nailArtist),
rating: (nailArtist.rating || 0).toString(),
portfolioText: portfolioText
})
viewModalVisible.value = true
}
/** handleViewModalCancel is a local helper used by this page script. */
const handleViewModalCancel = () => {
viewModalVisible.value = false
}
/** handleModalOk is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
const handleModalOk = async () => {
try {
await formRef.value?.validate()
const targetUserId = currentNailArtist.value?.userId ?? formState.userId
if (!targetUserId) {
message.error('未获取到当前美甲师信息,请关闭弹窗后重试')
return
}
modalLoading.value = true
await runWithGlobalLoading(async () => {
// 准备提交数据
const submitData = {
userId: targetUserId,
identity: formState.identity,
experience: formState.experience,
rating: formState.rating,
status: formState.status,
participateProduction: formState.participateProduction,
workStartTime: normalizeTime(formState.workStartTime),
workEndTime: normalizeTime(formState.workEndTime),
skills: formState.skills.join(','),
portfolio: formState.portfolio.join(',')
}
await adminNailArtistApi.saveNailArtistInfo(submitData)
message.success('保存成功')
handleClearDraft(false)
modalVisible.value = false
await fetchNailArtistList()
})
} catch (error) {
console.error(error)
const errorMessage = (error as Error)?.message
if (errorMessage) {
message.error(errorMessage)
return
}
message.error('操作失败')
} finally {
modalLoading.value = false
}
}
/** handleModalCancel is a local helper used by this page script. */
const handleModalCancel = () => {
modalVisible.value = false
currentNailArtist.value = null
formRef.value?.resetFields()
}
onMounted(async () => {
await loadUserPermissions()
fetchTagList()
fetchProductList()
fetchNailArtistList()
})
</script>
<style scoped>
.nail-artists {
padding: 0;
}
</style>