Browse Source

feat: #0000 部门管理 100%

luoyali 1 year ago
parent
commit
6380deeda0
1 changed files with 43 additions and 16 deletions
  1. 43 16
      src/views/setting/department/index.vue

+ 43 - 16
src/views/setting/department/index.vue

@@ -72,7 +72,20 @@ import StatusIndicator from '@/components/StatusIndicator'
 const visible = ref(false) // 弹窗显示隐藏
 const isCreate = ref(true)
 const activeData = ref({})
-const formsDialog = [
+const curSelectionRows = ref([]) // 表格选中数据
+const formsDialog = ref([
+	{
+		prop: 'pid',
+		label: '上级部门',
+		itemType: 'cascader',
+		props: {
+			value: 'id',
+			label: 'name',
+			emitPath: false,
+			checkStrictly: true
+		},
+		options: []
+	},
 	{
 		prop: 'name',
 		label: '名称',
@@ -104,11 +117,11 @@ const formsDialog = [
 		itemType: 'input',
 		rules: [{ required: true, message: '请输入备注', trigger: 'blur' }]
 	}
-]
+])
 // 新增的表单 和 编辑的表单
 const formOptions = computed(() => {
 	return {
-		forms: formsDialog,
+		forms: formsDialog.value,
 		labelWidth: 120,
 		span: 30,
 		showResetBtn: true,
@@ -120,15 +133,16 @@ const formOptions = computed(() => {
 const groupFilterText = ref('')
 const treeRef = ref<InstanceType<typeof ElTree>>()
 
-// 表格搜索条件
-const forms = ref([
-	{
-		prop: 'keyword',
-		label: '角色名称:',
-		itemType: 'input',
-		placeholder: '请输入角色名称'
-	}
-])
+const replaceChildren = arr => {
+	arr.forEach(item => {
+		item.label = item.name
+		item.value = item.id
+		if (item.children && item.children.length > 0) {
+			replaceChildren(item.children)
+		}
+	})
+	return arr
+}
 
 // table列表数据请求
 const queryList = async () => {
@@ -138,6 +152,10 @@ const queryList = async () => {
 		const list = await department.departmentPageApi(searchParams)
 		// tableOpts.total = total
 		tableOpts.list = list
+		formsDialog.value[0].options = list
+		// const test = replaceChildren(list)
+		// console.log(test);
+		// formsDialog.value[1].options = list
 	} catch {
 		console.log('获取列表数据失败')
 		// tableOpts.total = 0
@@ -150,9 +168,19 @@ const queryList = async () => {
 
 const selectionChange = e => {
 	// console.error('click 测试', e)
-	console.log(e, 'selectionChange')
+	curSelectionRows.value = e
 }
 
+// 表格搜索条件
+const forms = ref([
+	{
+		prop: 'keyword',
+		label: '角色名称:',
+		itemType: 'input',
+		placeholder: '请输入角色名称'
+	}
+])
+
 // table 参数
 const columns = [
 	{
@@ -215,11 +243,11 @@ const columns = [
 	}
 ]
 
-const { searchData, tableOpts, checkedColumns, activeColumns, curSelectionRows, updateParams } = useTablePage(
+const { searchData, tableOpts, checkedColumns, activeColumns, updateParams } = useTablePage(
 	{
 		options: {
 			showIndex: false,
-			// treeProps: { children: 'children', hasChildren: 'hasChildren' },
+			defaultExpandAll: true,
 			onSelectionChange: selectionChange
 		},
 		// 需要展示的列
@@ -285,7 +313,6 @@ const addHandler = () => {
 	activeData.value = {}
 	visible.value = true
 }
-
 nextTick(() => {
 	queryList()
 })