upload-image.js 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. "use strict";
  2. const common_vendor = require("../../../common/vendor.js");
  3. const sheep_index = require("../../index.js");
  4. require("../../api/index.js");
  5. require("../../api/distri/score.js");
  6. require("../../request/index.js");
  7. require("../../config/index.js");
  8. require("../../store/index.js");
  9. require("../../store/app.js");
  10. require("../../api/promotion/diy.js");
  11. require("../../platform/index.js");
  12. require("../../platform/provider/wechat/index.js");
  13. require("../../platform/provider/wechat/miniProgram.js");
  14. require("../../api/member/auth.js");
  15. require("../../api/member/social.js");
  16. require("../../api/member/user.js");
  17. require("../../platform/provider/apple/index.js");
  18. require("../../platform/share.js");
  19. require("../../router/index.js");
  20. require("../../hooks/useModal.js");
  21. require("../../helper/index.js");
  22. require("../../helper/test.js");
  23. require("../../helper/digit.js");
  24. require("../../api/member/signin.js");
  25. require("../../helper/throttle.js");
  26. require("../../url/index.js");
  27. require("../../platform/pay.js");
  28. require("../../api/pay/order.js");
  29. require("../../store/user.js");
  30. require("../../store/cart.js");
  31. require("../../api/trade/cart.js");
  32. require("../../api/pay/wallet.js");
  33. require("../../api/trade/order.js");
  34. require("../../api/promotion/coupon.js");
  35. require("../../store/sys.js");
  36. require("../../store/modal.js");
  37. require("../../api/distri/share.js");
  38. require("../../api/distri/team.js");
  39. require("../../api/infra/file.js");
  40. require("../../api/member/address.js");
  41. require("../../api/member/point.js");
  42. require("../../api/migration/app.js");
  43. require("../../api/migration/chat.js");
  44. require("../../api/migration/index.js");
  45. require("../../api/migration/third.js");
  46. require("../../api/pay/channel.js");
  47. require("../../api/product/category.js");
  48. require("../../api/product/comment.js");
  49. require("../../api/product/favorite.js");
  50. require("../../api/product/history.js");
  51. require("../../api/product/spu.js");
  52. require("../../api/promotion/activity.js");
  53. require("../../api/promotion/article.js");
  54. require("../../api/promotion/bargain.js");
  55. require("../../api/promotion/combination.js");
  56. require("../../api/promotion/rewardActivity.js");
  57. require("../../api/promotion/seckill.js");
  58. require("../../api/system/area.js");
  59. require("../../api/system/voice.js");
  60. require("../../api/trade/afterSale.js");
  61. require("../../api/trade/brokerage.js");
  62. require("../../api/trade/config.js");
  63. require("../../api/trade/delivery.js");
  64. require("../../config/zIndex.js");
  65. const _sfc_main = {
  66. name: "uploadImage",
  67. emits: ["uploadFiles", "choose", "delFile"],
  68. props: {
  69. filesList: {
  70. type: [Array, String],
  71. default() {
  72. return [];
  73. }
  74. },
  75. disabled: {
  76. type: Boolean,
  77. default: false
  78. },
  79. disablePreview: {
  80. type: Boolean,
  81. default: false
  82. },
  83. limit: {
  84. type: [Number, String],
  85. default: 9
  86. },
  87. imageStyles: {
  88. type: Object,
  89. default() {
  90. return {
  91. width: "auto",
  92. height: "auto",
  93. border: {}
  94. };
  95. }
  96. },
  97. delIcon: {
  98. type: Boolean,
  99. default: true
  100. },
  101. readonly: {
  102. type: Boolean,
  103. default: false
  104. }
  105. },
  106. computed: {
  107. list() {
  108. if (typeof this.filesList === "string") {
  109. if (this.filesList) {
  110. return [this.filesList];
  111. } else {
  112. return [];
  113. }
  114. }
  115. return this.filesList;
  116. },
  117. styles() {
  118. let styles = {
  119. width: "auto",
  120. height: "auto",
  121. border: {}
  122. };
  123. return Object.assign(styles, this.imageStyles);
  124. },
  125. boxStyle() {
  126. const { width = "auto", height = "auto" } = this.styles;
  127. let obj = {};
  128. if (height === "auto") {
  129. if (width !== "auto") {
  130. obj.height = this.value2px(width);
  131. obj["padding-top"] = 0;
  132. } else {
  133. obj.height = 0;
  134. }
  135. } else {
  136. obj.height = this.value2px(height);
  137. obj["padding-top"] = 0;
  138. }
  139. if (width === "auto") {
  140. if (height !== "auto") {
  141. obj.width = this.value2px(height);
  142. } else {
  143. obj.width = "33.3%";
  144. }
  145. } else {
  146. obj.width = this.value2px(width);
  147. }
  148. let classles = "";
  149. for (let i in obj) {
  150. classles += `${i}:${obj[i]};`;
  151. }
  152. return classles;
  153. },
  154. borderStyle() {
  155. let { border } = this.styles;
  156. let obj = {};
  157. const widthDefaultValue = 1;
  158. const radiusDefaultValue = 3;
  159. if (typeof border === "boolean") {
  160. obj.border = border ? "1px #eee solid" : "none";
  161. } else {
  162. let width = border && border.width || widthDefaultValue;
  163. width = this.value2px(width);
  164. let radius = border && border.radius || radiusDefaultValue;
  165. radius = this.value2px(radius);
  166. obj = {
  167. "border-width": width,
  168. "border-style": border && border.style || "solid",
  169. "border-color": border && border.color || "#eee",
  170. "border-radius": radius
  171. };
  172. }
  173. let classles = "";
  174. for (let i in obj) {
  175. classles += `${i}:${obj[i]};`;
  176. }
  177. return classles;
  178. }
  179. },
  180. methods: {
  181. getImageUrl(url) {
  182. if ("blob:http:" === url.substr(0, 10)) {
  183. return url;
  184. } else {
  185. return sheep_index.sheep.$url.cdn(url);
  186. }
  187. },
  188. uploadFiles(item, index) {
  189. this.$emit("uploadFiles", item);
  190. },
  191. choose() {
  192. this.$emit("choose");
  193. },
  194. delFile(index) {
  195. this.$emit("delFile", index);
  196. },
  197. previewImage(img, index) {
  198. let urls = [];
  199. if (Number(this.limit) === 1 && this.disablePreview && !this.disabled) {
  200. this.$emit("choose");
  201. }
  202. if (this.disablePreview)
  203. return;
  204. this.list.forEach((i) => {
  205. urls.push(this.getImageUrl(i));
  206. });
  207. common_vendor.index.previewImage({
  208. urls,
  209. current: index
  210. });
  211. },
  212. value2px(value) {
  213. if (typeof value === "number") {
  214. value += "px";
  215. } else {
  216. if (value.indexOf("%") === -1) {
  217. value = value.indexOf("px") !== -1 ? value : value + "px";
  218. }
  219. }
  220. return value;
  221. }
  222. }
  223. };
  224. function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  225. return common_vendor.e({
  226. a: common_vendor.f($options.list, (url, index, i0) => {
  227. return common_vendor.e({
  228. a: $options.getImageUrl(url),
  229. b: common_vendor.o(($event) => $options.previewImage(url, index), index)
  230. }, $props.delIcon && !$props.readonly ? {
  231. c: common_vendor.o(($event) => $options.delFile(index), index)
  232. } : {}, {
  233. d: index
  234. });
  235. }),
  236. b: $props.delIcon && !$props.readonly,
  237. c: common_vendor.s($options.borderStyle),
  238. d: common_vendor.s($options.boxStyle),
  239. e: $options.list.length < $props.limit && !$props.readonly
  240. }, $options.list.length < $props.limit && !$props.readonly ? {
  241. f: common_vendor.s($options.borderStyle),
  242. g: common_vendor.o((...args) => $options.choose && $options.choose(...args)),
  243. h: common_vendor.s($options.boxStyle)
  244. } : {});
  245. }
  246. const Component = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__file", "D:/zx/mall-front-app/sheep/components/s-uploader/upload-image.vue"]]);
  247. wx.createComponent(Component);