|
@@ -29,6 +29,7 @@ const props = withDefaults(
|
|
|
checkPageMultiple?: boolean //是否跨页多选
|
|
checkPageMultiple?: boolean //是否跨页多选
|
|
|
hasCheckbox?: boolean //是否有选择框 (checkMultiple 和 checkPageMultiple 为true 时不起作用)
|
|
hasCheckbox?: boolean //是否有选择框 (checkMultiple 和 checkPageMultiple 为true 时不起作用)
|
|
|
rowClickFun?: (r: any) => void
|
|
rowClickFun?: (r: any) => void
|
|
|
|
|
+ rowDbClickFun?: (r: any) => void
|
|
|
sortField?: string //排序字段
|
|
sortField?: string //排序字段
|
|
|
sortOrder?: "asc" | "desc"
|
|
sortOrder?: "asc" | "desc"
|
|
|
pagination?: boolean //是否分页
|
|
pagination?: boolean //是否分页
|
|
@@ -39,6 +40,7 @@ const props = withDefaults(
|
|
|
fixedRightNumber?: number //右边固定列数
|
|
fixedRightNumber?: number //右边固定列数
|
|
|
emptyTableText?: string
|
|
emptyTableText?: string
|
|
|
maxVisibleButtons?: number // 显示分页按钮数量
|
|
maxVisibleButtons?: number // 显示分页按钮数量
|
|
|
|
|
+ tableTitle?: string //排序字段
|
|
|
tableBoxClass?: string
|
|
tableBoxClass?: string
|
|
|
tableClass?: string
|
|
tableClass?: string
|
|
|
headerClass?: string
|
|
headerClass?: string
|
|
@@ -55,11 +57,13 @@ const props = withDefaults(
|
|
|
childrenField?: string
|
|
childrenField?: string
|
|
|
leafField?: string
|
|
leafField?: string
|
|
|
isLazy?: boolean
|
|
isLazy?: boolean
|
|
|
|
|
+ isLazySearch?: boolean
|
|
|
rootId?: string
|
|
rootId?: string
|
|
|
searchFormRowItems?: Array<VbFormRowItem>
|
|
searchFormRowItems?: Array<VbFormRowItem>
|
|
|
searchFormItems?: Array<VbFormItem>
|
|
searchFormItems?: Array<VbFormItem>
|
|
|
searchFormSpan?: number
|
|
searchFormSpan?: number
|
|
|
showToolbar?: boolean //是否显示toolbar
|
|
showToolbar?: boolean //是否显示toolbar
|
|
|
|
|
+ showSearchBar?: boolean //是否显示Searchbar
|
|
|
showRightToolbar?: boolean //是否显示右边的toolbar
|
|
showRightToolbar?: boolean //是否显示右边的toolbar
|
|
|
showRightSearchBtn?: boolean //初始是否显示搜索栏
|
|
showRightSearchBtn?: boolean //初始是否显示搜索栏
|
|
|
showRightColumnBtn?: boolean //是否显示右边toolbar的选择列按钮
|
|
showRightColumnBtn?: boolean //是否显示右边toolbar的选择列按钮
|
|
@@ -108,6 +112,7 @@ const props = withDefaults(
|
|
|
isTree: false,
|
|
isTree: false,
|
|
|
childrenField: "children",
|
|
childrenField: "children",
|
|
|
showToolbar: true,
|
|
showToolbar: true,
|
|
|
|
|
+ showSearchBar: true,
|
|
|
showRightToolbar: true,
|
|
showRightToolbar: true,
|
|
|
showRightColumnBtn: true,
|
|
showRightColumnBtn: true,
|
|
|
showRightSearchBtn: true,
|
|
showRightSearchBtn: true,
|
|
@@ -131,7 +136,7 @@ const emits = defineEmits<{
|
|
|
(e: "on-items-all-change", isChecked: boolean, rows: Array<any>): void
|
|
(e: "on-items-all-change", isChecked: boolean, rows: Array<any>): void
|
|
|
}>()
|
|
}>()
|
|
|
const id = ref("")
|
|
const id = ref("")
|
|
|
-const checkboxField = ref(props.keyField ? props.keyField : props.header[0].field)
|
|
|
|
|
|
|
+const keyField = ref(props.keyField ? props.keyField : props.header[0].field)
|
|
|
const currentPage = ref(props.currentPage)
|
|
const currentPage = ref(props.currentPage)
|
|
|
const itemsInTable = ref(props.pagination ? props.pageArray[0] : 1000)
|
|
const itemsInTable = ref(props.pagination ? props.pageArray[0] : 1000)
|
|
|
const selectedIds = ref(props.selectedIds)
|
|
const selectedIds = ref(props.selectedIds)
|
|
@@ -167,7 +172,7 @@ const dataToDisplay = computed(() => {
|
|
|
}
|
|
}
|
|
|
})
|
|
})
|
|
|
const totalItems = computed(() => {
|
|
const totalItems = computed(() => {
|
|
|
- if (props.url) {
|
|
|
|
|
|
|
+ if (props.remoteFun || props.url) {
|
|
|
return remoteTotal.value
|
|
return remoteTotal.value
|
|
|
} else if (props.data) {
|
|
} else if (props.data) {
|
|
|
if (props.data.length <= itemsInTable.value) {
|
|
if (props.data.length <= itemsInTable.value) {
|
|
@@ -232,14 +237,21 @@ function remote(id?: string) {
|
|
|
let curData: any = {}
|
|
let curData: any = {}
|
|
|
if (props.isLazy) {
|
|
if (props.isLazy) {
|
|
|
curData = treeAllData.find((v: any) => {
|
|
curData = treeAllData.find((v: any) => {
|
|
|
- return v[checkboxField.value] == id
|
|
|
|
|
|
|
+ return v[keyField.value] == id
|
|
|
})
|
|
})
|
|
|
|
|
+
|
|
|
if (!id && !curData) {
|
|
if (!id && !curData) {
|
|
|
throw new Error("懒加载模式,未获取到 parentId ,请检查")
|
|
throw new Error("懒加载模式,未获取到 parentId ,请检查")
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
if (curData?.children && curData?.children.length) {
|
|
if (curData?.children && curData?.children.length) {
|
|
|
- return
|
|
|
|
|
|
|
+ if (props.isLazySearch) {
|
|
|
|
|
+ curData.children = []
|
|
|
|
|
+ } else {
|
|
|
|
|
+ return Promise.resolve(0)
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
if (!props.keyField) {
|
|
if (!props.keyField) {
|
|
|
throw new Error("懒加载模式,请配置 keyField")
|
|
throw new Error("懒加载模式,请配置 keyField")
|
|
|
}
|
|
}
|
|
@@ -247,58 +259,87 @@ function remote(id?: string) {
|
|
|
}
|
|
}
|
|
|
tableLoading.value = true
|
|
tableLoading.value = true
|
|
|
|
|
|
|
|
- if (props.remoteFun) {
|
|
|
|
|
- props.remoteFun(params).then((res: any) => {
|
|
|
|
|
- processData(res.rows || res.data, res.total)
|
|
|
|
|
- })
|
|
|
|
|
- } else if (props.url) {
|
|
|
|
|
- const queryParam = props.method.toLocaleLowerCase() == "get" ? { params } : { data: params }
|
|
|
|
|
-
|
|
|
|
|
- const configs = Object.assign(
|
|
|
|
|
- { url: props.url, method: props.method, successAlert: false },
|
|
|
|
|
- props.configs,
|
|
|
|
|
- queryParam
|
|
|
|
|
- )
|
|
|
|
|
- Rs.request(configs)
|
|
|
|
|
- .then((res: any) => {
|
|
|
|
|
|
|
+ return new Promise((r) => {
|
|
|
|
|
+ if (props.remoteFun) {
|
|
|
|
|
+ props.remoteFun(params).then((res: any) => {
|
|
|
processData(res.rows || res.data, res.total)
|
|
processData(res.rows || res.data, res.total)
|
|
|
})
|
|
})
|
|
|
- .catch(() => {
|
|
|
|
|
- tableLoading.value = false
|
|
|
|
|
- })
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ } else if (props.url) {
|
|
|
|
|
+ const queryParam = props.method.toLocaleLowerCase() == "get" ? { params } : { data: params }
|
|
|
|
|
|
|
|
- function processData(data: any, total: number) {
|
|
|
|
|
- remoteTotal.value = total || 0
|
|
|
|
|
- tableLoading.value = false
|
|
|
|
|
- if (props.isLazy) {
|
|
|
|
|
- if (curData) {
|
|
|
|
|
- curData.children = data
|
|
|
|
|
- treeAllData.push(...curData.children)
|
|
|
|
|
- } else {
|
|
|
|
|
- treeData.push(...data)
|
|
|
|
|
- treeAllData.push(...treeData)
|
|
|
|
|
- }
|
|
|
|
|
- remoteData.value = JSON.parse(JSON.stringify(treeData))
|
|
|
|
|
- } else {
|
|
|
|
|
- remoteData.value = data
|
|
|
|
|
|
|
+ const configs = Object.assign(
|
|
|
|
|
+ { url: props.url, method: props.method, successAlert: false },
|
|
|
|
|
+ props.configs,
|
|
|
|
|
+ queryParam
|
|
|
|
|
+ )
|
|
|
|
|
+ Rs.request(configs)
|
|
|
|
|
+ .then((res: any) => {
|
|
|
|
|
+ processData(res.rows || res.data, res.total)
|
|
|
|
|
+ })
|
|
|
|
|
+ .catch(() => {
|
|
|
|
|
+ tableLoading.value = false
|
|
|
|
|
+ })
|
|
|
}
|
|
}
|
|
|
- if (props.checkPageMultiple) {
|
|
|
|
|
- remoteData.value.forEach((v: any) => {
|
|
|
|
|
- if (
|
|
|
|
|
- !allData.value.find((vv: any) => {
|
|
|
|
|
- return vv[checkboxField.value] == v[checkboxField.value]
|
|
|
|
|
|
|
+
|
|
|
|
|
+ function processData(data: any, total: number) {
|
|
|
|
|
+ remoteTotal.value = total || 0
|
|
|
|
|
+ tableLoading.value = false
|
|
|
|
|
+ let all: any = []
|
|
|
|
|
+ if (props.isLazy) {
|
|
|
|
|
+ if (props.isLazySearch) {
|
|
|
|
|
+ Object.keys(queryParams.value).forEach((v) => {
|
|
|
|
|
+ queryParams.value[v] = undefined
|
|
|
})
|
|
})
|
|
|
- ) {
|
|
|
|
|
- allData.value.push(v)
|
|
|
|
|
|
|
+ if (!data.length) {
|
|
|
|
|
+ const item = {}
|
|
|
|
|
+ item[props.iconField ?? ""] = "没有查询到字节点"
|
|
|
|
|
+ item[props.leafField ?? ""] = true
|
|
|
|
|
+ item[props.parentField ?? ""] = id
|
|
|
|
|
+ data.push(item)
|
|
|
|
|
+ }
|
|
|
|
|
+ r(1)
|
|
|
}
|
|
}
|
|
|
- })
|
|
|
|
|
- } else {
|
|
|
|
|
- allData.value = remoteData.value
|
|
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
- nextTick(bindEvent)
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ if (curData) {
|
|
|
|
|
+ curData.children = []
|
|
|
|
|
+ data.forEach((v: any) => {
|
|
|
|
|
+ const index = treeAllData.findIndex((vv: any) => {
|
|
|
|
|
+ return vv[keyField.value] == v[keyField.value]
|
|
|
|
|
+ })
|
|
|
|
|
+ if (index < 0) {
|
|
|
|
|
+ treeAllData.push(v)
|
|
|
|
|
+ curData.children.push(treeAllData[treeAllData.length - 1])
|
|
|
|
|
+ } else {
|
|
|
|
|
+ curData.children.push(treeAllData[index])
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
+ } else {
|
|
|
|
|
+ treeData.push(...data)
|
|
|
|
|
+ treeAllData.push(...treeData)
|
|
|
|
|
+ }
|
|
|
|
|
+ remoteData.value = JSON.parse(JSON.stringify(treeData))
|
|
|
|
|
+ all = treeAllData
|
|
|
|
|
+ } else {
|
|
|
|
|
+ remoteData.value = data
|
|
|
|
|
+ all = data
|
|
|
|
|
+ }
|
|
|
|
|
+ if (props.checkPageMultiple) {
|
|
|
|
|
+ all.forEach((v: any) => {
|
|
|
|
|
+ if (
|
|
|
|
|
+ !allData.value.find((vv: any) => {
|
|
|
|
|
+ return vv[keyField.value] == v[keyField.value]
|
|
|
|
|
+ })
|
|
|
|
|
+ ) {
|
|
|
|
|
+ allData.value.push(v)
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
+ } else {
|
|
|
|
|
+ allData.value = all
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ nextTick(bindEvent)
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function lazyLoad(id: string) {
|
|
function lazyLoad(id: string) {
|
|
@@ -320,7 +361,7 @@ const defaultHandleFuns = {
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
if (props.getEntiyFun) {
|
|
if (props.getEntiyFun) {
|
|
|
- props.getEntiyFun(row[checkboxField.value]).then((res) => {
|
|
|
|
|
|
|
+ props.getEntiyFun(row[keyField.value]).then((res) => {
|
|
|
emits("update:formData", res.data)
|
|
emits("update:formData", res.data)
|
|
|
if (props.modal) {
|
|
if (props.modal) {
|
|
|
props.modal.show()
|
|
props.modal.show()
|
|
@@ -345,7 +386,7 @@ const defaultHandleFuns = {
|
|
|
message.alertError("删除接口方法未配置,请联系管理员")
|
|
message.alertError("删除接口方法未配置,请联系管理员")
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
- const ids = rows.map((v: any) => v[checkboxField.value])
|
|
|
|
|
|
|
+ const ids = rows.map((v: any) => v[keyField.value])
|
|
|
message
|
|
message
|
|
|
.confirm('是否确认删除编号为"' + ids.join(",") + '"的数据项?')
|
|
.confirm('是否确认删除编号为"' + ids.join(",") + '"的数据项?')
|
|
|
.then(() => {
|
|
.then(() => {
|
|
@@ -422,7 +463,7 @@ function search() {
|
|
|
query()
|
|
query()
|
|
|
}
|
|
}
|
|
|
function bindEvent() {
|
|
function bindEvent() {
|
|
|
- if (props.rowClickFun) {
|
|
|
|
|
|
|
+ if (props.rowClickFun || props.rowDbClickFun) {
|
|
|
const tableBox = document.getElementById(id.value)
|
|
const tableBox = document.getElementById(id.value)
|
|
|
const table = tableBox?.querySelector("table")
|
|
const table = tableBox?.querySelector("table")
|
|
|
const tableBody = table?.querySelector("tbody")
|
|
const tableBody = table?.querySelector("tbody")
|
|
@@ -430,12 +471,18 @@ function bindEvent() {
|
|
|
trs?.forEach((v) => {
|
|
trs?.forEach((v) => {
|
|
|
const trId = v.id.replace("tr_", "")
|
|
const trId = v.id.replace("tr_", "")
|
|
|
const row = allData.value.find((vv: any) => {
|
|
const row = allData.value.find((vv: any) => {
|
|
|
- return vv[checkboxField.value] == trId
|
|
|
|
|
- })
|
|
|
|
|
-
|
|
|
|
|
- v.addEventListener("click", () => {
|
|
|
|
|
- props.rowClickFun && props.rowClickFun(row)
|
|
|
|
|
|
|
+ return vv[keyField.value] == trId
|
|
|
})
|
|
})
|
|
|
|
|
+ if (props.rowClickFun) {
|
|
|
|
|
+ v.addEventListener("click", () => {
|
|
|
|
|
+ props.rowClickFun && props.rowClickFun(row)
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
+ if (props.rowDbClickFun) {
|
|
|
|
|
+ v.addEventListener("dbclick", () => {
|
|
|
|
|
+ props.rowDbClickFun && props.rowDbClickFun(row)
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
})
|
|
})
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -447,10 +494,11 @@ function getSelected() {
|
|
|
return items[0]
|
|
return items[0]
|
|
|
}
|
|
}
|
|
|
function getSelecteds() {
|
|
function getSelecteds() {
|
|
|
|
|
+ console.log("GETS", selectedIds.value, keyField.value, allData.value)
|
|
|
const selectedArr: Array<any> = []
|
|
const selectedArr: Array<any> = []
|
|
|
selectedIds.value.forEach((v) => {
|
|
selectedIds.value.forEach((v) => {
|
|
|
const item = allData.value.find((vv: any) => {
|
|
const item = allData.value.find((vv: any) => {
|
|
|
- return vv[checkboxField.value] == v
|
|
|
|
|
|
|
+ return vv[keyField.value] == v
|
|
|
})
|
|
})
|
|
|
selectedArr.push(item)
|
|
selectedArr.push(item)
|
|
|
})
|
|
})
|
|
@@ -513,9 +561,11 @@ defineExpose({ search, getSelectedIds, getSelected, getSelecteds, getData, defau
|
|
|
<TableToolbar
|
|
<TableToolbar
|
|
|
v-if="showToolbar"
|
|
v-if="showToolbar"
|
|
|
:selected-rows="selectedIds.length"
|
|
:selected-rows="selectedIds.length"
|
|
|
|
|
+ :show-search-bar="showSearchBar"
|
|
|
:show-right-toolbar="showRightToolbar"
|
|
:show-right-toolbar="showRightToolbar"
|
|
|
:show-right-search-btn="showRightSearchBtn"
|
|
:show-right-search-btn="showRightSearchBtn"
|
|
|
:show-right-column-btn="showRightColumnBtn"
|
|
:show-right-column-btn="showRightColumnBtn"
|
|
|
|
|
+ :table-title="tableTitle"
|
|
|
:header="header"
|
|
:header="header"
|
|
|
:queryParams="queryParams"
|
|
:queryParams="queryParams"
|
|
|
:searchFormItems="searchFormItems"
|
|
:searchFormItems="searchFormItems"
|
|
@@ -538,7 +588,7 @@ defineExpose({ search, getSelectedIds, getSelected, getSelecteds, getData, defau
|
|
|
:header="displayColumns"
|
|
:header="displayColumns"
|
|
|
:data="dataToDisplay"
|
|
:data="dataToDisplay"
|
|
|
v-model:selected-ids="selectedIds"
|
|
v-model:selected-ids="selectedIds"
|
|
|
- :checkbox-field="checkboxField"
|
|
|
|
|
|
|
+ :key-field="keyField"
|
|
|
:check-multiple="checkMultiple || checkPageMultiple"
|
|
:check-multiple="checkMultiple || checkPageMultiple"
|
|
|
:has-checkbox="checkMultiple || checkPageMultiple || hasCheckbox"
|
|
:has-checkbox="checkMultiple || checkPageMultiple || hasCheckbox"
|
|
|
:empty-table-text="emptyTableText"
|
|
:empty-table-text="emptyTableText"
|
|
@@ -558,12 +608,12 @@ defineExpose({ search, getSelectedIds, getSelected, getSelecteds, getData, defau
|
|
|
:is-tree="isTree"
|
|
:is-tree="isTree"
|
|
|
:interval-left="intervalLeft"
|
|
:interval-left="intervalLeft"
|
|
|
:icon-field="iconField"
|
|
:icon-field="iconField"
|
|
|
- :key-field="keyField"
|
|
|
|
|
:parent-field="parentField"
|
|
:parent-field="parentField"
|
|
|
:children-field="childrenField"
|
|
:children-field="childrenField"
|
|
|
:leaf-field="leafField"
|
|
:leaf-field="leafField"
|
|
|
:expand-depth="expandDepth"
|
|
:expand-depth="expandDepth"
|
|
|
:lazy-load="isLazy ? lazyLoad : undefined"
|
|
:lazy-load="isLazy ? lazyLoad : undefined"
|
|
|
|
|
+ :lazy-search="isLazySearch"
|
|
|
>
|
|
>
|
|
|
<template v-for="(_, name) in $slots" #[name]="{ row: item }">
|
|
<template v-for="(_, name) in $slots" #[name]="{ row: item }">
|
|
|
<slot :name="name" :row="item" />
|
|
<slot :name="name" :row="item" />
|