

<script>
/* eslint-disable */
// sd-skip-auto-import
import{Message}from"ant-design-vue";import components from"./_import-components/sd-button-config-import";var _render=function e(){var t=this,n=t._self._c;return n("span",[n("a-button",{on:{click:t.open}},[t._v(t._s(t.label))]),n("sd-table-modal",t._g({ref:"tableModal",attrs:{"data-source":t.value,columns:t.columns,title:t.label},on:{add:t.add,rowClick:t.edit}},t.$listeners)),n("a-modal",{attrs:{"destroy-on-close":"",title:t.label,width:800,"ok-text":"保存","cancel-text":"退出"},on:{ok:t.save,cancel:()=>t.visible=false},model:{value:t.visible,callback:function(e){t.visible=e},expression:"visible"}},[n("SdForm",{ref:"form",attrs:{"init-values":t.initValues},scopedSlots:t._u([{key:"default",fn:function({model:e}){return[n("table",{staticClass:"sd-form-table"},t._l(t.initValues,(function(a){return n("tr",{directives:[{name:"show",rawName:"v-show",value:!a.sdHidden,expression:"!field.sdHidden"}],key:a.name},[n("sd-form-item-td",{attrs:{name:a.name},on:{change:e=>t.valueChange(e,a.name)}},["triggerEvent"===a.name?n("a-select",{attrs:{options:t.eventOptions},model:{value:e[a.name],callback:function(n){t.$set(e,a.name,n)},expression:"model[field.name]"}}):t._e()],1)],1)})),0)]}}])})],1)],1)};var staticRenderFns=[];_render._withStripped=true;export default{name:"SdButtonConfig",components:{...components,SdForm:()=>import("@/common/components/sd-form.vue")},model:{prop:"value",event:"change"},props:{value:{type:Array,default:()=>[]},component:{type:Object,default:()=>{}}},data(){return{label:"按钮设置",columns:[{title:"按钮名称",dataIndex:"buttonName",sdClickable:true},{title:"按钮编码",dataIndex:"buttonId",width:"180px"},{title:"按钮说明",dataIndex:"buttonDesc"}],editIndex:void 0,visible:false,initValues:[{name:"buttonName",caption:"按钮名称",dataType:"string",required:true},{name:"buttonId",caption:"按钮编码",dataType:"string",required:true,attr:{regex:/^[a-zA-Z][A-Za-z0-9]*$/,regexMessage:"请以字母开头，输入字母或数字"}},{name:"buttonDesc",caption:"按钮说明",dataType:"string"},{name:"buttonType",caption:"按钮类型",dataType:"selectlist",attr:{defaultValue:"batch",selectListItem:[{label:"一般",value:""},{label:"批量",value:"batch"}]}},{name:"triggerEvent",caption:"触发事件",dataType:"string",required:true}],btnType:""}},computed:{eventType(){return"batch"===this.btnType?"multiple":"none"},eventOptions(){return this.component?.attrFD?.formItemProps?.inputProps?.events?.filter((e=>e.associateData===this.eventType)).map((e=>({value:e.id,label:e.eventName})))||[]}},methods:{open(){this.$refs.tableModal.show()},add(){this.editIndex=void 0;this.buttonFormOpen()},edit(e,{rowIndex:t}){this.editIndex=t;this.buttonFormOpen(this.value[t])},buttonFormOpen(e){if(e)this.initValues.forEach((t=>t.value=e[t.name]));else this.initValues.forEach((e=>delete e.value));this.btnType=e?.buttonType??this.initValues.find((e=>"buttonType"===e.name)).attr.defaultValue;this.visible=true},save(){const e=this.$refs.form;e.validateFields().then((t=>{if(t){const t={};e.getBackendValues().forEach((e=>{t[e.name]=e.value}));const n=this.value?.findIndex((e=>e.buttonId===t.buttonId))??-1;if(n>-1&&n!==this.editIndex){Message.error("按钮编码重复");return}const a=this.value||[];if(!isNaN(this.editIndex))a[this.editIndex]=t;else a.push(t);this.$emit("change",[...a]);this.visible=false}}))},valueChange(e,t){if("buttonType"===t){this.btnType=e.target.value;this.$refs.form.setFieldValue("triggerEvent",void 0)}}},render:_render,staticRenderFns:staticRenderFns};</script>

<style module lang="scss">
@use '@/common/design' as *;
</style>
