File size: 11,187 Bytes
a757bd3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
<div class="conter_box active box_mail">
    <div class="bt-form">
        <div style="padding-bottom: 12px; margin-bottom: 18px; border-bottom: #ccc 1px dashed;">
            <div class="flex" style="align-item: center; height: 32px;">
                <span class="tname" style="width: 99px; line-height: 30px; padding-right: 20px; text-align: right;"><i class="total_tips">?</i>设为默认</span>
                <div>
                    <input class="btswitch btswitch-ios" id="default_setting" type="checkbox" />
                    <label style="position: relative;top: 5px;" class="btswitch-btn" for="default_setting"></label>
                </div>
            </div>
        </div>
        <div class="line">
            <div class="tab-nav recipient_nav relative">
                <span class="on" data-ctype="0" style="line-height: 30px;">收件者设置</span>
                <span data-ctype="1" style="line-height: 30px;">发送者设置</span>
            </div>
        </div>
        <div class="line recipient_view">
            <div class="line relative">
                <textarea name="recipient_textarea" class="bt-input-text mr5" type="text" style="width: 300px; height:120px; line-height:20px"></textarea>
                <div class="placeholder c9 reci_tips" style="position: absolute;top: 25px;left: 25px; display:none">每行填写一个邮箱,例:<br>xxx@163.com<br>xxx@qq.com</div>
            </div>
            <button class="btn btn-success btn-sm recipient_submit" style="/* margin-left: 100px; */">保存</button>
        </div>
        <div class="line sender_view" style="display:none">
            <div class="line">
                <span class="tname">发送人邮箱</span>
                <div class="info-r">
                    <input name="sender_mail_value" class="bt-input-text mr5" type="text" style="width: 300px">
                </div>
            </div>
            <div class="line">
                <span class="tname">smtp密码</span>
                <div class="info-r">
                    <input name="sender_mail_password" class="bt-input-text mr5" type="password" style="width: 300px">
                </div>
            </div>
            <div class="line">
                <span class="tname">smtp服务器</span>
                <div class="info-r">
                    <input name="sender_mail_server" class="bt-input-text mr5" type="text" style="width: 300px">
                </div>
            </div>
            <div class="line">
                <span class="tname">端口</span>
                <div class="info-r">
                    <input name="sender_mail_port" class="bt-input-text mr5" type="text" style="width: 300px">
                </div>
            </div>
            <button class="btn btn-success btn-sm sender_submit" style="margin-left: 100px;">保存</button>
            <ul class="help-info-text c7">
                <li>推荐使用465端口,协议为SSL/TLS</li>
                <li>25端口为SMTP协议,587端口为STARTTLS协议</li>
                <li><a href="https://www.bt.cn/bbs/thread-71298-1-1.html" target="_blank" class="btlink">配置教程</a></li>
            </ul>
        </div>
    </div>
</div>
<style type="text/css">
.total_tips {
    border: 1px solid #cbcbcb;
    border-radius: 8px;
    color: #cbcbcb;
    cursor: pointer;
    display: inline-block;
    font-family: arial;
    font-size: 12px;
    font-style: normal;
    height: 14px;
    line-height: 14px;
    margin-right: 5px;
    text-align: center;
    width: 14px;
}
</style>
<!--邮箱模块-->
<script type="text/javascript">
    var mail = {
        all_mail_info: {},
        init: function () {
            var that = this;
            this.all_mail_info = $('.alarm-view .bt-w-menu p.bgw').data('data'); //设置全局数据
            this.gat_info();
            this.init_default();
            // 选项卡切换时
            $('.recipient_nav span').click(function () {
                var _type = $(this).attr('data-ctype');
                $(this).addClass('on').siblings().removeClass('on')
                switch (_type) {
                    case '0':
                        $('.recipient_view').show();
                        $('.sender_view').hide();
                        break;
                    case '1':
                        $('.recipient_view').hide();
                        $('.sender_view').show();
                        that.get_sender_data();
                        break;
                }
            })
            // 收件者保存按钮
            $('.recipient_submit').click(function () {
                that.recipient_submit();
            })
            // 发送者信息设置
            $('.sender_submit').click(function () {
                that.sender_submit();
            })

            // 设置默认
            $('#default_setting').change(function () {
                var _default = $(this).prop('checked');
                var _send = that.all_mail_info.data.send;
                if (!_send) {
                    layer.msg('未配置邮箱发送者设置', { icon: 2 })
                    $(this).prop('checked', !_default);
                    return
                }
                var loadTs = layer.msg('正在设置邮箱配置中,请稍候...', { icon: 16, time: 0, shade: [0.3, '#000'] });
                $.post('/config?action=set_default_channel&channel=mail', { default: _default }, function (res) {
                    layer.close(loadTs);
                    layer.msg(res.msg, { icon: res.status ? 1 : 2 })
                    if (res.status) that.refresh_data();
                });
            });

            var showTips = ''
            $('.total_tips').hover(function(){
                showTips = setTimeout(function(){
                    layer.tips('设置为默认后,消息通知优先使用该消息通道发送。', $('.total_tips'), {
                        tips: [1, '#20a53a'],
                        time: 0,
                        success:function(layero,indexs){
                            layero.css("left", $('.total_tips').offset().left - 10);
                    }})
                },200)
            },function(){
                clearTimeout(showTips)
                layer.closeAll('tips');
            })
        },
        /**
            *@description 获取邮箱信息、设置收件者提示语事件
        */
        gat_info: function () {
            var _tips = $('textarea[name=recipient_textarea]');
            var msg = ''
            if (!$.isEmptyObject(this.all_mail_info['data']['receive'])) {
                msg = mail.all_mail_info['data']['receive'] ? mail.all_mail_info['data']['receive'].join('\n') : ''
            }
            _tips.html(msg)
            // 设置收件者tips
            if (_tips.val() == '') $('.reci_tips.placeholder').show();
            $('.placeholder').click(function () { $(this).hide().siblings('textarea').focus() })
            _tips.focus(function () {
                $('.reci_tips.placeholder').hide()
            })
            _tips.blur(function () {
                _tips.val() == '' ? $('.reci_tips.placeholder').show() : $('.reci_tips.placeholder').hide()
            });
        },

        init_default: function () {
            var data = this.all_mail_info.data;
            if (!$.isEmptyObject(data)) {
                var _default = data.hasOwnProperty('default') ? data.default : false;
                $('#default_setting').prop('checked', _default);
            }
        },
        /**
            *@description 设置发送者信息
        */
        get_sender_data: function () {
            var that = this;
            var data = this.all_mail_info.data;

            if (!$.isEmptyObject(data) && !$.isEmptyObject(data.send)) {
                var send = data.send;

                var mail_ = send.qq_mail || '',
                    stmp_pwd_ = send.qq_stmp_pwd || '',
                    hosts_ = send.hosts || '',
                    port_ = send.port || '';

                $('input[name=sender_mail_value]').val(mail_)
                $('input[name=sender_mail_password]').val(stmp_pwd_)
                $('input[name=sender_mail_server]').val(hosts_)
                $('input[name=sender_mail_port]').val(port_)
            } else {
                $('input[name=sender_mail_port]').val('465')
            }
        },
        /**
            *@description 设置收件者邮箱,保存按钮
        */
        recipient_submit: function () {
            var that = this;
            var reci_ = $('textarea[name=recipient_textarea]').val();
            var loadTs = layer.msg('正在设置收件者邮箱中,请稍候...', { icon: 16, time: 0, shade: [0.3, '#000'] });
            $.post('/config?action=set_msg_config&name=mail', { mails: reci_ }, function (res) {
                layer.close(loadTs);
                layer.msg(res.msg, { icon: res.status ? 1 : 2 })
                if (res.status) that.refresh_data();
            })
        },
        /**
            *@description 设置发送者邮箱,保存按钮
        */
        sender_submit: function () {
            var that = this;
            var _email = $('input[name=sender_mail_value]').val(),
                _passW = $('input[name=sender_mail_password]').val(),
                _server = $('input[name=sender_mail_server]').val(),
                _port = $('input[name=sender_mail_port]').val();

            if (_email == '') return layer.msg('邮箱地址不能为空!', { icon: 2 });
            if (_passW == '') return layer.msg('STMP密码不能为空!', { icon: 2 });
            if (_server == '') return layer.msg('STMP服务器地址不能为空!', { icon: 2 });
            if (_port == '') return layer.msg('请输入有效的端口号', { icon: 2 });

            var loadTs = layer.msg('正在生成邮箱通道中,请稍候...', { icon: 16, time: 0, shade: [0.3, '#000'] });
            $.post('/config?action=set_msg_config&name=mail', {
                send: 1,
                qq_mail: _email,
                qq_stmp_pwd: _passW,
                hosts: _server,
                port: _port
            }, function (rdata) {
                layer.close(loadTs);
                if (rdata.status) that.refresh_data();
                layer.msg(rdata.msg, { icon: rdata.status ? 1 : 2 });
            });
        },
        refresh_data: function () {
            var that = this
            $.post('/config?action=get_msg_configs', function (rdata) {
                $.each(rdata, function (key, item) {
                    var $el = $('.alarm-view .bt-w-menu .men_' + key);
                    if (item.data && item.data.default) {
                        $el.html($el.text() + '<span class="show-default"></span>');
                    } else {
                        $el.find('span').remove();
                    }
                    $('.alarm-view .bt-w-menu .men_' + key).data('data', item);
                    if (key === 'mail') {
                        that.all_mail_info = item;
                    }
                });
            })
        }
    }
</script>