mirror of
https://github.com/jumpserver/lina.git
synced 2025-09-26 15:07:04 +00:00
[Update] 完成刷新和搜索
This commit is contained in:
@@ -22,6 +22,7 @@
|
|||||||
"js-cookie": "2.2.0",
|
"js-cookie": "2.2.0",
|
||||||
"less": "^3.10.3",
|
"less": "^3.10.3",
|
||||||
"less-loader": "^5.0.0",
|
"less-loader": "^5.0.0",
|
||||||
|
"lodash": "^4.17.15",
|
||||||
"lodash.clonedeep": "^4.5.0",
|
"lodash.clonedeep": "^4.5.0",
|
||||||
"lodash.frompairs": "^4.0.1",
|
"lodash.frompairs": "^4.0.1",
|
||||||
"lodash.get": "^4.4.2",
|
"lodash.get": "^4.4.2",
|
||||||
|
@@ -727,7 +727,8 @@ export default {
|
|||||||
// JSON.stringify是为了后面深拷贝作准备
|
// JSON.stringify是为了后面深拷贝作准备
|
||||||
initExtraQuery: JSON.stringify(this.extraQuery || this.customQuery || {}),
|
initExtraQuery: JSON.stringify(this.extraQuery || this.customQuery || {}),
|
||||||
isSearchCollapse: false,
|
isSearchCollapse: false,
|
||||||
showNoData: false
|
showNoData: false,
|
||||||
|
innerQuery: {}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
@@ -849,6 +850,7 @@ export default {
|
|||||||
formValue = this.$refs.searchForm.getFormValue()
|
formValue = this.$refs.searchForm.getFormValue()
|
||||||
Object.assign(query, formValue)
|
Object.assign(query, formValue)
|
||||||
}
|
}
|
||||||
|
Object.assign(query, this.innerQuery)
|
||||||
Object.assign(query, this._extraQuery)
|
Object.assign(query, this._extraQuery)
|
||||||
|
|
||||||
query[this.pageSizeKey] = this.hasPagination
|
query[this.pageSizeKey] = this.hasPagination
|
||||||
@@ -939,18 +941,9 @@ export default {
|
|||||||
this.loading = false
|
this.loading = false
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
async search() {
|
search(attrs) {
|
||||||
const form = this.$refs.searchForm
|
this.innerQuery = Object.assign(this.innerQuery, attrs)
|
||||||
const valid = await new Promise(r => form.validate(r))
|
return this.getList()
|
||||||
if (!valid) return
|
|
||||||
|
|
||||||
try {
|
|
||||||
await this.beforeSearch(form.getFormValue())
|
|
||||||
this.page = defaultFirstPage
|
|
||||||
this.getList()
|
|
||||||
} catch (err) {
|
|
||||||
this.$emit('error', err)
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* 重置查询,相当于点击「重置」按钮
|
* 重置查询,相当于点击「重置」按钮
|
||||||
@@ -1165,15 +1158,12 @@ export default {
|
|||||||
return record[this.treeChildKey] && record[this.treeChildKey].length > 0
|
return record[this.treeChildKey] && record[this.treeChildKey].length > 0
|
||||||
},
|
},
|
||||||
onSortChange({ column, prop, order }) {
|
onSortChange({ column, prop, order }) {
|
||||||
if (!this.extraQuery) {
|
|
||||||
this.extraQuery = {}
|
|
||||||
}
|
|
||||||
if (!order) {
|
if (!order) {
|
||||||
delete this.extraQuery['sort']
|
delete this.innerQuery['sort']
|
||||||
delete this.extraQuery['direction']
|
delete this.innerQuery['direction']
|
||||||
} else {
|
} else {
|
||||||
this.extraQuery['sort'] = prop
|
this.innerQuery['sort'] = prop
|
||||||
this.extraQuery['direction'] = order
|
this.innerQuery['direction'] = order
|
||||||
}
|
}
|
||||||
this.getList()
|
this.getList()
|
||||||
}
|
}
|
||||||
|
@@ -91,6 +91,9 @@ export default {
|
|||||||
getList() {
|
getList() {
|
||||||
this.$refs.table.clearSelection()
|
this.$refs.table.clearSelection()
|
||||||
return this.$refs.table.getList()
|
return this.$refs.table.getList()
|
||||||
|
},
|
||||||
|
search(attrs) {
|
||||||
|
return this.$refs.table.search(attrs)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -14,6 +14,7 @@
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
import ActionsGroup from '@/components/ActionsGroup'
|
import ActionsGroup from '@/components/ActionsGroup'
|
||||||
|
import _ from 'lodash';
|
||||||
import { createSourceIdCache } from '@/api/common'
|
import { createSourceIdCache } from '@/api/common'
|
||||||
|
|
||||||
const defaultTrue = { type: Boolean, default: true }
|
const defaultTrue = { type: Boolean, default: true }
|
||||||
@@ -46,6 +47,10 @@ export default {
|
|||||||
type: Function,
|
type: Function,
|
||||||
default: () => {}
|
default: () => {}
|
||||||
},
|
},
|
||||||
|
searchTable: {
|
||||||
|
type: Function,
|
||||||
|
default: () => {}
|
||||||
|
},
|
||||||
selectedRows: {
|
selectedRows: {
|
||||||
type: Array,
|
type: Array,
|
||||||
default: () => ([])
|
default: () => ([])
|
||||||
@@ -57,6 +62,10 @@ export default {
|
|||||||
extraMoreActions: {
|
extraMoreActions: {
|
||||||
type: Array,
|
type: Array,
|
||||||
default: () => ([])
|
default: () => ([])
|
||||||
|
},
|
||||||
|
extraRightSideActions: {
|
||||||
|
type: Array,
|
||||||
|
default: () => ([])
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
@@ -65,7 +74,7 @@ export default {
|
|||||||
defaultRightSideActions: [
|
defaultRightSideActions: [
|
||||||
{ name: 'actionExport', fa: 'fa-download', has: this.hasExport },
|
{ name: 'actionExport', fa: 'fa-download', has: this.hasExport },
|
||||||
{ name: 'actionImport', fa: 'fa-upload', has: this.hasImport },
|
{ name: 'actionImport', fa: 'fa-upload', has: this.hasImport },
|
||||||
{ name: 'actionRefresh', fa: 'fa-refresh', has: this.hasRefresh }
|
{ name: 'actionRefresh', fa: 'fa-refresh', has: this.hasRefresh, callback: this.handleRefresh }
|
||||||
],
|
],
|
||||||
defaultActions: [
|
defaultActions: [
|
||||||
{
|
{
|
||||||
@@ -97,33 +106,18 @@ export default {
|
|||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
rightSideActions() {
|
rightSideActions() {
|
||||||
const actions = []
|
const actions = [...this.defaultRightSideActions, ...this.extraRightSideActions]
|
||||||
return actions
|
return this.cleanActions(actions)
|
||||||
for (const k in this.defaultRightSideActions) {
|
|
||||||
if (this['has' + k]) {
|
|
||||||
actions.push(this.defaultRightSideActions[k])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return actions
|
|
||||||
},
|
},
|
||||||
actions() {
|
actions() {
|
||||||
const actions = [...this.defaultActions, ...this.extraActions]
|
const actions = [...this.defaultActions, ...this.extraActions]
|
||||||
const validActions = []
|
return this.cleanActions(actions)
|
||||||
for (const action of actions) {
|
|
||||||
let ok = this.checkItem(action, 'has')
|
|
||||||
if (!ok) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
ok = this.checkItem(action, 'can')
|
|
||||||
action.disabled = !ok
|
|
||||||
validActions.push(action)
|
|
||||||
}
|
|
||||||
console.log(validActions)
|
|
||||||
return validActions
|
|
||||||
},
|
},
|
||||||
moreActions() {
|
moreActions() {
|
||||||
return this.defaultMoreActions
|
const actions = [...this.defaultMoreActions, ...this.extraMoreActions]
|
||||||
|
return this.cleanActions(actions)
|
||||||
},
|
},
|
||||||
|
|
||||||
namedActions() {
|
namedActions() {
|
||||||
const totalActions = [...this.actions, ...this.moreActions, ...this.rightSideActions]
|
const totalActions = [...this.actions, ...this.moreActions, ...this.rightSideActions]
|
||||||
const actions = {}
|
const actions = {}
|
||||||
@@ -137,10 +131,11 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
handleSearch(keyword) {
|
handleSearch: _.debounce(function() {
|
||||||
console.log('Search: ', keyword)
|
this.searchTable({search: this.keyword})
|
||||||
},
|
}, 500),
|
||||||
handleActionClick(item) {
|
handleActionClick(item) {
|
||||||
|
console.log('name cations', this.namedActions)
|
||||||
let handler = this.namedActions[item] ? this.namedActions[item].callback : null
|
let handler = this.namedActions[item] ? this.namedActions[item].callback : null
|
||||||
if (!handler) {
|
if (!handler) {
|
||||||
handler = () => {
|
handler = () => {
|
||||||
@@ -185,13 +180,32 @@ export default {
|
|||||||
const ids = rows.map((v) => {
|
const ids = rows.map((v) => {
|
||||||
return v.id
|
return v.id
|
||||||
})
|
})
|
||||||
console.log('Delete ids: ', ids)
|
|
||||||
const data = await createSourceIdCache(ids)
|
const data = await createSourceIdCache(ids)
|
||||||
const url = `${this.tableUrl}?spm=` + data.spm
|
const url = `${this.tableUrl}?spm=` + data.spm
|
||||||
return this.$axios.delete(url)
|
return this.$axios.delete(url)
|
||||||
},
|
},
|
||||||
handleBulkUpdate(rows) {
|
handleBulkUpdate(rows) {
|
||||||
},
|
},
|
||||||
|
handleExport() {
|
||||||
|
},
|
||||||
|
handleImport() {
|
||||||
|
},
|
||||||
|
handleRefresh() {
|
||||||
|
this.reloadTable()
|
||||||
|
},
|
||||||
|
cleanActions(actions) {
|
||||||
|
const validActions = []
|
||||||
|
for (const action of actions) {
|
||||||
|
let ok = this.checkItem(action, 'has')
|
||||||
|
if (!ok) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
ok = this.checkItem(action, 'can')
|
||||||
|
action.disabled = !ok
|
||||||
|
validActions.push(action)
|
||||||
|
}
|
||||||
|
return validActions
|
||||||
|
},
|
||||||
checkItem(item, attr) {
|
checkItem(item, attr) {
|
||||||
let ok = item[attr]
|
let ok = item[attr]
|
||||||
if (typeof ok === 'function') {
|
if (typeof ok === 'function') {
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
<template>
|
<template>
|
||||||
<div>
|
<div>
|
||||||
<TableAction :table-url="tableConfig.url" v-bind="headerActions" :selected-rows="selectedRows" :reload-table="reloadTable"></TableAction>
|
<TableAction :table-url="tableConfig.url" :search-table="search" v-bind="headerActions" :selected-rows="selectedRows" :reload-table="reloadTable"></TableAction>
|
||||||
<el-card class="table-content" shadow="never">
|
<el-card class="table-content" shadow="never">
|
||||||
<DataTable ref="dataTable" :config="tableConfig" @selection-change="handleSelectionChange">
|
<DataTable ref="dataTable" :config="tableConfig" @selection-change="handleSelectionChange">
|
||||||
</DataTable>
|
</DataTable>
|
||||||
@@ -48,6 +48,9 @@ export default {
|
|||||||
},
|
},
|
||||||
reloadTable() {
|
reloadTable() {
|
||||||
this.$refs.dataTable.getList()
|
this.$refs.dataTable.getList()
|
||||||
|
},
|
||||||
|
search(attrs) {
|
||||||
|
return this.$refs.dataTable.search(attrs)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -41,6 +41,9 @@ import service from '@/utils/request'
|
|||||||
// if the table component cannot access `this.$axios`, it cannot send request
|
// if the table component cannot access `this.$axios`, it cannot send request
|
||||||
Vue.prototype.$axios = service
|
Vue.prototype.$axios = service
|
||||||
|
|
||||||
|
import _ from 'lodash'
|
||||||
|
Vue.use(_)
|
||||||
|
|
||||||
new Vue({
|
new Vue({
|
||||||
el: '#app',
|
el: '#app',
|
||||||
i18n,
|
i18n,
|
||||||
|
Reference in New Issue
Block a user