1
This commit is contained in:
@@ -1,17 +1,30 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter_easyloading/flutter_easyloading.dart';
|
||||
import 'package:plan/api/dto/plan_detail_dto.dart';
|
||||
import 'package:plan/api/endpoints/plan_api.dart';
|
||||
import 'package:plan/utils/stream.dart';
|
||||
|
||||
class PlanDetailStore extends ChangeNotifier {
|
||||
///构造函数
|
||||
PlanDetailStore({
|
||||
this.planContent = "",
|
||||
this.planId = "",
|
||||
bool showRoleTalk = true,
|
||||
}) : _showRoleTalk = showRoleTalk;
|
||||
required this.scrollController,
|
||||
}) {
|
||||
//如果没有id进行初始化
|
||||
if (planId == "0") {
|
||||
createPlan();
|
||||
}else{
|
||||
//获取详情
|
||||
getPlanDetail();
|
||||
}
|
||||
}
|
||||
|
||||
///滚动控制器
|
||||
ScrollController scrollController;
|
||||
|
||||
///角色话语是否显示
|
||||
bool _showRoleTalk = true;
|
||||
bool _showRoleTalk = false;
|
||||
|
||||
bool get showRoleTalk => _showRoleTalk;
|
||||
|
||||
@@ -27,11 +40,123 @@ class PlanDetailStore extends ChangeNotifier {
|
||||
String planId = "";
|
||||
|
||||
///计划详情
|
||||
PlanDetailDto planDetail = PlanDetailDto();
|
||||
PlanDetailDto planDetail = PlanDetailDto(summary: "计划详情");
|
||||
|
||||
///流请求工具
|
||||
StreamUtils streamUtils = StreamUtils();
|
||||
|
||||
///创建计划
|
||||
void createPlan() async {
|
||||
var id = await initPlanApi(planContent, 1);
|
||||
planId = id.toString();
|
||||
// planId = "3";
|
||||
|
||||
///生成摘要---------------------------
|
||||
String summary = "";
|
||||
streamUtils.sendStream(
|
||||
"/plan/make_summary",
|
||||
data: {"plan_id": planId},
|
||||
onCall: (chunk) {
|
||||
summary = chunk['text'];
|
||||
},
|
||||
onEnd: () {
|
||||
planDetail.summary = summary;
|
||||
notifyListeners();
|
||||
},
|
||||
);
|
||||
|
||||
/// 生成对白-------------------------------
|
||||
String dialog = "";
|
||||
await streamUtils.sendStream(
|
||||
"/plan/make_dialog",
|
||||
data: {"plan_id": planId},
|
||||
onCall: (chunk) {
|
||||
dialog = chunk['text'];
|
||||
},
|
||||
onEnd: () {
|
||||
planDetail.dialog = dialog;
|
||||
notifyListeners();
|
||||
},
|
||||
);
|
||||
|
||||
/// 生成步骤-------------------------------
|
||||
await streamUtils.sendStream(
|
||||
"/plan/make_step",
|
||||
data: {"plan_id": planId},
|
||||
onCall: (chunk) {
|
||||
final text = chunk['text'].toString();
|
||||
|
||||
// 拆分出完整句子(以 [NEXT] 结尾)
|
||||
List<String> sentences = text
|
||||
.split("\n")
|
||||
.where((e) => e.contains("[NEXT]"))
|
||||
.map((e) => e.replaceAll("[NEXT]", "").trim())
|
||||
.toList();
|
||||
|
||||
// 直接覆盖 stepsList
|
||||
planDetail.stepsList = sentences.map((s) => PlanStepDto(stepContent: s)).toList();
|
||||
notifyListeners();
|
||||
},
|
||||
);
|
||||
|
||||
/// 生成步骤解释 -------------------------------
|
||||
await streamUtils.sendStream(
|
||||
"/plan/make_step_explain",
|
||||
data: {
|
||||
"plan_id": planId,
|
||||
"steps": planDetail.stepsList.map((e) => e.toJson()).toList(),
|
||||
},
|
||||
onCall: (chunk) {
|
||||
final text = chunk['text'].toString();
|
||||
List<String> sentences = text
|
||||
.split("\n")
|
||||
.where((e) => e.contains("[NEXT]"))
|
||||
.map((e) => e.replaceAll("[NEXT]", "").trim())
|
||||
.toList();
|
||||
for (int i = 0; i < sentences.length; i++) {
|
||||
planDetail.stepsList[i] = planDetail.stepsList[i]..stepExplain = sentences[i];
|
||||
}
|
||||
notifyListeners();
|
||||
},
|
||||
onEnd: () {},
|
||||
);
|
||||
|
||||
/// 生成建议 ------------------
|
||||
await streamUtils.sendStream(
|
||||
"/plan/make_suggestion",
|
||||
data: {
|
||||
"plan_id": planId,
|
||||
"steps": planDetail.stepsList.map((e) => e.toJson()).toList(),
|
||||
},
|
||||
onCall: (chunk) {
|
||||
final text = chunk['text'].toString();
|
||||
List<String> sentences = text
|
||||
.split("\n")
|
||||
.where((e) => e.contains("[NEXT]"))
|
||||
.map((e) => e.replaceAll("[NEXT]", "").trim())
|
||||
.toList();
|
||||
planDetail.suggestionsList = sentences;
|
||||
notifyListeners();
|
||||
},
|
||||
);
|
||||
await savePlan();
|
||||
}
|
||||
|
||||
///保存计划
|
||||
Future<void> savePlan() async {
|
||||
await savePlanApi(
|
||||
planId: planId,
|
||||
summary: planDetail.summary ?? "",
|
||||
dialog: planDetail.dialog ?? "",
|
||||
steps: planDetail.stepsList,
|
||||
suggestions: planDetail.suggestionsList,
|
||||
);
|
||||
EasyLoading.showToast("计划创建成功");
|
||||
}
|
||||
|
||||
///获取详情
|
||||
Future<void> getPlanDetail() async {
|
||||
planDetail = await getPlanDetailApi(planId);
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user