{% set sms_code_url = entire_url('/rbac/gen_sms_code.dspy') %} {% set phone_login_url = entire_url('/rbac/phone_login.dspy') %} { "id": "login_window", "widgettype": "PopupWindow", "options": { "title": "登录/注册", "auto_open": true, "anthor": "cc", "cwidth": 22, "cheight": 22 }, "subwidgets": [ { "widgettype": "TabPanel", "id": "login_tabs", "options": { "tab_wide": "auto", "height": "100%", "width": "100%", "tab_pos": "top", "items": [ { "name": "userpasswd", "label": "用户密码", "content": { "widgettype": "Form", "options": { "cols": 1, "fields": [ { "name": "username", "label": "用户名", "uitype": "str" }, { "name": "password", "label": "密码", "uitype": "password" } ] }, "binds": [ { "wid": "self", "event": "submit", "actiontype": "urlwidget", "target": "self", "options": { "method": "POST", "url": "{{entire_url('up_login.dspy')}}" } } ] } }, { "name": "phonecode", "label": "手机验证码", "content": { "widgettype": "VBox", "options": { "padding": "8px", "gap": "8px" }, "subwidgets": [ { "widgettype": "Form", "id": "phone_form", "options": { "description": "限中国国内手机号", "cols": 1, "fields": [ { "name": "cell_no", "label": "手机号", "uitype": "str" }, { "name": "codeid", "uitype": "hidden", "value": "" }, { "name": "check_code", "label": "验证码", "uitype": "str" } ] } }, { "widgettype": "HBox", "options": { "gap": "8px" }, "subwidgets": [ { "widgettype": "Button", "id": "gen_code_btn", "options": { "label": "发送验证码" }, "binds": [ { "wid": "self", "event": "click", "actiontype": "script", "target": "self", "script": "var form=bricks.getWidgetById('phone_form',bricks.app);if(!form){alert('form not found');return;}var vals=form._getValue();var cell=vals.cell_no;if(!cell||cell.length<11){alert('请输入正确的手机号');return;}var btn=bricks.getWidgetById('gen_code_btn',bricks.app);btn.disabled=true;if(btn.text_w)btn.text_w.set_otext('发送中...');fetch('{{sms_code_url}}?_webbricks_=1&cellphone='+encodeURIComponent(cell)).then(function(r){return r.json()}).then(function(d){if(d.status==='ok'){form.setValue({codeid:d.data.key});if(btn.text_w)btn.text_w.set_otext('已发送');var sec=60;var tmr=setInterval(function(){sec--;if(sec<=0){clearInterval(tmr);btn.disabled=false;if(btn.text_w)btn.text_w.set_otext('重新发送')}else{if(btn.text_w)btn.text_w.set_otext(sec+'s')}},1000)}else{alert(d.data.message||'发送验证码出错');btn.disabled=false;if(btn.text_w)btn.text_w.set_otext('发送验证码')}}).catch(function(e){alert('网络错误: '+e);btn.disabled=false;if(btn.text_w)btn.text_w.set_otext('发送验证码')})" } ] }, { "widgettype": "Button", "id": "phone_login_btn", "options": { "label": "登录", "css": "sage-btn-primary" }, "binds": [ { "wid": "self", "event": "click", "actiontype": "script", "target": "self", "script": "var form=bricks.getWidgetById('phone_form',bricks.app);if(!form)return;var vals=form._getValue();if(!vals.cell_no){alert('请输入手机号');return;}if(!vals.check_code){alert('请输入验证码');return;}if(!vals.codeid){alert('请先发送验证码');return;}var btn=bricks.getWidgetById('phone_login_btn',bricks.app);btn.disabled=true;if(btn.text_w)btn.text_w.set_otext('登录中...');var body='cellphone='+encodeURIComponent(vals.cell_no)+'&key='+encodeURIComponent(vals.codeid)+'&sms_code='+encodeURIComponent(vals.check_code);fetch('{{phone_login_url}}?_webbricks_=1',{method:'POST',headers:{'Content-Type':'application/x-www-form-urlencoded'},body:body}).then(function(r){return r.json()}).then(function(d){btn.disabled=false;if(btn.text_w)btn.text_w.set_otext('登录');if(d.status==='ok'){var u=d.data.user;var nick=u.nick_name||u.username;var msgW={widgettype:'Message',options:{timeout:3,auto_open:true,title:'登录成功',message:nick+' 欢迎'},binds:[{wid:'self',event:'dismissed',actiontype:'script',target:'self',script:'if(bricks.app&&bricks.app.dispatch)bricks.app.dispatch(\"user_logined\")'},{wid:'self',event:'dismissed',actiontype:'script',target:'body.login_window',script:'this.destroy()'}]};bricks.widgetBuild(msgW,bricks.app).then(function(w){if(w)bricks.app.add_widget(w)})}else if(d.status==='choose'){var users=d.data.users;var html='
该手机号关联多个账号,请选择:
';for(var i=0;i