admin模块接入数据库

This commit is contained in:
comlibmb
2026-02-13 17:29:50 +08:00
parent 56209b7a75
commit ec636dc703
58 changed files with 5586 additions and 1394 deletions

View File

@@ -17,7 +17,7 @@
</view>
<view class="content-card">
<view class="action-bar">
<button class="btn primary small" @click="onAdd">添加等级</button>
<button class="btn primary small" @click="openEditModal(null)">添加等级</button>
</view>
<view class="table-container">
<view class="table-header">
@@ -42,17 +42,17 @@
<view class="col col-level"><text>{{ item.level }}</text></view>
<view class="col col-percent"><text>{{ item.percent1 }}%</text></view>
<view class="col col-percent"><text>{{ item.percent2 }}%</text></view>
<view class="col col-stat"><text>{{ item.taskTotal }}</text></view>
<view class="col col-stat"><text>{{ item.taskFinish }}</text></view>
<view class="col col-stat"><text>{{ item.task_total }}</text></view>
<view class="col col-stat"><text>{{ item.task_finish }}</text></view>
<view class="col col-status">
<switch :checked="item.show" color="#1890ff" scale="0.8" />
<switch :checked="item.is_visible" color="#1890ff" scale="0.8" @change="() => onToggleVisible(item)" />
</view>
<view class="col col-ops">
<text class="op-link">等级任务</text>
<text class="op-divider">|</text>
<text class="op-link">编辑</text>
<text class="op-link" @click="openEditModal(item)">编辑</text>
<text class="op-divider">|</text>
<text class="op-link">删除</text>
<text class="op-link" @click="onDelete(item.id)">删除</text>
</view>
</view>
</view>
@@ -61,15 +61,171 @@
<text class="page-info">共 {{ levelList.length }} 条</text>
</view>
</view>
<view v-if="editPopupVisible" class="popup-mask" @click="closeEditModal">
<view class="popup-card" @click.stop>
<view class="popup-header">
<text class="popup-title">{{ editForm.id == null ? '添加分销等级' : '编辑分销等级' }}</text>
<text class="popup-close" @click="closeEditModal">×</text>
</view>
<view class="popup-body">
<view class="popup-item">
<text class="popup-label">等级名称</text>
<input v-model="editForm.name" class="popup-input" placeholder="如:一级分销员" />
</view>
<view class="popup-item">
<text class="popup-label">等级权重</text>
<input v-model="editForm.level" type="number" class="popup-input" placeholder="如1" />
</view>
<view class="popup-item">
<text class="popup-label">一级分佣比例 (%)</text>
<input v-model="editForm.percent1" type="digit" class="popup-input" placeholder="0 - 100" />
</view>
<view class="popup-item">
<text class="popup-label">二级分佣比例 (%)</text>
<input v-model="editForm.percent2" type="digit" class="popup-input" placeholder="0 - 100" />
</view>
<view class="popup-item">
<text class="popup-label">任务总数</text>
<input v-model="editForm.task_total" type="number" class="popup-input" placeholder="如0" />
</view>
<view class="popup-item">
<text class="popup-label">需完成数量</text>
<input v-model="editForm.task_finish" type="number" class="popup-input" placeholder="如0" />
</view>
<view class="popup-item popup-row">
<text class="popup-label">是否显示</text>
<switch :checked="!!editForm.is_visible" color="#1890ff" scale="0.8" @change="(e) => editForm.is_visible = e.detail.value" />
</view>
</view>
<view class="popup-footer">
<button class="btn" @click="closeEditModal">取消</button>
<button class="btn primary" @click="handleSave">保存</button>
</view>
</view>
</view>
</view>
</template>
<script setup lang="uts">
import { ref } from 'vue'
const levelList = ref([
{ id: '1', name: '一级分销员', level: 1, percent1: 0.00, percent2: 0.00, taskTotal: 0, taskFinish: 0, show: true },
])
function onSearch() { uni.showToast({ title: '查询中...', icon: 'none' }) }
function onAdd() { uni.showToast({ title: '添加中...', icon: 'none' }) }
import { ref, onMounted, reactive } from 'vue'
import { getDistributionLevelList, saveDistributionLevel, deleteDistributionLevel, DistributionLevel } from '@/services/admin/distributionService.uts'
const levelList = ref<DistributionLevel[]>([])
const isLoading = ref(false)
const editPopupVisible = ref(false)
const editForm = reactive<DistributionLevel>({
id: undefined,
name: '',
level: 1,
percent1: 0,
percent2: 0,
task_total: 0,
task_finish: 0,
is_visible: true
})
onMounted(() => {
loadLevels()
})
async function loadLevels() {
isLoading.value = true
try {
const res = await getDistributionLevelList()
levelList.value = res
} catch (e) {
uni.showToast({ title: '加载失败', icon: 'none' })
} finally {
isLoading.value = false
}
}
function onSearch() {
loadLevels()
}
function openEditModal(item: DistributionLevel | null) {
if (item != null) {
Object.assign(editForm, item)
} else {
Object.assign(editForm, {
id: undefined,
name: '',
level: levelList.value.length + 1,
percent1: 0,
percent2: 0,
task_total: 0,
task_finish: 0,
is_visible: true
})
}
editPopupVisible.value = true
}
function closeEditModal() {
editPopupVisible.value = false
}
async function handleSave() {
if (!editForm.name) {
uni.showToast({ title: '请输入等级名称', icon: 'none' })
return
}
isLoading.value = true
try {
const success = await saveDistributionLevel(editForm as DistributionLevel)
if (success) {
uni.showToast({ title: '保存成功', icon: 'success' })
closeEditModal()
loadLevels()
} else {
uni.showToast({ title: '保存失败', icon: 'none' })
}
} catch (e) {
uni.showToast({ title: '保存异常', icon: 'none' })
} finally {
isLoading.value = false
}
}
async function onDelete(id: string | undefined) {
if (id == null) return
uni.showModal({
title: '确认删除',
content: '确定要删除该分销等级吗?',
success: async (res) => {
if (res.confirm) {
isLoading.value = true
try {
const success = await deleteDistributionLevel(id)
if (success) {
uni.showToast({ title: '删除成功' })
loadLevels()
}
} finally {
isLoading.value = false
}
}
}
})
}
async function onToggleVisible(item: DistributionLevel) {
const updated = { ...item, is_visible: !item.is_visible } as DistributionLevel
const success = await saveDistributionLevel(updated)
if (success) {
loadLevels()
}
}
</script>
<style scoped lang="scss">
.admin-page { padding: 0; }
@@ -92,4 +248,97 @@ function onAdd() { uni.showToast({ title: '添加中...', icon: 'none' }) }
.op-divider { color: #e8e8e8; margin: 0 8px; }
.pagination { padding: 16px 24px; border-top: 1px solid #f0f0f0; }
.page-info { font-size: 14px; color: #999; }
/* 弹窗样式 */
.popup-mask {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: rgba(0, 0, 0, 0.5);
display: flex;
align-items: center;
justify-content: center;
z-index: 999;
}
.popup-card {
width: 500px;
background-color: #fff;
border-radius: 8px;
display: flex;
flex-direction: column;
overflow: hidden;
}
.popup-header {
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: center;
padding: 16px 20px;
border-bottom: 1px solid #f0f0f0;
}
.popup-title {
font-size: 16px;
font-weight: bold;
color: #333;
}
.popup-close {
font-size: 20px;
color: #999;
cursor: pointer;
padding: 4px;
}
.popup-body {
padding: 24px;
display: flex;
flex-direction: column;
gap: 16px;
}
.popup-item {
display: flex;
flex-direction: column;
gap: 8px;
}
.popup-row {
flex-direction: row;
align-items: center;
justify-content: space-between;
}
.popup-label {
font-size: 14px;
color: #666;
}
.popup-input {
border: 1px solid #d9d9d9;
border-radius: 4px;
height: 36px;
padding: 0 12px;
font-size: 14px;
width: 100%;
}
.popup-footer {
padding: 16px 24px;
border-top: 1px solid #f0f0f0;
display: flex;
flex-direction: row;
justify-content: flex-end;
gap: 12px;
}
.btn.ghost {
background-color: #fff;
color: #666;
border: 1px solid #d9d9d9;
}
</style>

View File

@@ -4,10 +4,12 @@
<view class="filter-row">
<view class="filter-item">
<text class="label">时间选择:</text>
<view class="date-picker-mock">
<text class="placeholder">开始日期 - 结束日期</text>
<text class="icon-calendar">📅</text>
</view>
<AnalyticsDateRangePicker
:initialStartDate="startDate"
:initialEndDate="endDate"
@apply="onApplyRange"
@clear="onClearRange"
/>
</view>
<view class="filter-item">
<text class="label">搜索:</text>
@@ -23,6 +25,11 @@
<button class="btn ghost small" @click="onExport">导出</button>
</view>
<view class="table-container">
<!-- Loading 遮罩 -->
<view v-if="isLoading" class="loading-mask">
<text class="loading-text">数据加载中...</text>
</view>
<view class="table-header">
<view class="col col-id"><text>ID</text></view>
<view class="col col-img"><text>头像</text></view>
@@ -38,16 +45,19 @@
<view class="col col-ops"><text>操作</text></view>
</view>
<view class="table-body">
<view v-if="promoterList.length === 0 && !isLoading" class="empty-row">
<text>暂无数据</text>
</view>
<view v-for="item in promoterList" :key="item.id" class="table-row">
<view class="col col-id"><text>{{ item.id }}</text></view>
<view class="col col-img">
<image class="table-img" src="/static/logo.png" mode="aspectFill" />
<image class="table-img" :src="item.avatar_url || '/static/logo.png'" mode="aspectFill" />
</view>
<view class="col col-info">
<view class="user-info-box">
<text class="info-text">昵称:{{ item.nickname }}</text>
<text class="info-text">姓名:{{ item.name }}</text>
<text class="info-text">电话:{{ item.phone }}</text>
<text class="info-text">姓名:{{ item.name || '-' }}</text>
<text class="info-text">电话:{{ item.phone || '-' }}</text>
</view>
</view>
<view class="col col-level"><text>{{ item.level }}</text></view>
@@ -68,21 +78,88 @@
</view>
</view>
<view class="pagination">
<text class="page-info">共 {{ promoterList.length }} 条</text>
<view class="pager-btns">
<button class="btn small" :disabled="page <= 1" @click="onPrevPage">上一页</button>
<text class="page-num">第 {{ page }} 页</text>
<button class="btn small" :disabled="promoterList.length < pageSize" @click="onNextPage">下一页</button>
</view>
<text class="page-info">当前页数据 {{ promoterList.length }} 条</text>
</view>
</view>
</view>
</template>
<script setup lang="uts">
import { ref } from 'vue'
const promoterList = ref([
{ id: '82764', nickname: '183****5762', name: '-', phone: '183****5762', level: '--', userCount: 0, orderCount: 0, orderAmount: '0.00', commissionTotal: '0.00', withdrawnAmount: 0, withdrawCount: 0, unwithdrawnAmount: 0 },
])
function onSearch() { uni.showToast({ title: '查询中...', icon: 'none' }) }
function onExport() { uni.showToast({ title: '开始导出', icon: 'none' }) }
function onPromoter(item: any) { uni.showToast({ title: '推广人: ' + item.id, icon: 'none' }) }
function onMore(item: any) { uni.showToast({ title: '更多: ' + item.id, icon: 'none' }) }
import { ref, onMounted } from 'vue'
import AnalyticsDateRangePicker from '@/components/analytics/AnalyticsDateRangePicker.uvue'
import { getPromoterList, Promoter, PromoterListParams } from '@/services/admin/distributionService.uts'
const promoterList = ref<Promoter[]>([])
const isLoading = ref(false)
const searchQuery = ref('')
const page = ref(1)
const pageSize = 20
const startDate = ref<string>('')
const endDate = ref<string>('')
onMounted(() => {
loadPromoters()
})
async function loadPromoters() {
isLoading.value = true
try {
const params: PromoterListParams = {
search: searchQuery.value,
page: page.value,
pageSize: pageSize,
startTime: startDate.value ? (startDate.value + ' 00:00:00') : null,
endTime: endDate.value ? (endDate.value + ' 23:59:59') : null
}
const res = await getPromoterList(params)
promoterList.value = res
} catch (e) {
uni.showToast({ title: '加载推广员失败', icon: 'none' })
} finally {
isLoading.value = false
}
}
function onSearch() {
page.value = 1
loadPromoters()
}
function onApplyRange(payload: any) {
startDate.value = payload?.start ?? ''
endDate.value = payload?.end ?? ''
page.value = 1
loadPromoters()
}
function onClearRange() {
startDate.value = ''
endDate.value = ''
page.value = 1
loadPromoters()
}
function onNextPage() {
if (promoterList.value.length < pageSize) return
page.value++
loadPromoters()
}
function onPrevPage() {
if (page.value <= 1) return
page.value--
loadPromoters()
}
function onExport() { uni.showToast({ title: '导出功能开发中', icon: 'none' }) }
function onPromoter(item : Promoter) { uni.showToast({ title: '推广人: ' + item.id, icon: 'none' }) }
function onMore(item : Promoter) { uni.showToast({ title: '更多: ' + item.id, icon: 'none' }) }
</script>
<style scoped lang="scss">
@@ -109,6 +186,26 @@ function onMore(item: any) { uni.showToast({ title: '更多: ' + item.id, icon:
.op-link { color: #1890ff; cursor: pointer; }
.op-divider { color: #e8e8e8; margin: 0 8px; }
.arrow-down { font-size: 10px; color: #1890ff; margin-left: 4px; }
.pagination { padding: 16px 24px; border-top: 1px solid #f0f0f0; }
.pagination { padding: 16px 24px; border-top: 1px solid #f0f0f0; display: flex; flex-direction: row; align-items: center; justify-content: space-between; }
.pager-btns { display: flex; flex-direction: row; align-items: center; gap: 12px; }
.page-num { font-size: 14px; color: #333; }
.page-info { font-size: 14px; color: #999; }
/* Loading & Empty Styles */
.loading-mask {
position: absolute;
top: 0; left: 0; right: 0; bottom: 0;
background-color: rgba(255, 255, 255, 0.7);
display: flex;
align-items: center;
justify-content: center;
z-index: 10;
}
.loading-text { color: #1890ff; font-size: 14px; }
.empty-row {
padding: 40px 0;
text-align: center;
color: #999;
font-size: 14px;
}
</style>

View File

@@ -301,10 +301,12 @@
</template>
<script setup lang="uts">
import { ref } from 'vue'
import { ref, onMounted } from 'vue'
import { getDistributionConfig, saveDistributionConfig, DistributionConfig } from '@/services/admin/distributionService.uts'
const activeTab = ref(0)
const tabs = ['分销模式', '返佣设置', '提现设置']
const isLoading = ref(false)
const form = ref({
// 分销模式
@@ -338,6 +340,50 @@ const form = ref({
user_extract_fee: '0'
})
onMounted(() => {
loadConfig()
})
async function loadConfig() {
isLoading.value = true
try {
const res = await getDistributionConfig()
if (res != null) {
// 映射 DB 类型 (boolean/number) 到页面字符串类型 ('1'/'0')
form.value.statue = res.is_enabled ? '1' : '0'
form.value.extract_type = res.extract_type
form.value.bind_type = res.bind_type
form.value.store_brokerage_binding_status = res.store_brokerage_binding_status
form.value.brokerage_poster_status = res.brokerage_poster_status ?? ''
form.value.brokerage_level = String(res.brokerage_level)
form.value.is_area_manager = res.is_area_manager ? '1' : '0'
form.value.is_agent_apply = res.is_agent_apply ? '1' : '0'
form.value.is_commission_window = res.is_commission_window ? '1' : '0'
form.value.is_self_brokerage = res.is_self_brokerage ? '1' : '0'
form.value.is_member_brokerage = res.is_member_brokerage ? '1' : '0'
form.value.brokerage_type = res.brokerage_type
form.value.is_promoter_brokerage = res.is_promoter_brokerage ? '1' : '0'
form.value.promoter_brokerage_price = String(res.promoter_brokerage_price)
form.value.promoter_brokerage_day_max = String(res.promoter_brokerage_day_max)
form.value.store_brokerage_ratio = String(res.store_brokerage_ratio)
form.value.store_brokerage_two_ratio = String(res.store_brokerage_two_ratio)
form.value.extract_frozen_time = String(res.extract_frozen_time)
form.value.user_extract_min_price = String(res.user_extract_min_price)
form.value.extract_bank_list = res.extract_bank_list
form.value.extract_type_list = res.extract_type_list
form.value.wechat_extract_type = res.wechat_extract_type
form.value.alipay_extract_type = res.alipay_extract_type
form.value.user_extract_fee = String(res.user_extract_fee)
}
} catch (e) {
uni.showToast({ title: '加载配置失败', icon: 'none' })
} finally {
isLoading.value = false
}
}
function onUploadPoster() {
uni.chooseImage({
count: 1,
@@ -347,8 +393,50 @@ function onUploadPoster() {
})
}
function onSubmit() {
async function onSubmit() {
isLoading.value = true
try {
// 映射页面字符串类型到 DB 类型
const config: DistributionConfig = {
is_enabled: form.value.statue === '1',
extract_type: form.value.extract_type,
bind_type: form.value.bind_type,
store_brokerage_binding_status: form.value.store_brokerage_binding_status,
brokerage_poster_status: form.value.brokerage_poster_status,
brokerage_level: parseInt(form.value.brokerage_level),
is_area_manager: form.value.is_area_manager === '1',
is_agent_apply: form.value.is_agent_apply === '1',
is_commission_window: form.value.is_commission_window === '1',
is_self_brokerage: form.value.is_self_brokerage === '1',
is_member_brokerage: form.value.is_member_brokerage === '1',
brokerage_type: form.value.brokerage_type,
is_promoter_brokerage: form.value.is_promoter_brokerage === '1',
promoter_brokerage_price: parseFloat(form.value.promoter_brokerage_price),
promoter_brokerage_day_max: parseFloat(form.value.promoter_brokerage_day_max),
store_brokerage_ratio: parseFloat(form.value.store_brokerage_ratio),
store_brokerage_two_ratio: parseFloat(form.value.store_brokerage_two_ratio),
extract_frozen_time: parseInt(form.value.extract_frozen_time),
user_extract_min_price: parseFloat(form.value.user_extract_min_price),
extract_bank_list: form.value.extract_bank_list,
extract_type_list: form.value.extract_type_list,
wechat_extract_type: form.value.wechat_extract_type,
alipay_extract_type: form.value.alipay_extract_type,
user_extract_fee: parseFloat(form.value.user_extract_fee)
}
const success = await saveDistributionConfig(config)
if (success) {
uni.showToast({ title: '保存成功', icon: 'success' })
} else {
uni.showToast({ title: '保存失败', icon: 'none' })
}
} catch (e) {
uni.showToast({ title: '操作异常', icon: 'none' })
} finally {
isLoading.value = false
}
}
</script>