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