/**
* 用于 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