简体中文
md.del.before
约 649 字大约 2 分钟
2025-12-15
该钩子发生在删除(包含批量删除)从对象数据之前。 删除从对象数据前执行额外的业务动作,包含且不限于以下功能:
- 拦截删除从对象数据
参数
| 参数 | 说明 | 类型 |
|---|---|---|
| 通用参数 | 详见 | -- |
| objApiName | 从对象apiName | String |
| recordType | 从对象业务类型 | String |
| delDatas | 被删除的从对象数据 | Array |
返回结果
暂无
基础示例
某企业希望员工删除从对象时
需求描述:某企业要求在员工删除已创建的从对象数据时,先填写删除原因,然后执行删除操作,并统计这些删除记录及原因。
import resonInputDialog from './resonInput';
const ResonInputDialog = Vue.extend(resonInputDialog);
export default class Plugin {
apply() {
return [{
event: 'md.del.before',
functional: this.mdDelBefore.bind(this)
}]
}
//如果是vcrm项目的中台插件需要交互参数位置
//mdDelBefore(plugin, context)
mdDelBefore(context, plugin) {
return new Promise(resolve => {
const { delDatas = [] } = context;
const delIds = delDatas.filter(item => item._id);
// 存在已创建的从对象数据
if(delIds.length){
const div = document.createElement('div');
document.body.appendChild(div);
const dialog = this.instance = new ResonInputDialog({
el: div,
propsData: {
mainId: data._id || '',
delIds: delIds,
// 保存记录成功
success: () => {
destroy();
resolve();
},
// 未填写直接关闭
fail: () => {
destroy();
reject(); // 拦截删除
}
}
});
return;
}
})
}
destroy(){
if(this.instance){
this.instance.$destroy();
this.instance = null;
}
}
}<template>
<fx-dialog title="删除原因填写" :visible.sync="dialogFormVisible" width="20%">
<fx-form :model="form">
<fx-form-item label="删除原因" :labfx-width="'60px'">
<fx-select
v-model="form.name"
:options="options"
filterable
allow-create
default-first-option
placeholder="请选择删除原因">
</fx-select>
</fx-form-item>
</fx-form>
<div slot="footer" class="dialog-footer">
<fx-button @click="cancel">取 消</fx-button>
<fx-button type="primary" @click="confirm">确 定</fx-button>
</div>
</fx-dialog>
</template>
<script>
export default {
props: {
mainId: {
type: String,
default: ''
},
delIds: {
type: Array,
},
success: {
type: Function
},
fail: {
type: Function,
}
},
data(){
return {
dialogFormVisible: true,
form: {
name: ''
},
options: [{
value: '0',
label: '客户原因-订单取消'
}, {
value: '1',
label: '销售原因-卡单删除(价格)'
}, {
value: '2',
label: '销售原因-销售拒发'
}, {
value: '3',
label: '销售原因-超分配'
}, {
value: '4',
label: '销售原因-手工已上传'
}, {
value: '5',
label: '销售原因-订单对接重复'
}, {
value: '6',
label: '销售原因-箱规错误'
}, {
value: '7',
label: '销售原因-停产单品'
}],
}
},
methods: {
cancel(){
this.dialogFormVisible = false;
this.fail && this.fail();
},
confirm(){
let { mainId, delIds, form } = this;
FxUI.userDefine.call_controller('func_u572k__c', [{
type: 'map',
name: 'args',
value: {
mainId, delIds, form
}
}]).then(res => {
// FxUI.alert('上传成功');
this.$alert('删除成功', '提示', {
confirmButtonText: '确定',
type:'success',
callback: action => {
this.dialogFormVisible = false;
this.success && this.success();
}
});
}).catch(res => {
this.$alert('删除失败', '提示', {
confirmButtonText: '确定',
type:'error',
callback: action => {
this.dialogFormVisible = true;
}
});
});
}
}
}
</script>
<style></style>注意事项
1. 此钩子中通过上下文API获取到的从对象数据不包含被删除的数据
在此钩子中使用上下文API获取对象数据时,数据已被删除,因此API无法找到相应的数据。
