@ditari/bsui 1.0.7 → 1.0.8
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/dist/cjs/components/components.cjs.js +1 -1
- package/dist/cjs/components/components.d.ts +2 -0
- package/dist/cjs/components/desensitize/Desensitize.cjs.js +1 -0
- package/dist/cjs/components/desensitize/Desensitize.d.ts +30 -0
- package/dist/cjs/components/desensitize/index.cjs.js +1 -0
- package/dist/cjs/components/desensitize/index.d.ts +30 -0
- package/dist/cjs/components/dic/DicReplace.cjs.js +1 -0
- package/dist/cjs/components/dic/DicReplace.d.ts +23 -0
- package/dist/cjs/components/dic/dic.worker.cjs.js +1 -0
- package/dist/cjs/components/dic/index.cjs.js +1 -0
- package/dist/cjs/components/dic/index.d.ts +23 -0
- package/dist/cjs/components/index.cjs.js +1 -1
- package/dist/cjs/components/menu/Menu.cjs.js +1 -1
- package/dist/cjs/components/select/Select.vue.cjs.js +1 -1
- package/dist/cjs/components/select/dic.worker.cjs.js +1 -0
- package/dist/cjs/components/table/Table.cjs.js +1 -0
- package/dist/cjs/components/table/Table.d.ts +71 -0
- package/dist/cjs/components/table/index.cjs.js +1 -1
- package/dist/cjs/components/table/index.d.ts +29 -102
- package/dist/cjs/components/table/interface/table.d.ts +33 -0
- package/dist/cjs/hooks/http/index.cjs.js +1 -1
- package/dist/cjs/hooks/http/index.d.ts +4 -7
- package/dist/cjs/utils/html.cjs.js +1 -0
- package/dist/cjs/utils/html.d.ts +1 -0
- package/dist/cjs/utils/index.d.ts +1 -0
- package/dist/css/desensitize/style/index.css +1 -0
- package/dist/css/grid/style/index.css +1 -1
- package/dist/css/index.css +1 -1
- package/dist/css/table/style/index.css +1 -0
- package/dist/esm/components/components.d.ts +2 -0
- package/dist/esm/components/components.esm.js +18 -14
- package/dist/esm/components/desensitize/Desensitize.d.ts +30 -0
- package/dist/esm/components/desensitize/Desensitize.esm.js +46 -0
- package/dist/esm/components/desensitize/index.d.ts +30 -0
- package/dist/esm/components/desensitize/index.esm.js +7 -0
- package/dist/esm/components/dic/DicReplace.d.ts +23 -0
- package/dist/esm/components/dic/DicReplace.esm.js +38 -0
- package/dist/esm/components/dic/dic.worker.esm.js +17 -0
- package/dist/esm/components/dic/index.d.ts +23 -0
- package/dist/esm/components/dic/index.esm.js +7 -0
- package/dist/esm/components/index.esm.js +22 -18
- package/dist/esm/components/menu/Menu.esm.js +8 -9
- package/dist/esm/components/select/Select.vue.esm.js +32 -28
- package/dist/esm/components/select/dic.worker.esm.js +12 -0
- package/dist/esm/components/select/index.d.ts +39 -58
- package/dist/esm/components/table/Table.d.ts +71 -0
- package/dist/esm/components/table/Table.esm.js +214 -0
- package/dist/esm/components/table/index.d.ts +29 -102
- package/dist/esm/components/table/index.esm.js +4 -5
- package/dist/esm/components/table/interface/table.d.ts +33 -0
- package/dist/esm/hooks/http/index.d.ts +4 -7
- package/dist/esm/hooks/http/index.esm.js +26 -25
- package/dist/esm/utils/html.d.ts +1 -0
- package/dist/esm/utils/html.esm.js +15 -0
- package/dist/esm/utils/index.d.ts +1 -0
- package/dist/style/desensitize/style/index.scss +7 -0
- package/dist/style/grid/style/index.scss +15 -6
- package/dist/style/index.scss +2 -0
- package/dist/style/table/style/index.scss +10 -0
- package/dist/style/theme/variable.scss +1 -0
- package/package.json +1 -1
- package/src/components/components.ts +2 -0
- package/src/components/desensitize/Desensitize.tsx +69 -0
- package/src/components/desensitize/index.ts +5 -0
- package/src/components/desensitize/style/index.scss +7 -0
- package/src/components/dic/DicReplace.tsx +55 -0
- package/src/components/dic/dic.worker.ts +25 -0
- package/src/components/dic/index.ts +5 -0
- package/src/components/grid/style/index.scss +15 -6
- package/src/components/index.scss +2 -0
- package/src/components/menu/Menu.jsx +2 -3
- package/src/components/select/Select.vue +11 -5
- package/src/components/select/{dic-worker.ts → dic.worker.ts} +4 -3
- package/src/components/table/Table.tsx +343 -0
- package/src/components/table/{Table.vue → TableBak.vue} +39 -27
- package/src/components/table/index.ts +1 -2
- package/src/components/table/interface/table.ts +54 -0
- package/src/components/table/style/index.scss +10 -0
- package/src/components/theme/variable.scss +1 -0
- package/src/hooks/http/index.ts +12 -14
- package/src/utils/html.ts +17 -0
- package/src/utils/index.ts +1 -0
- package/dist/cjs/components/select/dic-worker.cjs.js +0 -1
- package/dist/cjs/components/table/Field.vue.cjs.js +0 -1
- package/dist/cjs/components/table/Field.vue.cjs2.js +0 -1
- package/dist/cjs/components/table/Field.vue.d.ts +0 -28
- package/dist/cjs/components/table/Table.vue.cjs.js +0 -1
- package/dist/cjs/components/table/Table.vue.cjs2.js +0 -1
- package/dist/cjs/components/table/Table.vue.cjs3.js +0 -1
- package/dist/cjs/components/table/Table.vue.d.ts +0 -142
- package/dist/esm/components/select/dic-worker.esm.js +0 -12
- package/dist/esm/components/table/Field.vue.d.ts +0 -28
- package/dist/esm/components/table/Field.vue.esm.js +0 -38
- package/dist/esm/components/table/Field.vue.esm2.js +0 -4
- package/dist/esm/components/table/Table.vue.d.ts +0 -142
- package/dist/esm/components/table/Table.vue.esm.js +0 -238
- package/dist/esm/components/table/Table.vue.esm2.js +0 -4
- package/dist/esm/components/table/Table.vue.esm3.js +0 -5
- package/dist/esm/style.css +0 -1
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 脱敏
|
|
3
|
+
* @author 余春林
|
|
4
|
+
*/
|
|
5
|
+
import { defineComponent, computed, ref } from "vue";
|
|
6
|
+
import { EyeOutlined, EyeInvisibleOutlined } from "@ant-design/icons-vue";
|
|
7
|
+
import { prefixName } from "../theme";
|
|
8
|
+
|
|
9
|
+
//class名称
|
|
10
|
+
const baseClassName = `${prefixName}-desensitize`;
|
|
11
|
+
export default defineComponent({
|
|
12
|
+
name: "DDesensitize",
|
|
13
|
+
components: {
|
|
14
|
+
EyeOutlined,
|
|
15
|
+
EyeInvisibleOutlined
|
|
16
|
+
},
|
|
17
|
+
props: {
|
|
18
|
+
value: {
|
|
19
|
+
// type: [string,number] 可以使用PropType 来声明对象类型
|
|
20
|
+
// type: String as () => string | number,
|
|
21
|
+
type: String,
|
|
22
|
+
required: true
|
|
23
|
+
},
|
|
24
|
+
// 替换样式
|
|
25
|
+
style: {
|
|
26
|
+
type: String,
|
|
27
|
+
default: "*"
|
|
28
|
+
},
|
|
29
|
+
// 替换位置
|
|
30
|
+
rule: {
|
|
31
|
+
type: String,
|
|
32
|
+
required: true
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
setup(props) {
|
|
36
|
+
// 控制显示隐藏脱敏或者不脱敏
|
|
37
|
+
const invisible = ref(true);
|
|
38
|
+
const desensitizedString = computed(() => {
|
|
39
|
+
const value = props.value;
|
|
40
|
+
const rule = props.rule;
|
|
41
|
+
if (rule === "mobile") {
|
|
42
|
+
return value.replace(/(\d{3})\d{4}(\d{4})/, "$1 * * * * $2");
|
|
43
|
+
} else if (rule === "id") {
|
|
44
|
+
return value.replace(/(\d{4})\d{10}(\w{4})/, "$1 * * * * * $2");
|
|
45
|
+
} else {
|
|
46
|
+
return value;
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
return () => (
|
|
50
|
+
<>
|
|
51
|
+
<div class={baseClassName}>
|
|
52
|
+
<span class={"value"}>
|
|
53
|
+
{invisible.value ? desensitizedString.value : props.value}
|
|
54
|
+
</span>
|
|
55
|
+
<span>
|
|
56
|
+
<eye-outlined
|
|
57
|
+
onClick={() => (invisible.value = !invisible.value)}
|
|
58
|
+
v-show={!invisible.value}
|
|
59
|
+
/>
|
|
60
|
+
<eye-invisible-outlined
|
|
61
|
+
onClick={() => (invisible.value = !invisible.value)}
|
|
62
|
+
v-show={invisible.value}
|
|
63
|
+
/>
|
|
64
|
+
</span>
|
|
65
|
+
</div>
|
|
66
|
+
</>
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
});
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 字典替换
|
|
3
|
+
* 根据字典名字及对应的value替换成中文或者人能看懂的文字
|
|
4
|
+
* @author 余春林
|
|
5
|
+
*/
|
|
6
|
+
import { defineComponent, ref, watchEffect } from "vue";
|
|
7
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
8
|
+
// @ts-ignore
|
|
9
|
+
import DicWorker from "./dic.worker?worker&inline";
|
|
10
|
+
import { useDataDicStore } from "../../store/modules/DataDictionary";
|
|
11
|
+
|
|
12
|
+
export default defineComponent({
|
|
13
|
+
name: "DicReplace",
|
|
14
|
+
props: {
|
|
15
|
+
// 字典名称
|
|
16
|
+
name: {
|
|
17
|
+
type: String,
|
|
18
|
+
default: ""
|
|
19
|
+
},
|
|
20
|
+
// 值
|
|
21
|
+
value: {
|
|
22
|
+
type: String as any,
|
|
23
|
+
default: ""
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
setup(props) {
|
|
27
|
+
const { list } = useDataDicStore();
|
|
28
|
+
|
|
29
|
+
const workerStatus = ref(false);
|
|
30
|
+
const dicValueTxt = ref<any>("");
|
|
31
|
+
const worker = new DicWorker();
|
|
32
|
+
/**
|
|
33
|
+
* web worker 启动失败
|
|
34
|
+
*/
|
|
35
|
+
worker.onerror = () => {
|
|
36
|
+
workerStatus.value = false;
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* 监听web worker发送的数据
|
|
40
|
+
* @param e
|
|
41
|
+
*/
|
|
42
|
+
worker.onmessage = (e: any) => {
|
|
43
|
+
// 赋值给下拉选择数据变量
|
|
44
|
+
dicValueTxt.value = e.data;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
watchEffect(() => {
|
|
48
|
+
const value = props.value;
|
|
49
|
+
const name = props.name;
|
|
50
|
+
worker.postMessage({ list, name, value });
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
return <>{dicValueTxt.value}</>;
|
|
54
|
+
}
|
|
55
|
+
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 字典匹配worker
|
|
3
|
+
* 根据字典名称和value 替换对应的中文
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
self.addEventListener(
|
|
7
|
+
"message",
|
|
8
|
+
function (e) {
|
|
9
|
+
// 字典名字
|
|
10
|
+
const name = e.data.name ?? "";
|
|
11
|
+
// 字典值
|
|
12
|
+
const value = e.data.value ?? "";
|
|
13
|
+
// 字典列表
|
|
14
|
+
const parseData = JSON.parse(e.data.list) ?? [];
|
|
15
|
+
const rs = parseData[name] || [];
|
|
16
|
+
|
|
17
|
+
const str = rs
|
|
18
|
+
.filter((item: any) => item.value === value)
|
|
19
|
+
.map((item: any) => item.label)
|
|
20
|
+
.join("");
|
|
21
|
+
|
|
22
|
+
self.postMessage(str);
|
|
23
|
+
},
|
|
24
|
+
false
|
|
25
|
+
);
|
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
@import "../../theme/variable.scss";
|
|
2
2
|
|
|
3
|
+
/*输入框获取焦点时候的影响边框*/
|
|
4
|
+
@mixin input-focus {
|
|
5
|
+
&:focus {
|
|
6
|
+
box-shadow: 0 0 0 $grid-input-border-width $grid-input-focus-border-color;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
3
9
|
.#{$prefix-name}-grid {
|
|
4
10
|
position: relative;
|
|
5
11
|
display: grid;
|
|
@@ -20,13 +26,16 @@
|
|
|
20
26
|
border-right: $gird-border-width solid $grid-border-color;
|
|
21
27
|
}
|
|
22
28
|
.ant-input,
|
|
23
|
-
.ant-select-selector
|
|
29
|
+
.ant-select-selector,
|
|
30
|
+
.ant-input-number {
|
|
24
31
|
border: 0;
|
|
25
32
|
border-radius: 0;
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
33
|
+
@include input-focus;
|
|
34
|
+
// 数字输入框要单独处理
|
|
35
|
+
.ant-input-number-input {
|
|
36
|
+
border: 0;
|
|
37
|
+
border-radius: 0;
|
|
38
|
+
@include input-focus;
|
|
30
39
|
}
|
|
31
40
|
}
|
|
32
41
|
.ant-input[disabled] {
|
|
@@ -40,7 +49,7 @@
|
|
|
40
49
|
}
|
|
41
50
|
}
|
|
42
51
|
.ant-form-item-explain {
|
|
43
|
-
display:
|
|
52
|
+
display: $gird-error-display;
|
|
44
53
|
}
|
|
45
54
|
}
|
|
46
55
|
.ant-select-focused:not(.ant-select-disabled).ant-select:not(
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { defineComponent, h, inject, ref, resolveComponent } from "vue";
|
|
2
2
|
import { storeToRefs } from "pinia";
|
|
3
|
-
import { MenuOutlined } from "@ant-design/icons-vue";
|
|
4
3
|
|
|
5
4
|
import { useMenuStore } from "../../store/modules/Menu";
|
|
6
5
|
import { useSettingsStore } from "../../store/modules/Settings";
|
|
@@ -14,9 +13,9 @@ export default defineComponent({
|
|
|
14
13
|
|
|
15
14
|
const { getCollapsed } = storeToRefs(settingsStore);
|
|
16
15
|
// 当前展开的菜单
|
|
17
|
-
const openKeys = ref([
|
|
16
|
+
const openKeys = ref([]);
|
|
18
17
|
// 当前选中的菜单
|
|
19
|
-
const selectedKeys = ref([
|
|
18
|
+
const selectedKeys = ref([]);
|
|
20
19
|
|
|
21
20
|
/**
|
|
22
21
|
* 监听菜单点击事件
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
import { ref } from "vue";
|
|
3
3
|
import { useDataDicStore } from "../../store/modules/DataDictionary";
|
|
4
|
-
|
|
4
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
5
|
+
// @ts-ignore
|
|
6
|
+
import DicWorker from "./dic.worker?worker&inline";
|
|
5
7
|
|
|
6
8
|
interface Props {
|
|
7
9
|
value: any;
|
|
@@ -24,7 +26,7 @@ interface Emits {
|
|
|
24
26
|
const emits = defineEmits<Emits>();
|
|
25
27
|
const { getDicByKey, list } = useDataDicStore();
|
|
26
28
|
|
|
27
|
-
const { modelValue, data, onSearch, onSelect } = useSelect();
|
|
29
|
+
const { modelValue, data, onSearch, onSelect, onChange } = useSelect();
|
|
28
30
|
|
|
29
31
|
function useSelect() {
|
|
30
32
|
// 保存worker启动状态
|
|
@@ -43,7 +45,7 @@ function useSelect() {
|
|
|
43
45
|
// }
|
|
44
46
|
// );
|
|
45
47
|
// const worker = new Worker(
|
|
46
|
-
// new URL("./dic
|
|
48
|
+
// new URL("./dic.worker.ts?worker&inline", import.meta.url),
|
|
47
49
|
// {
|
|
48
50
|
// type: "module"
|
|
49
51
|
// }
|
|
@@ -95,14 +97,17 @@ function useSelect() {
|
|
|
95
97
|
const onSelect = (value: any) => {
|
|
96
98
|
// 发射选择的数据
|
|
97
99
|
emits("update:value", value);
|
|
98
|
-
emits("change", value);
|
|
99
100
|
};
|
|
100
101
|
|
|
102
|
+
const onChange = () => {
|
|
103
|
+
emits("change", modelValue.value);
|
|
104
|
+
};
|
|
101
105
|
return {
|
|
102
106
|
data,
|
|
103
107
|
modelValue,
|
|
104
108
|
onSearch,
|
|
105
|
-
onSelect
|
|
109
|
+
onSelect,
|
|
110
|
+
onChange
|
|
106
111
|
};
|
|
107
112
|
}
|
|
108
113
|
</script>
|
|
@@ -122,6 +127,7 @@ export default {
|
|
|
122
127
|
:disabled="disabled"
|
|
123
128
|
@select="onSelect"
|
|
124
129
|
@search="onSearch"
|
|
130
|
+
@change="onChange"
|
|
125
131
|
>
|
|
126
132
|
</a-select>
|
|
127
133
|
</template>
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* 字典匹配worker
|
|
3
|
+
* 根据 关键字 删选对应的字典列表内容
|
|
3
4
|
*/
|
|
4
5
|
|
|
5
6
|
self.addEventListener(
|
|
6
7
|
"message",
|
|
7
8
|
function (e) {
|
|
8
|
-
const keyword = e.data.keywords
|
|
9
|
-
const parseData = JSON.parse(e.data.list);
|
|
9
|
+
const keyword = e.data.keywords ?? "";
|
|
10
|
+
const parseData = JSON.parse(e.data.list) ?? [];
|
|
10
11
|
const filterRs = parseData.filter((item: any) => {
|
|
11
12
|
return (
|
|
12
13
|
item.value.toLowerCase().indexOf(keyword.toLowerCase()) !== -1 ||
|
|
@@ -0,0 +1,343 @@
|
|
|
1
|
+
import {
|
|
2
|
+
computed,
|
|
3
|
+
defineComponent,
|
|
4
|
+
defineEmits,
|
|
5
|
+
nextTick,
|
|
6
|
+
PropType,
|
|
7
|
+
ref,
|
|
8
|
+
watch,
|
|
9
|
+
watchEffect,
|
|
10
|
+
createSlots
|
|
11
|
+
} from "vue";
|
|
12
|
+
import { Pagination, Space, Table } from "ant-design-vue";
|
|
13
|
+
import { useEleHeight } from "../../utils";
|
|
14
|
+
import { prefixName } from "../theme";
|
|
15
|
+
|
|
16
|
+
import type { TableProps, Key } from "./interface/table";
|
|
17
|
+
/**
|
|
18
|
+
* 表格组件 基于TSX封装ATable
|
|
19
|
+
*/
|
|
20
|
+
const tableProps = () => {
|
|
21
|
+
return {
|
|
22
|
+
data: {
|
|
23
|
+
type: Object as PropType<TableProps["data"]>,
|
|
24
|
+
required: true
|
|
25
|
+
},
|
|
26
|
+
height: {
|
|
27
|
+
type: Number as PropType<TableProps["height"]>,
|
|
28
|
+
default: 300
|
|
29
|
+
},
|
|
30
|
+
keys: Array as PropType<TableProps["keys"]>,
|
|
31
|
+
rowKey: {
|
|
32
|
+
type: String as PropType<TableProps["rowKey"]>,
|
|
33
|
+
required: true,
|
|
34
|
+
default: "id"
|
|
35
|
+
},
|
|
36
|
+
loading: {
|
|
37
|
+
type: Boolean as PropType<TableProps["loading"]>,
|
|
38
|
+
default: false
|
|
39
|
+
},
|
|
40
|
+
pagination: {
|
|
41
|
+
type: Object as PropType<TableProps["pagination"]>,
|
|
42
|
+
default: () => ({})
|
|
43
|
+
},
|
|
44
|
+
config: {
|
|
45
|
+
type: Object as PropType<TableProps["config"]>,
|
|
46
|
+
default: () => ({})
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
// 使用有问题
|
|
52
|
+
// const tableEmits = defineEmits<{
|
|
53
|
+
// "update:keys": (keys: []) => void;
|
|
54
|
+
// }>();
|
|
55
|
+
// interface MyEvents {
|
|
56
|
+
// [key: string]: (...args: any[]) => void;
|
|
57
|
+
// "update:keys": (keys: []) => void;
|
|
58
|
+
// }
|
|
59
|
+
|
|
60
|
+
//分页默认配置
|
|
61
|
+
const paginationConfig = {
|
|
62
|
+
defaultPageSize: 20,
|
|
63
|
+
hideOnSinglePage: false,
|
|
64
|
+
pageSizeOptions: ["10", "20", "30", "40"],
|
|
65
|
+
responsive: true,
|
|
66
|
+
showQuickJumper: true,
|
|
67
|
+
showLessItems: true,
|
|
68
|
+
showTotal: (total: number) => {
|
|
69
|
+
return `总共 ${total} 条`;
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
//分页class名称
|
|
74
|
+
const basePageClassName = `${prefixName}-pagination`;
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* 表格组件定义
|
|
78
|
+
*/
|
|
79
|
+
const DXTable = defineComponent({
|
|
80
|
+
name: "DTable",
|
|
81
|
+
props: tableProps(),
|
|
82
|
+
// emits: { "update:keys": (keys: []) => void }
|
|
83
|
+
// TODO 需要做调整
|
|
84
|
+
emits: {
|
|
85
|
+
"update:keys": (keys: []) => null
|
|
86
|
+
},
|
|
87
|
+
setup(props, { emit, slots }) {
|
|
88
|
+
console.log(slots);
|
|
89
|
+
// 保存选中的唯一id
|
|
90
|
+
const selectedRowKeys = ref<any>(props.keys);
|
|
91
|
+
// 数据源
|
|
92
|
+
const dataSource = computed(() => props.data);
|
|
93
|
+
// 表格列
|
|
94
|
+
const columns = computed(() => props.config?.columns ?? []);
|
|
95
|
+
const paginationState = computed(
|
|
96
|
+
() => props.config?.pagination ?? ({} as any)
|
|
97
|
+
);
|
|
98
|
+
|
|
99
|
+
// 初始化表格
|
|
100
|
+
const { tableRef, tableHeight, onPageChange, onRowClassName } = useTable();
|
|
101
|
+
function useTable() {
|
|
102
|
+
const {
|
|
103
|
+
rowClassName,
|
|
104
|
+
keepSelected,
|
|
105
|
+
selection,
|
|
106
|
+
onPageChange: onChange
|
|
107
|
+
} = props.config;
|
|
108
|
+
// 表格组件对象
|
|
109
|
+
const tableRef = ref<any>(null);
|
|
110
|
+
// 表格计算出来的高度
|
|
111
|
+
const tableHeight = ref<number>();
|
|
112
|
+
// 表格body对象
|
|
113
|
+
const antTableBodyRef = ref<any>(null);
|
|
114
|
+
// 计算高度
|
|
115
|
+
const playHeight = (height: number) => {
|
|
116
|
+
const tableEl = tableRef?.value?.$el;
|
|
117
|
+
const headerHeight = useEleHeight(
|
|
118
|
+
tableEl.getElementsByClassName("ant-table-header")[0]
|
|
119
|
+
);
|
|
120
|
+
// 获取分页组件高度
|
|
121
|
+
let paginationHeight = 0;
|
|
122
|
+
if (props.config.pagination) {
|
|
123
|
+
paginationHeight = useEleHeight(
|
|
124
|
+
document.getElementsByClassName(basePageClassName)[0]
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
tableHeight.value = height - (headerHeight + paginationHeight);
|
|
128
|
+
// 设置body高度
|
|
129
|
+
tableEl.getElementsByClassName("ant-table-body")[0].style.height =
|
|
130
|
+
tableHeight.value - 10 + "px";
|
|
131
|
+
// 表格body对象 用于切换页码后滚动条置顶
|
|
132
|
+
antTableBodyRef.value =
|
|
133
|
+
tableEl.getElementsByClassName("ant-table-body")[0];
|
|
134
|
+
};
|
|
135
|
+
//监听传入的height的变化 默认组件创建的时候会执行一次
|
|
136
|
+
watchEffect(() => {
|
|
137
|
+
if (props.height !== 0) {
|
|
138
|
+
nextTick(() => {
|
|
139
|
+
// 必须在组件挂载成功后 执行计算高度 否则无法正确获取元素的高度
|
|
140
|
+
playHeight(props.height);
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
// 监听分页组件
|
|
145
|
+
const onPageChange = (page: number, size: number) => {
|
|
146
|
+
onChange ? onChange({ page, size }) : null;
|
|
147
|
+
// 切换分页的时候,表体滚动到顶部
|
|
148
|
+
antTableBodyRef.value.scrollTop = 0;
|
|
149
|
+
// 如果当前为单选或未开启分页保留数据选中的数据都会被清除
|
|
150
|
+
// 清空历史选中数据
|
|
151
|
+
if (selection === "S" || !keepSelected) {
|
|
152
|
+
selectedRowKeys.value = [];
|
|
153
|
+
emit("update:keys", selectedRowKeys.value);
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
//自定义样式
|
|
157
|
+
const onRowClassName = (record: any, index: number) => {
|
|
158
|
+
return rowClassName ? rowClassName(record, index) : undefined;
|
|
159
|
+
};
|
|
160
|
+
return { tableRef, tableHeight, onPageChange, onRowClassName };
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
//表格选中配置
|
|
164
|
+
const rowSelection = useRowSelection();
|
|
165
|
+
function useRowSelection() {
|
|
166
|
+
const {
|
|
167
|
+
rowKey,
|
|
168
|
+
config: { selection, getCheckboxProps }
|
|
169
|
+
} = props;
|
|
170
|
+
if (selection === "N") return undefined;
|
|
171
|
+
const onSelect = (record: any, selected: any) => {
|
|
172
|
+
if (selection === "S") {
|
|
173
|
+
selectedRowKeys.value = [];
|
|
174
|
+
selectedRowKeys.value = selected ? [record[rowKey]] : [];
|
|
175
|
+
} else {
|
|
176
|
+
selectedRowKeys.value = selected
|
|
177
|
+
? selectedRowKeys.value.concat(record[rowKey])
|
|
178
|
+
: selectedRowKeys.value.filter(
|
|
179
|
+
(key: Key) => key !== record[rowKey]
|
|
180
|
+
);
|
|
181
|
+
}
|
|
182
|
+
emit("update:keys", selectedRowKeys.value);
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
const onSelectAll = (
|
|
186
|
+
selected: any,
|
|
187
|
+
selectedRows: any,
|
|
188
|
+
changeRows: any
|
|
189
|
+
) => {
|
|
190
|
+
const _ids = changeRows.map((record: any) => record[rowKey]);
|
|
191
|
+
selectedRowKeys.value = selected
|
|
192
|
+
? selectedRowKeys.value.concat(_ids)
|
|
193
|
+
: selectedRowKeys.value.filter((key: Key) => !_ids.includes(key));
|
|
194
|
+
|
|
195
|
+
emit("update:keys", selectedRowKeys.value);
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
// 监听父组件手动改变keys 重新赋值给 表格选中变量selectedRowKeys
|
|
199
|
+
// 否则父组件 改变keys后当前selectedRowKeys还是原来的值
|
|
200
|
+
watch(
|
|
201
|
+
() => props.keys,
|
|
202
|
+
(val) => {
|
|
203
|
+
selectedRowKeys.value = val;
|
|
204
|
+
}
|
|
205
|
+
);
|
|
206
|
+
|
|
207
|
+
return {
|
|
208
|
+
selectedRowKeys,
|
|
209
|
+
onSelect,
|
|
210
|
+
onSelectAll,
|
|
211
|
+
fixed: true,
|
|
212
|
+
columnTitle: selection === "S" ? "选择" : null,
|
|
213
|
+
columnWidth: selection === "S" ? 60 : 40,
|
|
214
|
+
getCheckboxProps: getCheckboxProps
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
const customRow = useCustomRow();
|
|
219
|
+
//表格行配置
|
|
220
|
+
function useCustomRow() {
|
|
221
|
+
return (record: any) => {
|
|
222
|
+
// 用于存储 在某个事件内双击两次 则取消单击事件业务
|
|
223
|
+
let clickTimeout: any = undefined;
|
|
224
|
+
const {
|
|
225
|
+
rowKey,
|
|
226
|
+
config: { click, dbClick, selection, getCheckboxProps }
|
|
227
|
+
} = props;
|
|
228
|
+
const id = record[rowKey];
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* 处理单击事件业务
|
|
232
|
+
* @param record 当前点击行数据
|
|
233
|
+
*/
|
|
234
|
+
const onClick = () => {
|
|
235
|
+
if (selection === "N") {
|
|
236
|
+
// 1.未开启复选框 则不处理数据选中操作
|
|
237
|
+
// 2. 如果当前点击的行 包含在禁用的数据项目里面 则不进行选中操作
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
const haveState = selectedRowKeys.value.some(
|
|
241
|
+
(key: Key) => key === id
|
|
242
|
+
);
|
|
243
|
+
if (haveState) {
|
|
244
|
+
//如果 当前点击行的ID 已存在 那么直接过滤掉当前的id
|
|
245
|
+
selectedRowKeys.value = selectedRowKeys.value.filter(
|
|
246
|
+
(key: Key) => key !== id
|
|
247
|
+
);
|
|
248
|
+
} else {
|
|
249
|
+
if (selection === "S") {
|
|
250
|
+
//单选的时候 清空选中的数据 再赋值新的ID
|
|
251
|
+
selectedRowKeys.value = [];
|
|
252
|
+
selectedRowKeys.value.push(id);
|
|
253
|
+
} else {
|
|
254
|
+
//多选直接追加ID
|
|
255
|
+
selectedRowKeys.value.push(id);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
emit("update:keys", selectedRowKeys.value);
|
|
259
|
+
};
|
|
260
|
+
|
|
261
|
+
return {
|
|
262
|
+
onClick: () => {
|
|
263
|
+
if (!click) return;
|
|
264
|
+
const rs = getCheckboxProps ? getCheckboxProps(record) : null;
|
|
265
|
+
if (rs && rs.value === id) {
|
|
266
|
+
return;
|
|
267
|
+
}
|
|
268
|
+
clearTimeout(clickTimeout);
|
|
269
|
+
clickTimeout = setTimeout(() => {
|
|
270
|
+
// 处理单击事件业务
|
|
271
|
+
onClick();
|
|
272
|
+
// 回传数据 自定义单击后的业务
|
|
273
|
+
click(record);
|
|
274
|
+
}, 200);
|
|
275
|
+
}, // 点击行
|
|
276
|
+
onDblclick: () => {
|
|
277
|
+
if (!dbClick) return;
|
|
278
|
+
clearTimeout(clickTimeout);
|
|
279
|
+
// 回传数据 自定义单击后的业务
|
|
280
|
+
dbClick(record);
|
|
281
|
+
}
|
|
282
|
+
// onContextmenu: (event) => {
|
|
283
|
+
// //TODO
|
|
284
|
+
// },
|
|
285
|
+
// onMouseenter: (event) => {
|
|
286
|
+
// //TODO
|
|
287
|
+
// }, // 鼠标移入行
|
|
288
|
+
// onMouseleave: (event) => {
|
|
289
|
+
// //TODO
|
|
290
|
+
// }
|
|
291
|
+
};
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
return () => (
|
|
295
|
+
<>
|
|
296
|
+
<Table
|
|
297
|
+
ref={tableRef}
|
|
298
|
+
row-key={props.rowKey}
|
|
299
|
+
bordered={props.config.bordered}
|
|
300
|
+
columns={columns.value}
|
|
301
|
+
dataSource={dataSource.value}
|
|
302
|
+
loading={props.loading}
|
|
303
|
+
size={props.config?.size ?? "small"}
|
|
304
|
+
scroll={{
|
|
305
|
+
scrollToFirstRowOnChange: true,
|
|
306
|
+
x: "100%",
|
|
307
|
+
y: tableHeight.value + "px"
|
|
308
|
+
}}
|
|
309
|
+
pagination={false}
|
|
310
|
+
customRow={customRow}
|
|
311
|
+
rowSelection={rowSelection}
|
|
312
|
+
rowClassName={onRowClassName}
|
|
313
|
+
>
|
|
314
|
+
{{
|
|
315
|
+
bodyCell: ({ column }: any) => {
|
|
316
|
+
if (column.slot === "action") {
|
|
317
|
+
return <Space>{slots.action && slots.action()}</Space>;
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
}}
|
|
321
|
+
</Table>
|
|
322
|
+
<Pagination
|
|
323
|
+
v-show={paginationState.value}
|
|
324
|
+
class={[basePageClassName]}
|
|
325
|
+
v-model:current={paginationState.value.current}
|
|
326
|
+
v-model:pageSize={paginationState.value.pageSize}
|
|
327
|
+
disabled={props.loading}
|
|
328
|
+
show-size-changer
|
|
329
|
+
size={"default"}
|
|
330
|
+
hide-on-single-page={paginationConfig.hideOnSinglePage}
|
|
331
|
+
show-quick-jumper={paginationConfig.showQuickJumper}
|
|
332
|
+
default-page-size={paginationConfig.defaultPageSize}
|
|
333
|
+
page-size-options={paginationConfig.pageSizeOptions}
|
|
334
|
+
show-total={paginationConfig.showTotal}
|
|
335
|
+
total={paginationState.value.total}
|
|
336
|
+
onChange={onPageChange}
|
|
337
|
+
/>
|
|
338
|
+
</>
|
|
339
|
+
);
|
|
340
|
+
}
|
|
341
|
+
});
|
|
342
|
+
|
|
343
|
+
export default DXTable;
|