功能变化: 注册selectorTable前端组件

pull/103/head
李强 2023-06-10 15:37:54 +08:00
parent ccf21dcb1e
commit 3d662e0f0e
2 changed files with 23 additions and 8 deletions

View File

@ -3,6 +3,7 @@ import Vue from 'vue'
import d2Container from './d2-container' import d2Container from './d2-container'
import tableProgress from './table-progress/lib/table-progress.vue' import tableProgress from './table-progress/lib/table-progress.vue'
import cardSelect from '@/components/card-select/index' import cardSelect from '@/components/card-select/index'
import selectorTable from '@/components/selector-table/index'
// 注意 有些组件使用异步加载会有影响 // 注意 有些组件使用异步加载会有影响
Vue.component('d2-container', d2Container) Vue.component('d2-container', d2Container)
Vue.component('d2-icon', () => import('./d2-icon')) Vue.component('d2-icon', () => import('./d2-icon'))
@ -14,4 +15,5 @@ Vue.component('d2p-tree-selector', () => import('./tree-selector/lib/tree-select
Vue.component('dept-format', () => import('./dept-format/lib/dept-format.vue')) Vue.component('dept-format', () => import('./dept-format/lib/dept-format.vue'))
Vue.component('dvaHtml2pdf', () => import('./dvaHtml2pdf/index.vue')) Vue.component('dvaHtml2pdf', () => import('./dvaHtml2pdf/index.vue'))
Vue.component('table-progress', tableProgress) Vue.component('table-progress', tableProgress)
Vue.use(selectorTable)
Vue.use(cardSelect) Vue.use(cardSelect)

View File

@ -92,6 +92,7 @@ export default {
default () { default () {
return { return {
tableConfig: { tableConfig: {
pagination: true,
multiple: false, multiple: false,
columns: [] columns: []
} }
@ -160,10 +161,10 @@ export default {
handler (newValue, oldVal) { handler (newValue, oldVal) {
const { tableConfig } = this._elProps const { tableConfig } = this._elProps
// //
if (!tableConfig.multiple) { if (tableConfig.multiple) {
this.currentValue = [newValue]
} else {
this.currentValue = newValue this.currentValue = newValue
} else {
this.currentValue = [newValue]
} }
}, },
deep: true, deep: true,
@ -196,19 +197,27 @@ export default {
methods: { methods: {
// //
setCurrentValue (val) { setCurrentValue (val) {
const params = {}
if (this._elProps.tableConfig.pagination) {
params.page = this.pageConfig.page
params.limit = this.pageConfig.limit
}
if (val.toString().length > 0) { if (val.toString().length > 0) {
// value // value
const { url, value, label } = this.dict const { url, value, label } = this.dict
const params = {}
params[value] = val params[value] = val
params.query = `{${label},${value}}`
return request({ return request({
url: url, url: url,
params: params, params: params,
method: 'get' method: 'get'
}).then(res => { }).then(res => {
const { data } = res.data const { data, page, limit, total } = res
if (data && data.length > 0) { this.pageConfig.page = page
this.currentValue = data this.pageConfig.limit = limit
this.pageConfig.total = total
if (data.data && data.data.length > 0) {
this.currentValue = data.data
} else { } else {
this.currentValue = null this.currentValue = null
} }
@ -220,6 +229,7 @@ export default {
// //
getDict () { getDict () {
const that = this const that = this
const { value, label } = this.dict
let url let url
if (typeof that.dict.url === 'function') { if (typeof that.dict.url === 'function') {
const form = that.d2CrudContext.getForm() const form = that.d2CrudContext.getForm()
@ -233,7 +243,8 @@ export default {
} }
const params = { const params = {
page: that.pageConfig.page, page: that.pageConfig.page,
limit: that.pageConfig.limit limit: that.pageConfig.limit,
query: `{${label},${value}}`
} }
if (that.search) { if (that.search) {
params.search = that.search params.search = that.search
@ -269,6 +280,7 @@ export default {
const { tableConfig } = that._elProps const { tableConfig } = that._elProps
if (tableConfig.multiple) { if (tableConfig.multiple) {
that.$refs.tableRef.clearSelection() // , that.$refs.tableRef.clearSelection() // ,
// eslint-disable-next-line no-unused-expressions
that.currentValue ? that.currentValue.forEach(item => { that.currentValue ? that.currentValue.forEach(item => {
that.$refs.tableRef.toggleRowSelection(item, true) that.$refs.tableRef.toggleRowSelection(item, true)
}) : null }) : null
@ -333,6 +345,7 @@ export default {
this.$emit('input', '') this.$emit('input', '')
this.$emit('change', '') this.$emit('change', '')
} else { } else {
// eslint-disable-next-line no-unused-expressions
this.$refs.tableRef?.toggleRowSelection(obj, false) this.$refs.tableRef?.toggleRowSelection(obj, false)
// const { value } = this.dict // const { value } = this.dict
// const result = this.currentValue.map((item) => { // const result = this.currentValue.map((item) => {