From 4693f1067739e5790993222019f07efe35919b0f Mon Sep 17 00:00:00 2001 From: xiaobai <857694115@qq.com> Date: Fri, 23 Jul 2021 17:42:01 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E4=BB=A3=E7=A0=81=EF=BC=8C?= =?UTF-8?q?=E9=83=A8=E5=88=86=E6=8A=A5=E9=94=99=E4=BB=8D=E5=BE=85=E8=A7=A3?= =?UTF-8?q?=E5=86=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/common.js | 97 +++ src/api/data.js | 9 + src/api/dic_data.js | 40 + src/api/instrument.js | 46 ++ src/api/instrument_move.js | 31 + src/api/role.js | 52 ++ src/components/Crud/Delete/index.vue | 70 ++ src/components/Crud/Edit/index.vue | 21 + src/components/Crud/Pagination/index.vue | 20 + src/components/Crud/Query/index.vue | 17 + src/components/Crud/Table/index.vue | 115 +++ src/components/Crud/crud.js | 740 ++++++++++++++++++ src/components/Crud/index.vue | 167 ++++ src/components/TreeSelect/index.vue | 169 ++++ src/components/drawerDialog/index.vue | 111 ++- src/components/subTable/index.vue | 124 +++ src/views/allot/old_list.vue | 306 -------- src/views/allot/team_list.vue | 39 +- src/views/allot/zuofei_list.vue | 150 ---- src/views/base/list.vue | 150 ---- src/views/bjd/department_list.vue | 13 +- src/views/bjd/dj_input.vue | 9 +- src/views/bjd/jj_input.vue | 7 +- src/views/bjd/wx_list.vue | 525 ------------- src/views/bjd/zj_input.vue | 7 +- src/views/bjd/zj_list.vue | 362 --------- src/views/bjd/zlsc_list.vue | 444 ----------- src/views/bjd/zlsc_list_all.vue | 509 ------------ .../device_management/components/Move.vue | 316 ++++++++ src/views/device_management/index.vue | 557 +++++++++++++ src/views/dic/category.vue | 133 +++- src/views/dic/dic_type.vue | 453 ++++++++++- src/views/preview/old_project.vue | 16 - src/views/print/1000/print_list_depar.vue | 427 ---------- src/views/print/1000/print_list_zj.vue | 476 ----------- src/views/print/2000/print_list_zj.vue | 489 ------------ src/views/print/7000/print_list.vue | 339 -------- src/views/print/print_list_bg.vue | 495 ------------ src/views/print/print_list_jl.vue | 354 --------- src/views/task/list.vue | 23 +- src/views/user/department.vue | 46 +- src/views/user/role.vue | 189 ++++- src/views/user/user.vue | 304 +++++-- 43 files changed, 3655 insertions(+), 5312 deletions(-) create mode 100644 src/api/data.js create mode 100644 src/api/dic_data.js create mode 100644 src/api/instrument.js create mode 100644 src/api/instrument_move.js create mode 100644 src/api/role.js create mode 100644 src/components/Crud/Delete/index.vue create mode 100644 src/components/Crud/Edit/index.vue create mode 100644 src/components/Crud/Pagination/index.vue create mode 100644 src/components/Crud/Query/index.vue create mode 100644 src/components/Crud/Table/index.vue create mode 100644 src/components/Crud/crud.js create mode 100644 src/components/Crud/index.vue create mode 100644 src/components/TreeSelect/index.vue create mode 100644 src/components/subTable/index.vue delete mode 100644 src/views/allot/old_list.vue delete mode 100644 src/views/allot/zuofei_list.vue delete mode 100644 src/views/base/list.vue delete mode 100644 src/views/bjd/wx_list.vue delete mode 100644 src/views/bjd/zj_list.vue delete mode 100644 src/views/bjd/zlsc_list.vue delete mode 100644 src/views/bjd/zlsc_list_all.vue create mode 100644 src/views/device_management/components/Move.vue create mode 100644 src/views/device_management/index.vue delete mode 100644 src/views/preview/old_project.vue delete mode 100644 src/views/print/1000/print_list_depar.vue delete mode 100644 src/views/print/1000/print_list_zj.vue delete mode 100644 src/views/print/2000/print_list_zj.vue delete mode 100644 src/views/print/7000/print_list.vue delete mode 100644 src/views/print/print_list_bg.vue delete mode 100644 src/views/print/print_list_jl.vue diff --git a/src/api/common.js b/src/api/common.js index 06f25fc..ba92a53 100644 --- a/src/api/common.js +++ b/src/api/common.js @@ -32,4 +32,101 @@ export function backToLeaderFn(params) { return require('qs').stringify(data, { indices: false }) } }) +} +export function updateDepartmentFn(params) { + return api({ + url: '/department', + method: 'put', + data: params, + paramsSerializer: function(data) { + return require('qs').stringify(data, { indices: false }) + } + }) +} +export function deleteDepartmentFn(params) { + return api({ + url: '/department', + method: 'delete', + params: params, + paramsSerializer: function(data) { + return require('qs').stringify(data, { indices: false }) + } + }) +} +export function addDepartmentFn(data) { + return api({ + url: '/department', + method: 'post', + data: data, + paramsSerializer: function(data) { + return require('qs').stringify(data, { indices: false }) + } + }) +} +export function updateTeamFn(params) { + return apibjd({ + url: '/team', + method: 'put', + data: params, + paramsSerializer: function(data) { + return require('qs').stringify(data, { indices: false }) + } + }) +} +export function deleteTeamFn(params) { + return apibjd({ + url: '/team', + method: 'delete', + params: params, + paramsSerializer: function(data) { + return require('qs').stringify(data, { indices: false }) + } + }) +} +export function addTeamFn(params) { + return apibjd({ + url: '/team', + method: 'post', + data: params, + paramsSerializer: function(data) { + return require('qs').stringify(data, { indices: false }) + } + }) +} +export function deleteRenwuFn(params) { + return apibjd({ + url: '/renwu', + method: 'delete', + params: params, + paramsSerializer: function(data) { + return require('qs').stringify(data, { indices: false }) + } + }) +} +export function cancelRenwuFn(params) { + return apibjd({ + url: '/renwu/zfRenwu', + method: 'delete', + params: params, + paramsSerializer: function(data) { + return require('qs').stringify(data, { indices: false }) + } + }) +} +export function initData(params) { + return api({ + url: '/role/listRole', + method: 'get', + params: params, + paramsSerializer: function(data) { + return require('qs').stringify(data, { indices: false }) + } + }) +} +export function getDepartmentTreeList(params) { + return api({ + url: '/department', + method: 'get', + params + }) } diff --git a/src/api/data.js b/src/api/data.js new file mode 100644 index 0000000..87ee29c --- /dev/null +++ b/src/api/data.js @@ -0,0 +1,9 @@ +import api from '@/utils/api' +import qs from 'qs' + +export function initData(url, params) { + return api({ + url: url + '?' + qs.stringify(params, { indices: false }), + method: 'get' + }) +} diff --git a/src/api/dic_data.js b/src/api/dic_data.js new file mode 100644 index 0000000..b13f015 --- /dev/null +++ b/src/api/dic_data.js @@ -0,0 +1,40 @@ +import api from '@/utils/api' + +export function add(data) { + return api({ + url: '/dicData', + method: 'post', + data + }) +} + +export function edit(data) { + return api({ + url: '/dicData', + method: 'put', + data + }) +} + +export function del(id) { + return api({ + url: '/dicData/' + id, + method: 'delete' + }) +} + +export function getAllDicData() { + return api({ + url: '/dicData/getAll', + method: 'get' + }) +} + +export function getDicDataListByTypeName(typeName) { + return api({ + url: '/dicData/getDicDataListByTypeName/' + typeName, + method: 'get' + }) +} + +export default { add, edit, del, getAllDicData } diff --git a/src/api/instrument.js b/src/api/instrument.js new file mode 100644 index 0000000..4df3ce4 --- /dev/null +++ b/src/api/instrument.js @@ -0,0 +1,46 @@ +import api from '@/utils/api' +import qs from 'qs' + +export function add(data) { + return api({ + url: '/instrument', + method: 'post', + data + }) +} + +export function edit(data) { + return api({ + url: '/instrument', + method: 'put', + data + }) +} + +export function del(params) { + return api({ + url: '/instrument', + method: 'delete', + params, + paramsSerializer: function(params) { + return qs.stringify(params, { indices: false }) + } + }) +} + +export function getDepartmentStatistical() { + return api({ + url: '/instrument/getDepartmentStatistical', + method: 'get' + }) +} + +export function exportExcel(params) { + return api({ + url: '/instrument/exportExcel' + '?' + qs.stringify(params, { indices: false }), + method: 'get', + responseType: 'blob' + }) +} + +export default { add, edit, del, exportExcel } diff --git a/src/api/instrument_move.js b/src/api/instrument_move.js new file mode 100644 index 0000000..4cab98d --- /dev/null +++ b/src/api/instrument_move.js @@ -0,0 +1,31 @@ +import api from '@/utils/api' +import qs from 'qs' + +export function add(data) { + return api({ + url: '/move', + method: 'post', + data + }) +} + +export function edit(data) { + return api({ + url: '/move', + method: 'put', + data + }) +} + +export function del(params) { + return api({ + url: '/move', + method: 'delete', + params, + paramsSerializer: function(params) { + return qs.stringify(params, { indices: false }) + } + }) +} + +export default { add, edit, del } diff --git a/src/api/role.js b/src/api/role.js new file mode 100644 index 0000000..e949511 --- /dev/null +++ b/src/api/role.js @@ -0,0 +1,52 @@ +import api from '@/utils/api' +import qs from 'qs' + +export function add(data) { + return api({ + url: '/role', + method: 'post', + data + }) +} + +export function edit(data) { + return api({ + url: '/role', + method: 'put', + data + }) +} +export function del(params) { + return api({ + url: '/role', + method: 'delete', + params, + paramsSerializer: function(params) { + return qs.stringify(params, { indices: false }) + } + }) +} + +export function getRoleList(params) { + return api({ + url: '/role', + method: 'get', + params + }) +} + +export function getRoleMenuList(roleId) { + return api({ + url: '/role/getRoleMenuList/' + roleId, + method: 'get' + }) +} + +export function getAllRole() { + return api({ + url: '/role/getAllRole', + method: 'get' + }) +} + +export default { add, edit, del, getRoleMenuList } diff --git a/src/components/Crud/Delete/index.vue b/src/components/Crud/Delete/index.vue new file mode 100644 index 0000000..eb387b6 --- /dev/null +++ b/src/components/Crud/Delete/index.vue @@ -0,0 +1,70 @@ + + diff --git a/src/components/Crud/Edit/index.vue b/src/components/Crud/Edit/index.vue new file mode 100644 index 0000000..7892b1a --- /dev/null +++ b/src/components/Crud/Edit/index.vue @@ -0,0 +1,21 @@ + + diff --git a/src/components/Crud/Pagination/index.vue b/src/components/Crud/Pagination/index.vue new file mode 100644 index 0000000..28d5660 --- /dev/null +++ b/src/components/Crud/Pagination/index.vue @@ -0,0 +1,20 @@ + + + diff --git a/src/components/Crud/Query/index.vue b/src/components/Crud/Query/index.vue new file mode 100644 index 0000000..6980793 --- /dev/null +++ b/src/components/Crud/Query/index.vue @@ -0,0 +1,17 @@ + + + diff --git a/src/components/Crud/Table/index.vue b/src/components/Crud/Table/index.vue new file mode 100644 index 0000000..a7cb486 --- /dev/null +++ b/src/components/Crud/Table/index.vue @@ -0,0 +1,115 @@ + + + + diff --git a/src/components/Crud/crud.js b/src/components/Crud/crud.js new file mode 100644 index 0000000..474d8cb --- /dev/null +++ b/src/components/Crud/crud.js @@ -0,0 +1,740 @@ +import { initData } from '@/api/data' +import Vue from 'vue' + +/** + * CRUD 配置 + * @param options + * @author zhoujl fork by eladmin + */ +function CRUD(options) { + const defaultOptions = { + // 标题 + title: '', + // 请求数据的url + url: '', + // 表格数据 + data: [], + // 选择项 + selections: [], + // 待查询的对象 + query: {}, + // 查询数据的参数 + params: {}, + // Form 表单 + form: {}, + // 重置表单 + defaultForm: () => {}, + // 排序规则,默认 id 降序, 支持多字段排序 ['id,desc', 'createTime,asc'] + orderBy: ['id,desc'], + // 等待时间 + time: 50, + // CRUD Method + crudMethod: { + add: (form) => {}, + delete: (id) => {}, + edit: (form) => {}, + get: (id) => {} + }, + // 主页操作栏显示哪些按钮 + optionShow: { + add: true, + edit: true, + del: true + }, + // 自定义一些扩展属性 + props: {}, + // 在主页准备 + queryOnPresenterCreated: true, + // 调试开关 + debug: false + } + options = mergeOptions(defaultOptions, options) + // 定义数据 + const data = { + ...options, + // 记录数据状态 + dataStatus: {}, + status: { + add: CRUD.STATUS.NORMAL, + edit: CRUD.STATUS.NORMAL, + // 添加或编辑状态 + get editor() { + if (this.add === CRUD.STATUS.NORMAL && this.edit === CRUD.STATUS.NORMAL) { + return CRUD.STATUS.NORMAL + } else if (this.add === CRUD.STATUS.PREPARED || this.edit === CRUD.STATUS.PREPARED) { + return CRUD.STATUS.PREPARED + } else if (this.add === CRUD.STATUS.PROCESSING || this.edit === CRUD.STATUS.PROCESSING) { + return CRUD.STATUS.PROCESSING + } + throw new Error('wrong crud\'s editor status') + }, + // 标题 + get title() { + return this.add > CRUD.STATUS.NORMAL ? `新增${crud.title}` : this.edit > CRUD.STATUS.NORMAL ? `编辑${crud.title}` : crud.title + } + }, + msg: { + submit: '提交成功', + add: '新增成功', + edit: '编辑成功', + del: '删除成功' + }, + page: { + // 页码 + pageNum: 1, + // 每页数据条数 + pageSize: 20, + // 总数据条数 + total: 0 + } + } + const methods = { + /** + * 通用的提示 + */ + submitSuccessNotify() { + crud.notify(crud.msg.submit, CRUD.NOTIFICATION_TYPE.SUCCESS) + }, + addSuccessNotify() { + crud.notify(crud.msg.add, CRUD.NOTIFICATION_TYPE.SUCCESS) + }, + editSuccessNotify() { + crud.notify(crud.msg.edit, CRUD.NOTIFICATION_TYPE.SUCCESS) + }, + delSuccessNotify() { + crud.notify(crud.msg.del, CRUD.NOTIFICATION_TYPE.SUCCESS) + }, + // 搜索 + toQuery() { + crud.page.pageNum = 1 + crud.refresh() + }, + // 刷新 + refresh() { + if (!callVmHook(crud, CRUD.HOOK.beforeRefresh)) { + return + } + return new Promise((resolve) => { + // 请求数据 + initData(crud.url, crud.getQueryParams()).then(data => { + crud.page.total = data.total + if (data.list) { + crud.data = data.list + } else { + crud.data = data + } + crud.resetDataStatus() + // time 毫秒后显示表格 + setTimeout(() => { + callVmHook(crud, CRUD.HOOK.afterRefresh) + }, crud.time) + resolve(data) + }) + }) + }, + /** + * 启动添加 + */ + toAdd() { + if (!(callVmHook(crud, CRUD.HOOK.beforeToAdd, crud.form) && callVmHook(crud, CRUD.HOOK.beforeToCU, crud.form))) { + return + } + crud.status.add = CRUD.STATUS.PREPARED + callVmHook(crud, CRUD.HOOK.afterToAdd, crud.form) + callVmHook(crud, CRUD.HOOK.afterToCU, crud.form) + }, + /** + * 启动编辑 + * @param {*} data 数据项 + */ + toEdit(data) { + crud.resetForm(JSON.parse(JSON.stringify(data))) + if (!(callVmHook(crud, CRUD.HOOK.beforeToEdit, crud.form) && callVmHook(crud, CRUD.HOOK.beforeToCU, crud.form))) { + return + } + crud.status.edit = CRUD.STATUS.PREPARED + crud.getDataStatus(data.id).edit = CRUD.STATUS.PREPARED + callVmHook(crud, CRUD.HOOK.afterToEdit, crud.form) + callVmHook(crud, CRUD.HOOK.afterToCU, crud.form) + }, + /** + * 启动删除 + * @param {*} data 数据项 + */ + toDelete(data) { + crud.getDataStatus(data.id).delete = CRUD.STATUS.PREPARED + }, + /** + * 取消删除 + * @param {*} data 数据项 + */ + cancelDelete(data) { + if (!callVmHook(crud, CRUD.HOOK.beforeDeleteCancel, data)) { + return + } + crud.getDataStatus(data.id).delete = CRUD.STATUS.NORMAL + callVmHook(crud, CRUD.HOOK.afterDeleteCancel, data) + }, + /** + * 取消新增/编辑 + */ + cancelCU() { + const addStatus = crud.status.add + const editStatus = crud.status.edit + if (addStatus === CRUD.STATUS.PREPARED) { + if (!callVmHook(crud, CRUD.HOOK.beforeAddCancel, crud.form)) { + return + } + crud.status.add = CRUD.STATUS.NORMAL + } + if (editStatus === CRUD.STATUS.PREPARED) { + if (!callVmHook(crud, CRUD.HOOK.beforeEditCancel, crud.form)) { + return + } + crud.status.edit = CRUD.STATUS.NORMAL + crud.getDataStatus(crud.form.id).edit = CRUD.STATUS.NORMAL + } + crud.resetForm() + if (addStatus === CRUD.STATUS.PREPARED) { + callVmHook(crud, CRUD.HOOK.afterAddCancel, crud.form) + } + if (editStatus === CRUD.STATUS.PREPARED) { + callVmHook(crud, CRUD.HOOK.afterEditCancel, crud.form) + } + // 清除表单验证 + if (crud.findVM('form').$refs['form']) { + crud.findVM('form').$refs['form'].clearValidate() + } + }, + /** + * 提交新增/编辑 + */ + submitCU() { + if (!callVmHook(crud, CRUD.HOOK.beforeValidateCU)) { + return + } + crud.findVM('form').$refs['form'].validate(valid => { + if (!valid) { + return + } + if (!callVmHook(crud, CRUD.HOOK.afterValidateCU)) { + return + } + if (crud.status.add === CRUD.STATUS.PREPARED) { + crud.doAdd() + } else if (crud.status.edit === CRUD.STATUS.PREPARED) { + crud.doEdit() + } + }) + }, + /** + * 执行添加 + */ + doAdd() { + if (!callVmHook(crud, CRUD.HOOK.beforeSubmit)) { + return + } + crud.status.add = CRUD.STATUS.PROCESSING + crud.crudMethod.add(crud.form).then(() => { + crud.status.add = CRUD.STATUS.NORMAL + crud.resetForm() + crud.addSuccessNotify() + callVmHook(crud, CRUD.HOOK.afterSubmit) + crud.toQuery() + }).catch(() => { + crud.status.add = CRUD.STATUS.PREPARED + callVmHook(crud, CRUD.HOOK.afterAddError) + }) + }, + /** + * 执行编辑 + */ + doEdit() { + if (!callVmHook(crud, CRUD.HOOK.beforeSubmit)) { + return + } + crud.status.edit = CRUD.STATUS.PROCESSING + crud.crudMethod.edit(crud.form).then(() => { + crud.status.edit = CRUD.STATUS.NORMAL + crud.getDataStatus(crud.form.id).edit = CRUD.STATUS.NORMAL + crud.editSuccessNotify() + crud.resetForm() + callVmHook(crud, CRUD.HOOK.afterSubmit) + crud.refresh() + }).catch(() => { + crud.status.edit = CRUD.STATUS.PREPARED + callVmHook(crud, CRUD.HOOK.afterEditError) + }) + }, + /** + * 执行删除 + * @param {*} data 数据项 + */ + doDelete(data) { + let delAll = false + let dataStatus + const ids = [] + let singleId = 0 + if (data instanceof Array) { + delAll = true + data.forEach(val => { + ids.push(val.id) + }) + } else { + singleId = data.id + dataStatus = crud.getDataStatus(data.id) + } + if (!callVmHook(crud, CRUD.HOOK.beforeDelete, data)) { + return + } + if (!delAll) { + dataStatus.delete = CRUD.STATUS.PROCESSING + } + return crud.crudMethod.del(delAll ? { idArray: ids } : singleId).then(() => { + if (!delAll) { + dataStatus.delete = CRUD.STATUS.PREPARED + } + crud.dleChangePage(1) + crud.delSuccessNotify() + callVmHook(crud, CRUD.HOOK.afterDelete, data) + crud.refresh() + }).catch(() => { + if (!delAll) { + dataStatus.delete = CRUD.STATUS.PREPARED + } + }) + }, + /** + * 获取查询参数 + */ + getQueryParams: function() { + return { + pageNum: crud.page.pageNum, + pageSize: crud.page.pageSize, + orderBy: crud.orderBy, + ...crud.query, + ...crud.params + } + }, + // 当前页改变 + pageChangeHandler(e) { + crud.page.pageNum = e + crud.refresh() + }, + // 每页条数改变 + sizeChangeHandler(e) { + crud.page.pageSize = e + crud.page.pageNum = 1 + crud.refresh() + }, + // 预防删除第二页最后一条数据时,或者多选删除第二页的数据时,页码错误导致请求无数据 + dleChangePage(size) { + if (crud.data.length === size && crud.page.pageNum !== 1) { + crud.page.pageNum -= 1 + } + }, + // 选择改变 + selectionChangeHandler(val) { + crud.selections = val + }, + // 点击行选中 + rowClickHandler(row) { + crud.findVM('presenter').$refs['customTable'].$refs['table'].toggleRowSelection(row) + callVmHook(crud, CRUD.HOOK.afterRowClick, row) + }, + /** + * 重置查询参数 + * @param {Boolean} toQuery 重置后进行查询操作 + */ + resetQuery(toQuery = true) { + const defaultQuery = JSON.parse(JSON.stringify(crud.defaultQuery)) + const query = crud.query + Object.keys(query).forEach(key => { + query[key] = defaultQuery[key] + }) + if (toQuery) { + crud.toQuery() + } + callVmHook(crud, CRUD.HOOK.afterResetQuery) + }, + /** + * 重置表单 + * @param {Array} data 数据 + */ + resetForm(data) { + const form = data || (typeof crud.defaultForm === 'object' ? JSON.parse(JSON.stringify(crud.defaultForm)) : crud.defaultForm()) + const crudFrom = crud.form + for (const key in form) { + if (Object.prototype.hasOwnProperty.call(form, key)) { + if (Object.prototype.hasOwnProperty.call(crudFrom, key)) { + crudFrom[key] = form[key] + } else { + Vue.set(crudFrom, key, form[key]) + } + } + } + }, + /** + * 重置数据状态 + */ + resetDataStatus() { + const dataStatus = {} + + function resetStatus(datas) { + datas.forEach(e => { + dataStatus[e.id] = { + delete: 0, + edit: 0 + } + if (e.children) { + resetStatus(e.children) + } + }) + } + resetStatus(crud.data) + crud.dataStatus = dataStatus + }, + /** + * 获取数据状态 + * @param {Number | String} id 数据项id + */ + getDataStatus(id) { + return crud.dataStatus[id] + }, + /** + * 切换选中状态 + * @param selection + * @param data + */ + toggleRowSelection(selection, data) { + if (data.children) { + data.children.forEach(val => { + crud.findVM('presenter').$refs['customTable'].$refs['table'].toggleRowSelection(val, false) + if (val.children) { + crud.toggleRowSelection(selection, val) + } + }) + } + }, + findVM(type) { + return crud.vms.find(vm => vm && vm.type === type).vm + }, + notify(title, type = CRUD.NOTIFICATION_TYPE.INFO) { + crud.vms[0].vm.$notify({ + title, + type, + duration: 2500 + }) + }, + updateProp(name, value) { + Vue.set(crud.props, name, value) + } + } + const crud = Object.assign({}, data) + // 可观测化 + Vue.observable(crud) + // 附加方法 + Object.assign(crud, methods) + // 记录初始默认的查询参数,后续重置查询时使用 + Object.assign(crud, { + defaultQuery: JSON.parse(JSON.stringify(data.query)), + // 预留4位存储:组件 主页、头部、分页、表单,调试查看也方便找 + vms: Array(4), + /** + * 注册组件实例 + * @param {String} type 类型 + * @param {*} vm 组件实例 + * @param {Number} index 该参数内部使用 + */ + registerVM(type, vm, index = -1) { + const vmObj = { + type, + vm: vm + } + if (index < 0) { + this.vms.push(vmObj) + return + } + this.vms.length = Math.max(this.vms.length, index) + this.vms.splice(index, 1, vmObj) + }, + /** + * 取消注册组件实例 + * @param {*} vm 组件实例 + */ + unregisterVM(vm) { + this.vms.splice(this.vms.findIndex(e => e && e.vm === vm), 1) + } + }) + // 冻结处理,需要扩展数据的话,使用crud.updateProp(name, value),以crud.props.name形式访问,这个是响应式的,可以做数据绑定 + Object.freeze(crud) + return crud +} + +/** + * 合并选项参数 + */ +function mergeOptions(src, options) { + const optionsRet = { + ...src + } + for (const key in src) { + if (Object.prototype.hasOwnProperty.call(src, key)) { + if (Object.prototype.hasOwnProperty.call(options, key)) { + optionsRet[key] = options[key] + } + } + } + return optionsRet +} + +// hook VM +function callVmHook(crud, hook) { + if (crud.debug) { + console.log('callVmHook: ' + hook) + } + let result = true + const args = [crud] + for (let i = 2; i < arguments.length; ++i) { + args.push(arguments[i]) + } + // 有些组件扮演了多个角色,调用钩子时,需要去重 + const vmSet = new Set() + crud.vms.forEach(vm => vm && vmSet.add(vm.vm)) + vmSet.forEach(vm => { + if (vm[hook]) { + result = vm[hook].apply(vm, args) !== false && result + } + }) + return result +} + +/** + * crud主页 + */ +function presenter(crud) { + function obColumns(columns) { + return { + visible(col) { + return !columns || !columns[col] ? true : columns[col].visible + } + } + } + return { + inject: ['crud'], + beforeCreate() { + // 由于initInjections在initProvide之前执行,如果该组件自己就需要crud,需要在initInjections前准备好crud + this._provided = { + crud, + 'crud.query': crud.query, + 'crud.page': crud.page, + 'crud.form': crud.form + } + }, + data() { + return { + searchToggle: true, + columns: obColumns() + } + }, + created() { + this.crud.registerVM('presenter', this, 0) + if (crud.queryOnPresenterCreated) { + crud.resetQuery() + } + }, + beforeDestroy() { + this.crud.unregisterVM(this) + // 清除选中的数组 + this.$refs.customTable.$refs['table'].clearSelection() + }, + mounted() { + const columns = {} + setTimeout(() => { + this.$refs.customTable.$refs.table.columns.forEach(e => { + if (!e.property || e.type !== 'default') { + return + } + columns[e.property] = { + label: e.label, + visible: true + } + }) + this.columns = obColumns(columns) + this.crud.updateProp('tableColumns', columns) + }, 1) + } + } +} + +/** + * 头部 + */ +function header() { + return { + inject: { + crud: { + from: 'crud' + }, + query: { + from: 'crud.query' + } + }, + created() { + this.crud.registerVM('header', this, 1) + }, + beforeDestroy() { + this.crud.unregisterVM(this) + } + } +} + +/** + * 分页 + */ +function pagination() { + return { + inject: { + crud: { + from: 'crud' + }, + page: { + from: 'crud.page' + } + }, + created() { + this.crud.registerVM('pagination', this, 2) + }, + beforeDestroy() { + this.crud.unregisterVM(this) + } + } +} + +/** + * 表单 + */ +function form(defaultForm) { + return { + inject: { + crud: { + from: 'crud' + }, + form: { + from: 'crud.form' + } + }, + created() { + this.crud.registerVM('form', this, 3) + this.crud.defaultForm = defaultForm + this.crud.resetForm() + }, + beforeDestroy() { + this.crud.unregisterVM(this) + } + } +} + +/** + * crud + */ +function crud(options = {}) { + const defaultOptions = { + type: undefined + } + options = mergeOptions(defaultOptions, options) + return { + inject: { + crud: { + from: 'crud' + } + }, + created() { + this.crud.registerVM(options.type, this) + }, + beforeDestroy() { + this.crud.unregisterVM(this) + } + } +} + +/** + * CRUD钩子 + */ +CRUD.HOOK = { + /** 查询条件重置 -之后 */ + afterResetQuery: 'afterCrudResetQuery', + /** 刷新 - 之前 */ + beforeRefresh: 'beforeCrudRefresh', + /** 刷新 - 之后 */ + afterRefresh: 'afterCrudRefresh', + /** 删除 - 之前 */ + beforeDelete: 'beforeCrudDelete', + /** 删除 - 之后 */ + afterDelete: 'afterCrudDelete', + /** 删除取消 - 之前 */ + beforeDeleteCancel: 'beforeCrudDeleteCancel', + /** 删除取消 - 之后 */ + afterDeleteCancel: 'afterCrudDeleteCancel', + /** 新建 - 之前 */ + beforeToAdd: 'beforeCrudToAdd', + /** 新建 - 之后 */ + afterToAdd: 'afterCrudToAdd', + /** 编辑 - 之前 */ + beforeToEdit: 'beforeCrudToEdit', + /** 编辑 - 之后 */ + afterToEdit: 'afterCrudToEdit', + /** 开始 "新建/编辑" - 之前 */ + beforeToCU: 'beforeCrudToCU', + /** 开始 "新建/编辑" - 之后 */ + afterToCU: 'afterCrudToCU', + /** "新建/编辑" 验证 - 之前 */ + beforeValidateCU: 'beforeCrudValidateCU', + /** "新建/编辑" 验证 - 之后 */ + afterValidateCU: 'afterCrudValidateCU', + /** 添加取消 - 之前 */ + beforeAddCancel: 'beforeCrudAddCancel', + /** 添加取消 - 之后 */ + afterAddCancel: 'afterCrudAddCancel', + /** 编辑取消 - 之前 */ + beforeEditCancel: 'beforeCrudEditCancel', + /** 编辑取消 - 之后 */ + afterEditCancel: 'afterCrudEditCancel', + /** 行点击 - 之后 */ + afterRowClick: 'afterCrudRowClick', + /** 提交 - 之前 */ + beforeSubmit: 'beforeCrudSubmitCU', + /** 提交 - 之后 */ + afterSubmit: 'afterCrudSubmitCU', + afterAddError: 'afterCrudAddError', + afterEditError: 'afterCrudEditError' +} + +/** + * CRUD状态 + */ +CRUD.STATUS = { + NORMAL: 0, + PREPARED: 1, + PROCESSING: 2 +} + +/** + * CRUD通知类型 + */ +CRUD.NOTIFICATION_TYPE = { + SUCCESS: 'success', + WARNING: 'warning', + INFO: 'info', + ERROR: 'error' +} + +export default CRUD + +export { + presenter, + header, + form, + pagination, + crud +} diff --git a/src/components/Crud/index.vue b/src/components/Crud/index.vue new file mode 100644 index 0000000..f6b888b --- /dev/null +++ b/src/components/Crud/index.vue @@ -0,0 +1,167 @@ + + + + diff --git a/src/components/TreeSelect/index.vue b/src/components/TreeSelect/index.vue new file mode 100644 index 0000000..b3d61b9 --- /dev/null +++ b/src/components/TreeSelect/index.vue @@ -0,0 +1,169 @@ + + + + + + diff --git a/src/components/drawerDialog/index.vue b/src/components/drawerDialog/index.vue index 9f840cf..2833bc2 100644 --- a/src/components/drawerDialog/index.vue +++ b/src/components/drawerDialog/index.vue @@ -206,6 +206,17 @@
+
+

模板详情

+ + 新增 + +