class SCORMAPI {
constructor() {
this.LMSInitialize = this.LMSInitializeMethod;
this.LMSGetValue = this.LMSGetValueMethod;
this.LMSSetValue = this.LMSSetValueMethod;
this.LMSCommit = this.LMSCommitMethod;
this.LMSFinish = this.LMSFinishMethod;
this.LMSGetLastError = this.LMSGetLastErrorMethod;
this.LMSGetErrorString = this.LMSGetErrorStringMethod;
this.LMSGetDiagnostic = this.LMSGetDiagnosticMethod;
}
LMSInitializeMethod() {
return 'true';
}
LMSGetValueMethod(parameter) {
console.log(`Get ${parameter} value: ` + scormData.getValue(parameter));
return scormData.getValue(parameter);
}
LMSSetValueMethod(parameter, value) {
console.log(`Set ${parameter} value ${value}: ` + scormData.setValue(parameter, value));
return scormData.setValue(parameter, value);
}
LMSCommitMethod() {
let allData = scormData.getAllData();
console.log('allData', allData);
return 'true';
}
LMSFinishMethod() {
console.log('结束通信,上传数据');
return 'true';
}
LMSGetLastErrorMethod() {
}
LMSGetErrorStringMethod() {
}
LMSGetDiagnosticMethod() {
}
}
class SCORMDataModel {
constructor() {
this.data = {
"cmi.core.student_id": "",
"cmi.core.student_name": "",
"cmi.core.lesson_location": "",
"cmi.core.score.raw": "",
"cmi.core.score.max": "",
"cmi.core.score.min": "",
"cmi.core.credit": "",
"cmi.core.lesson_status": "",
"cmi.core.session_time": "",
"cmi.core.total_time": "",
"cmi.core.exit": "",
"cmi.launch_data": "",
};
}
getValue(parameter) {
if (this.data.hasOwnProperty(parameter)) {
return this.data[parameter];
}
return "";
}
setValue(parameter, value) {
if (this.data.hasOwnProperty(parameter)) {
this.data[parameter] = value;
return 'true';
}
return 'false';
}
getAllData() {
return this.data;
}
}
let scormData = new SCORMDataModel();
var API = new SCORMAPI();
console.log('API', API);
console.log('API.LMSInitializeMethod:', API.LMSInitializeMethod());
API.LMSGetValue("cmi.core.lesson_location", 'test/index.html');
API.LMSGetValue("cmi.core.lesson_location");
API.LMSCommit();
API.LMSFinish();