Skip to content

Commit c5d66d5

Browse files
committed
优化:试题列表中的课程名称,采用逐一加载
1 parent ae775e3 commit c5d66d5

File tree

1 file changed

+37
-18
lines changed
  • Sourcecode/Song.WebSite/Templates/OrgAdmin/Default/Question/Scripts

1 file changed

+37
-18
lines changed

Sourcecode/Song.WebSite/Templates/OrgAdmin/Default/Question/Scripts/List.js

Lines changed: 37 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ $ready(function () {
130130
},
131131
//获取课程
132132
getCourses: function (val) {
133-
var th = this;
133+
var th = this;
134134
th.loading = true;
135135
var orgid = th.organ.Org_ID;
136136
var sbjid = 0;
@@ -330,7 +330,7 @@ $ready(function () {
330330
Vue.component('course_name', {
331331
//couid:当前试题的id
332332
//courses:所有课程
333-
props: ["couid", "courses","index"],
333+
props: ["couid", "courses", "index"],
334334
data: function () {
335335
return {
336336
course: {},
@@ -340,30 +340,49 @@ $ready(function () {
340340
watch: {
341341
'couid': {
342342
handler: function (nv) {
343-
if (nv == null || nv == '') return;
344-
this.getcourse(nv);
343+
if (!$api.isnull(nv)) {
344+
if (this.index == 0) this.startInit();
345+
}
345346
}, immediate: true
346347
}
347348
},
348349
computed: {},
349350
mounted: function () { },
350351
methods: {
351-
getcourse: function (couid) {
352-
if (this.courses) {
353-
this.course = this.courses.find(item => item.Cou_ID == couid);
354-
if (this.course != undefined) return;
355-
}
352+
//初始加载
353+
startInit: function () {
354+
//加载完成,则加载后一个组件,实现逐个加载的效果
355+
this.getcourse().finally(() => {
356+
var vapp = window.vapp;
357+
var ctr = vapp.$refs['couname_' + (this.index + 1)];
358+
if (ctr != null) {
359+
window.setTimeout(
360+
ctr.startInit, 50);
361+
}
362+
});
363+
},
364+
//获取课程信息
365+
getcourse: function () {
356366
var th = this;
357-
th.loading = true;
358-
$api.cache('Course/ForID', { 'id': couid }).then(function (req) {
359-
if (req.data.success) {
360-
th.course = req.data.result;
361-
} else {
362-
console.error(req.data.exception);
363-
throw req.config.way + ' ' + req.data.message;
367+
return new Promise(function (res, rej) {
368+
if (th.courses) {
369+
th.course = th.courses.find(item => item.Cou_ID == th.couid);
370+
if (th.course != undefined) return res();
364371
}
365-
}).catch(err => console.error(err))
366-
.finally(() => th.loading = false);
372+
th.loading = true;
373+
$api.cache('Course/ForID', { 'id': th.couid }).then(function (req) {
374+
if (req.data.success) {
375+
th.course = req.data.result;
376+
} else {
377+
console.error(req.data.exception);
378+
throw req.config.way + ' ' + req.data.message;
379+
}
380+
}).catch(err => console.error(err))
381+
.finally(() => {
382+
th.loading = false;
383+
return res();
384+
});
385+
});
367386
}
368387
},
369388
template: `<span>

0 commit comments

Comments
 (0)