From 61677449ddf02df33ed97568520059e30793a6e4 Mon Sep 17 00:00:00 2001 From: newpanjing Date: Mon, 9 Sep 2019 14:27:58 +0800 Subject: [PATCH 1/3] =?UTF-8?q?fix=20#142=20=E8=87=AA=E5=AE=9A=E4=B9=89?= =?UTF-8?q?=E6=8C=89=E9=92=AE=E6=B7=BB=E5=8A=A0url=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- QUICK.md | 40 ++++++++++ doc/en/QUICK_en.md | 9 +++ simpleui/__init__.py | 2 +- simpleui/templates/admin/actions.html | 111 ++++++++++++++++++-------- simpleui/templates/admin/base.html | 3 +- simpleui/templatetags/simpletags.py | 5 ++ 6 files changed, 135 insertions(+), 35 deletions(-) diff --git a/QUICK.md b/QUICK.md index 30270fce..945a45b1 100644 --- a/QUICK.md +++ b/QUICK.md @@ -463,6 +463,46 @@ class EmployeAdmin(admin.ModelAdmin): |type|按钮类型,参考:https://element.eleme.cn/#/zh-CN/component/button| |style|自定义css样式| ++ 链接按钮 + +> 在2.9或以上版本中生效 + +|字段|说明| +|------|------| +|action_type|按钮动作类型,0=当前页内打开,1=新tab打开,2=浏览器tab打开| +|action_url|按钮访问链接| + +demo: +```python + # 增加自定义按钮 + actions = ['custom_button'] + + def custom_button(self, request, queryset): + pass + + # 显示的文本,与django admin一致 + custom_button.short_description = '测试按钮' + # icon,参考element-ui icon与https://fontawesome.com + custom_button.icon = 'fas fa-audio-description' + + # 指定element-ui的按钮类型,参考https://element.eleme.cn/#/zh-CN/component/button + custom_button.type = 'danger' + + # 给按钮追加自定义的颜色 + custom_button.style = 'color:black;' + + # 链接按钮,设置之后直接访问该链接 + # 3中打开方式 + # action_type 0=当前页内打开,1=新tab打开,2=浏览器tab打开 + # 设置了action_type,不设置url,页面内将报错 + # 设置成链接类型的按钮后,custom_button方法将不会执行。 + + custom_button.action_type = 0 + custom_button.action_url = 'http://www.baidu.com' + +``` + + ## 离线模式 > 在2.1.3或以上的版本中生效 在settings.py中加入 diff --git a/doc/en/QUICK_en.md b/doc/en/QUICK_en.md index d2873772..d1257a4d 100644 --- a/doc/en/QUICK_en.md +++ b/doc/en/QUICK_en.md @@ -431,6 +431,15 @@ Configuration compatible with native admin |type|Button type,Reference:https://element.eleme.cn/#/zh-CN/component/button| |style|Customize CSS styles| ++ Link Button + +> Requires version 2.9 or above + +|Field|Description| +|------|------| +|action_type|0=The current page, 1=Simpleui New tab,2=Browser new tab| +|action_url|The url address| + ## Offline > Requires version 2.1.3 or above diff --git a/simpleui/__init__.py b/simpleui/__init__.py index 8ced7434..094f43c8 100644 --- a/simpleui/__init__.py +++ b/simpleui/__init__.py @@ -1,2 +1,2 @@ def get_version(): - return '2.8' + return '2.9' diff --git a/simpleui/templates/admin/actions.html b/simpleui/templates/admin/actions.html index 5cb6de71..e8d14fb6 100644 --- a/simpleui/templates/admin/actions.html +++ b/simpleui/templates/admin/actions.html @@ -32,7 +32,8 @@ {{ field.1 }} {% else %} - {{ field.1 }} {% endif %} @@ -58,7 +59,8 @@ {{ selection_note_all }} {% blocktrans with cl.result_count as total_count %}Select all {{ total_count }} {{ module_name }}{% endblocktrans %} + title="{% trans "Click here to select the objects across all pages" %}">{% blocktrans with cl.result_count as total_count %} + Select all {{ total_count }} {{ module_name }}{% endblocktrans %} {% trans "Clear selection" %} @@ -68,9 +70,12 @@ {% endblock %} - - - + + + @@ -80,13 +85,12 @@ {% else %} - +{# #} + {% endif %} diff --git a/simpleui/templatetags/simpletags.py b/simpleui/templatetags/simpletags.py index 58401b5d..c26fceb6 100644 --- a/simpleui/templatetags/simpletags.py +++ b/simpleui/templatetags/simpletags.py @@ -353,14 +353,19 @@ def custom_button(context): # if hasattr(admin, 'actions'): # actions = admin.actions # 输出自定义按钮的属性 + if actions: + id = 0 for name in actions: values = {} fun = actions.get(name)[0] for key, v in fun.__dict__.items(): if key != '__len__' and key != '__wrapped__': values[key] = v + values['eid'] = id + id += 1 data[name] = values + return json.dumps(data, cls=LazyEncoder) From 8bd98dfaa7d6d0191ad0d5215775a58f2c977243 Mon Sep 17 00:00:00 2001 From: newpanjing Date: Mon, 9 Sep 2019 14:38:22 +0800 Subject: [PATCH 2/3] =?UTF-8?q?fix=20#142=20=E8=87=AA=E5=AE=9A=E4=B9=89?= =?UTF-8?q?=E6=8C=89=E9=92=AE=E6=B7=BB=E5=8A=A0url=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- simpleui/static/admin/simpleui-x/js/index.js | 6 +++--- simpleui/templates/admin/actions.html | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/simpleui/static/admin/simpleui-x/js/index.js b/simpleui/static/admin/simpleui-x/js/index.js index 0fa0cee0..d005f179 100644 --- a/simpleui/static/admin/simpleui-x/js/index.js +++ b/simpleui/static/admin/simpleui-x/js/index.js @@ -4,8 +4,6 @@ } window.addEventListener('hashchange', function (e) { - // console.log(e) - // console.log('hash') if (e.newURL != e.oldURL) { openByHash() } @@ -25,7 +23,9 @@ } function changeUrl(data) { - location.href = '#' + (data.url || '/') + if(data.url.indexOf('http')!=0){ + location.href = '#' + (data.url || '/') + } } window.callback = function () { diff --git a/simpleui/templates/admin/actions.html b/simpleui/templates/admin/actions.html index e8d14fb6..4f5eaf87 100644 --- a/simpleui/templates/admin/actions.html +++ b/simpleui/templates/admin/actions.html @@ -269,12 +269,13 @@ window.open(temp.action_url) break; } + console.log('中断后续操作') return; } } } } - + console.log('执行了') if (url) { window.location.href = url; return; From cb13fef0f1ad360164b35681d26aacaa4404ba80 Mon Sep 17 00:00:00 2001 From: newpanjing Date: Mon, 9 Sep 2019 14:42:39 +0800 Subject: [PATCH 3/3] Clear cache --- simpleui/templates/admin/index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/simpleui/templates/admin/index.html b/simpleui/templates/admin/index.html index df0d5393..220ca653 100755 --- a/simpleui/templates/admin/index.html +++ b/simpleui/templates/admin/index.html @@ -312,7 +312,7 @@ - + {% load_analysis %}