后台管理页面用户管理新增用户优化
This commit is contained in:
@@ -37,6 +37,7 @@ export interface CreateUserRequest {
|
||||
phone: string
|
||||
password: string
|
||||
type: number
|
||||
shopId?: number
|
||||
}
|
||||
|
||||
export interface UpdateUserRequest {
|
||||
@@ -44,6 +45,7 @@ export interface UpdateUserRequest {
|
||||
nickname?: string
|
||||
phone?: string
|
||||
type?: number
|
||||
shopId?: number
|
||||
}
|
||||
|
||||
export const userApi = {
|
||||
|
||||
@@ -99,27 +99,63 @@
|
||||
<a-select-option :value="4">管理员</a-select-option>
|
||||
</a-select>
|
||||
</a-form-item>
|
||||
<a-form-item v-if="currentUserInfo?.type !== 4" label="所属店铺" name="shopId">
|
||||
<a-select
|
||||
v-model:value="formState.shopId"
|
||||
placeholder="请选择店铺"
|
||||
:loading="shopLoading"
|
||||
:disabled="currentUserInfo?.type !== 4 && currentUserInfo?.shopId"
|
||||
>
|
||||
<a-select-option
|
||||
v-for="shop in shopList"
|
||||
:key="shop.id"
|
||||
:value="shop.id"
|
||||
>
|
||||
{{ shop.shopName }}
|
||||
</a-select-option>
|
||||
</a-select>
|
||||
</a-form-item>
|
||||
<a-form-item v-else label="所属店铺" name="shopId">
|
||||
<a-select
|
||||
v-model:value="formState.shopId"
|
||||
placeholder="请选择店铺(可选)"
|
||||
:loading="shopLoading"
|
||||
allowClear
|
||||
>
|
||||
<a-select-option
|
||||
v-for="shop in shopList"
|
||||
:key="shop.id"
|
||||
:value="shop.id"
|
||||
>
|
||||
{{ shop.shopName }}
|
||||
</a-select-option>
|
||||
</a-select>
|
||||
</a-form-item>
|
||||
</a-form>
|
||||
</a-modal>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, reactive, onMounted } from 'vue'
|
||||
import { ref, reactive, onMounted, computed } from 'vue'
|
||||
import { message, Modal } from 'ant-design-vue'
|
||||
import type { FormInstance } from 'ant-design-vue'
|
||||
import { PlusOutlined } from '@ant-design/icons-vue'
|
||||
import { DEFAULT_AVATAR } from '@/constants'
|
||||
import { userApi, type UserVO } from '@/api/user'
|
||||
import { adminShopApi, type Shop } from '@/api/admin'
|
||||
|
||||
const loading = ref(false)
|
||||
const shopLoading = ref(false)
|
||||
const searchText = ref('')
|
||||
const userList = ref<UserVO[]>([])
|
||||
const shopList = ref<Shop[]>([])
|
||||
const modalVisible = ref(false)
|
||||
const modalLoading = ref(false)
|
||||
const isEdit = ref(false)
|
||||
const formRef = ref<FormInstance>()
|
||||
const currentUser = ref<UserVO | null>(null)
|
||||
const currentUserInfo = getCurrentUserInfo()
|
||||
|
||||
const pagination = reactive({
|
||||
current: 1,
|
||||
@@ -135,7 +171,12 @@ const formState = reactive({
|
||||
nickname: '',
|
||||
phone: '',
|
||||
password: '',
|
||||
type: 0
|
||||
type: 0,
|
||||
shopId: undefined as number | undefined
|
||||
})
|
||||
|
||||
const isShopRequired = computed(() => {
|
||||
return currentUserInfo?.type !== 4
|
||||
})
|
||||
|
||||
const formRules = {
|
||||
@@ -143,7 +184,8 @@ const formRules = {
|
||||
nickname: [{ required: true, message: '请输入昵称', trigger: 'blur' }],
|
||||
phone: [{ required: true, message: '请输入手机号', trigger: 'blur' }],
|
||||
password: [{ required: true, message: '请输入密码', trigger: 'blur' }],
|
||||
type: [{ required: true, message: '请选择用户类型', trigger: 'change' }]
|
||||
type: [{ required: true, message: '请选择用户类型', trigger: 'change' }],
|
||||
shopId: [{ required: isShopRequired.value, message: '请选择店铺', trigger: 'change' }]
|
||||
}
|
||||
|
||||
const columns = [
|
||||
@@ -151,6 +193,7 @@ const columns = [
|
||||
{ title: '账号', dataIndex: 'account', key: 'account' },
|
||||
{ title: '昵称', dataIndex: 'nickname', key: 'nickname' },
|
||||
{ title: '手机号', dataIndex: 'phone', key: 'phone' },
|
||||
{ title: '所属店铺', key: 'shopName', width: 150 },
|
||||
{ title: '用户类型', key: 'type', width: 120 },
|
||||
{ title: '状态', key: 'status', width: 100 },
|
||||
{ title: '创建时间', dataIndex: 'createTime', key: 'createTime' },
|
||||
@@ -189,6 +232,27 @@ const getCurrentUserInfo = () => {
|
||||
return null
|
||||
}
|
||||
|
||||
const fetchShopList = async () => {
|
||||
shopLoading.value = true
|
||||
try {
|
||||
const params: any = {
|
||||
page: 1,
|
||||
size: 100
|
||||
}
|
||||
|
||||
if (currentUserInfo && currentUserInfo.type !== 4 && currentUserInfo.shopId) {
|
||||
params.shopId = currentUserInfo.shopId
|
||||
}
|
||||
|
||||
const res = await adminShopApi.listShops(params)
|
||||
shopList.value = res.list || []
|
||||
} catch (error) {
|
||||
message.error('获取店铺列表失败')
|
||||
} finally {
|
||||
shopLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const fetchUserList = async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
@@ -226,12 +290,14 @@ const handleTableChange = (pag: any) => {
|
||||
|
||||
const showAddModal = () => {
|
||||
isEdit.value = false
|
||||
const defaultShopId = currentUserInfo?.type !== 4 ? currentUserInfo?.shopId : undefined
|
||||
Object.assign(formState, {
|
||||
account: '',
|
||||
nickname: '',
|
||||
phone: '',
|
||||
password: '',
|
||||
type: 0
|
||||
type: 0,
|
||||
shopId: defaultShopId
|
||||
})
|
||||
modalVisible.value = true
|
||||
}
|
||||
@@ -244,7 +310,8 @@ const showEditModal = (record: UserVO) => {
|
||||
nickname: record.nickname,
|
||||
phone: record.phone,
|
||||
password: '',
|
||||
type: record.type
|
||||
type: record.type,
|
||||
shopId: record.shopId
|
||||
})
|
||||
modalVisible.value = true
|
||||
}
|
||||
@@ -313,6 +380,7 @@ const handleDelete = async (record: UserVO) => {
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
fetchShopList()
|
||||
fetchUserList()
|
||||
})
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user