|
|
@@ -14,75 +14,39 @@ |
|
|
|
:on-positive-click="handleConfirm" |
|
|
|
:on-negative-click="handleClose" |
|
|
|
> |
|
|
|
<n-form-item |
|
|
|
label="头像:" |
|
|
|
path="avatar" |
|
|
|
> |
|
|
|
<uploadImage |
|
|
|
:options="{ |
|
|
|
max:1, |
|
|
|
action: '/upload/uploadImage/demo', |
|
|
|
}" |
|
|
|
/> |
|
|
|
</n-form-item> |
|
|
|
<n-form-item label="用户编号:" path="code"> |
|
|
|
<n-form-item label="部门编号:" path="code"> |
|
|
|
<n-input |
|
|
|
v-model:value="form.code" |
|
|
|
clearable |
|
|
|
:maxlength="20" |
|
|
|
placeholder="请输入用户编号" |
|
|
|
placeholder="请输入部门编号" |
|
|
|
/> |
|
|
|
</n-form-item> |
|
|
|
<n-form-item label="用户账号:" path="username"> |
|
|
|
<n-form-item label="部门名称:" path="name"> |
|
|
|
<n-input |
|
|
|
v-model:value="form.username" |
|
|
|
v-model:value="form.name" |
|
|
|
clearable |
|
|
|
:maxlength="20" |
|
|
|
placeholder="请输入用户账号" |
|
|
|
/> |
|
|
|
</n-form-item> |
|
|
|
<n-form-item |
|
|
|
label="登录密码:" |
|
|
|
path="password" |
|
|
|
> |
|
|
|
<n-input |
|
|
|
v-model:value="form.password" |
|
|
|
type="password" |
|
|
|
:maxlength="20" |
|
|
|
placeholder="请输入登录密码" |
|
|
|
placeholder="请输入部门名称" |
|
|
|
/> |
|
|
|
</n-form-item> |
|
|
|
<n-form-item label="用户姓名:" path="realname"> |
|
|
|
<n-form-item label="部门全称:" path="fullname"> |
|
|
|
<n-input |
|
|
|
v-model:value="form.realname" |
|
|
|
v-model:value="form.fullname" |
|
|
|
clearable |
|
|
|
:maxlength="20" |
|
|
|
placeholder="请输入用户姓名" |
|
|
|
placeholder="请输入部门全称" |
|
|
|
/> |
|
|
|
</n-form-item> |
|
|
|
<n-form-item label="所属部门:" path="deptId"> |
|
|
|
<n-form-item label="所属部门:" path="pid"> |
|
|
|
<n-select |
|
|
|
v-model:value="form.deptId" |
|
|
|
:options="deptOptions" |
|
|
|
v-model:value="form.pid" |
|
|
|
:options="getDeptList" |
|
|
|
placeholder="请选择所属部门" |
|
|
|
/> |
|
|
|
</n-form-item> |
|
|
|
<n-form-item label="角色:" path="roleIds"> |
|
|
|
<n-select |
|
|
|
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 label="排序号" path="sort"> |
|
|
|
<n-input-number v-model:value="form.sort" placeholder="请输入排序号" /> |
|
|
|
</n-form-item> |
|
|
|
<n-form-item |
|
|
|
label="备注:" |
|
|
@@ -101,16 +65,12 @@ |
|
|
|
</template> |
|
|
|
|
|
|
|
<script> |
|
|
|
import { defineComponent, computed, onMounted, reactive, toRefs } from 'vue' |
|
|
|
import { defineComponent, computed, reactive, toRefs } from 'vue' |
|
|
|
import Modal from '@/components/Modal/index.vue' |
|
|
|
import uploadImage from '@/components/ImgUpload/index.vue' |
|
|
|
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' |
|
|
|
import { addDept, editDept } from '@/api/system/dept/index' |
|
|
|
export default defineComponent({ |
|
|
|
name: 'UserModal', |
|
|
|
components: { Modal, uploadImage }, |
|
|
|
components: { Modal }, |
|
|
|
props: { |
|
|
|
visible: { |
|
|
|
type: Boolean, |
|
|
@@ -119,6 +79,10 @@ export default defineComponent({ |
|
|
|
row: { |
|
|
|
type: Object, |
|
|
|
default: () => {} |
|
|
|
}, |
|
|
|
deptList: { |
|
|
|
type: Array, |
|
|
|
default: () => [] |
|
|
|
} |
|
|
|
}, |
|
|
|
emits: { |
|
|
@@ -142,34 +106,38 @@ export default defineComponent({ |
|
|
|
deptOptions: [], |
|
|
|
rolesOptions: [], |
|
|
|
rules: { |
|
|
|
avatar: [ |
|
|
|
{ required: true, message: '请选择头像', type: 'string', trigger: 'blur' } |
|
|
|
], |
|
|
|
code: [ |
|
|
|
{ required: true, message: '请输入编号', trigger: 'blur' } |
|
|
|
{ required: true, message: '请输入部门编号', trigger: 'blur' } |
|
|
|
], |
|
|
|
realname: [ |
|
|
|
{ required: true, message: '请输入用户姓名', type: 'string', trigger: 'blur' } |
|
|
|
name: [ |
|
|
|
{ required: true, message: '请输入部门名称', type: 'string', trigger: 'blur' } |
|
|
|
], |
|
|
|
deptId: [ |
|
|
|
{ required: true, message: '请选择部门', type: 'number', 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' } |
|
|
|
sort: [ |
|
|
|
{ required: true, type: 'number', message: '请输入排序号', 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 row = props.row |
|
|
|
if (props.row.pid === 0) { |
|
|
|
row.pid = null |
|
|
|
} |
|
|
|
return { |
|
|
|
title: Object.keys(props.row).length === 0 ? '添加用户' : '编辑用户', |
|
|
|
title: props.row.name ? '编辑部门' : '添加部门', |
|
|
|
show: props.visible, |
|
|
|
form: Object.assign(data.form, props.row), |
|
|
|
form: Object.assign(data.form, row), |
|
|
|
negativeText: '取消', |
|
|
|
positiveText: '确认' |
|
|
|
} |
|
|
@@ -180,44 +148,21 @@ export default defineComponent({ |
|
|
|
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 { |
|
|
|
...toRefs(data), |
|
|
|
getDeptList, |
|
|
|
getModalOptions, |
|
|
|
handleClose, |
|
|
|
handleUpload |
|
|
|
handleClose |
|
|
|
} |
|
|
|
}, |
|
|
|
methods: { |
|
|
|
// 表单提交 |
|
|
|
handleConfirm() { |
|
|
|
const type = Object.keys(this.row).length === 0 ? 'add' : 'edit' |
|
|
|
const type = this.row.name ? 'edit' : 'add' |
|
|
|
this.$refs.formRef.validate((errors) => { |
|
|
|
if (!errors) { |
|
|
|
if (type === 'add') { |
|
|
|
addUser(this.form).then(res => { |
|
|
|
addDept(this.form).then(res => { |
|
|
|
if (res.code === 0) { |
|
|
|
this.handleClose() |
|
|
|
this.$emit('done') |
|
|
@@ -229,7 +174,7 @@ export default defineComponent({ |
|
|
|
console.log(e) |
|
|
|
}) |
|
|
|
} else if (type === 'edit') { |
|
|
|
editUser(this.form).then(res => { |
|
|
|
editDept(this.form).then(res => { |
|
|
|
if (res.code === 0) { |
|
|
|
this.handleClose() |
|
|
|
this.$emit('done') |