From a021f3e5e59bd760c6c60f33d2529b027f11d162 Mon Sep 17 00:00:00 2001 From: zc <> Date: Tue, 7 Dec 2021 00:07:18 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E9=83=A8=E9=97=A8?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 添加部门查询 --- .env.development | 2 +- src/api/system/dept.ts | 68 ++++ src/components/TreeSelect/index.vue | 200 +++++++++++ src/utils/ruoyi.ts | 124 +++++++ src/views/system/dept/index.vue | 506 ++++++++++++++++++++++++++++ 5 files changed, 899 insertions(+), 1 deletion(-) create mode 100644 src/api/system/dept.ts create mode 100644 src/components/TreeSelect/index.vue create mode 100644 src/utils/ruoyi.ts create mode 100644 src/views/system/dept/index.vue diff --git a/.env.development b/.env.development index 163417bf..4af4799e 100644 --- a/.env.development +++ b/.env.development @@ -4,5 +4,5 @@ NODE_ENV='development' VITE_APP_TITLE = '管理系统' -VITE_APP_PORT = 9527 +VITE_APP_PORT = 9528 VITE_APP_BASE_API = '/dev-api' diff --git a/src/api/system/dept.ts b/src/api/system/dept.ts new file mode 100644 index 00000000..0e341bbc --- /dev/null +++ b/src/api/system/dept.ts @@ -0,0 +1,68 @@ +import request from '@/utils/request' + +// export function list(queryParams:object) { +// return request({ +// url: '/youlai-admin/api/v1/oauth-clients', +// method: 'get', +// params: queryParams +// }) +// } + +export const listDept = (queryParams?: object) => { + return request({ + url: '/youlai-admin/api/v1/depts/table', + method: 'get', + params: queryParams + }) +} + +export const getDept = (deptId: any) => { + return request({ + url: '/youlai-admin/api/v1/depts/select', + method: 'get' + }) +} + +// export const listDeptExcludeChild = (deptId: any) => { +// return https().request>(`system/dept/list/exclude/${deptId}`, Method.GET, undefined, ContentType.form) +// } + +export const delDept = (deptId: any) => { + return request({ + url: '/youlai-admin/api/v1/depts/'+deptId, + method: 'delete', + }) +} + + + +// 新增部门 + +export const addDept = (data: any) => { + return request({ + url: '/youlai-admin/api/v1/depts', + method: 'post', + data: data + }) +} + +// 修改部门 + +export const updateDept = (data: any) => { + return request({ + url: '/youlai-admin/api/v1/depts/' + id, + method: 'put', + data: data + }) +} + +// // 根据角色ID查询部门树结构 +// export const roleDeptTreeselect = (roleId: number | string) => { +// return https().request(`system/dept/roleDeptTreeselect/${roleId}`, Method.GET, undefined, ContentType.form) +// } +// +// // 查询部门下拉树结构 +// +// export const treeselect = () => { +// return https().request>('system/dept/treeselect', Method.GET, undefined, ContentType.form) +// } diff --git a/src/components/TreeSelect/index.vue b/src/components/TreeSelect/index.vue new file mode 100644 index 00000000..76289cb4 --- /dev/null +++ b/src/components/TreeSelect/index.vue @@ -0,0 +1,200 @@ + + + + + diff --git a/src/utils/ruoyi.ts b/src/utils/ruoyi.ts new file mode 100644 index 00000000..a0effbb0 --- /dev/null +++ b/src/utils/ruoyi.ts @@ -0,0 +1,124 @@ +/* + * @Description: + * @Autor: scy😊 + * @Date: 2021-02-04 09:08:51 + * @LastEditors: ZY + * @LastEditTime: 2021-02-23 14:44:09 + */ +// const baseURL = process.env.VUE_APP_BASE_API +// +// export function download(fileName: any) { +// window.location.href = baseURL + '/common/download?fileName=' + encodeURI(fileName) + '&delete=' + true +// } + +// 添加日期范围 + +type Params = {[key: string]: any} + +export const addDateRange = (params: Params, dateRange: any, propName?: any) => { + const search = params + search.params = {} + if (dateRange !== null && dateRange !== '') { + if (typeof (propName) === 'undefined') { + search.params.beginTime = dateRange[0] + search.params.endTime = dateRange[1] + } else { + search.params['begin' + propName] = dateRange[0] + search.params['end' + propName] = dateRange[1] + } + } + console.log(search) + return search +} + +/** + * 构造树型结构数据 + * @param {*} data 数据源 + * @param {*} id id字段 默认 'id' + * @param {*} parentId 父节点字段 默认 'parentId' + * @param {*} children 孩子节点字段 默认 'children' + * @param {*} rootId 根Id 默认 0 + */ +export const handleTree = (data?: any, id?: any, parentId?: any, children?: any, rootId?: any) => { + id = id || 'id' + parentId = parentId || 'parentId' + children = children || 'children' + const parentIds = data.map((item: any) => { return item[parentId] }) + rootId = rootId || Math.min(...parentIds) || 0 + // 对源数据深度克隆 + const cloneData = JSON.parse(JSON.stringify(data)) + // 循环所有项 + const treeData = cloneData.filter((father: any) => { + const branchArr = cloneData.filter((child: any) => { + // 返回每一项的子级数组 + return father[id] === child[parentId] + }) + if (branchArr.length > 0) { + father.children = branchArr + } + // 返回第一层 + return father[parentId] === rootId + }) + return treeData !== '' ? treeData : data +} + +// 回显数据字典 +export const selectDictLabel = (datas: Array, value: string) => { + const actions: string[] = [] + Object.keys(datas).some((key) => { + if (datas[key].dictValue === value) { + actions.push(datas[key].dictLabel) + return true + } + }) + return actions.join('') +} + +// 转换字符串,undefined,null等转化为"" +export function praseStrEmpty(str: null | undefined) { + if (!str || str === undefined || str === null) { + return '' + } + return str +} + +// 日期格式化 +export function parseTime(time: any, pattern: any) { + if (arguments.length === 0 || !time) { + return null + } + const format = pattern || '{y}-{m}-{d} {h}:{i}:{s}' + let date + if (typeof time === 'object') { + date = time + } else { + if ((typeof time === 'string') && (/^[0-9]+$/.test(time))) { + time = parseInt(time) + } else if (typeof time === 'string') { + time = time.replace(new RegExp(/-/gm), '/') + } + if ((typeof time === 'number') && (time.toString().length === 10)) { + time = time * 1000 + } + date = new Date(time) + } + const formatObj = { + y: date.getFullYear(), + m: date.getMonth() + 1, + d: date.getDate(), + h: date.getHours(), + i: date.getMinutes(), + s: date.getSeconds(), + a: date.getDay() + } + const timestr = format.replace(/{(y|m|d|h|i|s|a)+}/g, (result: any, key: any) => { + let value = formatObj[key] + // Note: getDay() returns 0 on Sunday + if (key === 'a') { return ['日', '一', '二', '三', '四', '五', '六'][value] } + if (result.length > 0 && value < 10) { + value = '0' + value + } + return value || 0 + }) + return timestr +} diff --git a/src/views/system/dept/index.vue b/src/views/system/dept/index.vue new file mode 100644 index 00000000..d15c137f --- /dev/null +++ b/src/views/system/dept/index.vue @@ -0,0 +1,506 @@ + + +