index.vue 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. save(search = null, type = 'form') {
  34. this.searchs.update(search, undefined, type)
  35. },
  36. validate(FC) {
  37. this.$refs.form.validate(valid => {
  38. FC(valid)
  39. if (valid) {
  40. this.searchs.update(this.model, undefined, 'form')
  41. }
  42. })
  43. },
  44. resetFields() {
  45. this.searchs.update(this.model, undefined, 'form')
  46. this.searchs.update({}, undefined, 'page')
  47. this.$refs.form.resetFields()
  48. }
  49. },
  50. }
  51. </script>
  52. <style lang="less" scoped>
  53. .save-form{
  54. }
  55. </style>