index.vue 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <template>
  2. <el-form
  3. class="save-form"
  4. v-bind="{...$attrs, ...$props}"
  5. v-on="$listeners"
  6. ref="form"
  7. >
  8. <slot/>
  9. </el-form>
  10. </template>
  11. <script>
  12. import { Searchs } from '@/helpers'
  13. export default {
  14. name: 'save-form',
  15. props: ['model'],
  16. data() {
  17. return {
  18. searchs: null
  19. }
  20. },
  21. mounted() {
  22. const searchs = new Searchs(this.$route.fullPath)
  23. this.searchs = searchs
  24. const active = searchs.get()
  25. for (const key in active.form) {
  26. if (active.form.hasOwnProperty(key)) {
  27. const item = active.form[key]
  28. this.model[key] = item
  29. }
  30. }
  31. },
  32. methods: {
  33. validate(FC) {
  34. this.$refs.form.validate(valid => {
  35. FC(valid)
  36. if (valid) {
  37. this.searchs.update(this.model, undefined, 'form')
  38. }
  39. })
  40. },
  41. resetFields() {
  42. this.searchs.update(this.model, undefined, 'form')
  43. this.searchs.update({}, undefined, 'page')
  44. this.$refs.form.resetFields()
  45. }
  46. },
  47. }
  48. </script>
  49. <style lang="less" scoped>
  50. .save-form{
  51. }
  52. </style>