feat(admin): implement user level, group and label modules with database, rpc and ui
This commit is contained in:
@@ -3,7 +3,12 @@
|
||||
<view class="content-card">
|
||||
<!-- 操作按钮行 -->
|
||||
<view class="action-bar">
|
||||
<view class="filter-item">
|
||||
<input class="filter-input" v-model="searchText" placeholder="搜索分组名称/备注" @confirm="handleSearch" />
|
||||
</view>
|
||||
<button class="btn primary small" @click="onAddGroup">添加分组</button>
|
||||
<button class="btn ghost small" @click="handleSearch">查询</button>
|
||||
<button class="btn ghost small" @click="handleReset">重置</button>
|
||||
</view>
|
||||
|
||||
<!-- 分组列表表格 -->
|
||||
@@ -11,19 +16,29 @@
|
||||
<!-- 表头 -->
|
||||
<view class="table-header">
|
||||
<view class="col col-id"><text>ID</text></view>
|
||||
<view class="col col-name"><text>分组</text></view>
|
||||
<view class="col col-name"><text>分组名称</text></view>
|
||||
<view class="col col-remark"><text>备注</text></view>
|
||||
<view class="col col-status"><text>状态</text></view>
|
||||
<view class="col col-ops"><text>操作</text></view>
|
||||
</view>
|
||||
|
||||
<!-- 表格内容 -->
|
||||
<view class="table-body">
|
||||
<view v-for="group in groupList" :key="group.id" class="table-row">
|
||||
<view v-if="loading" class="table-loading"><text>加载中...</text></view>
|
||||
<view v-else-if="groupList.length === 0" class="table-empty"><text>暂无数据</text></view>
|
||||
<view v-else v-for="(group, index) in groupList" :key="group.id" class="table-row">
|
||||
<view class="col col-id"><text>{{ group.id }}</text></view>
|
||||
<view class="col col-name"><text>{{ group.name }}</text></view>
|
||||
<view class="col col-remark"><text>{{ group.remark || '-' }}</text></view>
|
||||
<view class="col col-status">
|
||||
<view :class="['switch-box', group.status === 1 ? 'active' : '']" @click="onToggleStatus(index)">
|
||||
<view class="switch-dot"></view>
|
||||
</view>
|
||||
</view>
|
||||
<view class="col col-ops">
|
||||
<text class="op-link" @click="onEditGroup(group)">修改</text>
|
||||
<view class="op-divider">|</view>
|
||||
<text class="op-link" @click="onDeleteGroup(group)">删除</text>
|
||||
<text class="op-link text-danger" @click="onDeleteGroup(group.id)">删除</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
@@ -31,19 +46,15 @@
|
||||
|
||||
<!-- 分页区域 -->
|
||||
<view class="pagination-row">
|
||||
<text class="total-text">共 {{ groupList.length }} 条</text>
|
||||
<view class="page-size-selector">
|
||||
<text>15条/页</text>
|
||||
<text class="arrow">▼</text>
|
||||
</view>
|
||||
<text class="total-text">共 {{ total }} 条</text>
|
||||
<view class="page-btns">
|
||||
<view class="page-btn disabled"><text>‹</text></view>
|
||||
<view class="page-btn active"><text>1</text></view>
|
||||
<view class="page-btn disabled"><text>›</text></view>
|
||||
<view :class="['page-btn', page <= 1 ? 'disabled' : '']" @click="prevPage"><text>‹</text></view>
|
||||
<view class="page-btn active"><text>{{ page }}</text></view>
|
||||
<view :class="['page-btn', page >= totalPages ? 'disabled' : '']" @click="nextPage"><text>›</text></view>
|
||||
</view>
|
||||
<view class="page-jump">
|
||||
<text>前往</text>
|
||||
<input class="jump-input" value="1" />
|
||||
<input class="jump-input" v-model="jumpPage" @confirm="goToJumpPage" />
|
||||
<text>页</text>
|
||||
</view>
|
||||
</view>
|
||||
@@ -66,9 +77,26 @@
|
||||
class="form-input"
|
||||
v-model="formData.name"
|
||||
placeholder="请输入分组名称"
|
||||
autofocus
|
||||
/>
|
||||
</view>
|
||||
<view class="form-item" style="margin-top: 20px;">
|
||||
<view class="label-box">
|
||||
<text class="label">备注说明:</text>
|
||||
</view>
|
||||
<textarea
|
||||
class="form-textarea"
|
||||
v-model="formData.remark"
|
||||
placeholder="请输入备注说明"
|
||||
/>
|
||||
</view>
|
||||
<view class="form-item" style="margin-top: 20px;">
|
||||
<view class="label-box">
|
||||
<text class="label">状态:</text>
|
||||
</view>
|
||||
<view :class="['switch-box', formData.status === 1 ? 'active' : '']" @click="formData.status = (formData.status === 1 ? 0 : 1)">
|
||||
<view class="switch-dot"></view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<view class="modal-footer">
|
||||
<button class="btn ghost" @click="closeModal">取消</button>
|
||||
@@ -80,15 +108,51 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="uts">
|
||||
import { ref, reactive, computed } from 'vue'
|
||||
import { ref, reactive, computed, onMounted } from 'vue'
|
||||
import {
|
||||
fetchAdminUserGroupPage,
|
||||
saveAdminUserGroup,
|
||||
deleteAdminUserGroup,
|
||||
setAdminUserGroupStatus,
|
||||
type AdminUserGroup
|
||||
} from '@/services/admin/userGroupService.uts'
|
||||
|
||||
// 分组数据
|
||||
const groupList = ref([
|
||||
{ id: 251, name: 'A类客户' },
|
||||
{ id: 252, name: 'B类客户' },
|
||||
{ id: 253, name: 'C类客户' },
|
||||
{ id: 254, name: 'D类客户' }
|
||||
])
|
||||
const searchText = ref('')
|
||||
const total = ref(0)
|
||||
const groupList = ref<AdminUserGroup[]>([])
|
||||
const loading = ref(false)
|
||||
|
||||
const page = ref(1)
|
||||
const pageSize = ref(15)
|
||||
const jumpPage = ref('')
|
||||
|
||||
const totalPages = computed((): number => {
|
||||
if (pageSize.value <= 0) return 1
|
||||
const pages = Math.ceil(total.value / pageSize.value)
|
||||
return pages <= 0 ? 1 : pages
|
||||
})
|
||||
|
||||
const loadGroupList = async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
const res = await fetchAdminUserGroupPage(page.value, pageSize.value, {
|
||||
search: searchText.value || null,
|
||||
status: null,
|
||||
includeDeleted: false
|
||||
})
|
||||
|
||||
groupList.value = res.items
|
||||
total.value = res.total
|
||||
} catch (e) {
|
||||
uni.showToast({ title: '加载失败', icon: 'none' })
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
loadGroupList()
|
||||
})
|
||||
|
||||
// 弹窗状态
|
||||
const showModal = ref(false)
|
||||
@@ -97,35 +161,101 @@ const modalTitle = computed(() => isEdit.value ? '修改分组' : '添加分组'
|
||||
|
||||
// 表单数据
|
||||
const formData = reactive({
|
||||
id: 0,
|
||||
name: ''
|
||||
id: '',
|
||||
name: '',
|
||||
remark: '',
|
||||
status: 1
|
||||
})
|
||||
|
||||
// 搜索与重置
|
||||
function handleSearch() {
|
||||
page.value = 1
|
||||
loadGroupList()
|
||||
}
|
||||
|
||||
function handleReset() {
|
||||
searchText.value = ''
|
||||
page.value = 1
|
||||
loadGroupList()
|
||||
}
|
||||
|
||||
// 分页控制
|
||||
function prevPage() {
|
||||
if (page.value > 1) {
|
||||
page.value--
|
||||
loadGroupList()
|
||||
}
|
||||
}
|
||||
|
||||
function nextPage() {
|
||||
if (page.value < totalPages.value) {
|
||||
page.value++
|
||||
loadGroupList()
|
||||
}
|
||||
}
|
||||
|
||||
function goToJumpPage() {
|
||||
const targetPage = parseInt(jumpPage.value)
|
||||
if (!isNaN(targetPage) && targetPage >= 1 && targetPage <= totalPages.value) {
|
||||
page.value = targetPage
|
||||
loadGroupList()
|
||||
jumpPage.value = ''
|
||||
} else {
|
||||
uni.showToast({ title: '请输入有效的页码', icon: 'none' })
|
||||
}
|
||||
}
|
||||
|
||||
// 状态切换
|
||||
async function onToggleStatus(index: number) {
|
||||
const group = groupList.value[index]
|
||||
const targetStatus = group.status === 1 ? 0 : 1
|
||||
try {
|
||||
const ok = await setAdminUserGroupStatus(group.id, targetStatus)
|
||||
if (ok) {
|
||||
group.status = targetStatus
|
||||
uni.showToast({ title: '状态更新成功' })
|
||||
}
|
||||
} catch (e) {
|
||||
uni.showToast({ title: '状态更新失败', icon: 'none' })
|
||||
}
|
||||
}
|
||||
|
||||
// 添加分组
|
||||
function onAddGroup() {
|
||||
isEdit.value = false
|
||||
formData.id = 0
|
||||
formData.id = ''
|
||||
formData.name = ''
|
||||
formData.remark = ''
|
||||
formData.status = 1
|
||||
showModal.value = true
|
||||
}
|
||||
|
||||
// 修改分组
|
||||
function onEditGroup(group: any) {
|
||||
function onEditGroup(group: AdminUserGroup) {
|
||||
isEdit.value = true
|
||||
formData.id = group.id
|
||||
formData.name = group.name
|
||||
formData.remark = group.remark || ''
|
||||
formData.status = group.status
|
||||
showModal.value = true
|
||||
}
|
||||
|
||||
// 删除分组
|
||||
function onDeleteGroup(group: any) {
|
||||
function onDeleteGroup(id: string) {
|
||||
uni.showModal({
|
||||
title: '提示',
|
||||
content: '确定要删除该分组吗?',
|
||||
success: (res) => {
|
||||
success: async (res) => {
|
||||
if (res.confirm) {
|
||||
groupList.value = groupList.value.filter(item => item.id !== group.id)
|
||||
uni.showToast({ title: '删除成功', icon: 'success' })
|
||||
try {
|
||||
const ok = await deleteAdminUserGroup(id)
|
||||
if (ok) {
|
||||
uni.showToast({ title: '删除成功' })
|
||||
loadGroupList()
|
||||
}
|
||||
} catch (e) {
|
||||
uni.showToast({ title: '删除失败', icon: 'none' })
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -137,30 +267,28 @@ function closeModal() {
|
||||
}
|
||||
|
||||
// 提交表单
|
||||
function submitForm() {
|
||||
async function submitForm() {
|
||||
if (!formData.name) {
|
||||
uni.showToast({ title: '请输入分组名称', icon: 'none' })
|
||||
return
|
||||
}
|
||||
|
||||
if (isEdit.value) {
|
||||
// 模拟修改
|
||||
const index = groupList.value.findIndex(item => item.id === formData.id)
|
||||
if (index > -1) {
|
||||
groupList.value[index].name = formData.name
|
||||
}
|
||||
uni.showToast({ title: '修改成功', icon: 'success' })
|
||||
} else {
|
||||
// 模拟添加
|
||||
const newId = groupList.value.length > 0 ? Math.max(...groupList.value.map(g => g.id)) + 1 : 1
|
||||
groupList.value.push({
|
||||
id: newId,
|
||||
name: formData.name
|
||||
try {
|
||||
const resId = await saveAdminUserGroup({
|
||||
id: isEdit.value ? formData.id : null,
|
||||
name: formData.name,
|
||||
remark: formData.remark,
|
||||
status: formData.status
|
||||
})
|
||||
uni.showToast({ title: '添加成功', icon: 'success' })
|
||||
|
||||
if (resId != null) {
|
||||
uni.showToast({ title: isEdit.value ? '修改成功' : '添加成功' })
|
||||
closeModal()
|
||||
loadGroupList()
|
||||
}
|
||||
} catch (e) {
|
||||
uni.showToast({ title: '保存失败', icon: 'none' })
|
||||
}
|
||||
|
||||
closeModal()
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -181,6 +309,24 @@ function submitForm() {
|
||||
margin-bottom: 20px;
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.filter-item {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.filter-input {
|
||||
width: 200px;
|
||||
height: 32px;
|
||||
padding: 0 12px;
|
||||
border: 1px solid #d9d9d9;
|
||||
border-radius: 2px;
|
||||
font-size: 14px;
|
||||
background-color: #fff;
|
||||
}
|
||||
|
||||
/* 按钮样式 */
|
||||
@@ -274,6 +420,28 @@ function submitForm() {
|
||||
justify-content: flex-end;
|
||||
}
|
||||
|
||||
.col-remark {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.col-status {
|
||||
width: 120px;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.table-loading,
|
||||
.table-empty {
|
||||
padding: 24px;
|
||||
text-align: center;
|
||||
color: #999;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.text-danger {
|
||||
color: #ff4d4f;
|
||||
}
|
||||
|
||||
.op-link {
|
||||
color: #1890ff;
|
||||
cursor: pointer;
|
||||
@@ -291,6 +459,36 @@ function submitForm() {
|
||||
opacity: 0.5;
|
||||
}
|
||||
|
||||
/* Switch 开关 */
|
||||
.switch-box {
|
||||
width: 44px;
|
||||
height: 22px;
|
||||
background-color: #dcdfe6;
|
||||
border-radius: 11px;
|
||||
position: relative;
|
||||
transition: background-color 0.3s;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.switch-box.active {
|
||||
background-color: #1890ff;
|
||||
}
|
||||
|
||||
.switch-dot {
|
||||
width: 18px;
|
||||
height: 18px;
|
||||
background-color: #fff;
|
||||
border-radius: 9px;
|
||||
position: absolute;
|
||||
top: 2px;
|
||||
left: 2px;
|
||||
transition: transform 0.3s;
|
||||
}
|
||||
|
||||
.switch-box.active .switch-dot {
|
||||
transform: translateX(22px);
|
||||
}
|
||||
|
||||
/* 分页样式 */
|
||||
.pagination-row {
|
||||
margin-top: 24px;
|
||||
@@ -454,6 +652,20 @@ function submitForm() {
|
||||
}
|
||||
}
|
||||
|
||||
.form-textarea {
|
||||
flex: 1;
|
||||
height: 80px;
|
||||
padding: 4px 11px;
|
||||
border: 1px solid #d9d9d9;
|
||||
border-radius: 2px;
|
||||
font-size: 14px;
|
||||
|
||||
&:focus {
|
||||
border-color: #40a9ff;
|
||||
outline: none;
|
||||
}
|
||||
}
|
||||
|
||||
.modal-footer {
|
||||
padding: 10px 16px;
|
||||
border-top: 1px solid #f0f0f0;
|
||||
|
||||
@@ -1,9 +1,14 @@
|
||||
<template>
|
||||
<view class="user-label-page">
|
||||
<view class="content-card">
|
||||
<!-- 操作按钮行 -->
|
||||
<!-- 搜索与操作栏 -->
|
||||
<view class="action-bar">
|
||||
<view class="filter-item">
|
||||
<input class="filter-input" v-model="searchText" placeholder="搜索标签名称/备注" @confirm="handleSearch" />
|
||||
</view>
|
||||
<button class="btn primary small" @click="onAddLabel">添加标签</button>
|
||||
<button class="btn ghost small" @click="handleSearch">查询</button>
|
||||
<button class="btn ghost small" @click="handleReset">重置</button>
|
||||
</view>
|
||||
|
||||
<!-- 标签列表表格 -->
|
||||
@@ -12,18 +17,30 @@
|
||||
<view class="table-header">
|
||||
<view class="col col-id"><text>ID</text></view>
|
||||
<view class="col col-name"><text>标签名称</text></view>
|
||||
<view class="col col-remark"><text>备注</text></view>
|
||||
<view class="col col-status"><text>状态</text></view>
|
||||
<view class="col col-ops"><text>操作</text></view>
|
||||
</view>
|
||||
|
||||
<!-- 表格内容 -->
|
||||
<view class="table-body">
|
||||
<view v-for="label in labelList" :key="label.id" class="table-row">
|
||||
<view v-if="loading" class="table-loading"><text>加载中...</text></view>
|
||||
<view v-else-if="labelList.length === 0" class="table-empty"><text>暂无数据</text></view>
|
||||
<view v-else v-for="(label, index) in labelList" :key="label.id" class="table-row">
|
||||
<view class="col col-id"><text>{{ label.id }}</text></view>
|
||||
<view class="col col-name"><text>{{ label.name }}</text></view>
|
||||
<view class="col col-name">
|
||||
<text :style="{ color: label.color || '#666' }">{{ label.name }}</text>
|
||||
</view>
|
||||
<view class="col col-remark"><text>{{ label.remark || '-' }}</text></view>
|
||||
<view class="col col-status">
|
||||
<view :class="['switch-box', label.status === 1 ? 'active' : '']" @click="onToggleStatus(index)">
|
||||
<view class="switch-dot"></view>
|
||||
</view>
|
||||
</view>
|
||||
<view class="col col-ops">
|
||||
<text class="op-link" @click="onEditLabel(label)">修改</text>
|
||||
<view class="op-divider">|</view>
|
||||
<text class="op-link" @click="onDeleteLabel(label)">删除</text>
|
||||
<text class="op-link text-danger" @click="onDeleteLabel(label.id)">删除</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
@@ -31,19 +48,15 @@
|
||||
|
||||
<!-- 分页区域 -->
|
||||
<view class="pagination-row">
|
||||
<text class="total-text">共 {{ labelList.length }} 条</text>
|
||||
<view class="page-size-selector">
|
||||
<text>15条/页</text>
|
||||
<text class="arrow">▼</text>
|
||||
</view>
|
||||
<text class="total-text">共 {{ total }} 条</text>
|
||||
<view class="page-btns">
|
||||
<view class="page-btn disabled"><text>‹</text></view>
|
||||
<view class="page-btn active"><text>1</text></view>
|
||||
<view class="page-btn disabled"><text>›</text></view>
|
||||
<view :class="['page-btn', page <= 1 ? 'disabled' : '']" @click="prevPage"><text>‹</text></view>
|
||||
<view class="page-btn active"><text>{{ page }}</text></view>
|
||||
<view :class="['page-btn', page >= totalPages ? 'disabled' : '']" @click="nextPage"><text>›</text></view>
|
||||
</view>
|
||||
<view class="page-jump">
|
||||
<text>前往</text>
|
||||
<input class="jump-input" value="1" />
|
||||
<input class="jump-input" v-model="jumpPage" @confirm="goToJumpPage" />
|
||||
<text>页</text>
|
||||
</view>
|
||||
</view>
|
||||
@@ -66,9 +79,36 @@
|
||||
class="form-input"
|
||||
v-model="formData.name"
|
||||
placeholder="请输入标签名称"
|
||||
autofocus
|
||||
/>
|
||||
</view>
|
||||
<view class="form-item" style="margin-top: 20px;">
|
||||
<view class="label-box">
|
||||
<text class="label">标签颜色:</text>
|
||||
</view>
|
||||
<input
|
||||
class="form-input"
|
||||
v-model="formData.color"
|
||||
placeholder="例如: #1890ff"
|
||||
/>
|
||||
</view>
|
||||
<view class="form-item" style="margin-top: 20px;">
|
||||
<view class="label-box">
|
||||
<text class="label">备注说明:</text>
|
||||
</view>
|
||||
<textarea
|
||||
class="form-textarea"
|
||||
v-model="formData.remark"
|
||||
placeholder="请输入备注说明"
|
||||
/>
|
||||
</view>
|
||||
<view class="form-item" style="margin-top: 20px;">
|
||||
<view class="label-box">
|
||||
<text class="label">状态:</text>
|
||||
</view>
|
||||
<view :class="['switch-box', formData.status === 1 ? 'active' : '']" @click="formData.status = (formData.status === 1 ? 0 : 1)">
|
||||
<view class="switch-dot"></view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<view class="modal-footer">
|
||||
<button class="btn ghost" @click="closeModal">取消</button>
|
||||
@@ -80,15 +120,86 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="uts">
|
||||
import { ref, reactive, computed } from 'vue'
|
||||
import { ref, reactive, computed, onMounted } from 'vue'
|
||||
import {
|
||||
fetchAdminUserLabelPage,
|
||||
saveAdminUserLabel,
|
||||
deleteAdminUserLabel,
|
||||
setAdminUserLabelStatus,
|
||||
type AdminUserLabel
|
||||
} from '@/services/admin/userLabelService.uts'
|
||||
|
||||
// 标签数据
|
||||
const labelList = ref([
|
||||
{ id: 1, name: '新客户' },
|
||||
{ id: 2, name: '老客户' },
|
||||
{ id: 3, name: '活跃客户' },
|
||||
{ id: 4, name: '潜在客户' }
|
||||
])
|
||||
const searchText = ref('')
|
||||
const total = ref(0)
|
||||
const labelList = ref<AdminUserLabel[]>([])
|
||||
const loading = ref(false)
|
||||
|
||||
const page = ref(1)
|
||||
const pageSize = ref(15)
|
||||
const jumpPage = ref('')
|
||||
|
||||
const totalPages = computed((): number => {
|
||||
if (pageSize.value <= 0) return 1
|
||||
const pages = Math.ceil(total.value / pageSize.value)
|
||||
return pages <= 0 ? 1 : pages
|
||||
})
|
||||
|
||||
const loadLabelList = async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
const res = await fetchAdminUserLabelPage(page.value, pageSize.value, {
|
||||
search: searchText.value || null,
|
||||
status: null,
|
||||
includeDeleted: false
|
||||
})
|
||||
labelList.value = res.items
|
||||
total.value = res.total
|
||||
} catch (e) {
|
||||
uni.showToast({ title: '加载失败', icon: 'none' })
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
loadLabelList()
|
||||
})
|
||||
|
||||
function handleSearch() {
|
||||
page.value = 1
|
||||
loadLabelList()
|
||||
}
|
||||
|
||||
function handleReset() {
|
||||
searchText.value = ''
|
||||
page.value = 1
|
||||
loadLabelList()
|
||||
}
|
||||
|
||||
function prevPage() {
|
||||
if (page.value > 1) {
|
||||
page.value--
|
||||
loadLabelList()
|
||||
}
|
||||
}
|
||||
|
||||
function nextPage() {
|
||||
if (page.value < totalPages.value) {
|
||||
page.value++
|
||||
loadLabelList()
|
||||
}
|
||||
}
|
||||
|
||||
function goToJumpPage() {
|
||||
const targetPage = parseInt(jumpPage.value)
|
||||
if (!isNaN(targetPage) && targetPage >= 1 && targetPage <= totalPages.value) {
|
||||
page.value = targetPage
|
||||
loadLabelList()
|
||||
jumpPage.value = ''
|
||||
} else {
|
||||
uni.showToast({ title: '请输入有效的页码', icon: 'none' })
|
||||
}
|
||||
}
|
||||
|
||||
// 弹窗状态
|
||||
const showModal = ref(false)
|
||||
@@ -97,68 +208,100 @@ const modalTitle = computed(() => isEdit.value ? '修改标签' : '添加标签'
|
||||
|
||||
// 表单数据
|
||||
const formData = reactive({
|
||||
id: 0,
|
||||
name: ''
|
||||
id: '',
|
||||
name: '',
|
||||
color: '',
|
||||
remark: '',
|
||||
status: 1
|
||||
})
|
||||
|
||||
// 添加标签
|
||||
function onAddLabel() {
|
||||
isEdit.value = false
|
||||
formData.id = 0
|
||||
formData.id = ''
|
||||
formData.name = ''
|
||||
formData.color = ''
|
||||
formData.remark = ''
|
||||
formData.status = 1
|
||||
showModal.value = true
|
||||
}
|
||||
|
||||
// 修改标签
|
||||
function onEditLabel(label: any) {
|
||||
function onEditLabel(label: AdminUserLabel) {
|
||||
isEdit.value = true
|
||||
formData.id = label.id
|
||||
formData.name = label.name
|
||||
formData.color = label.color ?? ''
|
||||
formData.remark = label.remark ?? ''
|
||||
formData.status = label.status
|
||||
showModal.value = true
|
||||
}
|
||||
|
||||
// 删除标签
|
||||
function onDeleteLabel(label: any) {
|
||||
function onDeleteLabel(id: string) {
|
||||
uni.showModal({
|
||||
title: '提示',
|
||||
content: '确定要删除该标签吗?',
|
||||
success: (res) => {
|
||||
success: async (res) => {
|
||||
if (res.confirm) {
|
||||
labelList.value = labelList.value.filter(item => item.id !== label.id)
|
||||
uni.showToast({ title: '删除成功', icon: 'success' })
|
||||
try {
|
||||
const ok = await deleteAdminUserLabel(id)
|
||||
if (ok) {
|
||||
uni.showToast({ title: '删除成功' })
|
||||
loadLabelList()
|
||||
} else {
|
||||
uni.showToast({ title: '删除失败', icon: 'none' })
|
||||
}
|
||||
} catch (e) {
|
||||
uni.showToast({ title: '删除失败', icon: 'none' })
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// 关闭弹窗
|
||||
async function onToggleStatus(index: number) {
|
||||
const item = labelList.value[index]
|
||||
const targetStatus = item.status === 1 ? 0 : 1
|
||||
try {
|
||||
const ok = await setAdminUserLabelStatus(item.id, targetStatus)
|
||||
if (ok) {
|
||||
item.status = targetStatus
|
||||
uni.showToast({ title: '状态更新成功' })
|
||||
} else {
|
||||
uni.showToast({ title: '状态更新失败', icon: 'none' })
|
||||
}
|
||||
} catch (e) {
|
||||
uni.showToast({ title: '状态更新失败', icon: 'none' })
|
||||
}
|
||||
}
|
||||
|
||||
function closeModal() {
|
||||
showModal.value = false
|
||||
}
|
||||
|
||||
// 提交表单
|
||||
function submitForm() {
|
||||
async function submitForm() {
|
||||
if (!formData.name) {
|
||||
uni.showToast({ title: '请输入标签名称', icon: 'none' })
|
||||
return
|
||||
}
|
||||
|
||||
if (isEdit.value) {
|
||||
const index = labelList.value.findIndex(item => item.id === formData.id)
|
||||
if (index > -1) {
|
||||
labelList.value[index].name = formData.name
|
||||
}
|
||||
uni.showToast({ title: '修改成功', icon: 'success' })
|
||||
} else {
|
||||
const newId = labelList.value.length > 0 ? Math.max(...labelList.value.map(g => g.id)) + 1 : 1
|
||||
labelList.value.push({
|
||||
id: newId,
|
||||
name: formData.name
|
||||
|
||||
try {
|
||||
const resId = await saveAdminUserLabel({
|
||||
id: isEdit.value ? formData.id : null,
|
||||
name: formData.name,
|
||||
color: formData.color || null,
|
||||
remark: formData.remark || null,
|
||||
status: formData.status
|
||||
})
|
||||
uni.showToast({ title: '添加成功', icon: 'success' })
|
||||
|
||||
if (resId != null) {
|
||||
uni.showToast({ title: isEdit.value ? '修改成功' : '添加成功' })
|
||||
closeModal()
|
||||
loadLabelList()
|
||||
} else {
|
||||
uni.showToast({ title: '保存失败', icon: 'none' })
|
||||
}
|
||||
} catch (e) {
|
||||
uni.showToast({ title: '保存失败', icon: 'none' })
|
||||
}
|
||||
|
||||
closeModal()
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -179,6 +322,24 @@ function submitForm() {
|
||||
margin-bottom: 20px;
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.filter-item {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.filter-input {
|
||||
width: 200px;
|
||||
height: 32px;
|
||||
padding: 0 12px;
|
||||
border: 1px solid #d9d9d9;
|
||||
border-radius: 2px;
|
||||
font-size: 14px;
|
||||
background-color: #fff;
|
||||
}
|
||||
|
||||
/* 按钮样式 */
|
||||
@@ -265,6 +426,16 @@ function submitForm() {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.col-remark {
|
||||
flex: 1.5;
|
||||
}
|
||||
|
||||
.col-status {
|
||||
width: 120px;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.col-ops {
|
||||
width: 150px;
|
||||
display: flex;
|
||||
@@ -272,6 +443,14 @@ function submitForm() {
|
||||
justify-content: flex-end;
|
||||
}
|
||||
|
||||
.table-loading,
|
||||
.table-empty {
|
||||
padding: 24px;
|
||||
text-align: center;
|
||||
color: #999;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.op-link {
|
||||
color: #1890ff;
|
||||
cursor: pointer;
|
||||
@@ -289,10 +468,45 @@ function submitForm() {
|
||||
opacity: 0.5;
|
||||
}
|
||||
|
||||
.text-danger {
|
||||
color: #ff4d4f;
|
||||
}
|
||||
|
||||
/* Switch 开关 */
|
||||
.switch-box {
|
||||
width: 44px;
|
||||
height: 22px;
|
||||
background-color: #dcdfe6;
|
||||
border-radius: 11px;
|
||||
position: relative;
|
||||
transition: background-color 0.3s;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.switch-box.active {
|
||||
background-color: #1890ff;
|
||||
}
|
||||
|
||||
.switch-dot {
|
||||
width: 18px;
|
||||
height: 18px;
|
||||
background-color: #fff;
|
||||
border-radius: 9px;
|
||||
position: absolute;
|
||||
top: 2px;
|
||||
left: 2px;
|
||||
transition: transform 0.3s;
|
||||
}
|
||||
|
||||
.switch-box.active .switch-dot {
|
||||
transform: translateX(22px);
|
||||
}
|
||||
|
||||
/* 分页样式 */
|
||||
.pagination-row {
|
||||
margin-top: 24px;
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
justify-content: flex-end;
|
||||
color: #666;
|
||||
@@ -303,24 +517,9 @@ function submitForm() {
|
||||
margin-right: 16px;
|
||||
}
|
||||
|
||||
.page-size-selector {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding: 0 8px;
|
||||
height: 32px;
|
||||
border: 1px solid #d9d9d9;
|
||||
border-radius: 2px;
|
||||
margin-right: 16px;
|
||||
|
||||
.arrow {
|
||||
font-size: 10px;
|
||||
margin-left: 8px;
|
||||
color: #999;
|
||||
}
|
||||
}
|
||||
|
||||
.page-btns {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
margin-right: 16px;
|
||||
}
|
||||
|
||||
@@ -349,6 +548,7 @@ function submitForm() {
|
||||
|
||||
.page-jump {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
|
||||
.jump-input {
|
||||
@@ -448,6 +648,20 @@ function submitForm() {
|
||||
}
|
||||
}
|
||||
|
||||
.form-textarea {
|
||||
flex: 1;
|
||||
height: 80px;
|
||||
padding: 4px 11px;
|
||||
border: 1px solid #d9d9d9;
|
||||
border-radius: 2px;
|
||||
font-size: 14px;
|
||||
|
||||
&:focus {
|
||||
border-color: #40a9ff;
|
||||
outline: none;
|
||||
}
|
||||
}
|
||||
|
||||
.modal-footer {
|
||||
padding: 10px 16px;
|
||||
border-top: 1px solid #f0f0f0;
|
||||
|
||||
@@ -157,7 +157,13 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="uts">
|
||||
import { ref, reactive } from 'vue'
|
||||
import { ref, reactive, onMounted, computed } from 'vue'
|
||||
import {
|
||||
fetchAdminUserLevelPage,
|
||||
saveAdminUserLevel,
|
||||
deleteAdminUserLevel,
|
||||
setAdminUserLevelVisible
|
||||
} from '@/services/admin/userLevelService.uts'
|
||||
|
||||
interface LevelItem {
|
||||
id: number
|
||||
@@ -172,18 +178,76 @@ interface LevelItem {
|
||||
}
|
||||
|
||||
const filterName = ref('')
|
||||
const total = ref(5)
|
||||
const levelList = ref<LevelItem[]>([
|
||||
{ id: 1, name: 'V1', level: 1, iconBg: '#fdf6ec', iconSymbol: '👑', bgGradient: 'linear-gradient(to bottom right, #f5e6d3, #e8d5bc)', discount: 99, experience: 500, isShow: true },
|
||||
{ id: 2, name: 'V2', level: 2, iconBg: '#ecf5ff', iconSymbol: '💎', bgGradient: 'linear-gradient(to bottom right, #d3e9f5, #bcd9e8)', discount: 97, experience: 1000, isShow: true },
|
||||
{ id: 3, name: 'V3', level: 3, iconBg: '#f4f4f5', iconSymbol: '⭐', bgGradient: 'linear-gradient(to bottom right, #e3e3e3, #cbcbcb)', discount: 95, experience: 3000, isShow: true },
|
||||
{ id: 4, name: 'V4', level: 4, iconBg: '#fef0f0', iconSymbol: '👑', bgGradient: 'linear-gradient(to bottom right, #f5dfd3, #e8c6bc)', discount: 93, experience: 8000, isShow: true },
|
||||
{ id: 5, name: 'V5', level: 5, iconBg: '#f0f9eb', iconSymbol: '💠', bgGradient: 'linear-gradient(to bottom right, #d3e1f5, #bccce8)', discount: 70, experience: 15000, isShow: true }
|
||||
])
|
||||
const total = ref(0)
|
||||
const levelList = ref<AdminUserLevel[]>([])
|
||||
const loading = ref(false)
|
||||
const page = ref(1)
|
||||
const pageSize = ref(15)
|
||||
const jumpPage = ref('')
|
||||
|
||||
const totalPages = computed((): number => {
|
||||
if (pageSize.value <= 0) return 1
|
||||
const pages = Math.ceil(total.value / pageSize.value)
|
||||
return pages <= 0 ? 1 : pages
|
||||
})
|
||||
|
||||
const loadLevelList = async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
const res = await fetchAdminUserLevelPage(page.value, pageSize.value, {
|
||||
search: filterName.value || null,
|
||||
isVisible: null, // 全部
|
||||
status: null
|
||||
})
|
||||
|
||||
levelList.value = res.items
|
||||
total.value = res.total
|
||||
} catch (e) {
|
||||
uni.showToast({ title: '加载失败', icon: 'none' })
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
loadLevelList()
|
||||
})
|
||||
|
||||
const handleQuery = () => {
|
||||
page.value = 1
|
||||
loadLevelList()
|
||||
}
|
||||
|
||||
const prevPage = () => {
|
||||
if (page.value > 1) {
|
||||
page.value--
|
||||
loadLevelList()
|
||||
}
|
||||
}
|
||||
|
||||
const nextPage = () => {
|
||||
if (page.value < totalPages.value) {
|
||||
page.value++
|
||||
loadLevelList()
|
||||
}
|
||||
}
|
||||
|
||||
const goToJumpPage = () => {
|
||||
const targetPage = parseInt(jumpPage.value)
|
||||
if (!isNaN(targetPage) && targetPage >= 1 && targetPage <= totalPages.value) {
|
||||
page.value = targetPage
|
||||
loadLevelList()
|
||||
jumpPage.value = ''
|
||||
} else {
|
||||
uni.showToast({ title: '请输入有效的页码', icon: 'none' })
|
||||
}
|
||||
}
|
||||
|
||||
const showDrawer = ref(false)
|
||||
const isClosing = ref(false)
|
||||
const isEdit = ref(false)
|
||||
const editingId = ref<string | null>(null)
|
||||
|
||||
const form = reactive({
|
||||
name: '',
|
||||
level: 1,
|
||||
@@ -192,11 +256,11 @@ const form = reactive({
|
||||
isShow: true
|
||||
})
|
||||
|
||||
const handleQuery = () => { console.log('Querying...') }
|
||||
const handleAdd = () => {
|
||||
isEdit.value = false
|
||||
editingId.value = null
|
||||
form.name = ''
|
||||
form.level = levelList.value.length + 1
|
||||
form.level = 1
|
||||
form.discount = 100
|
||||
form.experience = 0
|
||||
form.isShow = true
|
||||
@@ -204,32 +268,74 @@ const handleAdd = () => {
|
||||
isClosing.value = false
|
||||
}
|
||||
|
||||
const handleEdit = (item: LevelItem) => {
|
||||
const handleEdit = (item: AdminUserLevel) => {
|
||||
isEdit.value = true
|
||||
editingId.value = item.id
|
||||
form.name = item.name
|
||||
form.level = item.level
|
||||
form.discount = item.discount
|
||||
form.experience = item.experience
|
||||
form.isShow = item.isShow
|
||||
form.level = item.level_weight
|
||||
form.discount = item.discount_percent
|
||||
form.experience = item.min_experience
|
||||
form.isShow = item.is_visible
|
||||
showDrawer.value = true
|
||||
isClosing.value = false
|
||||
}
|
||||
|
||||
const closeDrawer = () => {
|
||||
isClosing.value = true
|
||||
setTimeout(() => {
|
||||
showDrawer.value = false
|
||||
isClosing.value = false
|
||||
}, 300)
|
||||
const handleDelete = (id: string) => {
|
||||
uni.showModal({
|
||||
title: '确认删除',
|
||||
content: '确定要删除该用户等级吗?',
|
||||
success: async (res) => {
|
||||
if (res.confirm) {
|
||||
const ok = await deleteAdminUserLevel(id)
|
||||
if (ok) {
|
||||
uni.showToast({ title: '删除成功' })
|
||||
loadLevelList()
|
||||
} else {
|
||||
uni.showToast({ title: '删除失败', icon: 'none' })
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
const toggleShow = (index: number) => {
|
||||
levelList.value[index].isShow = !levelList.value[index].isShow
|
||||
const toggleShow = async (index: number) => {
|
||||
const item = levelList.value[index]
|
||||
const targetVisible = !item.is_visible
|
||||
const ok = await setAdminUserLevelVisible(item.id, targetVisible)
|
||||
if (ok) {
|
||||
item.is_visible = targetVisible
|
||||
} else {
|
||||
uni.showToast({ title: '修改失败', icon: 'none' })
|
||||
}
|
||||
}
|
||||
|
||||
const handleSave = () => {
|
||||
console.log('Saving...', form)
|
||||
closeDrawer()
|
||||
const handleSave = async () => {
|
||||
if (!form.name) {
|
||||
uni.showToast({ title: '请输入等级名称', icon: 'none' })
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
const resId = await saveAdminUserLevel({
|
||||
id: editingId.value,
|
||||
name: form.name,
|
||||
level_weight: form.level,
|
||||
min_experience: form.experience,
|
||||
discount_percent: form.discount,
|
||||
is_visible: form.isShow,
|
||||
status: 1 // 默认启用
|
||||
})
|
||||
|
||||
if (resId != null) {
|
||||
uni.showToast({ title: '保存成功' })
|
||||
closeDrawer()
|
||||
loadLevelList()
|
||||
} else {
|
||||
uni.showToast({ title: '保存失败', icon: 'none' })
|
||||
}
|
||||
} catch (e) {
|
||||
uni.showToast({ title: '保存出错', icon: 'none' })
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user