verce-vue-test 0.0.111 → 0.0.113

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.
@@ -0,0 +1,310 @@
1
+ <script setup lang="ts">
2
+ import { nextTick, ref, watch } from 'vue'
3
+ import {
4
+ Link,
5
+ List,
6
+ Reading,
7
+ RefreshLeft,
8
+ Tickets,
9
+ } from '@element-plus/icons-vue'
10
+
11
+ const props = withDefaults(defineProps<{
12
+ modelValue?: string
13
+ disabled?: boolean
14
+ }>(), {
15
+ modelValue: '',
16
+ disabled: false,
17
+ })
18
+
19
+ const emit = defineEmits<{
20
+ 'update:modelValue': [value: string]
21
+ change: [value: string]
22
+ }>()
23
+
24
+ const editorRef = ref<HTMLElement>()
25
+ const sourceMode = ref(false)
26
+ const localHtml = ref(props.modelValue)
27
+
28
+ watch(
29
+ () => props.modelValue,
30
+ (value) => {
31
+ if (value === localHtml.value) return
32
+ localHtml.value = value
33
+ syncEditorHtml()
34
+ },
35
+ )
36
+
37
+ function syncEditorHtml() {
38
+ void nextTick(() => {
39
+ if (editorRef.value && editorRef.value.innerHTML !== localHtml.value) {
40
+ editorRef.value.innerHTML = localHtml.value
41
+ }
42
+ })
43
+ }
44
+
45
+ function emitValue(value: string) {
46
+ localHtml.value = value
47
+ emit('update:modelValue', value)
48
+ emit('change', value)
49
+ }
50
+
51
+ function handleEditorInput() {
52
+ emitValue(editorRef.value?.innerHTML ?? '')
53
+ }
54
+
55
+ function handleSourceInput(value: string) {
56
+ emitValue(value)
57
+ }
58
+
59
+ function runCommand(command: string, value?: string) {
60
+ if (props.disabled) return
61
+ editorRef.value?.focus()
62
+ document.execCommand(command, false, value)
63
+ handleEditorInput()
64
+ }
65
+
66
+ function setBlock(tag: 'p' | 'h2' | 'blockquote' | 'pre') {
67
+ runCommand('formatBlock', tag)
68
+ }
69
+
70
+ function insertLink() {
71
+ const url = window.prompt('请输入链接地址')
72
+ if (!url) return
73
+ runCommand('createLink', url)
74
+ }
75
+
76
+ function toggleSourceMode() {
77
+ sourceMode.value = !sourceMode.value
78
+ if (!sourceMode.value) syncEditorHtml()
79
+ }
80
+
81
+ syncEditorHtml()
82
+ </script>
83
+
84
+ <template>
85
+ <div class="rich-text-editor" :class="{ 'is-disabled': disabled }">
86
+ <div class="editor-toolbar" aria-label="正文编辑工具栏">
87
+ <div class="toolbar-group">
88
+ <button type="button" title="正文" @mousedown.prevent @click="setBlock('p')">正文</button>
89
+ <button type="button" title="二级标题" @mousedown.prevent @click="setBlock('h2')">标题</button>
90
+ <button class="text-tool is-bold" type="button" title="加粗" @mousedown.prevent @click="runCommand('bold')">B</button>
91
+ <button class="text-tool is-italic" type="button" title="斜体" @mousedown.prevent @click="runCommand('italic')">I</button>
92
+ <button class="text-tool is-underline" type="button" title="下划线" @mousedown.prevent @click="runCommand('underline')">U</button>
93
+ </div>
94
+
95
+ <span class="toolbar-divider"></span>
96
+
97
+ <div class="toolbar-group">
98
+ <button type="button" title="无序列表" @mousedown.prevent @click="runCommand('insertUnorderedList')">
99
+ <el-icon><List /></el-icon>
100
+ </button>
101
+ <button type="button" title="有序列表" @mousedown.prevent @click="runCommand('insertOrderedList')">
102
+ <el-icon><Tickets /></el-icon>
103
+ </button>
104
+ <button type="button" title="引用" @mousedown.prevent @click="setBlock('blockquote')">
105
+ <el-icon><Reading /></el-icon>
106
+ </button>
107
+ <button type="button" title="代码块" @mousedown.prevent @click="setBlock('pre')">&lt;/&gt;</button>
108
+ <button type="button" title="插入链接" @mousedown.prevent @click="insertLink">
109
+ <el-icon><Link /></el-icon>
110
+ </button>
111
+ </div>
112
+
113
+ <span class="toolbar-divider"></span>
114
+
115
+ <div class="toolbar-group">
116
+ <button type="button" title="清除格式" @mousedown.prevent @click="runCommand('removeFormat')">
117
+ <el-icon><RefreshLeft /></el-icon>
118
+ </button>
119
+ </div>
120
+
121
+ <button
122
+ class="source-toggle"
123
+ :class="{ 'is-active': sourceMode }"
124
+ type="button"
125
+ @click="toggleSourceMode"
126
+ >
127
+ {{ sourceMode ? '返回编辑' : 'HTML' }}
128
+ </button>
129
+ </div>
130
+
131
+ <el-input
132
+ v-if="sourceMode"
133
+ :model-value="localHtml"
134
+ class="source-editor"
135
+ type="textarea"
136
+ :rows="16"
137
+ :disabled="disabled"
138
+ placeholder="请输入公告正文 HTML"
139
+ @update:model-value="handleSourceInput"
140
+ />
141
+
142
+ <div
143
+ v-else
144
+ ref="editorRef"
145
+ class="editor-content"
146
+ :contenteditable="disabled ? 'false' : 'true'"
147
+ data-placeholder="请输入公告正文,可使用上方工具栏设置标题、列表、引用和链接"
148
+ @input="handleEditorInput"
149
+ @blur="handleEditorInput"
150
+ ></div>
151
+ </div>
152
+ </template>
153
+
154
+ <style scoped>
155
+ .rich-text-editor {
156
+ overflow: hidden;
157
+ border: 1px solid #dcdfe6;
158
+ border-radius: 8px;
159
+ background: #ffffff;
160
+ transition: border-color 0.2s, box-shadow 0.2s;
161
+ }
162
+
163
+ .rich-text-editor:focus-within {
164
+ border-color: #409eff;
165
+ box-shadow: 0 0 0 2px rgba(64, 158, 255, 0.12);
166
+ }
167
+
168
+ .rich-text-editor.is-disabled {
169
+ background: #f5f7fa;
170
+ }
171
+
172
+ .editor-toolbar {
173
+ display: flex;
174
+ align-items: center;
175
+ gap: 6px;
176
+ min-height: 46px;
177
+ padding: 6px 10px;
178
+ border-bottom: 1px solid #e8ecf2;
179
+ background: #f8fafc;
180
+ }
181
+
182
+ .toolbar-group {
183
+ display: inline-flex;
184
+ align-items: center;
185
+ gap: 3px;
186
+ }
187
+
188
+ .editor-toolbar button {
189
+ display: inline-flex;
190
+ align-items: center;
191
+ justify-content: center;
192
+ min-width: 32px;
193
+ height: 32px;
194
+ padding: 0 8px;
195
+ border: 0;
196
+ border-radius: 5px;
197
+ color: #4d5b70;
198
+ background: transparent;
199
+ cursor: pointer;
200
+ font: inherit;
201
+ font-size: 13px;
202
+ }
203
+
204
+ .editor-toolbar button:hover,
205
+ .editor-toolbar button.is-active {
206
+ color: #1677ff;
207
+ background: #eaf3ff;
208
+ }
209
+
210
+ .text-tool.is-bold {
211
+ font-weight: 800;
212
+ }
213
+
214
+ .text-tool.is-italic {
215
+ font-family: Georgia, serif;
216
+ font-style: italic;
217
+ }
218
+
219
+ .text-tool.is-underline {
220
+ text-decoration: underline;
221
+ }
222
+
223
+ .toolbar-divider {
224
+ width: 1px;
225
+ height: 22px;
226
+ margin: 0 2px;
227
+ background: #dfe5ed;
228
+ }
229
+
230
+ .source-toggle {
231
+ margin-left: auto;
232
+ }
233
+
234
+ .editor-content {
235
+ min-height: 360px;
236
+ padding: 22px 24px;
237
+ outline: none;
238
+ color: #1f2937;
239
+ font-size: 15px;
240
+ line-height: 1.9;
241
+ }
242
+
243
+ .editor-content:empty::before {
244
+ color: #a8abb2;
245
+ content: attr(data-placeholder);
246
+ pointer-events: none;
247
+ }
248
+
249
+ .editor-content :deep(p) {
250
+ margin: 0 0 14px;
251
+ }
252
+
253
+ .editor-content :deep(h2) {
254
+ margin: 24px 0 10px;
255
+ color: #172033;
256
+ font-size: 18px;
257
+ line-height: 1.6;
258
+ }
259
+
260
+ .editor-content :deep(blockquote) {
261
+ margin: 16px 0;
262
+ padding: 10px 14px;
263
+ border-left: 4px solid #409eff;
264
+ color: #52627a;
265
+ background: #f4f8ff;
266
+ }
267
+
268
+ .editor-content :deep(pre) {
269
+ overflow-x: auto;
270
+ margin: 16px 0;
271
+ padding: 14px 16px;
272
+ border-radius: 6px;
273
+ color: #e2e8f0;
274
+ background: #172033;
275
+ font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
276
+ line-height: 1.65;
277
+ }
278
+
279
+ .editor-content :deep(a) {
280
+ color: #1677ff;
281
+ }
282
+
283
+ .source-editor {
284
+ display: block;
285
+ padding: 12px;
286
+ }
287
+
288
+ .source-editor :deep(.el-textarea__inner) {
289
+ border: 0;
290
+ box-shadow: none;
291
+ font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
292
+ line-height: 1.65;
293
+ resize: vertical;
294
+ }
295
+
296
+ @media (max-width: 720px) {
297
+ .editor-toolbar {
298
+ flex-wrap: wrap;
299
+ }
300
+
301
+ .source-toggle {
302
+ margin-left: 0;
303
+ }
304
+
305
+ .editor-content {
306
+ min-height: 300px;
307
+ padding: 18px;
308
+ }
309
+ }
310
+ </style>
@@ -0,0 +1,403 @@
1
+ <script setup lang="ts">
2
+ import { computed, onMounted, reactive, ref } from 'vue'
3
+ import { useRoute, useRouter } from 'vue-router'
4
+ import { ArrowLeft, Check } from '@element-plus/icons-vue'
5
+ import { ElMessage } from 'element-plus'
6
+ import type { FormInstance, FormRules } from 'element-plus'
7
+
8
+ import NoticeRichTextEditor from './components/NoticeRichTextEditor.vue'
9
+ import { createNotice, getNoticeDetail, updateNotice } from './api'
10
+
11
+ const route = useRoute()
12
+ const router = useRouter()
13
+ const formRef = ref<FormInstance>()
14
+ const pageLoading = ref(false)
15
+ const submitting = ref(false)
16
+
17
+ const noticeId = computed(() => {
18
+ const id = String(route.params.id ?? '').trim()
19
+ return id || undefined
20
+ })
21
+ const isEdit = computed(() => noticeId.value !== undefined)
22
+ const pageTitle = computed(() => (isEdit.value ? '编辑公告' : '新增公告'))
23
+
24
+ const form = reactive({
25
+ title: '',
26
+ publishTime: createDefaultPublishTime(),
27
+ pinned: false,
28
+ contentHtml: '',
29
+ })
30
+
31
+ const rules: FormRules = {
32
+ title: [
33
+ { required: true, message: '请输入公告标题', trigger: 'blur' },
34
+ { max: 300, message: '公告标题不能超过 300 个字符', trigger: 'blur' },
35
+ ],
36
+ publishTime: [
37
+ { required: true, message: '请选择发布时间', trigger: 'change' },
38
+ ],
39
+ }
40
+
41
+ function pad(value: number) {
42
+ return String(value).padStart(2, '0')
43
+ }
44
+
45
+ function createDefaultPublishTime() {
46
+ const now = new Date()
47
+ return [
48
+ now.getFullYear(),
49
+ '-',
50
+ pad(now.getMonth() + 1),
51
+ '-',
52
+ pad(now.getDate()),
53
+ ' ',
54
+ pad(now.getHours()),
55
+ ':',
56
+ pad(now.getMinutes()),
57
+ ':00',
58
+ ].join('')
59
+ }
60
+
61
+ function hasContent(html: string) {
62
+ const container = document.createElement('div')
63
+ container.innerHTML = html
64
+ return Boolean(container.textContent?.trim() || container.querySelector('img, video, iframe'))
65
+ }
66
+
67
+ async function loadDetail() {
68
+ if (!noticeId.value) return
69
+ pageLoading.value = true
70
+ try {
71
+ const detail = await getNoticeDetail(noticeId.value)
72
+ form.title = detail.annouTitle
73
+ form.publishTime = detail.createTm || createDefaultPublishTime()
74
+ form.pinned = detail.topFlag === '1'
75
+ form.contentHtml = detail.annouConte
76
+ } catch (error) {
77
+ ElMessage.error(error instanceof Error ? error.message : '公告详情加载失败')
78
+ } finally {
79
+ pageLoading.value = false
80
+ }
81
+ }
82
+
83
+ async function handleSubmit() {
84
+ if (!formRef.value) return
85
+
86
+ try {
87
+ await formRef.value.validate()
88
+ } catch {
89
+ return
90
+ }
91
+
92
+ if (!hasContent(form.contentHtml)) {
93
+ ElMessage.warning('请输入公告正文')
94
+ return
95
+ }
96
+
97
+ submitting.value = true
98
+ try {
99
+ const payload = {
100
+ title: form.title.trim(),
101
+ date: form.publishTime.slice(0, 10),
102
+ publishTime: form.publishTime,
103
+ pinned: form.pinned,
104
+ contentHtml: form.contentHtml,
105
+ }
106
+
107
+ if (noticeId.value) {
108
+ await updateNotice(noticeId.value, payload)
109
+ ElMessage.success('公告更新成功')
110
+ } else {
111
+ await createNotice(payload)
112
+ ElMessage.success('公告新增成功')
113
+ }
114
+
115
+ await router.push({ name: 'noticeManagement' })
116
+ } catch (error) {
117
+ ElMessage.error(error instanceof Error ? error.message : '公告保存失败')
118
+ } finally {
119
+ submitting.value = false
120
+ }
121
+ }
122
+
123
+ function handleCancel() {
124
+ void router.push({ name: 'noticeManagement' })
125
+ }
126
+
127
+ onMounted(loadDetail)
128
+ </script>
129
+
130
+ <template>
131
+ <main v-loading="pageLoading" class="notice-edit-page">
132
+ <section class="page-heading">
133
+ <button class="back-button" type="button" @click="handleCancel">
134
+ <el-icon><ArrowLeft /></el-icon>
135
+ </button>
136
+ <div>
137
+ <p class="heading-path">公告管理 / {{ pageTitle }}</p>
138
+ <h1>{{ pageTitle }}</h1>
139
+ <p>完善公告信息并编辑正文内容</p>
140
+ </div>
141
+ </section>
142
+
143
+ <el-form
144
+ ref="formRef"
145
+ :model="form"
146
+ :rules="rules"
147
+ label-position="top"
148
+ class="notice-form"
149
+ >
150
+ <el-card class="form-card basic-card" shadow="never">
151
+ <template #header>
152
+ <div class="card-heading">
153
+ <span class="card-step">01</span>
154
+ <div>
155
+ <strong>基本信息</strong>
156
+ <small>设置公告标题与展示规则</small>
157
+ </div>
158
+ </div>
159
+ </template>
160
+
161
+ <div class="basic-form-grid">
162
+ <el-form-item label="公告标题" prop="title" class="title-field">
163
+ <el-input
164
+ v-model="form.title"
165
+ maxlength="300"
166
+ show-word-limit
167
+ clearable
168
+ placeholder="请输入公告标题"
169
+ />
170
+ </el-form-item>
171
+ <el-form-item label="发布时间" prop="publishTime">
172
+ <el-date-picker
173
+ v-model="form.publishTime"
174
+ type="datetime"
175
+ value-format="YYYY-MM-DD HH:mm:ss"
176
+ placeholder="请选择发布时间"
177
+ style="width: 100%"
178
+ />
179
+ </el-form-item>
180
+ <el-form-item label="置顶设置">
181
+ <div class="pinned-setting">
182
+ <el-switch
183
+ v-model="form.pinned"
184
+ inline-prompt
185
+ active-text="是"
186
+ inactive-text="否"
187
+ />
188
+ <span>{{ form.pinned ? '该公告将在列表顶部优先展示' : '按发布时间参与列表排序' }}</span>
189
+ </div>
190
+ </el-form-item>
191
+ </div>
192
+ </el-card>
193
+
194
+ <el-card class="form-card content-card" shadow="never">
195
+ <template #header>
196
+ <div class="card-heading">
197
+ <span class="card-step">02</span>
198
+ <div>
199
+ <strong>公告正文</strong>
200
+ <small>支持基础排版及 HTML 源码编辑</small>
201
+ </div>
202
+ </div>
203
+ </template>
204
+
205
+ <el-form-item class="content-form-item" required>
206
+ <NoticeRichTextEditor v-model="form.contentHtml" />
207
+ </el-form-item>
208
+ </el-card>
209
+
210
+ <div class="form-actions">
211
+ <el-button @click="handleCancel">取消</el-button>
212
+ <el-button
213
+ type="primary"
214
+ :icon="Check"
215
+ :loading="submitting"
216
+ @click="handleSubmit"
217
+ >
218
+ {{ isEdit ? '保存修改' : '发布公告' }}
219
+ </el-button>
220
+ </div>
221
+ </el-form>
222
+ </main>
223
+ </template>
224
+
225
+ <style scoped>
226
+ .notice-edit-page {
227
+ min-height: 100%;
228
+ padding: 22px 22px 96px;
229
+ color: #1f2937;
230
+ background:
231
+ radial-gradient(circle at 88% 3%, rgba(64, 158, 255, 0.08), transparent 22%),
232
+ #f5f7fa;
233
+ font-family: "PingFang SC", "Microsoft YaHei", sans-serif;
234
+ }
235
+
236
+ .page-heading {
237
+ display: flex;
238
+ align-items: center;
239
+ gap: 14px;
240
+ margin: 0 auto 18px;
241
+ max-width: 1180px;
242
+ }
243
+
244
+ .back-button {
245
+ display: inline-flex;
246
+ flex: 0 0 auto;
247
+ align-items: center;
248
+ justify-content: center;
249
+ width: 36px;
250
+ height: 36px;
251
+ border: 1px solid #dfe5ed;
252
+ border-radius: 8px;
253
+ color: #52627a;
254
+ background: #ffffff;
255
+ cursor: pointer;
256
+ }
257
+
258
+ .back-button:hover {
259
+ border-color: #409eff;
260
+ color: #409eff;
261
+ }
262
+
263
+ .heading-path {
264
+ margin: 0 0 2px !important;
265
+ color: #8b98aa !important;
266
+ font-size: 12px !important;
267
+ }
268
+
269
+ .page-heading h1 {
270
+ margin: 0;
271
+ color: #172033;
272
+ font-size: 24px;
273
+ line-height: 1.4;
274
+ }
275
+
276
+ .page-heading p {
277
+ margin: 2px 0 0;
278
+ color: #8491a5;
279
+ font-size: 13px;
280
+ }
281
+
282
+ .notice-form {
283
+ max-width: 1180px;
284
+ margin: 0 auto;
285
+ }
286
+
287
+ .form-card {
288
+ border: 1px solid #e4e9f0;
289
+ border-radius: 8px;
290
+ }
291
+
292
+ .form-card + .form-card {
293
+ margin-top: 16px;
294
+ }
295
+
296
+ .form-card :deep(.el-card__header) {
297
+ padding: 16px 20px;
298
+ border-bottom-color: #edf0f5;
299
+ }
300
+
301
+ .form-card :deep(.el-card__body) {
302
+ padding: 22px 24px 6px;
303
+ }
304
+
305
+ .card-heading {
306
+ display: flex;
307
+ align-items: center;
308
+ gap: 11px;
309
+ }
310
+
311
+ .card-step {
312
+ display: inline-flex;
313
+ align-items: center;
314
+ justify-content: center;
315
+ width: 34px;
316
+ height: 34px;
317
+ border-radius: 8px;
318
+ color: #1677ff;
319
+ background: #eaf3ff;
320
+ font-size: 12px;
321
+ font-weight: 700;
322
+ letter-spacing: 0.04em;
323
+ }
324
+
325
+ .card-heading div {
326
+ display: flex;
327
+ flex-direction: column;
328
+ gap: 2px;
329
+ }
330
+
331
+ .card-heading strong {
332
+ color: #273247;
333
+ font-size: 16px;
334
+ }
335
+
336
+ .card-heading small {
337
+ color: #9aa5b5;
338
+ font-size: 12px;
339
+ font-weight: 400;
340
+ }
341
+
342
+ .basic-form-grid {
343
+ display: grid;
344
+ grid-template-columns: minmax(0, 1fr) 260px;
345
+ column-gap: 24px;
346
+ }
347
+
348
+ .title-field {
349
+ grid-column: 1 / -1;
350
+ }
351
+
352
+ .pinned-setting {
353
+ display: flex;
354
+ align-items: center;
355
+ gap: 12px;
356
+ min-height: 32px;
357
+ color: #8491a5;
358
+ font-size: 13px;
359
+ }
360
+
361
+ .content-card :deep(.el-card__body) {
362
+ padding-bottom: 22px;
363
+ }
364
+
365
+ .content-form-item {
366
+ margin-bottom: 0;
367
+ }
368
+
369
+ .content-form-item :deep(.el-form-item__content) {
370
+ display: block;
371
+ }
372
+
373
+ .form-actions {
374
+ position: fixed;
375
+ z-index: 20;
376
+ right: 0;
377
+ bottom: 0;
378
+ left: var(--app-aside-width, 200px);
379
+ display: flex;
380
+ justify-content: flex-end;
381
+ gap: 8px;
382
+ padding: 14px 24px;
383
+ border-top: 1px solid #e1e6ed;
384
+ background: rgba(255, 255, 255, 0.94);
385
+ box-shadow: 0 -8px 24px rgba(31, 41, 55, 0.04);
386
+ backdrop-filter: blur(12px);
387
+ }
388
+
389
+ @media (max-width: 900px) {
390
+ .notice-edit-page {
391
+ padding: 16px 16px 92px;
392
+ }
393
+
394
+ .basic-form-grid {
395
+ grid-template-columns: 1fr;
396
+ }
397
+
398
+ .title-field {
399
+ grid-column: auto;
400
+ }
401
+
402
+ }
403
+ </style>