|
@@ -2,114 +2,119 @@
|
|
import { ContentWrap } from '@/components/ContentWrap'
|
|
import { ContentWrap } from '@/components/ContentWrap'
|
|
import { useI18n } from '@/hooks/web/useI18n'
|
|
import { useI18n } from '@/hooks/web/useI18n'
|
|
import { Table } from '@/components/Table'
|
|
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, nextTick } from 'vue'
|
|
|
|
+import { ElButton, ElTree, ElTooltip, ElButtonGroup } 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 { useTable } from '@/hooks/web/useTable'
|
|
import { Search } from '@/components/Search'
|
|
import { Search } from '@/components/Search'
|
|
import Write from './components/Write.vue'
|
|
import Write from './components/Write.vue'
|
|
import Detail from './components/Detail.vue'
|
|
import Detail from './components/Detail.vue'
|
|
import { Dialog } from '@/components/Dialog'
|
|
import { Dialog } from '@/components/Dialog'
|
|
import { CrudSchema, useCrudSchemas } from '@/hooks/web/useCrudSchemas'
|
|
import { CrudSchema, useCrudSchemas } from '@/hooks/web/useCrudSchemas'
|
|
|
|
+import { useIcon } from '@/hooks/web/useIcon'
|
|
|
|
+const EditIcon = useIcon({ icon: 'ep:edit' })
|
|
|
|
+const DeleteIcon = useIcon({ icon: 'ep:delete' })
|
|
|
|
|
|
const { t } = useI18n()
|
|
const { t } = useI18n()
|
|
|
|
|
|
const { tableRegister, tableState, tableMethods } = useTable({
|
|
const { tableRegister, tableState, tableMethods } = useTable({
|
|
fetchDataApi: async () => {
|
|
fetchDataApi: async () => {
|
|
const { pageSize, currentPage } = tableState
|
|
const { pageSize, currentPage } = tableState
|
|
- const res = await getUserByIdApi({
|
|
|
|
- id: unref(currentNodeKey),
|
|
|
|
- pageIndex: unref(currentPage),
|
|
|
|
|
|
+ const res = await getUserList({
|
|
|
|
+ pageNum: unref(currentPage),
|
|
pageSize: unref(pageSize),
|
|
pageSize: unref(pageSize),
|
|
...unref(searchParams)
|
|
...unref(searchParams)
|
|
})
|
|
})
|
|
return {
|
|
return {
|
|
list: res.data.list || [],
|
|
list: res.data.list || [],
|
|
- total: res.data.total || 0
|
|
|
|
|
|
+ total: Number(res.data.totalCount)
|
|
}
|
|
}
|
|
},
|
|
},
|
|
fetchDelApi: async () => {
|
|
fetchDelApi: async () => {
|
|
- const res = await deleteUserByIdApi(unref(ids))
|
|
|
|
|
|
+ const res = await deleteUserById(unref(id))
|
|
return !!res
|
|
return !!res
|
|
}
|
|
}
|
|
})
|
|
})
|
|
const { total, loading, dataList, pageSize, currentPage } = tableState
|
|
const { total, loading, dataList, pageSize, currentPage } = tableState
|
|
-const { getList, getElTableExpose, delList } = tableMethods
|
|
|
|
|
|
+const { getList, delList } = tableMethods
|
|
|
|
|
|
const crudSchemas = reactive<CrudSchema[]>([
|
|
const crudSchemas = reactive<CrudSchema[]>([
|
|
{
|
|
{
|
|
- field: 'selection',
|
|
|
|
|
|
+ field: 'name',
|
|
|
|
+ label: t('userDemo.username')
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ field: 'account',
|
|
|
|
+ label: t('userDemo.account'),
|
|
search: {
|
|
search: {
|
|
hidden: true
|
|
hidden: true
|
|
- },
|
|
|
|
- form: {
|
|
|
|
- hidden: true
|
|
|
|
- },
|
|
|
|
- detail: {
|
|
|
|
- hidden: true
|
|
|
|
- },
|
|
|
|
- table: {
|
|
|
|
- type: 'selection'
|
|
|
|
}
|
|
}
|
|
},
|
|
},
|
|
{
|
|
{
|
|
- field: 'index',
|
|
|
|
- label: t('userDemo.index'),
|
|
|
|
|
|
+ field: 'isActive',
|
|
|
|
+ label: '是否启用',
|
|
form: {
|
|
form: {
|
|
- hidden: true
|
|
|
|
|
|
+ component: 'Switch',
|
|
|
|
+ value: '1',
|
|
|
|
+ componentProps: {
|
|
|
|
+ activeText: '启用',
|
|
|
|
+ inactiveText: '禁用',
|
|
|
|
+ activeValue: '1',
|
|
|
|
+ inactiveValue: '0'
|
|
|
|
+ }
|
|
},
|
|
},
|
|
search: {
|
|
search: {
|
|
- hidden: true
|
|
|
|
- },
|
|
|
|
- detail: {
|
|
|
|
- hidden: true
|
|
|
|
- },
|
|
|
|
- table: {
|
|
|
|
- type: 'index'
|
|
|
|
|
|
+ component: 'Select',
|
|
|
|
+ componentProps: {
|
|
|
|
+ options: [
|
|
|
|
+ {
|
|
|
|
+ value: '1',
|
|
|
|
+ label: '启用'
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ value: '0',
|
|
|
|
+ label: '禁用'
|
|
|
|
+ }
|
|
|
|
+ ]
|
|
|
|
+ }
|
|
}
|
|
}
|
|
},
|
|
},
|
|
{
|
|
{
|
|
- field: 'username',
|
|
|
|
- label: t('userDemo.username')
|
|
|
|
- },
|
|
|
|
- {
|
|
|
|
- field: 'account',
|
|
|
|
- label: t('userDemo.account')
|
|
|
|
- },
|
|
|
|
- {
|
|
|
|
- field: 'department.id',
|
|
|
|
- label: t('userDemo.department'),
|
|
|
|
- detail: {
|
|
|
|
- slots: {
|
|
|
|
- default: (data: DepartmentUserItem) => {
|
|
|
|
- return <>{data.department.departmentName}</>
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- },
|
|
|
|
|
|
+ field: 'roleId',
|
|
|
|
+ label: t('userDemo.role'),
|
|
search: {
|
|
search: {
|
|
hidden: true
|
|
hidden: true
|
|
},
|
|
},
|
|
form: {
|
|
form: {
|
|
- component: 'TreeSelect',
|
|
|
|
- componentProps: {
|
|
|
|
- nodeKey: 'id',
|
|
|
|
- props: {
|
|
|
|
- label: 'departmentName'
|
|
|
|
- }
|
|
|
|
- },
|
|
|
|
|
|
+ component: 'Select',
|
|
optionApi: async () => {
|
|
optionApi: async () => {
|
|
- const res = await getDepartmentApi()
|
|
|
|
- return res.data.list
|
|
|
|
|
|
+ const res = await getRoleApi()
|
|
|
|
+ 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: {
|
|
search: {
|
|
hidden: true
|
|
hidden: true
|
|
}
|
|
}
|
|
@@ -124,11 +129,27 @@ const crudSchemas = reactive<CrudSchema[]>([
|
|
hidden: true
|
|
hidden: true
|
|
}
|
|
}
|
|
},
|
|
},
|
|
|
|
+ {
|
|
|
|
+ field: 'password',
|
|
|
|
+ label: '密码',
|
|
|
|
+ form: {
|
|
|
|
+ component: 'Input',
|
|
|
|
+ componentProps: {
|
|
|
|
+ type: 'password'
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+ table: {
|
|
|
|
+ hidden: true
|
|
|
|
+ },
|
|
|
|
+ search: {
|
|
|
|
+ hidden: true
|
|
|
|
+ }
|
|
|
|
+ },
|
|
{
|
|
{
|
|
field: 'createTime',
|
|
field: 'createTime',
|
|
label: t('userDemo.createTime'),
|
|
label: t('userDemo.createTime'),
|
|
form: {
|
|
form: {
|
|
- component: 'Input'
|
|
|
|
|
|
+ hidden: true
|
|
},
|
|
},
|
|
search: {
|
|
search: {
|
|
hidden: true
|
|
hidden: true
|
|
@@ -147,21 +168,26 @@ const crudSchemas = reactive<CrudSchema[]>([
|
|
hidden: true
|
|
hidden: true
|
|
},
|
|
},
|
|
table: {
|
|
table: {
|
|
- width: 240,
|
|
|
|
|
|
+ width: 120,
|
|
|
|
+ fixed: 'right',
|
|
slots: {
|
|
slots: {
|
|
default: (data: any) => {
|
|
default: (data: any) => {
|
|
const row = data.row as DepartmentUserItem
|
|
const row = data.row as DepartmentUserItem
|
|
return (
|
|
return (
|
|
<>
|
|
<>
|
|
- <ElButton type="primary" onClick={() => action(row, 'edit')}>
|
|
|
|
- {t('exampleDemo.edit')}
|
|
|
|
- </ElButton>
|
|
|
|
- <ElButton type="success" onClick={() => action(row, 'detail')}>
|
|
|
|
- {t('exampleDemo.detail')}
|
|
|
|
- </ElButton>
|
|
|
|
- <ElButton type="danger" onClick={() => delData(row)}>
|
|
|
|
- {t('exampleDemo.del')}
|
|
|
|
- </ElButton>
|
|
|
|
|
|
+ <ElButtonGroup>
|
|
|
|
+ <ElTooltip content="编辑">
|
|
|
|
+ <ElButton text icon={EditIcon} onClick={() => action(row, 'edit')} />
|
|
|
|
+ </ElTooltip>
|
|
|
|
+ <ElTooltip content="删除">
|
|
|
|
+ <ElButton
|
|
|
|
+ text
|
|
|
|
+ icon={DeleteIcon}
|
|
|
|
+ type="danger"
|
|
|
|
+ onClick={() => delData(data.row)}
|
|
|
|
+ />
|
|
|
|
+ </ElTooltip>
|
|
|
|
+ </ElButtonGroup>
|
|
</>
|
|
</>
|
|
)
|
|
)
|
|
}
|
|
}
|
|
@@ -181,18 +207,6 @@ const setSearchParams = (params: any) => {
|
|
|
|
|
|
const treeEl = ref<typeof ElTree>()
|
|
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('')
|
|
const currentDepartment = ref('')
|
|
watch(
|
|
watch(
|
|
() => currentDepartment.value,
|
|
() => currentDepartment.value,
|
|
@@ -201,18 +215,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 dialogVisible = ref(false)
|
|
const dialogTitle = ref('')
|
|
const dialogTitle = ref('')
|
|
|
|
|
|
@@ -227,29 +229,25 @@ const AddAction = () => {
|
|
}
|
|
}
|
|
|
|
|
|
const delLoading = ref(false)
|
|
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
|
|
delLoading.value = true
|
|
|
|
|
|
- await delList(unref(ids).length).finally(() => {
|
|
|
|
|
|
+ await delList(unref(id)).finally(() => {
|
|
delLoading.value = false
|
|
delLoading.value = false
|
|
})
|
|
})
|
|
}
|
|
}
|
|
|
|
+const writeRef = ref<ComponentRef<typeof Write>>()
|
|
|
|
|
|
-const action = (row: DepartmentUserItem, type: string) => {
|
|
|
|
|
|
+const action = async (row: DepartmentUserItem, type: string) => {
|
|
dialogTitle.value = t(type === 'edit' ? 'exampleDemo.edit' : 'exampleDemo.detail')
|
|
dialogTitle.value = t(type === 'edit' ? 'exampleDemo.edit' : 'exampleDemo.detail')
|
|
actionType.value = type
|
|
actionType.value = type
|
|
currentRow.value = { ...row, department: unref(treeEl)?.getCurrentNode() || {} }
|
|
currentRow.value = { ...row, department: unref(treeEl)?.getCurrentNode() || {} }
|
|
dialogVisible.value = true
|
|
dialogVisible.value = true
|
|
}
|
|
}
|
|
|
|
|
|
-const writeRef = ref<ComponentRef<typeof Write>>()
|
|
|
|
-
|
|
|
|
const saveLoading = ref(false)
|
|
const saveLoading = ref(false)
|
|
|
|
|
|
const save = async () => {
|
|
const save = async () => {
|
|
@@ -258,13 +256,17 @@ const save = async () => {
|
|
if (formData) {
|
|
if (formData) {
|
|
saveLoading.value = true
|
|
saveLoading.value = true
|
|
try {
|
|
try {
|
|
- const res = await saveUserApi(formData)
|
|
|
|
|
|
+ let res: any
|
|
|
|
+ if (formData.id) {
|
|
|
|
+ res = await updataUser(formData)
|
|
|
|
+ } else {
|
|
|
|
+ res = await addUser(formData)
|
|
|
|
+ }
|
|
if (res) {
|
|
if (res) {
|
|
currentPage.value = 1
|
|
currentPage.value = 1
|
|
getList()
|
|
getList()
|
|
}
|
|
}
|
|
} catch (error) {
|
|
} catch (error) {
|
|
- console.log(error)
|
|
|
|
} finally {
|
|
} finally {
|
|
saveLoading.value = false
|
|
saveLoading.value = false
|
|
dialogVisible.value = false
|
|
dialogVisible.value = false
|
|
@@ -274,32 +276,8 @@ const save = async () => {
|
|
</script>
|
|
</script>
|
|
|
|
|
|
<template>
|
|
<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
|
|
<Search
|
|
:schema="allSchemas.searchSchema"
|
|
:schema="allSchemas.searchSchema"
|
|
@reset="setSearchParams"
|
|
@reset="setSearchParams"
|
|
@@ -308,9 +286,6 @@ const save = async () => {
|
|
|
|
|
|
<div class="mb-10px">
|
|
<div class="mb-10px">
|
|
<ElButton type="primary" @click="AddAction">{{ t('exampleDemo.add') }}</ElButton>
|
|
<ElButton type="primary" @click="AddAction">{{ t('exampleDemo.add') }}</ElButton>
|
|
- <ElButton :loading="delLoading" type="danger" @click="delData()">
|
|
|
|
- {{ t('exampleDemo.del') }}
|
|
|
|
- </ElButton>
|
|
|
|
</div>
|
|
</div>
|
|
<Table
|
|
<Table
|
|
v-model:current-page="currentPage"
|
|
v-model:current-page="currentPage"
|
|
@@ -329,7 +304,15 @@ const save = async () => {
|
|
<Write
|
|
<Write
|
|
v-if="actionType !== 'detail'"
|
|
v-if="actionType !== 'detail'"
|
|
ref="writeRef"
|
|
ref="writeRef"
|
|
- :form-schema="allSchemas.formSchema"
|
|
|
|
|
|
+ :form-schema="
|
|
|
|
+ allSchemas.formSchema.filter((e) => {
|
|
|
|
+ if (actionType === 'edit') {
|
|
|
|
+ return e.field !== 'password'
|
|
|
|
+ } else {
|
|
|
|
+ return true
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ "
|
|
:current-row="currentRow"
|
|
:current-row="currentRow"
|
|
/>
|
|
/>
|
|
|
|
|