/* * @Date: 2022-08-25 14:05:59 * @LastEditors: StavinLi 495727881@qq.com * @LastEditTime: 2022-09-21 14:36:34 * @FilePath: /Workflow-Vue3/src/components/dialog/common.js */ import { ref } from 'vue' import { getDepartments, getEmployees, getRoles } from '@/plugins/api.js' import $func from '@/plugins/preload.js' export const searchVal = ref('') export const departments = ref({ titleDepartments: [], childDepartments: [], employees: [], }) export const roles = ref({}) export const getRoleList = async () => { const { data: { list } } = await getRoles() roles.value = list } export const getDepartmentList = async (parentId = 0) => { const { data } = await getDepartments({ parentId }) departments.value = data } export const getDebounceData = (event, type = 1) => { $func.debounce(async () => { if (event.target.value) { const data = { searchName: event.target.value, pageNum: 1, pageSize: 30, } if (type == 1) { departments.value.childDepartments = [] const res = await getEmployees(data) departments.value.employees = res.data.list } else { const res = await getRoles(data) roles.value = res.data.list } } else { type == 1 ? await getDepartmentList() : await getRoleList() } })() }