Python flask实战订餐系统微信小程序-28删除和恢复账号功能实现

wechat xuhss 537℃ 0评论

删除和恢复账号

删除账号

  • 如果1 则显示删除

  • 如果0 则显示恢复

index.html修改

20210807075130 - Python flask实战订餐系统微信小程序-28删除和恢复账号功能实现

index.js 添加形影函数

;
var account_index_ops = {
    init:function(){
        this.eventBind();
    },
    eventBind:function(){
        var that = this;
        $(".wrap_search .search").click(function(){
            $(".wrap_search").submit();
        });

        $(".remove").click( function(){
            that.ops( "remove",$(this).attr("data") );
        } );

        $(".recover").click( function(){
            that.ops( "recover",$(this).attr("data") );
        } );
    },
    ops:function( act,id ){
        var callback = {
            'ok':function(){
                $.ajax({
                    url:common_ops.buildUrl( "/account/ops" ),
                    type:'POST',
                    data:{
                        act:act,
                        id:id
                    },
                    dataType:'json',
                    success:function( res ){
                        var callback = null;
                        if( res.code == 200 ){
                            callback = function(){
                                window.location.href = window.location.href;
                            }
                        }
                        common_ops.alert( res.msg,callback );
                    }
                });
            },
            'cancel':null
        };
        common_ops.confirm( ( act == "remove" ? "确定删除?":"确定恢复?" ), callback );
    }

};

$(document).ready( function(){
    account_index_ops.init();
} );

Account.py添加ops接口

@route_account.route( "/ops", methods = ["POST"] )
def ops():
    resp = {'code': 200, 'msg': '操作成功', 'data': {}}

    req = request.values
    id = req['id'] if 'id' in req else 0
    act = req['act'] if 'act' in req else ''

    if not id:
        resp['code'] = -1
        resp['msg'] = '请選擇要操作的賬號'
        return jsonify(resp)

    if not act in ["remove", 'recover']:
        resp['code'] = -1
        resp['msg'] = '操作有誤 請重試'
        return jsonify(resp)

    user_info = User.query.filter_by(uid=id).first()
    if not user_info:
        resp['code'] = -1
        resp['msg'] = '指定賬號不存在'
        return jsonify(resp)

    if act=="remove":
        user_info.status = 0
    elif act=="recover":
        user_info.status = 1

    user_info.update_time = getCurrentDate()
    db.session.add(user_info)
    db.session.commit()
    return jsonify(resp)

转载请注明:xuhss » Python flask实战订餐系统微信小程序-28删除和恢复账号功能实现

喜欢 (12)

您必须 登录 才能发表评论!