fix: 无法打开的bug

This commit is contained in:
2023-07-21 22:14:10 +08:00
parent 11bdda1a4b
commit 9451a8dd53
2 changed files with 24 additions and 9 deletions

View File

@ -2,15 +2,15 @@
* @Author: zhaojinfeng 121016171@qq.com * @Author: zhaojinfeng 121016171@qq.com
* @Date: 2023-07-18 12:30:07 * @Date: 2023-07-18 12:30:07
* @LastEditors: zhaojinfeng 121016171@qq.com * @LastEditors: zhaojinfeng 121016171@qq.com
* @LastEditTime: 2023-07-21 21:39:13 * @LastEditTime: 2023-07-21 22:13:32
* @FilePath: \vue3\packages\select-table-modal\index.vue * @FilePath: \vue3\packages\select-table-modal\index.vue
* @Description: 模态框选择表格 * @Description: 模态框选择表格
* *
--> -->
<template> <template>
<span @click="showDialog = true"> <span v-if="!hideButton" @click="open">
<slot> <slot>
<el-button @click="showDialog = true">点击选择</el-button> <el-button type="primary" plain>点击选择</el-button>
</slot> </slot>
</span> </span>
<el-config-provider :locale="locale"> <el-config-provider :locale="locale">
@ -84,7 +84,7 @@ const props = withDefaults(
emptyText?: string emptyText?: string
value?: any value?: any
rowKey?: string rowKey?: string
show: boolean show?: boolean
columns: Partial<TableColumnCtx<any>>[] columns: Partial<TableColumnCtx<any>>[]
formItems: FormItem[] formItems: FormItem[]
defaultParams?: Record<string, any> defaultParams?: Record<string, any>
@ -123,14 +123,25 @@ interface FormItem {
value: string value: string
}[] }[]
} }
const showDialog = useVModel(props, 'show') const showDialog = ref(false)
let tableData = $ref<any[]>([]) let tableData = $ref<any[]>([])
let selection = $ref<any>() let selection = $ref<any>()
function confirm() { function confirm() {
emit('confirm', selection) emit('confirm', selection)
showDialog.value = false if (props.hideButton)
emit('update:show', false)
else
showDialog.value = false
} }
function open() {
if (props.hideButton)
emit('update:show', true)
else
showDialog.value = true
}
let total = $ref(0) let total = $ref(0)
function handleCurrentChange(val?: any) { function handleCurrentChange(val?: any) {
@ -186,4 +197,9 @@ function closed() {
queryParams.pageNum = 1 queryParams.pageNum = 1
selection = undefined selection = undefined
} }
watch(() => props.show,
(show) => {
showDialog.value = show
})
</script> </script>

View File

@ -2,7 +2,7 @@
* @Author: zhaojinfeng 121016171@qq.com * @Author: zhaojinfeng 121016171@qq.com
* @Date: 2023-07-18 12:30:07 * @Date: 2023-07-18 12:30:07
* @LastEditors: zhaojinfeng 121016171@qq.com * @LastEditors: zhaojinfeng 121016171@qq.com
* @LastEditTime: 2023-07-21 21:40:46 * @LastEditTime: 2023-07-21 22:03:59
* @FilePath: \vue3\stories\SelectTableModal.stories.ts * @FilePath: \vue3\stories\SelectTableModal.stories.ts
* @Description: * @Description:
* *
@ -30,7 +30,6 @@ const meta = {
args: { args: {
value: '', value: '',
rowKey: 'prop1', rowKey: 'prop1',
show: false,
columns: [{ label: 'label1', prop: 'prop1' }, { label: 'label2', prop: 'prop2' }, { label: 'label3', prop: 'prop3' }], columns: [{ label: 'label1', prop: 'prop1' }, { label: 'label2', prop: 'prop2' }, { label: 'label3', prop: 'prop3' }],
formItems: [{ label: 'label1', prop: 'prop1' }, { label: 'label2', prop: 'prop2', selectOptions: [{ label: '1', value: '1' }, { label: '2', value: '2' }] }], formItems: [{ label: 'label1', prop: 'prop1' }, { label: 'label2', prop: 'prop2', selectOptions: [{ label: '1', value: '1' }, { label: '2', value: '2' }] }],
defaultParams: {}, defaultParams: {},
@ -46,7 +45,7 @@ const meta = {
return { args } return { args }
}, },
template: `<th-select-table-modal template: `<th-select-table-modal
v-model:show="args.show" v-model:value="args.value"
:row-key="args.rowKey" :row-key="args.rowKey"
:columns="args.columns" :columns="args.columns"
:form-items="args.formItems" :form-items="args.formItems"