talk2all-base v1.2.11
快速上手
talk2all-base 基于 vue3 + ts + Element-plus 再次封装的基础组件
vite4+ ndoe16+
安装 正式版 1.2.10+
npm i talk2all-base -S
&
pnpm add talk2all-base -S
使用
// main.ts
import talk2all from 'talk2all-base';
import 'talk2all-base/lib/style.css';
const app = createApp(App);
app.use(talk2all, {
proxyKey: '/api',
pageKey: 'page', // 分页字段
sizeKey: 'size', // 分页字段
tokenKey: 'token', // token 存储在localStorage
ISOK: 200, // 响应成功返回
ISERROR: 500, // 响应错误状态返回
codeKey: 'code', // 响应状态返回字段
msgKey: 'msg', // 响应提示文字返回字段
/* 分页接口
data => 表格 数据层级 数据结构 data.data
total => 总页数 数据层级 数据结构 data.data
*/
pageResponse: {
data: 'data', // 返回
total: 'total',
},
/* 详情接口 detailedInterface
data => 详情 数据层级 数据结构 data.data
*/
infoResponse: {
data: 'data', // 返回数据结构 data.data
},
});
app.mount('#app');
talk2AllBase 组件使用
<script setup lang="tsx">
import { ref, reactive } from 'vue';
import type {
TableBaseType,
BaseColumns,
} from 'talk2all-base/lib/tableBase/index';
import type { FormRules } from 'element-plus';
interface addFormVO {
title: string;
}
const talk2AllBaseRef: any = ref<TableBaseType>();
const columns: BaseColumns[] = reactive<BaseColumns[]>([
{
label: '名称',
prop: 'name',
align: 'center',
width: '200px',
},
{
label: '描述',
prop: 'prompt',
align: 'left',
},
{
label: '时间',
prop: 'time',
width: '180px',
},
{
label: '标题',
prop: 'title',
width: '180px',
},
{
label: '操作',
prop: '',
width: '100px',
render: (row: any) => {
return (
<div>
<el-button type="text" onclick={() => edit(row)}>
编辑
</el-button>
<el-button type="text" onclick={() => info(row)}>
查看
</el-button>
</div>
);
},
},
]);
const formInline = ref({
name: '',
});
const addForm = ref<addFormVO>({
title: '',
});
const rules = ref<FormRules<addFormVO>>({
title: { required: true, message: '标题不能为空', trigger: 'blur' },
});
const edit = (row: any) => {
talk2AllBaseRef.value?.edit(row.id);
};
const info = (row: any) => {
talk2AllBaseRef.value?.info(row.id);
};
</script>
<template>
<div class="table-box">
<talk2-all-base
ref="talk2AllBaseRef"
:hasselection="true"
:has-batch-delete="true"
:has-add="true"
:form-inline="formInline"
:columns="columns"
:addForm="addForm"
:rules="rules"
api-for-page=""
api-for-save=""
api-for-info=""
api-for-put=""
api-for-delete=""
>
<template #searchForm="data">
<el-form-item label="客户名称" prop="name">
<el-input v-model="data.formInline.name" placeholder="请输入客户名称">
</el-input>
</el-form-item>
</template>
<template #addForm="data">
<el-form-item label="标题" prop="title">
<el-input
v-model="data.addForm.title"
placeholder="请输入标题"
clearable
>
</el-input>
</el-form-item>
</template>
</talk2-all-base>
</div>
</template>
<style lang="scss" scoped>
.table-box {
width: 100%;
height: 600px;
}
</style>
tablebase 组件参数说明
参数 | 说明 | 类型 | 默认值 |
---|---|---|---|
apiForPage | 分页查询 | string | 空 |
apiForSave | 新增保存 | string | 空 |
apiForDelete | 删除 | string | 空 |
apiForPut | 修改 | string | 空 |
apiForInfo | 详情 | string | 空 |
rowKey | 表格主键 多层级用到此 id | string | id |
rowId | 表格 id 详情删除用到此 id | string | id |
operationtype | 表单状态 | string | add |
autoInit | 默认查询表格 | boolean | true |
hasAdd | 新增按钮 是否显示 | boolean | true |
hasBatchDelete | 批量删除 是否显示 | boolean | true |
hasSearch | 搜索按钮 是否显示 | boolean | true |
hasClear | 清空按钮 是否显示 | boolean | true |
hasformInlineBox | 搜索区域 是否显示 | boolean | true |
haspagination | 分页 是否显示 | boolean | true |
hasindex | 序号 是否显示 | boolean | true |
hasselection | 勾选框 是否显示 | boolean | true |
columns | 表头数据 | Array | [] |
addForm | 新增数据 | object | {} |
rules | 新增数据校验规则 | object | {} |
labelWidth | 新增数据表单表头宽度 | sting,number | 100px |
formInline | 查询数据 | object | {} |
pageResponse | 分页返回数据结构 同上 | object | {} |
infoResponse | 详情返回数据结构 | object | {} |
addBeforCallBack | 新增前回调 返回 false 阻止后续事件 | Function | |
editBeforCallBack | 编辑前回调 返回 false 阻止后续事件 | Function | |
infoBeforCallBack | 查看详情前回调 返回 false 阻止后续事件 | Function | |
submitBeforCallBack | 编辑新增提交前回调 返回 false 阻止后续事件 | Function |
tablebase 事件说明
事件名 | 说明 | 返回 |
---|---|---|
pageCallBack | 表格数据请求成功 | 返回表格数据 |
selection-change | 表格勾选数据返回 | 返回勾选表格数据 |
submitCallBack | 新增 编辑完成成功 | null |
infoCallBack | 详情接口请求成功 | 请求数据详情 |
resetFields | 清空按钮回调 | null |
clsoeDialog | 弹窗关闭回调 | null |
error | 接口请求失败的回调 | res(返回数据),type (接口类型)page,info,add,edit,delete |
tablebase 方法说明
方法名 | 说明 | 参数 | 返回 |
---|---|---|---|
search | 刷新表格 页面重置为 1 | null | null |
query | 刷新表格 页面不重置 | null | null |
add | 新增方法(打开新增弹窗) | null | null |
delete | 删除列(调用删除接口) | id | null |
edit | 编辑列(调用编辑接口) | string ,number,object | null |
info | 查看列(调用编辑接口,表单会禁止输入) | string ,number,object | null |
formInlineRef | 查询表单对象 ref | null | null |
addFormRef | 新增编辑表单对象 ref | null | null |
openDialog | 打开新增编辑弹窗 | string 'add','info','edit' | null |
clsoeDialog | 关闭新增编辑弹窗 | null | null |
tablebase 插槽说明
插槽名 | 说明 |
---|---|
formInline | 搜索区域(左侧) 作用域参数为 {formInline} |
optionForm | 功能按钮区域(右侧) |
addForm | 弹窗表单 作用域参数为 {addForm} |
dialogFoot | 弹窗按钮区域 |
operationtype 表单状态
参数 | 说明 | 类型 |
---|---|---|
add | 新增 | string |
edit | 编辑 data.data | string |
info | 详情 data.data | string |
columns 参数说明
参数 | 说明 | 类型 | 可选值 | 默认值 |
---|---|---|---|---|
label | 显示的标题 | string | - | - |
prop | 字段名称 对应列内容的字段名 | string | - | - |
align | 对齐方式 | string | left / center / right | center |
width | 对应列的宽度 | string / number | - | - |
minWidth | 对应列的最小宽度 | string / number | - | - |
sortable | 对应列是否可以排序 | boolean | - | fasle |
fixed | 列是否固定在左侧或者右侧 | string | - | - |
showOverflowTooltip | 当内容过长被隐藏时显示 tooltip | boolean | - | true |
render | 使用 render 函数 | function | 返回当前行的数据 ,index | - |
children | 多层级表头 | Array | - | - |
// 需要在使用的项目的tsconfig.json文件中添加以下
compilerOptions:{
"types": [
"talk2all-base/global",
],
}
// 如果表单的清空提交不做处理 需要在使用的项目的vite.config文件中 注释此段的代码
import Components from 'unplugin-vue-components/vite';
Components({
resolvers: [ElementPlusResolver()],
}),
// 或者删除局部引入 elfrom 或者 elfromitem
import { ElForm, ElFormItem } from 'element-plus';
// 如果tsx 语法eslint报错 tsconfig.json
{
"compilerOptions": {
"noImplicitAny": false, // 隐式具有“any”类型
}
}
联系我 506970220@qq.com
3 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago