forked fromzhangchunlin/uliweb-apijson
- Notifications
You must be signed in to change notification settings - Fork4
fix request data cannot modify issue; add view and delete action supp…#13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
23 changes: 16 additions & 7 deletionsdemo/apps/apijson_demo/templates/index.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
80 changes: 0 additions & 80 deletionsdemo/apps/tables/templates/vue/inc_apijson_table.html
This file was deleted.
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
189 changes: 189 additions & 0 deletionsuliweb_apijson/apijson/templates/vue/inc_apijson_table.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,189 @@ | ||
<script> | ||
Vue.component('apijson-table', { | ||
delimiters: ['{', '}'], | ||
props: ["table_name"], | ||
template: `<div> | ||
<i-table stripe border :columns="tcolumns" :data="tlist" @on-sort-change="table_on_sort_change"></i-table> | ||
<page :total="total" :page-size="query_count" :current.sync="current_page" :page-size-opts="[10, 20, 50, 100]" show-sizer @on-change="page_on_change" @on-page-size-change="page_on_page_size_change"></page> | ||
<modal v-model="modal_view" title="View"> | ||
<i-form @submit.native.prevent :label-width="80"> | ||
<form-item v-for="item in view_items" :key="item.key" :label="item.key"> | ||
<i-input v-if="typeof item.value !=='boolean'" v-model="item.value" :readonly=true></i-input> | ||
<checkbox v-if="typeof item.value ==='boolean'" v-model="item.value" disabled></checkbox> | ||
</form-item> | ||
</i-form> | ||
</modal> | ||
<modal v-model="modal_delete" title="Confirm to delete" @on-ok="real_remove"> | ||
<p>Confirm to delete #{delete_params.row&&delete_params.row.id} in table '{table_name}'?</p> | ||
</modal> | ||
</div>`, | ||
data: function(){ | ||
var thisp = this | ||
return { | ||
modal_view: false, | ||
view_items: [], | ||
modal_delete: false, | ||
delete_params:{}, | ||
tcolumns: [ | ||
{title:'#',key:'id',width:80}, | ||
{ | ||
title: 'Action', | ||
width: 140, | ||
render: (h, params) => { | ||
return h('div', [ | ||
h('Button', { | ||
props: { | ||
type: 'primary', | ||
size: 'small' | ||
}, | ||
style: { | ||
marginRight: '5px' | ||
}, | ||
on: { | ||
click: function(){ | ||
thisp.show(params) | ||
} | ||
} | ||
}, 'View'), | ||
h('Button', { | ||
props: { | ||
type: 'error', | ||
size: 'small' | ||
}, | ||
on: { | ||
click: function(){ | ||
thisp.remove(params) | ||
} | ||
} | ||
}, 'Delete') | ||
]); | ||
} | ||
} | ||
], | ||
tcolumns_init: false, | ||
tlist:[], | ||
query_count: 10, | ||
current_page: 1, | ||
total: 0, | ||
sort_key: "id", | ||
sort_order: "-" | ||
} | ||
}, | ||
methods: { | ||
update_list: function(){ | ||
var thisp = this | ||
var arr_params = { | ||
"@count":thisp.query_count, | ||
"@page":thisp.current_page-1, | ||
"@query":2 | ||
} | ||
arr_params[this.table_name] = { | ||
"@order":thisp.sort_key+thisp.sort_order, | ||
"@role":"{{=role}}" | ||
} | ||
var params = { | ||
"[]":arr_params, | ||
"total@":"/[]/total" | ||
} | ||
$.ajax({ | ||
type: "POST", | ||
url: "{{=url_for('uliweb_apijson.apijson.views.ApiJson.get')}}", | ||
contentType: 'application/json', | ||
data: JSON.stringify(params), | ||
success: function (data) { | ||
if (data.code==200) { | ||
var arr = data["[]"] | ||
if (!thisp.tcolumns_init) { | ||
if (arr.length>0) { | ||
var item = arr[0] | ||
for (var k in item){ | ||
if (k!="id") { | ||
var col = {title:k,key:k} | ||
if (typeof item[k] ==="boolean") { | ||
col["width"] = 80 | ||
} | ||
else if (typeof item[k] ==="number") { | ||
col["width"] = 100 | ||
} | ||
thisp.tcolumns.push(col) | ||
} | ||
} | ||
thisp.tcolumns_init = true | ||
} | ||
} | ||
thisp.tlist = arr | ||
thisp.total = data.total | ||
} | ||
} | ||
}) | ||
}, | ||
show: function(params){ | ||
var row = params.row | ||
this.view_items = [] | ||
this.view_items.push({key:"id",value:row.id}) | ||
for (var k in row){ | ||
if (k!="id" && k[0]!="_") { | ||
value = row[k] | ||
this.view_items.push({key:k,value:value}) | ||
} | ||
} | ||
this.modal_view = true | ||
}, | ||
remove: function(params){ | ||
this.delete_params = params | ||
this.modal_delete = true | ||
}, | ||
real_remove: function(){ | ||
var thisp = this | ||
var params = { | ||
"@tag": thisp.table_name | ||
} | ||
params[thisp.table_name] = { | ||
"id": thisp.delete_params.row.id | ||
} | ||
$.ajax({ | ||
type: "POST", | ||
url: "{{=url_for('uliweb_apijson.apijson.views.ApiJson.delete')}}", | ||
contentType: 'application/json', | ||
data: JSON.stringify(params), | ||
success: function (data) { | ||
if (data.code!=200){ | ||
thisp.$Notice.error({ | ||
title: 'error when remove #'+thisp.delete_params.row.id+' in table '+thisp.table_name, | ||
desc: data.msg | ||
}) | ||
return | ||
} | ||
var result = data[thisp.table_name] | ||
if (result.code!=200){ | ||
thisp.$Notice.error({ | ||
title: 'error when remove #'+thisp.delete_params.row.id+' in table '+thisp.table_name, | ||
desc: result.msg | ||
}) | ||
return | ||
} | ||
thisp.$Notice.success({ | ||
title: 'success remove #'+thisp.delete_params.row.id+' in table '+thisp.table_name, | ||
desc: result.msg | ||
}); | ||
thisp.update_list() | ||
} | ||
}) | ||
}, | ||
table_on_sort_change: function(){ | ||
}, | ||
page_on_change: function(data) { | ||
this.update_list() | ||
}, | ||
page_on_page_size_change: function(data) { | ||
this.query_count = data | ||
this.current_page = 0 | ||
this.update_list() | ||
} | ||
}, | ||
mounted: function(){ | ||
this.update_list() | ||
} | ||
}) | ||
</script> |
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.