@ditari/bsui 1.1.16 → 1.1.18

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.
@@ -0,0 +1,49 @@
1
+ <script setup lang="ts">
2
+ import { ref } from "vue";
3
+
4
+ const queryParams = ref({
5
+ name: "",
6
+ age: ""
7
+ });
8
+ const loading = ref(false);
9
+ const onQuery = () => {
10
+ console.log("query");
11
+ loading.value = true;
12
+ setTimeout(() => {
13
+ loading.value = false;
14
+ }, 3000);
15
+ };
16
+
17
+ const onReset = () => {
18
+ console.log("reset");
19
+ };
20
+ </script>
21
+ <script lang="ts">
22
+ /**
23
+ * 表单查询条件组件demo
24
+ */
25
+ export default {
26
+ name: "QueryFormDemo"
27
+ };
28
+ </script>
29
+ <template>
30
+ <d-query-form
31
+ :loading="loading"
32
+ :model="queryParams"
33
+ label-width="90px"
34
+ @query="onQuery"
35
+ @reset="onReset"
36
+ >
37
+ <a-col :span="6">
38
+ <a-form-item label="年龄" name="age">
39
+ <a-input v-model:value="queryParams.age" />
40
+ </a-form-item>
41
+ </a-col>
42
+ <a-col v-for="item in 8" :key="item" :span="6">
43
+ <a-form-item label="标题" name="name">
44
+ <a-input v-model:value="queryParams.name" />
45
+ </a-form-item>
46
+ </a-col>
47
+ </d-query-form>
48
+ </template>
49
+ <style scoped></style>
@@ -0,0 +1,34 @@
1
+ <script setup lang="ts">
2
+
3
+ import { useTable } from "./hooks";
4
+
5
+ const { data, loading, config, selectedRowKeys } = useTable();
6
+ </script>
7
+ <script lang="ts">
8
+ export default {
9
+ name: "List"
10
+ };
11
+ </script>
12
+ <template>
13
+ <d-list-layout>
14
+ <template #form>
15
+ <!-- <d-query-form :value="formState" :scheme="scheme"> </d-query-form>-->
16
+ </template>
17
+ <template #table="{ height }">
18
+ <d-table
19
+ v-model:keys="selectedRowKeys"
20
+ row-key="id"
21
+ :loading="loading"
22
+ :expanded-row-keys="['1', '2']"
23
+ :data="[]"
24
+ :config="config"
25
+ :height="height"
26
+ >
27
+ <template #action>
28
+ <a-button>ok</a-button>
29
+ </template>
30
+ </d-table>
31
+ </template>
32
+ </d-list-layout>
33
+ </template>
34
+ <style scoped></style>
@@ -0,0 +1,106 @@
1
+ import { useRequestList } from "../../../../../hooks/src/http/index";
2
+ import { reactive, ref } from "vue";
3
+ import { testService } from "../../api/list";
4
+
5
+ export const useTableConfig = () => {
6
+ const columns = [
7
+ {
8
+ title: "Id",
9
+ dataIndex: "id",
10
+ width: 350
11
+ },
12
+ {
13
+ title: "Name",
14
+ dataIndex: "name",
15
+ width: 350
16
+ },
17
+ {
18
+ title: "avatar",
19
+ dataIndex: "avatar",
20
+ width: 350,
21
+ config: {
22
+ type: "dic",
23
+ name: "k_v",
24
+ style: {
25
+ D: "red",
26
+ S: "blue"
27
+ }
28
+ }
29
+ },
30
+ {
31
+ title: "Job",
32
+ dataIndex: "job",
33
+ width: 350,
34
+ config: {
35
+ type: "date",
36
+ formatter: "YYYY"
37
+ }
38
+ },
39
+ {
40
+ title: "操作",
41
+ width: 100,
42
+ fixed: "right",
43
+ slot: "action"
44
+ }
45
+ ];
46
+
47
+ return {
48
+ columns
49
+ };
50
+ };
51
+
52
+ export const useTable = () => {
53
+ const queryParams = ref({});
54
+ const selectedRowKeys = ref<any>([]);
55
+ const { columns } = useTableConfig();
56
+
57
+ const { data, loading, onPageChange, pagination, run, onQuery } =
58
+ useRequestList(testService, {
59
+ params: queryParams,
60
+ dataKey: "data.data"
61
+ });
62
+
63
+ const id = ref("");
64
+
65
+ //表格选项
66
+ const config = reactive({
67
+ columns,
68
+ bordered: true,
69
+ pagination,
70
+ selection: "N",
71
+ pageOption: {
72
+ sizeOptions: ["20", "40", "50", "100"],
73
+
74
+ },
75
+ onPageChange,
76
+ dbClick: (record: any) => {
77
+ const index = selectedRowKeys.value.indexOf(record.id);
78
+ if (index > -1) {
79
+ selectedRowKeys.value.splice(index, 1);
80
+ }
81
+ id.value = id.value === record.id ? "" : record.id;
82
+ },
83
+ rowClassName: (record: any) => {
84
+ if (record.id === id.value) {
85
+ return "row-class";
86
+ }
87
+ },
88
+ getCheckboxProps: (record: any) => {
89
+ return {
90
+ disabled: record.id === "1",
91
+ name: "id",
92
+ value: id.value
93
+ };
94
+ }
95
+ });
96
+
97
+ return {
98
+ selectedRowKeys,
99
+ data,
100
+ loading,
101
+ queryParams,
102
+ config: reactive(config),
103
+ run,
104
+ onQuery
105
+ };
106
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ditari/bsui",
3
- "version": "1.1.16",
3
+ "version": "1.1.18",
4
4
  "description": "",
5
5
  "keywords": [],
6
6
  "author": "",
@@ -1,4 +1,4 @@
1
- import { defineComponent, nextTick, ref } from "vue";
1
+ import { defineComponent, onMounted, 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
+ onMounted(() => {
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
 
@@ -179,7 +179,7 @@ const DXTable = defineComponent({
179
179
  });
180
180
  // 监听分页组件
181
181
  const onPageChange = (page: number, size: number) => {
182
- onChange ? onChange({ page, size }) : null;
182
+ onChange ? onChange({ page: page === 0 ? 1 : page, size }) : null;
183
183
  // 切换分页的时候,表体滚动到顶部
184
184
  antTableBodyRef.value.scrollTop = 0;
185
185
  // 如果当前为单选或未开启分页保留数据选中的数据都会被清除
@@ -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>