Commit 96220e6b authored by liujiangnan's avatar liujiangnan

feat

parent 9edc2e35
```
import 'dart:async';
import 'dart:ui';
import 'package:ai_courseware/models/courseware_page_model.dart';
import 'package:ai_courseware/pages/courseware_viewer/courseware_viewer_controller.dart';
import 'package:ai_courseware/pages/courseware_viewer/models/drag_match_script_model.dart';
import 'package:ai_courseware/providers/audio_provider.dart';
import 'package:ai_courseware/services/ai_teaching/ai_teaching_service.dart';
import 'package:audioplayers/audioplayers.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
class ImagesActionsTemplate extends StatefulWidget {
final CoursewarePageModel pageData;
const ImagesActionsTemplate({super.key, required this.pageData});
@override
ImagesActionsTemplateState createState() => ImagesActionsTemplateState();
}
class ImagesActionsTemplateState extends State<ImagesActionsTemplate>
with SingleTickerProviderStateMixin {
// final PageController _pageController = PageController();
// int _currentPage = 0;
String? _activeToolType;
String? _pendingToolType;
late final AnimationController _toolAnimController = AnimationController(
vsync: this,
duration: const Duration(milliseconds: 250),
);
late final Animation<double> _toolFadeAnim = CurvedAnimation(
parent: _toolAnimController,
curve: Curves.easeOut,
reverseCurve: Curves.easeIn,
);
// AI 教学服务
CoursewareViewerController get _controller =>
Get.find<CoursewareViewerController>();
// AI 事件订阅
StreamSubscription<AITeachingEvent>? _aiEventSubscription;
// 音频相关
AudioProvider get _audioProvider => Get.find<AudioProvider>();
AudioPlayer get _audioPlayer => _audioProvider.audioPlayer;
Duration _position = Duration.zero;
bool _isPlaying = false;
// 歌词滚动
final ScrollController _lyricsScrollController = ScrollController();
int _activeWordIndex = -1;
// 当前 action 索引
int _currentActionIndex = 0;
int? _selectedChoiceIndex;
// 提示文字
String? _hintText;
// 是否需要下一题
bool _isNeedNextAction = false;
// ==================== 数据源 ====================
// List<Map<String, dynamic>> get _pages {
// final pages = widget.pageData.content['page'] as List?;
// return pages?.cast<Map<String, dynamic>>() ?? [];
// }
String get _image => widget.pageData.content['image'] as String? ?? '';
List<Map<String, dynamic>> get _currentActions {
final actions = widget.pageData.content['action'] as List?;
return actions?.cast<Map<String, dynamic>>() ?? [];
}
Map<String, dynamic>? get _currentAction {
if (_currentActionIndex >= _currentActions.length) return null;
return _currentActions[_currentActionIndex];
}
String? get _currentActionType => _currentAction?['type'] as String?;
// 从当前 lyrics action 中获取音频和歌词数据
String? get _audioUrl {
final action = _currentAction;
if (action == null || action['type'] != 'lyrics') return null;
final content = action['content'] as List?;
if (content == null || content.isEmpty) return null;
return (content[0] as Map<String, dynamic>)['audio_url'] as String?;
}
List<Map<String, dynamic>> get _points {
final action = _currentAction;
if (action == null || action['type'] != 'lyrics') return [];
final content = action['content'] as List?;
if (content == null || content.isEmpty) return [];
final points = (content[0] as Map<String, dynamic>)['points'] as List?;
return points?.cast<Map<String, dynamic>>() ?? [];
}
// 从当前 text action 中获取文本
String get _questionText {
final action = _currentAction;
if (action == null) return '';
return action['text'] as String? ?? action['question'] as String? ?? '';
}
// 从当前 choice action 中获取选项
List<Map<String, dynamic>> get _choiceOptions {
final action = _currentAction;
if (action == null || action['type'] != 'choice') return [];
final options = action['options'] as List?;
return options?.cast<Map<String, dynamic>>() ?? [];
}
String get _choiceQuestion {
final action = _currentAction;
if (action == null) return '';
return action['question'] as String? ?? '';
}
@override
void initState() {
super.initState();
debugPrint('📢 ImagesActionsTemplate: initState');
// 重置状态,确保每次初始化时都是干净的状态
_activeToolType = null;
_pendingToolType = null;
_toolAnimController.reset();
_toolAnimController.addStatusListener(_onToolAnimStatus);
_setupAIEventListener();
_audioPlayer.onPositionChanged.listen((pos) {
if (mounted) setState(() => _position = pos);
});
_audioPlayer.onPlayerStateChanged.listen((state) {
if (!_isCurrentPage) return;
if (mounted) {
final wasPlaying = _isPlaying;
setState(() => _isPlaying = state == PlayerState.playing);
// 音频播放完成时,通知 AI 老师走下一步
if (wasPlaying && state == PlayerState.completed) {
_onAudioPlaybackComplete();
}
}
});
// 没有 AI 脚本时,初始显示第一个 action
WidgetsBinding.instance.addPostFrameCallback((_) {
// final script = widget.pageData.script;
// if (script == null || script.isEmpty) {
_showCurrentAction();
// }
});
}
/// 音频播放完成回调
void _onAudioPlaybackComplete() {
debugPrint('📢 ImagesActionsTemplate: 音频播放完成,通知 AI 老师');
// 通知 AI 服务音频播放完成,触发下一步
_controller.aiTeachingService.proceedToNextStep();
// 下一题
nextAction();
}
/// 设置 AI 事件监听
void _setupAIEventListener() {
_aiEventSubscription = _controller.aiTeachingService.onEvent.listen((
event,
) {
_handleAIEvent(event);
});
}
/// 检查是否是当前页面
bool get _isCurrentPage {
final currentPageIndex = _controller.currentPageIndex.value;
final pages = _controller.pages;
if (currentPageIndex < 0 || currentPageIndex >= pages.length) return false;
return pages[currentPageIndex].id == widget.pageData.id;
}
// bool isFirstShowQues = false;
/// 处理 AI 事件
void _handleAIEvent(AITeachingEvent event) {
// 只处理当前页面的事件
if (!_isCurrentPage) return;
switch (event.type) {
// case AITeachingEventType.stepStarted:
// // if (isFirstShowQues == true) {
// // return;
// // }
// // if (isFirstShowQues == false) {
// // isFirstShowQues = true;
// // }
// _showCurrentAction();
// break;
case AITeachingEventType.speakingFinished:
_onAISpeakingFinished(event);
break;
// case AITeachingEventType.waitingForSpeech:
// // query/question 类型:AI 等待用户说话时弹出题目
// _showCurrentAction();
// break;
// case AITeachingEventType.waitingForAction:
// _showCurrentAction();
// break;
case AITeachingEventType.llmResponseReceived:
_onLLMResponseReceived(event);
break;
case AITeachingEventType.hesitationDetected:
_onHesitationDetected(event);
break;
case AITeachingEventType.allCompleted:
_onAllCompleted();
break;
default:
break;
}
}
void _onLLMResponseReceived(AITeachingEvent event) {
// 下次说完话 就转下一题
_isNeedNextAction = true;
}
/// 超时事件处理
void _onHesitationDetected(AITeachingEvent event) {
debugPrint('📢 ImagesActionsTemplate: 检测到超时,设置 needNextAction = true');
// 超时时,下次说完话就转下一题
_isNeedNextAction = true;
}
/// AI 说话结束时
void _onAISpeakingFinished(AITeachingEvent event) {
final step = event.data as ScriptStep?;
if (step == null) return;
if (_isNeedNextAction) {
_isNeedNextAction = false;
nextAction();
return;
}
switch (step.type) {
case 'listen_audio':
_showCurrentAction();
// showTool('lyrics');
// 下一题
// nextAction();
break;
// case 'question':
// showTool('question');
// break;
}
}
/// AI 教学全部完成时的回调
void _onAllCompleted() {
debugPrint('📢 ImagesActionsTemplate: AI 教学全部完成');
_controller.markPageCompleted();
}
void _onToolAnimStatus(AnimationStatus status) {
if (status == AnimationStatus.dismissed) {
if (_pendingToolType != null) {
final pendingType = _pendingToolType;
setState(() => _activeToolType = pendingType);
_pendingToolType = null;
_toolAnimController.forward();
// 如果是歌词模式,自动开始播放音频
if (pendingType == 'lyrics' &&
_audioUrl != null &&
_audioUrl!.isNotEmpty) {
WidgetsBinding.instance.addPostFrameCallback((_) {
_audioProvider.playUrl(_audioUrl!);
});
}
} else {
setState(() => _activeToolType = null);
}
}
}
@override
void dispose() {
debugPrint('📢 ImagesActionsTemplate: dispose');
_aiEventSubscription?.cancel();
_toolAnimController.removeStatusListener(_onToolAnimStatus);
_toolAnimController.dispose();
// _pageController.dispose();
_lyricsScrollController.dispose();
super.dispose();
}
// ==================== 底部工具栏显示控制 ====================
void showTool(String type) {
debugPrint('📢 ImagesActionsTemplate: showTool: $type');
if (_activeToolType == type && _toolAnimController.isCompleted) {
return;
}
debugPrint('📢 ImagesActionsTemplate: _activeToolType: $_activeToolType');
debugPrint(
'📢 ImagesActionsTemplate: _toolAnimController.isCompleted: ${_toolAnimController.isCompleted}',
);
debugPrint('📢 ImagesActionsTemplate: _pendingToolType: $_pendingToolType');
debugPrint(
'📢 ImagesActionsTemplate: _toolAnimController.isDismissed: ${_toolAnimController.isDismissed}',
);
if (_activeToolType != null && _activeToolType != type) {
_pendingToolType = type;
if (!_toolAnimController.isDismissed) {
_toolAnimController.reverse();
} else {
_onToolAnimStatus(AnimationStatus.dismissed);
}
return;
}
setState(() => _activeToolType = type);
_toolAnimController.forward();
// 如果是歌词模式,自动开始播放音频
if (type == 'lyrics' && _audioUrl != null && _audioUrl!.isNotEmpty) {
WidgetsBinding.instance.addPostFrameCallback((_) {
_audioProvider.playUrl(_audioUrl!);
});
}
}
void hideTool() {
if (_activeToolType == null) return;
_pendingToolType = null;
_toolAnimController.reverse();
}
void showHint(String text) {
setState(() => _hintText = text);
}
void clearHint() {
setState(() => _hintText = null);
}
// ==================== Action 控制 ====================
void _showCurrentAction() {
final type = _currentActionType;
if (type != null) {
final toolType =
(type == 'query' || type == 'reading') ? 'question' : type;
showTool(toolType);
} else {
hideTool();
}
}
void nextAction() {
if (_currentActionIndex < _currentActions.length - 1) {
setState(() {
_currentActionIndex++;
_selectedChoiceIndex = null;
_activeWordIndex = -1;
_hintText = null;
});
_showCurrentAction();
}
}
void previousAction() {
if (_currentActionIndex > 0) {
setState(() {
_currentActionIndex--;
_selectedChoiceIndex = null;
_activeWordIndex = -1;
});
_showCurrentAction();
}
}
// ==================== 音频控制 ====================
Future<void> _toggleAudio() async {
if (_audioUrl == null || _audioUrl!.isEmpty) return;
if (_isPlaying) {
await _audioPlayer.pause();
} else {
await _audioProvider.playUrl(_audioUrl!);
}
}
// ==================== 选择题回调 ====================
void _onChoiceTap(int index) {
if (_selectedChoiceIndex != null) return;
setState(() => _selectedChoiceIndex = index);
final options = _choiceOptions;
final correctIndex = options.indexWhere((o) => o['isCorrect'] == true);
final isCorrect = index == correctIndex;
if (isCorrect) {
// 通知 controller 用户答对
_controller.onTemplateCorrect(index, correctIndex);
} else {
// 通知 controller 用户答错
_controller.onTemplateWrong(index, correctIndex);
}
}
@override
Widget build(BuildContext context) {
return Stack(
fit: StackFit.expand,
children: [
_buildImage(),
if (_activeToolType != null) _buildAnimatedBottomToolOverlay(),
],
);
}
// ==================== 底层:可翻页图片 ====================
Widget _buildImage() {
return ClipRect(
child: Image.network(
_image,
fit: BoxFit.fitHeight,
width: double.infinity,
height: double.infinity,
),
);
}
// ==================== 底部弹出工具栏 ====================
Widget _buildAnimatedBottomToolOverlay() {
return Positioned(
left: 0,
right: 0,
bottom: 0,
child: FadeTransition(
opacity: _toolFadeAnim,
child: SlideTransition(
position: Tween<Offset>(
begin: const Offset(0, 0.3),
end: Offset.zero,
).animate(_toolFadeAnim),
child: _buildToolContent(),
),
),
);
}
Widget _buildToolContent() {
switch (_activeToolType) {
case 'lyrics':
return _buildLyricsTool();
case 'question':
return _buildQuestionTool();
case 'choice':
return _buildChoiceTool();
default:
return const SizedBox.shrink();
}
}
// ==================== 工具子组件:歌词 ====================
Widget _buildLyricsTool() {
return Container(
width: double.infinity,
height: 110.w,
padding: EdgeInsets.symmetric(horizontal: 16.w, vertical: 15.w),
color: const Color(0xFFF6FBFF),
child: Row(
children: [
// 左侧喇叭图标
GestureDetector(
onTap: _toggleAudio,
child: Container(
width: 90.w,
height: 60.w,
margin: EdgeInsets.only(top: 12.w, right: 12.w),
child: Image.asset(
'packages/ai_courseware/assets/images/template/yile/yile_player.png',
fit: BoxFit.contain,
),
),
),
// 右侧歌词区域
Expanded(
child: ScrollConfiguration(
behavior: ScrollConfiguration.of(
context,
).copyWith(scrollbars: false),
child: RawScrollbar(
controller: _lyricsScrollController,
thumbVisibility: true,
thickness: 6.w,
radius: Radius.circular(3.w),
thumbColor: const Color(0xFFEF4444),
trackVisibility: true,
trackColor: const Color(0xFFE0E0E0),
trackRadius: Radius.circular(3.w),
padding: EdgeInsets.only(left: 8.w),
child: SingleChildScrollView(
controller: _lyricsScrollController,
child: _buildLyricsRichText(),
),
),
),
),
],
),
);
}
List<Map<String, dynamic>> get _allWords {
final result = <Map<String, dynamic>>[];
for (final point in _points) {
final words = (point['words'] as List?) ?? [];
for (final w in words) {
result.add(w as Map<String, dynamic>);
}
}
return result;
}
Widget _buildLyricsRichText() {
final posMs = _position.inMilliseconds;
final words = _allWords;
final spans = <InlineSpan>[];
int newActiveIndex = -1;
for (int i = 0; i < words.length; i++) {
final w = words[i];
final word = w['word'] as String? ?? '';
final startMs = ((w['start'] as num?) ?? 0) * 1000;
final endMs = ((w['end'] as num?) ?? 0) * 1000;
final isActive = posMs >= startMs && posMs < endMs;
final isPassed = posMs >= endMs;
if (isActive) newActiveIndex = i;
spans.add(
TextSpan(
text: '$word ',
style: TextStyle(
fontSize: 32.sp,
fontWeight: FontWeight.w600,
height: 1.2,
color:
(isActive || isPassed)
? const Color(0xFFFF8C00)
: const Color(0xFF333333),
),
),
);
}
if (newActiveIndex != _activeWordIndex && newActiveIndex >= 0) {
_activeWordIndex = newActiveIndex;
WidgetsBinding.instance.addPostFrameCallback((_) {
_scrollToActiveWord(newActiveIndex, words.length);
});
}
return RichText(text: TextSpan(children: spans), maxLines: null);
}
void _scrollToActiveWord(int activeIndex, int totalWords) {
if (!_lyricsScrollController.hasClients || totalWords <= 0) return;
final maxScroll = _lyricsScrollController.position.maxScrollExtent;
if (maxScroll <= 0) return;
final viewportHeight = _lyricsScrollController.position.viewportDimension;
final totalContentHeight = maxScroll + viewportHeight;
final estimatedPosition = totalContentHeight * (activeIndex / totalWords);
final target = (estimatedPosition - viewportHeight * 0.55).clamp(
0.0,
maxScroll,
);
if (target > _lyricsScrollController.offset ||
(_lyricsScrollController.offset - target).abs() >
viewportHeight * 0.5) {
_lyricsScrollController.animateTo(
target,
duration: const Duration(milliseconds: 300),
curve: Curves.easeOut,
);
}
}
// ==================== 公共底部工具面板 ====================
Widget _buildActionPanel({required String title, required Widget content}) {
return SizedBox(
width: double.infinity,
child: Stack(
clipBehavior: Clip.none,
children: [
Padding(
padding: EdgeInsets.only(top: 40.w),
child: ClipRect(
child: BackdropFilter(
filter: ImageFilter.blur(sigmaX: 10, sigmaY: 10),
child: Container(
width: double.infinity,
constraints: BoxConstraints(minHeight: 110.w),
padding: EdgeInsets.symmetric(
horizontal: 24.w,
vertical: 16.w,
),
alignment: Alignment.centerLeft,
decoration: BoxDecoration(
color: const Color(0xFFF47931).withValues(alpha: 0.80),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
title,
style: TextStyle(
fontSize: 32.sp,
fontWeight: FontWeight.w600,
color: Colors.white,
),
),
SizedBox(height: 16.w),
content,
],
),
),
),
),
),
Positioned(
top: 15.w,
left: 0,
child: Container(
width: 140.w,
height: 50.w,
padding: EdgeInsets.only(left: 60.w),
decoration: BoxDecoration(
gradient: const LinearGradient(
colors: [Color(0xFFFF9E3A), Color(0xFFFF4A4D)],
),
borderRadius: BorderRadius.only(
topLeft: Radius.circular(12.w),
topRight: Radius.circular(12.w),
bottomRight: Radius.circular(12.w),
),
),
alignment: Alignment.centerLeft,
child: Text(
'${_currentActionIndex + 1}/${_currentActions.length}',
style: TextStyle(
fontSize: 26.sp,
fontWeight: FontWeight.w600,
color: Colors.white,
),
),
),
),
Positioned(
top: 0,
left: 0,
child: Image.asset(
_currentActionType == 'reading'
? 'packages/ai_courseware/assets/images/template/yile/mic.png'
: 'packages/ai_courseware/assets/images/template/yile/question.png',
fit: BoxFit.fill,
width: 60.w,
height: 60.w,
),
),
],
),
);
}
// ==================== 工具子组件:问题 ====================
Widget _buildQuestionTool() {
return _buildActionPanel(
title: _questionText,
content:
_hintText != null
? Container(
width: double.infinity,
constraints: BoxConstraints(minHeight: 76.w),
padding: EdgeInsets.symmetric(horizontal: 20.w),
decoration: BoxDecoration(
color: Colors.white.withValues(alpha: 0.6),
borderRadius: BorderRadius.circular(16.w),
),
alignment: Alignment.centerLeft,
child: Row(
children: [
Image.asset(
'packages/ai_courseware/assets/images/template/yile/idea.png',
fit: BoxFit.contain,
width: 56.w,
height: 56.w,
),
SizedBox(width: 20.w),
Expanded(
child: Text(
_hintText!,
style: TextStyle(
fontSize: 32.sp,
fontWeight: FontWeight.w600,
color: Colors.white,
),
),
),
],
),
)
: const SizedBox.shrink(),
);
}
// ==================== 工具子组件:选择题 ====================
Widget _buildChoiceTool() {
final options = _choiceOptions;
if (options.isEmpty) return const SizedBox.shrink();
final correctIndex = options.indexWhere((o) => o['isCorrect'] == true);
return _buildActionPanel(
title: _choiceQuestion,
content: _buildChoiceOptions(options, correctIndex),
);
}
bool _shouldSingleColumn(List<Map<String, dynamic>> options) {
for (final option in options) {
final text = (option['text'] as String?) ?? '';
final wordCount = text.trim().split(RegExp(r'\s+')).length;
if (wordCount > 3 || text.length > 20) return true;
}
return false;
}
Widget _buildChoiceOptions(
List<Map<String, dynamic>> options,
int correctIndex,
) {
final singleColumn = _shouldSingleColumn(options);
final perRow =
singleColumn ? 1 : (options.length <= 3 ? options.length : 2);
final rows = <Widget>[];
for (var i = 0; i < options.length; i += perRow) {
final end = (i + perRow).clamp(0, options.length);
final rowItems = <Widget>[];
for (var j = i; j < end; j++) {
if (rowItems.isNotEmpty) rowItems.add(SizedBox(width: 12.w));
rowItems.add(
Expanded(child: _buildChoiceItem(options[j], j, correctIndex)),
);
}
final missing = perRow - (end - i);
for (var k = 0; k < missing; k++) {
rowItems.add(SizedBox(width: 12.w));
rowItems.add(const Expanded(child: SizedBox.shrink()));
}
if (rows.isNotEmpty) rows.add(SizedBox(height: 12.w));
rows.add(Row(children: rowItems));
}
return Column(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.center,
children: rows,
);
}
Widget _buildChoiceItem(
Map<String, dynamic> option,
int index,
int correctIndex,
) {
final selected = _selectedChoiceIndex == index;
final hasSelected = _selectedChoiceIndex != null;
final isCorrect = index == correctIndex;
Color bgColor = Colors.white;
Color textColor = const Color(0xFF333333);
if (hasSelected && selected) {
if (isCorrect) {
bgColor = const Color(0xFF4CAF50);
textColor = Colors.white;
} else {
bgColor = const Color(0xFFEF4444);
textColor = Colors.white;
}
}
return GestureDetector(
onTap: hasSelected ? null : () => _onChoiceTap(index),
child: Container(
height: 76.w,
padding: EdgeInsets.symmetric(horizontal: 16.w, vertical: 14.w),
decoration: BoxDecoration(
color: bgColor,
borderRadius: BorderRadius.circular(16.w),
),
alignment: Alignment.centerLeft,
child: Text(
option['text'] as String,
style: TextStyle(
fontSize: 26.sp,
fontWeight: FontWeight.w600,
color: textColor,
),
textAlign: TextAlign.center,
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
),
);
}
}
```
```
CoursewarePageModel(
id: '1',
type: CoursewareTemplateType.imagesActions,
content: {}
)
```
......@@ -283,6 +283,9 @@
<span>AI 编排脚本区</span>
<el-button type="text" size="mini" @click="toggleRightPanel">收起</el-button>
</div>
<div class="panel-actions">
<el-button type="primary" size="small" @click="handleAiGenerateDownload">AI生成</el-button>
</div>
<el-input
type="textarea"
:rows="16"
......
......@@ -596,10 +596,7 @@ Atmosphere and Colors: [Fill in content]
}
}
},
saveData: function () {
if (!window.courseware || !window.courseware.setData) {
return;
}
buildCoursewareData: function () {
var action = [];
if (this.audioPreviewUrl || (this.aiTagData && this.aiTagData.length)) {
action.push({
......@@ -626,15 +623,66 @@ Atmosphere and Colors: [Fill in content]
});
});
}
var data = {
return {
image: this.imagePreviewUrl,
action: action,
aiImageContent: this.aiImageContent,
ai_script: this.scriptText
};
// console.log('saveData payload', JSON.stringify(data, null, 2));
},
saveData: function () {
if (!window.courseware || !window.courseware.setData) {
return;
}
var data = this.buildCoursewareData();
window.courseware.setData(data, function () {}, key);
},
downloadTextFile: function (filename, text) {
var blob = new Blob([text], { type: 'text/markdown;charset=utf-8' });
var url = URL.createObjectURL(blob);
var a = document.createElement('a');
a.href = url;
a.download = filename;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
URL.revokeObjectURL(url);
},
handleAiGenerateDownload: async function () {
var _this = this;
try {
var tplRes = await fetch('./ImagesActionsTemplate.md');
if (!tplRes.ok) {
throw new Error('无法读取 ImagesActionsTemplate.md');
}
var tplText = await tplRes.text();
_this.downloadTextFile('ImagesActionsTemplate.md', tplText);
var dataRes = await fetch('./ImagesActionsTemplateData.md');
if (!dataRes.ok) {
throw new Error('无法读取 ImagesActionsTemplateData.md');
}
var dataTemplate = await dataRes.text();
var jsonPretty = JSON.stringify(this.buildCoursewareData(), null, 2);
var inner = jsonPretty.split('\n').map(function (line) {
return ' ' + line;
}).join('\n');
// 支持 content: {} 或 content: { \n } 等空对象写法
var filled = dataTemplate.replace(
/(\s*content:\s*)\{\s*\}/,
'$1{\n' + inner + '\n }'
);
if (filled === dataTemplate) {
throw new Error('ImagesActionsTemplateData.md 中未找到可替换的空 content(需为 content: {})');
}
setTimeout(function () {
_this.downloadTextFile('ImagesActionsTemplateData.md', filled);
}, 200);
this.$message.success('已开始下载两个 MD 文件');
} catch (err) {
this.$message.error((err && err.message) ? err.message : '下载失败');
}
},
validateJson: function () {
if (!this.scriptText) {
this.jsonError = '';
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment