index.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. <template>
  2. <view class="container">
  3. <navBar title="推广海报" :back="true" color="#333333" background="#FFFFFF" />
  4. <!-- <view class="test" @click="createPoster">
  5. 生成
  6. </view> -->
  7. <view class="haobaoBox" v-if="showPoster">
  8. <wike-painter style="display: none;" :board="posterObj" @done="posterSuccess" ref="painter"></wike-painter>
  9. <image :src="haibaoUrl" mode="" class="haibao"></image>
  10. </view>
  11. <view class="btnBox">
  12. <view class="btn" @click="toSave">
  13. 保存到手机相册
  14. </view>
  15. </view>
  16. </view>
  17. </template>
  18. <script>
  19. // import navBar from '@/components/navBar/index.vue'
  20. export default {
  21. // components: {
  22. // navBar
  23. // },
  24. data() {
  25. return {
  26. picBase: this.$picBase2,
  27. isLoading: true,
  28. tobheight: 45,
  29. // platform: this.$platform.get(),
  30. showAuthModal: true,
  31. empty: false,
  32. pages: 1,
  33. currentTab: 0,
  34. hasAuth: true, //是否有权限
  35. commissionLv: {
  36. name: '合伙人'
  37. },
  38. //合伙人等级
  39. commissionWallet: null, //合伙人钱包
  40. agentFrom: null, //是否显示我的资料
  41. showLv: true,
  42. loadStatus: 'loadmore', //loadmore-加载前的状态,loading-加载中的状态,nomore-没有更多的状态
  43. currentPage: 1,
  44. lastPage: 1,
  45. logMap: {
  46. system: this.$IMG_URL + '/imgs/commission/commission_base_notice.png',
  47. admin: this.$IMG_URL + '/imgs/commission/commission_base_avatar.png'
  48. },
  49. showTerm: true, //条件弹窗
  50. showGoodsTerm: false, //商品条件
  51. showMoneyTerm: false, //金额条件
  52. goodsTermList: [],
  53. moneyTermNum: 0,
  54. authNotice: {},
  55. showPoster: false,
  56. posterObj: {},
  57. posterfff: '您好,我是AI语言模型,可以帮助你做很多事情。例如:\n- 回答你的问题\n- 给你提供某些信息\n- 帮你搜索网页\n- 聊天和闲聊\n- 玩一些小游戏\n- 计算数学题\n- 翻译语言\n- 生成文本\n等等.....\n如果你有任何问题或需要帮助,请随时告诉我。',
  58. spmplatform: 0,
  59. is_examine: 1,
  60. commission_price: 0,
  61. // info: {},
  62. posterheight: 0,
  63. poster_bg_img_path: '',
  64. commission_alias: '',
  65. info: {
  66. commission_alias: "",
  67. commission_price: "0",
  68. extract_min_price: "100",
  69. first: "50",
  70. instructions: "满100可以提现,48小时到账",
  71. intro: "<p><span style=\"color: rgb(102, 102, 102); font-family: \" helvetica=\"\" pingfang=\"\" font-size:=\"\" text-align:=\"\" text-wrap:=\"\" background-color:=\"\">入驻说明,加入分销商需要沟通买399年卡会员.</span></p><p><font color=\"#666666\">联系客服开通!</font></p>",
  72. is_commission: "1",
  73. is_examine: "2",
  74. is_ranking: "1",
  75. is_self_buy: "2",
  76. is_self_buy_commission: "2",
  77. level: "2",
  78. poster_bg_height: "1334",
  79. poster_bg_img: "1671",
  80. poster_bg_img_filename: "分销海报.jpg",
  81. poster_bg_img_path: "https://nywhcm.com/addons/wike_aging/public/static/storage/20230625/74f8be11f3f174e63576a777c71d644b.jpg",
  82. poster_bg_width: "750",
  83. poster_qrcode_width: "135",
  84. poster_qrcode_width_filename: "tmp_c1537e2c3beb0a3d14f87a63da8b84cc548ea7871f918188.jpg",
  85. poster_qrcode_width_path: "https://nywhcm.com/addons/wike_aging/public/static/storage/20230322/17859fbc20087bd430f224905f5d9370.jpg",
  86. poster_qrcode_x: "514",
  87. poster_qrcode_y: "1174",
  88. second: "10",
  89. third: "0"
  90. },
  91. haibaoUrl:''
  92. }
  93. },
  94. onLoad() {
  95. this.createPoster()
  96. },
  97. methods: {
  98. toSave() {
  99. uni.showLoading({
  100. title: '海报生成中'
  101. });
  102. this.$refs.painter.canvasToTempFilePathSync({
  103. // 在nvue里是jpeg
  104. fileType: 'jpg',
  105. quality: 1,
  106. success: res => {
  107. // #ifdef MP-WEIXIN
  108. wx.showShareImageMenu({
  109. path: res.tempFilePath
  110. })
  111. // this.showPoster = false;
  112. uni.hideLoading();
  113. // #endif
  114. }
  115. });
  116. },
  117. getdownload(e) {
  118. return new Promise((resolve, reject) => {
  119. uni.request({
  120. url: e,
  121. method: 'GET',
  122. responseType: 'arraybuffer',
  123. success: ress => {
  124. let base64 = wx.arrayBufferToBase64(ress.data);
  125. base64 = 'data:image/jpeg;base64,' + base64
  126. resolve(base64);
  127. },
  128. fail: (e) => {
  129. resolve('fail');
  130. }
  131. })
  132. });
  133. },
  134. posterSuccess() {
  135. uni.hideLoading();
  136. },
  137. test() {
  138. console.log('1212232323---------', this.commissionLv);
  139. },
  140. revertUrl(){
  141. this.$refs.painter.canvasToTempFilePathSync({
  142. // 在nvue里是jpeg
  143. fileType: 'jpg',
  144. quality: 1,
  145. success: res => {
  146. this.haibaoUrl=res.tempFilePath
  147. console.log('this.haibaoUrl',this.haibaoUrl);
  148. }
  149. });
  150. },
  151. async createPoster(e) {
  152. let that = this;
  153. let httpsurl = '';
  154. uni.showLoading({
  155. title: '海报渲染中'
  156. });
  157. console.log('1212232323---------', that.info);
  158. if (that.info.poster_bg_img_path.indexOf("https") < 0) {
  159. httpsurl = await that.getdownload(that.info.poster_bg_img_path.replace("http:", "https:"));
  160. } else {
  161. httpsurl = await that.getdownload(that.info.poster_bg_img_path);
  162. }
  163. if (httpsurl == 'fail') {
  164. uni.hideLoading();
  165. uni.showToast({
  166. title: '生成失败',
  167. icon: 'none'
  168. })
  169. return;
  170. }
  171. let proportionally = this.info.poster_bg_width / uni.$u.sys().windowWidth;
  172. (this.posterObj = {
  173. width: (this.info.poster_bg_width / proportionally) + 'px',
  174. height: (this.info.poster_bg_height / proportionally) + 'px',
  175. background: '#fff',
  176. borderRadius: '16rpx',
  177. views: [{
  178. src: httpsurl,
  179. type: "image",
  180. css: {
  181. width: (this.info.poster_bg_width / proportionally) + 'px',
  182. height: (this.info.poster_bg_height / proportionally) + 'px',
  183. }
  184. },
  185. {
  186. type: 'view',
  187. css: {
  188. left: (this.info.poster_qrcode_x / proportionally) + 'px',
  189. top: (this.info.poster_qrcode_y / proportionally) + 'px',
  190. position: 'fixed',
  191. },
  192. // #ifdef H5
  193. views: [{
  194. type: 'qrcode',
  195. text: this.qrcode,
  196. css: {
  197. width: (this.info.poster_qrcode_width / proportionally) + 'px',
  198. height: (this.info.poster_qrcode_width / proportionally) + 'px',
  199. background: '#fff'
  200. }
  201. }],
  202. // #endif
  203. // #ifdef MP-WEIXIN
  204. views: [{
  205. type: 'image',
  206. src: this.qrcode,
  207. css: {
  208. width: (this.info.poster_qrcode_width / proportionally) + 'px',
  209. height: (this.info.poster_qrcode_width / proportionally) + 'px',
  210. background: '#fff'
  211. }
  212. }]
  213. // #endif
  214. }
  215. ]
  216. }),
  217. (
  218. this.showPoster = true,
  219. // this.revertUrl()
  220. setTimeout(()=>{
  221. that.$refs.painter.canvasToTempFilePathSync({
  222. // 在nvue里是jpeg
  223. fileType: 'jpg',
  224. quality: 1,
  225. success: res => {
  226. that.haibaoUrl=res.tempFilePath
  227. console.log('that.haibaoUrl',that.haibaoUrl);
  228. }
  229. })
  230. },1000)
  231. );
  232. },
  233. }
  234. }
  235. </script>
  236. <style lang="scss" scoped>
  237. @import "./index.scss";
  238. </style>