当前位置:   article > 正文

【实用模板】Vue代码文件常用弹窗页面组件

【实用模板】Vue代码文件常用弹窗页面组件
  1. <template>
  2. <div :class="$options.name" v-if="dialogVisible">
  3. <el-dialog
  4. :custom-class="`弹窗页面组件-el-dialog`"
  5. :append-to-body="true"
  6. :close-on-click-modal="true"
  7. :close-on-press-escape="true"
  8. :destroy-on-close="true"
  9. :fullscreen="false"
  10. :show-close="true"
  11. :title="`弹窗标题`"
  12. :width="`600px`"
  13. :visible.sync="dialogVisible"
  14. style="animation: none"
  15. >
  16. <div style="margin: -20px 0">
  17. <!-- 这里添加弹窗内容 -->
  18. <div class="form-body" @keyup.ctrl.enter="save">
  19. <el-form
  20. @submit.native.prevent
  21. :disabled="disabledForm"
  22. label-position="right"
  23. size=""
  24. >
  25. <el-form-item :label="`名称`" label-width="80px" required>
  26. <el-input
  27. v-model.trim="form.MC"
  28. ref="MC"
  29. @focus="$refs.MC.select()"
  30. :placeholder="`输入名称`"
  31. :maxlength="20"
  32. clearable
  33. show-word-limit
  34. />
  35. </el-form-item>
  36. <el-form-item :label="`备注`" label-width="80px">
  37. <el-input
  38. type="textarea"
  39. v-model="form.BZ"
  40. ref="BZ"
  41. @focus="$refs.BZ.select()"
  42. :placeholder="`请输入内容`"
  43. :maxlength="200"
  44. :rows="3"
  45. show-word-limit
  46. />
  47. </el-form-item>
  48. </el-form>
  49. </div>
  50. </div>
  51. <div slot="footer">
  52. <el-button type="info" @click="cancel" plain>取消</el-button>
  53. <el-button type="primary" @click="save" v-if="!disabledForm">确定</el-button>
  54. </div>
  55. </el-dialog>
  56. </div>
  57. </template>
  58. <script>
  59. export default {
  60. name: "弹窗页面组件",
  61. components: {},
  62. data() {
  63. return {
  64. loading: false, //加载状态
  65. elementLoadingText: ``, //加载提示文字
  66. dialogVisible: false,
  67. form: {}, //表单信息
  68. disabledForm: false,
  69. };
  70. },
  71. props: [
  72. "value", //是否显示
  73. "disabled", //是否禁用
  74. "data",
  75. "readonly",
  76. ],
  77. computed: {},
  78. watch: {
  79. value: {
  80. handler(d) {
  81. this.dialogVisible = d;
  82. },
  83. deep: true,
  84. immediate: true,
  85. },
  86. dialogVisible(d) {
  87. this.$emit("input", d);
  88. }, //是否显示(双向绑定)
  89. readonly: {
  90. handler(d) {
  91. this.disabledForm = d;
  92. },
  93. deep: true,
  94. immediate: true,
  95. },
  96. data: {
  97. handler(newValue, oldValue) {
  98. //console.log('深度监听:', newValue, oldValue);
  99. if (newValue && Object.keys(newValue).length) {
  100. this.form = JSON.parse(JSON.stringify(newValue));
  101. } else {
  102. this.form = {
  103. // 字段名: 默认值, //默认字段、属性值
  104. };
  105. }
  106. },
  107. deep: true, //深度监听
  108. immediate: true, //立即执行
  109. },
  110. },
  111. created() {},
  112. mounted() {},
  113. destroyed() {},
  114. methods: {
  115. valid(d) {
  116. if (!this.form.MC)
  117. return this.$message.error(this.$refs.MC.$el.querySelector("input").placeholder);
  118. },
  119. save() {
  120. if (this.valid()) return;
  121. if (this.form.ID) {
  122. // 修改
  123. } else {
  124. // 新增
  125. }
  126. let data = {
  127. ...this.form,
  128. sgLog: `前端请求来源:${this.$options.name}保存数据接口`,
  129. };
  130. this.$d.保存数据接口({
  131. data,
  132. r: {
  133. l: { show: () => (this.loading = true), close: () => (this.loading = false) },
  134. s: (d) => {
  135. this.initList({ keyword: "" });
  136. this.$emit(`save`, this.form);
  137. this.cancel(this.form);
  138. },
  139. },
  140. });
  141. },
  142. cancel(d) {
  143. this.dialogVisible = false;
  144. this.$emit(`hide`, d);
  145. },
  146. },
  147. };
  148. </script>
  149. <style lang="scss" scoped>
  150. .弹窗页面组件 {
  151. }
  152. </style>
  153. <style lang="scss">
  154. .弹窗页面组件-el-dialog {
  155. }
  156. </style>

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Gausst松鼠会/article/detail/274378
推荐阅读
相关标签
  

闽ICP备14008679号