fetch(modify):账号列表合并
All checks were successful
构建并部署前端到测试环境 / build-and-deploy (push) Successful in 4m31s

This commit is contained in:
sexygoat
2026-02-09 10:49:52 +08:00
parent e8700c2585
commit ca3184857e
4 changed files with 172 additions and 43 deletions

View File

@@ -828,24 +828,24 @@ export const asyncRoutes: AppRouteRecord[] = [
keepAlive: true keepAlive: true
} }
}, },
{ // {
path: 'platform-account', // path: 'platform-account',
name: 'PlatformAccount', // name: 'PlatformAccount',
component: RoutesAlias.PlatformAccount, // component: RoutesAlias.PlatformAccount,
meta: { // meta: {
title: 'menus.accountManagement.platformAccount', // title: 'menus.accountManagement.platformAccount',
keepAlive: true // keepAlive: true
} // }
}, // },
{ // {
path: 'shop-account', // path: 'shop-account',
name: 'ShopAccount', // name: 'ShopAccount',
component: RoutesAlias.ShopAccount, // component: RoutesAlias.ShopAccount,
meta: { // meta: {
title: 'menus.accountManagement.shopAccount', // title: 'menus.accountManagement.shopAccount',
keepAlive: true // keepAlive: true
} // }
}, // },
// { // {
// path: 'customer-role', // path: 'customer-role',
// name: 'CustomerRole', // name: 'CustomerRole',

View File

@@ -80,7 +80,7 @@ export enum RoutesAlias {
// 账号管理 // 账号管理
Account = '/account-management/account', // 账号管理 Account = '/account-management/account', // 账号管理
PlatformAccount = '/account-management/platform-account', // 平台账号管理 // PlatformAccount = '/account-management/platform-account', // 平台账号管理
CustomerManagement = '/account-management/customer', // 客户管理 CustomerManagement = '/account-management/customer', // 客户管理
CustomerRole = '/account-management/customer-role', // 客户角色 CustomerRole = '/account-management/customer-role', // 客户角色
AgentManagement = '/account-management/agent', // 代理商管理 AgentManagement = '/account-management/agent', // 代理商管理

View File

@@ -60,7 +60,7 @@
<ElFormItem label="手机号" prop="phone"> <ElFormItem label="手机号" prop="phone">
<ElInput v-model="formData.phone" placeholder="请输入手机号" maxlength="11" /> <ElInput v-model="formData.phone" placeholder="请输入手机号" maxlength="11" />
</ElFormItem> </ElFormItem>
<ElFormItem label="账号类型" prop="user_type"> <ElFormItem v-if="dialogType === 'add'" label="账号类型" prop="user_type">
<ElSelect <ElSelect
v-model="formData.user_type" v-model="formData.user_type"
placeholder="请选择账号类型" placeholder="请选择账号类型"
@@ -72,6 +72,42 @@
<ElOption label="企业账号" :value="4" /> <ElOption label="企业账号" :value="4" />
</ElSelect> </ElSelect>
</ElFormItem> </ElFormItem>
<ElFormItem v-if="dialogType === 'add' && formData.user_type === 3" label="关联店铺" prop="shop_id">
<ElSelect
v-model="formData.shop_id"
placeholder="请输入店铺名称搜索"
style="width: 100%"
filterable
remote
:remote-method="handleShopSearch"
clearable
>
<ElOption
v-for="shop in shopList"
:key="shop.id"
:label="shop.shop_name"
:value="shop.id"
/>
</ElSelect>
</ElFormItem>
<ElFormItem v-if="dialogType === 'add' && formData.user_type === 4" label="关联企业" prop="enterprise_id">
<ElSelect
v-model="formData.enterprise_id"
placeholder="请输入企业名称搜索"
style="width: 100%"
filterable
remote
:remote-method="handleEnterpriseSearch"
clearable
>
<ElOption
v-for="enterprise in enterpriseList"
:key="enterprise.id"
:label="enterprise.enterprise_name"
:value="enterprise.id"
/>
</ElSelect>
</ElFormItem>
</ElForm> </ElForm>
<template #footer> <template #footer>
<div class="dialog-footer"> <div class="dialog-footer">
@@ -378,12 +414,16 @@
formData.username = row.username formData.username = row.username
formData.phone = row.phone formData.phone = row.phone
formData.user_type = row.user_type formData.user_type = row.user_type
formData.shop_id = row.shop_id || null
formData.enterprise_id = row.enterprise_id || null
formData.password = '' formData.password = ''
} else { } else {
formData.id = '' formData.id = ''
formData.username = '' formData.username = ''
formData.phone = '' formData.phone = ''
formData.user_type = 2 formData.user_type = 2
formData.shop_id = null
formData.enterprise_id = null
formData.password = '' formData.password = ''
} }
} }
@@ -523,7 +563,9 @@
username: '', username: '',
password: '', password: '',
phone: '', phone: '',
user_type: 2 user_type: 2,
shop_id: null as number | null,
enterprise_id: null as number | null
}) })
onMounted(() => { onMounted(() => {
@@ -682,7 +724,31 @@
{ len: 11, message: '手机号必须为 11 位', trigger: 'blur' }, { len: 11, message: '手机号必须为 11 位', trigger: 'blur' },
{ pattern: /^1[3-9]\d{9}$/, message: '请输入正确的手机号格式', trigger: 'blur' } { pattern: /^1[3-9]\d{9}$/, message: '请输入正确的手机号格式', trigger: 'blur' }
], ],
user_type: [{ required: true, message: '请选择账号类型', trigger: 'change' }] user_type: [{ required: true, message: '请选择账号类型', trigger: 'change' }],
shop_id: [
{
validator: (rule: any, value: any, callback: any) => {
if (formData.user_type === 3 && !value) {
callback(new Error('代理账号必须关联店铺'))
} else {
callback()
}
},
trigger: 'change'
}
],
enterprise_id: [
{
validator: (rule: any, value: any, callback: any) => {
if (formData.user_type === 4 && !value) {
callback(new Error('企业账号必须关联企业'))
} else {
callback()
}
},
trigger: 'change'
}
]
}) })
// 提交表单 // 提交表单
@@ -692,17 +758,31 @@
await formRef.value.validate(async (valid) => { await formRef.value.validate(async (valid) => {
if (valid) { if (valid) {
try { try {
if (dialogType.value === 'add') {
// 创建账号
const data: any = { const data: any = {
username: formData.username, username: formData.username,
phone: formData.phone, phone: formData.phone,
password: formData.password,
user_type: formData.user_type user_type: formData.user_type
} }
if (dialogType.value === 'add') { // 根据账号类型添加相应的字段
data.password = formData.password if (formData.user_type === 3) {
data.shop_id = formData.shop_id
} else if (formData.user_type === 4) {
data.enterprise_id = formData.enterprise_id
}
await AccountService.createAccount(data) await AccountService.createAccount(data)
ElMessage.success('添加成功') ElMessage.success('添加成功')
} else { } else {
// 编辑账号 - 只提交username和phone
const data: any = {
username: formData.username,
phone: formData.phone
}
await AccountService.updateAccount(Number(formData.id), data) await AccountService.updateAccount(Number(formData.id), data)
ElMessage.success('更新成功') ElMessage.success('更新成功')
} }

View File

@@ -79,21 +79,41 @@
<ElOption label="企业账号" :value="4" /> <ElOption label="企业账号" :value="4" />
</ElSelect> </ElSelect>
</ElFormItem> </ElFormItem>
<ElFormItem v-if="formData.user_type === 3" label="关联店铺ID" prop="shop_id"> <ElFormItem v-if="formData.user_type === 3" label="关联店铺" prop="shop_id">
<ElInputNumber <ElSelect
v-model="formData.shop_id" v-model="formData.shop_id"
:min="1" placeholder="请输入店铺名称搜索"
placeholder="请输入店铺ID"
style="width: 100%" style="width: 100%"
filterable
remote
:remote-method="handleShopSearch"
clearable
>
<ElOption
v-for="shop in shopList"
:key="shop.id"
:label="shop.shop_name"
:value="shop.id"
/> />
</ElSelect>
</ElFormItem> </ElFormItem>
<ElFormItem v-if="formData.user_type === 4" label="关联企业ID" prop="enterprise_id"> <ElFormItem v-if="formData.user_type === 4" label="关联企业" prop="enterprise_id">
<ElInputNumber <ElSelect
v-model="formData.enterprise_id" v-model="formData.enterprise_id"
:min="1" placeholder="请输入企业名称搜索"
placeholder="请输入企业ID"
style="width: 100%" style="width: 100%"
filterable
remote
:remote-method="handleEnterpriseSearch"
clearable
>
<ElOption
v-for="enterprise in enterpriseList"
:key="enterprise.id"
:label="enterprise.enterprise_name"
:value="enterprise.id"
/> />
</ElSelect>
</ElFormItem> </ElFormItem>
<ElFormItem v-if="dialogType === 'edit'" label="状态"> <ElFormItem v-if="dialogType === 'edit'" label="状态">
<ElSwitch <ElSwitch
@@ -255,7 +275,7 @@
import { useCheckedColumns } from '@/composables/useCheckedColumns' import { useCheckedColumns } from '@/composables/useCheckedColumns'
import { useAuth } from '@/composables/useAuth' import { useAuth } from '@/composables/useAuth'
import ArtButtonTable from '@/components/core/forms/ArtButtonTable.vue' import ArtButtonTable from '@/components/core/forms/ArtButtonTable.vue'
import { AccountService, RoleService, ShopService } from '@/api/modules' import { AccountService, RoleService, ShopService, EnterpriseService } from '@/api/modules'
import type { SearchFormItem } from '@/types' import type { SearchFormItem } from '@/types'
import type { PlatformRole, PlatformAccount } from '@/types/api' import type { PlatformRole, PlatformAccount } from '@/types/api'
import { formatDateTime } from '@/utils/business/format' import { formatDateTime } from '@/utils/business/format'
@@ -607,6 +627,7 @@
getAccountList() getAccountList()
loadAllRoles() loadAllRoles()
loadShopList() loadShopList()
loadEnterpriseList()
}) })
// 加载所有角色列表 // 加载所有角色列表
@@ -884,12 +905,13 @@
} }
// 加载店铺列表 // 加载店铺列表
const loadShopList = async () => { const loadShopList = async (keyword: string = '') => {
try { try {
const res = await ShopService.getShops({ const res = await ShopService.getShops({
page: 1, page: 1,
page_size: 9999, page_size: 20, // 默认加载20条
status: 1 // 只加载启用的店铺 status: 1, // 只加载启用的店铺
shop_name: keyword || undefined // 根据店铺名称搜索
}) })
if (res.code === 0) { if (res.code === 0) {
shopList.value = res.data.items || [] shopList.value = res.data.items || []
@@ -898,6 +920,33 @@
console.error('获取店铺列表失败:', error) console.error('获取店铺列表失败:', error)
} }
} }
// 店铺搜索处理
const handleShopSearch = (query: string) => {
loadShopList(query)
}
// 加载企业列表
const loadEnterpriseList = async (keyword: string = '') => {
try {
const res = await EnterpriseService.getEnterprises({
page: 1,
page_size: 20, // 默认加载20条
status: 1, // 只加载启用的企业
enterprise_name: keyword || undefined // 根据企业名称搜索
})
if (res.code === 0) {
enterpriseList.value = res.data.items || []
}
} catch (error) {
console.error('获取企业列表失败:', error)
}
}
// 企业搜索处理
const handleEnterpriseSearch = (query: string) => {
loadEnterpriseList(query)
}
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>