feat: 完成user新增编辑详情接口对接
This commit is contained in:
@@ -16,6 +16,22 @@ export const getSubCompOpt = () => {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 查询角色信息
|
||||||
|
export const getRolesOpt = () => {
|
||||||
|
return request({
|
||||||
|
url: '/admin/role/option',
|
||||||
|
method: 'get',
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取岗位下拉
|
||||||
|
export const getJobOpt = () => {
|
||||||
|
return request({
|
||||||
|
url: '/admin/job/option',
|
||||||
|
method: 'get',
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
export const getUserList = (params) => {
|
export const getUserList = (params) => {
|
||||||
return request({
|
return request({
|
||||||
url: '/admin/user',
|
url: '/admin/user',
|
||||||
@@ -23,18 +39,17 @@ export const getUserList = (params) => {
|
|||||||
params
|
params
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
//获取用户详情
|
//获取用户详情
|
||||||
export const getUserDetail = (userId) => {
|
export const getUserDetail = (userId) => {
|
||||||
return request({
|
return request({
|
||||||
url: `/admin/user/info/${userId}`,
|
url: `/admin/mosr/user/info/${userId}`,
|
||||||
method: "get"
|
method: "get"
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
// 新增用户
|
// 新增用户
|
||||||
export const addUser = (data) => {
|
export const addUser = (data) => {
|
||||||
return request({
|
return request({
|
||||||
url: '/admin/user',
|
url: '/admin/mosr/user',
|
||||||
method: 'post',
|
method: 'post',
|
||||||
data
|
data
|
||||||
})
|
})
|
||||||
@@ -42,7 +57,7 @@ export const addUser = (data) => {
|
|||||||
// 修改用户
|
// 修改用户
|
||||||
export const editUser = (data) => {
|
export const editUser = (data) => {
|
||||||
return request({
|
return request({
|
||||||
url: '/admin/user',
|
url: '/admin/mosr/user',
|
||||||
method: 'put',
|
method: 'put',
|
||||||
data
|
data
|
||||||
})
|
})
|
||||||
|
|||||||
235
src/views/system/user/add.vue
Normal file
235
src/views/system/user/add.vue
Normal file
@@ -0,0 +1,235 @@
|
|||||||
|
<template>
|
||||||
|
<baseTitle :title="'用户信息录入'"></baseTitle>
|
||||||
|
<fvForm :schema="schame" @getInstance="getInstance" :rules="rules"></fvForm>
|
||||||
|
<div class="oper-page-btn">
|
||||||
|
<el-button type="primary" @click="handleSubmit">提交</el-button>
|
||||||
|
<el-button type="primary" @click="handleBack">返回</el-button>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="jsx">
|
||||||
|
import { addUser, editUser } from '@/api/user/user.js'
|
||||||
|
import { ElLoading, ElNotification } from 'element-plus';
|
||||||
|
import { useTagsView } from '@/stores/tagsview.js'
|
||||||
|
import { useAuthStore } from '@/stores/userstore.js'
|
||||||
|
import { useCacheStore } from "@/stores/cache.js";
|
||||||
|
import { getDeptOpt, getSubCompOpt, getRolesOpt, getJobOpt, getUserDetail } from '@/api/user/user.js'
|
||||||
|
|
||||||
|
const tagsViewStore = useTagsView()
|
||||||
|
const authStore = useAuthStore()
|
||||||
|
const cacheStore = useCacheStore();
|
||||||
|
const route = useRoute()
|
||||||
|
|
||||||
|
const form = ref(null)
|
||||||
|
|
||||||
|
const localData = reactive({
|
||||||
|
subCompanyIdOpt: [],
|
||||||
|
departmentIdOpt: [],
|
||||||
|
roleOpt: [],
|
||||||
|
jobOpt: []
|
||||||
|
})
|
||||||
|
|
||||||
|
const schame = computed(()=>{
|
||||||
|
let arr = [
|
||||||
|
{
|
||||||
|
label: '子公司',
|
||||||
|
prop: 'subCompanyId',
|
||||||
|
component: 'el-tree-select',
|
||||||
|
props: {
|
||||||
|
placeholder: '请输入',
|
||||||
|
clearable: true,
|
||||||
|
filterable: true,
|
||||||
|
checkStrictly: true,
|
||||||
|
data: localData.subCompanyIdOpt
|
||||||
|
},
|
||||||
|
on: {
|
||||||
|
change: async (val) => {
|
||||||
|
const { data } = await getDeptOpt({subCompanyId: val})
|
||||||
|
localData.departmentIdOpt = data
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '归属部门',
|
||||||
|
prop: 'departmentId',
|
||||||
|
component: 'el-tree-select',
|
||||||
|
props: {
|
||||||
|
placeholder: '请选择',
|
||||||
|
clearable: true,
|
||||||
|
data: localData.departmentIdOpt,
|
||||||
|
filterable: true,
|
||||||
|
checkStrictly: true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '用户账号',
|
||||||
|
prop: 'userName',
|
||||||
|
component: 'el-input',
|
||||||
|
props: {
|
||||||
|
placeholder: '请输入'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '用户昵称',
|
||||||
|
prop: 'nickName',
|
||||||
|
component: 'el-input',
|
||||||
|
props: {
|
||||||
|
placeholder: '请输入'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '用户密码',
|
||||||
|
prop: 'password',
|
||||||
|
component: 'el-input',
|
||||||
|
props: {
|
||||||
|
placeholder: '请输入',
|
||||||
|
type: 'password'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '岗位',
|
||||||
|
prop: 'jobId',
|
||||||
|
component: 'el-tree-select',
|
||||||
|
props: {
|
||||||
|
placeholder: '请选择',
|
||||||
|
filterable: true,
|
||||||
|
checkStrictly: true,
|
||||||
|
data: localData.jobOpt
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '角色',
|
||||||
|
prop: 'roleIds',
|
||||||
|
component: 'el-tree-select',
|
||||||
|
props: {
|
||||||
|
placeholder: '请选择',
|
||||||
|
multiple: true,
|
||||||
|
data: localData.roleOpt
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '性别',
|
||||||
|
prop: 'sex',
|
||||||
|
component: 'el-tree-select',
|
||||||
|
props: {
|
||||||
|
placeholder: '请选择',
|
||||||
|
data: cacheStore.getDict('user_sex')
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '帐号状态',
|
||||||
|
prop: 'state',
|
||||||
|
component: 'el-tree-select',
|
||||||
|
props: {
|
||||||
|
placeholder: '请选择',
|
||||||
|
data: cacheStore.getDict('normal_disable')
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '手机号码',
|
||||||
|
prop: 'mobile',
|
||||||
|
component: 'el-input',
|
||||||
|
props: {
|
||||||
|
placeholder: '请输入'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '邮箱',
|
||||||
|
prop: 'email',
|
||||||
|
component: 'el-input',
|
||||||
|
props: {
|
||||||
|
placeholder: '请输入'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
]
|
||||||
|
let editArr = []
|
||||||
|
if(!route.query.isAdd) {
|
||||||
|
arr.forEach(item=>{
|
||||||
|
if(item.prop != 'password') {
|
||||||
|
editArr.push(item)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
return !authStore.roles.includes('superAdmin') ? editArr.slice(1) : editArr
|
||||||
|
}
|
||||||
|
return !authStore.roles.includes('superAdmin') ? arr.slice(1) : arr
|
||||||
|
})
|
||||||
|
|
||||||
|
const rules = reactive({
|
||||||
|
userName: [{required: true, message: '请输入', trigger: 'change'}],
|
||||||
|
nickName: [{required: true, message: '请输入', trigger: 'change'}],
|
||||||
|
password: [{required: true, message: '请输入', trigger: 'change'}],
|
||||||
|
departmentId: [{required: true, message: '请选择', trigger: 'change'}],
|
||||||
|
subCompanyId: [{required: true, message: '请选择', trigger: 'change'}],
|
||||||
|
jobId: [{required: true, message: '请选择', trigger: 'change'}],
|
||||||
|
roleIds: [{required: true, message: '请选择', trigger: 'change'}],
|
||||||
|
sex: [{required: true, message: '请选择', trigger: 'change'}],
|
||||||
|
state: [{required: true, message: '请选择', trigger: 'change'}],
|
||||||
|
})
|
||||||
|
|
||||||
|
const getInstance = (e) => {
|
||||||
|
form.value = e
|
||||||
|
}
|
||||||
|
|
||||||
|
const init = async () => {
|
||||||
|
const { data } = await getDeptOpt()
|
||||||
|
localData.departmentIdOpt = data
|
||||||
|
const res = await getSubCompOpt()
|
||||||
|
localData.subCompanyIdOpt = res.data
|
||||||
|
const roleRes = await getRolesOpt()
|
||||||
|
localData.roleOpt = roleRes.data
|
||||||
|
const jobRes = await getJobOpt()
|
||||||
|
localData.jobOpt = jobRes.data
|
||||||
|
}
|
||||||
|
|
||||||
|
const getInfo = async () => {
|
||||||
|
if(!route.query.id) return
|
||||||
|
// 获取详情数据
|
||||||
|
const { data } = await getUserDetail(route.query.id)
|
||||||
|
form.value.setValues(data)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleSubmit = async () => {
|
||||||
|
const loading = ElLoading.service({fullscreen: true})
|
||||||
|
try {
|
||||||
|
const { isValidate } = await form.value.validate()
|
||||||
|
if(!isValidate) return Promise.reject()
|
||||||
|
const values = form.value.getValues()
|
||||||
|
let message
|
||||||
|
if(route.query.isAdd) {
|
||||||
|
const { code, msg } = await addUser(values)
|
||||||
|
code === 1000 ? message = msg : null
|
||||||
|
} else {
|
||||||
|
const { code, msg } = await editUser(values)
|
||||||
|
code === 1000 ? message = msg : null
|
||||||
|
}
|
||||||
|
ElNotification({
|
||||||
|
title: route.query.isAdd ? '新增' : '编辑',
|
||||||
|
message: message,
|
||||||
|
type: 'success'
|
||||||
|
})
|
||||||
|
loading.close()
|
||||||
|
tagsViewStore.delViewAndGoView('/system/user')
|
||||||
|
} catch {
|
||||||
|
loading.close()
|
||||||
|
return Promise.reject()
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleBack = () => {
|
||||||
|
history.back()
|
||||||
|
}
|
||||||
|
|
||||||
|
onMounted(()=>{
|
||||||
|
if(!route.query.isAdd) {
|
||||||
|
getInfo()
|
||||||
|
}
|
||||||
|
init()
|
||||||
|
})
|
||||||
|
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss" scoped>
|
||||||
|
|
||||||
|
</style>
|
||||||
@@ -7,9 +7,11 @@
|
|||||||
import Tag from '@/components/Tag.vue'
|
import Tag from '@/components/Tag.vue'
|
||||||
import fvSelect from '@/fvcomponents/fvSelect/index.vue'
|
import fvSelect from '@/fvcomponents/fvSelect/index.vue'
|
||||||
import { useAuthStore } from '@/stores/userstore.js'
|
import { useAuthStore } from '@/stores/userstore.js'
|
||||||
import { getDeptOpt, getSubCompOpt } from '../../../api/user/user';
|
import { getDeptOpt, getSubCompOpt } from '../../../api/user/user.js';
|
||||||
|
import { ElMessageBox } from 'element-plus';
|
||||||
|
|
||||||
const authStore = useAuthStore()
|
const authStore = useAuthStore()
|
||||||
|
const router = useRouter()
|
||||||
|
|
||||||
const searchConfig = ref([
|
const searchConfig = ref([
|
||||||
{
|
{
|
||||||
@@ -117,15 +119,18 @@ const tableConfig = reactive({
|
|||||||
currentRender: ({row, index}) => {
|
currentRender: ({row, index}) => {
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<el-button type="primary" link>编辑</el-button>
|
<el-button type="primary" link onClick={()=>handleEdit(row)}>编辑</el-button>
|
||||||
<el-button type="danger" link>删除</el-button>
|
<el-button type="danger" link onClick={()=>handleDel(row)}>删除</el-button>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
api: '/admin/mosr/user',
|
api: '/admin/mosr/user',
|
||||||
params: {}
|
params: {},
|
||||||
|
btns: [
|
||||||
|
{name: '新增', type: 'primary', auth: ['admin:user:add'], key: 'add'}
|
||||||
|
]
|
||||||
})
|
})
|
||||||
|
|
||||||
const init = async () => {
|
const init = async () => {
|
||||||
@@ -147,7 +152,40 @@ const search = (val) => {
|
|||||||
tableIns.value.refresh()
|
tableIns.value.refresh()
|
||||||
}
|
}
|
||||||
|
|
||||||
const headBtnClick = (key) => {}
|
const handleAdd = () => {
|
||||||
|
router.push({
|
||||||
|
path: '/system/useradd',
|
||||||
|
query: {
|
||||||
|
isAdd: 1
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleEdit = (row) => {
|
||||||
|
router.push({
|
||||||
|
path: '/system/useredit',
|
||||||
|
query: {
|
||||||
|
id: row.userId
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleDel = (row) => {
|
||||||
|
ElMessageBox.confirm('确定删除该条数据吗?', '确定删除', {
|
||||||
|
type: 'warning',
|
||||||
|
confirmButtonText: '确定',
|
||||||
|
cancelButtonText: '取消'
|
||||||
|
}).then(async res => {
|
||||||
|
// const { code } = await
|
||||||
|
}).catch(()=>{})
|
||||||
|
}
|
||||||
|
|
||||||
|
const headBtnClick = (key) => {
|
||||||
|
switch(key) {
|
||||||
|
case 'add': handleAdd()
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
|
|||||||
Reference in New Issue
Block a user