|
@@ -12,10 +12,11 @@ export default (target, hasPagination = true) => ({
|
|
|
pageNo: 0,
|
|
|
pageSize: 20
|
|
|
},
|
|
|
- data: Object.freeze([]),
|
|
|
+ list: Object.freeze([]),
|
|
|
total: 0,
|
|
|
selectedData: null,
|
|
|
- selectedList: Object.freeze([])
|
|
|
+ selectedList: Object.freeze([]),
|
|
|
+ editorName: 'editor'
|
|
|
}),
|
|
|
methods: {
|
|
|
afterLoadList () {
|
|
@@ -31,14 +32,23 @@ export default (target, hasPagination = true) => ({
|
|
|
Object.assign(query, this.pagination)
|
|
|
this.$$request(target.$$api.getPagination, this.query, this.pagination)
|
|
|
.then(data => {
|
|
|
- this.total = data.count
|
|
|
- this.data = Object.freeze(bindPrototype(data.list, target))
|
|
|
- this.afterLoadList()
|
|
|
+ const { count, list } = data
|
|
|
+ const { pagination } = this
|
|
|
+ const { pageSize } = pagination
|
|
|
+ if (list.length > 0 || pagination.pageNo === 1) {
|
|
|
+ this.total = count
|
|
|
+ this.list = Object.freeze(bindPrototype(data.list, target))
|
|
|
+ this.afterLoadList()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ pagination.pageNo = Math.floor(count / pageSize)
|
|
|
+ this.loadList()
|
|
|
}).catch(console.error).finally(() => {})
|
|
|
} else {
|
|
|
this.$$request(target.$$api.getList, this.query).then(list => {
|
|
|
this.total = list.length
|
|
|
- this.data = Object.freeze(bindPrototype(Object.freeze(list), target))
|
|
|
+ this.list = Object.freeze(bindPrototype(Object.freeze(list), target))
|
|
|
this.afterLoadList()
|
|
|
}).catch(console.error).finally(() => {})
|
|
|
}
|
|
@@ -56,6 +66,47 @@ export default (target, hasPagination = true) => ({
|
|
|
onRowClick (data) {
|
|
|
this.selectedData = data
|
|
|
},
|
|
|
+ onOpenEditorBtnClick (data) {
|
|
|
+ const editor = this.getEditor()
|
|
|
+ data instanceof Event ? editor.open() : editor.open(data)
|
|
|
+ },
|
|
|
+ deleteSuccess () {
|
|
|
+ this.loadList()
|
|
|
+ this.$notify({
|
|
|
+ title: '成功',
|
|
|
+ message: '删除成功',
|
|
|
+ type: 'success',
|
|
|
+ position: 'bottom-right'
|
|
|
+ })
|
|
|
+ },
|
|
|
+ deleteFailed () {
|
|
|
+ this.$notify.error({
|
|
|
+ title: '失败',
|
|
|
+ message: '删除失败',
|
|
|
+ position: 'bottom-right'
|
|
|
+ })
|
|
|
+ },
|
|
|
+ deleteData (data) {
|
|
|
+ this.$$request(target.$$api.delete, data)
|
|
|
+ .then(this.deleteSuccess)
|
|
|
+ .catch(this.deleteFailed)
|
|
|
+ .finally(() => {})
|
|
|
+ },
|
|
|
+ onDeleteBtnClick (data) {
|
|
|
+ const name = this[this.$$nameProp]
|
|
|
+ this.$confirm(`此操作将永久删除${name ? `'${name}'` : '该记录'}, 是否继续?`, '确认', {
|
|
|
+ confirmButtonText: '确定',
|
|
|
+ cancelButtonText: '取消',
|
|
|
+ confirmButtonClass: 'confirm-dialog-confirm-btn',
|
|
|
+ cancelButtonClass: 'confirm-dialog-cancel-btn',
|
|
|
+ type: 'warning'
|
|
|
+ }).then(() => {
|
|
|
+ this.deleteData(data)
|
|
|
+ }).catch(() => {})
|
|
|
+ },
|
|
|
+ getEditor () {
|
|
|
+ return this.$refs[this.editorName]
|
|
|
+ },
|
|
|
getOptions (optionTargetConfigs, optionGroup) {
|
|
|
return Promise.all(
|
|
|
optionTargetConfigs.map(
|