部门管理模块增删改查完成
This commit is contained in:
parent
25bade7644
commit
bcd60063f4
|
|
@ -1,6 +1,6 @@
|
||||||
import { defAxios as request } from '@/utils/http'
|
import { defAxios as request } from '@/utils/http'
|
||||||
/**
|
/**
|
||||||
* 获取部门分页数据接口
|
* 获取部门管理数据接口
|
||||||
* @returns 部门分页
|
* @returns 部门分页
|
||||||
*/
|
*/
|
||||||
export function getDeptList(params) {
|
export function getDeptList(params) {
|
||||||
|
|
|
||||||
|
|
@ -14,75 +14,39 @@
|
||||||
:on-positive-click="handleConfirm"
|
:on-positive-click="handleConfirm"
|
||||||
:on-negative-click="handleClose"
|
:on-negative-click="handleClose"
|
||||||
>
|
>
|
||||||
<n-form-item
|
<n-form-item label="部门编号:" path="code">
|
||||||
label="头像:"
|
|
||||||
path="avatar"
|
|
||||||
>
|
|
||||||
<uploadImage
|
|
||||||
:options="{
|
|
||||||
max:1,
|
|
||||||
action: '/upload/uploadImage/demo',
|
|
||||||
}"
|
|
||||||
/>
|
|
||||||
</n-form-item>
|
|
||||||
<n-form-item label="用户编号:" path="code">
|
|
||||||
<n-input
|
<n-input
|
||||||
v-model:value="form.code"
|
v-model:value="form.code"
|
||||||
clearable
|
clearable
|
||||||
:maxlength="20"
|
:maxlength="20"
|
||||||
placeholder="请输入用户编号"
|
placeholder="请输入部门编号"
|
||||||
/>
|
/>
|
||||||
</n-form-item>
|
</n-form-item>
|
||||||
<n-form-item label="用户账号:" path="username">
|
<n-form-item label="部门名称:" path="name">
|
||||||
<n-input
|
<n-input
|
||||||
v-model:value="form.username"
|
v-model:value="form.name"
|
||||||
clearable
|
clearable
|
||||||
:maxlength="20"
|
:maxlength="20"
|
||||||
placeholder="请输入用户账号"
|
placeholder="请输入部门名称"
|
||||||
/>
|
/>
|
||||||
</n-form-item>
|
</n-form-item>
|
||||||
<n-form-item
|
<n-form-item label="部门全称:" path="fullname">
|
||||||
label="登录密码:"
|
|
||||||
path="password"
|
|
||||||
>
|
|
||||||
<n-input
|
<n-input
|
||||||
v-model:value="form.password"
|
v-model:value="form.fullname"
|
||||||
type="password"
|
|
||||||
:maxlength="20"
|
|
||||||
placeholder="请输入登录密码"
|
|
||||||
/>
|
|
||||||
</n-form-item>
|
|
||||||
<n-form-item label="用户姓名:" path="realname">
|
|
||||||
<n-input
|
|
||||||
v-model:value="form.realname"
|
|
||||||
clearable
|
clearable
|
||||||
:maxlength="20"
|
:maxlength="20"
|
||||||
placeholder="请输入用户姓名"
|
placeholder="请输入部门全称"
|
||||||
/>
|
/>
|
||||||
</n-form-item>
|
</n-form-item>
|
||||||
<n-form-item label="所属部门:" path="deptId">
|
<n-form-item label="所属部门:" path="pid">
|
||||||
<n-select
|
<n-select
|
||||||
v-model:value="form.deptId"
|
v-model:value="form.pid"
|
||||||
:options="deptOptions"
|
:options="getDeptList"
|
||||||
placeholder="请选择所属部门"
|
placeholder="请选择所属部门"
|
||||||
/>
|
/>
|
||||||
</n-form-item>
|
</n-form-item>
|
||||||
<n-form-item label="角色:" path="roleIds">
|
<n-form-item label="排序号" path="sort">
|
||||||
<n-select
|
<n-input-number v-model:value="form.sort" placeholder="请输入排序号" />
|
||||||
v-model:value="form.roleIds"
|
|
||||||
clearable
|
|
||||||
:multiple="true"
|
|
||||||
:options="rolesOptions"
|
|
||||||
placeholder="请选择角色"
|
|
||||||
/>
|
|
||||||
</n-form-item>
|
|
||||||
<n-form-item label="状态" path="status">
|
|
||||||
<n-radio-group
|
|
||||||
v-model:value="form.status"
|
|
||||||
>
|
|
||||||
<n-radio :value="1">正常</n-radio>
|
|
||||||
<n-radio :value="2">禁用</n-radio>
|
|
||||||
</n-radio-group>
|
|
||||||
</n-form-item>
|
</n-form-item>
|
||||||
<n-form-item
|
<n-form-item
|
||||||
label="备注:"
|
label="备注:"
|
||||||
|
|
@ -101,16 +65,12 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { defineComponent, computed, onMounted, reactive, toRefs } from 'vue'
|
import { defineComponent, computed, reactive, toRefs } from 'vue'
|
||||||
import Modal from '@/components/Modal/index.vue'
|
import Modal from '@/components/Modal/index.vue'
|
||||||
import uploadImage from '@/components/ImgUpload/index.vue'
|
import { addDept, editDept } from '@/api/system/dept/index'
|
||||||
import { getDeptAll } from '@/api/system/dept/index'
|
|
||||||
import { getRoleAll } from '@/api/system/role/index'
|
|
||||||
import { addUser, editUser } from '@/api/system/user/index'
|
|
||||||
import { dataToSelect } from '@/utils/handleData.js'
|
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
name: 'UserModal',
|
name: 'UserModal',
|
||||||
components: { Modal, uploadImage },
|
components: { Modal },
|
||||||
props: {
|
props: {
|
||||||
visible: {
|
visible: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
|
|
@ -119,6 +79,10 @@ export default defineComponent({
|
||||||
row: {
|
row: {
|
||||||
type: Object,
|
type: Object,
|
||||||
default: () => {}
|
default: () => {}
|
||||||
|
},
|
||||||
|
deptList: {
|
||||||
|
type: Array,
|
||||||
|
default: () => []
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
emits: {
|
emits: {
|
||||||
|
|
@ -142,34 +106,38 @@ export default defineComponent({
|
||||||
deptOptions: [],
|
deptOptions: [],
|
||||||
rolesOptions: [],
|
rolesOptions: [],
|
||||||
rules: {
|
rules: {
|
||||||
avatar: [
|
|
||||||
{ required: true, message: '请选择头像', type: 'string', trigger: 'blur' }
|
|
||||||
],
|
|
||||||
code: [
|
code: [
|
||||||
{ required: true, message: '请输入编号', trigger: 'blur' }
|
{ required: true, message: '请输入部门编号', trigger: 'blur' }
|
||||||
],
|
],
|
||||||
realname: [
|
name: [
|
||||||
{ required: true, message: '请输入用户姓名', type: 'string', trigger: 'blur' }
|
{ required: true, message: '请输入部门名称', type: 'string', trigger: 'blur' }
|
||||||
],
|
],
|
||||||
deptId: [
|
sort: [
|
||||||
{ required: true, message: '请选择部门', type: 'number', trigger: 'blur' }
|
{ required: true, type: 'number', message: '请输入排序号', trigger: 'blur' }
|
||||||
],
|
|
||||||
status: [
|
|
||||||
{ required: true, message: '请选择状态', type: 'number', trigger: 'blur' }
|
|
||||||
],
|
|
||||||
roleIds: [
|
|
||||||
{ required: true, message: '请选择角色', type: 'array', trigger: 'blur' }
|
|
||||||
],
|
|
||||||
username: [
|
|
||||||
{ required: true, message: '请输入用户账号', type: 'string', trigger: 'blur' }
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
// 获取部门选项
|
||||||
|
const getDeptList = computed(() => {
|
||||||
|
const list = props.deptList.map((item) => {
|
||||||
|
const menu = {
|
||||||
|
label: item.name,
|
||||||
|
value: item.id
|
||||||
|
}
|
||||||
|
return menu
|
||||||
|
})
|
||||||
|
return list
|
||||||
|
})
|
||||||
|
|
||||||
const getModalOptions = computed(() => {
|
const getModalOptions = computed(() => {
|
||||||
|
const row = props.row
|
||||||
|
if (props.row.pid === 0) {
|
||||||
|
row.pid = null
|
||||||
|
}
|
||||||
return {
|
return {
|
||||||
title: Object.keys(props.row).length === 0 ? '添加用户' : '编辑用户',
|
title: props.row.name ? '编辑部门' : '添加部门',
|
||||||
show: props.visible,
|
show: props.visible,
|
||||||
form: Object.assign(data.form, props.row),
|
form: Object.assign(data.form, row),
|
||||||
negativeText: '取消',
|
negativeText: '取消',
|
||||||
positiveText: '确认'
|
positiveText: '确认'
|
||||||
}
|
}
|
||||||
|
|
@ -180,44 +148,21 @@ export default defineComponent({
|
||||||
emit('update:visible', false)
|
emit('update:visible', false)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取部门列表
|
|
||||||
async function getDeptOptions() {
|
|
||||||
const res = await getDeptAll()
|
|
||||||
data.deptOptions = dataToSelect(res.data, { label: 'name', value: 'id' })
|
|
||||||
}
|
|
||||||
|
|
||||||
// 获取角色列表
|
|
||||||
async function getRoleOptions() {
|
|
||||||
const res = await getRoleAll()
|
|
||||||
data.rolesOptions = dataToSelect(res.data, { label: 'name', value: 'id' })
|
|
||||||
}
|
|
||||||
|
|
||||||
onMounted(() => {
|
|
||||||
getDeptOptions()
|
|
||||||
getRoleOptions()
|
|
||||||
})
|
|
||||||
|
|
||||||
// 上传文件
|
|
||||||
const handleUpload = ({ file }) => {
|
|
||||||
console.log(file)
|
|
||||||
// data.form.avatar = file.url
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...toRefs(data),
|
...toRefs(data),
|
||||||
|
getDeptList,
|
||||||
getModalOptions,
|
getModalOptions,
|
||||||
handleClose,
|
handleClose
|
||||||
handleUpload
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
// 表单提交
|
// 表单提交
|
||||||
handleConfirm() {
|
handleConfirm() {
|
||||||
const type = Object.keys(this.row).length === 0 ? 'add' : 'edit'
|
const type = this.row.name ? 'edit' : 'add'
|
||||||
this.$refs.formRef.validate((errors) => {
|
this.$refs.formRef.validate((errors) => {
|
||||||
if (!errors) {
|
if (!errors) {
|
||||||
if (type === 'add') {
|
if (type === 'add') {
|
||||||
addUser(this.form).then(res => {
|
addDept(this.form).then(res => {
|
||||||
if (res.code === 0) {
|
if (res.code === 0) {
|
||||||
this.handleClose()
|
this.handleClose()
|
||||||
this.$emit('done')
|
this.$emit('done')
|
||||||
|
|
@ -229,7 +174,7 @@ export default defineComponent({
|
||||||
console.log(e)
|
console.log(e)
|
||||||
})
|
})
|
||||||
} else if (type === 'edit') {
|
} else if (type === 'edit') {
|
||||||
editUser(this.form).then(res => {
|
editDept(this.form).then(res => {
|
||||||
if (res.code === 0) {
|
if (res.code === 0) {
|
||||||
this.handleClose()
|
this.handleClose()
|
||||||
this.$emit('done')
|
this.$emit('done')
|
||||||
|
|
|
||||||
|
|
@ -3,10 +3,10 @@
|
||||||
<n-card>
|
<n-card>
|
||||||
<headSearch :info="info" @search="handleSearch" />
|
<headSearch :info="info" @search="handleSearch" />
|
||||||
<data-table
|
<data-table
|
||||||
|
ref="tableRef"
|
||||||
:columns="columns"
|
:columns="columns"
|
||||||
:data="data"
|
|
||||||
:request="loadDataTable"
|
:request="loadDataTable"
|
||||||
:row-key="(row) => row.id"
|
:pagination="false"
|
||||||
data-type="tree"
|
data-type="tree"
|
||||||
size="large"
|
size="large"
|
||||||
scroll-x="1200"
|
scroll-x="1200"
|
||||||
|
|
@ -22,6 +22,7 @@
|
||||||
v-if="modalShow"
|
v-if="modalShow"
|
||||||
v-model:visible="modalShow"
|
v-model:visible="modalShow"
|
||||||
:row="rowData"
|
:row="rowData"
|
||||||
|
:dept-list="deptList"
|
||||||
@done="handleSearch"
|
@done="handleSearch"
|
||||||
/>
|
/>
|
||||||
</template>
|
</template>
|
||||||
|
|
@ -30,8 +31,8 @@
|
||||||
import headSearch from '@/components/Search/index.vue'
|
import headSearch from '@/components/Search/index.vue'
|
||||||
import dataTable from '@/components/DataTable/index.vue'
|
import dataTable from '@/components/DataTable/index.vue'
|
||||||
import TableAction from '@/components/DataTable/tools/Action.vue'
|
import TableAction from '@/components/DataTable/tools/Action.vue'
|
||||||
import { getDeptList, deleteDept } from '@/api/system/dept/index.js'
|
import { getDeptList, getDeptAll, deleteDept } from '@/api/system/dept/index.js'
|
||||||
import { h, unref, toRefs, ref, reactive } from 'vue'
|
import { h, unref, toRefs, ref, reactive, onMounted } from 'vue'
|
||||||
import DeptModal from './components/DeptModal.vue'
|
import DeptModal from './components/DeptModal.vue'
|
||||||
import info from './info.js'
|
import info from './info.js'
|
||||||
export default {
|
export default {
|
||||||
|
|
@ -55,34 +56,22 @@ export default {
|
||||||
key: 'fullname',
|
key: 'fullname',
|
||||||
align: 'center'
|
align: 'center'
|
||||||
},
|
},
|
||||||
{
|
|
||||||
title: '部门类型',
|
|
||||||
key: 'type',
|
|
||||||
align: 'center',
|
|
||||||
width: 100
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
title: '排序',
|
title: '排序',
|
||||||
key: 'sort',
|
key: 'sort',
|
||||||
align: 'center'
|
align: 'center'
|
||||||
},
|
},
|
||||||
{
|
|
||||||
title: '备注',
|
|
||||||
key: 'note',
|
|
||||||
align: 'center',
|
|
||||||
width: 100
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
title: '创建时间',
|
title: '创建时间',
|
||||||
key: 'createTime',
|
key: 'createTime',
|
||||||
align: 'center',
|
align: 'center',
|
||||||
width: 160
|
minWidth: 120
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: '更新时间',
|
title: '更新时间',
|
||||||
key: 'updateTime',
|
key: 'updateTime',
|
||||||
align: 'center',
|
align: 'center',
|
||||||
width: 160
|
minWidth: 120
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: '操作',
|
title: '操作',
|
||||||
|
|
@ -97,18 +86,29 @@ export default {
|
||||||
type: 'button',
|
type: 'button',
|
||||||
props: {
|
props: {
|
||||||
type: 'primary',
|
type: 'primary',
|
||||||
onClick: play.bind(null, row)
|
onClick: add.bind(null, row)
|
||||||
},
|
},
|
||||||
auth: 'basic_list'
|
auth: 'basic_list'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: '修改',
|
label: '修改',
|
||||||
|
type: 'button',
|
||||||
|
props: {
|
||||||
|
type: 'primary',
|
||||||
|
onClick: play.bind(null, row)
|
||||||
|
},
|
||||||
auth: 'basic_list'
|
auth: 'basic_list'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: '删除',
|
label: '删除',
|
||||||
type: 'popconfirm',
|
type: 'popconfirm',
|
||||||
auth: 'basic_list'
|
auth: 'basic_list',
|
||||||
|
tip: '确定删除这条数据吗?',
|
||||||
|
props: {
|
||||||
|
negativeText: '取消',
|
||||||
|
positiveText: '确认',
|
||||||
|
onPositiveClick: deleteSingle.bind(null, row.id)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
align: 'center'
|
align: 'center'
|
||||||
|
|
@ -116,23 +116,24 @@ export default {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
data: [],
|
|
||||||
info: ref(info),
|
info: ref(info),
|
||||||
modalShow: false,
|
modalShow: false,
|
||||||
rowData: {}
|
rowData: {
|
||||||
|
status: 1,
|
||||||
|
type: 0,
|
||||||
|
hide: 0
|
||||||
|
},
|
||||||
|
deptList: []
|
||||||
})
|
})
|
||||||
|
|
||||||
// 新增
|
// 获取全部菜单信息
|
||||||
function handleModal() {
|
async function getDept() {
|
||||||
data.modalShow = true
|
const list = await getDeptAll()
|
||||||
|
data.deptList = list.data
|
||||||
}
|
}
|
||||||
|
onMounted(() => {
|
||||||
// 编辑
|
getDept()
|
||||||
function play(row) {
|
})
|
||||||
data.rowData = row
|
|
||||||
data.modalShow = true
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description: 获取部门数据并做树形结构处理
|
* @description: 获取部门数据并做树形结构处理
|
||||||
* @return {*}
|
* @return {*}
|
||||||
|
|
@ -156,7 +157,46 @@ export default {
|
||||||
return await getDeptList(_params)
|
return await getDeptList(_params)
|
||||||
}
|
}
|
||||||
|
|
||||||
return { ...toRefs(data), loadDataTable, handleSearch, handleModal }
|
// 新增
|
||||||
|
function handleModal() {
|
||||||
|
data.modalShow = true
|
||||||
|
data.rowData = {}
|
||||||
|
}
|
||||||
|
// 行内新增
|
||||||
|
function add(row) {
|
||||||
|
data.modalShow = true
|
||||||
|
data.rowData = {}
|
||||||
|
data.rowData.pid = row.id
|
||||||
|
}
|
||||||
|
|
||||||
|
// 编辑
|
||||||
|
function play(row) {
|
||||||
|
data.rowData = row
|
||||||
|
data.modalShow = true
|
||||||
|
}
|
||||||
|
|
||||||
|
// 单个删除数据
|
||||||
|
function deleteSingle(id) {
|
||||||
|
deleteData(id)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 删除方法
|
||||||
|
function deleteData(id) {
|
||||||
|
deleteDept(id)
|
||||||
|
.then((res) => {
|
||||||
|
if (res.code === 0) {
|
||||||
|
handleSearch({})
|
||||||
|
$message.success(res.msg)
|
||||||
|
} else {
|
||||||
|
$message.error(res.msg)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch((e) => {
|
||||||
|
console.log(e)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return { ...toRefs(data), tableRef, loadDataTable, handleSearch, handleModal, deleteSingle }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
|
||||||
|
|
@ -12,8 +12,8 @@
|
||||||
<n-form-item label="上级菜单" path="pid">
|
<n-form-item label="上级菜单" path="pid">
|
||||||
<n-select
|
<n-select
|
||||||
v-model:value="form.pid"
|
v-model:value="form.pid"
|
||||||
placeholder="请选择上级菜单"
|
|
||||||
:options="getMenuList"
|
:options="getMenuList"
|
||||||
|
placeholder="请选择上级菜单"
|
||||||
/>
|
/>
|
||||||
</n-form-item>
|
</n-form-item>
|
||||||
</n-gi>
|
</n-gi>
|
||||||
|
|
@ -128,6 +128,7 @@ export default defineComponent({
|
||||||
}],
|
}],
|
||||||
sort: [{
|
sort: [{
|
||||||
required: true,
|
required: true,
|
||||||
|
type: 'number',
|
||||||
message: '请输入排序号',
|
message: '请输入排序号',
|
||||||
trigger: 'blur'
|
trigger: 'blur'
|
||||||
}]
|
}]
|
||||||
|
|
@ -192,7 +193,7 @@ export default defineComponent({
|
||||||
methods: {
|
methods: {
|
||||||
// 表单提交
|
// 表单提交
|
||||||
handleConfirm() {
|
handleConfirm() {
|
||||||
const type = this.data.title ? 'add' : 'edit'
|
const type = this.data.title ? 'edit' : 'add'
|
||||||
this.$refs.formRef.validate((errors) => {
|
this.$refs.formRef.validate((errors) => {
|
||||||
if (!errors) {
|
if (!errors) {
|
||||||
if (type === 'add') {
|
if (type === 'add') {
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@
|
||||||
:request="loadDataTable"
|
:request="loadDataTable"
|
||||||
>
|
>
|
||||||
<template #tableTitle>
|
<template #tableTitle>
|
||||||
<n-button type="primary" @click="handlleRoleAdd"> 添加菜单 </n-button>
|
<n-button type="primary" @click="handleModal"> 添加菜单 </n-button>
|
||||||
</template>
|
</template>
|
||||||
</data-table>
|
</data-table>
|
||||||
</n-card>
|
</n-card>
|
||||||
|
|
@ -217,7 +217,7 @@ export default {
|
||||||
}
|
}
|
||||||
|
|
||||||
// 打开新增弹框
|
// 打开新增弹框
|
||||||
function handlleRoleAdd() {
|
function handleModal() {
|
||||||
data.modalShow = true
|
data.modalShow = true
|
||||||
data.rowData = {}
|
data.rowData = {}
|
||||||
}
|
}
|
||||||
|
|
@ -258,7 +258,7 @@ export default {
|
||||||
tableRef,
|
tableRef,
|
||||||
loadDataTable,
|
loadDataTable,
|
||||||
handleSearch,
|
handleSearch,
|
||||||
handlleRoleAdd,
|
handleModal,
|
||||||
deleteSingle
|
deleteSingle
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue