p-pc-ui 1.2.2 → 1.2.5

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.
@@ -1,113 +0,0 @@
1
- <template>
2
- <Modal
3
- v-model:open="visible"
4
- :title="titleText"
5
- :width="modalWidth"
6
- okText="确定"
7
- cancel-text="取消"
8
- @ok="ok"
9
- @cancel="cancel"
10
- >
11
- <div style="max-height: 600px; overflow-y: auto; padding-right: 80px">
12
- <p-form v-if="visible" ref="PFormRef" :render-data="formRenderData" :init-form="initFormValue"></p-form>
13
- </div>
14
- </Modal>
15
- </template>
16
-
17
- <script lang="ts" setup>
18
- import PForm from "../p-form/p-form.vue";
19
- import { ref, reactive } from "vue";
20
- import { message, Modal } from "ant-design-vue";
21
- import * as _ from "../../utils/dataUtils";
22
- import type { FormDataItem } from "../p-form/index.d";
23
-
24
- interface Props {}
25
- const props = defineProps<Props>();
26
-
27
- const modalWidth = ref(600);
28
-
29
- const visible = ref(false);
30
- const titleText = ref("");
31
- const PFormRef = ref();
32
-
33
- let formRenderData = reactive([]);
34
- let initFormValue: any = reactive({});
35
-
36
- interface ModalFormConfig {
37
- operateType: "add" | "detail" | "edit";
38
- renderFormData: FormDataItem[];
39
- onOk: Function;
40
- title?: string;
41
- renderKeys?: string[];
42
- width?: number;
43
- rowId?: string;
44
- extraFormData?: { [key: string]: any };
45
- initFormData?: { [key: string]: any };
46
- }
47
-
48
- let modalConfig: ModalFormConfig;
49
-
50
- const open = async (config: ModalFormConfig) => {
51
- const { operateType, rowId, initFormData, onOk, renderFormData, renderKeys, extraFormData, title, width } = config;
52
- if (!["add", "edit", "detail"].includes(operateType)) return message.error("操作类型错误");
53
- if (["edit", "detail"].includes(operateType) && _.isEmpty(rowId)) return message.error("请传入主键ID");
54
-
55
- // 设置modal的宽度
56
- modalWidth.value = width || 600;
57
-
58
- if (!_.isEmpty(initFormData)) {
59
- initFormValue = initFormData;
60
- } else {
61
- initFormValue = {};
62
- }
63
-
64
- if (title) {
65
- titleText.value = title;
66
- } else {
67
- const typeMap = {
68
- add: "新增",
69
- edit: "编辑",
70
- detail: "查看",
71
- };
72
- titleText.value = typeMap[operateType];
73
- }
74
-
75
- const filterRenderData: any = [];
76
- for (const renderKey of renderKeys || renderFormData.map((val) => val.key)) {
77
- const renderItem = _.cloneDeep(renderFormData).find((val) => val.key == renderKey);
78
- if (!_.isEmpty(renderItem)) {
79
- filterRenderData.push(renderItem);
80
- }
81
- }
82
-
83
- modalConfig = config;
84
- formRenderData = filterRenderData;
85
- visible.value = true;
86
- };
87
-
88
- const ok = async () => {
89
- let formData = await PFormRef.value.getFormData();
90
- if (_.isEmpty(formData)) return;
91
- if (!_.isEmpty(modalConfig.extraFormData)) {
92
- formData = { ...formData, ...modalConfig.extraFormData };
93
- }
94
- let callbackRes = null;
95
- if (modalConfig.operateType == "edit") {
96
- callbackRes = await modalConfig.onOk(modalConfig.rowId, formData);
97
- } else {
98
- callbackRes = await modalConfig.onOk(formData);
99
- }
100
- if (callbackRes === false) return;
101
- visible.value = false;
102
- };
103
-
104
- const cancel = () => {
105
- visible.value = false;
106
- };
107
-
108
- defineExpose({
109
- open,
110
- });
111
- </script>
112
-
113
- <style scoped></style>
@@ -1,42 +0,0 @@
1
-
2
- interface TableBase {
3
- title: string;
4
- width?: number;
5
- sorter?: boolean;
6
- align?: 'center' | 'left' | 'right';
7
- mapPath?: string[];
8
- customRender?: Function;
9
- default?: any;
10
- }
11
-
12
- interface TablePic extends TableBase {
13
- key: string;
14
- type: 'pic';
15
- showOssUrlFunc?: (ossKey: string) => string;
16
- picWidth?: number;
17
- picHeight?: number;
18
- }
19
-
20
- interface TableLink extends TableBase {
21
- key: string;
22
- type: 'link';
23
- }
24
-
25
- interface TableCommon extends TableBase {
26
- key: string;
27
- type: 'common';
28
- }
29
-
30
- interface TableDate extends TableBase {
31
- key: string;
32
- type: 'date';
33
- format?: string;
34
- }
35
-
36
- interface TableOperate extends TableBase {
37
- type: 'operate',
38
- operateButtons: { label: string; click: Function; visibleFunc?: Function }[];
39
-
40
- }
41
-
42
- export type TableColumn = TableCommon | TablePic | TableLink | TableDate | TableOperate;
@@ -1,299 +0,0 @@
1
- <script lang="ts" setup>
2
- // import "viewerjs/dist/viewer.css";
3
- import { api as viewerApi } from "v-viewer";
4
- import PForm from "../p-form/p-form.vue";
5
- import { h, ref, reactive, onMounted, toRaw } from "vue";
6
- import * as _ from "../../utils/dataUtils";
7
- import dayjs from "dayjs";
8
- import { Table as ATable, Button as AButton } from "ant-design-vue";
9
- import type { FormDataItem } from "../p-form/index.d";
10
- import type { TableColumn } from "./index.d";
11
- const SearchFormRef = ref();
12
-
13
- interface Props {
14
- tableColumns: TableColumn[];
15
- getData: null | ((query: object) => Promise<{ data: any[]; count: number; pages: { total: number; now: number } }>);
16
- searchRenderData?: FormDataItem[];
17
- initSearchFormData?: any;
18
- height?: number;
19
- }
20
-
21
- const props = withDefaults(defineProps<Props>(), {
22
- getData: null,
23
- height: 1000,
24
- searchRenderData: [] as any,
25
- });
26
-
27
- const pageQuery = reactive({
28
- p: 1,
29
- pc: 10,
30
- od: "-id",
31
- });
32
-
33
- const tableData = reactive({
34
- data: [] as any,
35
- count: 0,
36
- pages: {
37
- total: 0,
38
- now: 0,
39
- },
40
- });
41
-
42
- const emits = defineEmits(["select"]);
43
-
44
- const rowSelection = {
45
- onChange: (selectedRowKeys, selectedRows) => {
46
- emits("select", selectedRowKeys);
47
- },
48
- };
49
-
50
- const loading = ref(false);
51
-
52
- let searchQuery = {};
53
-
54
- const renderTableColumns = (tableColumns: TableColumn[]) => {
55
- const returnColumns: any = [];
56
- for (const renderItem of tableColumns) {
57
- if (renderItem.type == "operate") {
58
- renderItem.customRender = ({ text, record }) => {
59
- const buttons: any = [];
60
- for (const buttonItem of renderItem.operateButtons) {
61
- if (buttonItem.visibleFunc && !buttonItem.visibleFunc(record)) continue;
62
- buttons.push(
63
- h(
64
- "a",
65
- {
66
- onClick: () => {
67
- buttonItem.click(record);
68
- },
69
- },
70
- buttonItem.label
71
- )
72
- );
73
- }
74
- return h("div", { style: { display: "flex", justifyContent: "space-around" } }, buttons);
75
- };
76
-
77
- renderItem.width = renderItem.operateButtons.length * 65;
78
- renderItem.align = "center";
79
- }
80
-
81
- // 处理默认字段
82
- if (!_.isEmpty(renderItem.default)) {
83
- renderItem.customRender = ({ text, record }) => {
84
- return h("span", text || renderItem.default);
85
- };
86
- }
87
-
88
- // 解析json字段
89
- if (renderItem.key && renderItem.key.includes(".")) {
90
- renderItem.customRender = ({ text, record }) => {
91
- return h("span", _.get(record, renderItem.key!.split(".")));
92
- };
93
- }
94
-
95
- if (renderItem.type == "pic") {
96
- renderItem.customRender = ({ text, record }) => {
97
- const key = renderItem.key;
98
- let pics = key.includes(".") ? _.get(record, key.split(".")) : _.get(record, key);
99
- if (_.isEmpty(pics)) return h("span", "暂无");
100
- pics = _.isArray(pics) ? pics : [pics];
101
- const format_pics: any = [];
102
- for (const pic_item of pics) {
103
- if (!pic_item.includes("http") && renderItem.showOssUrlFunc) {
104
- format_pics.push(renderItem.showOssUrlFunc(pic_item));
105
- } else {
106
- format_pics.push(pic_item);
107
- }
108
- }
109
-
110
- return h(
111
- "a",
112
- {
113
- onClick: () => {
114
- viewerApi({ images: format_pics });
115
- },
116
- },
117
- h("img", {
118
- src: format_pics[0],
119
- style: {
120
- width: (renderItem.picWidth || 60) + "px",
121
- height: (renderItem.picHeight || 60) + "px",
122
- marginLeft: "10px",
123
- },
124
- })
125
- );
126
- };
127
- }
128
-
129
- // 处理MAP字段
130
- if (renderItem.mapPath) {
131
- const mapInfoStr: any = localStorage.getItem("map");
132
- const mapInfo = JSON.parse(mapInfoStr);
133
- const mapItem = _.get(mapInfo, renderItem.mapPath);
134
- renderItem.customRender = ({ text, record }) => {
135
- return h("span", mapItem[text]);
136
- };
137
- }
138
-
139
- if (renderItem.type == "date") {
140
- renderItem.customRender = ({ text, record }) => {
141
- return h("span", dayjs(text).format(renderItem.format || "YYYY-MM-DD HH:mm:ss"));
142
- };
143
- }
144
-
145
- renderItem["dataIndex"] = renderItem["key"];
146
- returnColumns.push(renderItem);
147
- }
148
-
149
- return returnColumns;
150
- };
151
-
152
- const columns = renderTableColumns(props.tableColumns);
153
-
154
- const renderTableData = async () => {
155
- loading.value = true;
156
- const _searchInitFormData = props.initSearchFormData ? JSON.parse(JSON.stringify(props.initSearchFormData)) : {};
157
- const _pageQuery = JSON.parse(JSON.stringify(pageQuery));
158
- if (!props.getData) return;
159
- const _tableData = await props.getData({ ..._searchInitFormData, ..._pageQuery, ..._.cloneDeep(searchQuery) });
160
- tableData.data = _tableData.data;
161
- tableData.count = _tableData.count;
162
- tableData.pages = _tableData.pages;
163
- loading.value = false;
164
- };
165
-
166
- const refresh = () => {
167
- renderTableData();
168
- };
169
-
170
- const onPageChange = (p) => {
171
- pageQuery.p = p;
172
- refresh();
173
- };
174
-
175
- const onPageSizeChange = (current, pc) => {
176
- pageQuery.p = 1;
177
- pageQuery.pc = pc;
178
- refresh();
179
- };
180
-
181
- const searchClick = async () => {
182
- const query = await SearchFormRef.value.getFormData();
183
-
184
- if (_.isEmpty(query)) return;
185
- searchQuery = _.pickBy(query, (value, key) => {
186
- return value !== "" && value != undefined;
187
- });
188
-
189
- pageQuery.p = 1;
190
- refresh();
191
- };
192
-
193
- const resetSearch = () => {
194
- searchQuery = {};
195
- pageQuery.p = 1;
196
- SearchFormRef.value.resetForm();
197
- refresh();
198
- };
199
-
200
- const onchange = (pagination, filters, sorter, extra) => {
201
- if (!_.isEmpty(sorter)) {
202
- const od: any = [];
203
-
204
- if (sorter.order == "ascend") {
205
- od.push(sorter.field);
206
- } else if (sorter.order == "descend") {
207
- od.push(`-${sorter.field}`);
208
- } else {
209
- od.push("-id");
210
- }
211
-
212
- pageQuery.od = od.join(",");
213
- refresh();
214
- }
215
- };
216
-
217
- const getTableData = () => {
218
- return toRaw(tableData)["data"];
219
- };
220
-
221
- onMounted(() => {
222
- renderTableData();
223
- });
224
-
225
- defineExpose({
226
- refresh,
227
- tableData,
228
- getTableData,
229
- });
230
- </script>
231
-
232
- <template>
233
- <div v-if="searchRenderData.length > 0" class="search-form">
234
- <PForm
235
- ref="SearchFormRef"
236
- :is-search-form="true"
237
- :render-data="searchRenderData"
238
- :init-form="initSearchFormData"
239
- layout="inline"
240
- >
241
- <template v-slot:button>
242
- <a-button type="primary" @click="searchClick" style="margin-left: 20px"> 搜索 </a-button>
243
- <a-button style="margin-left: 10px" @click="resetSearch"> 重置 </a-button>
244
- </template>
245
- </PForm>
246
- </div>
247
-
248
- <div style="display: flex; justify-content: flex-end; margin-bottom: 10px; margin-top: 10px; padding: 20px">
249
- <slot name="button"></slot>
250
- </div>
251
-
252
- <a-table
253
- rowKey="id"
254
- :row-selection="rowSelection"
255
- :columns="columns"
256
- :data-source="tableData?.data || []"
257
- :loading="loading"
258
- :scroll="{
259
- y: height,
260
- }"
261
- :pagination="{
262
- current: pageQuery.p,
263
- defaultPageSize: pageQuery.pc,
264
- showSizeChanger: true,
265
- pageSizeOptions: ['10', '20', '50', '100', '200'],
266
- total: tableData.count,
267
- onChange: onPageChange,
268
- onShowSizeChange: onPageSizeChange,
269
- }"
270
- bordered
271
- @change="onchange"
272
- >
273
- <template #bodyCell="slotProps">
274
- <slot name="bodyCell" v-bind="slotProps" />
275
- </template>
276
- </a-table>
277
- </template>
278
-
279
- <style>
280
- .ant-table-striped :deep(.table-striped) td {
281
- background-color: #fafafa;
282
- }
283
-
284
- .ant-table-thead > tr > th {
285
- position: relative;
286
- color: rgba(0, 0, 0, 0.85);
287
- font-weight: 500;
288
- text-align: left;
289
- background: #fafafa !important;
290
- border-bottom: 1px solid #f0f0f0;
291
- transition: background 0.3s ease;
292
- }
293
-
294
- .search-form {
295
- padding: 10px;
296
- padding-top: 25px;
297
- border-bottom: 10px solid #f5f5f5;
298
- }
299
- </style>
package/dist/index.ts DELETED
@@ -1,8 +0,0 @@
1
- import PTable from './components/p-table/p-table.vue'
2
- import PForm from './components/p-form/p-form.vue'
3
- import PModalForm from './components/p-modal-form/p-modal-form.vue'
4
-
5
- export { PTable, PModalForm, PForm }
6
- export type { FormDataItem } from './components/p-form/index.d'
7
- export type { TableColumn } from './components/p-table/index.d'
8
-