|
| 1 | +<template> |
| 2 | + <div class="message-detail-editor"> |
| 3 | + <div v-if="showMeta" class="prop-item-time"> |
| 4 | + <label>时间:</label> |
| 5 | + <div>{{ formatDate(message.time) }}</div> |
| 6 | + </div> |
| 7 | + |
| 8 | + <div class="prop-item"> |
| 9 | + <label>玩家名</label> |
| 10 | + <input |
| 11 | + type="text" |
| 12 | + :value="values.playerName" |
| 13 | + @input="emitTextInput('playerName', $event)" |
| 14 | + @blur="emitCommit('playerName')" |
| 15 | + @keydown.enter.exact.prevent="emitCommit('playerName')" |
| 16 | + /> |
| 17 | + </div> |
| 18 | + |
| 19 | + <div class="prop-item"> |
| 20 | + <label>账号</label> |
| 21 | + <input |
| 22 | + type="text" |
| 23 | + :value="values.account" |
| 24 | + @input="emitTextInput('account', $event)" |
| 25 | + @blur="emitCommit('account')" |
| 26 | + @keydown.enter.exact.prevent="emitCommit('account')" |
| 27 | + /> |
| 28 | + </div> |
| 29 | + |
| 30 | + <div class="prop-item"> |
| 31 | + <label>身份</label> |
| 32 | + <select |
| 33 | + :value="values.role" |
| 34 | + @change="emitFieldChange('role', getRoleValue($event))" |
| 35 | + > |
| 36 | + <option value="pl">玩家</option> |
| 37 | + <option value="gm">主持人</option> |
| 38 | + <option value="npc">NPC</option> |
| 39 | + <option value="ob">观众</option> |
| 40 | + <option value="bot">骰子</option> |
| 41 | + <option value="unknown">未知</option> |
| 42 | + </select> |
| 43 | + </div> |
| 44 | + |
| 45 | + <div class="prop-row"> |
| 46 | + <ToggleButton |
| 47 | + :model-value="values.isOoc" |
| 48 | + @update:model-value=" |
| 49 | + emitFieldChange('isOoc', Boolean($event)) |
| 50 | + " |
| 51 | + > |
| 52 | + 场外消息 |
| 53 | + </ToggleButton> |
| 54 | + <ToggleButton |
| 55 | + :model-value="values.isCommand" |
| 56 | + @update:model-value=" |
| 57 | + emitFieldChange('isCommand', Boolean($event)) |
| 58 | + " |
| 59 | + > |
| 60 | + 指令消息 |
| 61 | + </ToggleButton> |
| 62 | + </div> |
| 63 | + |
| 64 | + <div class="prop-item full-width"> |
| 65 | + <label>消息内容</label> |
| 66 | + <textarea |
| 67 | + :value="values.content" |
| 68 | + :rows="contentRows" |
| 69 | + @input="emitTextInput('content', $event)" |
| 70 | + @blur="emitCommit('content')" |
| 71 | + @keydown.enter.exact.prevent="emitCommit('content')" |
| 72 | + ></textarea> |
| 73 | + </div> |
| 74 | + |
| 75 | + <div class="prop-item full-width"> |
| 76 | + <label>备注</label> |
| 77 | + <input |
| 78 | + type="text" |
| 79 | + :value="values.note" |
| 80 | + placeholder="备注信息..." |
| 81 | + @input="emitTextInput('note', $event)" |
| 82 | + @blur="emitCommit('note')" |
| 83 | + @keydown.enter.exact.prevent="emitCommit('note')" |
| 84 | + /> |
| 85 | + </div> |
| 86 | + </div> |
| 87 | +</template> |
| 88 | + |
| 89 | +<script setup lang="ts"> |
| 90 | +import ToggleButton from '@/components/common/ToggleButton.vue'; |
| 91 | +import type { Message, RoleType } from '@/types/log'; |
| 92 | +import { formatDate } from '@/utils/date'; |
| 93 | +
|
| 94 | +export type MessageDetailTextField = |
| 95 | + | 'playerName' |
| 96 | + | 'account' |
| 97 | + | 'content' |
| 98 | + | 'note'; |
| 99 | +
|
| 100 | +export interface MessageDetailValues { |
| 101 | + playerName: string; |
| 102 | + account: string; |
| 103 | + role: RoleType; |
| 104 | + content: string; |
| 105 | + note: string; |
| 106 | + isOoc: boolean; |
| 107 | + isCommand: boolean; |
| 108 | +} |
| 109 | +
|
| 110 | +const props = withDefaults( |
| 111 | + defineProps<{ |
| 112 | + message: Message; |
| 113 | + values: MessageDetailValues; |
| 114 | + showMeta?: boolean; |
| 115 | + contentRows?: number; |
| 116 | + }>(), |
| 117 | + { |
| 118 | + showMeta: true, |
| 119 | + contentRows: 5, |
| 120 | + }, |
| 121 | +); |
| 122 | +
|
| 123 | +const emit = defineEmits<{ |
| 124 | + (e: 'textInput', field: MessageDetailTextField, value: string): void; |
| 125 | + (e: 'commitText', field: MessageDetailTextField): void; |
| 126 | + <K extends keyof MessageDetailValues>( |
| 127 | + e: 'fieldChange', |
| 128 | + field: K, |
| 129 | + value: MessageDetailValues[K], |
| 130 | + ): void; |
| 131 | +}>(); |
| 132 | +
|
| 133 | +function emitTextInput(field: MessageDetailTextField, event: Event) { |
| 134 | + emit('textInput', field, getEventValue(event)); |
| 135 | +} |
| 136 | +
|
| 137 | +function emitCommit(field: MessageDetailTextField) { |
| 138 | + emit('commitText', field); |
| 139 | +} |
| 140 | +
|
| 141 | +function emitFieldChange<K extends keyof MessageDetailValues>( |
| 142 | + field: K, |
| 143 | + value: MessageDetailValues[K], |
| 144 | +) { |
| 145 | + emit('fieldChange', field, value); |
| 146 | +} |
| 147 | +
|
| 148 | +function getEventValue(event: Event) { |
| 149 | + return (event.target as HTMLInputElement | HTMLTextAreaElement).value; |
| 150 | +} |
| 151 | +
|
| 152 | +function getRoleValue(event: Event): RoleType { |
| 153 | + return (event.target as HTMLSelectElement).value as RoleType; |
| 154 | +} |
| 155 | +
|
| 156 | +void props; |
| 157 | +</script> |
| 158 | + |
| 159 | +<style scoped> |
| 160 | +.message-detail-editor { |
| 161 | + padding: 10px; |
| 162 | + display: grid; |
| 163 | + grid-template-columns: repeat(2, minmax(0, 1fr)); |
| 164 | + gap: 8px; |
| 165 | +} |
| 166 | +
|
| 167 | +.prop-item-time { |
| 168 | + grid-column: span 2; |
| 169 | + display: flex; |
| 170 | + gap: 4px; |
| 171 | + font-size: 12px; |
| 172 | +} |
| 173 | +
|
| 174 | +.prop-item { |
| 175 | + display: flex; |
| 176 | + flex-direction: column; |
| 177 | + gap: 4px; |
| 178 | + min-width: 0; |
| 179 | +} |
| 180 | +
|
| 181 | +.prop-item.full-width { |
| 182 | + grid-column: span 2; |
| 183 | +} |
| 184 | +
|
| 185 | +.prop-item label { |
| 186 | + font-size: 11px; |
| 187 | + color: var(--text-muted); |
| 188 | +} |
| 189 | +
|
| 190 | +.prop-item input[type='text'], |
| 191 | +.prop-item select, |
| 192 | +.prop-item textarea { |
| 193 | + width: 100%; |
| 194 | + box-sizing: border-box; |
| 195 | + background-color: var(--bg-primary); |
| 196 | + border: 1px solid var(--border-color); |
| 197 | + color: var(--text-primary); |
| 198 | + padding: 6px 8px; |
| 199 | + border-radius: 4px; |
| 200 | + font-size: 13px; |
| 201 | + outline: none; |
| 202 | +} |
| 203 | +
|
| 204 | +.prop-item input:focus, |
| 205 | +.prop-item select:focus, |
| 206 | +.prop-item textarea:focus { |
| 207 | + border-color: var(--active-accent); |
| 208 | +} |
| 209 | +
|
| 210 | +.prop-row { |
| 211 | + grid-column: span 2; |
| 212 | + display: flex; |
| 213 | + gap: 20px; |
| 214 | + padding-top: 5px; |
| 215 | +} |
| 216 | +
|
| 217 | +.prop-row :deep(.toggle-button) { |
| 218 | + font-size: 12px; |
| 219 | +} |
| 220 | +</style> |
0 commit comments