index.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import { __assign } from "tslib";
  2. import { Component, triggerEvent, getValueFromProps } from '../../_util/simply';
  3. import { resolveEventValue } from '../../_util/platform';
  4. import { FormImageUploadDefaultProps } from './props';
  5. import { createForm } from '../form';
  6. Component(FormImageUploadDefaultProps, {
  7. handleRef: function (imageUpload) {
  8. this.imageUpload = imageUpload;
  9. },
  10. onChange: function (value) {
  11. this.emit('onChange', resolveEventValue(value));
  12. triggerEvent(this, 'change', resolveEventValue(value));
  13. },
  14. onPreview: function (file) {
  15. triggerEvent(this, 'preview', resolveEventValue(file));
  16. },
  17. onChooseImageError: function (err) {
  18. triggerEvent(this, 'chooseImageError', resolveEventValue(err));
  19. },
  20. handleUpload: function (localFile) {
  21. var onUpload = getValueFromProps(this, 'onUpload');
  22. if (!onUpload) {
  23. throw new Error('need props onUpload');
  24. }
  25. return onUpload(localFile);
  26. },
  27. handleRemove: function (file) {
  28. var onRemove = getValueFromProps(this, 'onRemove');
  29. if (onRemove) {
  30. return onRemove(file);
  31. }
  32. },
  33. handleBeforeUpload: function (localFileList) {
  34. var onBeforeUpload = getValueFromProps(this, 'onBeforeUpload');
  35. if (onBeforeUpload) {
  36. return onBeforeUpload(localFileList);
  37. }
  38. },
  39. }, {}, [
  40. createForm({
  41. methods: {
  42. setFormData: function (values) {
  43. this.setData(__assign(__assign({}, this.data), { formData: __assign(__assign({}, this.data.formData), values) }));
  44. this.imageUpload && this.imageUpload.update(this.data.formData.value);
  45. },
  46. },
  47. }),
  48. ], {});