price-to-img.js 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. exports.ids = [24];
  2. exports.modules = {
  3. /***/ 203:
  4. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  5. "use strict";
  6. // ESM COMPAT FLAG
  7. __webpack_require__.r(__webpack_exports__);
  8. // CONCATENATED MODULE: ./node_modules/babel-loader/lib??ref--2-0!./node_modules/vue-loader/lib/loaders/templateLoader.js??ref--6!./node_modules/@nuxt/components/dist/loader.js??ref--0-0!./node_modules/vue-loader/lib??vue-loader-options!./components/PriceToImg.vue?vue&type=template&id=2e991f10
  9. var render = function render() {
  10. var _vm = this,
  11. _c = _vm._self._c;
  12. return _c('div', {
  13. ref: "printArea",
  14. staticStyle: {
  15. "font-family": "ProximaNova-Regular",
  16. "background-color": "#fff",
  17. "padding": "20px",
  18. "word-break": "break-word",
  19. "box-sizing": "border-box"
  20. }
  21. }, [_vm._ssrNode("<table><tbody><tr><td style=\"margin-right: 14px;\">" + (_vm.isImgSrc ? "<img" + _vm._ssrAttr("src", _vm.comInfo.image) + " width=\"320\" height=\"320\">" : "<img width=\"250\" height=\"250\">") + "</td> <td style=\"vertical-align: top;\"><p style=\"font-weight: bold;font-size: 22px;padding-bottom: 24px;color:#00213B\"><span style=\"margin-right: 5px;\">" + _vm._ssrEscape(_vm._s(_vm.pageData.product_code)) + "</span> <span>" + _vm._ssrEscape(_vm._s(_vm.pageData.product_name)) + "</span></p> <p style=\"line-height: 20px;color:#00213B;font-size: 14px;\">" + _vm._s(_vm.comInfo.description) + "</p></td></tr></tbody></table> <div><p style=\"font-weight: bold;font-size: 17px;margin: 12px 0 8px;color:#00213B\">Specifications</p> <table style=\"width:100%;border-collapse: collapse;font-size: 14px;table-layout: fixed;text-align:center;\"><tbody><tr style=\"background-color: #F7F8FC;font-weight: bold;\">" + _vm._ssrList(_vm.headerColumns, function (item, key) {
  22. return "<td style=\"padding:10px 0;color:#00213B;width: 25%;font-size: 14px;border:1px solid #EFEFEF\">" + _vm._ssrEscape(_vm._s(item.label)) + "</td>";
  23. }) + "</tr> <tr>" + _vm._ssrList(_vm.headerColumns, function (item, key) {
  24. return "<td style=\"padding:10px 0 6px;color:#00213B;border:1px solid #EFEFEF\">" + (_vm.specificationsObj[item.prop] ? "<div>" + (item.prop != 'addonArr' ? "<span>" + _vm._ssrEscape(_vm._s(_vm.specificationsObj[item.prop])) + "</span>" : _vm._ssrList(_vm.specificationsObj.addonArr, function (opt, idx) {
  25. return "<div style=\"padding-bottom:4px;\">" + _vm._ssrEscape(_vm._s(opt)) + "</div>";
  26. })) + "</div>" : "<span>-</span>") + "</td>";
  27. }) + "</tr></tbody></table></div> <div><p style=\"font-weight: bold;font-size: 17px;margin: 12px 0 8px;color:#00213B\">Quote</p> <table style=\"width:100%;border-collapse: collapse;font-size: 14px;table-layout: fixed;text-align:center;\"><tbody>" + (_vm.comLocationNum !== 1 ? "<tr style=\"background-color: #F7F8FC;font-weight: bold;\"><td" + _vm._ssrAttr("colspan", _vm.tableColumns.length - 1) + " style=\"padding:10px 0;color:#00213B;border:1px solid #EFEFEF\">Quote</td> <td" + _vm._ssrStyle({
  28. "padding": "10px 0",
  29. "color": "#00213B",
  30. "border": "1px solid #EFEFEF"
  31. }, {
  32. width: _vm.comWidth
  33. }, null) + ">Total</td></tr>" : "<!---->") + " <tr style=\"background-color: #F7F8FC;font-weight: bold;\">" + _vm._ssrList(_vm.tableColumns, function (item, key) {
  34. return "<td" + _vm._ssrStyle({
  35. "padding": "10px 0",
  36. "color": "#00213B",
  37. "border": "1px solid #EFEFEF"
  38. }, {
  39. width: _vm.comWidth
  40. }, null) + ">" + _vm._ssrEscape(_vm._s(item.label)) + "</td>";
  41. }) + "</tr> " + _vm._ssrList(_vm.tableData, function (row) {
  42. return "<tr style=\"padding:10px 0;\">" + _vm._ssrList(_vm.tableColumns, function (column) {
  43. return "<td" + _vm._ssrStyle({
  44. "padding": "10px 0",
  45. "color": "#00213B",
  46. "border": "1px solid #EFEFEF",
  47. "white-space": "nowrap"
  48. }, _vm.getColumnHeaderStyle(column), null) + ">" + _vm._ssrEscape("\n " + _vm._s(row[column.prop].includes('.') ? '£' : '') + " " + _vm._s(row[column.prop] ? row[column.prop] : '0.00') + "\n ") + "</td>";
  49. }) + "</tr>";
  50. }) + "</tbody></table></div> " + (_vm.emailForm.Comments ? "<div style=\"color:#00213B\"><p style=\"margin: 20px 0;\">" + _vm._ssrEscape(_vm._s(_vm.emailForm.Comments)) + "</p></div>" : "<!---->"))]);
  51. };
  52. var staticRenderFns = [];
  53. // CONCATENATED MODULE: ./components/PriceToImg.vue?vue&type=template&id=2e991f10
  54. // EXTERNAL MODULE: external "html2canvas"
  55. var external_html2canvas_ = __webpack_require__(142);
  56. var external_html2canvas_default = /*#__PURE__*/__webpack_require__.n(external_html2canvas_);
  57. // CONCATENATED MODULE: ./node_modules/babel-loader/lib??ref--2-0!./node_modules/@nuxt/components/dist/loader.js??ref--0-0!./node_modules/vue-loader/lib??vue-loader-options!./components/PriceToImg.vue?vue&type=script&lang=js
  58. /* harmony default export */ var PriceToImgvue_type_script_lang_js = ({
  59. props: {
  60. pageData: {
  61. type: Object,
  62. default: {}
  63. },
  64. specificationsObj: {
  65. type: Object,
  66. default: {}
  67. },
  68. tableData: {
  69. type: Array,
  70. default: []
  71. },
  72. tableColumns: {
  73. type: Array,
  74. default: []
  75. },
  76. comLocationNum: {
  77. type: Number,
  78. default: 1
  79. },
  80. emailForm: {
  81. type: Object,
  82. default: {}
  83. },
  84. loading: {
  85. type: Boolean,
  86. default: false
  87. },
  88. isImgSrc: {
  89. type: Boolean,
  90. default: true
  91. },
  92. width: {
  93. type: String,
  94. default: '100%'
  95. }
  96. },
  97. data() {
  98. return {
  99. headerColumns: [{
  100. label: "LeadTime",
  101. prop: "time",
  102. type: "pre" //去掉$符号
  103. }, {
  104. label: "Model",
  105. prop: "model",
  106. type: "pre" //去掉$符号
  107. }, {
  108. label: "Decoration",
  109. prop: "decoration",
  110. type: "pre" //去掉$符号
  111. }, {
  112. label: "Add On",
  113. prop: "addonArr",
  114. type: "pre" //去掉$符号
  115. }]
  116. };
  117. },
  118. computed: {
  119. comInfo() {
  120. var _this$pageData;
  121. return (_this$pageData = this.pageData) === null || _this$pageData === void 0 ? void 0 : _this$pageData.main;
  122. },
  123. comWidth() {
  124. return 100 / this.tableColumns.length + '%';
  125. }
  126. },
  127. created() {
  128. if (!this.isImgSrc) {
  129. this.getBase64Image(this.comInfo.image, 'productImg');
  130. }
  131. },
  132. methods: {
  133. getColumnHeaderStyle(column) {
  134. if (column.prop === 'project') {
  135. return {
  136. 'font-weight': 'bold'
  137. };
  138. }
  139. return {};
  140. },
  141. //Base64生成产品图片,因为跨域
  142. getBase64Image(url, ref) {
  143. var that = this;
  144. var image = new Image();
  145. image.src = url + '?v=' + Math.random(); // 处理缓存
  146. image.crossOrigin = '*'; // 支持跨域图片
  147. image.onload = function () {
  148. var base64 = that.drawBase64Image(image);
  149. that.$refs[ref].src = base64;
  150. };
  151. },
  152. drawBase64Image(img) {
  153. var canvas = document.createElement('canvas');
  154. canvas.width = img.width;
  155. canvas.height = img.height;
  156. var ctx = canvas.getContext('2d');
  157. ctx.drawImage(img, 0, 0, img.width, img.height);
  158. var dataURL = canvas.toDataURL('image/png');
  159. return dataURL;
  160. },
  161. htmlToPdf(title) {
  162. const element = this.$refs.printArea;
  163. const clientWidth = element.offsetWidth;
  164. const clientHeight = element.offsetHeight;
  165. const kh = [clientWidth, clientHeight];
  166. const opts = {
  167. scale: 1.5,
  168. // 缩放比例,提高生成图片清晰度
  169. useCORS: true,
  170. // 允许加载跨域的图片
  171. // allowTaint: true, // 允许图片跨域,和 useCORS 二者不可共同使用
  172. tainttest: true,
  173. // 检测每张图片已经加载完成
  174. logging: true // 日志开关,发布的时候记得改成 false
  175. };
  176. external_html2canvas_default()(element, opts).then(canvas => {
  177. const dataURL = canvas.toDataURL('image/png');
  178. this.downloadImage(dataURL, kh, title);
  179. this.$emit('update:loading', false);
  180. }).catch(() => {
  181. this.$emit('update:loading', false);
  182. // Bus.$emit("finishDownload");
  183. });
  184. },
  185. getUrlBase64(url, kh) {
  186. return new Promise(resolve => {
  187. let canvas = document.createElement('canvas');
  188. const ctx = canvas.getContext('2d');
  189. const img = new Image();
  190. img.crossOrigin = 'Anonymous'; // 允许跨域
  191. img.src = url;
  192. img.onload = () => {
  193. // eslint-disable-next-line prefer-destructuring
  194. canvas.height = kh[1];
  195. // eslint-disable-next-line prefer-destructuring
  196. canvas.width = kh[0];
  197. ctx.drawImage(img, 0, 0, kh[0], kh[1]);
  198. const dataURL = canvas.toDataURL('image/png');
  199. canvas = null;
  200. resolve(dataURL);
  201. };
  202. });
  203. },
  204. downloadImage(imgUrl, kh, title) {
  205. this.getUrlBase64(imgUrl, kh).then(base64 => {
  206. const link = document.createElement('a');
  207. link.href = base64;
  208. link.download = `${title}.png`;
  209. link.click();
  210. });
  211. }
  212. }
  213. });
  214. // CONCATENATED MODULE: ./components/PriceToImg.vue?vue&type=script&lang=js
  215. /* harmony default export */ var components_PriceToImgvue_type_script_lang_js = (PriceToImgvue_type_script_lang_js);
  216. // EXTERNAL MODULE: ./node_modules/vue-loader/lib/runtime/componentNormalizer.js
  217. var componentNormalizer = __webpack_require__(2);
  218. // CONCATENATED MODULE: ./components/PriceToImg.vue
  219. /* normalize component */
  220. var component = Object(componentNormalizer["a" /* default */])(
  221. components_PriceToImgvue_type_script_lang_js,
  222. render,
  223. staticRenderFns,
  224. false,
  225. null,
  226. null,
  227. "dda7dca6"
  228. )
  229. /* harmony default export */ var PriceToImg = __webpack_exports__["default"] = (component.exports);
  230. /***/ })
  231. };;
  232. //# sourceMappingURL=price-to-img.js.map