vue-super-crud 1.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.browserslistrc +3 -0
- package/.versionrc.json +36 -0
- package/CHANGELOG.md +232 -0
- package/LICENSE +201 -0
- package/README.md +46 -0
- package/babel.config.js +12 -0
- package/build/alias.js +10 -0
- package/build/build.js +52 -0
- package/build/config.js +70 -0
- package/deploy.bat +14 -0
- package/docs/.vuepress/components/button/base.vue +88 -0
- package/docs/.vuepress/components/common/code-format.vue +331 -0
- package/docs/.vuepress/components/commonConfig/presetCodeTemplate/base.vue +68 -0
- package/docs/.vuepress/components/commonConfig/presetCodeTemplate/customParams.vue +73 -0
- package/docs/.vuepress/components/commonConfig/renderType/component.vue +160 -0
- package/docs/.vuepress/components/commonConfig/renderType/formatter.vue +49 -0
- package/docs/.vuepress/components/commonConfig/renderType/render.vue +91 -0
- package/docs/.vuepress/components/commonConfig/renderType/slot.vue +63 -0
- package/docs/.vuepress/components/crud/baseUse/baseUse.vue +98 -0
- package/docs/.vuepress/components/crud/baseUse/columnAction.vue +72 -0
- package/docs/.vuepress/components/crud/baseUse/columnWidth.vue +107 -0
- package/docs/.vuepress/components/crud/baseUse/handleRow.vue +65 -0
- package/docs/.vuepress/components/crud/baseUse/height.vue +82 -0
- package/docs/.vuepress/components/crud/baseUse/index.vue +54 -0
- package/docs/.vuepress/components/crud/baseUse/loading.vue +70 -0
- package/docs/.vuepress/components/crud/baseUse/pagination.vue +108 -0
- package/docs/.vuepress/components/crud/baseUse/selection.vue +114 -0
- package/docs/.vuepress/components/crud/baseUse/summaryMethod.vue +118 -0
- package/docs/.vuepress/components/crud/baseUse/title.vue +54 -0
- package/docs/.vuepress/components/crud/baseUse/toolbar.vue +69 -0
- package/docs/.vuepress/components/crud/buttons/common.vue +115 -0
- package/docs/.vuepress/components/crud/buttons/fast.vue +82 -0
- package/docs/.vuepress/components/crud/contextMenu/base.vue +72 -0
- package/docs/.vuepress/components/crud/copy.vue +52 -0
- package/docs/.vuepress/components/crud/crudEvents/api.vue +157 -0
- package/docs/.vuepress/components/crud/crudEvents/deleteTip.vue +93 -0
- package/docs/.vuepress/components/crud/crudEvents/events.vue +188 -0
- package/docs/.vuepress/components/crud/dataSort/base.vue +142 -0
- package/docs/.vuepress/components/crud/genDynamicColumns/base.vue +53 -0
- package/docs/.vuepress/components/crud/genDynamicColumns/dynamicAndFixed.vue +111 -0
- package/docs/.vuepress/components/crud/genDynamicColumns/treeDynamic.vue +68 -0
- package/docs/.vuepress/components/crud/handleBar/handleRow.vue +65 -0
- package/docs/.vuepress/components/crud/handleBar/toolbar.vue +69 -0
- package/docs/.vuepress/components/crud/renderType/1.vue +57 -0
- package/docs/.vuepress/components/crud/renderType/2.vue +63 -0
- package/docs/.vuepress/components/crud/renderType/3.vue +105 -0
- package/docs/.vuepress/components/crud/renderType/5.vue +91 -0
- package/docs/.vuepress/components/crud/search/1.vue +90 -0
- package/docs/.vuepress/components/crud/search/2.vue +78 -0
- package/docs/.vuepress/components/crud/search/3.vue +107 -0
- package/docs/.vuepress/components/crud/search/base.vue +123 -0
- package/docs/.vuepress/components/crud/search/localSearch.vue +124 -0
- package/docs/.vuepress/components/crud/search/special.vue +148 -0
- package/docs/.vuepress/components/crud/selection/events.vue +47 -0
- package/docs/.vuepress/components/crud/selection/pagination.vue +94 -0
- package/docs/.vuepress/components/crud/selection/singleSelection.vue +64 -0
- package/docs/.vuepress/components/crud/span/base.vue +69 -0
- package/docs/.vuepress/components/crud/span/special.vue +75 -0
- package/docs/.vuepress/components/crud/summary/base.vue +99 -0
- package/docs/.vuepress/components/crud/tableEdit/addDeleteBtn.vue +174 -0
- package/docs/.vuepress/components/crud/tableEdit/cellEdit.vue +194 -0
- package/docs/.vuepress/components/crud/tableEdit/controlEdit.vue +219 -0
- package/docs/.vuepress/components/crud/tableEdit/dialog.vue +172 -0
- package/docs/.vuepress/components/crud/tableEdit/free.vue +88 -0
- package/docs/.vuepress/components/crud/tableEdit/freeColumn.vue +82 -0
- package/docs/.vuepress/components/crud/tableEdit/methods.vue +154 -0
- package/docs/.vuepress/components/crud/tableEdit/rowAction.vue +107 -0
- package/docs/.vuepress/components/crud/tableEdit/rowBatch.vue +116 -0
- package/docs/.vuepress/components/crud/tableEdit/rowClick.vue +98 -0
- package/docs/.vuepress/components/crud/validate/base.vue +122 -0
- package/docs/.vuepress/components/crud/validate/custom.vue +82 -0
- package/docs/.vuepress/components/crud/validate/regulars.vue +88 -0
- package/docs/.vuepress/components/crud/validate/relation.vue +91 -0
- package/docs/.vuepress/components/crud/validate/tree.vue +82 -0
- package/docs/.vuepress/components/dialog/baseUse/base.vue +92 -0
- package/docs/.vuepress/components/dialog/baseUse/beforeConfirm.vue +78 -0
- package/docs/.vuepress/components/dialog/baseUse/control.vue +79 -0
- package/docs/.vuepress/components/dialog/baseUse/drawer.vue +59 -0
- package/docs/.vuepress/components/dialog/baseUse/footer.vue +87 -0
- package/docs/.vuepress/components/dialog/baseUse/insertSlot.vue +79 -0
- package/docs/.vuepress/components/dict/DictLinkage.vue +91 -0
- package/docs/.vuepress/components/dict/baseUse.vue +72 -0
- package/docs/.vuepress/components/dict/component.vue +82 -0
- package/docs/.vuepress/components/dict/localDict.vue +68 -0
- package/docs/.vuepress/components/form/baseUse/base.vue +48 -0
- package/docs/.vuepress/components/form/baseUse/dataFormat.vue +92 -0
- package/docs/.vuepress/components/form/baseUse/deep.vue +57 -0
- package/docs/.vuepress/components/form/baseUse/gridLayout.vue +47 -0
- package/docs/.vuepress/components/form/baseUse/group.vue +66 -0
- package/docs/.vuepress/components/form/baseUse/hidden.vue +40 -0
- package/docs/.vuepress/components/form/baseUse/inlineLayout.vue +48 -0
- package/docs/.vuepress/components/form/baseUse/label.vue +51 -0
- package/docs/.vuepress/components/form/baseUse/tooltip.vue +40 -0
- package/docs/.vuepress/components/form/baseUse/validate.vue +52 -0
- package/docs/.vuepress/components/form/detail/base.vue +78 -0
- package/docs/.vuepress/components/form/detail/border.vue +90 -0
- package/docs/.vuepress/components/form/detail/singleDetail.vue +72 -0
- package/docs/.vuepress/components/formatData/baseUse.vue +131 -0
- package/docs/.vuepress/components/mock/index.js +347 -0
- package/docs/.vuepress/components/mockData/custom.vue +69 -0
- package/docs/.vuepress/components/mockData/example.vue +290 -0
- package/docs/.vuepress/components/positionSlot/base.vue +24 -0
- package/docs/.vuepress/components/positionSlot/form.vue +71 -0
- package/docs/.vuepress/components/positionSlot/table.vue +85 -0
- package/docs/.vuepress/components/tabs/base.vue +57 -0
- package/docs/.vuepress/components/temp.js +195 -0
- package/docs/.vuepress/config.js +146 -0
- package/docs/.vuepress/enhanceApp.js +142 -0
- package/docs/.vuepress/public/favicon.ico +0 -0
- package/docs/.vuepress/public/super.png +0 -0
- package/docs/.vuepress/styles/index.styl +25 -0
- package/docs/.vuepress/styles/palette.styl +6 -0
- package/docs/README.md +14 -0
- package/docs/guide/button/base.md +31 -0
- package/docs/guide/commonConfig/jsx.md +166 -0
- package/docs/guide/commonConfig/presetCodeTemplate.md +68 -0
- package/docs/guide/commonConfig/renderType.md +181 -0
- package/docs/guide/crud/baseUse.md +120 -0
- package/docs/guide/crud/buttons.md +18 -0
- package/docs/guide/crud/config.md +217 -0
- package/docs/guide/crud/contextMenu.md +18 -0
- package/docs/guide/crud/dataSort.md +66 -0
- package/docs/guide/crud/genDynamicColumns.md +145 -0
- package/docs/guide/crud/handleBar.md +26 -0
- package/docs/guide/crud/renderType.md +4 -0
- package/docs/guide/crud/search.md +150 -0
- package/docs/guide/crud/selection.md +73 -0
- package/docs/guide/crud/span.md +98 -0
- package/docs/guide/crud/summary.md +167 -0
- package/docs/guide/crud/tableEdit.md +377 -0
- package/docs/guide/crud/validate.md +158 -0
- package/docs/guide/dialog/baseUse.md +81 -0
- package/docs/guide/dict/baseUse.md +174 -0
- package/docs/guide/dict/component.md +88 -0
- package/docs/guide/dict/config.md +44 -0
- package/docs/guide/form/baseUse.md +142 -0
- package/docs/guide/form/detail.md +38 -0
- package/docs/guide/formatData/baseUse.md +98 -0
- package/docs/guide/formatData/config.md +142 -0
- package/docs/guide/mockData/base.md +26 -0
- package/docs/guide/positionSlot/base.md +41 -0
- package/docs/guide/question/base.md +44 -0
- package/docs/guide/start/base.md +30 -0
- package/docs/guide/tabs/base.md +63 -0
- package/examples/App.vue +52 -0
- package/examples/Layout/components/AppMain.vue +40 -0
- package/examples/Layout/components/Item.vue +29 -0
- package/examples/Layout/components/Link.vue +44 -0
- package/examples/Layout/components/SidebarItem.vue +93 -0
- package/examples/Layout/index.vue +69 -0
- package/examples/assets/logo.png +0 -0
- package/examples/favicon.ico +0 -0
- package/examples/index.html +18 -0
- package/examples/main.js +54 -0
- package/examples/router/index.js +140 -0
- package/examples/store/index.js +0 -0
- package/examples/styles/index.scss +63 -0
- package/examples/styles/sidebar.scss +226 -0
- package/examples/styles/transition.scss +48 -0
- package/examples/styles/variables.scss +25 -0
- package/examples/views/crud/base.vue +68 -0
- package/examples/views/crud/handleRow.vue +84 -0
- package/examples/views/crud/search.vue +116 -0
- package/examples/views/dashboard/index.vue +244 -0
- package/examples/views/dashboard/index1.vue +234 -0
- package/examples/views/dashboard/test.vue +9 -0
- package/examples/views/formTest/index.vue +168 -0
- package/examples/views/nested/menu1/index.vue +7 -0
- package/examples/views/nested/menu1/menu1-1/index.vue +7 -0
- package/examples/views/nested/menu1/menu1-2/index.vue +7 -0
- package/examples/views/nested/menu1/menu1-2/menu1-2-1/index.vue +5 -0
- package/examples/views/nested/menu1/menu1-2/menu1-2-2/index.vue +5 -0
- package/examples/views/nested/menu1/menu1-3/index.vue +5 -0
- package/examples/views/nested/menu2/index.vue +5 -0
- package/gulpfile.js +84 -0
- package/lib/index.css +1 -0
- package/lib/super-crud.min.js +15 -0
- package/package.json +66 -0
- package/packages/button/index.vue +189 -0
- package/packages/core/components/comp.vue +223 -0
- package/packages/core/components/position.vue +135 -0
- package/packages/core/components/render.vue +460 -0
- package/packages/core/configManager.js +302 -0
- package/packages/core/create.js +8 -0
- package/packages/core/defaultRender.js +64 -0
- package/packages/core/dict/global.js +10 -0
- package/packages/core/dict/index.js +432 -0
- package/packages/core/dict/mixin.js +94 -0
- package/packages/core/event.js +60 -0
- package/packages/core/index.js +6 -0
- package/packages/core/init.js +122 -0
- package/packages/core/mock/genConfig.js +228 -0
- package/packages/core/mock/genData.js +422 -0
- package/packages/core/mock/index.js +4 -0
- package/packages/core/rules.js +111 -0
- package/packages/crud/column.vue +205 -0
- package/packages/crud/columnAction.vue +207 -0
- package/packages/crud/columnCell.vue +146 -0
- package/packages/crud/defaultColumn.vue +130 -0
- package/packages/crud/drawerColumn.vue +225 -0
- package/packages/crud/form.vue +69 -0
- package/packages/crud/index.vue +564 -0
- package/packages/crud/menuBar.vue +298 -0
- package/packages/crud/mixins/cacheHandler.js +36 -0
- package/packages/crud/mixins/calcColumnWidth.js +79 -0
- package/packages/crud/mixins/calcHeight.js +105 -0
- package/packages/crud/mixins/columnHandler.js +128 -0
- package/packages/crud/mixins/contextMenu.js +98 -0
- package/packages/crud/mixins/dataProcessor.js +202 -0
- package/packages/crud/mixins/dialog.js +109 -0
- package/packages/crud/mixins/excelHandler.js +150 -0
- package/packages/crud/mixins/exposeMethods.js +107 -0
- package/packages/crud/mixins/generateDynamicColumns.js +250 -0
- package/packages/crud/mixins/props.js +38 -0
- package/packages/crud/mixins/searchHandler.js +151 -0
- package/packages/crud/mixins/select.js +359 -0
- package/packages/crud/mixins/spanMethod.js +288 -0
- package/packages/crud/mixins/summary.js +177 -0
- package/packages/crud/mixins/tableEdit.js +547 -0
- package/packages/crud/mixins/validate.js +219 -0
- package/packages/crud/pagination.vue +110 -0
- package/packages/crud/search.vue +119 -0
- package/packages/crud/searchHeader.vue +231 -0
- package/packages/crud/selectBanner.vue +138 -0
- package/packages/crud/utils/EditState.js +319 -0
- package/packages/crud/utils/excelExport.js +112 -0
- package/packages/crud/utils/excelImport.js +112 -0
- package/packages/crud/utils/index.js +98 -0
- package/packages/dialog/dialog.js +233 -0
- package/packages/dialog/dialog.vue +15 -0
- package/packages/dialog/index.js +22 -0
- package/packages/dict/cascadeFormat.vue +179 -0
- package/packages/dict/dateFormat.vue +40 -0
- package/packages/dict/form/cascade.vue +61 -0
- package/packages/dict/form/checkbox.vue +90 -0
- package/packages/dict/form/extendMethod.js +22 -0
- package/packages/dict/form/input-base.js +31 -0
- package/packages/dict/form/input.js +20 -0
- package/packages/dict/form/radio.vue +69 -0
- package/packages/dict/form/select.vue +118 -0
- package/packages/dict/form/switch.vue +75 -0
- package/packages/dict/valueFormat.vue +188 -0
- package/packages/directive/dialog/drag.js +86 -0
- package/packages/directive/dialog/dragSize.js +42 -0
- package/packages/directive/index.js +9 -0
- package/packages/directive/insertSlot.js +10 -0
- package/packages/form/contextMenu.js +192 -0
- package/packages/form/draftDrawer.vue +391 -0
- package/packages/form/formAction.vue +97 -0
- package/packages/form/formItem.vue +259 -0
- package/packages/form/index.vue +451 -0
- package/packages/form/props.js +15 -0
- package/packages/grid/cell.vue +65 -0
- package/packages/grid/index.vue +130 -0
- package/packages/group/index.vue +96 -0
- package/packages/tabs/index.vue +290 -0
- package/packages/tooltip/index.js +9 -0
- package/packages/tooltip/tooltip.vue +32 -0
- package/packages/tooltip/tooltipComponent.js +38 -0
- package/packages/verifyInput/index.vue +131 -0
- package/src/config/common.js +88 -0
- package/src/config/crud.js +567 -0
- package/src/config/dialog.js +87 -0
- package/src/config/form.js +215 -0
- package/src/config/index.js +9 -0
- package/src/constants/index.js +72 -0
- package/src/index.js +67 -0
- package/src/template/btn/crud.js +6 -0
- package/src/template/btn/dialog.js +1 -0
- package/src/template/btn/form.js +3 -0
- package/src/template/btn/index.js +9 -0
- package/src/template/dicts.js +1 -0
- package/src/template/formatData.js +507 -0
- package/src/template/index.js +19 -0
- package/src/template/render.js +124 -0
- package/src/template/rules.js +53 -0
- package/src/utils/bem.js +49 -0
- package/src/utils/cache.js +77 -0
- package/src/utils/getType.js +34 -0
- package/src/utils/index.js +212 -0
- package/src/utils/mergeTemp.js +124 -0
- package/styles/button.scss +3 -0
- package/styles/crud.scss +425 -0
- package/styles/dialog.scss +95 -0
- package/styles/form.scss +532 -0
- package/styles/group.scss +78 -0
- package/styles/index.scss +94 -0
- package/styles/tabs.scss +139 -0
- package/styles/verifyInput.scss +56 -0
- package/vue-jsx-sync.js +90 -0
- package/vue.config.js +54 -0
@@ -0,0 +1,564 @@
|
|
1
|
+
<template>
|
2
|
+
<div
|
3
|
+
:class="[
|
4
|
+
b(),
|
5
|
+
{
|
6
|
+
[b('maximize')]: isMaximize,
|
7
|
+
[b('is-auto-height')]: isAutoHeight,
|
8
|
+
[b('is-change-show-search')]: isChangeShowSearch,
|
9
|
+
},
|
10
|
+
]"
|
11
|
+
:style="{
|
12
|
+
padding: wrapperPadding,
|
13
|
+
height: wrapperHeight,
|
14
|
+
}"
|
15
|
+
ref="wrapper"
|
16
|
+
@click="handleWrapperClick"
|
17
|
+
>
|
18
|
+
<position slotName="title" :slots="$scopedSlots"
|
19
|
+
><div v-if="crudOptions.title" class="sc-title">
|
20
|
+
{{ crudOptions.title }}
|
21
|
+
</div></position
|
22
|
+
>
|
23
|
+
<search ref="searchRef" />
|
24
|
+
<menuBar ref="menuBar" />
|
25
|
+
<!-- 选中数据横幅 -->
|
26
|
+
<selectBanner v-if="selection.banner || singleSelection.banner" />
|
27
|
+
<el-form
|
28
|
+
:model="{
|
29
|
+
list,
|
30
|
+
}"
|
31
|
+
:show-message="false"
|
32
|
+
:size="crudOptions.size"
|
33
|
+
:disabled="crudOptions.disabled"
|
34
|
+
ref="tableFormRef"
|
35
|
+
@validate="createListError"
|
36
|
+
class="height--form"
|
37
|
+
>
|
38
|
+
<component
|
39
|
+
:is="virtualized ? 'virtualScroll' : 'div'"
|
40
|
+
:data="virtualized ? list : null"
|
41
|
+
:key-prop="valueKey"
|
42
|
+
:virtualized="virtualized"
|
43
|
+
v-bind="$attrs"
|
44
|
+
@change="(renderData) => (virtualList = renderData)"
|
45
|
+
>
|
46
|
+
<el-table
|
47
|
+
ref="tableRef"
|
48
|
+
:key="key"
|
49
|
+
v-loading="loadingStatus"
|
50
|
+
:element-loading-text="crudOptions.loadingText"
|
51
|
+
:element-loading-spinner="crudOptions.loadingSpinner"
|
52
|
+
:element-loading-background="crudOptions.loadingBackground"
|
53
|
+
highlight-current-row
|
54
|
+
highlight-selection-row
|
55
|
+
v-bind="tableProps"
|
56
|
+
v-on="{ ...$listeners, ...crudOptions }"
|
57
|
+
:data="virtualized ? virtualList : list"
|
58
|
+
@cell-mouse-enter="cellMouseEnter"
|
59
|
+
@cell-mouse-leave="cellMouseLeave"
|
60
|
+
@row-contextmenu="openContextMenu"
|
61
|
+
@selection-change="selectionChange"
|
62
|
+
@select="select"
|
63
|
+
@select-all="selectAll"
|
64
|
+
@row-click="rowClick"
|
65
|
+
@row-dblclick="rowDblclick"
|
66
|
+
@cell-click="cellClick"
|
67
|
+
@cell-dblclick="cellDblclick"
|
68
|
+
:row-key="rowKey_"
|
69
|
+
:row-style="defineRowIndex"
|
70
|
+
:cell-class-name="cellClassName_"
|
71
|
+
:row-class-name="rowClassName_"
|
72
|
+
:lazy="crudOptions.lazy || crudOptions.autoLazy"
|
73
|
+
:load="lazyLoad"
|
74
|
+
:spanMethod="spanMethod"
|
75
|
+
:summary-method="summaryMethod"
|
76
|
+
:show-summary="showSummary"
|
77
|
+
>
|
78
|
+
<template slot="empty">
|
79
|
+
<div :class="b('empty')" v-if="showEmpty">
|
80
|
+
<slot name="empty" v-if="$scopedSlots.empty"></slot>
|
81
|
+
<el-empty
|
82
|
+
v-else
|
83
|
+
:image="crudOptions.empty.image"
|
84
|
+
:image-size="crudOptions.empty.size"
|
85
|
+
:description="crudOptions.empty.text"
|
86
|
+
></el-empty>
|
87
|
+
</div>
|
88
|
+
</template>
|
89
|
+
<defaultColumn
|
90
|
+
v-for="col in defaultColumns"
|
91
|
+
:col="col"
|
92
|
+
:key="col.type"
|
93
|
+
/>
|
94
|
+
<slot></slot>
|
95
|
+
<column
|
96
|
+
v-for="col in columns"
|
97
|
+
:col="col"
|
98
|
+
:key="col.prop || col.label"
|
99
|
+
/>
|
100
|
+
<columnAction />
|
101
|
+
</el-table>
|
102
|
+
</component>
|
103
|
+
<el-tooltip
|
104
|
+
effect="light"
|
105
|
+
:popper-class="b('error-tip')"
|
106
|
+
placement="top"
|
107
|
+
ref="tooltip"
|
108
|
+
:content="errorContent"
|
109
|
+
>
|
110
|
+
</el-tooltip>
|
111
|
+
</el-form>
|
112
|
+
<div
|
113
|
+
v-if="editConfig.lastAdd"
|
114
|
+
:class="b('add-button')"
|
115
|
+
@click="handleLastAdd"
|
116
|
+
>
|
117
|
+
<i class="el-icon-plus" /> 新增一行
|
118
|
+
</div>
|
119
|
+
<position :inline="false" slotName="pagination" :slots="$scopedSlots"
|
120
|
+
><pagination ref="paginationRef"
|
121
|
+
/></position>
|
122
|
+
</div>
|
123
|
+
</template>
|
124
|
+
|
125
|
+
<script>
|
126
|
+
import { create, init, event } from "core";
|
127
|
+
import position from "core/components/position";
|
128
|
+
import {
|
129
|
+
uniqueId,
|
130
|
+
pick,
|
131
|
+
get,
|
132
|
+
isFunction,
|
133
|
+
cloneDeep,
|
134
|
+
merge,
|
135
|
+
isPlainObject,
|
136
|
+
} from "lodash-es";
|
137
|
+
import tableEdit from "./mixins/tableEdit.js";
|
138
|
+
import validate from "./mixins/validate.js";
|
139
|
+
import contextMenu from "./mixins/contextMenu";
|
140
|
+
import dialog from "./mixins/dialog.js";
|
141
|
+
import select from "./mixins/select.js";
|
142
|
+
import calcHeight from "./mixins/calcHeight.js";
|
143
|
+
import spanMethod from "./mixins/spanMethod.js";
|
144
|
+
import exposeMethods from "./mixins/exposeMethods";
|
145
|
+
import generateDynamicColumns from "./mixins/generateDynamicColumns";
|
146
|
+
import dataProcessor from "./mixins/dataProcessor";
|
147
|
+
import summary from "./mixins/summary";
|
148
|
+
import columnHandler from "./mixins/columnHandler";
|
149
|
+
import cacheHandler from "./mixins/cacheHandler";
|
150
|
+
import searchHandler from "./mixins/searchHandler";
|
151
|
+
import search from "./search.vue";
|
152
|
+
import menuBar from "./menuBar.vue";
|
153
|
+
import columnAction from "./columnAction.vue";
|
154
|
+
import column from "./column.vue";
|
155
|
+
import defaultColumn from "./defaultColumn.vue";
|
156
|
+
import pagination from "./pagination.vue";
|
157
|
+
import group from "../group/index.vue";
|
158
|
+
import selectBanner from "./selectBanner.vue";
|
159
|
+
import virtualScroll from "el-table-virtual-scroll";
|
160
|
+
import {
|
161
|
+
toCamelCase,
|
162
|
+
toTreeArray,
|
163
|
+
findTree,
|
164
|
+
filterColumns,
|
165
|
+
mergeTemp,
|
166
|
+
singleMerge,
|
167
|
+
checkVisibility,
|
168
|
+
filterButtons,
|
169
|
+
} from "utils";
|
170
|
+
import tableProps from "./mixins/props";
|
171
|
+
|
172
|
+
export default create({
|
173
|
+
name: "crud",
|
174
|
+
components: {
|
175
|
+
columnAction,
|
176
|
+
column,
|
177
|
+
defaultColumn,
|
178
|
+
menuBar,
|
179
|
+
pagination,
|
180
|
+
search,
|
181
|
+
group,
|
182
|
+
position,
|
183
|
+
selectBanner,
|
184
|
+
virtualScroll,
|
185
|
+
},
|
186
|
+
mixins: [
|
187
|
+
init("crudOptions"),
|
188
|
+
tableEdit,
|
189
|
+
dialog,
|
190
|
+
validate,
|
191
|
+
contextMenu,
|
192
|
+
event,
|
193
|
+
select,
|
194
|
+
calcHeight,
|
195
|
+
spanMethod,
|
196
|
+
exposeMethods,
|
197
|
+
generateDynamicColumns,
|
198
|
+
summary,
|
199
|
+
dataProcessor,
|
200
|
+
columnHandler,
|
201
|
+
cacheHandler,
|
202
|
+
searchHandler,
|
203
|
+
],
|
204
|
+
props: {
|
205
|
+
// 防止scope中携带实例时,拷贝合并报错
|
206
|
+
scope: Object,
|
207
|
+
data: {
|
208
|
+
type: Array,
|
209
|
+
default: () => {
|
210
|
+
return [];
|
211
|
+
},
|
212
|
+
},
|
213
|
+
total: {
|
214
|
+
type: Number,
|
215
|
+
default: 0,
|
216
|
+
},
|
217
|
+
search: {
|
218
|
+
type: Object,
|
219
|
+
default: () => {
|
220
|
+
return {};
|
221
|
+
},
|
222
|
+
},
|
223
|
+
loading: {
|
224
|
+
type: Boolean,
|
225
|
+
},
|
226
|
+
slots: {},
|
227
|
+
searchParams: {},
|
228
|
+
load: Function,
|
229
|
+
},
|
230
|
+
provide() {
|
231
|
+
return {
|
232
|
+
ctx: this,
|
233
|
+
controlCtx: this,
|
234
|
+
};
|
235
|
+
},
|
236
|
+
data() {
|
237
|
+
// $refs: {
|
238
|
+
// searchRef
|
239
|
+
// tableFormRef
|
240
|
+
// tableRef
|
241
|
+
// crudForm 弹窗表单实例
|
242
|
+
// dialogVm 弹窗实例
|
243
|
+
// };
|
244
|
+
return {
|
245
|
+
key: Math.random(),
|
246
|
+
showSearch: false,
|
247
|
+
isMaximize: false,
|
248
|
+
query: {},
|
249
|
+
form: {},
|
250
|
+
selectionRow: [],
|
251
|
+
isChangeShowSearch: false,
|
252
|
+
virtualList: [],
|
253
|
+
lazyTreeData: [],
|
254
|
+
showPopperNum: 0,
|
255
|
+
sameRowSpans: [],
|
256
|
+
_showSummary: false,
|
257
|
+
treeNodeMap: new Map(),
|
258
|
+
labelMinWidthMap: new Map(),
|
259
|
+
};
|
260
|
+
},
|
261
|
+
created() {
|
262
|
+
this.getLocalCache();
|
263
|
+
},
|
264
|
+
mounted() {
|
265
|
+
this.crudOptions.init && this.initQuery();
|
266
|
+
this.extendMethod(this.$refs.tableFormRef, ["validate", "clearValidate"]);
|
267
|
+
this.extendMethod(this.$refs.tableRef);
|
268
|
+
this.refactorTableHeaderClick();
|
269
|
+
},
|
270
|
+
computed: {
|
271
|
+
rowKey_() {
|
272
|
+
if (
|
273
|
+
this.isTree ||
|
274
|
+
this.crudOptions.selection.reserveSelection ||
|
275
|
+
this.crudOptions.selection["reserve-selection"] ||
|
276
|
+
this.crudOptions.rowKey
|
277
|
+
) {
|
278
|
+
return this.valueKey;
|
279
|
+
}
|
280
|
+
},
|
281
|
+
virtualized() {
|
282
|
+
return this.crudOptions.virtualized;
|
283
|
+
},
|
284
|
+
valueKey() {
|
285
|
+
if (this.crudOptions.uniqueId) return "$uniqueId";
|
286
|
+
if (this.crudOptions.rowKey) return this.crudOptions.rowKey;
|
287
|
+
return this.crudOptions.valueKey;
|
288
|
+
},
|
289
|
+
isTree() {
|
290
|
+
let flag = false;
|
291
|
+
this.data.forEach((ele) => {
|
292
|
+
if (ele.children) {
|
293
|
+
flag = true;
|
294
|
+
}
|
295
|
+
});
|
296
|
+
return flag;
|
297
|
+
},
|
298
|
+
crudOptions() {
|
299
|
+
return this.resultOptions;
|
300
|
+
},
|
301
|
+
tableProps() {
|
302
|
+
const obj = {};
|
303
|
+
Object.keys(this.crudOptions).forEach((key) => {
|
304
|
+
obj[toCamelCase(key)] = this.crudOptions[key];
|
305
|
+
});
|
306
|
+
const props = pick(obj, tableProps);
|
307
|
+
const height = this.tableHeight;
|
308
|
+
if (height) {
|
309
|
+
props.height = height;
|
310
|
+
} else {
|
311
|
+
delete props.height;
|
312
|
+
}
|
313
|
+
return props;
|
314
|
+
},
|
315
|
+
defaultColumns() {
|
316
|
+
const columns = [];
|
317
|
+
const options = pick(this.crudOptions, [
|
318
|
+
"expand",
|
319
|
+
"index",
|
320
|
+
"selection",
|
321
|
+
"singleSelection",
|
322
|
+
]);
|
323
|
+
Object.keys(options).forEach((key) => {
|
324
|
+
if (checkVisibility(options[key])) {
|
325
|
+
columns.push({ type: key, ...options[key] });
|
326
|
+
}
|
327
|
+
});
|
328
|
+
return filterColumns(columns.sort((a, b) => a.order - b.order));
|
329
|
+
},
|
330
|
+
columns() {
|
331
|
+
if (this.crudOptions.dynamicConfig) {
|
332
|
+
const dynamicColumns = (
|
333
|
+
this.generateDynamicColumns(
|
334
|
+
this.data,
|
335
|
+
this.crudOptions.dynamicConfig
|
336
|
+
) || []
|
337
|
+
).map(this.handleInitColumn);
|
338
|
+
return filterColumns(
|
339
|
+
this.insertColumns(
|
340
|
+
dynamicColumns,
|
341
|
+
this.resultColumns,
|
342
|
+
this.crudOptions.dynamicInsertPosition
|
343
|
+
)
|
344
|
+
);
|
345
|
+
}
|
346
|
+
return filterColumns(this.resultColumns);
|
347
|
+
},
|
348
|
+
flatColumns() {
|
349
|
+
return toTreeArray(this.columns);
|
350
|
+
},
|
351
|
+
trueRenderColumns() {
|
352
|
+
return this.flatColumns.filter((i) => !i.children);
|
353
|
+
},
|
354
|
+
columnsMap() {
|
355
|
+
const map = {};
|
356
|
+
this.trueRenderColumns.forEach((i) => {
|
357
|
+
map[i.prop] = i;
|
358
|
+
});
|
359
|
+
return map;
|
360
|
+
},
|
361
|
+
extendsScopedSlots() {
|
362
|
+
const slots = { ...this.$scopedSlots };
|
363
|
+
this.extendsSlots(slots, "add", "form");
|
364
|
+
this.extendsSlots(slots, "edit", "form");
|
365
|
+
this.extendsSlots(slots, "view", "form");
|
366
|
+
this.extendsSlots(slots, "searchHeader", "search");
|
367
|
+
return slots;
|
368
|
+
},
|
369
|
+
wrapperPadding() {
|
370
|
+
if (this.crudOptions.padding) return this.crudOptions.padding;
|
371
|
+
const { gap = 0 } = this.crudOptions;
|
372
|
+
return this.isAutoHeight ? `${gap}px ${gap}px 0` : `${gap}px`;
|
373
|
+
},
|
374
|
+
showEmpty() {
|
375
|
+
return checkVisibility(
|
376
|
+
this.crudOptions.empty,
|
377
|
+
null,
|
378
|
+
this.$scopedSlots.empty
|
379
|
+
);
|
380
|
+
},
|
381
|
+
},
|
382
|
+
watch: {
|
383
|
+
showPopperNum() {
|
384
|
+
this.$emit("update:showPopper", this.showPopperNum !== 0);
|
385
|
+
},
|
386
|
+
},
|
387
|
+
methods: {
|
388
|
+
// 重写表头点击事件
|
389
|
+
refactorTableHeaderClick() {
|
390
|
+
const tableHeader = this.$refs.tableRef.$refs.tableHeader;
|
391
|
+
const headerClick = tableHeader.handleHeaderClick;
|
392
|
+
tableHeader.handleHeaderClick = (event, column) => {
|
393
|
+
return tableHeader.$parent.$emit("header-click", column, event);
|
394
|
+
// const col = this.columnsMap[column.property];
|
395
|
+
// headerClick.call(tableHeader, event, column);
|
396
|
+
};
|
397
|
+
},
|
398
|
+
lazyLoad(tree, treeNode, resolve) {
|
399
|
+
if (this.crudOptions.autoLazy) {
|
400
|
+
this.treeNodeMap.set(tree[this.valueKey], { tree, treeNode, resolve });
|
401
|
+
const { item } = findTree(
|
402
|
+
this.lazyTreeData,
|
403
|
+
(item) => item[this.valueKey] === tree[this.valueKey]
|
404
|
+
);
|
405
|
+
if (item && item.children && item.children.length) {
|
406
|
+
const list = cloneDeep(item.children);
|
407
|
+
this.handleLocalLazy(list);
|
408
|
+
resolve(list);
|
409
|
+
} else {
|
410
|
+
// 更新空的懒加载节点
|
411
|
+
this.$set(
|
412
|
+
this.$refs.tableRef.store.states.lazyTreeNodeMap,
|
413
|
+
tree[this.valueKey],
|
414
|
+
[]
|
415
|
+
);
|
416
|
+
}
|
417
|
+
}
|
418
|
+
if (this.load) {
|
419
|
+
this.load(tree, treeNode, resolve);
|
420
|
+
}
|
421
|
+
},
|
422
|
+
handleLocalLazy(list) {
|
423
|
+
list.forEach((i) => {
|
424
|
+
if (i.children && i.children.length) {
|
425
|
+
delete i.children;
|
426
|
+
i.hasChildren = true;
|
427
|
+
}
|
428
|
+
});
|
429
|
+
},
|
430
|
+
getRenderColumns(mode) {
|
431
|
+
const options = this.crudOptions;
|
432
|
+
const key = mode + "Form";
|
433
|
+
if (
|
434
|
+
isPlainObject(options.formOptions) &&
|
435
|
+
Array.isArray(options.formOptions.renderColumns) &&
|
436
|
+
!options[key]?.renderColumns &&
|
437
|
+
options[key] !== false
|
438
|
+
) {
|
439
|
+
return options.formOptions.renderColumns || [];
|
440
|
+
}
|
441
|
+
if (
|
442
|
+
isPlainObject(options[key]) &&
|
443
|
+
Array.isArray(options[key].renderColumns)
|
444
|
+
) {
|
445
|
+
return options[key].renderColumns || [];
|
446
|
+
}
|
447
|
+
return this.columns
|
448
|
+
?.filter(
|
449
|
+
(column) =>
|
450
|
+
column[mode] && column[mode] !== false && options[key] !== false
|
451
|
+
)
|
452
|
+
.map((column) => column[mode]);
|
453
|
+
},
|
454
|
+
refreshTable() {
|
455
|
+
this.$refs.tableRef.doLayout();
|
456
|
+
this.$nextTick(() => {
|
457
|
+
// 触发表格重新渲染
|
458
|
+
this.key = Date.now();
|
459
|
+
});
|
460
|
+
},
|
461
|
+
defineRowIndex({ row, rowIndex }) {
|
462
|
+
Object.defineProperty(row, "$index", {
|
463
|
+
value: rowIndex,
|
464
|
+
writable: true,
|
465
|
+
enumerable: false,
|
466
|
+
});
|
467
|
+
return this.crudOptions.rowStyle
|
468
|
+
? this.crudOptions.rowStyle.call(null, {
|
469
|
+
row,
|
470
|
+
rowIndex,
|
471
|
+
})
|
472
|
+
: null;
|
473
|
+
},
|
474
|
+
_runWithoutDeps(fn) {
|
475
|
+
// 获取 Vue 实例内部的 Dep
|
476
|
+
const Dep = this.$data.__ob__.dep.constructor;
|
477
|
+
const target = Dep.target;
|
478
|
+
if (Dep.target) {
|
479
|
+
Dep.target = null;
|
480
|
+
}
|
481
|
+
|
482
|
+
try {
|
483
|
+
return fn();
|
484
|
+
} finally {
|
485
|
+
Dep.target = target;
|
486
|
+
}
|
487
|
+
},
|
488
|
+
|
489
|
+
// 根据依赖收集状态执行回调函数
|
490
|
+
executeWithDeps(callback, collectDep = true, ...args) {
|
491
|
+
if (!callback) return;
|
492
|
+
|
493
|
+
if (collectDep === false) {
|
494
|
+
return this._runWithoutDeps(() => {
|
495
|
+
return callback.call(null, ...args);
|
496
|
+
});
|
497
|
+
}
|
498
|
+
|
499
|
+
return callback.call(null, ...args);
|
500
|
+
},
|
501
|
+
cellClassName_({ row, column, rowIndex, columnIndex }) {
|
502
|
+
const { cellClassName, methodCollectDepends, editTheme } =
|
503
|
+
column?.options || {};
|
504
|
+
let cellName =
|
505
|
+
this.executeWithDeps(cellClassName, methodCollectDepends, {
|
506
|
+
row,
|
507
|
+
column,
|
508
|
+
rowIndex,
|
509
|
+
columnIndex,
|
510
|
+
}) || "";
|
511
|
+
|
512
|
+
const col = column.col;
|
513
|
+
if (!col) return cellName;
|
514
|
+
|
515
|
+
// 添加编辑状态类
|
516
|
+
if (
|
517
|
+
!col.type &&
|
518
|
+
editTheme &&
|
519
|
+
this.validateEdit(col, { row, $index: rowIndex })
|
520
|
+
) {
|
521
|
+
cellName += (cellName ? " " : "") + "edit-cell";
|
522
|
+
}
|
523
|
+
|
524
|
+
// 添加自定义单元格类
|
525
|
+
if (!col.type && !this.isDefaultColumn(col)) {
|
526
|
+
cellName += (cellName ? " " : "") + "custom-cell";
|
527
|
+
}
|
528
|
+
|
529
|
+
return cellName;
|
530
|
+
},
|
531
|
+
// 校验按钮隐藏
|
532
|
+
checkHiddenButtons(key, buttons, scope) {
|
533
|
+
buttons = filterButtons(buttons, this.crudOptions, scope, key);
|
534
|
+
return buttons;
|
535
|
+
},
|
536
|
+
handleWrapperClick() {
|
537
|
+
if (this.showPopperNum > 0) {
|
538
|
+
this.$emit("closeSearchPopover");
|
539
|
+
}
|
540
|
+
},
|
541
|
+
// 强制更新表格
|
542
|
+
_forceUpdate() {
|
543
|
+
this.$refs?.tableRef?.store?.updateColumns();
|
544
|
+
},
|
545
|
+
rowClick(row, column, event) {
|
546
|
+
this.selectRowClick(row, column, event);
|
547
|
+
if (!column) return;
|
548
|
+
this.handleRowClick({ row, $index: row.$index }, column.col.prop);
|
549
|
+
},
|
550
|
+
rowDblclick(row, column, event) {
|
551
|
+
if (!column) return;
|
552
|
+
this.handleRowClick({ row, $index: row.$index }, column.col.prop);
|
553
|
+
},
|
554
|
+
cellClick(row, column, cell, event) {
|
555
|
+
if (!column) return;
|
556
|
+
this.handleCellClick({ row, $index: row.$index }, column.col);
|
557
|
+
},
|
558
|
+
cellDblclick(row, column, cell, event) {
|
559
|
+
if (!column) return;
|
560
|
+
this.handleCellClick({ row, $index: row.$index }, column.col);
|
561
|
+
},
|
562
|
+
},
|
563
|
+
});
|
564
|
+
</script>
|