liuyg
2021-07-02 25ce610f6ecca7325e7a743dc032c4a76559c63d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/**
 * Created by wangjian on 16/1/20.
 */
define(['dojo/_base/declare',
  'dijit/_WidgetBase',
  'dojo/_base/lang',
  'dojo/_base/html',
  'dojo/on',
  'dojo/mouse',
  'dojo/_base/fx',
  'dojo/topic',
  'dojo/Evented'
], function(declare, _WidgetBase, lang, html, on, Mouse, baseFx, topic, Evented) {
  var ANIMATION_DURATION = 1000,
    AUTO_CLOSE_INTERVAL = 10000,
    STATE_HIDE = 0,
    STATE_SHOW = 1;
 
  return declare([_WidgetBase, Evented], {
    'baseClass': 'jimu-appstate-popup',
    declaredClass: 'jimu.dijit.AppStatePopup',
 
    currentState: STATE_HIDE,
    timeoutHandler: undefined,
 
    constructor: function(params) {
      this.inherited(arguments);
      if('animationDuration' in params) {
        ANIMATION_DURATION = params.animationDuration;
      }
 
      if('autoCloseInterval' in params) {
        AUTO_CLOSE_INTERVAL = params.autoCloseInterval;
      }
    },
 
    postCreate: function() {
      if(window.appInfo.isRunInMobile){
        html.addClass(this.domNode, 'mobile');
      }
      var header = html.create('div', {
        'class': 'appstate-header'
      });
      html.create('div', {
        'class': 'appstate-title',
        innerHTML: this.nls.title
      }, header);
      var closeNode = html.create('div', {
        'class': 'appstate-close'
      }, header);
      html.place(header, this.domNode);
      var labelNode = html.create('div', {
        'class': 'appstate-tips',
        innerHTML: this.nls.restoreMap
      });
      html.place(labelNode, this.domNode);
 
      this.own(on(labelNode, 'click', lang.hitch(this, function() {
        this.emit('applyAppState');
        this.hide();
      })));
 
      this.own(on(closeNode, 'click', lang.hitch(this, function() {
        this.hide();
      })));
 
      this.own(on(this.domNode, Mouse.enter, lang.hitch(this, function() {
        this._timerStop();
      })));
 
      this.own(on(this.domNode, Mouse.leave, lang.hitch(this, function() {
        this._timerStart();
      })));
    },
 
    show: function() {
      var animProperties;
      if(window.appInfo.isRunInMobile){
        animProperties = {
          top: {
            start: -120,
            end: 0
          }
        };
      }else {
        animProperties = {
          bottom: {
            start: -100,
            end: 10
          }
        };
      }
      baseFx.animateProperty({
        node: this.domNode,
        duration: ANIMATION_DURATION,
        properties: animProperties,
        onEnd: lang.hitch(this, function() {
          this.currentState = STATE_SHOW;
        })
      }).play();
 
      //wait for splash hide, when init
      topic.subscribe("splashPopupShow", lang.hitch(this, function () {
        this._timerStop();
      }));
      topic.subscribe("splashPopupHide", lang.hitch(this, function () {
        this._timerStart();
      }));
 
      this.timeoutHandler = setTimeout(lang.hitch(this, this.hide), AUTO_CLOSE_INTERVAL);
    },
 
    hide: function() {
      if(this.currentState === STATE_HIDE) {
        return;
      }
 
      var animProperties;
      if(window.appInfo.isRunInMobile){
        animProperties = {
          top: {
            start: 0,
            end: -120
          }
        };
      }else {
        animProperties = {
          bottom: {
            start: 10,
            end: -100
          }
        };
      }
 
      baseFx.animateProperty({
        node: this.domNode,
        duration: ANIMATION_DURATION,
        properties: animProperties,
        onEnd: lang.hitch(this, function() {
          this.currentState = STATE_HIDE;
          html.setStyle(this.domNode, 'display', 'none');
        })
      }).play();
    },
 
    _timerStart: function () {
      if (this.currentState === STATE_SHOW && !this.timeoutHandler) {
        this.timeoutHandler = setTimeout(lang.hitch(this, this.hide), AUTO_CLOSE_INTERVAL);
      }
    },
    _timerStop: function () {
      if (this.timeoutHandler) {
        clearTimeout(this.timeoutHandler);
        this.timeoutHandler = undefined;
      }
    }
  });
});