|
@@ -2,10 +2,10 @@
|
|
|
import { ContentWrap } from '@/components/ContentWrap'
|
|
|
import { useI18n } from '@/hooks/web/useI18n'
|
|
|
import { Table } from '@/components/Table'
|
|
|
-import { ref, unref, nextTick, watch, reactive } from 'vue'
|
|
|
-import { ElButton, ElTree, ElInput, ElDivider } from 'element-plus'
|
|
|
-import { getDepartmentApi, getUserByIdApi, saveUserApi, deleteUserByIdApi } from '@/api/department'
|
|
|
-import type { DepartmentItem, DepartmentUserItem } from '@/api/department/types'
|
|
|
+import { ref, unref, watch, reactive } from 'vue'
|
|
|
+import { ElButton, ElTree } from 'element-plus'
|
|
|
+import { getUserList, addUser, updataUser, deleteUserById, getRoleApi } from '@/api/department'
|
|
|
+import type { DepartmentUserItem } from '@/api/department/types'
|
|
|
import { useTable } from '@/hooks/web/useTable'
|
|
|
import { Search } from '@/components/Search'
|
|
|
import Write from './components/Write.vue'
|
|
@@ -18,9 +18,8 @@ const { t } = useI18n()
|
|
|
const { tableRegister, tableState, tableMethods } = useTable({
|
|
|
fetchDataApi: async () => {
|
|
|
const { pageSize, currentPage } = tableState
|
|
|
- const res = await getUserByIdApi({
|
|
|
- id: unref(currentNodeKey),
|
|
|
- pageIndex: unref(currentPage),
|
|
|
+ const res = await getUserList({
|
|
|
+ pageNum: unref(currentPage),
|
|
|
pageSize: unref(pageSize),
|
|
|
...unref(searchParams)
|
|
|
})
|
|
@@ -30,29 +29,14 @@ const { tableRegister, tableState, tableMethods } = useTable({
|
|
|
}
|
|
|
},
|
|
|
fetchDelApi: async () => {
|
|
|
- const res = await deleteUserByIdApi(unref(ids))
|
|
|
+ const res = await deleteUserById(unref(id))
|
|
|
return !!res
|
|
|
}
|
|
|
})
|
|
|
const { total, loading, dataList, pageSize, currentPage } = tableState
|
|
|
-const { getList, getElTableExpose, delList } = tableMethods
|
|
|
+const { getList, delList } = tableMethods
|
|
|
|
|
|
const crudSchemas = reactive<CrudSchema[]>([
|
|
|
- {
|
|
|
- field: 'selection',
|
|
|
- search: {
|
|
|
- hidden: true
|
|
|
- },
|
|
|
- form: {
|
|
|
- hidden: true
|
|
|
- },
|
|
|
- detail: {
|
|
|
- hidden: true
|
|
|
- },
|
|
|
- table: {
|
|
|
- type: 'selection'
|
|
|
- }
|
|
|
- },
|
|
|
{
|
|
|
field: 'index',
|
|
|
label: t('userDemo.index'),
|
|
@@ -70,7 +54,7 @@ const crudSchemas = reactive<CrudSchema[]>([
|
|
|
}
|
|
|
},
|
|
|
{
|
|
|
- field: 'username',
|
|
|
+ field: 'name',
|
|
|
label: t('userDemo.username')
|
|
|
},
|
|
|
{
|
|
@@ -78,38 +62,55 @@ const crudSchemas = reactive<CrudSchema[]>([
|
|
|
label: t('userDemo.account')
|
|
|
},
|
|
|
{
|
|
|
- field: 'department.id',
|
|
|
- label: t('userDemo.department'),
|
|
|
- detail: {
|
|
|
- slots: {
|
|
|
- default: (data: DepartmentUserItem) => {
|
|
|
- return <>{data.department.departmentName}</>
|
|
|
- }
|
|
|
+ field: 'isActive',
|
|
|
+ label: '是否启用',
|
|
|
+ form: {
|
|
|
+ component: 'Switch',
|
|
|
+ value: '1',
|
|
|
+ componentProps: {
|
|
|
+ activeText: '启用',
|
|
|
+ inactiveText: '禁用',
|
|
|
+ activeValue: '1',
|
|
|
+ inactiveValue: '0'
|
|
|
}
|
|
|
- },
|
|
|
+ }
|
|
|
+ },
|
|
|
+ {
|
|
|
+ field: 'roleId',
|
|
|
+ label: t('userDemo.role'),
|
|
|
search: {
|
|
|
hidden: true
|
|
|
},
|
|
|
form: {
|
|
|
- component: 'TreeSelect',
|
|
|
- componentProps: {
|
|
|
- nodeKey: 'id',
|
|
|
- props: {
|
|
|
- label: 'departmentName'
|
|
|
- }
|
|
|
- },
|
|
|
+ component: 'Select',
|
|
|
optionApi: async () => {
|
|
|
- const res = await getDepartmentApi()
|
|
|
- return res.data.list
|
|
|
+ const res = await getRoleApi()
|
|
|
+ console.log(res)
|
|
|
+ return res.data.map((e) => {
|
|
|
+ return {
|
|
|
+ label: e.roleDesc,
|
|
|
+ value: e.id
|
|
|
+ }
|
|
|
+ })
|
|
|
}
|
|
|
+ }
|
|
|
+ },
|
|
|
+ {
|
|
|
+ field: 'phone',
|
|
|
+ label: '电话',
|
|
|
+ form: {
|
|
|
+ component: 'Input'
|
|
|
},
|
|
|
- table: {
|
|
|
- type: 'index'
|
|
|
+ search: {
|
|
|
+ hidden: true
|
|
|
}
|
|
|
},
|
|
|
{
|
|
|
- field: 'role',
|
|
|
- label: t('userDemo.role'),
|
|
|
+ field: 'address',
|
|
|
+ label: '住址',
|
|
|
+ form: {
|
|
|
+ component: 'Input'
|
|
|
+ },
|
|
|
search: {
|
|
|
hidden: true
|
|
|
}
|
|
@@ -124,11 +125,27 @@ const crudSchemas = reactive<CrudSchema[]>([
|
|
|
hidden: true
|
|
|
}
|
|
|
},
|
|
|
+ {
|
|
|
+ field: 'password',
|
|
|
+ label: '密码',
|
|
|
+ form: {
|
|
|
+ component: 'Input',
|
|
|
+ componentProps: {
|
|
|
+ type: 'password'
|
|
|
+ }
|
|
|
+ },
|
|
|
+ table: {
|
|
|
+ hidden: true
|
|
|
+ },
|
|
|
+ search: {
|
|
|
+ hidden: true
|
|
|
+ }
|
|
|
+ },
|
|
|
{
|
|
|
field: 'createTime',
|
|
|
label: t('userDemo.createTime'),
|
|
|
form: {
|
|
|
- component: 'Input'
|
|
|
+ hidden: true
|
|
|
},
|
|
|
search: {
|
|
|
hidden: true
|
|
@@ -181,18 +198,6 @@ const setSearchParams = (params: any) => {
|
|
|
|
|
|
const treeEl = ref<typeof ElTree>()
|
|
|
|
|
|
-const currentNodeKey = ref('')
|
|
|
-const departmentList = ref<DepartmentItem[]>([])
|
|
|
-const fetchDepartment = async () => {
|
|
|
- const res = await getDepartmentApi()
|
|
|
- departmentList.value = res.data.list
|
|
|
- currentNodeKey.value =
|
|
|
- (res.data.list[0] && res.data.list[0]?.children && res.data.list[0].children[0].id) || ''
|
|
|
- await nextTick()
|
|
|
- unref(treeEl)?.setCurrentKey(currentNodeKey.value)
|
|
|
-}
|
|
|
-fetchDepartment()
|
|
|
-
|
|
|
const currentDepartment = ref('')
|
|
|
watch(
|
|
|
() => currentDepartment.value,
|
|
@@ -201,18 +206,6 @@ watch(
|
|
|
}
|
|
|
)
|
|
|
|
|
|
-const currentChange = (data: DepartmentItem) => {
|
|
|
- if (data.children) return
|
|
|
- currentNodeKey.value = data.id
|
|
|
- currentPage.value = 1
|
|
|
- getList()
|
|
|
-}
|
|
|
-
|
|
|
-const filterNode = (value: string, data: DepartmentItem) => {
|
|
|
- if (!value) return true
|
|
|
- return data.departmentName.includes(value)
|
|
|
-}
|
|
|
-
|
|
|
const dialogVisible = ref(false)
|
|
|
const dialogTitle = ref('')
|
|
|
|
|
@@ -227,16 +220,13 @@ const AddAction = () => {
|
|
|
}
|
|
|
|
|
|
const delLoading = ref(false)
|
|
|
-const ids = ref<string[]>([])
|
|
|
+const id = ref<number>(0)
|
|
|
|
|
|
-const delData = async (row?: DepartmentUserItem) => {
|
|
|
- const elTableExpose = await getElTableExpose()
|
|
|
- ids.value = row
|
|
|
- ? [row.id]
|
|
|
- : elTableExpose?.getSelectionRows().map((v: DepartmentUserItem) => v.id) || []
|
|
|
+const delData = async (row: DepartmentUserItem) => {
|
|
|
+ id.value = row.id
|
|
|
delLoading.value = true
|
|
|
|
|
|
- await delList(unref(ids).length).finally(() => {
|
|
|
+ await delList(unref(id)).finally(() => {
|
|
|
delLoading.value = false
|
|
|
})
|
|
|
}
|
|
@@ -258,7 +248,12 @@ const save = async () => {
|
|
|
if (formData) {
|
|
|
saveLoading.value = true
|
|
|
try {
|
|
|
- const res = await saveUserApi(formData)
|
|
|
+ let res: any
|
|
|
+ if (formData.id) {
|
|
|
+ res = await updataUser(formData)
|
|
|
+ } else {
|
|
|
+ res = await addUser(formData)
|
|
|
+ }
|
|
|
if (res) {
|
|
|
currentPage.value = 1
|
|
|
getList()
|
|
@@ -274,32 +269,8 @@ const save = async () => {
|
|
|
</script>
|
|
|
|
|
|
<template>
|
|
|
- <div class="flex w-100% h-100%">
|
|
|
- <ContentWrap class="flex-1">
|
|
|
- <div class="flex justify-center items-center">
|
|
|
- <div class="flex-1">{{ t('userDemo.departmentList') }}</div>
|
|
|
- <ElInput
|
|
|
- v-model="currentDepartment"
|
|
|
- class="flex-[2]"
|
|
|
- :placeholder="t('userDemo.searchDepartment')"
|
|
|
- clearable
|
|
|
- />
|
|
|
- </div>
|
|
|
- <ElDivider />
|
|
|
- <ElTree
|
|
|
- ref="treeEl"
|
|
|
- :data="departmentList"
|
|
|
- default-expand-all
|
|
|
- node-key="id"
|
|
|
- :current-node-key="currentNodeKey"
|
|
|
- :props="{
|
|
|
- label: 'departmentName'
|
|
|
- }"
|
|
|
- :filter-node-method="filterNode"
|
|
|
- @current-change="currentChange"
|
|
|
- />
|
|
|
- </ContentWrap>
|
|
|
- <ContentWrap class="flex-[3] ml-20px">
|
|
|
+ <div>
|
|
|
+ <ContentWrap>
|
|
|
<Search
|
|
|
:schema="allSchemas.searchSchema"
|
|
|
@reset="setSearchParams"
|
|
@@ -308,9 +279,6 @@ const save = async () => {
|
|
|
|
|
|
<div class="mb-10px">
|
|
|
<ElButton type="primary" @click="AddAction">{{ t('exampleDemo.add') }}</ElButton>
|
|
|
- <ElButton :loading="delLoading" type="danger" @click="delData()">
|
|
|
- {{ t('exampleDemo.del') }}
|
|
|
- </ElButton>
|
|
|
</div>
|
|
|
<Table
|
|
|
v-model:current-page="currentPage"
|