@ditari/bsui 1.1.16 → 1.1.17

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,4 +1,4 @@
1
- import { defineComponent, nextTick, ref } from "vue";
1
+ import { defineComponent, nextTick, ref, watch, watchEffect } from "vue";
2
2
  import { Form, FormItem, Row, Col, Button, Space } from "ant-design-vue";
3
3
  import {
4
4
  SearchOutlined,
@@ -10,6 +10,7 @@ import DJsonSchemeRender from "../json-scheme-render/JsonSchemeRender";
10
10
 
11
11
  /**
12
12
  * 查询表单渲染
13
+ * 展开,隐藏功能
13
14
  */
14
15
  export default defineComponent({
15
16
  name: "DQueryForm",
@@ -18,7 +19,7 @@ export default defineComponent({
18
19
  type: [Array, Object] as unknown as () => any[] | Record<string, any>,
19
20
  default: () => []
20
21
  },
21
- value: {
22
+ model: {
22
23
  type: Object as () => Record<string, unknown>,
23
24
  default: () => ({})
24
25
  },
@@ -33,131 +34,168 @@ export default defineComponent({
33
34
  },
34
35
  emits: ["reset", "query"],
35
36
  setup(props, { slots, emit }) {
36
- const modelValue = ref(props.value);
37
- const loading = ref(props.loading);
38
-
39
- // 为24网格布局
40
- const gridCount = 24;
41
- // 每列占6个格子
42
- const colSpan = 6;
43
- // 每行显示4列
44
- const colsPerRow = 4;
45
- // 操作按钮span
46
- const actionSpan = ref(6);
47
- // 控制展开或隐藏按钮文本
48
- const isExpend = ref(false);
49
- // 控制展开按按钮是否显示
50
- const expendBtnVisible = ref(false);
51
-
52
- // 行对象
53
- const rowRef = ref<any>(null);
54
- nextTick(() => {
55
- handleShowOrHidden();
56
- });
57
-
58
- /**
59
- * 操作按钮渲染
60
- */
61
- function renderAction() {
62
- return (
63
- <Space>
64
- <Button
65
- loading={loading.value}
66
- type={"primary"}
67
- shape={"round"}
68
- onClick={onQuery}
69
- >
70
- {{
71
- default: () => "查询",
72
- icon: () => <SearchOutlined />
73
- }}
74
- </Button>
75
- <Button disabled={loading.value} shape={"round"} onClick={onReset}>
76
- {{
77
- default: () => "重置",
78
- icon: () => <ReloadOutlined />
79
- }}
80
- </Button>
81
- {expendBtnVisible.value ? (
82
- <Button onClick={onExpend} shape={"round"}>
83
- {{
84
- default: () => (isExpend.value ? "收起" : "展开"),
85
- icon: () => (
86
- <DoubleRightOutlined rotate={isExpend.value ? -90 : 90} />
87
- )
88
- }}
89
- </Button>
90
- ) : null}
91
- </Space>
92
- );
93
- }
37
+ // 表单
38
+ const { loading, modelValue, formRef, onQuery, onReset } = useForm();
39
+ // 展开
40
+ const { rowRef, actionSpan, onExpend, expendBtnVisible, isExpend } =
41
+ useExpand();
42
+ //渲染操作列
43
+ const { renderAction } = useRender();
94
44
 
95
- function onExpend() {
96
- isExpend.value = !isExpend.value;
97
- handleShowOrHidden();
98
- }
45
+ function useForm() {
46
+ const loading = ref(false);
47
+ const formRef = ref<any>(null);
48
+ const modelValue = ref<any>({});
99
49
 
100
- /**
101
- * 处理隐藏或显示
102
- */
103
- function handleShowOrHidden() {
104
- const colEl = Array.from(rowRef.value?.$el?.children);
105
- // col总条数 减掉操作栏按钮的div个数为1
106
- const colElLen = colEl.length - 1;
107
- // 已占用的网格数 = col总条数 * 每列占用的网格数
108
- const occupiedCols = colElLen * colSpan;
109
- // 总行数 = 总div数 / 每行显示的列数
110
- const fullRows = Math.ceil(colElLen / colsPerRow);
111
- // 最后一行的网格数 = 已占用的网格数 % 24
112
- const lastRowCols = occupiedCols % gridCount;
113
- // 最后一行剩余的网格数
114
- const remainingCols = gridCount - lastRowCols;
115
-
116
- // 网格行大于2才显示展开或隐藏按钮
117
- if (fullRows > 2) {
118
- expendBtnVisible.value = true;
119
- }
120
- // 最后一行的起始索引
121
- const lastRowStartIndex = colsPerRow * (fullRows - 1) - 1;
122
- // 只有展开按钮显示时才处理
123
- if (expendBtnVisible.value) {
124
- colEl.forEach((col: any, index) => {
125
- if (index >= lastRowStartIndex) {
126
- // 最后一个元素不隐藏 是操作按钮的div
127
- index !== colElLen
128
- ? (col.style.display = !isExpend.value ? "none" : "block")
129
- : null; // 隐藏元素
130
- }
131
- });
132
- }
50
+ watchEffect(() => {
51
+ modelValue.value = props.model;
52
+ });
133
53
 
134
- if (expendBtnVisible.value) {
135
- // 如果是展开状态 则操作按钮占用剩余的网格数 否则占用6个网格
136
- isExpend.value
137
- ? (actionSpan.value = remainingCols)
138
- : (actionSpan.value = colSpan);
139
- }
140
- }
54
+ watch(
55
+ () => props.loading,
56
+ (val) => {
57
+ loading.value = val;
58
+ }
59
+ );
141
60
 
142
- // 表单
143
- const { formRef, onQuery, onReset } = useForm();
144
- function useForm() {
145
- const formRef = ref<any>(null);
146
61
  const onQuery = () => {
147
- emit("query");
62
+ emit("query", modelValue.value);
148
63
  };
149
64
 
150
65
  const onReset = () => {
151
- formRef.value.resetFields();
66
+ formRef.value?.resetFields();
152
67
  emit("reset");
153
68
  };
154
69
  return {
70
+ loading,
71
+ modelValue,
155
72
  formRef,
156
73
  onQuery,
157
74
  onReset
158
75
  };
159
76
  }
160
77
 
78
+ function useRender() {
79
+ /**
80
+ * 操作按钮渲染
81
+ */
82
+ function renderAction() {
83
+ return (
84
+ <Space>
85
+ <Button
86
+ loading={loading.value}
87
+ type={"primary"}
88
+ shape={"round"}
89
+ onClick={onQuery}
90
+ >
91
+ {{
92
+ default: () => "查询",
93
+ icon: () => <SearchOutlined />
94
+ }}
95
+ </Button>
96
+ <Button disabled={loading.value} shape={"round"} onClick={onReset}>
97
+ {{
98
+ default: () => "重置",
99
+ icon: () => <ReloadOutlined />
100
+ }}
101
+ </Button>
102
+ {expendBtnVisible.value ? (
103
+ <Button onClick={onExpend} shape={"round"}>
104
+ {{
105
+ default: () => (isExpend.value ? "收起" : "展开"),
106
+ icon: () => (
107
+ <DoubleRightOutlined rotate={isExpend.value ? -90 : 90} />
108
+ )
109
+ }}
110
+ </Button>
111
+ ) : null}
112
+ </Space>
113
+ );
114
+ }
115
+ return {
116
+ renderAction
117
+ };
118
+ }
119
+
120
+ function useExpand() {
121
+ // 为24网格布局
122
+ const gridCount = 24;
123
+ // 每列占6个格子
124
+ const colSpan = 6;
125
+ // 每行显示4列
126
+ const colsPerRow = 4;
127
+ // 操作按钮span
128
+ const actionSpan = ref(6);
129
+ // 控制展开或隐藏按钮文本
130
+ const isExpend = ref(false);
131
+ // 控制展开按按钮是否显示
132
+ const expendBtnVisible = ref(false);
133
+ // 行对象
134
+ const rowRef = ref<any>(null);
135
+
136
+ nextTick(() => {
137
+ handleShowOrHidden();
138
+ });
139
+
140
+ function onExpend() {
141
+ isExpend.value = !isExpend.value;
142
+ handleShowOrHidden();
143
+ }
144
+
145
+ /**
146
+ * 处理隐藏或显示
147
+ */
148
+ function handleShowOrHidden() {
149
+ const colEl = Array.from(rowRef.value?.$el?.children);
150
+ // col总条数 减掉操作栏按钮的div个数为1
151
+ const colElLen = colEl.length - 1;
152
+ // 已占用的网格数 = col总条数 * 每列占用的网格数
153
+ const occupiedCols = colElLen * colSpan;
154
+ // 总行数 = 总div数 / 每行显示的列数
155
+ const fullRows = Math.ceil(colElLen / colsPerRow);
156
+ // 最后一行的网格数 = 已占用的网格数 % 24
157
+ const lastRowCols = occupiedCols % gridCount;
158
+ // 最后一行剩余的网格数
159
+ const remainingCols = gridCount - lastRowCols;
160
+
161
+ // 网格行大于2才显示展开或隐藏按钮
162
+ if (fullRows > 2) {
163
+ expendBtnVisible.value = true;
164
+ } else {
165
+ // 如果没有大于两行,操作栏占用剩余的宽度
166
+ actionSpan.value = remainingCols;
167
+ }
168
+ // 最后一行的起始索引
169
+ const lastRowStartIndex = colsPerRow * (fullRows - 1) - 1;
170
+ // 只有展开按钮显示时才处理
171
+ if (expendBtnVisible.value) {
172
+ colEl.forEach((col: any, index) => {
173
+ if (index >= lastRowStartIndex) {
174
+ // 最后一个元素不隐藏 是操作按钮的div
175
+ index !== colElLen
176
+ ? (col.style.display = !isExpend.value ? "none" : "block")
177
+ : null; // 隐藏元素
178
+ }
179
+ });
180
+ }
181
+
182
+ if (expendBtnVisible.value) {
183
+ // 如果是展开状态 则操作按钮占用剩余的网格数 否则占用6个网格
184
+ isExpend.value
185
+ ? (actionSpan.value = remainingCols)
186
+ : (actionSpan.value = colSpan);
187
+ }
188
+ }
189
+
190
+ return {
191
+ rowRef,
192
+ actionSpan,
193
+ onExpend,
194
+ expendBtnVisible,
195
+ isExpend
196
+ };
197
+ }
198
+
161
199
  return () => (
162
200
  <>
163
201
  <Form
@@ -47,10 +47,10 @@ const tableProps = () => {
47
47
  type: Object as PropType<TableProps["expandedRowKeys"]>,
48
48
  default: () => []
49
49
  },
50
- defaultExpandAllRows: Boolean as PropType<
51
- TableProps["defaultExpandAllRows"]
52
- >,
53
- default: () => true
50
+ defaultExpandAllRows: {
51
+ type: Boolean as PropType<TableProps["defaultExpandAllRows"]>,
52
+ default: () => true
53
+ }
54
54
  };
55
55
  };
56
56
 
@@ -386,6 +386,15 @@ const DXTable = defineComponent({
386
386
  return <>{slots.summary && slots.summary()}</>;
387
387
  };
388
388
 
389
+ /**
390
+ * 展开行事件
391
+ * @param expanded
392
+ * @param record
393
+ */
394
+ const onExpand = (expanded: any, record: any) => {
395
+ props.config.onExpand && props.config.onExpand({ expanded, record });
396
+ };
397
+
389
398
  return () => (
390
399
  <div ref={tableRootRef} style={{ height: "100%" }}>
391
400
  <Table
@@ -408,6 +417,7 @@ const DXTable = defineComponent({
408
417
  customRow={customRow}
409
418
  rowSelection={rowSelection.value}
410
419
  rowClassName={onRowClassName}
420
+ onExpand={onExpand}
411
421
  >
412
422
  {{
413
423
  bodyCell: ({ column, record, index }: any) => {
@@ -1,13 +0,0 @@
1
- <script setup lang="ts">
2
- import { ref } from "vue";
3
- const name = ref("");
4
- </script>
5
- <script lang="ts">
6
- export default {
7
- name: "Test"
8
- };
9
- </script>
10
- <template>
11
- <a-input v-model:value="name" />
12
- </template>
13
- <style scoped></style>