Form.ShowDialog 和Form.Modal 方法 基础学习

本文深入探讨了Windows窗体的DialogResult属性的作用,包括设置窗体对话框结果、模式对话框的行为以及如何通过DialogResult属性确定对话框的关闭原因。此外,文章还介绍了模式对话框与无模式对话框的区别,以及如何在代码中使用ShowDialog方法显示模式对话框,并通过返回值处理对话框中的操作。

1.DialogResult

获取或设置窗体的对话框结果。

 

窗体的对话框结果是当窗体显示为模式对话框时从该窗体返回的值。

 

如果窗体显示为对话框,用 DialogResult 枚举中的值设置此属性将”设置该窗体的对话框结果值、隐藏模式对话框并将控制返回给调用窗体。”三种功能。

 

此属性通常由窗体上 Button 控件的 DialogResult 属性设置。当用户单击 Button 控件时,分配给 Button 的 DialogResult 属性的值将分配给该窗体的 DialogResult 属性。

当窗体显示为模式对话框时,单击“关闭”按钮(窗体右上角带 X 的按钮)会隐藏窗体并将 DialogResult 属性设置为 DialogResult.Cancel。当用户单击对话框的“关闭”按钮或设置 DialogResult 属性的值时,不会自动调用 Close 方法(也就是说还会再次显示出来。除非手写调用Close方法。)。而是隐藏该窗体并可重新显示该窗体,而不用创建该对话框的新实例。

 

 

因为此行为,所以当应用程序不再需要该窗体时,必须调用该窗体的 Dispose 方法。

可以使用此属性确定对话框是如何关闭的,以便正确处理在该对话框中执行的操作。

注意:

通过在窗体的 Closing 事件的事件处理程序中设置 DialogResult 属性,可以重写用户单击“关闭”按钮时分配给 DialogResult 属性的值。

注意:

如果 Form 显示为无模式窗口,则 DialogResult 属性返回的值可能不返回分配给该窗体的值,因为关闭该窗体时将自动释放该窗体的资源。

 

 

 

  static class Program

    {

        /// <summary>

        /// 应用程序的主入口点。

        /// </summary>

        [STAThread]

        static voidMain()

        {

            DevExpress.XtraEditors.Controls.Localizer.Active = new DevExpress.LocalizationCHS.XtraEditorsLocalizer();

            DevExpress.XtraGrid.Localization.GridLocalizer.Active = new DevExpress.LocalizationCHS.XtraGridLocalizer();

            //DevExpress.XtraLayout.Localization.LayoutLocalizer.Active = new DevExpress.LocalizationCHS.XtraLayoutLocalizer();

 

 

            Application.EnableVisualStyles();

            Application.SetCompatibleTextRenderingDefault(false);

            Form frm = new DLPro.Login();

           

            if (frm.ShowDialog() == DialogResult.OK)

            {

                  Application.Run(new ContainerForm());//这里之所以不再重新显示出LOGIN。是因为在Login中代码写了close方法。

若不写Close方法,LOGIN窗体依然会再次弹出。因为它是模式窗口不是无模式窗口(无模式窗口自动调用DISPOSE()方法。)

            }

        }

 

模态对话框就是对话框不结束,即Domodal就不返回
Domodal   下一句的程序就无法运行,需要输入参数时要用这种方法
而无模式没有这个限制
一般用于工具条等

 

 

模式对话框不返回的话是无法切换到调用窗口的,无模式的可以。
无模式的对话框是新建一个窗口(用CreateWindow函数),而模式对话框则是调用窗口的一个子窗口。

 

 

Modal是什么?就是模式,可以认为对话框有两种“模式”,一种是中止主程序执行,直到对话框返回,这就是“有模式”,另一种不中止主程序执行,就像Word的Find对话框,这就是“无模式”,《VC++6.0技术内幕》专门有两章讲这个

 

打开一个模式对话框后,其他所有对话框都不能用鼠标和键盘操作!非模对话框打开后,它下面的对话框还能操作。仅此而已!应用的时候,如果希望多个对话框能同时操作,就用非模态的,大多情况下是模态的,好控制!

无模式总结:创建时用Create,清除时用DestroyWindow,创建对象时用new,清除对象时用CDialog::PostNcDestroy并执行delete   this语句。非模态对话框的生存周期较长,其对象的生存周期需要存在于父窗口类对象的整个生存周期。因此需要在父窗口类添加指向非模态对话框类对象的指针成员变量。
模式总结:创建时用DoModal,清除时用EndDialog,对象的创建正常,并且利用析构函数清除对象。

 

Form..::.Modal 属性

当有模式地显示窗体时,不能进行任何输入(通过键盘或鼠标单击),对模式窗体上的对象的输入除外。该程序必须隐藏或关闭模式窗体(通常是响应某个用户操作),然后才能对另一窗体进行输入。有模式显示的窗体通常用作应用程序中的对话框。

可以使用此属性确定从某方法或属性获取的窗体是否已经有模式地显示。

若要有模式地显示某窗体,请使用 ShowDialog 方法。

 

 

下面的代码示例使用 Modal 属性来确定窗体是否显示为模式窗体。如果不显示为模式窗体,则将更改 FormBorderStyle 和 TopLevel 属性,以使该窗体成为具有工具窗口边框的非顶级窗体。

 

private void ShowMyNonModalForm()

           {

                 Form myForm = new Form();

                 myForm.Text = "My Form";

                 myForm.SetBounds(10,10,200,200);

 

                 myForm.Show();

                 // Determine if the form is modal.

                 if(myForm.Modal == false)

                 {

                      // Change borderstyle and make it not a top level window.

                       myForm.FormBorderStyle = FormBorderStyle.FixedToolWindow;

                      myForm.TopLevel = false;

                 }

           }

 

Form..::.ShowDialog 方法  返回值就是DialogResult类型的值.

 

将窗体显示为模式对话框。

 

 

名称

说明

 

ShowDialog()()()

将窗体显示为模式对话框,并将当前活动窗口设置为它的所有者。

 

ShowDialog(IWin32Window)

将窗体显示为具有指定所有者的模式对话框。

Form..::.ShowDialog 方法

可以使用此方法在应用程序中显示模式对话框。调用此方法时,直到关闭对话框后,才执行此方法后面的代码。可以将 DialogResult 枚举值之一分配给对话框,方法是将该值分配给窗体上 Button 的 DialogResult 属性或通过使用代码设置窗体的 DialogResult 属性。此方法随后返回该值。可以使用此返回值确定如何处理对话框中发生的操作。例如,如果关闭了对话框,并通过此方法返回了 DialogResult.Cancel 值,则可防止执行在调用 ShowDialog 之后的代码。

当窗体显示为模式对话框时,单击“关闭”按钮(窗体右上角带 X 的按钮)会隐藏窗体并将 DialogResult 属性设置为 DialogResult.Cancel。与无模式窗体不同,当用户单击对话框的关闭窗体按钮或设置 DialogResult 属性的值时,.NET Framework 不调用 Close 方法。窗体转而可以隐藏并可重新显示,而不用创建该对话框的新实例。因为未关闭显示为对话框的窗体,所以在您的应用程序不再需要该窗体时,必须调用该窗体的 Dispose 方法。

ShowDialog 方法的此版本不将窗体或控件指定为其所有者。当调用此版本时,使当前活动窗口成为该对话框的所有者。如果要指定特定所有者,请使用此方法的其他版本。

 

 

下面的代码示例将一个窗体显示为模式对话框并计算该对话框的返回值,然后确定是否读取该对话框窗体上 TextBox 控件的值。此示例要求已创建了一个名为 testDialog 的 Form,并且它包含一个名为 TextBox1 的 TextBox 控件。另外,该示例还要求另一个 Form 包含此示例中的代码并从中调用该代码,以便将 testDialog 显示为模式对话框。该示例使用指定对话框所有者的 ShowDialog 版本。

C# 

复制代码

public void ShowMyDialogBox()

{

   Form2 testDialog = new Form2();

 

   // Show testDialog as a modal dialog and determine if DialogResult = OK.

   if (testDialog.ShowDialog(this) == DialogResult.OK)

   {

      // Read the contents of testDialog's TextBox.

      this.txtResult.Text = testDialog.TextBox1.Text;

   }

   else

   {

      this.txtResult.Text = "Cancelled";

   }

   testDialog.Dispose();

}

 

Form..::.ShowDialog 方法 (IWin32Window)

将窗体显示为具有指定所有者的模式对话框。

C#

public DialogResult ShowDialog(

      IWin32Window owner

)

 

参数

owner

类型:System.Windows.Forms..::.IWin32Window

任何实现 IWin32Window(表示将拥有模式对话框的顶级窗口)的对象。

返回值

类型:System.Windows.Forms..::.DialogResult

DialogResult 值之一。

 

 

 

每个FORM都有自己的一个DialogResult属性。使用this就可以调出。并设置其属性值。然后我们利用模式对话框的返回值。SHOWDIALOG。来对比是否是正确的执行了我们的需要。这样你要关闭这个这个模式对话框时就要注意问题:就是如果你在此模式对话框中的函数中已经设置了其 this.DialogResult= DialogResult .NO;则此窗口就会自动关闭了。

 

DialogResult.None值。代表根本没有进行设置。只是一个状态,并没有任何实际应用意义。

,单独设置DialogResult.None将代表没有任何操作,此窗口继续执行。

 

因为只要是模式的对话框肯定要返回给父级,那么即使是直接调用this.close.其返回的值也是DialogResult.Cancel

 

但是要区分DialogResult.Cancel和this.close.返回的值DialogResult.Cancel。

因为DialogResult.Cancel会使窗口继续运行。而this.close则可以进行销毁.

 

 

 

 

Application..::.EnableVisualStyles 方法

启用应用程序的可视样式。

 

Application..::.SetCompatibleTextRenderingDefault 方法

:在应用程序范围内设置控件显示文本的默认方式(可以设为使用新的GDI+   ,   还是旧的GDI)

<template> <e-layout> <!-- 搜索 --> <template v-slot:search-bar> <el-form :inline="true" :model="searchForm" @keyup.enter.native="search" @submit.native.prevent> <el-form-item> <el-date-picker v-model="searchForm.date" type="datetimerange" :picker-options="$constants.datePickerOptions" :range-separator="$t('Common.searchForm.datePicker.separator')" :start-placeholder="$t('Common.searchForm.datePicker.startTime')" :end-placeholder="$t('Common.searchForm.datePicker.endTime')" value-format="yyyy-MM-dd HH:mm:ss" :default-time="['00:00:00', '23:59:59']" align="right"> </el-date-picker> </el-form-item> <el-form-item> <el-input v-model="searchForm.ani" :placeholder="$t('OutboundCallJob.searchForm.ani')" clearable></el-input> <!-- 主叫号码 --> </el-form-item> <el-form-item> <el-input v-model="searchForm.dnis" :placeholder="$t('OutboundCallJob.searchForm.dnis')" clearable></el-input> <!-- 被叫号码 --> </el-form-item> <el-form-item> <template> <el-select v-model="searchForm.status" :placeholder="$t('OutboundCallJob.searchForm.status')" clearable> <el-option :label="$t('Common.enum.status.enabled')" value="enabled"></el-option> <!-- 启用 --> <el-option :label="$t('Common.enum.status.disabled')" value="disabled"></el-option> <!-- 停用 --> </el-select> </template> </el-form-item> <el-form-item> <el-button type="primary" size="mini" @click="search" :loading="loading" icon="el-icon-search">{{ $t('Common.button.search') }}</el-button> <!-- 搜索 --> </el-form-item> </el-form> </template> <!-- 按钮 --> <template v-slot:btn-bar> <el-row> <el-button type="success" size="mini" @click="toAdd" icon="el-icon-plus" v-has-permission="'monitor:outbound-call-task:addCycle'">{{ $t('Common.button.new') }}</el-button> <!-- 新建 --> </el-row> </template> <!-- 表格 --> <template v-slot:main-content> <el-table :data="tableData" height="100%" highlight-current-row ref="clearTableData"> <template slot="empty"> <el-empty :description="$t('Common.table.emptyDescription')" /> <!-- 暂无数据 --> </template> <el-table-column type="index" :label="$t('Common.table.index')" width="50" fixed="left" align='center'/> <!-- 序号 --> <el-table-column prop="createTime" :label="$t('OutboundCallJob.table.createTime')" min-width="150" align='center'/> <!-- 创建时间 --> <el-table-column prop="userName" :label="$t('OutboundCallJob.table.userName')" min-width="120" align='left'/> <!-- 创建人 --> <el-table-column prop="ani" :label="$t('OutboundCallJob.table.ani')" min-width="150" align='left'/> <!-- 主叫号码 --> <el-table-column prop="dnis" :label="$t('OutboundCallJob.table.dnis')" min-width="150" align='left'/> <!-- 被叫号码 --> <el-table-column prop="status" :label="$t('OutboundCallJob.table.status')" min-width="100" align='center'> <!-- 状态 --> <template v-slot="scope"> <el-tag v-if="scope.row.status === 'disabled'" type="info" effect="plain">{{ $t('Common.enum.status.disabled') }}</el-tag> <!-- 停用 --> <el-tag v-else-if="scope.row.status === 'enabled'" type="success" effect="plain">{{ $t('Common.enum.status.enabled') }}</el-tag> <!-- 启用 --> </template> </el-table-column> <el-table-column prop="text" :label="$t('OutboundCallJob.table.text')" show-overflow-tooltip min-width="300" align='left'/> <!-- 文本内容 --> <el-table-column prop="cron" :label="$t('OutboundCallJob.table.cron')" min-width="100" align='left'/> <!-- cron表达式 --> <el-table-column :label="$t('Common.table.operate')" min-width="200" class-name="small-padding fixed-width" fixed="right" > <!-- 操作 --> <template v-slot="scope"> <span> <el-button type='text' class="row-button" @click.stop="toEdit(scope.row)" v-has-permission="'outbound:cycle:update'"><i class="el-icon-edit"> </i>{{ $t('Common.button.edit') }}</el-button> <!-- 编辑 --> <el-button type="text" class="row-button" @click.stop="toDelete(scope.row)" v-has-permission="'outbound:cycle:delete'"><i class="el-icon-delete"> </i>{{ $t('Common.button.delete') }}</el-button> <!-- 删除 --> <el-button type="text" class="row-button" @click.stop="viewDetail(scope.row)"><i class="el-icon-document"> </i>{{ $t('OutboundCallTask.detailLabel') }}</el-button> <!-- 执行详情 --> </span> </template> </el-table-column> </el-table> </template> <!--分页工具条--> <template v-slot:pagination-bar> <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page.sync="pagination.currentPage" :page-size.sync="pagination.pageSize" :page-sizes="pagination.pageSizes" :total="pagination.total" layout="prev, pager, next, total, sizes, jumper" background > </el-pagination> </template> <!-- 新建弹窗 --> <el-dialog :title="dialogTitle" :visible.sync="isShowDialog" :close-on-click-modal="false" width="600px"> <el-form ref="addForm" label-width="90px" :model="form" :rules="addFormRules" > <!-- 执行周期 --> <el-form-item :label="$t('OutboundCallJob.form.label.scheduleInterval')" prop="scheduleInterval"> <!-- 执行周期 --> <cron-picker :cron="form.cron" @change="onChange" :locale="en" /> </el-form-item> <!-- Cron表达式 --> <el-form-item :label="$t('OutboundCallJob.form.label.cron')" prop="cron" style="margin-top: -15px"> <!-- Cron表达式 --> <el-input v-model="form.cron" disabled></el-input> </el-form-item> <!-- 主叫号码 --> <el-form-item :label="$t('OutboundCallJob.form.label.ani')" prop="ani"> <!-- 主叫号码 --> <el-input v-model="form.ani" :placeholder="$t('OutboundCallJob.form.placeholder.ani')"></el-input> </el-form-item> <!-- 被叫号码 --> <el-form-item :label="$t('OutboundCallJob.form.label.dnis')" prop="dnis"> <!-- 被叫号码 --> <div style="display: flex; justify-content: space-between"> <el-input v-model="form.dnis" :placeholder="$t('OutboundCallJob.form.placeholder.dnis')" style="margin-right: 10px"></el-input> <el-button type="success" icon="el-icon-share" @click.prevent="fillMyMobile">{{ $t('Common.button.copy') }}</el-button> <!-- 我的号码 --> </div> </el-form-item> <!-- 文本内容 --> <el-form-item :label="$t('OutboundCallJob.form.label.text')" prop="text" :autosize="{ minRows: 4, maxRows: 8}"> <el-input type="textarea" v-model="form.text" :placeholder="$t('OutboundCallJob.form.placeholder.text')"></el-input> </el-form-item> <!-- 状态 --> <el-form-item :label="$t('OutboundCallJob.form.label.status')"> <template> <el-radio-group v-model="form.status"> <el-radio label="enabled">{{ $t('Common.enum.status.enabled') }}</el-radio> <!-- 启用 --> <el-radio label="disabled">{{ $t('Common.enum.status.disabled') }}</el-radio> <!-- 停用 --> </el-radio-group> </template> </el-form-item> </el-form> <div slot="footer" class="dialog-footer"> <el-button @click="isShowDialog = false" icon="el-icon-close">{{ $t('Common.dialog.button.cancel') }}</el-button> <!-- 取 消 --> <el-button type="primary" @click="createCallJob" icon="el-icon-check">{{ $t('Common.dialog.button.save') }}</el-button> <!-- 保 存 --> </div> </el-dialog> </e-layout> </template> <script> import CronPicker from 'cron-picker-vue' import expiringStorage from '@/utils/expiringStorage' export default { components: { CronPicker }, data () { return { tableData: [], dialogTitle: '', isShowDialog: false, searchForm: { status: '', result: '', ani: '', dnis: '', date: [] }, form: { scheduleInterval: 'day', // 调度周期 cron: '', // Cron 表达式 ani: '', dnis: '', status: '', text: '' }, // 表单验证 addFormRules: { cron: [ { required: true, message: this.$t('OutboundCallJob.rules.addFormRules.cron.required'), trigger: 'blur' } // 执行周期不能为空 ], dnis: [ { required: true, message: this.$t('OutboundCallJob.rules.addFormRules.dnis.required'), trigger: 'blur' } // 被叫号码不能为空 ], text: [ { required: true, message: this.$t('OutboundCallJob.rules.addFormRules.text.required'), trigger: 'blur' } // 文本内容不能为空 ] }, loading: false, pagination: { currentPage: 1, pageSize: 20, total: 0, pageSizes: [20, 40, 60, 80, 100, 200, 500] } } }, computed: { cronLocale () { return { everyText: this.$t('CronPicker.every'), minutesText: this.$t('CronPicker.minutes'), hoursText: this.$t('CronPicker.hours'), daysText: this.$t('CronPicker.days'), weeksText: this.$t('CronPicker.weeks'), monthsText: this.$t('CronPicker.months'), yearsText: this.$t('CronPicker.years'), specificWeekdayText: this.$t('CronPicker.specificWeekday'), specificDateText: this.$t('CronPicker.specificDate'), specificTimeText: this.$t('CronPicker.specificTime'), specificMinuteText: this.$t('CronPicker.specificMinute'), specificHourText: this.$t('CronPicker.specificHour'), specificDayText: this.$t('CronPicker.specificDay'), specificMonthText: this.$t('CronPicker.specificMonth'), specificYearText: this.$t('CronPicker.specificYear'), atText: this.$t('CronPicker.at'), andText: this.$t('CronPicker.and'), onText: this.$t('CronPicker.on'), ofText: this.$t('CronPicker.of'), theText: this.$t('CronPicker.the'), lastText: this.$t('CronPicker.last'), firstText: this.$t('CronPicker.first'), secondText: this.$t('CronPicker.second'), thirdText: this.$t('CronPicker.third'), fourthText: this.$t('CronPicker.fourth'), fifthText: this.$t('CronPicker.fifth'), sixthText: this.$t('CronPicker.sixth'), seventhText: this.$t('CronPicker.seventh'), eighthText: this.$t('CronPicker.eighth'), ninthText: this.$t('CronPicker.ninth'), tenthText: this.$t('CronPicker.tenth'), eleventhText: this.$t('CronPicker.eleventh'), twelfthText: this.$t('CronPicker.twelfth'), thirteenthText: this.$t('CronPicker.thirteenth'), fourteenthText: this.$t('CronPicker.fourteenth'), fifteenthText: this.$t('CronPicker.fifteenth'), sixteenthText: this.$t('CronPicker.sixteenth'), seventeenthText: this.$t('CronPicker.seventeenth'), eighteenthText: this.$t('CronPicker.eighteenth'), nineteenthText: this.$t('CronPicker.nineteenth'), twentiethText: this.$t('CronPicker.twentieth'), twentyFirstText: this.$t('CronPicker.twentyFirst'), twentySecondText: this.$t('CronPicker.twentySecond'), twentyThirdText: this.$t('CronPicker.twentyThird'), twentyFourthText: this.$t('CronPicker.twentyFourth'), twentyFifthText: this.$t('CronPicker.twentyFifth'), twentySixthText: this.$t('CronPicker.twentySixth'), twentySeventhText: this.$t('CronPicker.twentySeventh'), twentyEighthText: this.$t('CronPicker.twentyEighth'), twentyNinthText: this.$t('CronPicker.twentyNinth'), thirtiethText: this.$t('CronPicker.thirtieth'), thirtyFirstText: this.$t('CronPicker.thirtyFirst'), sundayText: this.$t('CronPicker.sunday'), mondayText: this.$t('CronPicker.monday'), tuesdayText: this.$t('CronPicker.tuesday'), wednesdayText: this.$t('CronPicker.wednesday'), thursdayText: this.$t('CronPicker.thursday'), fridayText: this.$t('CronPicker.friday'), saturdayText: this.$t('CronPicker.saturday') } } }, created () { this.search() }, methods: { toAdd () { this.reset() this.dialogTitle = this.$t('OutboundCallJob.dialog.title.new') // 新建 this.isShowDialog = true }, toEdit (row) { this.reset() this.dialogTitle = this.$t('OutboundCallJob.dialog.title.edit') // 编辑 this.isShowDialog = true Object.assign(this.form, row) this.form.id = row.id }, // 创建确认 createCallJob () { let fromData = new FormData() fromData.append('ani', this.form.ani) fromData.append('dnis', this.form.dnis) fromData.append('cron', this.form.cron) fromData.append('status', this.form.status) fromData.append('scheduleInterval', this.form.scheduleInterval) fromData.append('text', this.form.text) this.$refs['addForm'].validate(valid => { // 判断输入校验是否成功 if (!valid) { return } // 新建 if (!this.form.id) { this.$http.post(this.$apiUrl('callJobCreate'), fromData, { headers: { 'Content-Type': 'application/json' } } ).then(response => { this.$message.success(this.$t('OutboundCallJob.message.createSuccess')) // 创建成功 this.isShowDialog = false this.search() }) // 编辑 } else { fromData.append('id', this.form.id) this.$http.put(this.$apiUrl('callJobUpdate'), fromData, { headers: { 'Content-Type': 'application/json' } } ).then(response => { this.$message.success(this.$t('OutboundCallJob.message.updateSuccess')) // 修改成功 this.isShowDialog = false this.search() }).catch((error) => { console.dir(error) this.$message.error(error.message) }) } }) }, // 删除 toDelete (row) { this.$confirm( this.$t('OutboundCallJob.confirm.delete'), // 此操作将删除该任务,是否继续? this.$t('OutboundCallJob.confirm.title'), // 提示 { confirmButtonText: this.$t('OutboundCallJob.confirm.confirmButtonText'), // 确定 cancelButtonText: this.$t('OutboundCallJob.confirm.cancelButtonText'), // 取消 type: 'warning' }).then(() => { this.delete(row.id) }) }, delete (id) { this.$http.delete(this.$apiUrl('callJobDelete', [id])) .then(response => { this.$message.success(this.$t('OutboundCallJob.message.deleteSuccess')) // 删除成功! this.search() }) .catch((error) => { if (error.response) { this.$message.error(`${this.$t('OutboundCallJob.message.deleteFail')}: ${error.response.data.message}`) // 删除失败! ${error.response.data.message} } else { this.$message.error(`${this.$t('OutboundCallJob.message.deleteFail')}: ${error.message}`) // 删除失败! ${error.message} } }) }, // 列表搜索 search () { let startTime = '' let endTime = '' if (this.searchForm.date && this.searchForm.date.length > 0) { startTime = this.searchForm.date[0] endTime = this.searchForm.date[1] } let form = { startTime: startTime, endTime: endTime, page: this.pagination.currentPage, size: this.pagination.pageSize, ...this.searchForm } let url = this.$apiUrl('callJobSearch') + '?' + this.$qs.stringify(form) this.$http.get(url).then(response => { this.tableData = response.data.data.records this.pagination.total = response.data.data.total }).catch((error) => { this.$message.error(error.message) }) }, // 重置表单 reset () { this.form = { scheduleInterval: 'day', // 调度周期 cron: '', // Cron 表达式 ani: '', dnis: '', status: 'enabled', text: '' } this.$nextTick(() => { this.$refs['addForm'].clearValidate() }) }, fillMyMobile () { let user = expiringStorage.get('user') console.log(user) if (user.mobile) { this.form.dnis = user.mobile } }, viewDetail (callJob) { this.$emit('navigateToDetail', callJob.id) }, // change 事件会返回新的 interval cron onChange (cron) { console.log(cron) this.form.cron = cron }, handleSizeChange (val) { this.pagination.pageSize = val this.search() }, handleCurrentChange (val) { this.pagination.currentPage = val this.search() } } } </script> <style scoped lang="scss"> ::v-deep .cron-picker .el-select { margin-bottom: 15px; } </style>
08-27
<template> <el-dialog id="split_dialog" draggable width="750px" :title="$t('HDP.MDA.BatchTrial')" :before-close="isShowDialog" :visible="dialogSplitVisible" :close-on-click-modal="false" > <p> <span>{{ $t('HDP.MDA.IMM.TriggerSuppliers.Info') }}</span> <br /> <span>{{ $t('HDP.MDA.TrialBatches.DOCS.Info') }}</span> </p> <el-form ref="form" :model="form" tip-placement="top-end" label-position="right" label-width="160px"> <el-form-item ref="numberProp" :label="$t('HDP.PUB.IMMCount')" style="width: 710px" prop="numberProp" :rules="[]"> <el-input :model-value="quantity" :placeholder="$t('HDP.PUB.Tips.PlsEnterContent')" style="width: 480px" readonly disabled /> <el-tooltip :content="$t('HDP.MDA.AddSplit')" placement="bottom" :visible-arrow="false"> <el-button icon="ipd-font-icon icon-plus" @click="add" /> </el-tooltip> </el-form-item> <el-form-item v-for="(domain, index) in form.domains" :key="index" :ref="`splitItem${index}`" :label="index === 0 ? $t('HDP.MDA.ADDSplitNum') : ''" style="width: 710px" :prop="`domains.${index}.value`" :rules="[{ validator: validateFn, trigger: 'blur' }]" > <el-input v-model.number="domain.value" style="width: 480px" :placeholder="$t('HDP.PUB.input.positive.interger')" autocomplete="off" /> <el-button v-if="index !== 0" icon="ipd-font-icon icon-del" @click="del(index)" /> </el-form-item> <el-form-item> <el-button type="primary" @click="isShowDialog('submit')">{{ $t('HDPMda.Text.Confirm') }}</el-button> <el-button style="margin-left: 8px; color: #1890ff" @click="isShowDialog">{{ $t('HDPMda.Text.Cancel') }}</el-button> </el-form-item> </el-form> </el-dialog> </template> <script> export default { emits: ['splitQuantity', 'getChildDomains', 'clearTrialFiles'], data() { return { form: { domains: [ { value: '', }, { value: '', }, ], }, errNotice: '', splitArr: [], lastIndex: '', }; }, props: { dialogSplitVisible: { type: Boolean, default: false, }, quantity: { type: String, default: '', }, }, methods: { add() { this.form.domains.unshift({ value: '' }); }, del(index) { if (this.form.domains.length > 1) { this.form.domains.splice(index, 1); } }, validate() { let flag = false; this.$refs.form.validate(valid => { flag = valid; }); return flag; }, // 输入框校验 validateFn(rule, value, callback) { if (Number(value) === 0) { callback(new Error('拆分数量需要填写正整数')); } if (value) { const reg = /^[1-9]\d*$/g; if (!reg.test(value)) { callback(new Error('拆分数量需要填写正整数')); } else { callback(); } } else { callback(); } }, isShowDialog(status = null) { if (status === 'submit') { this.splitArr = []; let splitSum = 0; this.form.domains.forEach(item => { if (item.value !== '') { if (item.value > 0) { splitSum += Number(item.value); this.splitArr.push(Number(item.value)); } } }); this.$refs.numberProp.rules.length = 0; if (splitSum == this.quantity) { this.$emit('splitQuantity', this.splitArr, !this.validate()); this.$emit('getChildDomains', this.form.domains); this.$emit('clearTrialFiles'); } else if (splitSum !== this.quantity) { if (splitSum) { this.$refs.numberProp.rules.push({ validator: (rule, value, callback) => { callback(new Error('拆分后的试制数量之须等于IMM申请数量')); }, trigger: 'blur', }); } this.validate(); } } else { this.$refs.form.resetFields(); this.$emit('splitQuantity', [], false); } }, }, }; </script> 上边的代码在执行时会遇到isShowDialog时,显示 this.form.domains为null导致报错,帮我分析一下原因
最新发布
09-16
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值