@lx-frontend/wrap-element-ui 1.0.1-beta.4 → 1.0.1-beta.6

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,51 +1,44 @@
1
- import { ref, nextTick } from "vue"
2
- import { IColorList, IEmits } from "./types"
3
-
4
- interface IUseRowBgColorParams {
5
- colorList: IColorList;
6
- emit: IEmits;
7
- }
8
-
9
- export default function useRowBgColor({ colorList, emit }: IUseRowBgColorParams) {
10
- const colorPopoverRef = ref<any>(null);
11
-
12
- const isDefaultColor = (id: number) => {
13
- if (!id) {
14
- // 没有颜色id,则认为是默认色
15
- return true;
16
- }
17
- return colorList.find(c => +c.id === +id)?.default;
18
- }
19
-
20
- const getColorById = (id: number, type: 'bg' | 'sample' = 'bg') => {
21
- return colorList.find(c => +c.id === +id)?.[`${type}Color`] || '';
22
- }
23
-
24
- const setRowStyle = (scope) => {
25
- const row = scope.row;
26
- return {
27
- backgroundColor: row.colorId ? getColorById(row.colorId) : ''
28
- }
29
- }
30
-
31
- const handleColorChange = async (colorId: number, scope) => {
32
- const { row, $index: rowIndex, store } = scope;
33
- const dataList = store.states.data;
34
- const curRow = { ...dataList[rowIndex], colorId: +colorId };
35
- const newList = [...dataList];
36
- newList.splice(rowIndex, 1, curRow);
37
- store.states.data = newList;
38
- emit('row-bg-change', { colorId, row, rowIndex });
39
- await nextTick();
40
- // TODO: 为什么不是数组?为什么关闭弹窗不生效了?
41
- colorPopoverRef.value?.doClose();
42
- }
43
-
44
- return {
45
- isDefaultColor,
46
- getColorById,
47
- setRowStyle,
48
- handleColorChange,
49
- colorPopoverRef
50
- }
1
+ import { IColorList, IEmits } from "./types"
2
+
3
+ interface IUseRowBgColorParams {
4
+ colorList: IColorList;
5
+ emit: IEmits;
6
+ }
7
+
8
+ export default function useRowBgColor({ colorList, emit }: IUseRowBgColorParams) {
9
+ const isDefaultColor = (id: number) => {
10
+ if (!id) {
11
+ // 没有颜色id,则认为是默认色
12
+ return true;
13
+ }
14
+ return colorList.find(c => +c.id === +id)?.default;
15
+ }
16
+
17
+ const getColorById = (id: number, type: 'bg' | 'sample' = 'bg') => {
18
+ return colorList.find(c => +c.id === +id)?.[`${type}Color`] || '';
19
+ }
20
+
21
+ const setRowStyle = (scope) => {
22
+ const row = scope.row;
23
+ return {
24
+ backgroundColor: row.colorId ? getColorById(row.colorId) : ''
25
+ }
26
+ }
27
+
28
+ const handleColorChange = async (colorId: number, scope) => {
29
+ const { row, $index: rowIndex, store } = scope;
30
+ const dataList = store.states.data;
31
+ const curRow = { ...dataList[rowIndex], colorId: +colorId };
32
+ const newList = [...dataList];
33
+ newList.splice(rowIndex, 1, curRow);
34
+ store.states.data = newList;
35
+ emit('row-bg-change', { colorId, row, rowIndex });
36
+ }
37
+
38
+ return {
39
+ isDefaultColor,
40
+ getColorById,
41
+ setRowStyle,
42
+ handleColorChange,
43
+ }
51
44
  }
@@ -1,119 +1,119 @@
1
- import { ref, nextTick, watch, ComputedRef, Ref, onMounted, computed } from "vue"
2
- import { IColumnConfig, IProps } from "./types"
3
-
4
- interface IViewSettingParams {
5
- tableDomRef: any
6
- showingColumns: Ref<string[]>
7
- actualColumns: ComputedRef<IColumnConfig[]>
8
- props: IProps
9
- }
10
-
11
- export default function useViewSetting({ tableDomRef, showingColumns, actualColumns, props }: IViewSettingParams) {
12
- const viewSettingDragSortOptions = ref<IColumnConfig[]>([]);
13
- const columnsToBeShown = ref<string[]>([]); // 显示设置弹窗中勾选的列
14
- const viewSettingVisible = ref(false);
15
- const leftFixedColumnCount = ref(0);
16
- const tempLeftFixedColumnCount = ref(0);
17
-
18
- const storageKey = computed(() => `@lx-frontend/wrap-element-ui/table_setting_cloumns/${props.settingStorgeKey || (location.pathname === '/' ? location.hash : location.pathname)}`);
19
-
20
- const saveSettingToStorge = () => localStorage.setItem(storageKey.value, JSON.stringify({
21
- showingColumns: showingColumns.value,
22
- leftFixedColumnCount: leftFixedColumnCount.value
23
- }));
24
-
25
- watch(
26
- () => props.columnConfig,
27
- (val) => {
28
- const _keys = new Set(props.columnConfig.map(c => (c.prop)));
29
- const _cache = localStorage.getItem(storageKey.value);
30
- const setColumns = () => (showingColumns.value = val.filter(v => !v.defaultHide).map(c => c.prop));
31
- if (!_cache) {
32
- setColumns();
33
- leftFixedColumnCount.value = props.leftFixedCount as number;
34
- } else {
35
- try {
36
- // 缓存数据字段可能随着更新导致对不上,清理无效数据,防止出问题
37
- const cache = JSON.parse(_cache);
38
- if (!cache.showingColumns || !Array.isArray(cache.showingColumns)) {
39
- setColumns();
40
- } else {
41
- showingColumns.value = cache.showingColumns.filter(key => _keys.has(key));
42
- }
43
- const _leftFixedColumnCount = Number(cache?.leftFixedColumnCount)
44
- leftFixedColumnCount.value = isNaN(_leftFixedColumnCount) ? (props.leftFixedCount as number) : _leftFixedColumnCount;
45
- // 写入清理后的数据
46
- saveSettingToStorge();
47
- } catch (error) {
48
- console.error(error);
49
- localStorage.removeItem(storageKey.value);
50
- setColumns();
51
- }
52
- }
53
- },
54
- { immediate: true }
55
- )
56
-
57
- watch(
58
- () => columnsToBeShown.value,
59
- (val) => {
60
- viewSettingDragSortOptions.value = props.columnConfig
61
- .filter(c => val.includes(c.prop));
62
- if (tempLeftFixedColumnCount.value > val.length) tempLeftFixedColumnCount.value = val.length
63
- },
64
- { immediate: true }
65
- )
66
-
67
- watch(
68
- () => showingColumns.value,
69
- (val) => {
70
- // 只要正在显示的列发生变化,dialog中的显示项也要同步变化,反之不然
71
- columnsToBeShown.value = [...val];
72
- },
73
- { immediate: true }
74
- )
75
-
76
- onMounted(() => {
77
- leftFixedColumnCount.value = props.leftFixedCount as number;
78
- })
79
-
80
- const handleViewSettingShow = () => {
81
- viewSettingDragSortOptions.value = actualColumns.value
82
- .filter(c => columnsToBeShown.value.includes(c.prop));
83
- tempLeftFixedColumnCount.value = leftFixedColumnCount.value;
84
- viewSettingVisible.value = true;
85
- }
86
-
87
- const handleViewSettingClose = () => {
88
- viewSettingVisible.value = false;
89
- // 恢复显示的列
90
- showingColumns.value = actualColumns.value.map(c => c.prop);
91
- }
92
-
93
- const handleViewSettingConfirm = async () => {
94
- viewSettingVisible.value = false;
95
- showingColumns.value = viewSettingDragSortOptions.value.map(c => c.prop);
96
- leftFixedColumnCount.value = tempLeftFixedColumnCount.value;
97
- saveSettingToStorge()
98
- await nextTick();
99
- tableDomRef.value?.doLayout();
100
- }
101
-
102
- const handleInputTempLeftFixedColumnCount = (value: string) => {
103
- const _value = Number(value)
104
- if (isNaN(_value)) return
105
- tempLeftFixedColumnCount.value = Math.max(0, Math.min(columnsToBeShown.value.length, Math.floor(_value)))
106
- }
107
-
108
- return {
109
- viewSettingDragSortOptions,
110
- columnsToBeShown,
111
- viewSettingVisible,
112
- leftFixedColumnCount,
113
- tempLeftFixedColumnCount,
114
- handleInputTempLeftFixedColumnCount,
115
- handleViewSettingShow,
116
- handleViewSettingClose,
117
- handleViewSettingConfirm
118
- }
119
- }
1
+ import { ref, nextTick, watch, ComputedRef, Ref, onMounted, computed } from "vue"
2
+ import { IColumnConfig, IProps } from "./types"
3
+
4
+ interface IViewSettingParams {
5
+ tableDomRef: any
6
+ showingColumns: Ref<string[]>
7
+ actualColumns: ComputedRef<IColumnConfig[]>
8
+ props: IProps
9
+ }
10
+
11
+ export default function useViewSetting({ tableDomRef, showingColumns, actualColumns, props }: IViewSettingParams) {
12
+ const viewSettingDragSortOptions = ref<IColumnConfig[]>([]);
13
+ const columnsToBeShown = ref<string[]>([]); // 显示设置弹窗中勾选的列
14
+ const viewSettingVisible = ref(false);
15
+ const leftFixedColumnCount = ref(0);
16
+ const tempLeftFixedColumnCount = ref(0);
17
+
18
+ const storageKey = computed(() => `@lx-frontend/wrap-element-ui/table_setting_cloumns/${props.settingStorgeKey || (location.pathname === '/' ? location.hash : location.pathname)}`);
19
+
20
+ const saveSettingToStorge = () => localStorage.setItem(storageKey.value, JSON.stringify({
21
+ showingColumns: showingColumns.value,
22
+ leftFixedColumnCount: leftFixedColumnCount.value
23
+ }));
24
+
25
+ watch(
26
+ () => props.columnConfig,
27
+ (val) => {
28
+ const _keys = new Set(props.columnConfig.map(c => (c.prop)));
29
+ const _cache = localStorage.getItem(storageKey.value);
30
+ const setColumns = () => (showingColumns.value = val.filter(v => !v.defaultHide).map(c => c.prop));
31
+ if (!_cache) {
32
+ setColumns();
33
+ leftFixedColumnCount.value = props.leftFixedCount as number;
34
+ } else {
35
+ try {
36
+ // 缓存数据字段可能随着更新导致对不上,清理无效数据,防止出问题
37
+ const cache = JSON.parse(_cache);
38
+ if (!cache.showingColumns || !Array.isArray(cache.showingColumns)) {
39
+ setColumns();
40
+ } else {
41
+ showingColumns.value = cache.showingColumns.filter(key => _keys.has(key));
42
+ }
43
+ const _leftFixedColumnCount = Number(cache?.leftFixedColumnCount)
44
+ leftFixedColumnCount.value = isNaN(_leftFixedColumnCount) ? (props.leftFixedCount as number) : _leftFixedColumnCount;
45
+ // 写入清理后的数据
46
+ saveSettingToStorge();
47
+ } catch (error) {
48
+ console.error(error);
49
+ localStorage.removeItem(storageKey.value);
50
+ setColumns();
51
+ }
52
+ }
53
+ },
54
+ { immediate: true }
55
+ )
56
+
57
+ watch(
58
+ () => columnsToBeShown.value,
59
+ (val) => {
60
+ viewSettingDragSortOptions.value = props.columnConfig
61
+ .filter(c => val.includes(c.prop));
62
+ if (tempLeftFixedColumnCount.value > val.length) tempLeftFixedColumnCount.value = val.length
63
+ },
64
+ { immediate: true }
65
+ )
66
+
67
+ watch(
68
+ () => showingColumns.value,
69
+ (val) => {
70
+ // 只要正在显示的列发生变化,dialog中的显示项也要同步变化,反之不然
71
+ columnsToBeShown.value = [...val];
72
+ },
73
+ { immediate: true }
74
+ )
75
+
76
+ onMounted(() => {
77
+ leftFixedColumnCount.value = props.leftFixedCount as number;
78
+ })
79
+
80
+ const handleViewSettingShow = () => {
81
+ viewSettingDragSortOptions.value = actualColumns.value
82
+ .filter(c => columnsToBeShown.value.includes(c.prop));
83
+ tempLeftFixedColumnCount.value = leftFixedColumnCount.value;
84
+ viewSettingVisible.value = true;
85
+ }
86
+
87
+ const handleViewSettingClose = () => {
88
+ viewSettingVisible.value = false;
89
+ // 恢复显示的列
90
+ showingColumns.value = actualColumns.value.map(c => c.prop);
91
+ }
92
+
93
+ const handleViewSettingConfirm = async () => {
94
+ viewSettingVisible.value = false;
95
+ showingColumns.value = viewSettingDragSortOptions.value.map(c => c.prop);
96
+ leftFixedColumnCount.value = tempLeftFixedColumnCount.value;
97
+ saveSettingToStorge()
98
+ await nextTick();
99
+ tableDomRef.value?.doLayout();
100
+ }
101
+
102
+ const handleInputTempLeftFixedColumnCount = (value: string) => {
103
+ const _value = Number(value)
104
+ if (isNaN(_value)) return
105
+ tempLeftFixedColumnCount.value = Math.max(0, Math.min(columnsToBeShown.value.length, Math.floor(_value)))
106
+ }
107
+
108
+ return {
109
+ viewSettingDragSortOptions,
110
+ columnsToBeShown,
111
+ viewSettingVisible,
112
+ leftFixedColumnCount,
113
+ tempLeftFixedColumnCount,
114
+ handleInputTempLeftFixedColumnCount,
115
+ handleViewSettingShow,
116
+ handleViewSettingClose,
117
+ handleViewSettingConfirm
118
+ }
119
+ }
@@ -0,0 +1,65 @@
1
+ <template>
2
+ <div>
3
+ <el-popover
4
+ v-model="visible"
5
+ placement="right"
6
+ trigger="click"
7
+ popper-class="color-popover"
8
+ >
9
+ <div class="color-list">
10
+ <div
11
+ v-for="color in colorList"
12
+ :key="color.id"
13
+ class="color-list__item"
14
+ :style="{ backgroundColor: color.sampleColor }"
15
+ @click="() => {
16
+
17
+ visible = false
18
+ handleColorChange(color.id, scope)
19
+ }"
20
+ >
21
+ <span :style="{color: color.textColor}">{{ color.name }}</span>
22
+ </div>
23
+ </div>
24
+
25
+ <div slot="reference">
26
+ <div
27
+ v-if="isDefaultColor(scope.row.colorId)"
28
+ class="editable-table__color-icon"
29
+ />
30
+ <div
31
+ v-else
32
+ class="editable-table__selected-color"
33
+ :style="{ backgroundColor: getColorById(scope.row.colorId, 'sample') }"
34
+ />
35
+ </div>
36
+ </el-popover>
37
+ </div>
38
+ </template>
39
+
40
+ <script setup lang="ts">
41
+ import { ref } from 'vue';
42
+ import { IColorList, IEmits, ITableDataItem } from './types';
43
+ import useRowBgColor from './useRowBgColor';
44
+
45
+ const props = defineProps<{
46
+ colorList: IColorList,
47
+ scope: any
48
+ }>();
49
+
50
+ const emit = defineEmits<{
51
+ (e: 'row-bg-change', param: { colorId: number; row: ITableDataItem; rowIndex: number }): void
52
+ }>();
53
+
54
+ const {
55
+ getColorById,
56
+ isDefaultColor,
57
+ handleColorChange,
58
+ } = useRowBgColor({
59
+ colorList: props.colorList,
60
+ emit: emit as IEmits,
61
+ });
62
+
63
+ const visible = ref(false);
64
+
65
+ </script>