|
@@ -12,7 +12,7 @@ import setDialogToJs from "@/components/js-dialog-comp/useDialogToJs";
|
|
|
import CyDialog from "@/components/cy/dialog/src/CyDialog.vue";
|
|
|
import {IsCyDialog} from "@/components/cy/dialog/src/useCyDialog";
|
|
|
import CyFlex from "@/components/cy/flex/src/CyFlex.vue";
|
|
|
-import {tsxTemplate, tsxVModel} from "@/utils/cy-use/useTsxUtils";
|
|
|
+import {tsxVModel} from "@/utils/cy-use/useTsxUtils";
|
|
|
|
|
|
declare type PageQuery = {
|
|
|
currentPage?: number,
|
|
@@ -37,11 +37,21 @@ declare type SimplifiedConfiguration<D> = {
|
|
|
showCheckbox?: boolean,
|
|
|
mountedQuery?: boolean,
|
|
|
dialogProps?: IsCyDialog,
|
|
|
- dialogHeader?: () => any
|
|
|
+ dialogHeader?: () => any,
|
|
|
+ getQueryParams?: () => any,
|
|
|
}
|
|
|
|
|
|
|
|
|
-function useVxeTable<D = any>(simplifiedConfiguration: SimplifiedConfiguration<D>) {
|
|
|
+function useVxeTable<D>(simplifiedConfiguration: SimplifiedConfiguration<D> = {}) {
|
|
|
+ simplifiedConfiguration = {
|
|
|
+ rowHeight: 48,
|
|
|
+ keyField: '',
|
|
|
+ showPage: false,
|
|
|
+ mountedQuery: false,
|
|
|
+ result: 'result',
|
|
|
+ total: 'total',
|
|
|
+ ...simplifiedConfiguration
|
|
|
+ }
|
|
|
const tableRef: Ref<TablePublicMethods<D> & TableExportMethods<D> | undefined> = ref()
|
|
|
const props: VxeTableProps<D> & VxeTableEventProps<D> & SimplifiedConfiguration<D> = reactive({
|
|
|
height: 'auto',
|
|
@@ -50,9 +60,9 @@ function useVxeTable<D = any>(simplifiedConfiguration: SimplifiedConfiguration<D
|
|
|
rowConfig: {
|
|
|
isHover: true,
|
|
|
isCurrent: true,
|
|
|
- height: simplifiedConfiguration?.rowHeight || 48,
|
|
|
+ height: simplifiedConfiguration?.rowHeight,
|
|
|
useKey: true,
|
|
|
- keyField: simplifiedConfiguration?.keyField || '',
|
|
|
+ keyField: simplifiedConfiguration?.keyField,
|
|
|
},
|
|
|
stripe: true,
|
|
|
scrollY: {
|
|
@@ -88,10 +98,18 @@ function useVxeTable<D = any>(simplifiedConfiguration: SimplifiedConfiguration<D
|
|
|
delete props.rowConfig?.height
|
|
|
props.scrollY!.enabled = false
|
|
|
props!.showOverflow = false
|
|
|
- props!.checkboxConfig!.reserve = true
|
|
|
- if (stringIsBlank(props.rowConfig?.keyField)) {
|
|
|
+
|
|
|
+ if (stringIsBlank(simplifiedConfiguration.keyField)) {
|
|
|
BizException(ExceptionEnum.MESSAGE_ERROR, '请先设置行id')
|
|
|
}
|
|
|
+
|
|
|
+ if (!XEUtils.isFunction(simplifiedConfiguration.remoteSearch)) {
|
|
|
+ console.error('请设置remoteSearch函数')
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!XEUtils.isFunction(simplifiedConfiguration.getQueryParams)) {
|
|
|
+ console.error('请设置 getQueryParams 函数')
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
const pageVO = reactive({
|
|
@@ -126,8 +144,17 @@ function useVxeTable<D = any>(simplifiedConfiguration: SimplifiedConfiguration<D
|
|
|
|
|
|
const CyVxeTable = (props: VxeTableProps<D>, {slots}: any) => {
|
|
|
|
|
|
- mutation.setTableDefaultSlots = () => {
|
|
|
- return slots.default ? slots.default() : null
|
|
|
+ function getSlotsByName(name: string) {
|
|
|
+ return slots[name] ? slots[name]() : null
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ mutation.getTableDefaultSlots = () => {
|
|
|
+ return getSlotsByName('default')
|
|
|
+ }
|
|
|
+
|
|
|
+ mutation.getDialogHeaderSlots = () => {
|
|
|
+ return getSlotsByName('dialogHeader')
|
|
|
}
|
|
|
|
|
|
const TempVxeTable = () => {
|
|
@@ -156,14 +183,19 @@ function useVxeTable<D = any>(simplifiedConfiguration: SimplifiedConfiguration<D
|
|
|
return <ElPopover placement="right">
|
|
|
{{
|
|
|
default: () => {
|
|
|
+ const size = simplifiedConfiguration.showPage ? pageMemory.size : getCheckboxRecords().length
|
|
|
+
|
|
|
return [
|
|
|
- `当前选中${pageMemory.size}条`,
|
|
|
+ `当前选中${size}条`,
|
|
|
<div style="text-align: right;margin-top: 5px;">
|
|
|
<ElButton
|
|
|
type="primary"
|
|
|
onClick={(el) => {
|
|
|
- if (pageMemory.size > 0)
|
|
|
+ if (simplifiedConfiguration.showPage && pageMemory.size > 0) {
|
|
|
+ handelLookCheckBox()
|
|
|
+ } else if (size > 0) {
|
|
|
handelLookCheckBox()
|
|
|
+ }
|
|
|
}}
|
|
|
>{{default: () => '详情'}}
|
|
|
</ElButton>
|
|
@@ -211,7 +243,7 @@ function useVxeTable<D = any>(simplifiedConfiguration: SimplifiedConfiguration<D
|
|
|
}
|
|
|
}}
|
|
|
</VxeColumn> : null,
|
|
|
- ...slots.default ? slots.default() : null,
|
|
|
+ slots.default ? slots.default() : null,
|
|
|
];
|
|
|
}
|
|
|
}}
|
|
@@ -276,9 +308,9 @@ function useVxeTable<D = any>(simplifiedConfiguration: SimplifiedConfiguration<D
|
|
|
// @ts-ignore
|
|
|
simplifiedConfiguration.remoteSearch(data).then(res => {
|
|
|
// @ts-ignore
|
|
|
- const data: D[] = XEUtils.get(res, simplifiedConfiguration!.result || 'result') as D[]
|
|
|
+ const data: D[] = XEUtils.get(res, simplifiedConfiguration!.result) as D[]
|
|
|
// @ts-ignore
|
|
|
- const total: number = XEUtils.get(res, simplifiedConfiguration!.total || 'total') as number
|
|
|
+ const total: number = XEUtils.get(res, simplifiedConfiguration!.total) as number
|
|
|
props.data = data
|
|
|
pageVO.total = total
|
|
|
}).catch((e) => {
|
|
@@ -298,14 +330,19 @@ function useVxeTable<D = any>(simplifiedConfiguration: SimplifiedConfiguration<D
|
|
|
|
|
|
const pageMemory = reactive(new Map<any, D>());
|
|
|
|
|
|
- function getCheckboxRecords() {
|
|
|
- // @ts-ignore
|
|
|
- return eachAndReturnList(pageMemory, (item) => {
|
|
|
- return item
|
|
|
- })
|
|
|
+ function getCheckboxRecords(): D[] {
|
|
|
+ if (simplifiedConfiguration.showPage) {
|
|
|
+ // @ts-ignore
|
|
|
+ return eachAndReturnList(pageMemory, (item) => {
|
|
|
+ return item
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ return tableRef.value!.getCheckboxRecords()
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
function handelCheckbox() {
|
|
|
+ if (simplifiedConfiguration.showPage) return
|
|
|
const data = tableRef.value!.getCheckboxRecords()
|
|
|
if (data.length > 0) {
|
|
|
XEUtils.arrayEach(tableRef.value!.getCheckboxRecords(), (item) => {
|
|
@@ -342,18 +379,18 @@ function useVxeTable<D = any>(simplifiedConfiguration: SimplifiedConfiguration<D
|
|
|
|
|
|
function querySearch() {
|
|
|
props.loading = true
|
|
|
- // @ts-ignore
|
|
|
if (simplifiedConfiguration.showPage) {
|
|
|
+ const parameterData = simplifiedConfiguration?.getQueryParams?.()
|
|
|
const pageData = {
|
|
|
...pageVO,
|
|
|
total: 0,
|
|
|
- currentPage: 1
|
|
|
+ currentPage: 1,
|
|
|
+ ...parameterData
|
|
|
}
|
|
|
queryParamsCache = pageData
|
|
|
pageQuery(pageData)
|
|
|
} else {
|
|
|
- // @ts-ignore
|
|
|
- simplifiedConfiguration.remoteSearch({...pageVO}).then(res => {
|
|
|
+ simplifiedConfiguration?.remoteSearch?.({}).then(res => {
|
|
|
props.data = res
|
|
|
}).catch(() => {
|
|
|
props.data = []
|
|
@@ -378,15 +415,16 @@ function useVxeTable<D = any>(simplifiedConfiguration: SimplifiedConfiguration<D
|
|
|
{{
|
|
|
header: () => {
|
|
|
try {
|
|
|
- if (simplifiedConfiguration.dialogHeader) {
|
|
|
- const Scc = simplifiedConfiguration?.dialogHeader();
|
|
|
- if (typeof Scc !== 'undefined') {
|
|
|
- return <Scc/>
|
|
|
- } else {
|
|
|
- console.error('dialogHeader需要返回一个组件')
|
|
|
- }
|
|
|
+ let HeaderSlots = null
|
|
|
+ if (mutation.getDialogHeaderSlots() != null) {
|
|
|
+ HeaderSlots = mutation.getDialogHeaderSlots()
|
|
|
+ } else if (simplifiedConfiguration.dialogHeader) {
|
|
|
+ HeaderSlots = simplifiedConfiguration?.dialogHeader();
|
|
|
+ }
|
|
|
+ console.log(HeaderSlots)
|
|
|
+ if (HeaderSlots != null) {
|
|
|
+ return HeaderSlots
|
|
|
}
|
|
|
-
|
|
|
} catch (e) {
|
|
|
console.error('dialogHeader需要返回一个组件', e)
|
|
|
return null
|
|
@@ -406,7 +444,7 @@ function useVxeTable<D = any>(simplifiedConfiguration: SimplifiedConfiguration<D
|
|
|
{{
|
|
|
default: () => {
|
|
|
return [
|
|
|
- <VxeColumn title={"删除"} width={80} fixed="left">
|
|
|
+ <VxeColumn title={"取消选中"} width={80} fixed="left">
|
|
|
{{
|
|
|
default({row}: any) {
|
|
|
return <ElButton
|
|
@@ -414,12 +452,12 @@ function useVxeTable<D = any>(simplifiedConfiguration: SimplifiedConfiguration<D
|
|
|
onClick={(el) => {
|
|
|
handelCheckboxChange({row, checked: false})
|
|
|
}}
|
|
|
- >{{default: () => '删除'}}
|
|
|
+ >{{default: () => '取消'}}
|
|
|
</ElButton>
|
|
|
}
|
|
|
}}
|
|
|
</VxeColumn>,
|
|
|
- mutation.setTableDefaultSlots()
|
|
|
+ mutation.getTableDefaultSlots()
|
|
|
]
|
|
|
}
|
|
|
}}
|
|
@@ -450,7 +488,7 @@ function useVxeTable<D = any>(simplifiedConfiguration: SimplifiedConfiguration<D
|
|
|
await tableRef.value?.setCheckboxRow(row, checked)
|
|
|
// @ts-ignore
|
|
|
const key = XEUtils.get(row, simplifiedConfiguration!.keyField, null) as string | null
|
|
|
- if (key === null) return
|
|
|
+ if (key === null || !simplifiedConfiguration.showPage) return
|
|
|
if (checked) {
|
|
|
pageMemory.set(key, row)
|
|
|
} else {
|
|
@@ -461,7 +499,10 @@ function useVxeTable<D = any>(simplifiedConfiguration: SimplifiedConfiguration<D
|
|
|
tableRef.value?.clearCheckboxRow()
|
|
|
pageMemory.clear()
|
|
|
},
|
|
|
- setTableDefaultSlots(): any {
|
|
|
+ getTableDefaultSlots(): any {
|
|
|
+
|
|
|
+ },
|
|
|
+ getDialogHeaderSlots(): any {
|
|
|
|
|
|
}
|
|
|
}
|