vue + Ant Design 表格多選 mixin

/**
 * 用于 mixin 表格多選 
 **/

export const rowSelectionMixin = {
    data() {
        return {
            /* table選中keys*/
            selectedRowKeys: [],
            /* table選中records*/
            selectionRows: [],
        }
    },
    computed: {
        rowSelection() {
            return {
                selectedRowKeys: this.selectedRowKeys,
                onChange: this.onSelectChange,
                getCheckboxProps: record => ({
                    props: {
                        /** 禁止選擇行
                         *  默認(rèn)不禁止任何行,如果有需要 可以通過(guò) disabledRow 方法進(jìn)行操作
                         *  在表格數(shù)組改變的時(shí)候,會(huì)調(diào)用此處回調(diào),如果禁止選擇條件變化,需要重新對(duì)表格數(shù)據(jù)進(jìn)行賦值
                         *  e.g: this.dataSource = [...this.dataSource]
                         *  改變禁止選擇條件時(shí),要先清空之前選擇的數(shù)據(jù)
                         */
                        disabled: this.disabledRow ? this.disabledRow(record) : false
                    }
                })
            }
        }
    },
    methods: {
        // 此方法不傳參數(shù)默認(rèn)取消選擇框,但是當(dāng)此方法在 組件中直接調(diào)用時(shí),要注意加(),因?yàn)椴患訒?huì)默認(rèn)傳一個(gè)點(diǎn)擊事件的對(duì)象過(guò)來(lái),會(huì)報(bào)錯(cuò)
        onSelectChange(selectedRowKeys = [], selectionRows = []) {
            console.log(selectedRowKeys);
            this.selectedRowKeys = selectedRowKeys;
            this.selectionRows = selectionRows;
        },
        // 批量操作
        /** 
         * 傳入一個(gè)回調(diào)函數(shù),此處進(jìn)行默認(rèn)判斷空減少重復(fù)操作 
         * 例子: @click="batchOperation(()=>changeHeadTeacher('selectedRows',12313))"
         * 加一個(gè)空方法來(lái)中轉(zhuǎn),因?yàn)?@click="batchOperation(changeHeadTeacher('selectedRows',12313))" 會(huì)將執(zhí)行完的方法的返回值作為參數(shù)傳進(jìn)來(lái)
         */
        batchOperation(callback = () => {}) {
            console.log(callback);
            if (this.selectedRowKeys.length > 0) callback();
            else this.$message.warning("至少選擇一條數(shù)據(jù)!")
        }
    }
}

vue 富文本圖片上傳處理
vue Ant Design Select 選擇框輸入搜索已有數(shù)據(jù) mixin

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容