@neatui/vue 2.7.2 → 2.7.3

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,155 +0,0 @@
1
- <template>
2
- <div v-if="isArray(node.child)" :class="wrap" v-bind="node.model[1]" v-on="event(node, data)">
3
- <TableColView v-for="(sub, idx) in node.child" :key="idx" :col="sub" :data="data" />
4
- </div>
5
- <IFollowView v-else-if="node.popup" v-bind="node.popup.attrs">
6
- <TableColView :col="{ ...node, popup: null }" :data="data" />
7
- <template #tips>
8
- <div class="nx-ms ny-sl">
9
- <TableColView :col="node.popup" :data="data" />
10
- </div>
11
- <div ui-tips-arrow=""></div>
12
- </template>
13
- </IFollowView>
14
- <img v-else-if="node.model[0] === 'Image' && value" :class="wrap" v-on="event(node, data)" :src="value" v-bind="node.model[1]" />
15
- <el-input v-else-if="node.model[0] === 'Input'" :class="wrap" v-on="event(node, data)" v-model="value" v-bind="node.model[1]" size="mini" />
16
- <div v-else :class="wrap" v-bind="node.attrs" v-on="event(node, data)" v-html="value"></div>
17
- </template>
18
-
19
- <script setup lang="ts">
20
- import { computed } from 'vue';
21
- import { isFunction, isArray, isObject, deepcopy } from '@fekit/utils';
22
- import TableColView from './TableColView@v3.vue';
23
- import IFollowView from '../IFollowView/IFollowView.vue';
24
-
25
- // 定义接口
26
- interface ColType {
27
- field?: string | Function;
28
- model?: any[] | Function;
29
- enums?: any[] | Function;
30
- popup?: any | Function;
31
- attrs?: any;
32
- event?: any;
33
- value?: any | Function;
34
- child?: any[];
35
- [key: string]: any;
36
- }
37
-
38
- interface DataType {
39
- [key: string]: any;
40
- }
41
-
42
- // Props定义
43
- interface Props {
44
- col: ColType;
45
- data: DataType;
46
- }
47
-
48
- const props = withDefaults(defineProps<Props>(), {
49
- col: () => ({}),
50
- data: () => ({})
51
- });
52
-
53
- // Emits定义
54
- const emit = defineEmits<{
55
- 'update:modelValue': [value: any];
56
- }>();
57
-
58
- // 计算属性
59
- const node = computed(() => {
60
- const _node = deepcopy(props.col);
61
-
62
- // 字段
63
- if (isFunction(_node.field)) {
64
- _node.field = (_node.field as Function)(props.data);
65
- }
66
- if (!_node.field) {
67
- _node.field = '';
68
- }
69
-
70
- // 模型
71
- if (isFunction(_node.model)) {
72
- _node.model = (_node.model as Function)(props.data);
73
- }
74
- if (!_node.model) {
75
- _node.model = ['Text', {}];
76
- }
77
-
78
- // 枚举
79
- if (isFunction(_node.enums)) {
80
- _node.enums = (_node.enums as Function)(props.data);
81
- }
82
-
83
- // 提示
84
- if (_node.popup) {
85
- if (isFunction(_node.popup)) {
86
- _node.popup = (_node.popup as Function)(props.data);
87
- }
88
- }
89
-
90
- return _node;
91
- });
92
-
93
- const wrap = computed(() => {
94
- return (node.value?.attrs?.class?.includes('wrap') ? node.value?.attrs?.class : (node.value?.attrs?.class || '') + ' nowrap').trim();
95
- });
96
-
97
- const value = computed({
98
- get() {
99
- let _value = node.value.value;
100
- if (isFunction(_value)) {
101
- _value = (_value as Function)(props.data, props.data[node.value.field], node.value);
102
- } else {
103
- _value = props.data[node.value.field];
104
- }
105
- if (node.value.enums) {
106
- _value = findEnumName(node.value.enums, _value);
107
- }
108
- if (node.value.model[0] === 'Text' && (_value === null || _value === undefined)) {
109
- _value = '‐‐';
110
- }
111
- return _value;
112
- },
113
- set(newValue: any) {
114
- const _value = node.value.value;
115
- if (isFunction(_value)) {
116
- props.data[node.value.field] = (_value as Function)(props.data, newValue, node.value);
117
- } else {
118
- props.data[node.value.field] = newValue;
119
- }
120
- }
121
- });
122
-
123
- // 方法
124
- const findEnumName = (enums: any[], val: any, join = ' Ι ') => {
125
- const _core = (v: any) => {
126
- const { label = v } = enums.find(({ value = '' }) => value == v) || {};
127
- return label;
128
- };
129
- if (enums && enums.find) {
130
- if (isArray(val)) {
131
- const arr = val.map((i: any) => _core(i));
132
- return join ? arr.join(join) : arr;
133
- } else {
134
- return _core(val);
135
- }
136
- } else {
137
- return val;
138
- }
139
- };
140
-
141
- const event = (col: ColType, data: DataType) => {
142
- const _event: Record<string, Function> = {};
143
- if (isObject(col.event)) {
144
- for (const key in col.event) {
145
- const fun = col.event[key];
146
- if (isFunction(fun)) {
147
- _event[key] = (...args: any[]) => {
148
- return (fun as Function)({ data }, ...args);
149
- };
150
- }
151
- }
152
- }
153
- return { ..._event };
154
- };
155
- </script>