迁移合作订单完整能力,并统一 AppRoleCode 角色权限与首页菜单展示。
新增 CooperationOrder 模块(双 Tab 列表、获客员绑定、主 Tab 扫码)、订单来源/带客单绑定及配套 API 测试;同步引入 roleCode 权限匹配与相关单元测试。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@ -19,7 +19,7 @@ Statistics 模块负责登录后的数据 Tab,展示当前景区下的订单
|
||||
|
||||
切换时间段时同时请求汇总接口和第一页日数据接口。汇总接口使用 `range` 参数,日数据接口使用 `start_time`、`end_time`、`page` 和 `page_size`。
|
||||
|
||||
`roleId == 53` 时使用景区管理员接口,其他角色使用摄影师接口。日数据响应使用 `DataListPayload` 解码,兼容后端返回 `data` 或 `list` 字段。
|
||||
`currentAppRole.isScenicAdmin == true` 时使用景区管理员接口,其他角色使用摄影师接口。日数据响应使用 `DataListPayload` 解码,兼容后端返回 `data` 或 `list` 字段。
|
||||
|
||||
## 分页规则
|
||||
|
||||
|
||||
@ -28,13 +28,13 @@ final class StatisticsViewModel: ObservableObject {
|
||||
}
|
||||
|
||||
/// 切换统计时间段,并重置分页重新加载。
|
||||
func selectPeriod(_ period: StatisticsPeriod, api: StatisticsServing, scenicId: Int?, roleId: Int?) async throws {
|
||||
func selectPeriod(_ period: StatisticsPeriod, api: StatisticsServing, scenicId: Int?, appRole: AppRoleCode?) async throws {
|
||||
selectedPeriod = period
|
||||
try await reload(api: api, scenicId: scenicId, roleId: roleId)
|
||||
try await reload(api: api, scenicId: scenicId, appRole: appRole)
|
||||
}
|
||||
|
||||
/// 刷新统计汇总和第一页日数据,缺少景区时清空旧状态。
|
||||
func reload(api: StatisticsServing, scenicId: Int?, roleId: Int?, showLoading: Bool = true) async throws {
|
||||
func reload(api: StatisticsServing, scenicId: Int?, appRole: AppRoleCode?, showLoading: Bool = true) async throws {
|
||||
guard let scenicId else {
|
||||
reset()
|
||||
return
|
||||
@ -43,7 +43,7 @@ final class StatisticsViewModel: ObservableObject {
|
||||
if showLoading { loading = true }
|
||||
defer { if showLoading { loading = false } }
|
||||
|
||||
let isScenicAdmin = roleId == 53
|
||||
let isScenicAdmin = appRole?.isScenicAdmin == true
|
||||
async let summaryResult = api.summary(
|
||||
scenicId: scenicId,
|
||||
range: selectedPeriod.apiRange,
|
||||
@ -66,7 +66,7 @@ final class StatisticsViewModel: ObservableObject {
|
||||
}
|
||||
|
||||
/// 加载每日统计下一页。
|
||||
func loadMore(api: StatisticsServing, scenicId: Int?, roleId: Int?) async throws {
|
||||
func loadMore(api: StatisticsServing, scenicId: Int?, appRole: AppRoleCode?) async throws {
|
||||
guard !loadingMore, hasMore, let scenicId else { return }
|
||||
|
||||
loadingMore = true
|
||||
@ -79,7 +79,7 @@ final class StatisticsViewModel: ObservableObject {
|
||||
endTime: selectedPeriod.apiEndTime,
|
||||
page: nextPage,
|
||||
pageSize: pageSize,
|
||||
isScenicAdmin: roleId == 53
|
||||
isScenicAdmin: appRole?.isScenicAdmin == true
|
||||
)
|
||||
dailyItems.append(contentsOf: result.data)
|
||||
totalDailyCount = result.total
|
||||
|
||||
@ -22,8 +22,8 @@ struct StatisticsView: View {
|
||||
accountContext.currentScenic?.id
|
||||
}
|
||||
|
||||
private var currentRoleId: Int? {
|
||||
permissionContext.currentRole?.id
|
||||
private var currentAppRole: AppRoleCode? {
|
||||
permissionContext.currentAppRole
|
||||
}
|
||||
|
||||
private var contentMaxWidth: CGFloat {
|
||||
@ -62,7 +62,7 @@ struct StatisticsView: View {
|
||||
.onChange(of: accountContext.currentScenic?.id) { _ in
|
||||
Task { await reload() }
|
||||
}
|
||||
.onChange(of: permissionContext.currentRole?.id) { _ in
|
||||
.onChange(of: permissionContext.currentRole?.roleCode) { _ in
|
||||
Task { await reload() }
|
||||
}
|
||||
}
|
||||
@ -289,7 +289,7 @@ struct StatisticsView: View {
|
||||
private func selectPeriod(_ period: StatisticsPeriod) async {
|
||||
do {
|
||||
try await globalLoading.withLoading(message: "加载中...") {
|
||||
try await viewModel.selectPeriod(period, api: statisticsAPI, scenicId: currentScenicId, roleId: currentRoleId)
|
||||
try await viewModel.selectPeriod(period, api: statisticsAPI, scenicId: currentScenicId, appRole: currentAppRole)
|
||||
}
|
||||
} catch {
|
||||
toastCenter.show(error.localizedDescription)
|
||||
@ -299,7 +299,7 @@ struct StatisticsView: View {
|
||||
private func reload(showLoading: Bool = true) async {
|
||||
do {
|
||||
try await globalLoading.withOptionalLoading(showLoading && currentScenicId != nil && viewModel.dailyItems.isEmpty, message: "加载中...") {
|
||||
try await viewModel.reload(api: statisticsAPI, scenicId: currentScenicId, roleId: currentRoleId, showLoading: showLoading)
|
||||
try await viewModel.reload(api: statisticsAPI, scenicId: currentScenicId, appRole: currentAppRole, showLoading: showLoading)
|
||||
}
|
||||
} catch {
|
||||
toastCenter.show(error.localizedDescription)
|
||||
@ -308,7 +308,7 @@ struct StatisticsView: View {
|
||||
|
||||
private func loadMore() async {
|
||||
do {
|
||||
try await viewModel.loadMore(api: statisticsAPI, scenicId: currentScenicId, roleId: currentRoleId)
|
||||
try await viewModel.loadMore(api: statisticsAPI, scenicId: currentScenicId, appRole: currentAppRole)
|
||||
} catch {
|
||||
toastCenter.show(error.localizedDescription)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user