Browse Source

运营中心-重新登录弹窗

zhuth 7 years ago
parent
commit
30d1738862

+ 26 - 0
frontend/operation-web/app/util/BaseUtil.js

@@ -215,6 +215,32 @@ Ext.define('saas.util.BaseUtil', {
             var xr = (new Array(arr[1].length > decimalPrecision ? decimalPrecision : arr[1].length)).fill('0');
             var format = f1 + '.' + xr.join('');
             return Ext.util.Format.number(value, format);
+        },
+
+        showLoginWin: function() {
+            var main = Ext.getCmp('rootView'),
+            win = Ext.getCmp('relogin');
+
+            if(!win) {
+                win = main.add({
+                    xtype: 'relogin'
+                });
+            }
+
+            win.show();
+        },
+
+        hashcode: function(obj) {
+            let str = JSON.stringify(obj);
+            let hash = 0,
+                i, chr, len;
+            if (str.length === 0) return hash;
+            for (i = 0, len = str.length; i < len; i++) {
+                chr = str.charCodeAt(i);
+                hash = ((hash << 5) - hash) + chr;
+                hash |= 0;
+            }
+            return hash;
         }
     }
 });

+ 103 - 0
frontend/operation-web/app/view/auth/ReLogin.js

@@ -0,0 +1,103 @@
+/**
+ * 重新登录弹窗
+ */
+Ext.define('saas.view.auth.ReLogin', {
+    extend: 'Ext.window.Window',
+    xtype: 'relogin',
+    id: 'relogin',
+
+    controller: 'relogin',
+
+    title: '重新登录',
+    cls: 'x-window-dbfind x-relogin-win',
+    layout: 'fit',
+    modal: true,
+    width: 350,
+    bodyPadding: 20,
+
+    items: [{
+        xtype: 'form',
+        reference: 'reloginform',
+        defaults: {
+            anchor: '100%',
+            labelWidth: 120
+        },
+        items: [{
+            xtype: 'displayfield',
+            height: 32,
+            cls: 'infoLabel',
+            value: '会话已过期,请重新登录',
+        }, {
+            xtype: 'textfield',
+            name: 'username',
+            emptyText: '请输入账号/邮箱/手机号',
+            fieldLabel: '账号',
+            bind: '{account.username}',
+            readOnly: true,
+            hideLabel: true,
+            allowBlank: false
+        }, {
+            xtype: 'textfield',
+            hideLabel: true,
+            fieldLabel: '密码',
+            emptyText: '密码',
+            inputType: 'password',
+            name: 'password',
+            // bind: '{password}',
+            allowBlank: false,
+            enableKeyEvents: true,
+            listeners: {
+                keydown: {
+                    fn: function(th, e, eOpts) {
+                        if(e.keyCode == 13) {
+                            this.up('relogin').getController().onLogin();
+                        }
+                    }
+                }
+            }
+        }, {
+            xtype: 'container',
+            layout: 'hbox',
+            items: [{
+                xtype: 'checkboxfield',
+                flex: 1,
+                cls: 'form-panel-font-color rememberMeCheckbox',
+                height: 30,
+                name: 'remember',
+                bind: '{remember}',
+                boxLabel: '记住密码'
+            }, {
+                xtype: 'box',
+                // html: '<a href="#passwordreset" class="link-forgot-password"> 忘记密码 ?</a>'
+            }]
+        }, {
+            xtype: 'container',
+            layout: {
+                type: 'hbox',
+                pack: 'center'
+            },
+            items: [{
+                xtype: 'button',
+                text: '登录',
+                formBind: true,
+                width: 68,
+                margin: '0 12 0 0',
+                listeners: {
+                    click: 'onLogin'
+                }
+            }, {
+                xtype: 'button',
+                text: '取消',
+                width: 68,
+                margin: '0 0 0 12',
+                listeners: {
+                    click: 'onCancel'
+                }
+            }]
+        }]
+    }],
+
+    listeners: {
+        afterrender: 'onAfterRender',
+    }
+});

+ 15 - 0
frontend/operation-web/app/view/auth/ReLogin.scss

@@ -0,0 +1,15 @@
+.x-relogin-win {
+    .infoLabel {
+        .x-form-display-field {
+            font-size: 14px;
+            vertical-align: middle;
+            line-height: 32px;
+            color: red;
+        }
+    }
+    .rememberMeCheckbox {
+        .x-form-checkbox-default,.x-form-cb-label-default.x-form-cb-label-after {
+            margin: 0;
+        }
+    }
+}

+ 103 - 0
frontend/operation-web/app/view/auth/ReLoginController.js

@@ -0,0 +1,103 @@
+Ext.define('saas.view.auth.ReLoginController', {
+    extend: 'Ext.app.ViewController',
+    alias: 'controller.relogin',
+
+    init: function () {
+        this.callParent(arguments);
+    },
+
+    onAfterRender: function() {
+        var me = this,
+        view = me.getView(),
+        model = me.getViewModel(),
+        remember = model.get('remember'),
+        password = model.get('repassword'),
+        lastSuccess = model.get('lastSuccess'),
+        form = me.lookup('reloginform'),
+        passwordField = form.getForm().findField('password');
+
+        if(remember && lastSuccess) {
+            passwordField.setValue(password);
+        }
+    },
+
+    onLogin: function () {
+        var me = this,
+            view = me.getView(),
+            viewModel = me.getViewModel(),
+            companyId = saas.util.BaseUtil.getCurrentUser().companyId,
+            form = me.lookup('reloginform'),
+            values = form.getValues();
+
+        if(!form.isValid()) {
+            return;
+        }
+
+        view.mask('请稍等...');
+
+        saas.model.Session.login(values.username, values.password, companyId)
+        .then(function (session) {
+            view.isMasked() && view.unmask();
+            viewModel.set('session', session);
+
+            session.get('account').companyId = companyId;
+            
+            me.successReLogin();
+            me.fireEvent('login', session);
+            return session;
+        })
+        .then(function(session) {
+            let headers = Ext.Ajax.getDefaultHeaders() || {};
+            
+            headers['Authorization'] = session.data.token;
+            Ext.Ajax.setDefaultHeaders(headers);
+
+            saas.util.State.set('session', session.data);
+
+            let sessionStr = session.data ? JSON.stringify(session.data) : '';
+
+            if (typeof require === 'function') {
+                let ipc = require('electron').ipcRenderer;
+                ipc.send('session.change', sessionStr);
+            }else {
+                //解析session 把data作为sessionStr
+                sessionStr = session ? JSON.stringify(session.data) : '';
+                const frame = window.frames[window.frames.length - 1];
+                frame.postMessage(sessionStr, '*');
+            }
+            return session;
+        })
+        .catch(function (error) {
+            view.isMasked() && view.unmask();
+            console.error(error);
+            saas.util.BaseUtil.showErrorToast('登录失败: ' + error.message);
+            me.failureReLogin();
+        });
+    },
+
+    successReLogin: function() {
+        var me = this,
+            view = me.getView(),
+            form = me.lookup('reloginform'),
+            values = form.getValues();
+            viewModel = me.getViewModel();
+
+        viewModel.set('repassword', values.password);
+        viewModel.set('lastSuccess', true);
+        view.close();
+    },
+
+    failureReLogin: function() {
+        var me = this,
+        viewModel = me.getViewModel();
+
+        viewModel.set('lastSuccess', false);
+    },
+
+    onCancel: function() {
+        var me = this,
+        view = me.getView();
+
+        view.close();
+    },
+});

+ 1 - 1
frontend/operation-web/overrides/data/Connection.js

@@ -60,7 +60,7 @@ Ext.define('saas.override.data.Connection', {
 
         if(res && res.code == 40001) {
             // 如果token超时则显示重新登陆弹窗
-            // saas.util.BaseUtil.showLoginWin();
+            saas.util.BaseUtil.showLoginWin();
             throw new Error('会话已过期');
         }