fa-upload-image.vue 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <template>
  2. <view>
  3. <u-upload
  4. :action="vuex_config.config.upload.uploadurl"
  5. :file-list="fileList"
  6. :header="header"
  7. :form-data="formdata"
  8. @on-uploaded="successUpload"
  9. @on-error="errorUpload"
  10. @on-remove="remove"
  11. :max-count="imgType=='single'?1:99"
  12. width="150"
  13. height="150"
  14. ></u-upload>
  15. </view>
  16. </template>
  17. <script>
  18. import Emitter from '@/uview-ui/libs/util/emitter.js';
  19. export default {
  20. name: 'fa-upload-image',
  21. mixins: [Emitter],
  22. props: {
  23. value:{
  24. type:String,
  25. default:''
  26. },
  27. imgType: {
  28. type: String,
  29. default: 'single'
  30. },
  31. fileList:{
  32. type:Array,
  33. default(){
  34. return []
  35. }
  36. }
  37. },
  38. created() {
  39. this.header = {
  40. token: this.vuex_token || '',
  41. uid: this.vuex_user.id || 0
  42. };
  43. let isObj = this.$u.test.object(this.vuex_config.config.upload.multipart);
  44. if (isObj) {
  45. this.formdata = this.vuex_config.config.upload.multipart;
  46. }
  47. },
  48. data() {
  49. return {
  50. header: {},
  51. formdata: {},
  52. };
  53. },
  54. methods: {
  55. successUpload(e) {
  56. console.log(e)
  57. this.changes(e)
  58. },
  59. remove(index, lists, name){
  60. this.changes(lists)
  61. },
  62. changes(e){
  63. console.log(e)
  64. let urls = [];
  65. e.map(item => {
  66. //编辑时,已存在的,response不存在
  67. if(!item.response){
  68. urls.push(item.url)
  69. }else if (item.response.code) {
  70. urls.push(item.response.data.url);
  71. }
  72. });
  73. let value = urls.join(',');
  74. this.$emit('input', value);
  75. setTimeout(() => {
  76. this.dispatch('u-form-item', 'on-form-blur', value);
  77. }, 50);
  78. },
  79. errorUpload(e) {
  80. this.$u.toast('上传失败了!');
  81. }
  82. }
  83. };
  84. </script>
  85. <style lang="scss"></style>