Commit 5a77febf authored by chunsen's avatar chunsen

feat: 在表单组件中添加英美音标、英文定义和例句翻译字段,并优化课程ID获取逻辑

parent d5e53c2b
......@@ -70,8 +70,25 @@
<input type="text" nz-input [(ngModel)]="word.wordTranslation" (blur)="save()" style="width: 250px;">
</div>
<!-- 英式音标 -->
<div style="margin-bottom: 10px; display: flex; align-items: center;">
<span style="width: 120px; text-align: right;">英式音标:</span>
<input type="text" nz-input [(ngModel)]="word.britishPhonetic" (blur)="save()" style="width: 250px;">
</div>
<!-- 美式音标 -->
<div style="margin-bottom: 10px; display: flex; align-items: center;">
<span style="width: 120px; text-align: right;">美式音标:</span>
<input type="text" nz-input [(ngModel)]="word.americanPhonetic" (blur)="save()" style="width: 250px;">
</div>
<div style="margin-top: 20px; border-top: 1px dashed #eee; padding-top: 15px;">
<!-- 英文定义 -->
<div style="margin-bottom: 10px; display: flex; align-items: center;">
<span style="width: 120px; text-align: right;">英文定义:</span>
<input type="text" nz-input [(ngModel)]="word.englishDefinition" (blur)="save()" style="width: 250px;">
</div>
<div style="margin-top: 20px; border-top: 1px dashed #eee; padding-top: 15px;">
<div style="margin-bottom: 10px; display: flex; align-items: center;">
<span style="width: 120px; text-align: right;">
<span style="color: #ff4d4f; margin-right: 4px;">*</span>显示类型:
......@@ -96,6 +113,12 @@
<input type="text" nz-input [(ngModel)]="word.exampleSentence" (blur)="save()" style="width: 250px;">
</div>
<!-- 例句翻译 -->
<div style="margin-bottom: 10px; display: flex; align-items: center;">
<span style="width: 120px; text-align: right;">例句翻译:</span>
<input type="text" nz-input [(ngModel)]="word.exampleSentenceTranslation" (blur)="save()" style="width: 250px;">
</div>
<!-- 例句音频 -->
<div style="margin-bottom: 10px; display: flex; align-items: center;">
<span style="width: 120px; text-align: right;">例句音频:</span>
......@@ -119,33 +142,6 @@
x
</button>
</div>
<!-- 其他可选字段 -->
<div style="margin-top: 20px; border-top: 1px dashed #eee; padding-top: 15px;">
<!-- 英式音标 -->
<div style="margin-bottom: 10px; display: flex; align-items: center;">
<span style="width: 120px; text-align: right;">英式音标:</span>
<input type="text" nz-input [(ngModel)]="word.britishPhonetic" (blur)="save()" style="width: 250px;">
</div>
<!-- 美式音标 -->
<div style="margin-bottom: 10px; display: flex; align-items: center;">
<span style="width: 120px; text-align: right;">美式音标:</span>
<input type="text" nz-input [(ngModel)]="word.americanPhonetic" (blur)="save()" style="width: 250px;">
</div>
<!-- 英文定义 -->
<div style="margin-bottom: 10px; display: flex; align-items: center;">
<span style="width: 120px; text-align: right;">英文定义:</span>
<input type="text" nz-input [(ngModel)]="word.englishDefinition" (blur)="save()" style="width: 250px;">
</div>
<!-- 例句翻译 -->
<div style="margin-bottom: 10px; display: flex; align-items: center;">
<span style="width: 120px; text-align: right;">例句翻译:</span>
<input type="text" nz-input [(ngModel)]="word.exampleSentenceTranslation" (blur)="save()" style="width: 250px;">
</div>
</div>
</div>
</div>
......
......@@ -37,7 +37,8 @@ export class FormComponent implements OnInit, OnChanges, OnDestroy {
'ordinal number',
];
// 存储courseId
courseId: string = '';
constructor(private appRef: ApplicationRef, private changeDetectorRef: ChangeDetectorRef,
private message: NzMessageService) {
......@@ -61,19 +62,10 @@ export class FormComponent implements OnInit, OnChanges, OnDestroy {
ngOnInit() {
this.item = {};
// 获取父窗口URL中的courseId参数作为pictureBookId
const courseIdStr = this.getParentUrlParam('courseId');
let courseId = 0;
if (courseIdStr) {
courseId = parseInt(courseIdStr, 10);
if (isNaN(courseId)) {
courseId = 0;
}
console.log('从父窗口URL获取到courseId:', courseId);
}
// 获取课程ID
this.getCourseIdFromParent();
// 获取存储的数据
(<any>window).courseware.getData((data) => {
if (data) {
......@@ -87,15 +79,12 @@ export class FormComponent implements OnInit, OnChanges, OnDestroy {
this.initItem();
// 确保pictureBookId存在并且是整数
if (courseId > 0) {
this.item.pictureBookId = courseId;
} else if (this.item.pictureBookId) {
// 确保现有的pictureBookId是整数
const pictureBookId = parseInt(this.item.pictureBookId, 10);
this.item.pictureBookId = isNaN(pictureBookId) ? 0 : pictureBookId;
} else {
this.item.pictureBookId = 0;
// 如果有courseId,设置为pictureBookId
if (this.courseId) {
const courseIdNum = parseInt(this.courseId, 10);
if (!isNaN(courseIdNum)) {
this.item.pictureBookId = courseIdNum;
}
}
// 确保每个单词都有正确的ID(pictureBookId + 索引)
......@@ -201,7 +190,7 @@ export class FormComponent implements OnInit, OnChanges, OnDestroy {
id: 0, // 临时ID,将在ensureWordIds中设置正确的值
pictureBookId: pictureBookId,
word: '',
displayType: '3', // 默认为"核心单词"
displayType: 1, // 默认为"词卡单词"
partOfSpeech: '',
exampleSentence: '',
wordAudioUrl: '',
......@@ -318,7 +307,7 @@ export class FormComponent implements OnInit, OnChanges, OnDestroy {
id: 0, // 临时ID,将在ensureWordIds中设置正确的值
pictureBookId: pictureBookId,
word: '',
displayType: '3', // 默认为"核心单词"
displayType: 1, // 默认为"词卡单词"
partOfSpeech: '',
exampleSentence: '',
wordAudioUrl: '',
......@@ -566,6 +555,27 @@ export class FormComponent implements OnInit, OnChanges, OnDestroy {
this.message.info(`准备为题目生成音频`);
}
// 获取课程ID
getCourseIdFromParent() {
const call_back = (res) => {
console.log("courseId res: ", res);
this.courseId = res;
}
const checkAndCall = () => {
if (typeof commonPostMessageWithCallback === "function") {
commonPostMessageWithCallback(
{
action: "getCourseId",
},
call_back
);
} else {
this.message.create("error", "通信方法不可用");
}
};
checkAndCall();
}
// 生成选项音频
generateOptionAudio(option, word) {
if (!option.answer || option.answer.trim() === '') {
......
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