提交 28614bfc 编写于 作者: J Jingle

增加新功能 layer dialog

上级 94bb671b
无法预览此类型文件
default_app_config = 'finance.apps.FinanceConfig'
......@@ -14,6 +14,68 @@ class ProxyResource(resources.ModelResource):
model = Record
@admin.register(Layer)
class RecordAdmin(AjaxAdmin):
"""
自定义按钮 弹出对话框
"""
actions = ('layer_input',)
def layer_input(self, request, queryset):
# 这里的queryset 会有数据过滤,只包含选中的数据
post = request.POST
# 这里获取到数据后,可以做些业务处理
# post中的_action 是方法名
# post中 _selected 是选中的数据,逗号分割
if not post.get('_selected'):
return JsonResponse(data={
'status': 'error',
'msg': '请先选中数据!'
})
else:
return JsonResponse(data={
'status': 'success',
'msg': '处理成功!'
})
layer_input.short_description = '弹出对话框输入'
layer_input.type = 'success'
layer_input.icon = 'el-icon-s-promotion'
# 指定一个输入参数,应该是一个数组
# 指定为弹出层,这个参数最关键
layer_input.layer = {
# 弹出层中的输入框配置
# 这里指定对话框的标题
'title': '弹出层输入框',
# 提示信息
'tips': '这个弹出对话框是需要在admin中进行定义,数据新增编辑等功能,需要自己来实现。',
# 确认按钮显示文本
'confirm_button': '确认提交',
# 取消按钮显示文本
'cancel_button': '取消',
# 弹出层对话框的宽度,默认50%
'width': '40%',
# 表单中 label的宽度,对应element-ui的 label-width,默认80px
'labelWidth': "80px",
'params': [{
# 这里的type 对应el-input的原生input属性,默认为input
'type': 'input',
# key 对应post参数中的key
'key': 'name',
# 显示的文本
'label': '名称',
# 为空校验,默认为False
'require': True
}]
}
# Register your models here.
@admin.register(Record)
# class RecordAdmin(admin.ModelAdmin):
......@@ -159,3 +221,4 @@ class RecordAdmin(ImportExportActionModelAdmin, AjaxAdmin):
}]
}]
}
......@@ -3,3 +3,4 @@ from django.apps import AppConfig
class FinanceConfig(AppConfig):
name = 'finance'
verbose_name = '财务管理'
......@@ -20,3 +20,9 @@ class Record(models.Model):
def __str__(self):
return self.name
class Layer(Record):
class Meta:
verbose_name = "按钮弹出对话框"
verbose_name_plural = "按钮弹出对话框"
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册