Skip to content

Commit

Permalink
Merge pull request #147 from newpanjing/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
newpanjing authored Sep 9, 2019
2 parents 84e68ff + cb13fef commit 8df434f
Show file tree
Hide file tree
Showing 8 changed files with 140 additions and 39 deletions.
40 changes: 40 additions & 0 deletions QUICK.md
Original file line number Diff line number Diff line change
Expand Up @@ -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中加入
Expand Down
9 changes: 9 additions & 0 deletions doc/en/QUICK_en.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion simpleui/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
def get_version():
return '2.8'
return '2.9'
6 changes: 3 additions & 3 deletions simpleui/static/admin/simpleui-x/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
}

window.addEventListener('hashchange', function (e) {
// console.log(e)
// console.log('hash')
if (e.newURL != e.oldURL) {
openByHash()
}
Expand All @@ -25,7 +23,9 @@
}

function changeUrl(data) {
location.href = '#' + (data.url || '/')
if(data.url.indexOf('http')!=0){
location.href = '#' + (data.url || '/')
}
}

window.callback = function () {
Expand Down
112 changes: 79 additions & 33 deletions simpleui/templates/admin/actions.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
</el-select>
<el-button icon="fas fa-download" data-name="{{ field.0 }}">{{ field.1 }}</el-button>
{% else %}
<el-button :icon="customButton.{{ field.0 }}.icon" :style="customButton.{{ field.0 }}.style"
<el-button :eid="customButton.{{ field.0 }}.eid"
:icon="customButton.{{ field.0 }}.icon" :style="customButton.{{ field.0 }}.style"
:type="customButton.{{ field.0 }}.type" data-name="{{ field.0 }}">{{ field.1 }}
</el-button>
{% endif %}
Expand All @@ -58,7 +59,8 @@
<span class="all">{{ selection_note_all }}</span>
<span class="question">
<a href="#"
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 %}</a>
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 %}</a>
</span>
<span class="clear">
<a href="#" onclick="unSelect()">{% trans "Clear selection" %}</a>
Expand All @@ -68,9 +70,12 @@
{% endblock %}

<el-button-group class="btn-group">
<a href="javascript:;" @click="searchDisplay()" class="el-button el-button--default"><span class="el-icon-search"></span></a>
<a href="javascript:;" @click="reload()" class="el-button el-button--default"><span class="el-icon-refresh"></span></a>
<a href="javascript:;" @click="openNewPage()" class="el-button el-button--default"><span class="el-icon-news"></span></a>
<a href="javascript:;" @click="searchDisplay()" class="el-button el-button--default"><span
class="el-icon-search"></span></a>
<a href="javascript:;" @click="reload()" class="el-button el-button--default"><span
class="el-icon-refresh"></span></a>
<a href="javascript:;" @click="openNewPage()" class="el-button el-button--default"><span
class="el-icon-news"></span></a>

</el-button-group>

Expand All @@ -80,13 +85,12 @@
<script type="text/javascript">



var _action = new Vue({
el: '.actions',
data: {
select_across: 0,
file_format: 1,
show:true,
show: true,
options: [{
value: 0,
label: 'csv'
Expand All @@ -113,49 +117,49 @@
label: 'html'
}],
customButton:{% autoescape off %}{% custom_button %}{% endautoescape %},
exts:[]
exts: []
},
created(){
created() {
if (localStorage && typeof (localStorage.searchStatus) != 'undefined') {
this.show = localStorage.searchStatus=='true';
this.show = localStorage.searchStatus == 'true';
}
},
watch:{
'show':function(newValue){
obj=document.querySelector('.xfull')
if(!newValue){
watch: {
'show': function (newValue) {
obj = document.querySelector('.xfull')
if (!newValue) {
//隐藏
document.getElementById('toolbar').style.display = 'none';
if(obj) {
if (obj) {
obj.style.display = 'none';
}
}else{
} else {
//显示
document.getElementById('toolbar').style.display = 'inherit';
if(obj){
if (obj) {
obj.style.display = 'inherit';
}
}
if(localStorage){
localStorage['searchStatus']=newValue;
if (localStorage) {
localStorage['searchStatus'] = newValue;
}
}
},
methods: {
searchDisplay:function(){
searchDisplay: function () {

this.show = !this.show;

},
reload:function(){
window.location.reload()
reload: function () {
window.location.reload()
},
openNewPage:function(){
openNewPage: function () {
window.open(window.location.href)
},
getIcon:getIcon,
extClick:function(item){
window.location.href=item.url;
getIcon: getIcon,
extClick: function (item) {
window.location.href = item.url;
},
formSubmit: function () {
$("#changelist-form").submit();
Expand All @@ -174,8 +178,9 @@
});


var self=this;
function showMessage(msgs){
var self = this;

function showMessage(msgs) {
msgs.forEach(item => {
this.$notify({
title: getLanuage('Tips'),
Expand All @@ -190,28 +195,28 @@
//#67 #66 修复删除问题,改为弹出确认

this.$confirm(getLanuage('Are you sure you want to delete the selected?'))
.then(_ =>{
.then(_ => {
$.ajax({
type: "POST",//方法类型
url: "",//url
data: $("#changelist-form").serialize()+'&post=yes',
data: $("#changelist-form").serialize() + '&post=yes',
success: function (result) {
var msgs = $(result).find('#out_message').html().replace('var messages=', '');
showMessage.call(self,JSON.parse(msgs));
showMessage.call(self, JSON.parse(msgs));
setTimeout(() => {
window.location.reload();
}, 1000);
},
error: function () {
this.$notify({
this.$notify({
title: getLanuage('Tips'),
message: 'Network error',
type: 'error',
dangerouslyUseHTMLString: true
});
}
});
}).catch(_ =>{
}).catch(_ => {

});
}
Expand All @@ -230,6 +235,47 @@
$(function () {
$(".actions button[data-name!='delete_selected']").click(function () {
var url = $(this).attr("url");
var eid = $(this).attr('eid');
if (eid) {
for (var i in _action.customButton) {
var temp = _action.customButton[i];
if (temp.eid == eid) {

if (typeof(temp.action_type)!='undefined') {

if (!temp.action_url) {
this.$notify({
title: 'error',
message: 'action must contain attributes:action_url! ',
type: 'error',
dangerouslyUseHTMLString: true
});
return;
}

switch (temp.action_type) {
case 0:
window.location.href = temp.action_url;
break;
case 1:
parent.window.app.openTab({
url: temp.action_url,
icon: temp.icon || 'fa fa-file',
name: temp.short_description,
breadcrumbs: []
});
break;
case 2:
window.open(temp.action_url)
break;
}
console.log('中断后续操作')
return;
}
}
}
}
console.log('执行了')
if (url) {
window.location.href = url;
return;
Expand Down
3 changes: 2 additions & 1 deletion simpleui/templates/admin/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
<script type="text/javascript" src="{% static '/admin/simpleui-x/js/vue.min.js' %}"></script>
<script type="text/javascript" src="{% static '/admin/simpleui-x/elementui/index.js' %}"></script>
{% else %}
<script src="https://cdn.jsdelivr.net/npm/vue"></script>
{# <script src="https://cdn.jsdelivr.net/npm/vue"></script>#}
<script src="https://unpkg.com/[email protected]/dist/vue.min.js"></script>
<script src="https://unpkg.com/element-ui/lib/index.js"></script>
{% endif %}

Expand Down
2 changes: 1 addition & 1 deletion simpleui/templates/admin/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@
<script type="text/javascript" src="{% static '/admin/simpleui-x/js/cookie.js' %}"></script>
<script type="text/javascript" src="{% static '/admin/simpleui-x/theme/theme.js' %}"></script>
<script type="text/javascript" src="{% static '/admin/simpleui-x/waves/waves.min.js' %}?_=2.0.5"></script>
<script type="text/javascript" src="{% static '/admin/simpleui-x/js/index.js' %}?_=2.8"></script>
<script type="text/javascript" src="{% static '/admin/simpleui-x/js/index.js' %}?_=2.9"></script>
<script type="text/javascript" async src="https://api.github.com/repos/newpanjing/simpleui/releases/latest?callback=simple_call"></script>

{% load_analysis %}
Expand Down
5 changes: 5 additions & 0 deletions simpleui/templatetags/simpletags.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down

0 comments on commit 8df434f

Please sign in to comment.