feat: add product factors step one analysis

dev-QQq
chenyuan 3 weeks ago
parent 9041939c82
commit bead15769f

@ -201,3 +201,39 @@ export function checkNewProductSurveyStepFour(form) {
headers: { repeatSubmit: false }, headers: { repeatSubmit: false },
}); });
} }
const productDevelopmentFactorsStepOneDimensions = ["用户需求真实性", "产品体验闭环", "生态与兼容"];
function validateProductDevelopmentFactorsStepOneDemo(payload) {
const factors = Array.isArray(payload?.factors) ? payload.factors : [];
if (factors.length !== productDevelopmentFactorsStepOneDimensions.length) {
throw new Error("请完成用户需求真实性、产品体验闭环和生态与兼容分析");
}
const dimensions = factors.map((factor) => String(factor?.dimension || "").trim());
if (new Set(dimensions).size !== productDevelopmentFactorsStepOneDimensions.length
|| productDevelopmentFactorsStepOneDimensions.some((dimension) => !dimensions.includes(dimension))) {
throw new Error("提交的分析维度不完整或重复");
}
const incompleteFactor = factors.find((factor) => !String(factor?.successAnalysis || "").trim()
|| !String(factor?.failedAnalysis || "").trim());
if (incompleteFactor) {
throw new Error(`请完成${incompleteFactor.dimension || "该项"}的成功产品和失败产品分析`);
}
return { valid: true, message: "校验通过" };
}
export function checkProductDevelopmentFactorsStepOne(payload) {
if (isStudentDemo()) {
try {
return Promise.resolve({ code: 200, data: validateProductDevelopmentFactorsStepOneDemo(payload) });
} catch (error) {
return Promise.reject(error);
}
}
return request({
url: "/api/student-training-answers/product-development-factors/step-1/validate",
method: "post",
data: payload,
headers: { repeatSubmit: false },
});
}

@ -49,16 +49,8 @@
</div> </div>
</div> </div>
<div class="product-entry"> <template v-if="currentStep === 0">
<label class="product-field"> <p class="factor-intro">用户角度分析填写下表</p>
<span>成功产品</span>
<input v-model="form.successProduct" class="input-field input-single" placeholder="填写上一实训任务中的成功产品" />
</label>
<label class="product-field">
<span>失败产品</span>
<input v-model="form.failedProduct" class="input-field input-single" placeholder="填写一个失败产品案例" />
</label>
</div>
<div class="training-table-wrap"> <div class="training-table-wrap">
<table class="factor-table"> <table class="factor-table">
@ -78,14 +70,14 @@
<textarea <textarea
v-model="row.successAnalysis" v-model="row.successAnalysis"
class="table-textarea" class="table-textarea"
placeholder="填写成功产品在该维度的表现" placeholder="填写成功产品在该维度的分析"
/> />
</td> </td>
<td> <td>
<textarea <textarea
v-model="row.failedAnalysis" v-model="row.failedAnalysis"
class="table-textarea" class="table-textarea"
placeholder="填写失败产品在该维度的问题" placeholder="填写失败产品在该维度的分析"
/> />
</td> </td>
</tr> </tr>
@ -94,36 +86,38 @@
</div> </div>
<div class="task-actions"> <div class="task-actions">
<button type="button" class="btn-nav btn-save" :disabled="saving" @click="saveCurrentProgress"> <button type="button" class="btn-nav btn-submit" :disabled="saving" @click="saveAndGoToStepTwo">
<el-icon><CircleCheck /></el-icon> 保存并进入第 2
保存当前进度
</button>
<button type="button" class="btn-nav btn-submit" :disabled="saving" @click="submitTask">
提交任务
</button> </button>
<button type="button" class="btn-nav" :disabled="saving" @click="resetTraining"> <button type="button" class="btn-nav" :disabled="saving" @click="resetTraining">
<el-icon><RefreshLeft /></el-icon> <el-icon><RefreshLeft /></el-icon>
清空填写 清空填写
</button> </button>
</div> </div>
</template>
<div v-else class="step-placeholder">
<p> {{ currentStep + 1 }} 步内容待配置</p>
<span> 1 步分析已保存可从上方步骤栏返回查看</span>
</div>
</section> </section>
</section> </section>
</main> </main>
<TrainingAiSidebar <TrainingAiSidebar
study-tip="当前任务建议:先选定一个成功产品和一个失败产品,再围绕八个维度逐项补充证据。" study-tip="当前任务请从用户角度对成功与失败产品完成三项对比分析。"
reference-title="关键因素分析参考" reference-title="关键因素分析参考"
reference-text="· 用户需求真实性:是否高频、真实、可付费<br />· 产品体验闭环:是否易用、稳定、反馈清晰<br />· 技术与商业可行:技术、合规、成本、生态是否支撑落地" reference-text="· 用户需求真实性:是否高频、真实、可付费<br />· 产品体验闭环:是否易用、稳定、反馈清晰<br />· 生态与兼容:是否支持主流平台与生态扩展"
assist-text="建议把上一任务的产品调研信息引用到成功产品列,再为失败产品补充真实市场反馈或用户评价。" assist-text="请围绕每项评估要求,分别说明成功产品与失败产品的表现。"
:progress-items="progressItems" :progress-items="progressItems"
/> />
</div> </div>
</template> </template>
<script setup> <script setup>
import { CircleCheck, Download, Operation, RefreshLeft } from "@element-plus/icons-vue"; import { Download, Operation, RefreshLeft } from "@element-plus/icons-vue";
import { getTrainingTaskByKey } from "@/api/trainingTask"; import { getTrainingTaskByKey } from "@/api/trainingTask";
import { getStudentTrainingAnswer, saveStudentTrainingAnswer } from "@/api/studentTrainingAnswer"; import { checkProductDevelopmentFactorsStepOne, getStudentTrainingAnswer, saveStudentTrainingAnswer } from "@/api/studentTrainingAnswer";
import useUserStore from "@/store/modules/user"; import useUserStore from "@/store/modules/user";
import TrainingAiSidebar from "@/views/components/TrainingAiSidebar.vue"; import TrainingAiSidebar from "@/views/components/TrainingAiSidebar.vue";
import TrainingMaterialButton from "@/views/components/TrainingMaterialButton.vue"; import TrainingMaterialButton from "@/views/components/TrainingMaterialButton.vue";
@ -161,70 +155,33 @@ const taskGoals = computed(() => parseArray(taskConfig.value?.objectives, defaul
const taskRequirement = computed(() => taskConfig.value?.requirements || defaultTask.requirement); const taskRequirement = computed(() => taskConfig.value?.requirements || defaultTask.requirement);
const trainingSteps = computed(() => parseArray(taskConfig.value?.steps, []).slice(0, 4)); const trainingSteps = computed(() => parseArray(taskConfig.value?.steps, []).slice(0, 4));
const form = ref({ const STEP_ONE_FACTOR_ROWS = [
successProduct: "",
failedProduct: "",
});
const createFactorRows = () => [
{ {
dimension: "用户需求真实性", dimension: "用户需求真实性",
criteria: "是否解决真实、高频、可付费的痛点,用户愿为该功能支付溢价,非“技术炫技”或“伪需求”", criteria: "是否解决真实、高频、可付费的痛点,用户愿为该功能支付溢价,非“技术炫技”或“伪需求”",
successAnalysis: "",
failedAnalysis: "",
}, },
{ {
dimension: "产品体验闭环", dimension: "产品体验闭环",
criteria: "操作是否无需说明书,“零学习成本”?是否操作简单、反馈明确、稳定性高", criteria: "操作是否无需说明书,“零学习成本”?是否操作简单、反馈明确、稳定性高",
successAnalysis: "",
failedAnalysis: "",
},
{
dimension: "技术应用",
criteria: "核心技术是否已成熟、可量产避免使用实验室级原型如未验证的AI模型",
successAnalysis: "",
failedAnalysis: "",
},
{
dimension: "合规与认证",
criteria:
"是否通过目标市场强制认证目标市场要求的产品资质、检测报告等中国CCC美国FCC欧盟CE出口需符合RoHS、REACH。是否规避专利与知识产权风险",
successAnalysis: "",
failedAnalysis: "",
},
{
dimension: "供应链与成本控制",
criteria: "BOM成本是否可控是否支持规模化是否具备备选供应链关键元器件如芯片、传感器有≥2家可替换供应商",
successAnalysis: "",
failedAnalysis: "",
},
{
dimension: "商业模式",
criteria:
"盈利模式是否清晰硬件销售利润率≥50%或有订阅服务如云存储、AI功能包。是否构建“数据-反馈-迭代”闭环?产品使用数据可回传,驱动功能优化与新版本开发",
successAnalysis: "",
failedAnalysis: "",
},
{
dimension: "市场反馈",
criteria: "是否处于需求上升期?功能、设计、服务、品牌是否有差异化壁垒?用户是否高留存、高互动、低退货?",
successAnalysis: "",
failedAnalysis: "",
}, },
{ {
dimension: "生态与兼容", dimension: "生态与兼容",
criteria: criteria:
"是否能接入主流平台是否支持iOS/Android、HomeKit、米家、Alexa等生态是否支持第三方开发者扩展提供API或SDK鼓励生态共建", "是否能接入主流平台是否支持iOS/Android、HomeKit、米家、Alexa等生态是否支持第三方开发者扩展提供API或SDK鼓励生态共建",
successAnalysis: "",
failedAnalysis: "",
}, },
]; ];
const createFactorRows = () => STEP_ONE_FACTOR_ROWS.map((row) => ({
...row,
successAnalysis: "",
failedAnalysis: "",
}));
const factorRows = ref(createFactorRows()); const factorRows = ref(createFactorRows());
const progressItems = [ const progressItems = [
{ text: "进行中:成功/失败产品对比", status: "doing" }, { text: "进行中:成功/失败产品对比", status: "doing" },
{ text: "进行中:八个关键因素分析", status: "doing" }, { text: "进行中:三项关键因素分析", status: "doing" },
{ text: "待完成:导出实训成果", status: "" }, { text: "待完成:导出实训成果", status: "" },
]; ];
@ -259,6 +216,7 @@ async function loadSavedAnswer() {
applySavedAnswer(answer.step1Answer); applySavedAnswer(answer.step1Answer);
clearDraft(); clearDraft();
} }
restoreCurrentStep(answer?.currentStep);
} catch (error) { } catch (error) {
// Keep local draft when the backend answer cannot be loaded. // Keep local draft when the backend answer cannot be loaded.
} }
@ -297,10 +255,6 @@ function applySavedAnswer(value) {
if (!parsed || typeof parsed !== "object") { if (!parsed || typeof parsed !== "object") {
return; return;
} }
form.value = {
successProduct: parsed.successProduct || "",
failedProduct: parsed.failedProduct || "",
};
if (Array.isArray(parsed.factors)) { if (Array.isArray(parsed.factors)) {
const savedByDimension = parsed.factors.reduce((map, row) => { const savedByDimension = parsed.factors.reduce((map, row) => {
if (row?.dimension) { if (row?.dimension) {
@ -316,6 +270,14 @@ function applySavedAnswer(value) {
} }
} }
function restoreCurrentStep(savedStep) {
const stepNumber = Number(savedStep);
const targetIndex = stepNumber - 1;
if (Number.isInteger(stepNumber) && targetIndex >= 0 && targetIndex < trainingSteps.value.length) {
currentStep.value = targetIndex;
}
}
function persistDraft() { function persistDraft() {
if (!draftReady.value) return; if (!draftReady.value) return;
try { try {
@ -347,8 +309,6 @@ function clearDraft() {
function buildOutcome() { function buildOutcome() {
return { return {
title: taskTitle.value, title: taskTitle.value,
successProduct: form.value.successProduct,
failedProduct: form.value.failedProduct,
factors: factorRows.value.map((row) => ({ factors: factorRows.value.map((row) => ({
dimension: row.dimension, dimension: row.dimension,
criteria: row.criteria, criteria: row.criteria,
@ -358,53 +318,52 @@ function buildOutcome() {
}; };
} }
function buildAnswerPayload(saveAction = "SAVE") { function buildStepOneValidationPayload() {
return {
factors: factorRows.value.map(({ dimension, successAnalysis, failedAnalysis }) => ({
dimension,
successAnalysis,
failedAnalysis,
})),
};
}
function buildAnswerPayload(saveAction = "SAVE", persistedStep = currentStep.value + 1) {
return { return {
step1Answer: JSON.stringify(buildOutcome()), step1Answer: JSON.stringify(buildOutcome()),
currentStep: 1, currentStep: persistedStep,
submitted: false, submitted: false,
saveAction, saveAction,
}; };
} }
async function saveCurrentProgress() { async function saveAndGoToStepTwo() {
if (saving.value) return; if (saving.value) return;
saving.value = true; saving.value = true;
try { try {
await saveStudentTrainingAnswer(TASK_KEY, buildAnswerPayload("SAVE")); await checkProductDevelopmentFactorsStepOne(buildStepOneValidationPayload());
await saveStudentTrainingAnswer(TASK_KEY, buildAnswerPayload("SAVE", 2));
clearDraft(); clearDraft();
proxy?.$modal?.msgSuccess("已保存"); if (trainingSteps.value.length < 2) {
} catch (error) { proxy?.$modal?.msgSuccess("已保存,当前任务尚未配置第 2 步");
proxy?.$modal?.msgError?.("保存失败"); return;
} finally {
saving.value = false;
}
} }
currentStep.value = 1;
async function submitTask() { proxy?.$modal?.msgSuccess("已保存,已进入第 2 步");
if (saving.value) return;
saving.value = true;
try {
await saveStudentTrainingAnswer(TASK_KEY, buildAnswerPayload("SUBMIT"));
clearDraft();
proxy?.$modal?.msgSuccess("提交成功");
} catch (error) { } catch (error) {
proxy?.$modal?.msgError?.("提交失败"); proxy?.$modal?.msgError?.(error?.message || "请完成三项成功产品和失败产品分析");
} finally { } finally {
saving.value = false; saving.value = false;
} }
} }
async function resetTraining() { async function resetTraining() {
form.value = {
successProduct: "",
failedProduct: "",
};
factorRows.value = createFactorRows(); factorRows.value = createFactorRows();
currentStep.value = 0;
clearDraft(); clearDraft();
try { try {
saving.value = true; saving.value = true;
await saveStudentTrainingAnswer(TASK_KEY, buildAnswerPayload("RESET")); await saveStudentTrainingAnswer(TASK_KEY, buildAnswerPayload("RESET", 1));
} catch (error) { } catch (error) {
// Clearing the page should still work locally even when backend reset fails. // Clearing the page should still work locally even when backend reset fails.
} finally { } finally {
@ -756,24 +715,6 @@ function exportOutcome() {
line-height: 1.4; line-height: 1.4;
} }
.product-entry {
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
gap: 16px;
margin-bottom: 16px;
}
.product-field {
display: grid;
grid-template-columns: 92px minmax(0, 1fr);
align-items: center;
gap: 10px;
color: #dff5ff;
font-size: 14px;
font-weight: 800;
}
.input-field,
.table-textarea { .table-textarea {
width: 100%; width: 100%;
border: 1px solid rgba(45, 95, 126, 0.95); border: 1px solid rgba(45, 95, 126, 0.95);
@ -793,11 +734,6 @@ function exportOutcome() {
} }
} }
.input-single {
height: 42px;
padding: 0 16px;
}
.training-table-wrap { .training-table-wrap {
overflow-x: auto; overflow-x: auto;
border: 1px solid rgba(0, 180, 255, 0.22); border: 1px solid rgba(0, 180, 255, 0.22);
@ -866,6 +802,38 @@ function exportOutcome() {
line-height: 1.6; line-height: 1.6;
} }
.factor-intro {
margin: 0 0 18px;
color: #d7ecff;
font-size: 16px;
font-weight: 700;
line-height: 1.8;
}
.step-placeholder {
display: grid;
place-items: center;
min-height: 280px;
padding: 28px;
border: 1px dashed rgba(101, 207, 239, 0.42);
border-radius: 18px;
color: #b8d9ec;
background: rgba(1, 14, 26, 0.42);
text-align: center;
p {
margin: 0 0 8px;
color: #eaffff;
font-size: 20px;
font-weight: 800;
}
span {
font-size: 14px;
line-height: 1.7;
}
}
.task-actions { .task-actions {
display: flex; display: flex;
justify-content: center; justify-content: center;
@ -1024,13 +992,6 @@ function exportOutcome() {
} }
} }
.product-entry {
grid-template-columns: 1fr;
}
.product-field {
grid-template-columns: 1fr;
}
} }
.workbench-head--actions-only { .workbench-head--actions-only {
justify-content: flex-end; justify-content: flex-end;

@ -0,0 +1,23 @@
const assert = require("node:assert/strict");
const fs = require("node:fs");
const path = require("node:path");
const root = path.resolve(__dirname, "..");
const page = fs.readFileSync(path.join(root, "src/views/foundation/product-development-factors.vue"), "utf8");
const api = fs.readFileSync(path.join(root, "src/api/studentTrainingAnswer.js"), "utf8");
assert.match(page, /const STEP_ONE_FACTOR_ROWS = \[/, "step one must define its fixed three rows");
assert.match(page, /用户需求真实性/, "step one must include user-demand authenticity");
assert.match(page, /产品体验闭环/, "step one must include product-experience loop");
assert.match(page, /生态与兼容/, "step one must include ecosystem compatibility");
assert.match(page, /v-if="currentStep === 0"/, "the factor table must only render on step one");
assert.match(page, /saveAndGoToStepTwo/, "step one must expose a save-and-advance action");
assert.match(page, /await checkProductDevelopmentFactorsStepOne\(buildStepOneValidationPayload\(\)\)/, "advance must validate before saving");
assert.match(page, /buildAnswerPayload\("SAVE", 2\)/, "advance must save step two progress without submitting");
assert.doesNotMatch(page, /v-model="form\.successProduct"/, "the prototype must not display a success-product name input");
assert.doesNotMatch(page, /v-model="form\.failedProduct"/, "the prototype must not display a failed-product name input");
assert.doesNotMatch(page, /buildAnswerPayload\("SUBMIT"\)/, "step one must not submit the entire task");
assert.match(api, /export function checkProductDevelopmentFactorsStepOne\(/, "the student API must expose the step-one validator");
assert.match(api, /product-development-factors\/step-1\/validate/, "the student API must call the step-one validation route");
console.log("product development factors step-one contract passed");
Loading…
Cancel
Save