34 lines
837 B
Python
34 lines
837 B
Python
#!/usr/bin/env python
|
||
# -*- coding: utf-8 -*-
|
||
|
||
|
||
class ApiResult:
|
||
"""
|
||
接口返回类
|
||
"""
|
||
|
||
def __init__(self):
|
||
super().__init__()
|
||
|
||
def __init__(self, success, code, data, message):
|
||
# 只要服务端没报错,success都是True
|
||
self.success = success
|
||
# 根据处理结果不同,返回不同的值
|
||
self.code = code
|
||
# 返回数据
|
||
self.data = data
|
||
# 提示信息
|
||
self.message = message
|
||
|
||
@staticmethod
|
||
def instance(success, code, data, message):
|
||
return ApiResult(success, code, data, message).__dict__
|
||
|
||
@staticmethod
|
||
def ok(code, data, message):
|
||
return ApiResult(True, code, data, message).__dict__
|
||
|
||
@staticmethod
|
||
def fail(code, data, message):
|
||
return ApiResult(False, code, data, message).__dict__
|