功能:增加店长员工审核与登录提醒
This commit is contained in:
@@ -12,10 +12,28 @@ function buildScheduleSummary(item) {
|
||||
return time ? `${mode} ${time}` : mode
|
||||
}
|
||||
|
||||
function formatApplicationTime(value) {
|
||||
if (!value) return ''
|
||||
return String(value).replace('T', ' ').slice(0, 16)
|
||||
}
|
||||
|
||||
function confirmModal(options) {
|
||||
return new Promise(resolve => {
|
||||
wx.showModal({ ...options, success: resolve, fail: () => resolve({ confirm: false }) })
|
||||
})
|
||||
}
|
||||
|
||||
Page({
|
||||
data: {
|
||||
employees: [],
|
||||
loadError: '',
|
||||
isManager: false,
|
||||
reviewExpanded: false,
|
||||
reviewApplications: [],
|
||||
reviewPendingCount: 0,
|
||||
reviewLoading: false,
|
||||
reviewError: '',
|
||||
reviewingId: '',
|
||||
createModalVisible: false,
|
||||
creating: false,
|
||||
createForm: {
|
||||
@@ -31,7 +49,96 @@ Page({
|
||||
},
|
||||
|
||||
onLoad() {
|
||||
const userInfo = getApp().globalData.userInfo || {}
|
||||
this.setData({ isManager: Number(userInfo.type) === 2 })
|
||||
this.loadEmployees()
|
||||
if (Number(userInfo.type) === 2) this.loadReviewSummary()
|
||||
},
|
||||
|
||||
onShow() {
|
||||
const app = getApp()
|
||||
if (!this.data.isManager || !app.globalData.openEmployeeReview) return
|
||||
app.globalData.openEmployeeReview = false
|
||||
this.setData({ reviewExpanded: true })
|
||||
return this.loadReviewApplications()
|
||||
},
|
||||
|
||||
async loadReviewSummary() {
|
||||
if (!this.data.isManager) return
|
||||
try {
|
||||
const summary = await employeesApi.reviewSummary()
|
||||
this.setData({ reviewPendingCount: Number(summary.pendingCount || 0) })
|
||||
} catch (error) {
|
||||
// 审核摘要失败不影响员工列表。
|
||||
}
|
||||
},
|
||||
|
||||
toggleReview() {
|
||||
if (!this.data.isManager) return
|
||||
const reviewExpanded = !this.data.reviewExpanded
|
||||
this.setData({ reviewExpanded })
|
||||
if (reviewExpanded) this.loadReviewApplications()
|
||||
},
|
||||
|
||||
async loadReviewApplications() {
|
||||
if (!this.data.isManager || this.data.reviewLoading) return
|
||||
this.setData({ reviewLoading: true, reviewError: '' })
|
||||
try {
|
||||
const data = await employeesApi.reviewApplications()
|
||||
const applications = (Array.isArray(data) ? data : []).map(item => ({
|
||||
...item,
|
||||
applicantNickname: item.applicantNickname || '待审核员工',
|
||||
applicantAvatar: item.applicantAvatar || '',
|
||||
applicantMaskedPhone: item.applicantMaskedPhone || '',
|
||||
applicationTimeText: formatApplicationTime(item.createTime)
|
||||
}))
|
||||
this.setData({ reviewApplications: applications, reviewPendingCount: applications.length })
|
||||
} catch (error) {
|
||||
this.setData({ reviewError: error.message || '审核申请加载失败' })
|
||||
} finally {
|
||||
this.setData({ reviewLoading: false })
|
||||
}
|
||||
},
|
||||
|
||||
async approveApplication(event) {
|
||||
const id = event.currentTarget.dataset.id
|
||||
if (!id || this.data.reviewingId) return
|
||||
const result = await confirmModal({ title: '通过员工申请', content: '确认允许该员工加入当前门店吗?' })
|
||||
if (!result.confirm) return
|
||||
await this.submitReview(id, () => employeesApi.approveApplication(id), '申请已通过')
|
||||
},
|
||||
|
||||
async rejectApplication(event) {
|
||||
const id = event.currentTarget.dataset.id
|
||||
if (!id || this.data.reviewingId) return
|
||||
const result = await confirmModal({
|
||||
title: '驳回员工申请',
|
||||
content: '',
|
||||
editable: true,
|
||||
placeholderText: '请输入驳回原因',
|
||||
confirmText: '确认驳回'
|
||||
})
|
||||
if (!result.confirm) return
|
||||
const reason = String(result.content || '').trim()
|
||||
if (!reason) {
|
||||
wx.showToast({ title: '请输入驳回原因', icon: 'none' })
|
||||
return
|
||||
}
|
||||
await this.submitReview(id, () => employeesApi.rejectApplication(id, reason), '申请已驳回')
|
||||
},
|
||||
|
||||
async submitReview(id, action, successMessage) {
|
||||
this.setData({ reviewingId: String(id) })
|
||||
try {
|
||||
await action()
|
||||
wx.showToast({ title: successMessage, icon: 'success' })
|
||||
await Promise.all([this.loadReviewApplications(), this.loadEmployees()])
|
||||
} catch (error) {
|
||||
wx.showToast({ title: error.message || '申请状态已变化,请刷新重试', icon: 'none' })
|
||||
await this.loadReviewApplications()
|
||||
} finally {
|
||||
this.setData({ reviewingId: '' })
|
||||
}
|
||||
},
|
||||
|
||||
async loadEmployees() {
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
const assert = require('assert')
|
||||
|
||||
global.wx = {
|
||||
getAccountInfoSync: () => ({ miniProgram: { envVersion: 'develop' } }),
|
||||
getDeviceInfo: () => ({ platform: 'devtools' }),
|
||||
getStorageSync: () => '',
|
||||
setStorageSync: () => {},
|
||||
removeStorageSync: () => {}
|
||||
}
|
||||
|
||||
const appMock = {
|
||||
globalData: {
|
||||
userInfo: { type: 2 },
|
||||
openEmployeeReview: true
|
||||
}
|
||||
}
|
||||
global.getApp = () => appMock
|
||||
|
||||
let definition
|
||||
global.Page = value => { definition = value }
|
||||
require('./index')
|
||||
|
||||
function createPage() {
|
||||
return {
|
||||
...definition,
|
||||
data: { ...definition.data, isManager: true },
|
||||
setData(values) { Object.assign(this.data, values) }
|
||||
}
|
||||
}
|
||||
|
||||
async function run() {
|
||||
const employeesApi = require('../../api/employees')
|
||||
employeesApi.reviewApplications = async () => [{
|
||||
id: 12,
|
||||
applicationNo: 'SALON-001',
|
||||
applicantNickname: '小周',
|
||||
createTime: '2026-10-12T10:30:00'
|
||||
}]
|
||||
|
||||
const page = createPage()
|
||||
await page.onShow()
|
||||
|
||||
assert.strictEqual(appMock.globalData.openEmployeeReview, false)
|
||||
assert.strictEqual(page.data.reviewExpanded, true)
|
||||
assert.strictEqual(page.data.reviewPendingCount, 1)
|
||||
assert.strictEqual(page.data.reviewApplications[0].applicationTimeText, '2026-10-12 10:30')
|
||||
}
|
||||
|
||||
run().catch(error => {
|
||||
console.error(error)
|
||||
process.exitCode = 1
|
||||
})
|
||||
@@ -1,9 +1,40 @@
|
||||
<view class="page">
|
||||
<view class="list-heading">
|
||||
<text>美甲师</text>
|
||||
<button wx:if="{{isManager}}" class="compact-btn review-toggle {{reviewExpanded ? 'is-open' : ''}}" bindtap="toggleReview">
|
||||
审核<text wx:if="{{reviewPendingCount > 0}}" class="review-badge">{{reviewPendingCount}}</text>
|
||||
</button>
|
||||
<button class="compact-btn" bindtap="addEmployee">新增</button>
|
||||
</view>
|
||||
|
||||
<view wx:if="{{isManager && reviewExpanded}}" class="review-panel card">
|
||||
<view class="review-panel-head">
|
||||
<view><text class="review-title">员工申请审核</text><text class="review-subtitle">仅显示当前门店待处理申请</text></view>
|
||||
<text class="review-count">{{reviewPendingCount}} 项</text>
|
||||
</view>
|
||||
<view wx:if="{{reviewLoading}}" class="review-state">正在加载申请…</view>
|
||||
<view wx:elif="{{reviewError}}" class="review-state review-error">
|
||||
<text>{{reviewError}}</text>
|
||||
<button class="secondary-btn review-retry" bindtap="loadReviewApplications">重试</button>
|
||||
</view>
|
||||
<view wx:elif="{{reviewApplications.length === 0}}" class="review-state">暂无待审核员工申请</view>
|
||||
<view wx:else class="review-list">
|
||||
<view wx:for="{{reviewApplications}}" wx:key="id" class="review-item">
|
||||
<image class="review-avatar" src="{{item.applicantAvatar || '/assets/images/default-user-avatar.png'}}" mode="aspectFill"></image>
|
||||
<view class="review-info">
|
||||
<text class="review-name">{{item.applicantNickname}}</text>
|
||||
<text wx:if="{{item.applicantMaskedPhone}}" class="review-meta">{{item.applicantMaskedPhone}}</text>
|
||||
<text class="review-meta">{{item.shopName || '当前门店'}} · {{item.applicationTimeText}}</text>
|
||||
<text class="review-number">申请编号 {{item.applicationNo}}</text>
|
||||
</view>
|
||||
<view class="review-actions">
|
||||
<button class="review-action reject" data-id="{{item.id}}" disabled="{{reviewingId}}" bindtap="rejectApplication">驳回</button>
|
||||
<button class="review-action approve" data-id="{{item.id}}" loading="{{reviewingId == item.id}}" disabled="{{reviewingId}}" bindtap="approveApplication">通过</button>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="list">
|
||||
<view wx:if="{{loadError}}" class="empty card">
|
||||
<text>{{loadError}}</text>
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
font-weight: 800;
|
||||
}
|
||||
|
||||
.list-heading text {
|
||||
.list-heading > text {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
@@ -17,6 +17,173 @@
|
||||
margin-left: auto;
|
||||
}
|
||||
|
||||
.list-heading .review-toggle {
|
||||
position: relative;
|
||||
margin-right: 12rpx;
|
||||
margin-left: 0;
|
||||
border-color: #c9d8d2;
|
||||
background: #eef5f2;
|
||||
color: #2f6f62;
|
||||
}
|
||||
|
||||
.list-heading .review-toggle.is-open {
|
||||
background: #2f6f62;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.review-badge {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
min-width: 30rpx;
|
||||
height: 30rpx;
|
||||
margin-left: 8rpx;
|
||||
padding: 0 7rpx;
|
||||
border-radius: 999rpx;
|
||||
background: #d9685f;
|
||||
color: #fff;
|
||||
font-size: 19rpx;
|
||||
line-height: 30rpx;
|
||||
}
|
||||
|
||||
.review-panel {
|
||||
margin-bottom: 22rpx;
|
||||
padding: 22rpx;
|
||||
border: 1rpx solid #dce8e3;
|
||||
background: #f8fcfa;
|
||||
}
|
||||
|
||||
.review-panel-head,
|
||||
.review-item,
|
||||
.review-actions {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.review-panel-head {
|
||||
justify-content: space-between;
|
||||
margin-bottom: 16rpx;
|
||||
}
|
||||
|
||||
.review-title,
|
||||
.review-subtitle,
|
||||
.review-name,
|
||||
.review-meta,
|
||||
.review-number {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.review-title {
|
||||
color: #25211d;
|
||||
font-size: 28rpx;
|
||||
font-weight: 900;
|
||||
}
|
||||
|
||||
.review-subtitle {
|
||||
margin-top: 4rpx;
|
||||
color: #8b847c;
|
||||
font-size: 21rpx;
|
||||
}
|
||||
|
||||
.review-count {
|
||||
color: #2f6f62;
|
||||
font-size: 23rpx;
|
||||
font-weight: 800;
|
||||
}
|
||||
|
||||
.review-list {
|
||||
display: grid;
|
||||
gap: 14rpx;
|
||||
}
|
||||
|
||||
.review-item {
|
||||
gap: 14rpx;
|
||||
padding: 18rpx;
|
||||
border-radius: 20rpx;
|
||||
background: #fff;
|
||||
box-shadow: 0 5rpx 18rpx rgba(47, 111, 98, 0.07);
|
||||
}
|
||||
|
||||
.review-avatar {
|
||||
flex: 0 0 auto;
|
||||
width: 72rpx;
|
||||
height: 72rpx;
|
||||
border-radius: 50%;
|
||||
background: #eee9e1;
|
||||
}
|
||||
|
||||
.review-info {
|
||||
min-width: 0;
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.review-name {
|
||||
color: #28231f;
|
||||
font-size: 27rpx;
|
||||
font-weight: 900;
|
||||
}
|
||||
|
||||
.review-meta,
|
||||
.review-number {
|
||||
margin-top: 4rpx;
|
||||
overflow: hidden;
|
||||
color: #817a72;
|
||||
font-size: 20rpx;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.review-number {
|
||||
color: #aaa198;
|
||||
font-size: 18rpx;
|
||||
}
|
||||
|
||||
.review-actions {
|
||||
flex: 0 0 auto;
|
||||
gap: 8rpx;
|
||||
}
|
||||
|
||||
.review-action {
|
||||
width: auto;
|
||||
min-width: 82rpx;
|
||||
height: 54rpx;
|
||||
margin: 0;
|
||||
padding: 0 15rpx;
|
||||
border-radius: 999rpx;
|
||||
font-size: 21rpx;
|
||||
font-weight: 800;
|
||||
line-height: 54rpx;
|
||||
}
|
||||
|
||||
.review-action.reject {
|
||||
border: 1rpx solid #e7c7c2;
|
||||
background: #fff5f3;
|
||||
color: #a8554e;
|
||||
}
|
||||
|
||||
.review-action.approve {
|
||||
border: 1rpx solid #2f6f62;
|
||||
background: #2f6f62;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.review-state {
|
||||
padding: 34rpx 12rpx;
|
||||
color: #8c857d;
|
||||
font-size: 23rpx;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.review-state.review-error {
|
||||
color: #a8554e;
|
||||
}
|
||||
|
||||
.review-retry {
|
||||
width: 150rpx;
|
||||
min-width: 150rpx;
|
||||
margin: 16rpx auto 0;
|
||||
}
|
||||
|
||||
.employee-card {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
|
||||
@@ -183,7 +183,7 @@ Page({
|
||||
},
|
||||
|
||||
finishLogin(result) {
|
||||
getApp().setSession(result)
|
||||
getApp().setSession(result, true)
|
||||
auth.setLoginPreference(this.data.rememberMe ? {
|
||||
rememberMe: true,
|
||||
preferredShopId: result.userInfo && result.userInfo.shopId,
|
||||
|
||||
@@ -5,6 +5,7 @@ const auth = require('../../utils/auth')
|
||||
const { uploadProfileImage } = require('../../utils/upload')
|
||||
const { normalizeAvatar } = require('../../utils/profile-card')
|
||||
const profileCache = require('../../utils/profile-cache')
|
||||
const employeesApi = require('../../api/employees')
|
||||
|
||||
function canCreateAppointment() {
|
||||
const app = getApp()
|
||||
@@ -110,6 +111,7 @@ Page({
|
||||
},
|
||||
|
||||
async refreshAccountPrompts() {
|
||||
let shouldShowProfilePrompt = false
|
||||
try {
|
||||
const profile = await profileCache.getProfile()
|
||||
const session = auth.getSession()
|
||||
@@ -119,14 +121,47 @@ Page({
|
||||
const missingNickname = !String(profile.nickname || '').trim() || String(profile.nickname).startsWith('微信用户')
|
||||
const avatar = normalizeAvatar(profile.avatar)
|
||||
const skipped = wx.getStorageSync(auth.PROFILE_PROMPT_SKIPPED_KEY) === '1'
|
||||
shouldShowProfilePrompt = !skipped && (missingNickname || !avatar)
|
||||
this.setData({
|
||||
phoneBannerVisible: Number(profile.phoneVerified) !== 1 && dismissed !== today,
|
||||
profilePromptVisible: !skipped && (missingNickname || !avatar),
|
||||
profilePromptVisible: false,
|
||||
profileForm: { nickname: missingNickname ? '' : profile.nickname, avatar }
|
||||
})
|
||||
} catch (error) {
|
||||
// 资料提醒失败不影响规划数据。
|
||||
}
|
||||
const navigatedToReview = await this.showEmployeeReviewNotice()
|
||||
if (!navigatedToReview) {
|
||||
this.setData({ profilePromptVisible: shouldShowProfilePrompt })
|
||||
}
|
||||
},
|
||||
|
||||
async showEmployeeReviewNotice() {
|
||||
const app = getApp()
|
||||
const userInfo = app.globalData.userInfo || {}
|
||||
if (Number(userInfo.type) !== 2 || app.globalData.reviewNoticeShown) return false
|
||||
let summary
|
||||
try {
|
||||
summary = await employeesApi.reviewSummary()
|
||||
} catch (error) {
|
||||
return false
|
||||
}
|
||||
if (!summary.noticeEnabled || Number(summary.pendingCount || 0) <= 0) return false
|
||||
app.globalData.reviewNoticeShown = true
|
||||
const result = await new Promise(resolve => {
|
||||
wx.showModal({
|
||||
title: '有员工申请待审核',
|
||||
content: `当前有 ${summary.pendingCount} 条员工加入申请,是否立即处理?`,
|
||||
cancelText: '稍后处理',
|
||||
confirmText: '立即审核',
|
||||
success: resolve,
|
||||
fail: () => resolve({ confirm: false })
|
||||
})
|
||||
})
|
||||
if (!result.confirm) return false
|
||||
app.globalData.openEmployeeReview = true
|
||||
wx.switchTab({ url: '/pages/employees/index' })
|
||||
return true
|
||||
},
|
||||
|
||||
openAccountSettings() { wx.navigateTo({ url: '/pages/account-settings/index' }) },
|
||||
|
||||
@@ -7,9 +7,12 @@ global.wx = {
|
||||
getStorageSync: () => '',
|
||||
setStorageSync: () => {},
|
||||
removeStorageSync: () => {},
|
||||
showToast: () => {}
|
||||
showToast: () => {},
|
||||
showModal: ({ success }) => success({ confirm: false }),
|
||||
switchTab: () => {}
|
||||
}
|
||||
global.getApp = () => ({ globalData: { userInfo: {} } })
|
||||
const appMock = { globalData: { userInfo: {} } }
|
||||
global.getApp = () => appMock
|
||||
|
||||
let definition
|
||||
global.Page = value => { definition = value }
|
||||
@@ -69,6 +72,19 @@ async function run() {
|
||||
assert.strictEqual(calendarRequests, 1)
|
||||
resolveCalendar({ artists: [], appointments: [], daySummaries: [] })
|
||||
await Promise.all([requestOne, requestTwo])
|
||||
|
||||
const employeesApi = require('../../api/employees')
|
||||
const noticePage = createPage()
|
||||
appMock.globalData.userInfo = { type: 2 }
|
||||
appMock.globalData.reviewNoticeShown = false
|
||||
employeesApi.reviewSummary = async () => ({ pendingCount: 2, noticeEnabled: true })
|
||||
let switched = false
|
||||
global.wx.showModal = ({ success }) => success({ confirm: true })
|
||||
global.wx.switchTab = ({ url }) => { switched = url === '/pages/employees/index' }
|
||||
assert.strictEqual(await noticePage.showEmployeeReviewNotice(), true)
|
||||
assert.strictEqual(switched, true)
|
||||
assert.strictEqual(appMock.globalData.reviewNoticeShown, true)
|
||||
assert.strictEqual(appMock.globalData.openEmployeeReview, true)
|
||||
}
|
||||
|
||||
run().catch(error => {
|
||||
|
||||
Reference in New Issue
Block a user