@@ -130,7 +130,7 @@ $ready(function () {
130
130
} ,
131
131
//获取课程
132
132
getCourses : function ( val ) {
133
- var th = this ;
133
+ var th = this ;
134
134
th . loading = true ;
135
135
var orgid = th . organ . Org_ID ;
136
136
var sbjid = 0 ;
@@ -330,7 +330,7 @@ $ready(function () {
330
330
Vue . component ( 'course_name' , {
331
331
//couid:当前试题的id
332
332
//courses:所有课程
333
- props : [ "couid" , "courses" , "index" ] ,
333
+ props : [ "couid" , "courses" , "index" ] ,
334
334
data : function ( ) {
335
335
return {
336
336
course : { } ,
@@ -340,30 +340,49 @@ $ready(function () {
340
340
watch : {
341
341
'couid' : {
342
342
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
+ }
345
346
} , immediate : true
346
347
}
347
348
} ,
348
349
computed : { } ,
349
350
mounted : function ( ) { } ,
350
351
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 ( ) {
356
366
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 ( ) ;
364
371
}
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
+ } ) ;
367
386
}
368
387
} ,
369
388
template : `<span>
0 commit comments