feat(admin): complete integration of auth, delivery, and system infrastructure modules
This commit is contained in:
@@ -6,157 +6,253 @@
|
||||
</view>
|
||||
|
||||
<!-- 表格区域 -->
|
||||
<view class="table-wrap">
|
||||
<view class="table-wrap border-shadow">
|
||||
<view class="table-header">
|
||||
<view class="th" style="flex: 1;">ID</view>
|
||||
<view class="th" style="flex: 1;">序号</view>
|
||||
<view class="th" style="flex: 1.5;">头像</view>
|
||||
<view class="th" style="flex: 2;">名称</view>
|
||||
<view class="th" style="flex: 2.5;">手机号码</view>
|
||||
<view class="th" style="flex: 1.5;">是否显示</view>
|
||||
<view class="th" style="flex: 1.5;">状态</view>
|
||||
<view class="th" style="flex: 3;">添加时间</view>
|
||||
<view class="th" style="flex: 2;">操作</view>
|
||||
</view>
|
||||
<view class="table-body">
|
||||
<view v-for="item in courierList" :key="item.id" class="tr">
|
||||
<view class="td" style="flex: 1;">{{ item.id }}</view>
|
||||
<view v-if="loading" class="loading-box">
|
||||
<text>加载中...</text>
|
||||
</view>
|
||||
<view v-else-if="staffList.length === 0" class="no-data">
|
||||
<text class="no-data-text">暂无配送员数据</text>
|
||||
</view>
|
||||
<view v-else v-for="(item, index) in staffList" :key="item.id" class="tr">
|
||||
<view class="td" style="flex: 1;"><text class="td-txt">{{ (page - 1) * pageSize + index + 1 }}</text></view>
|
||||
<view class="td" style="flex: 1.5;">
|
||||
<image class="avatar" :src="item.avatar" mode="aspectFill" />
|
||||
<image v-if="item.avatar" class="avatar" :src="item.avatar" mode="aspectFill" />
|
||||
<view v-else class="avatar-placeholder"><text>👤</text></view>
|
||||
</view>
|
||||
<view class="td" style="flex: 2;">{{ item.name }}</view>
|
||||
<view class="td" style="flex: 2.5;">{{ item.phone }}</view>
|
||||
<view class="td" style="flex: 2;"><text class="td-txt">{{ item.nickname }}</text></view>
|
||||
<view class="td" style="flex: 2.5;"><text class="td-txt">{{ item.phone }}</text></view>
|
||||
<view class="td" style="flex: 1.5;">
|
||||
<switch :checked="item.isshow" color="#1890ff" @change="onToggleShow(item)" />
|
||||
<switch :checked="item.status === 1" color="#1890ff" scale="0.7" @change="onToggleStatus(item)" />
|
||||
</view>
|
||||
<view class="td" style="flex: 3;">{{ item.addTime }}</view>
|
||||
<view class="td" style="flex: 3;"><text class="td-txt-small">{{ formatTime(item.created_at) }}</text></view>
|
||||
<view class="td" style="flex: 2;">
|
||||
<text class="action-btn" @click="onEdit(item)">编辑</text>
|
||||
<text class="action-btn-del" @click="onDel(item)">删除</text>
|
||||
<view class="divider"></view>
|
||||
<text class="action-btn danger" @click="onDelete(item)">删除</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 分页栏 -->
|
||||
<view class="pagination-footer">
|
||||
<text class="total-txt">共 {{ total }} 条</text>
|
||||
<view class="page-btns">
|
||||
<text :class="['p-btn', page <= 1 ? 'disabled' : '']" @click="prevPage"> < </text>
|
||||
<text class="p-btn active">{{ page }}</text>
|
||||
<text :class="['p-btn', staffList.length < pageSize ? 'disabled' : '']" @click="nextPage"> > </text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 添加/编辑 弹窗 -->
|
||||
<view v-if="showModal" class="modal-overlay" @click="closeModal">
|
||||
<view class="modal-card" @click.stop>
|
||||
<view class="modal-header">
|
||||
<text class="modal-title">{{ isEdit ? '编辑配送员' : '添加配送员' }}</text>
|
||||
<text class="close-btn" @click="closeModal">×</text>
|
||||
</view>
|
||||
<view class="modal-body">
|
||||
<view class="form-item">
|
||||
<text class="f-label">名称:</text>
|
||||
<input class="f-input" v-model="form.nickname" placeholder="请输入名称" />
|
||||
</view>
|
||||
<view class="form-item">
|
||||
<text class="f-label">手机号:</text>
|
||||
<input class="f-input" v-model="form.phone" type="number" placeholder="请输入手机号" />
|
||||
</view>
|
||||
<view class="form-item">
|
||||
<text class="f-label">头像:</text>
|
||||
<view class="upload-placeholder" @click="handleUpload">
|
||||
<image v-if="form.avatar" :src="form.avatar" mode="aspectFill" class="avatar-preview" />
|
||||
<text v-else>+</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<view class="modal-footer">
|
||||
<button class="btn" @click="closeModal">取消</button>
|
||||
<button class="btn btn-primary" @click="handleSave">保存</button>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script setup lang="uts">
|
||||
import { ref, reactive } from 'vue'
|
||||
import { ref, reactive, onMounted } from 'vue'
|
||||
import { fetchDeliveryStaffPage, saveDeliveryStaff, deleteDeliveryStaff, type DeliveryStaff } from '@/services/admin/deliveryService.uts'
|
||||
|
||||
type CourierItem = {
|
||||
id: number
|
||||
avatar: string
|
||||
name: string
|
||||
phone: string
|
||||
isshow: boolean
|
||||
addTime: string
|
||||
const staffList = ref<DeliveryStaff[]>([])
|
||||
const loading = ref(false)
|
||||
const total = ref(0)
|
||||
const page = ref(1)
|
||||
const pageSize = 15
|
||||
|
||||
// Modal state
|
||||
const showModal = ref(false)
|
||||
const isEdit = ref(false)
|
||||
const form = reactive({
|
||||
id: '' as string | null,
|
||||
nickname: '',
|
||||
phone: '',
|
||||
avatar: '',
|
||||
status: 1
|
||||
})
|
||||
|
||||
onMounted(() => {
|
||||
loadData()
|
||||
})
|
||||
|
||||
async function loadData() {
|
||||
loading.value = true
|
||||
try {
|
||||
const res = await fetchDeliveryStaffPage(page.value, pageSize)
|
||||
staffList.value = res.items
|
||||
total.value = res.total
|
||||
} catch (e) {
|
||||
uni.showToast({ title: '加载失败', icon: 'none' })
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const courierList = reactive<CourierItem[]>([
|
||||
{ id: 106, avatar: '/static/logo.png', name: 'cheshi', phone: '18943652356', isshow: true, addTime: '2025-06-29 21:45:19' },
|
||||
{ id: 105, avatar: '/static/logo.png', name: 'dl', phone: '15648569914', isshow: true, addTime: '2025-06-28 18:40:26' },
|
||||
{ id: 102, avatar: '/static/logo.png', name: '小牛马', phone: '13548652258', isshow: true, addTime: '2025-06-26 15:14:40' }
|
||||
])
|
||||
|
||||
function onAdd() {
|
||||
console.log('Add courier')
|
||||
isEdit.value = false
|
||||
form.id = null
|
||||
form.nickname = ''
|
||||
form.phone = ''
|
||||
form.avatar = ''
|
||||
form.status = 1
|
||||
showModal.value = true
|
||||
}
|
||||
|
||||
function onToggleShow(item: CourierItem) {
|
||||
item.isshow = !item.isshow
|
||||
function onEdit(item : DeliveryStaff) {
|
||||
isEdit.value = true
|
||||
form.id = item.id
|
||||
form.nickname = item.nickname
|
||||
form.phone = item.phone
|
||||
form.avatar = item.avatar || ''
|
||||
form.status = item.status
|
||||
showModal.value = true
|
||||
}
|
||||
|
||||
function onEdit(item: CourierItem) {
|
||||
console.log('Edit:', item.name)
|
||||
function closeModal() {
|
||||
showModal.value = false
|
||||
}
|
||||
|
||||
function onDel(item: CourierItem) {
|
||||
console.log('Delete:', item.id)
|
||||
async function handleSave() {
|
||||
if (!form.nickname || !form.phone) {
|
||||
uni.showToast({ title: '请填写姓名和手机号', icon: 'none' })
|
||||
return
|
||||
}
|
||||
|
||||
loading.value = true
|
||||
try {
|
||||
const resId = await saveDeliveryStaff(form)
|
||||
if (resId != null) {
|
||||
uni.showToast({ title: '保存成功' })
|
||||
closeModal()
|
||||
loadData()
|
||||
}
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function onDelete(item : DeliveryStaff) {
|
||||
uni.showModal({
|
||||
title: '提示',
|
||||
content: `确定要删除配送员 "${item.nickname}" 吗?`,
|
||||
success: async (res) => {
|
||||
if (res.confirm) {
|
||||
const ok = await deleteDeliveryStaff(item.id)
|
||||
if (ok) {
|
||||
uni.showToast({ title: '删除成功' })
|
||||
loadData()
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
async function onToggleStatus(item : DeliveryStaff) {
|
||||
const nextStatus = item.status === 1 ? 0 : 1
|
||||
const ok = await saveDeliveryStaff({ ...item, status: nextStatus })
|
||||
if (ok != null) {
|
||||
item.status = nextStatus
|
||||
uni.showToast({ title: '状态已更新' })
|
||||
}
|
||||
}
|
||||
|
||||
function prevPage() { if (page.value > 1) { page.value--; loadData(); } }
|
||||
function nextPage() { if (staffList.value.length >= pageSize) { page.value++; loadData(); } }
|
||||
|
||||
function formatTime(iso : string | null) : string {
|
||||
if (!iso) return '-'
|
||||
return iso.substring(0, 16).replace('T', ' ')
|
||||
}
|
||||
|
||||
function handleUpload() {
|
||||
uni.showToast({ title: '上传功能开发中', icon: 'none' })
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.admin-page-container {
|
||||
padding: 15px;
|
||||
background-color: #f5f7f9;
|
||||
min-height: 100vh;
|
||||
}
|
||||
<style scoped lang="scss">
|
||||
.admin-page-container { padding: 24px; background-color: #f5f7f9; min-height: 100vh; }
|
||||
.page-card { background-color: #fff; border-radius: 4px; padding: 24px; }
|
||||
|
||||
.page-card {
|
||||
background-color: #fff;
|
||||
border-radius: 4px;
|
||||
padding: 20px;
|
||||
}
|
||||
.action-wrap { margin-bottom: 24px; }
|
||||
.btn { height: 32px; padding: 0 20px; border-radius: 4px; border: none; cursor: pointer; display: flex; align-items: center; justify-content: center; font-size: 14px; }
|
||||
.btn-primary { background-color: #1890ff; color: #fff; }
|
||||
|
||||
.action-wrap {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
.table-wrap { border: 1px solid #f0f0f0; border-radius: 4px; }
|
||||
.table-header { display: flex; flex-direction: row; background-color: #f8f8f9; }
|
||||
.th { padding: 12px 10px; font-size: 14px; font-weight: bold; color: #515a6e; border-bottom: 1px solid #f0f0f0; text-align: center; }
|
||||
.tr { display: flex; flex-direction: row; border-bottom: 1px solid #f0f0f0; min-height: 60px; align-items: center; }
|
||||
.td { padding: 10px; display: flex; align-items: center; justify-content: center; }
|
||||
.td-txt { font-size: 13px; color: #606266; }
|
||||
.td-txt-small { font-size: 12px; color: #999; }
|
||||
|
||||
.btn {
|
||||
height: 32px;
|
||||
line-height: 30px;
|
||||
padding: 0 15px;
|
||||
font-size: 14px;
|
||||
border-radius: 4px;
|
||||
border: none;
|
||||
}
|
||||
.avatar { width: 40px; height: 40px; border-radius: 4px; }
|
||||
.avatar-placeholder { width: 40px; height: 40px; border-radius: 4px; background-color: #f0f0f0; display: flex; align-items: center; justify-content: center; font-size: 20px; }
|
||||
|
||||
.btn-primary {
|
||||
background-color: #1890ff;
|
||||
color: #fff;
|
||||
}
|
||||
.action-btn { color: #1890ff; font-size: 13px; cursor: pointer; }
|
||||
.danger { color: #ff4d4f; }
|
||||
.divider { width: 1px; height: 12px; background-color: #e8e8e8; margin: 0 8px; }
|
||||
|
||||
.table-wrap {
|
||||
width: 100%;
|
||||
border: 1px solid #f0f0f0;
|
||||
}
|
||||
.no-data, .loading-box { padding: 60px 0; text-align: center; width: 100%; }
|
||||
.no-data-text { font-size: 14px; color: #ccc; }
|
||||
|
||||
.table-header {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
background-color: #f8f8f9;
|
||||
}
|
||||
.pagination-footer { margin-top: 24px; display: flex; flex-direction: row; align-items: center; justify-content: flex-end; gap: 12px; }
|
||||
.total-txt { font-size: 13px; color: #999; }
|
||||
.page-btns { display: flex; flex-direction: row; gap: 8px; }
|
||||
.p-btn { width: 30px; height: 30px; border: 1px solid #dcdee2; display: flex; align-items: center; justify-content: center; border-radius: 4px; cursor: pointer; font-size: 13px; }
|
||||
.p-btn.active { background-color: #1890ff; color: #fff; border-color: #1890ff; }
|
||||
.p-btn.disabled { opacity: 0.5; cursor: not-allowed; }
|
||||
|
||||
.th {
|
||||
padding: 12px 10px;
|
||||
font-size: 14px;
|
||||
font-weight: bold;
|
||||
color: #515a6e;
|
||||
border-bottom: 1px solid #f0f0f0;
|
||||
text-align: center;
|
||||
}
|
||||
/* Modal */
|
||||
.modal-overlay { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background-color: rgba(0,0,0,0.5); z-index: 1000; display: flex; align-items: center; justify-content: center; }
|
||||
.modal-card { width: 450px; background-color: #fff; border-radius: 8px; overflow: hidden; }
|
||||
.modal-header { padding: 16px 20px; border-bottom: 1px solid #f0f0f0; display: flex; flex-direction: row; justify-content: space-between; align-items: center; }
|
||||
.modal-title { font-size: 16px; font-weight: bold; color: #333; }
|
||||
.close-btn { font-size: 24px; color: #999; cursor: pointer; }
|
||||
.modal-body { padding: 24px; }
|
||||
.form-item { margin-bottom: 20px; display: flex; flex-direction: row; align-items: center; }
|
||||
.f-label { width: 80px; font-size: 14px; color: #666; text-align: right; margin-right: 15px; }
|
||||
.f-input { flex: 1; border: 1px solid #dcdfe6; height: 36px; padding: 0 12px; border-radius: 4px; font-size: 14px; }
|
||||
|
||||
.tr {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
border-bottom: 1px solid #f0f0f0;
|
||||
}
|
||||
.upload-placeholder { width: 64px; height: 64px; border: 1px dashed #dcdfe6; border-radius: 4px; display: flex; align-items: center; justify-content: center; font-size: 24px; color: #ccc; cursor: pointer; }
|
||||
.avatar-preview { width: 100%; height: 100%; border-radius: 4px; }
|
||||
|
||||
.td {
|
||||
padding: 12px 10px;
|
||||
font-size: 14px;
|
||||
color: #515a6e;
|
||||
text-align: center;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.avatar {
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
.action-btn {
|
||||
color: #1890ff;
|
||||
font-size: 13px;
|
||||
margin-right: 10px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.action-btn-del {
|
||||
color: #ed4014;
|
||||
font-size: 13px;
|
||||
cursor: pointer;
|
||||
}
|
||||
.modal-footer { padding: 16px 24px; border-top: 1px solid #f0f0f0; display: flex; flex-direction: row; justify-content: flex-end; gap: 12px; }
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user