1.0.30-beta.19 • Published 9 months ago

@dang_8899/xl-ui v1.0.30-beta.19

Weekly downloads
-
License
-
Repository
-
Last release
9 months ago

组件

1.KFBtn //按钮组件
## 组件用法示例

### 1. KFBtn(按钮组件)

```js
<template>
  <KFButton type="primary">主要按钮</KFButton>
  <KFButton type="danger">危险按钮</KFButton>
  <KFButton type="primary" :disabled="true">禁用按钮</KFButton>
</template>

2. KFDialog(对话框组件)

<template>
  <KFDialog v-model:visible="dialogVisible" title="标题">
    <div>内容区域</div>
    <template #footer>
      <KFButton @click="dialogVisible = false">取消</KFButton>
      <KFButton type="primary" @click="onConfirm">确定</KFButton>
    </template>
  </KFDialog>
  <KFButton @click="dialogVisible = true">打开对话框</KFButton>
</template>
<script setup lang="ts">
import { ref } from 'vue'
const dialogVisible = ref(false)
const onConfirm = () => {
  dialogVisible.value = false
}
</script>

3. KFInput(输入框组件)

<template>
  <KFInput v-model="inputValue" width="300px" placeholder="请输入内容" />
</template>
<script setup lang="ts">
import { ref } from 'vue'
const inputValue = ref('')
</script>

4. KFSelect(下拉选择组件)

<template>
  <KFSelect v-model="selectValue" :options="options" placeholder="请选择" />
</template>
<script setup lang="ts">
import { ref } from 'vue'
const selectValue = ref('')
const options = [
  { label: '选项一', value: 1 },
  { label: '选项二', value: 2 }
]
</script>

5. KFTable(表格组件)

<template>
  <KFTable :columns="columns" :table-data="tableData" :pagination="true" />
</template>
<script setup lang="ts">
const columns = [
  { prop: 'name', label: '姓名' },
  { prop: 'age', label: '年龄' }
]
const tableData = [
  { name: '张三', age: 25 },
  { name: '李四', age: 30 }
]
</script>

Props 属性

属性名说明类型默认值
loading表格加载中booleanfalse
allData是否全量数据(前端分页)booleanfalse
defaultSort默认排序字段Record<string, string>{}
pageInfo分页信息{currentPage:number;pageSize:number;totalCount:number;}{currentPage:1,pageSize:10,totalCount:0}
rowKey行key字段string''
sortChange自定义排序方法Function() => {}
tableData表格数据object[][]
columns表格列配置any[][]
currentPage当前页number1
totalCount总条数number0
params请求参数object{}
pagination是否显示分页器booleantrue
showExpand是否显示展开行booleanfalse
showExpandTitle展开行标题string''
showExpandProp展开行属性string''
showExpandColWidth展开行列宽number100
children子表格字段string''
hasChildren子表格是否有子级booleanfalse
filterMethod行过滤方法(row:object)=>boolean()=>true
expandedRowKeys展开行keynumber[] | string[][]
defaultExpandAll是否默认展开所有booleanfalse
highlight是否高亮booleanfalse
searchValue搜索值string''
highlightField高亮字段string''
paginationLayout分页器配置string'total, sizes, prev, pager, next, jumper'
filterDataMethod数据过滤方法(row:any)=>any-
getRowClass自定义行样式(row:object,rowIndex:number)=>string()=>''

columns 属性说明

属性名说明类型
prop字段名(必填)string
sortable是否可排序boolean
label列名string
align对齐方式string
width列宽number|string
fixed是否固定boolean
resizable列宽是否可拖动boolean
type类型string
showOverflowTooltip超出隐藏并显示tooltipboolean
renderHTML自定义渲染Function
renderAsync自定义异步渲染Function
formatter自定义格式化Function

事件

事件名说明回调参数
getList获取数据(pageInfo)
update:params更新请求参数(params)
update:pageInfo更新分页信息(pageInfo)
sort-change排序变化({column, prop, order})

方法(ref调用)

const tableRef = ref()
tableRef.value.clearSort(column: string) // 清除指定列排序

插槽

  • 默认插槽:自定义单元格内容
  • expand:自定义展开行内容
<KFTable :columns="columns" :table-data="tableData">
  <template #default="{ row, column, $index }">
    <span>{{ row[column.prop] }}</span>
  </template>
  <template #expand="{ row }">
    <div>自定义展开内容:{{ row.name }}</div>
  </template>
</KFTable>

6. CustomCardTable(卡片式表格组件)

<template>
  <CustomCardTable
    v-model:items="tableItems"
    :column-num="3"
    :row-width="400"
  >
    <template #default="{ item, updateItem }">
      <span>{{ item.value }}</span>
    </template>
  </CustomCardTable>
</template>
<script setup lang="ts">
import { ref } from 'vue'
const tableItems = ref([
  { label: '姓名', value: '张三' },
  { label: '年龄', value: '25' }
])
</script>
// 卡片式表格组件参数说明
interface TableItem {
  label: string;      // 标签名
  value?: string | number; // 值
  prop?: string;      // 属性名
  slot?: string;      // 自定义插槽名
}

interface Props {
  items: TableItem[];           // 表格数据,必填
  columnNum?: number;           // 列数,默认2
  rowWidth?: string | number;   // 单元格宽度,默认336px
}
<!-- 使用示例 -->
<template>
  <CustomCardTable
    v-model:items="tableItems"
    :column-num="3"
    :row-width="400"
  >
    <template #default="{ item, updateItem }">
      <span>{{ item.value }}</span>
    </template>
  </CustomCardTable>
</template>

插槽说明:

  • 默认插槽可以自定义每个单元格的内容
  • 插槽参数:
    • item: TableItem - 当前项数据
    • updateItem: (newItem: TableItem) => void - 更新当前项数据的方法

使用update-item方法示例:

<template>
  <CustomCardTable v-model:items="tableItems">
    <template #default="{ item, updateItem }">
      <!-- 使用DInput组件实现数据双向绑定 -->
      <DInput
        :model-value="item.value"
        @update:model-value="(newValue) => updateItem({ ...item, value: newValue })"
      />
      
      <!-- 或者使用原生输入框 -->
      <input
        :value="item.value"
        @input="(e) => updateItem({ ...item, value: e.target.value })"
      />
    </template>
  </CustomCardTable>
</template>

<script setup lang="ts">
import { ref } from 'vue'

const tableItems = ref([
  { label: '姓名', value: '张三' },
  { label: '年龄', value: '25' }
])
</script>

说明: 1. updateItem方法用于更新单个表格项的数据 2. 需要通过v-model:items绑定数据以实现双向数据绑定

7. KFDrawer(抽屉组件)

<template>
  <KFDrawer v-model:visible="drawerVisible" title="抽屉标题" :width="600" :footer="true" :before-close="beforeClose">
    <div>抽屉内容</div>
    <template #footer-left>
      <span>自定义左侧内容</span>
    </template>
    <template #footer>
      <KFButton @click="drawerVisible = false">取消</KFButton>
      <KFButton type="primary" @click="onConfirm">确定</KFButton>
    </template>
  </KFDrawer>
  <KFButton @click="drawerVisible = true">打开抽屉</KFButton>
</template>
<script setup lang="ts">
import { ref } from 'vue'
const drawerVisible = ref(false)
const beforeClose = () => {
  // 关闭前逻辑
}
const onConfirm = () => {
  drawerVisible.value = false
}
</script>

Props 属性

属性名说明类型默认值
visible是否显示抽屉booleanfalse
title抽屉标题string''
beforeClose关闭前回调Function() => {}
width抽屉宽度(px)number540
footer是否显示底部booleantrue

事件

事件名说明回调参数
update:visible显隐切换(visible)

插槽

  • 默认插槽:抽屉内容
  • footer-left:底部左侧自定义内容
  • footer:底部自定义内容(覆盖默认按钮)

方法

const tableRef = ref()
tableRef.value.clearSort(column: string) // 清除指定列排序

插槽

  • 默认插槽:自定义单元格内容
  • expand:自定义展开行内容
<KFTable :columns="columns" :table-data="tableData">
  <template #default="{ row, column, $index }">
    <span>{{ row[column.prop] }}</span>
  </template>
  <template #expand="{ row }">
    <div>自定义展开内容:{{ row.name }}</div>
  </template>
</KFTable>

8. KFQuarterPicker(季度选择器)

<template>
  <KFQuarterPicker v-model="quarter" format="YYYY年第q季度" value-format="YYYYQQ" :placeholder="'请选择季度'" :width="240" :clearable="true" @change="onChange" :disabled-date="disabledQuarter" />
</template>
<script setup lang="ts">
import { ref } from 'vue'
const quarter = ref('202401')
const onChange = (val) => {
  // 选中季度变化
}
const disabledQuarter = (year, quarterIndex) => {
  // 禁用某些季度
  return false
}
</script>

Props 属性

属性名说明类型默认值
modelValue/v-model绑定值string/Date-
format显示格式(如YYYY年第q季度)string'YYYY年第q季度'
value-format绑定值格式(YYYYMM/QQ等)string-
placeholder占位内容string'请选择季度'
width输入框宽度number240
clearable是否可清空booleantrue
disabled-date禁用季度方法Function-

事件

事件名说明回调参数
change选择变化(value)

方法(ref调用)

方法名说明参数
getPrevYear上一年-
getNextYear下一年-

插槽

  • 默认插槽:自定义单元格内容
  • expand:自定义展开行内容
<KFTable :columns="columns" :table-data="tableData">
  <template #default="{ row, column, $index }">
    <span>{{ row[column.prop] }}</span>
  </template>
  <template #expand="{ row }">
    <div>自定义展开内容:{{ row.name }}</div>
  </template>
</KFTable>

9. KFTimeComb(时间选择面板)

<template>
  <KFTimeComb v-model:currentTime="timeRange" />
</template>
<script setup lang="ts">
import { ref } from 'vue'
const timeRange = ref([])
</script>

Props 属性

属性名说明类型默认值
currentTime当前时间范围array[]

事件

事件名说明回调参数
update:currentTime时间变化(array)

用法说明

  • 支持日、周、月、年、季度等多种快捷时间选择。
  • 通过v-model:currentTime获取选中的时间区间。

插槽

  • 默认插槽:自定义单元格内容
  • expand:自定义展开行内容
<KFTable :columns="columns" :table-data="tableData">
  <template #default="{ row, column, $index }">
    <span>{{ row[column.prop] }}</span>
  </template>
  <template #expand="{ row }">
    <div>自定义展开内容:{{ row.name }}</div>
  </template>
</KFTable>

10. KFEmpty(空状态组件)

<template>
  <KFEmpty tip="暂无数据">
    <div>可自定义内容</div>
  </KFEmpty>
</template>

Props 属性

属性名说明类型默认值
tip提示文字string暂无内容

插槽

  • 默认插槽:自定义空状态内容

方法

const tableRef = ref()
tableRef.value.clearSort(column: string) // 清除指定列排序

插槽

  • 默认插槽:自定义单元格内容
  • expand:自定义展开行内容
<KFTable :columns="columns" :table-data="tableData">
  <template #default="{ row, column, $index }">
    <span>{{ row[column.prop] }}</span>
  </template>
  <template #expand="{ row }">
    <div>自定义展开内容:{{ row.name }}</div>
  </template>
</KFTable>

11. CustomCardTable(卡片式表格组件)

<template>
  <CustomCardTable
    v-model:items="tableItems"
    :column-num="3"
    :row-width="400"
  >
    <template #default="{ item, updateItem }">
      <span>{{ item.value }}</span>
    </template>
  </CustomCardTable>
</template>
<script setup lang="ts">
import { ref } from 'vue'
const tableItems = ref([
  { label: '姓名', value: '张三' },
  { label: '年龄', value: '25' }
])
</script>
// 卡片式表格组件参数说明
interface TableItem {
  label: string;      // 标签名
  value?: string | number; // 值
  prop?: string;      // 属性名
  slot?: string;      // 自定义插槽名
}

interface Props {
  items: TableItem[];           // 表格数据,必填
  columnNum?: number;           // 列数,默认2
  rowWidth?: string | number;   // 单元格宽度,默认336px
}
<!-- 使用示例 -->
<template>
  <CustomCardTable
    v-model:items="tableItems"
    :column-num="3"
    :row-width="400"
  >
    <template #default="{ item, updateItem }">
      <span>{{ item.value }}</span>
    </template>
  </CustomCardTable>
</template>

插槽说明:

  • 默认插槽可以自定义每个单元格的内容
  • 插槽参数:
    • item: TableItem - 当前项数据
    • updateItem: (newItem: TableItem) => void - 更新当前项数据的方法

使用update-item方法示例:

<template>
  <CustomCardTable v-model:items="tableItems">
    <template #default="{ item, updateItem }">
      <!-- 使用DInput组件实现数据双向绑定 -->
      <DInput
        :model-value="item.value"
        @update:model-value="(newValue) => updateItem({ ...item, value: newValue })"
      />
      
      <!-- 或者使用原生输入框 -->
      <input
        :value="item.value"
        @input="(e) => updateItem({ ...item, value: e.target.value })"
      />
    </template>
  </CustomCardTable>
</template>

<script setup lang="ts">
import { ref } from 'vue'

const tableItems = ref([
  { label: '姓名', value: '张三' },
  { label: '年龄', value: '25' }
])
</script>

### 12.
```js

重要说明

1.使用yalc测试当前组件,需要先安装yalc

# 重要说明

## 1. 使用 yalc 测试当前组件库
### 步骤一:全局安装 yalc(如未安装可跳过此步)
```bash
npm install -g yalc

2. 必须打包后,使用yalc发布

npm run build-only
yalc publish

3. 必须在项目中安装yalc

yalc link @dang_8899/xl-ui // 首次安装
yalc update @dang_8899/xl-ui // 后续更新

如果更新组件库并没有生效,必须确认自己是否有重复上述操作,如没有,把node_modules删除,并重新安装,如果npm有安装过当前组件,需要删除,因为会和yalc的版本冲突,最后最后,重要提醒,一定要使用webstorm打包,因为vscode会有缓存,如果webstorm上有.vscode文件夹也有删除,因为会有缓存,.idea文件夹也删除

XL-UI 工具函数文档

目录

  1. 数据处理
  2. UI 交互
  3. DOM 操作
  4. 树形结构处理
  5. 主题设置
  6. 其他工具

1. 数据处理

getDataFunc

解构接口返回数据,自动处理标准接口格式。

import { getDataFunc } from '@dang_8899/xl-ui'

// 示例
const response = {
  data: {
    code: '00000',
    data: { name: 'xl' }
  }
}
const result = getDataFunc(response) // { name: 'xl' }

getEnumKeyByValue

根据枚举值获取枚举键名。

import { getEnumKeyByValue } from '@dang_8899/xl-ui'

// 示例
enum Status {
  Active = 1,
  Inactive = 0
}
const key = getEnumKeyByValue(Status, 1) // 'Active'

enumToOptions

将枚举对象转换为选项列表,常用于下拉选择框。

import { enumToOptions } from '@dang_8899/xl-ui'

// 示例
enum Status {
  Active = 1,
  Inactive = 0
}
const options = enumToOptions(Status)
// 结果:[
//   { label: 'Active', value: 1 },
//   { label: 'Inactive', value: 0 }
// ]

2. UI 交互

openVn

快捷消息提示。

import { openVn } from '@dang_8899/xl-ui'

// 示例
openVn('操作成功', 'success')
openVn('发生错误', 'error')

openFunc

确认对话框。

import { openFunc } from '@dang_8899/xl-ui'

// 示例
openFunc({
  title: '提示',
  content: '确定删除吗?',
  cb: () => {
    // 确认后的回调
    console.log('用户点击确定')
  }
})

commonOper

通用操作回调处理。

import { commonOper } from '@dang_8899/xl-ui'

// 示例
const visible = ref(true)
const getList = () => {
  // 刷新列表
}
commonOper(true, visible, getList)

3. DOM 操作

copyText

复制文本到剪贴板。

import { copyText } from '@dang_8899/xl-ui'

// 示例
const success = copyText('要复制的文本')
if (success) {
  console.log('复制成功')
}

getDownload

文件下载。

import { getDownload } from '@dang_8899/xl-ui'

// 示例
getDownload({
  url: 'https://example.com/file.pdf',
  fileName: 'document.pdf'
})

4. 树形结构处理

treeFilterNode

树节点过滤,支持关键字搜索。

import { treeFilterNode } from '@dang_8899/xl-ui'

// 示例
const treeData = [
  {
    orgId: 1,
    orgName: '总部',
    child: [
      { orgId: 2, orgName: '技术部' }
    ]
  }
]
const expandKeys: number[] = []
const filteredTree = treeFilterNode(treeData, '技术', expandKeys)

5. 主题设置

setThemeColor

设置主题色。

import { setThemeColor } from '@dang_8899/xl-ui'

// 示例
setThemeColor('#615DEE')

6. 其他工具

generateRandomId

生成随机ID。

import { generateRandomId } from '@dang_8899/xl-ui'

// 示例
const id = generateRandomId() // '1679012345_abc123def'

isAbsoluteUrl

判断是否为绝对路径URL。

import { isAbsoluteUrl } from '@dang_8899/xl-ui'

// 示例
isAbsoluteUrl('https://example.com') // true
isAbsoluteUrl('/path/to/file') // false

isOverflow

检测元素内容是否溢出。

import { isOverflow } from '@dang_8899/xl-ui'

// 示例
const element = document.querySelector('.some-element')
if (element && isOverflow(element)) {
  console.log('内容溢出')
}

注意事项

  • 所有方法都经过 TypeScript 类型检查
  • UI 相关方法依赖于 Element Plus
  • 建议在使用前先查看对应方法的类型定义,以了解详细的参数要求
1.0.30-beta.19

9 months ago

1.0.30-beta.17

9 months ago

1.0.30-beta.16

9 months ago

1.0.30-beta.15

9 months ago

1.0.30-beta.14

9 months ago

1.0.30-beta.13

9 months ago

1.0.30-beta.12

9 months ago

1.0.30-beta.11

9 months ago

1.0.30-beta.10

9 months ago

1.0.30-beta.9

9 months ago

1.0.30-beta.8

9 months ago

1.0.30-beta.7

9 months ago

1.0.30-beta.6

9 months ago

1.0.29-beta.5

10 months ago

1.0.29-beta.4

10 months ago

1.0.29-beta.3

10 months ago

1.0.29-beta.2

10 months ago

1.0.29-beta

11 months ago

1.0.28

11 months ago

1.0.27

12 months ago

1.0.26

12 months ago

1.0.25

12 months ago

1.0.24

12 months ago

1.0.2-3.1

12 months ago

1.0.23

12 months ago

1.0.16

1 year ago

1.0.15

1 year ago

1.0.14

1 year ago

1.0.13

1 year ago

1.0.11

1 year ago

1.0.10

1 year ago

1.0.9

1 year ago

1.0.8

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

0.0.1

1 year ago