Skip to content

Commit

Permalink
feat: 新增组件
Browse files Browse the repository at this point in the history
  • Loading branch information
zhoumengxiang committed Nov 10, 2023
1 parent 5cb0d34 commit a4c4d2f
Show file tree
Hide file tree
Showing 47 changed files with 4,269 additions and 84 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@



### 特性
💎 简单易用 - 基于 Element-plus 进行面向常见业务的封装
📦 场景丰富 - 提供一些列面向常见业务场景基础组件
💡 TypeScript - 提供完整 TypeScript 类型定义
🎨 更少的代码 - 多种配置减少代码的书写
-💎 简单易用 - 基于 Element-plus 进行面向常见业务的封装
-📦 场景丰富 - 提供一些列面向常见业务场景基础组件
-💡 TypeScript - 提供完整 TypeScript 类型定义
-🎨 更少的代码 - 多种配置减少代码的书写

### 发布到githubio
- 提交代码后,登录到github 点Actions查看流水线是否构建成功
```js
// 需要在使用的项目的tsconfig.json文件中添加以下
compilerOptions:{
Expand Down
11 changes: 9 additions & 2 deletions global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ import TTimerBtn from './lib/timer-btn/src/index.vue'
import TModuleForm from './lib/module-form/src/index.vue'
import TAdaptivePage from './lib/adaptive-page/src/index.vue'
import TDatePicker from './lib/date-picker/src/index.vue'
import ProSearch from "./lib/proSearch/src/index.vue"
import ProTable from "./lib/proTable/index.vue"
import ProLayout from "./lib/proLayout/index.vue"
import ProLoading from "./lib/proLoading/index.vue"
// GlobalComponents for Volar
declare module '@vue/runtime-core' {
export interface GlobalComponents {
Expand Down Expand Up @@ -121,6 +125,10 @@ declare module '@vue/runtime-core' {
TModuleForm: typeof TModuleForm
TAdaptivePage: typeof TAdaptivePage
TDatePicker: typeof TDatePicker
ProSearch: typeof ProSearch
ProTable: typeof ProTable
ProLoading: typeof ProLoading
ProLayout: typeof ProLayout
}

interface ComponentCustomProperties {
Expand All @@ -131,8 +139,7 @@ declare module '@vue/runtime-core' {
$alert: typeof import('element-plus')['ElMessageBox']['alert']
$confirm: typeof import('element-plus')['ElMessageBox']['confirm']
$prompt: typeof import('element-plus')['ElMessageBox']['prompt']
$loading: typeof import('element-plus')['ElLoadingService']
// $loading: typeof import('element-plus')['ElLoadingService']
}
}

export {}
14 changes: 9 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"name": "lighting-pro",
"version": "0.0.2",
"version": "0.0.3",
"description": "Vue3 中基于Element-plus二次封装基础组件文档",
"author": "lantingBoy",
"license": "ISC",
"private": false,
"main": "lib/lamp-pro.umd.cjs",
"module": "lib/lamp-pro.umd.cjs",
"main": "lib/lighting-pro.umd.cjs",
"module": "lib/lighting-pro.umd.cjs",
"types": "lib/index.d.ts",
"type": "module",
"files": [
Expand Down Expand Up @@ -61,13 +61,14 @@
"unplugin-auto-import": "^0.11.2",
"vite": "^3.1.0",
"vite-plugin-compression": "^0.5.1",
"vite-plugin-dts": "^1.7.3",
"vite-plugin-dts": "3.6.3",
"vite-plugin-vue-setup-extend": "^0.4.0",
"vitepress": "1.0.0-alpha.75",
"vue": "3.2.44",
"vue-hooks-plus": "^1.8.5",
"vue-router": "^4.1.5",
"vue-tsc": "^0.40.4",
"vue3-print-nb": "^0.1.4",
"vuedraggable": "^4.1.0"
},
"repository": {
Expand All @@ -87,5 +88,8 @@
"二次封装组件",
"封装组件",
"components"
]
],
"dependencies": {
"vue-loading-overlay": "^6.0.3"
}
}
92 changes: 92 additions & 0 deletions packages/SearchForm/components/SearchFormItem.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<template>
<component
:is="column.search?.render ?? `el-${column.search?.el}`"
v-bind="{ ...handleSearchProps, ...placeholder, searchParam: _searchParam, clearable }"
v-model.trim="_searchParam[column.search?.key ?? handleProp(column.prop!)]"
:data="column.search?.el === 'tree-select' ? columnEnum : []"
:options="['cascader', 'select-v2'].includes(column.search?.el!) ? columnEnum : []"
>
<template v-if="column.search?.el === 'cascader'" #default="{ data }">
<span>{{ data[fieldNames.label] }}</span>
</template>
<template v-if="column.search?.el === 'select'">
<component
:is="`el-option`"
v-for="(col, index) in columnEnum"
:key="index"
:label="col[fieldNames.label]"
:value="col[fieldNames.value]"
></component>
</template>
<slot v-else></slot>
</component>
</template>

<script setup lang="ts" name="SearchFormItem">
import { computed, inject, ref } from "vue";
import { handleProp } from "@/assets/js";
import { ColumnProps } from "@/proTable/interface";
interface SearchFormItem {
column: ColumnProps;
searchParam: { [key: string]: any };
}
const props = defineProps<SearchFormItem>();
// Re receive SearchParam
const _searchParam = computed(() => props.searchParam);
// 判断 fieldNames 设置 label && value && children 的 key 值
const fieldNames = computed(() => {
return {
label: props.column.fieldNames?.label ?? "label",
value: props.column.fieldNames?.value ?? "value",
children: props.column.fieldNames?.children ?? "children"
};
});
// 接收 enumMap (el 为 select-v2 需单独处理 enumData)
const enumMap = inject("enumMap", ref(new Map()));
const columnEnum = computed(() => {
let enumData = enumMap.value.get(props.column.prop);
if (!enumData) return [];
if (props.column.search?.el === "select-v2" && props.column.fieldNames) {
enumData = enumData.map((item: { [key: string]: any }) => {
return { ...item, label: item[fieldNames.value.label], value: item[fieldNames.value.value] };
});
}
return enumData;
});
// 处理透传的 searchProps (el 为 tree-select、cascader 的时候需要给下默认 label && value && children)
const handleSearchProps = computed(() => {
const label = fieldNames.value.label;
const value = fieldNames.value.value;
const children = fieldNames.value.children;
const searchEl = props.column.search?.el;
let searchProps = props.column.search?.props ?? {};
if (searchEl === "tree-select") {
searchProps = { ...searchProps, props: { ...searchProps.props, label, children }, nodeKey: value };
}
if (searchEl === "cascader") {
searchProps = { ...searchProps, props: { ...searchProps.props, label, value, children } };
}
return searchProps;
});
// 处理默认 placeholder
const placeholder = computed(() => {
const search = props.column.search;
if (["datetimerange", "daterange", "monthrange"].includes(search?.props?.type) || search?.props?.isRange) {
return { rangeSeparator: "", startPlaceholder: "开始时间", endPlaceholder: "结束时间" };
}
const placeholder = search?.props?.placeholder ?? (search?.el?.includes("input") ? "请输入" : "请选择");
return { placeholder };
});
// 是否有清除按钮 (当搜索项有默认值时,清除按钮不显示)
const clearable = computed(() => {
const search = props.column.search;
return search?.props?.clearable ?? (search?.defaultValue == null || search?.defaultValue == undefined);
});
</script>
94 changes: 94 additions & 0 deletions packages/SearchForm/index.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<template>
<div v-if="columns.length" class="card table-search">
<el-form ref="formRef" :model="searchParam">
<Grid ref="gridRef" :collapsed="collapsed" :gap="[20, 0]" :cols="searchCol">
<GridItem v-for="(item, index) in columns" :key="item.prop" v-bind="getResponsive(item)" :index="index">
<el-form-item>
<template #label>
<el-space :size="4">
<span>{{ `${item.search?.label ?? item.label}` }}</span>
<el-tooltip v-if="item.search?.tooltip" effect="dark" :content="item.search?.tooltip" placement="top">
<i :class="'iconfont icon-yiwen'"></i>
</el-tooltip>
</el-space>
<span>:</span>
</template>
<SearchFormItem :column="item" :search-param="searchParam" />
</el-form-item>
</GridItem>
<GridItem suffix>
<div class="operation">
<el-button type="primary" :icon="Search" @click="search"> 搜索 </el-button>
<el-button :icon="Delete" @click="reset"> 重置 </el-button>
<el-button v-if="showCollapse" type="primary" link class="search-isOpen" @click="collapsed = !collapsed">
{{ collapsed ? "展开" : "合并" }}
<el-icon class="el-icon--right">
<component :is="collapsed ? ArrowDown : ArrowUp"></component>
</el-icon>
</el-button>
</div>
</GridItem>
</Grid>
</el-form>
</div>
</template>
<script setup lang="ts" name="SearchForm">
import { computed, ref } from "vue";
import { ColumnProps } from "@/proTable/interface";
import { BreakPoint } from "@/grid/interface";
import { Delete, Search, ArrowDown, ArrowUp } from "@element-plus/icons-vue";
import SearchFormItem from "./components/SearchFormItem.vue";
import Grid from "@/grid/index.vue";
import GridItem from "@/grid/components/GridItem.vue";
interface ProTableProps {
columns?: ColumnProps[]; // 搜索配置列
searchParam?: { [key: string]: any }; // 搜索参数
searchCol: number | Record<BreakPoint, number>;
search: (params: any) => void; // 搜索方法
reset: (params: any) => void; // 重置方法
}
// 默认值
const props = withDefaults(defineProps<ProTableProps>(), {
columns: () => [],
searchParam: () => ({})
});
// 获取响应式设置
const getResponsive = (item: ColumnProps) => {
return {
span: item.search?.span,
offset: item.search?.offset ?? 0,
xs: item.search?.xs,
sm: item.search?.sm,
md: item.search?.md,
lg: item.search?.lg,
xl: item.search?.xl
};
};
// 是否默认折叠搜索项
const collapsed = ref(true);
// 获取响应式断点
const gridRef = ref();
const breakPoint = computed<BreakPoint>(() => gridRef.value?.breakPoint);
// 判断是否显示 展开/合并 按钮
const showCollapse = computed(() => {
let show = false;
props.columns.reduce((prev, current) => {
prev +=
(current.search![breakPoint.value]?.span ?? current.search?.span ?? 1) +
(current.search![breakPoint.value]?.offset ?? current.search?.offset ?? 0);
if (typeof props.searchCol !== "number") {
if (prev >= props.searchCol[breakPoint.value]) show = true;
} else {
if (prev >= props.searchCol) show = true;
}
return prev;
}, 0);
return show;
});
</script>
82 changes: 82 additions & 0 deletions packages/assets/iconfont/iconfont.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
@font-face {
font-family: "hdzkIcon"; /* Project id 4053247 */
src: url('iconfont.ttf?t=1683597555982') format('truetype');
}

.hdzkIcon {
font-family: "hdzkIcon" !important;
font-size: 16px;
font-style: normal;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}

.icon-arrow_down:before {
content: "\e634";
}

.icon-user:before {
content: "\e633";
}

.icon-org_tree:before {
content: "\e632";
}

.icon-org_extend:before {
content: "\e631";
}

.icon-anquan:before {
content: "\e630";
}

.icon-fenzu:before {
content: "\e68f";
}

.icon-daochu:before {
content: "\e690";
}

.icon-dongzuo:before {
content: "\e691";
}

.icon-kapianshitu:before {
content: "\e692";
}

.icon-riqi:before {
content: "\e693";
}

.icon-search:before {
content: "\e694";
}

.icon-shaixuan:before {
content: "\e695";
}

.icon-dayinji:before {
content: "\e696";
}

.icon-chongzhi:before {
content: "\e697";
}

.icon-shoucang:before {
content: "\e698";
}

.icon-liebiaoshitu:before {
content: "\e699";
}

.icon-weishoucang:before {
content: "\e69a";
}


Binary file added packages/assets/iconfont/iconfont.ttf
Binary file not shown.
Binary file added packages/assets/iconfont/iconfont.woff
Binary file not shown.
Binary file added packages/assets/iconfont/iconfont.woff2
Binary file not shown.
Binary file added packages/assets/images/close.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added packages/assets/images/notData.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit a4c4d2f

Please sign in to comment.