增加运营商管理

This commit is contained in:
aaron 2025-03-09 13:42:09 +08:00
parent d4454b818e
commit d05216743c
5 changed files with 550 additions and 4 deletions

View File

@ -25,6 +25,9 @@
<a-menu-item key="user-list"> <a-menu-item key="user-list">
<router-link to="/user/list">用户列表</router-link> <router-link to="/user/list">用户列表</router-link>
</a-menu-item> </a-menu-item>
<a-menu-item key="user-partner">
<router-link to="/user/partner">运营商管理</router-link>
</a-menu-item>
<a-menu-item key="deliveryman-list"> <a-menu-item key="deliveryman-list">
<router-link to="/deliveryman/list">配送员列表</router-link> <router-link to="/deliveryman/list">配送员列表</router-link>
</a-menu-item> </a-menu-item>
@ -226,6 +229,11 @@ export default defineComponent({
key: 'user-list', key: 'user-list',
title: '用户列表', title: '用户列表',
path: '/user/list' path: '/user/list'
},
{
key: 'user-partner',
title: '运营商管理',
path: '/user/partner'
} }
] ]
}, },

View File

@ -22,6 +22,12 @@ const routes = [
component: () => import('../views/user/UserList.vue'), component: () => import('../views/user/UserList.vue'),
meta: { title: '用户列表' } meta: { title: '用户列表' }
}, },
{
path: '/user/partner',
name: 'PartnerList',
component: () => import('../views/user/PartnerList.vue'),
meta: { title: '运营商管理' }
},
{ {
path: '/deliveryman/list', path: '/deliveryman/list',
name: 'DeliverymanList', name: 'DeliverymanList',

View File

@ -516,7 +516,6 @@ export default defineComponent({
<style scoped> <style scoped>
.deliveryman-list { .deliveryman-list {
padding: 24px;
background: #fff; background: #fff;
} }

View File

@ -0,0 +1,530 @@
<template>
<page-container>
<div class="partner-list">
<div class="table-header">
<h1>运营商管理</h1>
</div>
<!-- 筛选区域 -->
<div class="table-filter">
<a-form layout="inline">
<a-form-item label="手机号">
<a-input
v-model:value="filterForm.phone"
placeholder="请输入手机号"
style="width: 200px"
allowClear
@change="handleFilterChange"
/>
</a-form-item>
<a-form-item label="小区">
<a-select
v-model:value="filterForm.community_id"
style="width: 200px"
placeholder="请选择小区"
allowClear
@change="handleFilterChange"
>
<a-select-option
v-for="community in communityList"
:key="community.id"
:value="community.id"
>
{{ community.name }}
</a-select-option>
</a-select>
</a-form-item>
<a-form-item>
<a-space>
<a-button type="primary" @click="handleSearch">
查询
</a-button>
<a-button @click="handleReset">
重置
</a-button>
</a-space>
</a-form-item>
</a-form>
</div>
<a-table
:columns="columns"
:data-source="tableData"
:pagination="pagination"
:loading="loading"
@change="handleTableChange"
row-key="userid"
>
<template #bodyCell="{ column, record }">
<template v-if="column.key === 'phone'">
{{ formatPhone(record.phone) }}
</template>
</template>
</a-table>
</div>
<!-- 角色编辑模态框 -->
<a-modal
v-model:visible="roleModalVisible"
title="修改用户角色"
@ok="handleRolesSave"
@cancel="handleRolesCancel"
:confirmLoading="rolesSaving"
>
<a-form layout="vertical">
<a-form-item label="用户角色">
<a-checkbox-group v-model:value="selectedRoles">
<a-checkbox
v-for="role in availableRoles"
:key="role.value"
:value="role.value"
:disabled="role.value === 'user'"
>
{{ role.label }}
</a-checkbox>
</a-checkbox-group>
</a-form-item>
</a-form>
</a-modal>
<!-- 密码重置结果模态框 -->
<a-modal
v-model:visible="passwordModalVisible"
title="重置密码结果"
>
<p>密码重置成功新密码为</p>
<div class="password-display">
<a-input ref="passwordInput" v-model:value="newPassword" readonly />
</div>
<p class="password-tip">请及时保存并告知用户</p>
<template #footer>
<a-space>
<a-button type="primary" @click="handleCopyPassword">
复制密码
</a-button>
<a-button @click="handleClosePasswordModal">
关闭
</a-button>
</a-space>
</template>
</a-modal>
</page-container>
</template>
<script>
import { defineComponent, ref, onMounted } from 'vue'
import { message, Tag, Modal, Checkbox, Select } from 'ant-design-vue'
import { getUserList } from '@/api/user'
import request from '@/utils/request'
import PageContainer from '@/components/PageContainer.vue'
export default defineComponent({
components: {
PageContainer,
ATag: Tag,
ACheckbox: Checkbox,
ACheckboxGroup: Checkbox.Group,
ASelect: Select,
ASelectOption: Select.Option
},
setup() {
const loading = ref(false)
const tableData = ref([])
const communityList = ref([]) //
const pagination = ref({
current: 1,
pageSize: 10,
total: 0,
showSizeChanger: true,
showTotal: (total) => `${total} 条记录`
})
const columns = [
{
title: 'ID',
dataIndex: 'userid',
key: 'userid',
width: 80,
},
{
title: '昵称',
dataIndex: 'nickname',
key: 'nickname',
width: 120,
},
{
title: '手机号',
dataIndex: 'phone',
key: 'phone',
width: 120,
}
]
// 4*
const formatPhone = (phone) => {
if (!phone) return ''
return phone.replace(/(\d{3})\d{4}(\d{4})/, '$1****$2')
}
//
const filterForm = ref({
phone: undefined,
community_id: undefined
})
//
const fetchData = async () => {
try {
loading.value = true
const params = {
skip: (pagination.value.current - 1) * pagination.value.pageSize,
limit: pagination.value.pageSize,
role: 'partner', //
phone: filterForm.value.phone,
community_id: filterForm.value.community_id
}
//
Object.keys(params).forEach(key => {
if (params[key] === undefined || params[key] === '') {
delete params[key]
}
})
const res = await getUserList(params)
if (res.code === 200) {
tableData.value = res.data.items
pagination.value.total = res.data.total
} else {
message.error(res.message || '获取数据失败')
}
} catch (error) {
console.error('获取运营商列表失败:', error)
message.error('获取数据失败')
} finally {
loading.value = false
}
}
//
const handleTableChange = (pag) => {
pagination.value.current = pag.current
pagination.value.pageSize = pag.pageSize
fetchData()
}
//
const getRoleName = (role) => {
const roleMap = {
'admin': '管理员',
'user': '普通用户',
'merchant': '商家',
'deliveryman': '配送员',
'partner': '运营商'
}
return roleMap[role] || role
}
//
const getRoleColor = (role) => {
const colorMap = {
'admin': 'red',
'user': 'blue',
'merchant': 'orange',
'deliveryman': 'purple',
'partner': 'green'
}
return colorMap[role] || 'default'
}
//
const currentUserId = ref(null)
//
const roleModalVisible = ref(false)
const rolesSaving = ref(false)
const selectedRoles = ref([])
//
const passwordModalVisible = ref(false)
const newPassword = ref('')
const passwordInput = ref(null)
//
const availableRoles = [
{ label: '普通用户', value: 'user' },
{ label: '商家', value: 'merchant' },
{ label: '配送员', value: 'deliveryman' },
{ label: '运营商', value: 'partner' }
]
//
const handleEditRoles = (record) => {
currentUserId.value = record.userid
selectedRoles.value = record.roles || ['user']
roleModalVisible.value = true
}
//
const handleRolesSave = async () => {
try {
rolesSaving.value = true
//
const originalRoles = tableData.value.find(
user => user.userid === currentUserId.value
)?.roles || []
// admin
const newRoles = selectedRoles.value
if (originalRoles.includes('admin')) {
newRoles.push('admin')
}
//
if (!newRoles.includes('user')) {
newRoles.push('user')
}
await request.put(`/api/user/roles`, {
user_id: currentUserId.value,
roles: newRoles
})
message.success('角色修改成功')
roleModalVisible.value = false
fetchData() //
} catch (error) {
console.error('修改角色失败:', error)
message.error('修改角色失败')
} finally {
rolesSaving.value = false
}
}
//
const handleRolesCancel = () => {
roleModalVisible.value = false
resetStates()
}
//
const handleFilterChange = () => {
pagination.value.current = 1 //
}
//
const handleSearch = () => {
pagination.value.current = 1
fetchData()
}
//
const handleReset = () => {
filterForm.value = {
phone: undefined,
community_id: undefined
}
pagination.value.current = 1
fetchData()
}
//
const generatePassword = () => {
const chars = '1234567890'
let password = ''
for (let i = 0; i < 6; i++) {
password += chars.charAt(Math.floor(Math.random() * chars.length))
}
return password
}
//
const handleResetPassword = (record) => {
Modal.confirm({
title: '重置密码',
content: `确定要重置用户 ${record.nickname || record.phone} 的密码吗?`,
async onOk() {
try {
const password = generatePassword()
await request.post('/api/user/reset-password', {
user_id: record.userid,
new_password: password
})
newPassword.value = password
passwordModalVisible.value = true
message.success('密码重置成功')
} catch (error) {
console.error('重置密码失败:', error)
message.error('重置密码失败')
}
}
})
}
//
const handleCopyPassword = async () => {
try {
await navigator.clipboard.writeText(newPassword.value)
message.success('密码已复制到剪贴板')
} catch (err) {
// API使
passwordInput.value.select()
document.execCommand('copy')
message.success('密码已复制到剪贴板')
}
}
//
const handleClosePasswordModal = () => {
passwordModalVisible.value = false
newPassword.value = ''
resetStates()
}
//
const resetStates = () => {
currentUserId.value = null
selectedRoles.value = []
}
//
const fetchCommunityList = async () => {
try {
const res = await request.get('/api/community')
if (res.code === 200 && res.data && res.data.items) {
communityList.value = res.data.items || []
} else {
message.error(res.message || '获取小区列表失败')
}
} catch (error) {
console.error('获取小区列表失败:', error)
message.error('获取小区列表失败')
}
}
onMounted(() => {
fetchData()
fetchCommunityList() //
})
return {
loading,
columns,
tableData,
communityList, //
pagination,
handleTableChange,
formatPhone,
getRoleName,
getRoleColor,
roleModalVisible,
rolesSaving,
selectedRoles,
availableRoles,
handleEditRoles,
handleRolesSave,
handleRolesCancel,
filterForm,
handleFilterChange,
handleSearch,
handleReset,
passwordModalVisible,
newPassword,
passwordInput,
handleResetPassword,
handleCopyPassword,
handleClosePasswordModal,
currentUserId
}
}
})
</script>
<style scoped>
.table-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 16px;
}
.table-header h1 {
margin: 0;
}
:deep(.ant-table-content) {
overflow-x: auto;
}
.partner-list {
/* 保留其他必要样式 */
}
:deep(.ant-tag) {
min-width: 80px;
text-align: center;
margin-right: 0;
}
:deep(.ant-space) {
display: flex;
align-items: center;
}
:deep(.ant-btn-link) {
padding: 0 4px;
height: 24px;
line-height: 24px;
}
.table-filter {
margin-bottom: 16px;
padding: 16px 24px;
background: #fff;
border-radius: 2px;
}
:deep(.ant-form-item) {
margin-bottom: 0;
margin-right: 16px;
}
:deep(.ant-form-item:last-child) {
margin-right: 0;
}
.password-display {
margin: 16px 0;
background: #f5f5f5;
padding: 12px;
border-radius: 4px;
}
.password-tip {
color: #ff4d4f;
margin-top: 8px;
margin-bottom: 0;
}
:deep(.ant-input[readonly]) {
background-color: #fff;
cursor: text;
color: rgba(0, 0, 0, 0.85);
font-family: monospace;
font-size: 16px;
text-align: center;
}
:deep(.ant-select) {
width: 100% !important;
}
:deep(.ant-input) {
width: 200px !important;
}
</style>

View File

@ -275,7 +275,8 @@ export default defineComponent({
'admin': '管理员', 'admin': '管理员',
'user': '普通用户', 'user': '普通用户',
'merchant': '商家', 'merchant': '商家',
'deliveryman': '配送员' 'deliveryman': '配送员',
'partner': '运营商'
} }
return roleMap[role] || role return roleMap[role] || role
} }
@ -286,7 +287,8 @@ export default defineComponent({
'admin': 'red', 'admin': 'red',
'user': 'blue', 'user': 'blue',
'merchant': 'orange', 'merchant': 'orange',
'deliveryman': 'purple' 'deliveryman': 'purple',
'partner': 'green'
} }
return colorMap[role] || 'default' return colorMap[role] || 'default'
} }
@ -308,7 +310,8 @@ export default defineComponent({
const availableRoles = [ const availableRoles = [
{ label: '普通用户', value: 'user' }, { label: '普通用户', value: 'user' },
{ label: '商家', value: 'merchant' }, { label: '商家', value: 'merchant' },
{ label: '配送员', value: 'deliveryman' } { label: '配送员', value: 'deliveryman' },
{ label: '运营商', value: 'partner' }
] ]
// //