-
Notifications
You must be signed in to change notification settings - Fork 61
Expand file tree
/
Copy pathHelpAction.vue
More file actions
434 lines (377 loc) · 12 KB
/
Copy pathHelpAction.vue
File metadata and controls
434 lines (377 loc) · 12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
<template>
<ActionShell
:visible="visible"
:title="config.title || '帮助信息'"
:width="config.width || 700"
:height="config.height"
:canceled-on-touch-outside="!config.keep"
:module="module"
:extend="extend"
:api-url="apiUrl"
@close="handleClose"
@toast="(message, type) => emit('toast', message, type)"
@reset="() => emit('reset')"
>
<a-space direction="vertical" fill size="medium">
<ActionMessage v-if="config.msg" :html="formattedMessage" />
<a-descriptions v-if="config.data && dataList.length > 0" title="帮助信息" bordered :column="1">
<a-descriptions-item v-for="(item, index) in dataList" :key="index" :label="item.key">
<span v-html="formatDataText(item.value)"></span>
</a-descriptions-item>
</a-descriptions>
<a-card v-if="config.img" :bordered="true">
<a-image
:src="config.img"
:alt="config.imgAlt || '帮助图片'"
:height="config.imgHeight || 300"
fit="contain"
show-loader
@load="onImageLoad"
@error="onImageError"
/>
<a-alert v-if="imageError" type="error" show-icon>图片加载失败</a-alert>
</a-card>
<a-card v-if="config.qr" title="扫描二维码" :bordered="true" class="help-qrcode-card">
<a-space direction="vertical" align="center" fill>
<a-image
:src="config.qr"
alt="二维码"
:preview="false"
fit="contain"
@load="onQrLoad"
@error="onQrError"
/>
<a-alert v-if="qrError" type="error" show-icon>二维码加载失败</a-alert>
<a-typography-text v-if="config.qrText" type="secondary">
{{ config.qrText }}
</a-typography-text>
</a-space>
</a-card>
<a-list v-if="config.details" bordered>
<template #header>详细信息</template>
<a-list-item v-for="(detail, index) in detailsList" :key="index">
<a-list-item-meta :title="detail.title || undefined">
<template #description>
<div v-html="detail.content"></div>
</template>
</a-list-item-meta>
</a-list-item>
</a-list>
<a-card v-if="config.steps" title="操作步骤" :bordered="true">
<a-steps direction="vertical" :current="stepsList.length">
<a-step v-for="(step, index) in stepsList" :key="index" :title="step.title || `步骤${index + 1}`">
<template #description>
<a-space direction="vertical" fill>
<div v-html="step.content"></div>
<a-image
v-if="step.image"
:src="step.image"
:alt="step.title || `步骤${index + 1}`"
:height="180"
fit="contain"
/>
</a-space>
</template>
</a-step>
</a-steps>
</a-card>
<a-collapse v-if="config.faq" accordion>
<a-collapse-item v-for="(item, index) in faqList" :key="String(index)" :header="item.question">
<div v-html="item.answer"></div>
</a-collapse-item>
</a-collapse>
<a-list v-if="config.links" bordered>
<template #header>相关链接</template>
<a-list-item v-for="(link, index) in linksList" :key="index">
<a-link :href="link.url" :target="link.target || '_blank'" @click="onLinkClick(link)">
{{ link.title }}
</a-link>
<template v-if="link.description" #extra>
<a-typography-text type="secondary">{{ link.description }}</a-typography-text>
</template>
</a-list-item>
</a-list>
<a-descriptions v-if="config.contact" title="联系我们" bordered :column="1">
<a-descriptions-item v-if="config.contact.email" label="邮箱">
<a-link :href="`mailto:${config.contact.email}`">{{ config.contact.email }}</a-link>
</a-descriptions-item>
<a-descriptions-item v-if="config.contact.phone" label="电话">
<a-link :href="`tel:${config.contact.phone}`">{{ config.contact.phone }}</a-link>
</a-descriptions-item>
<a-descriptions-item v-if="config.contact.website" label="网站">
<a-link :href="config.contact.website" target="_blank">{{ config.contact.website }}</a-link>
</a-descriptions-item>
<a-descriptions-item v-if="config.contact.address" label="地址">
{{ config.contact.address }}
</a-descriptions-item>
</a-descriptions>
<ActionTimeout
v-if="config.timeout"
:time-left="timeLeft"
:total="Number(config.timeout) || 0"
/>
</a-space>
<template #footer>
<ActionFooter
:show-ok="true"
:show-cancel="config.allowPrint || config.allowCopy"
:show-reset="config.allowPrint && config.allowCopy"
:ok-text="config.closeText || '关闭'"
:cancel-text="config.allowCopy ? '复制内容' : '打印'"
reset-text="打印"
@ok="handleClose"
@cancel="config.allowCopy ? handleCopy() : handlePrint()"
@reset="handlePrint"
/>
</template>
</ActionShell>
</template>
<script>
import { ref, computed, watch, onMounted, onUnmounted } from 'vue'
import ActionShell from './shared/ActionShell.vue'
import ActionMessage from './shared/ActionMessage.vue'
import ActionTimeout from './shared/ActionTimeout.vue'
import ActionFooter from './shared/ActionFooter.vue'
export default {
name: 'HelpAction',
components: {
ActionShell,
ActionMessage,
ActionTimeout,
ActionFooter
},
props: {
config: {
type: Object,
required: true
},
visible: {
type: Boolean,
default: true
},
// T4接口调用相关属性
module: {
type: String,
default: ''
},
extend: {
type: [Object, String],
default: () => ({})
},
apiUrl: {
type: String,
default: ''
}
},
emits: ['close', 'link-click', 'toast', 'reset', 'special-action'],
setup(props, { emit }) {
const imageError = ref(false)
const qrError = ref(false)
const expandedFaq = ref(-1)
const timeLeft = ref(0)
const timer = ref(null)
// 计算属性
const formattedMessage = computed(() => {
if (!props.config.msg) return ''
// 如果消息已经包含HTML标签,直接返回
if (/<[^>]+>/.test(props.config.msg)) {
return props.config.msg
}
// 否则支持简单的 Markdown 格式转换
return props.config.msg
.replace(/\*\*(.*?)\*\*/g, '<strong>$1</strong>')
.replace(/\*(.*?)\*/g, '<em>$1</em>')
.replace(/`(.*?)`/g, '<code>$1</code>')
.replace(/\n/g, '<br>')
})
const detailsList = computed(() => {
if (!props.config.details) return []
if (Array.isArray(props.config.details)) {
return props.config.details
}
if (typeof props.config.details === 'string') {
return [{ content: props.config.details }]
}
return [props.config.details]
})
const stepsList = computed(() => {
if (!props.config.steps) return []
if (Array.isArray(props.config.steps)) {
return props.config.steps
}
return []
})
const faqList = computed(() => {
if (!props.config.faq) return []
if (Array.isArray(props.config.faq)) {
return props.config.faq
}
return []
})
const linksList = computed(() => {
if (!props.config.links) return []
if (Array.isArray(props.config.links)) {
return props.config.links
}
return []
})
const dataList = computed(() => {
if (!props.config.data || typeof props.config.data !== 'object') return []
return Object.entries(props.config.data).map(([key, value]) => ({
key,
value
}))
})
// 方法
const formatDataText = (text) => {
if (!text) return ''
// 如果文本已经包含HTML标签,直接返回
if (/<[^>]+>/.test(text)) {
return text
}
// 否则支持简单的 Markdown 格式转换和换行
return String(text)
.replace(/\*\*(.*?)\*\*/g, '<strong>$1</strong>')
.replace(/\*(.*?)\*/g, '<em>$1</em>')
.replace(/`(.*?)`/g, '<code>$1</code>')
.replace(/\n/g, '<br>')
}
const onImageLoad = () => {
imageError.value = false
}
const onImageError = () => {
imageError.value = true
}
const onQrLoad = () => {
qrError.value = false
}
const onQrError = () => {
qrError.value = true
}
const toggleFaq = (index) => {
expandedFaq.value = expandedFaq.value === index ? -1 : index
}
const onLinkClick = (link) => {
emit('link-click', link)
}
const handlePrint = () => {
try {
window.print()
} catch (err) {
console.warn('打印功能不可用:', err)
}
}
const handleCopy = async () => {
try {
// 收集所有文本内容
const content = []
if (props.config.msg) {
content.push(props.config.msg)
}
if (props.config.details) {
content.push('\n详细信息:')
detailsList.value.forEach(detail => {
if (detail.title) content.push(`${detail.title}:`)
content.push(detail.content.replace(/<[^>]*>/g, ''))
})
}
if (props.config.steps) {
content.push('\n操作步骤:')
stepsList.value.forEach((step, index) => {
content.push(`${index + 1}. ${step.title || ''}`)
content.push(step.content.replace(/<[^>]*>/g, ''))
})
}
if (props.config.faq) {
content.push('\n常见问题:')
faqList.value.forEach(item => {
content.push(`Q: ${item.question}`)
content.push(`A: ${item.answer.replace(/<[^>]*>/g, '')}`)
})
}
const text = content.join('\n')
if (navigator.clipboard) {
await navigator.clipboard.writeText(text)
} else {
// 降级方案
const textarea = document.createElement('textarea')
textarea.value = text
document.body.appendChild(textarea)
textarea.select()
document.execCommand('copy')
document.body.removeChild(textarea)
}
// 可以添加成功提示
console.log('内容已复制到剪贴板')
} catch (err) {
console.warn('复制失败:', err)
}
}
const handleClose = () => {
emit('close')
}
// 超时处理
const startTimeout = () => {
if (!props.config.timeout || props.config.timeout <= 0) return
timeLeft.value = props.config.timeout
timer.value = setInterval(() => {
timeLeft.value--
if (timeLeft.value <= 0) {
clearInterval(timer.value)
handleClose()
}
}, 1000)
}
const stopTimeout = () => {
if (timer.value) {
clearInterval(timer.value)
timer.value = null
}
timeLeft.value = 0
}
// 监听显示状态
watch(() => props.visible, (visible) => {
if (visible) {
startTimeout()
} else {
stopTimeout()
}
})
onMounted(() => {
if (props.visible && props.config.timeout) {
startTimeout()
}
})
onUnmounted(() => {
stopTimeout()
})
return {
imageError,
qrError,
expandedFaq,
timeLeft,
formattedMessage,
detailsList,
stepsList,
faqList,
linksList,
dataList,
formatDataText,
onImageLoad,
onImageError,
onQrLoad,
onQrError,
toggleFaq,
onLinkClick,
handlePrint,
handleCopy,
handleClose
}
}
}
</script>
<style scoped>
.help-qrcode-card :deep(.arco-card-body) {
background: var(--action-qr-bg);
}
</style>