@@ -2,7 +2,7 @@ import { observable, action } from 'mobx';
22import _ , { get , assign } from 'lodash' ;
33
44import { useTableActions } from 'mixins' ;
5- import { getProgress , getCookie } from 'utils' ;
5+ import { getProgress , getCookie , sleep } from 'utils' ;
66import { formCheck , fieldCheck } from 'config/form-check' ;
77
88import Store from '../Store' ;
@@ -38,7 +38,7 @@ class AppStore extends Store {
3838 readme : '' ,
3939 tos : '' ,
4040 icon : '' ,
41- screenshots : [ ]
41+ screenshots : ''
4242 } ;
4343
4444 @observable summaryInfo = { } ;
@@ -93,8 +93,6 @@ class AppStore extends Store {
9393
9494 @observable iconShow = '' ;
9595
96- @observable screenshotsShow = '' ;
97-
9896 // menu actions logic
9997 @observable
10098 handleApp = {
@@ -471,34 +469,46 @@ class AppStore extends Store {
471469
472470 @action
473471 uploadScreenshot = async base64Str => {
474- const { screenshots } = this . appDetail ;
475- const len = _ . isArray ( screenshots ) ? screenshots . length : 0 ;
476- if ( len >= 6 ) {
472+ const screenshotStr = _ . get ( this . appDetail , 'screenshots' , '' ) ;
473+ const screenshots = screenshotStr ? screenshotStr . split ( ',' ) : [ ] ;
474+ sequence = screenshots . length - 1 ;
475+ sequence ++ ;
476+
477+ if ( sequence >= 6 ) {
477478 return this . error ( 'MAX_UPLOAD_SCREENSHOTS' ) ;
478479 }
479480
481+ this . appDetail . screenshots = sequence === 0 ? base64Str : `${ screenshotStr } ,${ base64Str } ` ;
482+
480483 const result = await this . attachment ( {
481484 app_id : this . appDetail . app_id ,
482485 type : 'screenshot' ,
483486 attachment_content : base64Str ,
484487 sequence
485488 } ) ;
489+ await sleep ( sequence * 200 ) ;
486490
487- if ( result && result . errDetail ) {
491+ if ( result && result . err ) {
492+ sequence -- ;
488493 return false ;
489494 }
490-
491- sequence ++ ;
492- if ( _ . isArray ( screenshots ) ) {
493- this . appDetail . screenshots . push ( base64Str ) ;
494- } else {
495- this . appDetail . screenshots = [ base64Str ] ;
496- }
497495 } ;
498496
499497 @action
500- deleteScreenshot = ( ) => {
501- this . appDetail . screenshots = [ ] ;
498+ deleteScreenshot = async ( ) => {
499+ const screenshotStr = _ . get ( this . appDetail , 'screenshots' , '' ) ;
500+ const screenshots = screenshotStr ? screenshotStr . split ( ',' ) : [ ] ;
501+
502+ this . appDetail . screenshots = '' ;
503+ for ( let i = 0 ; i < screenshots . length ; i ++ ) {
504+ await this . attachment ( {
505+ app_id : this . appDetail . app_id ,
506+ type : 'screenshot' ,
507+ attachment_content : '' ,
508+ sequence : 0
509+ } ) ;
510+ await sleep ( 200 ) ;
511+ }
502512 } ;
503513
504514 @action
0 commit comments