0.1.53-alpha • Published 2 years ago

heisenberg-element v0.1.53-alpha

Weekly downloads
-
License
-
Repository
-
Last release
2 years ago

简介

heisenberg-element 是基于 element-ui 二次封装的几个常用组件, 可以运行在 vue2.6 vue2.7 的项目中

安装使用

  • 安装
npm install heisenberg-element  or  yarn add heisenberg-element
  • 导入依赖
// main.js

import HeisenbergElement from 'heisenberg-element'
import 'heisenberg-element/lib/heisenberg-element.css'

Vue.use(HeisenbergElement)

使用

  • Dialog
<template>
  <div>
    <el-button @click="handleOpen">打开Dialog</el-button>
    <LbDialog
      title="aaaa"
      @register="register"
      @confirm="hanndleConfirm"
      :confirmLoading="confirmLoading"
      @cancel="handleCancel"
    >
      12321321
    </LbDialog>
  </div>
</template>
<script setup>
import { useDialog } from "heisenberg-element";
import { ref } from "vue";

const confirmLoading = ref(false);

const [register, { openDialog, closeDialog }] = useDialog();

const handleOpen = () => {
  openDialog();
};

const hanndleConfirm = () => {
  confirmLoading.value = true;
  setTimeout(() => {
    confirmLoading.value = false;
    closeDialog();
  }, 2000);
};

const handleCancel = () => {
  console.log("cancel");
};
</script>

Attributes

参数说明类型可选值默认值
value是否显示 dialog 支持 v-modelbooleanfalse
confirmLoading提交按钮加载状态booleanfalse

其他属性请查看element-ui

Slot | name | 说明 | | ----------- | --------------------- | | footer | Dialog 按钮操作区的内容,传入后不触发confirmhandleCancel事件 |

Events | name | 说明 | | ----------- | --------------------- | | confirm | 点击提交按钮 | | cancel | 点击取消按钮触发 | | register | 注册组件事件,在 setup 中配合useDialog使用|

import { useDialog } from "heisenberg-element";
const [
  register,
  { setDialogProps, openDialog, closeDialog, setConfirmLoadong },
] = useDialog();

useDialog

name说明类型参数
register要使用方达必须要监听 register 方法传入register--
setDialogProps设置 Dialog 的 propsFunction见上 Attributes
openDialog打开 DialogFunction传输的数据,可使用useDialogInuseDialogInner的导出的 register 接收
closeDialog关闭 DialogFunction-

useDialogInuseDialogInner

name说明类型参数
closeDialog关闭 DialogFunction-
setDialogProps设置 Dialog 的 propsFunction见上 Attributes
register监听 register 方法传入FunctionFunction, 回调参数为 openDialog 传入的参数
  • LbDrawer
<template>
  <div>
    <el-button @click="openDrawer">打开抽屉</el-button>
    <LbDrawer title="aaaa" @register="register" @confirm="confirm">
      <el-button @click="closeDrawer">关闭</el-button>
    </LbDrawer>
  </div>
</template>
<script setup>
import { useDrawer } from "heisenberg-element";

const [register, { openDrawer, closeDrawer }] = useDrawer();

const confirm = () => {
  console.log("confirm");
};
</script>
  • lbForm
<template>
  <div>
    <LbForm ref="lbForm" @register="register"> </LbForm>
    <el-button @click="handleSubmit">提交</el-button>
    <el-button @click="handleRefSubmit">ref提交</el-button>
  </div>
</template>
<script setup>
import { ref } from "vue";
import { useForm } from "heisenberg-element";

const lbForm = ref(null);

const [register, { submit }] = useForm({
  schemas: [
    {
      field: "name",
      label: "姓名",
      component: "Input",
      rules: [{ required: true, message: "请输入姓名" }],
      colProps: {
        span: 8,
      },
    },
    {
      field: "age",
      label: "年龄",
      component: "InputNumber",
      rules: [{ required: true, message: "请输入年龄" }],
      colProps: {
        span: 8,
      },
    },
  ],
});

const handleSubmit = async () => {
  const data = await submit();
  console.log(data);
};

const handleRefSubmit = async () => {
  const res = await lbForm.value.submit();
  console.log(res);
};
</script>
schemas描述类型
field字段名称string
label表单 labelstring
component组件Input、DatePicker、Select、CheckboxGroup、RadioGroup、Switch、Cascader、InputNumber、Divider、ApiSelectApiCascader
rules规则array
colProps布局-
slot传入插槽后将优先渲染具名插槽-
  • LbTable
<template>
  <div>
    <div>
      <el-button @click="test2">设置加载</el-button>
    </div>
    <lb-table @register="register" boder>
      <template v-slot:date="{ slotScope }">
        <span>{{ slotScope.row.date }}</span>
      </template>
    </lb-table>
  </div>
</template>
<script setup>
import { useTable } from "heisenberg-element";
import axios from "axios";

const test = async (params) => {
  const { data } = await axios.get("http://localhost:30012/", {
    params: params,
  });
  return data;
};

const [register, { setLoading }] = useTable({
  column: [
    {
      prop: "date",
      label: "日期",
      slot: "date",
    },
    {
      prop: "name",
      label: "姓名",
    },
    {
      prop: "province",
      label: "省份",
    },
    {
      prop: "city",
      label: "市区",
    },
    {
      prop: "address",
      label: "地址",
    },
    {
      prop: "zip",
      label: "邮编",
    },
  ],
  pagination: true,
  height: "750",
  boder: true,
  api: test,
});

const test2 = () => {
  setLoading(true);
  setTimeout(() => {
    setLoading(false);
  }, 2000);
};
</script>
  • LbDialog
<template>
  <div>
    <el-button @click="handleOpen">打开Dialog</el-button>
    <LbDialog
      title="aaaa"
      @register="register"
      @confirm="hanndleConfirm"
      :confirmLoading="confirmLoading"
      @cancel="handleCancel"
    >
      12321321
    </LbDialog>
  </div>
</template>
<script setup>
import { useDialog } from "heisenberg-element";
import { ref } from "vue";

const confirmLoading = ref(false);

const [register, { openDialog, closeDialog }] = useDialog();

const handleOpen = () => {
  openDialog();
};

const hanndleConfirm = () => {
  confirmLoading.value = true;
  setTimeout(() => {
    confirmLoading.value = false;
    closeDialog();
  }, 2000);
};

const handleCancel = () => {
  console.log("cancel");
};
</script>
0.1.53-alpha

2 years ago

0.1.52-alpha

2 years ago

0.1.51-alpha

2 years ago

0.1.50-alpha

2 years ago

0.1.44-alpha

2 years ago

0.1.43-alpha

2 years ago

0.1.42-alpha

2 years ago

0.1.41-alpha

2 years ago

0.1.40-alpha

2 years ago

0.1.39-alpha

2 years ago

0.1.38-alpha

2 years ago

0.1.37-alpha

2 years ago

0.1.36-alpha

2 years ago

0.1.35-alpha

2 years ago

0.1.34-alpha

2 years ago

0.1.33-alpha

2 years ago

0.1.32-alpha

2 years ago

0.1.31-alpha

2 years ago

0.1.30-alpha

2 years ago

0.1.29-alpha

2 years ago

0.1.28-alpha

2 years ago

0.1.27-alpha

2 years ago

0.1.26-alpha

2 years ago

0.1.25-alpha

2 years ago

0.1.24-alpha

2 years ago

0.1.23-alpha

2 years ago

0.1.22-alpha

2 years ago

0.1.21-alpha

2 years ago

0.1.20-alpha

2 years ago

0.1.19-alpha

2 years ago

0.1.18-alpha

2 years ago

0.1.17-alpha

2 years ago

0.1.16-alpha

2 years ago

0.1.15-alpha

2 years ago

0.1.14-alpha

2 years ago

0.1.13-alpha

2 years ago

0.1.12

2 years ago

0.1.11

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago

0.0.93

2 years ago

0.0.92

2 years ago

0.0.91

2 years ago

0.0.9

2 years ago

0.0.8

2 years ago