ux(ui): readable persona form instead of raw JSON + step-by-step guides for non-IT users
- GroupEdit: replace raw JSON persona dump with a labeled, sectioned PersonaForm
(ข้อมูลพื้นฐาน / ข้อมูลลูกค้า / การขาย / ช่องทาง) shown in a modal; admin edits by field.
- New reusable components/PersonaForm.vue.
- GroupBuilder + Personas: add friendly step-by-step guidance cards ('วิธีสร้าง',
'วิธีฝึก') so admins/trainees know what to do at each step.
- Rebuild dist.
This commit is contained in:
@@ -1,37 +1,58 @@
|
||||
<template>
|
||||
<div>
|
||||
<router-link to="/" class="btn-back">← {{ i18n.t('dashboard') }}</router-link>
|
||||
<div class="row" style="align-items:center;margin-bottom:16px">
|
||||
<h2 style="margin:0">{{ i18n.t('groupBuilder') }} — {{ group && group.title }}</h2>
|
||||
<button class="primary" style="margin-left:auto" @click="analyze" :disabled="busy">
|
||||
<span v-if="busy" class="spinner" style="margin-right:4px"></span>{{ i18n.t('analyze') }}
|
||||
</button>
|
||||
<router-link to="/training" class="btn-back">← {{ i18n.t('training') }}</router-link>
|
||||
<div class="row" style="align-items:center;margin-bottom:8px">
|
||||
<h2 style="margin:0">🛠 {{ i18n.t('managePersonas') }}</h2>
|
||||
<div class="row" style="margin-left:auto;gap:10px">
|
||||
<button @click="analyze" :disabled="busy" class="primary">
|
||||
<span v-if="busy" class="spinner"></span>{{ busy ? 'กำลังสร้าง…' : '✨ สร้าง/วิเคราะห์บุคคลต้นแบบ' }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<p class="muted" v-if="group">สินค้า: <strong>{{ group.title }}</strong></p>
|
||||
|
||||
<div class="error" v-if="error" style="margin:12px 0">{{ error }}</div>
|
||||
|
||||
<!-- Step guidance -->
|
||||
<div class="card guide">
|
||||
<strong>วิธีใช้หน้านี้</strong>
|
||||
<ol style="margin:8px 0 0;padding-left:20px;line-height:1.8">
|
||||
<li>กดปุ่ม <strong>✨ สร้าง/วิเคราะห์บุคคลต้นแบบ</strong> เพื่อให้ระบบสร้างลูกค้าจำลอง 15 คน (ระดับ A/B/C)</li>
|
||||
<li>แต่ละการ์ดคือลูกค้าจำลอง 1 คน — กด <strong>✏️ แก้ไข</strong> เพื่อปรับรายละเอียดให้ตรงใจ</li>
|
||||
<li>เมื่อพร้อมให้ผู้ใช้ฝึก กด <strong>เปิดใช้งาน</strong> (ยังทำในขั้นถัดไป)</li>
|
||||
</ol>
|
||||
</div>
|
||||
<div class="error" v-if="error">{{ error }}</div>
|
||||
|
||||
<div v-if="personas.length === 0 && !busy" class="card empty-state">
|
||||
<strong>No personas yet</strong>
|
||||
<span>Click {{ i18n.t('analyze') }} to generate the 15 personas (5 per tier).</span>
|
||||
<strong>ยังไม่มีบุคคลต้นแบบ</strong>
|
||||
<span>กด "✨ สร้าง/วิเคราะห์บุคคลต้นแบบ" เพื่อให้ระบบสร้างลูกค้าจำลองให้</span>
|
||||
</div>
|
||||
|
||||
<!-- Persona list -->
|
||||
<div v-for="tier in ['A','B','C']" :key="tier" style="margin-bottom:20px">
|
||||
<h4>{{ tierLabel(tier) }}</h4>
|
||||
<div class="grid">
|
||||
<div v-for="p in byTier(tier)" :key="p.id" class="card pcard">
|
||||
<div class="row">
|
||||
<div class="row" style="justify-content:space-between;align-items:center">
|
||||
<strong>{{ p.name }}</strong>
|
||||
<span class="badge" v-if="p.special === 'wrong_text'">⚠️ wrong_text</span>
|
||||
<span class="badge" :class="tierClass(p.tier)">{{ p.tier }}</span>
|
||||
</div>
|
||||
<div class="muted">{{ p.profession }} · {{ p.age_group }} · {{ p.channel }} · {{ p.initiation_mode }}</div>
|
||||
<div class="muted" style="margin-top:4px">diff {{ p.difficulty }} · {{ p.income }} · {{ p.personality }}</div>
|
||||
<details style="margin-top:8px" open>
|
||||
<summary>{{ i18n.t('reveal') }}</summary>
|
||||
<pre class="json">{{ JSON.stringify(p, null, 2) }}</pre>
|
||||
</details>
|
||||
<button @click="editPersona(p)">✏️ Edit</button>
|
||||
<div class="diff">
|
||||
<span v-for="n in 5" :key="n" class="star" :class="{ on: n <= (p.difficulty || 1) }">★</span>
|
||||
</div>
|
||||
<div class="muted">{{ p.profession }} · {{ p.age_group }} · {{ p.location }}</div>
|
||||
<div class="muted">{{ p.channel }} · {{ p.initiation_mode === 'seller' ? 'เริ่มขายเอง' : 'ลูกค้าทักก่อน' }}</div>
|
||||
<button class="edit-btn" @click="openEdit(p)">✏️ แก้ไขรายละเอียด</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Edit modal -->
|
||||
<div v-if="editing" class="modal-backdrop" @click.self="editing=null">
|
||||
<div class="modal">
|
||||
<PersonaForm :persona="editing" @save="savePersona" @cancel="editing=null" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -40,6 +61,7 @@ import { onMounted, ref } from 'vue'
|
||||
import { useRoute } from 'vue-router'
|
||||
import { api } from '../api'
|
||||
import { i18n } from '../i18n'
|
||||
import PersonaForm from '../components/PersonaForm.vue'
|
||||
|
||||
const route = useRoute()
|
||||
const gid = route.params.gid
|
||||
@@ -47,6 +69,7 @@ const group = ref(null)
|
||||
const personas = ref([])
|
||||
const busy = ref(false)
|
||||
const error = ref('')
|
||||
const editing = ref(null)
|
||||
|
||||
async function load() {
|
||||
const data = await api.getGroup(gid)
|
||||
@@ -55,9 +78,9 @@ async function load() {
|
||||
}
|
||||
function byTier(t) { return personas.value.filter((p) => p.tier === t) }
|
||||
function tierLabel(t) { return i18n.t(t === 'A' ? 'tierA' : t === 'B' ? 'tierB' : 'tierC') }
|
||||
function tierClass(t) { return { A: 'tier-a', B: 'tier-b', C: 'tier-c' }[t] || '' }
|
||||
async function analyze() {
|
||||
busy.value = true
|
||||
error.value = ''
|
||||
busy.value = true; error.value = ''
|
||||
try {
|
||||
const data = await api.analyzeGroup(gid)
|
||||
personas.value = data.personas
|
||||
@@ -65,23 +88,29 @@ async function analyze() {
|
||||
} catch (e) { error.value = e.message }
|
||||
finally { busy.value = false }
|
||||
}
|
||||
function editPersona(p) {
|
||||
const json = prompt('Edit persona JSON (full fields):', JSON.stringify(p, null, 2))
|
||||
if (!json) return
|
||||
function openEdit(p) { editing.value = JSON.parse(JSON.stringify(p)) }
|
||||
async function savePersona(payload) {
|
||||
busy.value = true
|
||||
try {
|
||||
const parsed = JSON.parse(json)
|
||||
api.updatePersona(gid, p.id, parsed).then(load)
|
||||
} catch (e) { error.value = 'Invalid JSON: ' + e.message }
|
||||
await api.updatePersona(gid, editing.value.id, payload)
|
||||
editing.value = null
|
||||
await load()
|
||||
} catch (e) { error.value = e.message }
|
||||
finally { busy.value = false }
|
||||
}
|
||||
onMounted(load)
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; }
|
||||
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; }
|
||||
.pcard { display: flex; flex-direction: column; }
|
||||
.pcard button { margin-top: auto; }
|
||||
.json {
|
||||
background: #0f172a; color: #9ca3af; padding: 10px; border-radius: 8px;
|
||||
font-size: 11px; overflow: auto; max-height: 220px;
|
||||
}
|
||||
.edit-btn { margin-top: auto; }
|
||||
.star { color: #d8dbe3; }
|
||||
.star.on { color: #f59e0b; }
|
||||
.badge.tier-a { background: #dcfce7; color: #166534; }
|
||||
.badge.tier-b { background: #fef9c3; color: #854d0e; }
|
||||
.badge.tier-c { background: #fee2e2; color: #991b1b; }
|
||||
.guide { background: #eef2ff; border-color: #c7d2fe; margin-bottom: 16px; }
|
||||
.modal-backdrop { position: fixed; inset: 0; background: rgba(15,23,42,.5); display: flex; justify-content: center; align-items: flex-start; padding: 40px 16px; z-index: 50; overflow: auto; }
|
||||
.modal { background: #fff; border-radius: 14px; padding: 24px; width: 100%; max-width: 720px; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user