fetch(modify):修复BUG
All checks were successful
构建并部署前端到测试环境 / build-and-deploy (push) Successful in 3m27s

This commit is contained in:
sexygoat
2026-02-03 14:39:45 +08:00
parent 2c6fe4375b
commit de9753f42d
28 changed files with 4344 additions and 5092 deletions

View File

@@ -5,7 +5,6 @@
<ArtSearchBar
v-model:filter="formFilters"
:items="formItems"
:show-expand="false"
@reset="handleReset"
@search="handleSearch"
></ArtSearchBar>
@@ -121,10 +120,11 @@
import ArtButtonTable from '@/components/core/forms/ArtButtonTable.vue'
import { AccountService } from '@/api/modules/account'
import { RoleService } from '@/api/modules/role'
import { ShopService } from '@/api/modules'
import type { SearchFormItem } from '@/types'
import type { PlatformRole } from '@/types/api'
import { formatDateTime } from '@/utils/business/format'
import { CommonStatus, getStatusText } from '@/config/constants'
import { CommonStatus, getStatusText, STATUS_SELECT_OPTIONS } from '@/config/constants'
defineOptions({ name: 'Account' }) // 定义组件名称,用于 KeepAlive 缓存控制
@@ -140,12 +140,20 @@
// 定义表单搜索初始值
const initialSearchState = {
name: '',
phone: ''
phone: '',
user_type: undefined as number | undefined,
shop_id: undefined as number | undefined,
enterprise_id: undefined as number | undefined,
status: undefined as number | undefined
}
// 响应式表单数据
const formFilters = reactive({ ...initialSearchState })
// 店铺和企业列表
const shopList = ref<any[]>([])
const enterpriseList = ref<any[]>([])
const pagination = reactive({
currentPage: 1,
pageSize: 20,
@@ -176,7 +184,7 @@
}
// 表单配置项
const formItems: SearchFormItem[] = [
const formItems = computed<SearchFormItem[]>(() => [
{
label: '账号名称',
prop: 'name',
@@ -194,17 +202,59 @@
clearable: true,
placeholder: '请输入手机号'
}
},
{
label: '账号类型',
prop: 'user_type',
type: 'select',
options: [
{ label: '超级管理员', value: 1 },
{ label: '平台用户', value: 2 },
{ label: '代理账号', value: 3 },
{ label: '企业账号', value: 4 }
],
config: {
clearable: true,
placeholder: '请选择账号类型'
}
},
{
label: '关联店铺',
prop: 'shop_id',
type: 'select',
options: shopList.value.map((shop) => ({
label: shop.shop_name,
value: shop.id
})),
config: {
clearable: true,
filterable: true,
remote: true,
remoteMethod: handleShopSearch,
placeholder: '请输入店铺名称搜索'
}
},
{
label: '状态',
prop: 'status',
type: 'select',
options: STATUS_SELECT_OPTIONS,
config: {
clearable: true,
placeholder: '请选择状态'
}
}
]
])
// 列配置
const columnOptions = [
{ label: 'ID', prop: 'ID' },
{ label: '账号名称', prop: 'username' },
{ label: '手机号', prop: 'phone' },
{ label: '账号类型', prop: 'user_type_name' },
{ label: '账号类型', prop: 'user_type' },
{ label: '店铺名称', prop: 'shop_name' },
{ label: '企业名称', prop: 'enterprise_name' },
{ label: '状态', prop: 'status' },
{ label: '创建时间', prop: 'CreatedAt' },
{ label: '创建时间', prop: 'created_at' },
{ label: '操作', prop: 'operation' }
]
@@ -256,21 +306,20 @@
// 动态列配置
const { columnChecks, columns } = useCheckedColumns(() => [
{
prop: 'ID',
label: 'ID'
},
{
prop: 'username',
label: '账号名称'
label: '账号名称',
minWidth: 120
},
{
prop: 'phone',
label: '手机号'
label: '手机号',
width: 130
},
{
prop: 'user_type',
label: '账号类型',
width: 120,
formatter: (row: any) => {
const typeMap: Record<number, string> = {
1: '超级管理员',
@@ -281,9 +330,26 @@
return typeMap[row.user_type] || '-'
}
},
{
prop: 'shop_name',
label: '店铺名称',
minWidth: 150,
formatter: (row: any) => {
return row.shop_name || '-'
}
},
{
prop: 'enterprise_name',
label: '企业名称',
minWidth: 150,
formatter: (row: any) => {
return row.enterprise_name || '-'
}
},
{
prop: 'status',
label: '状态',
width: 100,
formatter: (row: any) => {
return h(ElSwitch, {
modelValue: row.status,
@@ -298,13 +364,15 @@
}
},
{
prop: 'CreatedAt',
prop: 'created_at',
label: '创建时间',
formatter: (row: any) => formatDateTime(row.CreatedAt)
width: 180,
formatter: (row: any) => formatDateTime(row.created_at)
},
{
prop: 'operation',
label: '操作',
width: 200,
fixed: 'right',
formatter: (row: any) => {
return h('div', { style: 'display: flex; gap: 8px;' }, [
@@ -340,6 +408,7 @@
onMounted(() => {
getAccountList()
loadAllRoles()
loadShopList()
})
// 加载所有角色列表
@@ -400,7 +469,12 @@
const params = {
page: pagination.currentPage,
pageSize: pagination.pageSize,
keyword: formFilters.name || formFilters.phone || undefined
username: formFilters.name || undefined,
phone: formFilters.phone || undefined,
user_type: formFilters.user_type,
shop_id: formFilters.shop_id,
enterprise_id: formFilters.enterprise_id,
status: formFilters.status
}
const res = await AccountService.getAccounts(params)
if (res.code === 0) {
@@ -489,7 +563,7 @@
// 先更新UI
row.status = newStatus
try {
await AccountService.updateAccount(row.ID, { status: newStatus })
await AccountService.updateAccountStatus(row.ID, newStatus as 0 | 1)
ElMessage.success('状态切换成功')
} catch (error) {
// 切换失败,恢复原状态
@@ -497,6 +571,28 @@
console.error(error)
}
}
// 加载店铺列表
const loadShopList = async (keyword: string = '') => {
try {
const res = await ShopService.getShops({
page: 1,
page_size: 20, // 默认加载20条
status: 1, // 只加载启用的店铺
shop_name: keyword || undefined // 根据店铺名称搜索
})
if (res.code === 0) {
shopList.value = res.data.items || []
}
} catch (error) {
console.error('获取店铺列表失败:', error)
}
}
// 店铺搜索处理
const handleShopSearch = (query: string) => {
loadShopList(query)
}
</script>
<style lang="scss" scoped>

View File

@@ -165,7 +165,7 @@
import type { FormRules } from 'element-plus'
import { useCheckedColumns } from '@/composables/useCheckedColumns'
import ArtButtonTable from '@/components/core/forms/ArtButtonTable.vue'
import { AccountService, RoleService } from '@/api/modules'
import { AccountService, RoleService, ShopService } from '@/api/modules'
import type { SearchFormItem } from '@/types'
import type { PlatformRole, PlatformAccount } from '@/types/api'
import { formatDateTime } from '@/utils/business/format'
@@ -189,12 +189,19 @@
const initialSearchState = {
username: '',
phone: '',
user_type: undefined as number | undefined,
shop_id: undefined as number | undefined,
enterprise_id: undefined as number | undefined,
status: undefined as number | undefined
}
// 响应式表单数据
const searchForm = reactive({ ...initialSearchState })
// 店铺和企业列表
const shopList = ref<any[]>([])
const enterpriseList = ref<any[]>([])
const pagination = reactive({
currentPage: 1,
pageSize: 20,
@@ -225,7 +232,7 @@
}
// 表单配置项
const searchFormItems: SearchFormItem[] = [
const searchFormItems = computed<SearchFormItem[]>(() => [
{
label: '账号名称',
prop: 'username',
@@ -244,6 +251,35 @@
placeholder: '请输入手机号'
}
},
{
label: '账号类型',
prop: 'user_type',
type: 'select',
options: [
{ label: '超级管理员', value: 1 },
{ label: '平台用户', value: 2 },
{ label: '代理账号', value: 3 },
{ label: '企业账号', value: 4 }
],
config: {
clearable: true,
placeholder: '请选择账号类型'
}
},
{
label: '关联店铺',
prop: 'shop_id',
type: 'select',
options: shopList.value.map((shop) => ({
label: shop.shop_name,
value: shop.id
})),
config: {
clearable: true,
filterable: true,
placeholder: '请选择店铺'
}
},
{
label: '状态',
prop: 'status',
@@ -254,7 +290,7 @@
placeholder: '请选择状态'
}
}
]
])
// 列配置
const columnOptions = [
@@ -262,6 +298,8 @@
{ label: '账号名称', prop: 'username' },
{ label: '手机号', prop: 'phone' },
{ label: '账号类型', prop: 'user_type' },
{ label: '店铺名称', prop: 'shop_name' },
{ label: '企业名称', prop: 'enterprise_name' },
{ label: '状态', prop: 'status' },
{ label: '创建时间', prop: 'CreatedAt' },
{ label: '操作', prop: 'operation' }
@@ -284,7 +322,7 @@
formData.user_type = row.user_type
formData.enterprise_id = row.enterprise_id || null
formData.shop_id = row.shop_id || null
formData.status = row.status as CommonStatus
formData.status = row.status as unknown as CommonStatus
formData.password = ''
} else {
formData.id = 0
@@ -333,19 +371,23 @@
const { columnChecks, columns } = useCheckedColumns(() => [
{
prop: 'ID',
label: 'ID'
label: 'ID',
width: 80
},
{
prop: 'username',
label: '账号名称'
label: '账号名称',
minWidth: 120
},
{
prop: 'phone',
label: '手机号'
label: '手机号',
width: 130
},
{
prop: 'user_type',
label: '账号类型',
width: 120,
formatter: (row: PlatformAccount) => {
const typeMap: Record<number, string> = {
1: '超级管理员',
@@ -356,9 +398,26 @@
return typeMap[row.user_type] || '-'
}
},
{
prop: 'shop_name',
label: '店铺名称',
minWidth: 150,
formatter: (row: PlatformAccount) => {
return row.shop_name || '-'
}
},
{
prop: 'enterprise_name',
label: '企业名称',
minWidth: 150,
formatter: (row: PlatformAccount) => {
return row.enterprise_name || '-'
}
},
{
prop: 'status',
label: '状态',
width: 100,
formatter: (row: PlatformAccount) => {
return h(ElSwitch, {
modelValue: row.status,
@@ -375,6 +434,7 @@
{
prop: 'CreatedAt',
label: '创建时间',
width: 180,
formatter: (row: PlatformAccount) => formatDateTime(row.CreatedAt)
},
{
@@ -429,6 +489,7 @@
onMounted(() => {
getAccountList()
loadAllRoles()
loadShopList()
})
// 加载所有角色列表
@@ -512,9 +573,11 @@
const params = {
page: pagination.currentPage,
pageSize: pagination.pageSize,
user_type: 2, // 筛选平台账号
username: searchForm.username || undefined,
phone: searchForm.phone || undefined,
user_type: searchForm.user_type, // 账号类型筛选(可选)
shop_id: searchForm.shop_id, // 店铺筛选
enterprise_id: searchForm.enterprise_id, // 企业筛选
status: searchForm.status
}
const res = await AccountService.getAccounts(params)
@@ -659,6 +722,22 @@
console.error(error)
}
}
// 加载店铺列表
const loadShopList = async () => {
try {
const res = await ShopService.getShops({
page: 1,
page_size: 9999,
status: 1 // 只加载启用的店铺
})
if (res.code === 0) {
shopList.value = res.data.items || []
}
} catch (error) {
console.error('获取店铺列表失败:', error)
}
}
</script>
<style lang="scss" scoped>