feat: table 添加action disable 功能

This commit is contained in:
bac-joker 2020-12-14 20:50:11 +08:00
parent 2ae642fd72
commit c287a54575
4 changed files with 14283 additions and 6 deletions

View File

@ -16,6 +16,7 @@
<Column prop="age" name="年龄" sort /> <Column prop="age" name="年龄" sort />
<Column prop="adr" name="地址" /> <Column prop="adr" name="地址" />
<Column prop="status" name="等级" /> <Column prop="status" name="等级" />
<Column name="操作" :action="action" />
</Wb-table> </Wb-table>
<Wb-button class="mt20" @click="getSelectedTr">获取选择的行</Wb-button> <Wb-button class="mt20" @click="getSelectedTr">获取选择的行</Wb-button>
</div> </div>
@ -255,12 +256,24 @@ export default {
func: function () { func: function () {
console.log(this) console.log(this)
console.log(arguments) console.log(arguments)
},
disabled(trData) {
if (trData.name === '张晓刚') {
return true;
}
return false;
} }
}, { }, {
text: '删除', text: '删除',
func: function () { func: function () {
console.log(this) console.log(this)
console.log(arguments) console.log(arguments)
},
disabled(trData) {
if (trData.name !== '张晓刚') {
return true;
}
return false;
} }
}], }],
component: function (trData, tdData) { component: function (trData, tdData) {
@ -337,6 +350,12 @@ export default {
}, },
methods: { methods: {
disabledCell(trData) {
if (trData.name === '张晓刚') {
return true;
}
return false;
},
formatDate: function (data) { formatDate: function (data) {
var year = data.getFullYear(); var year = data.getFullYear();
var m = data.getMonth(); var m = data.getMonth();

14238
packages/fes-ui/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,11 +1,12 @@
<template> <template>
<div class="ui-table-action"> <div class="ui-table-action">
<Wb-button <Wb-button
v-for="(item, index) in col.action" v-for="(item, index) in actions"
:key="index" :key="index"
@click.stop="fireAction(item, $event)" :disabled="item._disabled"
class="ui-table-action-text" :class="['ui-table-action-text', item.disabledClassName, item._disabled && 'disabled']"
type="text" type="text"
@click.stop="fireAction(item, $event)"
> >
{{ item.text }} {{ item.text }}
</Wb-button> </Wb-button>
@ -13,7 +14,6 @@
</template> </template>
<script> <script>
import WbButton from '../button'; import WbButton from '../button';
export default { export default {
components: { components: {
WbButton WbButton
@ -28,10 +28,26 @@ export default {
default: undefined default: undefined
} }
}, },
computed: {
actions() {
return this.col.action.map((item) => {
let _disabled = false;
if (typeof item.disabled === 'boolean') {
_disabled = item.disabled;
}
if (typeof item.disabled === 'function') {
_disabled = item.disabled(this.trData);
}
return Object.assign({_disabled}, item);
})
}
},
methods: { methods: {
fireAction(item, event) { fireAction(item, event) {
if (!item._disabled) {
this.$emit('on-click', item, this.trData, event); this.$emit('on-click', item, this.trData, event);
} }
} }
}
}; };
</script> </script>

View File

@ -73,6 +73,10 @@ $table-head-background-color: $background-color-base;
&:first-child { &:first-child {
padding-left: 0; padding-left: 0;
} }
&.disabled {
cursor: not-allowed;
color: #657180;
}
} }
.ui-table-column-sorter { .ui-table-column-sorter {
margin-left: 4px; margin-left: 4px;