dialogComponent.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. <template>
  2. <el-dialog
  3. :title="dialogTitle"
  4. v-model="dialogVisible"
  5. width="640px"
  6. @close="closeDialog()"
  7. @open="open"
  8. >
  9. <el-form
  10. ref="formInfo"
  11. :model="form"
  12. class="demo-form-inline"
  13. label-width="100px"
  14. :rules="rules"
  15. >
  16. <el-form-item label="账号:" prop="accountNumber">
  17. <el-input v-model="form.accountNumber"></el-input>
  18. </el-form-item>
  19. <el-form-item label="用户名:" prop="userName">
  20. <el-input v-model="form.userName"></el-input>
  21. </el-form-item>
  22. <el-form-item label="手机号码:" prop="phone">
  23. <el-input v-model="form.phone"></el-input>
  24. </el-form-item>
  25. <el-form-item label="告警短信" prop="phone">
  26. <el-checkbox v-model="checked1" label="接收"></el-checkbox>
  27. </el-form-item>
  28. <br />
  29. <br />
  30. <br />
  31. <div style="text-align: right">
  32. <el-button @click="closeDialog(0)">取消</el-button>
  33. <el-button type="primary" @click="submitForm('formInfo')"
  34. >确定</el-button
  35. >
  36. </div>
  37. </el-form>
  38. </el-dialog>
  39. </template>
  40. <script>
  41. import { defineComponent, ref, watchEffect } from 'vue'
  42. export default defineComponent({
  43. name: 'DialogComponent',
  44. emits: ['closeDialog'],
  45. props: {
  46. flag: Boolean,
  47. dialogTitle: String,
  48. itemInfo: Object,
  49. },
  50. setup(props, context) {
  51. context
  52. const dialogVisible = ref(false)
  53. const formInfo = ref(null)
  54. const form = ref([])
  55. // open(): Dialog弹窗打开之前做的事
  56. const open = () => {
  57. form.value = props.itemInfo.value
  58. console.log('form.value')
  59. console.log( form.value)
  60. }
  61. const options = [
  62. {
  63. value: '选项1',
  64. label: '站点一',
  65. },
  66. {
  67. value: '选项2',
  68. label: '站点二',
  69. },
  70. {
  71. value: '选项3',
  72. label: '站点三',
  73. },
  74. {
  75. value: '选项4',
  76. label: '站点四',
  77. },
  78. {
  79. value: '选项5',
  80. label: '站点五',
  81. },
  82. ]
  83. // 关闭弹框
  84. const closeDialog = () => {
  85. context.emit('closeDialog', false)
  86. dialogVisible.value = false
  87. }
  88. watchEffect((fn, options) => {
  89. fn, options
  90. dialogVisible.value = props.flag
  91. })
  92. const roleValid = (rule, value, callback) => {
  93. rule
  94. if (value.length === 0) {
  95. callback(new Error('角色不能为空'))
  96. } else {
  97. callback()
  98. }
  99. }
  100. // 保存-修改操作
  101. const submitForm = () => {
  102. console.log(formInfo)
  103. formInfo.value.validate((valid) => {
  104. if (valid) {
  105. // 走保存请求
  106. this.$message({
  107. message: '操作成功!',
  108. type: 'success',
  109. })
  110. this.closeDialog(1)
  111. } else {
  112. console.log('error submit!!')
  113. return false
  114. }
  115. })
  116. }
  117. return {
  118. closeDialog,
  119. dialogVisible,
  120. options,
  121. roleValid,
  122. formInfo,
  123. form,
  124. open,
  125. submitForm,
  126. rules: {
  127. accountNumber: [
  128. // required 是否为必填项, trigger:表单验证的触发时机,失去焦点进行验证
  129. { required: true, message: "请输入账号", trigger: "blur" },
  130. {
  131. min: 3,
  132. max: 6,
  133. message: "用户名长度在 3 到 6 个字符",
  134. trigger: "blur",
  135. },
  136. ],
  137. userName: [
  138. { required: true, message: "请输入用户名", trigger: "blur" },
  139. {
  140. min: 3,
  141. max: 6,
  142. message: "用户名长度在 3 到 6 个字符",
  143. trigger: "blur",
  144. },
  145. ],
  146. phone: [
  147. { required: false, message: "请输入编号", trigger: "blur" },
  148. {
  149. min: 3,
  150. max: 6,
  151. message: "用户名长度在 3 到 6 个字符",
  152. trigger: "blur",
  153. },
  154. ],
  155. },
  156. }
  157. },
  158. })
  159. </script>
  160. <style scoped lang="scss">
  161. .el-input,
  162. .el-select {
  163. width: 240px;
  164. }
  165. </style>