upload-file.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. "use strict";
  2. const common_vendor = require("../../../common/vendor.js");
  3. const _sfc_main = {
  4. name: "uploadFile",
  5. emits: ["uploadFiles", "choose", "delFile"],
  6. props: {
  7. filesList: {
  8. type: Array,
  9. default() {
  10. return [];
  11. }
  12. },
  13. delIcon: {
  14. type: Boolean,
  15. default: true
  16. },
  17. limit: {
  18. type: [Number, String],
  19. default: 9
  20. },
  21. showType: {
  22. type: String,
  23. default: ""
  24. },
  25. listStyles: {
  26. type: Object,
  27. default() {
  28. return {
  29. // 是否显示边框
  30. border: true,
  31. // 是否显示分隔线
  32. dividline: true,
  33. // 线条样式
  34. borderStyle: {}
  35. };
  36. }
  37. },
  38. readonly: {
  39. type: Boolean,
  40. default: false
  41. }
  42. },
  43. computed: {
  44. list() {
  45. let files = [];
  46. this.filesList.forEach((v) => {
  47. files.push(v);
  48. });
  49. return files;
  50. },
  51. styles() {
  52. let styles = {
  53. border: true,
  54. dividline: true,
  55. "border-style": {}
  56. };
  57. return Object.assign(styles, this.listStyles);
  58. },
  59. borderStyle() {
  60. let { borderStyle, border } = this.styles;
  61. let obj = {};
  62. if (!border) {
  63. obj.border = "none";
  64. } else {
  65. let width = borderStyle && borderStyle.width || 1;
  66. width = this.value2px(width);
  67. let radius = borderStyle && borderStyle.radius || 5;
  68. radius = this.value2px(radius);
  69. obj = {
  70. "border-width": width,
  71. "border-style": borderStyle && borderStyle.style || "solid",
  72. "border-color": borderStyle && borderStyle.color || "#eee",
  73. "border-radius": radius
  74. };
  75. }
  76. let classles = "";
  77. for (let i in obj) {
  78. classles += `${i}:${obj[i]};`;
  79. }
  80. return classles;
  81. },
  82. borderLineStyle() {
  83. let obj = {};
  84. let { borderStyle } = this.styles;
  85. if (borderStyle && borderStyle.color) {
  86. obj["border-color"] = borderStyle.color;
  87. }
  88. if (borderStyle && borderStyle.width) {
  89. let width = borderStyle && borderStyle.width || 1;
  90. let style = borderStyle && borderStyle.style || 0;
  91. if (typeof width === "number") {
  92. width += "px";
  93. } else {
  94. width = width.indexOf("px") ? width : width + "px";
  95. }
  96. obj["border-width"] = width;
  97. if (typeof style === "number") {
  98. style += "px";
  99. } else {
  100. style = style.indexOf("px") ? style : style + "px";
  101. }
  102. obj["border-top-style"] = style;
  103. }
  104. let classles = "";
  105. for (let i in obj) {
  106. classles += `${i}:${obj[i]};`;
  107. }
  108. return classles;
  109. }
  110. },
  111. methods: {
  112. uploadFiles(item, index) {
  113. this.$emit("uploadFiles", {
  114. item,
  115. index
  116. });
  117. },
  118. choose() {
  119. this.$emit("choose");
  120. },
  121. delFile(index) {
  122. this.$emit("delFile", index);
  123. },
  124. value2px(value) {
  125. if (typeof value === "number") {
  126. value += "px";
  127. } else {
  128. value = value.indexOf("px") !== -1 ? value : value + "px";
  129. }
  130. return value;
  131. }
  132. }
  133. };
  134. function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  135. return common_vendor.e({
  136. a: !$props.readonly
  137. }, !$props.readonly ? {
  138. b: common_vendor.o((...args) => $options.choose && $options.choose(...args))
  139. } : {}, {
  140. c: $options.list.length > 0
  141. }, $options.list.length > 0 ? {
  142. d: common_vendor.f($options.list, (item, index, i0) => {
  143. return common_vendor.e({
  144. a: common_vendor.t(item.name)
  145. }, $props.delIcon && !$props.readonly ? {
  146. b: common_vendor.o(($event) => $options.delFile(index), index)
  147. } : {}, {
  148. c: item.progress && item.progress !== 100 || item.progress === 0
  149. }, item.progress && item.progress !== 100 || item.progress === 0 ? {
  150. d: item.progress === -1 ? 0 : item.progress,
  151. e: item.errMsg ? "#ff5a5f" : "#EBEBEB"
  152. } : {}, {
  153. f: item.status === "error"
  154. }, item.status === "error" ? {
  155. g: common_vendor.o(($event) => $options.uploadFiles(item, index), index)
  156. } : {}, {
  157. h: index,
  158. i: index !== 0 && $options.styles.dividline ? 1 : "",
  159. j: common_vendor.s(index !== 0 && $options.styles.dividline && $options.borderLineStyle)
  160. });
  161. }),
  162. e: $props.delIcon && !$props.readonly,
  163. f: common_vendor.s($options.borderStyle)
  164. } : {});
  165. }
  166. const Component = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__file", "D:/zx/mall-front-app/sheep/components/s-uploader/upload-file.vue"]]);
  167. wx.createComponent(Component);