3939</template >
4040
4141<script setup lang="ts">
42- import { ref , reactive , onMounted , provide , watch , nextTick } from ' vue'
42+ import { reactive , onMounted , provide , watch , nextTick , useTemplateRef } from ' vue'
4343import { useI18n } from ' vue-i18n'
4444import Table from ' /@/components/table/index.vue'
4545import TableHeader from ' /@/components/table/header/index.vue'
@@ -66,13 +66,14 @@ const emits = defineEmits<{
6666 (e : ' choice' , value : string []): void
6767}>()
6868
69- const tableRef = ref ()
7069const { t } = useI18n ()
7170const state = reactive ({
7271 ready: false ,
7372 tableSelectable: true ,
7473})
7574
75+ const tableRef = useTemplateRef (' tableRef' )
76+
7677const optBtn: OptButton [] = [
7778 {
7879 render: ' tipButton' ,
@@ -83,8 +84,8 @@ const optBtn: OptButton[] = [
8384 class: ' table-row-choice' ,
8485 disabledTip: false ,
8586 click : (row : TableRow ) => {
86- const elTableRef = tableRef .value .getRef ()
87- elTableRef .clearSelection ()
87+ const elTableRef = tableRef .value ? .getRef ()
88+ elTableRef ? .clearSelection ()
8889 emits (' choice' , props .returnFullUrl ? [row .full_url ] : [row .url ])
8990 },
9091 },
@@ -198,16 +199,16 @@ const onChoice = () => {
198199 files .push (props .returnFullUrl ? baTable .table .selection [key ].full_url : baTable .table .selection [key ].url )
199200 }
200201 emits (' choice' , files )
201- const elTableRef = tableRef .value .getRef ()
202- elTableRef .clearSelection ()
202+ const elTableRef = tableRef .value ? .getRef ()
203+ elTableRef ? .clearSelection ()
203204 }
204205}
205206
206207const onSelectionChange = (selection : TableRow []) => {
207208 if (props .limit == 0 ) return
208209 if (selection .length > props .limit ) {
209- const elTableRef = tableRef .value .getRef ()
210- elTableRef .toggleRowSelection (selection [selection .length - 1 ], false )
210+ const elTableRef = tableRef .value ? .getRef ()
211+ elTableRef ? .toggleRowSelection (selection [selection .length - 1 ], false )
211212 }
212213 state .tableSelectable = ! (selection .length >= props .limit )
213214}
0 commit comments