Skip to content

Commit

Permalink
perf(CrudTable): 优化CrudTable部分代码
Browse files Browse the repository at this point in the history
  • Loading branch information
BoBoooooo committed Sep 15, 2020
1 parent 05e7d32 commit b946b7d
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 511 deletions.
38 changes: 16 additions & 22 deletions src/api/public/crud.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* @file: 通用请求crud
可根据后台接口情况自行修改
* @copyright: BoBo
* @author: BoBo
* @Date: 2020年04月24 11:35:00
Expand All @@ -18,49 +19,42 @@ interface optionsType {
/**
* 操作类型枚举
*/
export const DML = {
INSERT: 'add',
UPDATE: 'update',
DELETE: 'delete',
SELECT: 'list',
TREE: 'tree',
DETAIL: 'detail',
DELETES: 'deleteByIds',
};
export enum DML {
INSERT= 'add',
UPDATE= 'update',
DELETE= 'delete',
SELECT= 'list',
TREE= 'tree',
DETAIL= 'detail',
DELETES='deleteByIds',
}

/**
*
* @param dml 操作类型
* @param tableName 数据库表名
* @param data body data
* @param params query Params
* @param encrypt 是否加密
*/
export function crud(dml:string, tableName:string, data:object = {}, params:any = null, encrypt:boolean = false) {
export function crud(dml:DML, tableName:string, data:object = {}, params:any = null) {
const options:optionsType = {
url: `/${tableName}/${dml}`,
url: `/${tableName}/${dml}`, // 例如users表的查询接口为 /users/list
method: 'post',
};
// 以下请求通过包体传参
if ('list,tree'.includes(dml)) {
// 所有list接口后端使用实体类接收,需要保证结构
if ('list'.includes(dml)) {
// list接口高级查询条件拼接
options.data = {
orderCondition: '',
searchCondition: [],
pageIndex: 0,
pageSize: 0,
...data,
};
options.params = params;
} else if ('add,update'.includes(dml) || dml === 'deleteByIds') {
options.data = data;
} else {
// delete,tree两个请求在url传参
options.params = data;
options.data = data;
}
options.params = params;

if (encrypt) {
options.headers.encrypt = true;
}
return axios(options as any);
}
164 changes: 0 additions & 164 deletions src/components/CrudTable/ColumnFilterDialog.vue

This file was deleted.

10 changes: 5 additions & 5 deletions src/components/CrudTable/CrudTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@
:append-to-body="appendToBody"
:close_on_click_modal="closeOnClickModal"
:fullscreen="fullscreen"
@btnonclick="btnOnClick">
@btnonclick="formBtnOnClick">
<template #formTitle>
<slot name="formTitle"></slot>
</template>
Expand Down Expand Up @@ -572,7 +572,7 @@ export default class CrudTable extends Vue {
})
.then(() => {
// 如果prop传入了promiseForDel说明需要回调自定义删除
const promise = this.promiseForDel ? this.promiseForDel({ id: row.id }) : crud(DML.DELETE, this.tableName, { id: row.id });
const promise = this.promiseForDel ? this.promiseForDel({ id: row.id }) : crud(DML.DELETE, this.tableName, {}, { id: row.id });
promise.then(() => {
this.tableReload();
this.$message({
Expand Down Expand Up @@ -646,13 +646,13 @@ export default class CrudTable extends Vue {
}
// 生成的按钮点击
btnOnClick(widget) {
this.$emit('btnOnClick', widget);
formBtnOnClick(widget) {
this.$emit('formBtnOnClick', widget);
}
// 监听dialog中form对象改变
formChange(val) {
this.$emit('change', val);
this.$emit('formChange', val);
}
}
</script>
Expand Down
Loading

0 comments on commit b946b7d

Please sign in to comment.