vue-element-ui-x 0.1.7-beta → 0.1.9-beta

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,293 +1,293 @@
1
- <template>
2
- <div class="el-x-thoughtchain">
3
- <el-timeline
4
- ref="timelineRef"
5
- :style="{
6
- maxWidth: maxWidth,
7
- }"
8
- >
9
- <transition-group
10
- name="thought-chain"
11
- tag="div"
12
- >
13
- <el-timeline-item
14
- v-for="item in thinkingItems"
15
- :key="getId(item)"
16
- :type="getType(item)"
17
- :icon="dotIsIcon ? item.icon : 'el-icon-more'"
18
- :color="dotIsIcon ? item.iconColor : null"
19
- :size="dotIsIcon ? item.iconSize : 'normal'"
20
- :timestamp="getTitle(item)"
21
- :hide-timestamp="item.hideTitle"
22
- :placement="item.placement || 'top'"
23
- >
24
- <div v-if="!item.isCanExpand">
25
- <el-x-typewriter
26
- :content="getThinkTitle(item)"
27
- :is-markdown="item.isMarkdown"
28
- :typing="item.typing"
29
- />
30
- </div>
31
- <el-collapse
32
- v-else-if="!item.isDefaultExpand"
33
- @change="() => handleExpand(item)"
34
- >
35
- <el-collapse-item :title="getThinkTitle(item)">
36
- <el-x-typewriter
37
- :content="getThinkContent(item)"
38
- :is-markdown="item.isMarkdown"
39
- :typing="item.typing"
40
- />
41
- </el-collapse-item>
42
- </el-collapse>
43
- <el-collapse
44
- v-else
45
- v-model="defaultActiveNodes"
46
- @change="() => handleExpand(item)"
47
- >
48
- <el-collapse-item
49
- :title="getThinkTitle(item)"
50
- :name="String(getId(item))"
51
- >
52
- <el-x-typewriter
53
- :content="getThinkContent(item)"
54
- :is-markdown="item.isMarkdown"
55
- :typing="item.typing"
56
- />
57
- </el-collapse-item>
58
- </el-collapse>
59
-
60
- <template
61
- v-if="!dotIsIcon"
62
- slot="dot"
63
- >
64
- <div
65
- class="el-x-thoughtchain-item-dot"
66
- :style="{ margin: dotMargin }"
67
- >
68
- <slot
69
- name="icon"
70
- :item="item"
71
- >
72
- <el-button
73
- circle
74
- :type="getType(item)"
75
- :loading="isLoading(item)"
76
- :size="dotSize"
77
- >
78
- <template slot="loading">
79
- <i class="el-icon-loading el-x-thoughtchain-loading"></i>
80
- </template>
81
-
82
- <i
83
- v-if="!isLoading(item) && !isError(item)"
84
- class="el-icon-check"
85
- ></i>
86
- <i
87
- v-if="!isLoading(item) && isError(item)"
88
- class="el-icon-close"
89
- ></i>
90
- </el-button>
91
- </slot>
92
- </div>
93
- </template>
94
- </el-timeline-item>
95
- </transition-group>
96
- </el-timeline>
97
- </div>
98
- </template>
99
-
100
- <script>
101
- import { get } from 'lodash';
102
- import ElXTypewriter from '../../Typewriter/index.js';
103
- export default {
104
- name: 'ElXThoughtChain',
105
- components: {
106
- ElXTypewriter,
107
- },
108
- props: {
109
- thinkingItems: {
110
- type: Array,
111
- default: () => [],
112
- },
113
- dotIsIcon: {
114
- type: Boolean,
115
- default: false,
116
- },
117
- dotSize: {
118
- type: String,
119
- default: 'small',
120
- },
121
- maxWidth: {
122
- type: String,
123
- default: '600px',
124
- },
125
- lineGradient: {
126
- type: Boolean,
127
- default: false,
128
- },
129
- rowKey: {
130
- type: String,
131
- default: 'id',
132
- },
133
- statusKey: {
134
- type: String,
135
- default: 'status',
136
- },
137
- statusEnum: {
138
- type: Object,
139
- default: () => ({
140
- loading: {
141
- value: 'loading',
142
- type: 'warning',
143
- },
144
- error: {
145
- value: 'error',
146
- type: 'danger',
147
- },
148
- success: {
149
- value: 'success',
150
- type: 'success',
151
- },
152
- }),
153
- },
154
- titleKey: {
155
- type: String,
156
- default: 'title',
157
- },
158
- thinkTitleKey: {
159
- type: String,
160
- default: 'thinkTitle',
161
- },
162
- thinkContentKey: {
163
- type: String,
164
- default: 'thinkContent',
165
- },
166
- },
167
- data() {
168
- return {
169
- colorArr: {
170
- // 使用与SCSS变量对应的字符串表示
171
- info: 'var(--color-info, #909399)',
172
- success: 'var(--color-success, #67C23A)',
173
- warning: 'var(--color-warning, #E6A23C)',
174
- danger: 'var(--color-danger, #F56C6C)',
175
- primary: 'var(--color-primary, #409EFF)',
176
- },
177
- defaultActiveNodes: [],
178
- };
179
- },
180
- computed: {
181
- dotMargin() {
182
- switch (this.dotSize) {
183
- case 'mini':
184
- return '-8px 0 0 -9px';
185
- case 'small':
186
- return '-8px 0 0 -11px';
187
- case 'medium':
188
- return '-8px 0 0 -13px';
189
- default:
190
- return '-8px 0 0 -16px';
191
- }
192
- },
193
- getLineColor() {
194
- if (this.thinkingItems.length) {
195
- const arr = this.thinkingItems.map(item => {
196
- const _type_ = this.getType(item);
197
- if (_type_) {
198
- return this.colorArr[_type_];
199
- }
200
- return '';
201
- });
202
- return arr;
203
- }
204
- return [];
205
- },
206
- activeNamesComputed() {
207
- return this.thinkingItems
208
- .filter(item => item.isCanExpand && item.isDefaultExpand)
209
- .map(item => String(this.getId(item)));
210
- },
211
- },
212
- watch: {
213
- activeNamesComputed: {
214
- handler(v) {
215
- this.defaultActiveNodes = [...v];
216
- },
217
- immediate: true,
218
- },
219
- getLineColor() {
220
- this.$nextTick(() => {
221
- this.getEle();
222
- });
223
- },
224
- },
225
- mounted() {
226
- this.$nextTick(() => {
227
- this.getEle();
228
- });
229
- },
230
- methods: {
231
- handleExpand(item) {
232
- this.$emit('handleExpand', item);
233
- },
234
- setRadialGradient(colors, ele) {
235
- const length = ele.length;
236
- Array.from(ele).forEach((item, index) => {
237
- const line = item.children[0];
238
- if (line) {
239
- line.setAttribute(
240
- 'style',
241
- `
242
- border: none;
243
- width:2px;
244
- background: linear-gradient(to bottom, ${colors[index]} 0% , ${
245
- colors[index < length ? index + 1 : index]
246
- } 100%);
247
- `,
248
- );
249
- }
250
- });
251
- },
252
- getEle() {
253
- if (this.getLineColor && this.$refs.timelineRef && this.lineGradient) {
254
- const ele = this.$refs.timelineRef.$el.children[0].children;
255
- this.setRadialGradient(this.getLineColor, ele);
256
- }
257
- },
258
- isLoading(item) {
259
- const status = this.getStatus(item);
260
- return status === this.statusEnum.loading.value;
261
- },
262
- isError(item) {
263
- const status = this.getStatus(item);
264
- return status === this.statusEnum.error.value;
265
- },
266
- getId(item) {
267
- return get(item, this.rowKey);
268
- },
269
- getType(item) {
270
- const status = this.getStatus(item);
271
- // 优先查找statusEnum中value匹配的项
272
- const matchedStatus = Object.values(this.statusEnum).find(s => s.value === status);
273
- return matchedStatus ? matchedStatus.type : 'success';
274
- },
275
-
276
- getTitle(item) {
277
- return get(item, this.titleKey) || '';
278
- },
279
- getThinkTitle(item) {
280
- return get(item, this.thinkTitleKey) || '';
281
- },
282
- getThinkContent(item) {
283
- return get(item, this.thinkContentKey) || '';
284
- },
285
- getStatus(item) {
286
- return get(item, this.statusKey);
287
- },
288
- },
289
- };
290
- </script>
291
- <style lang="scss" scoped>
292
- @import '../../../styles/ThoughtChain.scss';
293
- </style>
1
+ <template>
2
+ <div class="el-x-thoughtchain">
3
+ <el-timeline
4
+ ref="timelineRef"
5
+ :style="{
6
+ maxWidth: maxWidth,
7
+ }"
8
+ >
9
+ <transition-group
10
+ name="thought-chain"
11
+ tag="div"
12
+ >
13
+ <el-timeline-item
14
+ v-for="item in thinkingItems"
15
+ :key="getId(item)"
16
+ :type="getType(item)"
17
+ :icon="dotIsIcon ? item.icon : 'el-icon-more'"
18
+ :color="dotIsIcon ? item.iconColor : null"
19
+ :size="dotIsIcon ? item.iconSize : 'normal'"
20
+ :timestamp="getTitle(item)"
21
+ :hide-timestamp="item.hideTitle"
22
+ :placement="item.placement || 'top'"
23
+ >
24
+ <div v-if="!item.isCanExpand">
25
+ <el-x-typewriter
26
+ :content="getThinkTitle(item)"
27
+ :is-markdown="item.isMarkdown"
28
+ :typing="item.typing"
29
+ />
30
+ </div>
31
+ <el-collapse
32
+ v-else-if="!item.isDefaultExpand"
33
+ @change="() => onExpand(item)"
34
+ >
35
+ <el-collapse-item :title="getThinkTitle(item)">
36
+ <el-x-typewriter
37
+ :content="getThinkContent(item)"
38
+ :is-markdown="item.isMarkdown"
39
+ :typing="item.typing"
40
+ />
41
+ </el-collapse-item>
42
+ </el-collapse>
43
+ <el-collapse
44
+ v-else
45
+ v-model="defaultActiveNodes"
46
+ @change="() => onExpand(item)"
47
+ >
48
+ <el-collapse-item
49
+ :title="getThinkTitle(item)"
50
+ :name="String(getId(item))"
51
+ >
52
+ <el-x-typewriter
53
+ :content="getThinkContent(item)"
54
+ :is-markdown="item.isMarkdown"
55
+ :typing="item.typing"
56
+ />
57
+ </el-collapse-item>
58
+ </el-collapse>
59
+
60
+ <template
61
+ v-if="!dotIsIcon"
62
+ slot="dot"
63
+ >
64
+ <div
65
+ class="el-x-thoughtchain-item-dot"
66
+ :style="{ margin: dotMargin }"
67
+ >
68
+ <slot
69
+ name="icon"
70
+ :item="item"
71
+ >
72
+ <el-button
73
+ circle
74
+ :type="getType(item)"
75
+ :loading="isLoading(item)"
76
+ :size="dotSize"
77
+ >
78
+ <template slot="loading">
79
+ <i class="el-icon-loading el-x-thoughtchain-loading"></i>
80
+ </template>
81
+
82
+ <i
83
+ v-if="!isLoading(item) && !isError(item)"
84
+ class="el-icon-check"
85
+ ></i>
86
+ <i
87
+ v-if="!isLoading(item) && isError(item)"
88
+ class="el-icon-close"
89
+ ></i>
90
+ </el-button>
91
+ </slot>
92
+ </div>
93
+ </template>
94
+ </el-timeline-item>
95
+ </transition-group>
96
+ </el-timeline>
97
+ </div>
98
+ </template>
99
+
100
+ <script>
101
+ import { get } from 'lodash';
102
+ import ElXTypewriter from '../../Typewriter/index.js';
103
+ export default {
104
+ name: 'ElXThoughtChain',
105
+ components: {
106
+ ElXTypewriter,
107
+ },
108
+ props: {
109
+ thinkingItems: {
110
+ type: Array,
111
+ default: () => [],
112
+ },
113
+ dotIsIcon: {
114
+ type: Boolean,
115
+ default: false,
116
+ },
117
+ dotSize: {
118
+ type: String,
119
+ default: 'small',
120
+ },
121
+ maxWidth: {
122
+ type: String,
123
+ default: '600px',
124
+ },
125
+ lineGradient: {
126
+ type: Boolean,
127
+ default: false,
128
+ },
129
+ rowKey: {
130
+ type: String,
131
+ default: 'id',
132
+ },
133
+ statusKey: {
134
+ type: String,
135
+ default: 'status',
136
+ },
137
+ statusEnum: {
138
+ type: Object,
139
+ default: () => ({
140
+ loading: {
141
+ value: 'loading',
142
+ type: 'warning',
143
+ },
144
+ error: {
145
+ value: 'error',
146
+ type: 'danger',
147
+ },
148
+ success: {
149
+ value: 'success',
150
+ type: 'success',
151
+ },
152
+ }),
153
+ },
154
+ titleKey: {
155
+ type: String,
156
+ default: 'title',
157
+ },
158
+ thinkTitleKey: {
159
+ type: String,
160
+ default: 'thinkTitle',
161
+ },
162
+ thinkContentKey: {
163
+ type: String,
164
+ default: 'thinkContent',
165
+ },
166
+ },
167
+ data() {
168
+ return {
169
+ colorArr: {
170
+ // 使用与SCSS变量对应的字符串表示
171
+ info: 'var(--color-info, #909399)',
172
+ success: 'var(--color-success, #67C23A)',
173
+ warning: 'var(--color-warning, #E6A23C)',
174
+ danger: 'var(--color-danger, #F56C6C)',
175
+ primary: 'var(--color-primary, #409EFF)',
176
+ },
177
+ defaultActiveNodes: [],
178
+ };
179
+ },
180
+ computed: {
181
+ dotMargin() {
182
+ switch (this.dotSize) {
183
+ case 'mini':
184
+ return '-8px 0 0 -9px';
185
+ case 'small':
186
+ return '-8px 0 0 -11px';
187
+ case 'medium':
188
+ return '-8px 0 0 -13px';
189
+ default:
190
+ return '-8px 0 0 -16px';
191
+ }
192
+ },
193
+ getLineColor() {
194
+ if (this.thinkingItems.length) {
195
+ const arr = this.thinkingItems.map(item => {
196
+ const _type_ = this.getType(item);
197
+ if (_type_) {
198
+ return this.colorArr[_type_];
199
+ }
200
+ return '';
201
+ });
202
+ return arr;
203
+ }
204
+ return [];
205
+ },
206
+ activeNamesComputed() {
207
+ return this.thinkingItems
208
+ .filter(item => item.isCanExpand && item.isDefaultExpand)
209
+ .map(item => String(this.getId(item)));
210
+ },
211
+ },
212
+ watch: {
213
+ activeNamesComputed: {
214
+ handler(v) {
215
+ this.defaultActiveNodes = [...v];
216
+ },
217
+ immediate: true,
218
+ },
219
+ getLineColor() {
220
+ this.$nextTick(() => {
221
+ this.getEle();
222
+ });
223
+ },
224
+ },
225
+ mounted() {
226
+ this.$nextTick(() => {
227
+ this.getEle();
228
+ });
229
+ },
230
+ methods: {
231
+ onExpand(item) {
232
+ this.$emit('handle-expand', item);
233
+ },
234
+ setRadialGradient(colors, ele) {
235
+ const length = ele.length;
236
+ Array.from(ele).forEach((item, index) => {
237
+ const line = item.children[0];
238
+ if (line) {
239
+ line.setAttribute(
240
+ 'style',
241
+ `
242
+ border: none;
243
+ width:2px;
244
+ background: linear-gradient(to bottom, ${colors[index]} 0% , ${
245
+ colors[index < length ? index + 1 : index]
246
+ } 100%);
247
+ `,
248
+ );
249
+ }
250
+ });
251
+ },
252
+ getEle() {
253
+ if (this.getLineColor && this.$refs.timelineRef && this.lineGradient) {
254
+ const ele = this.$refs.timelineRef.$el.children[0].children;
255
+ this.setRadialGradient(this.getLineColor, ele);
256
+ }
257
+ },
258
+ isLoading(item) {
259
+ const status = this.getStatus(item);
260
+ return status === this.statusEnum.loading.value;
261
+ },
262
+ isError(item) {
263
+ const status = this.getStatus(item);
264
+ return status === this.statusEnum.error.value;
265
+ },
266
+ getId(item) {
267
+ return get(item, this.rowKey);
268
+ },
269
+ getType(item) {
270
+ const status = this.getStatus(item);
271
+ // 优先查找statusEnum中value匹配的项
272
+ const matchedStatus = Object.values(this.statusEnum).find(s => s.value === status);
273
+ return matchedStatus ? matchedStatus.type : 'success';
274
+ },
275
+
276
+ getTitle(item) {
277
+ return get(item, this.titleKey) || '';
278
+ },
279
+ getThinkTitle(item) {
280
+ return get(item, this.thinkTitleKey) || '';
281
+ },
282
+ getThinkContent(item) {
283
+ return get(item, this.thinkContentKey) || '';
284
+ },
285
+ getStatus(item) {
286
+ return get(item, this.statusKey);
287
+ },
288
+ },
289
+ };
290
+ </script>
291
+ <style lang="scss" scoped>
292
+ @import '../../../styles/ThoughtChain.scss';
293
+ </style>