index.vue 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  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="widthFix" 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. import {
  21. getCode,
  22. getPosterBg
  23. } from '@/api/index/index.js'
  24. export default {
  25. // components: {
  26. // navBar
  27. // },
  28. data() {
  29. return {
  30. picBase: this.$picBase2,
  31. isLoading: true,
  32. tobheight: 45,
  33. // platform: this.$platform.get(),
  34. showAuthModal: true,
  35. empty: false,
  36. pages: 1,
  37. currentTab: 0,
  38. hasAuth: true, //是否有权限
  39. commissionLv: {
  40. name: '合伙人'
  41. },
  42. //合伙人等级
  43. commissionWallet: null, //合伙人钱包
  44. agentFrom: null, //是否显示我的资料
  45. showLv: true,
  46. loadStatus: 'loadmore', //loadmore-加载前的状态,loading-加载中的状态,nomore-没有更多的状态
  47. currentPage: 1,
  48. lastPage: 1,
  49. logMap: {
  50. system: this.$IMG_URL + '/imgs/commission/commission_base_notice.png',
  51. admin: this.$IMG_URL + '/imgs/commission/commission_base_avatar.png'
  52. },
  53. showTerm: true, //条件弹窗
  54. showGoodsTerm: false, //商品条件
  55. showMoneyTerm: false, //金额条件
  56. goodsTermList: [],
  57. moneyTermNum: 0,
  58. authNotice: {},
  59. showPoster: false,
  60. posterObj: {},
  61. posterfff: '您好,我是AI语言模型,可以帮助你做很多事情。例如:\n- 回答你的问题\n- 给你提供某些信息\n- 帮你搜索网页\n- 聊天和闲聊\n- 玩一些小游戏\n- 计算数学题\n- 翻译语言\n- 生成文本\n等等.....\n如果你有任何问题或需要帮助,请随时告诉我。',
  62. spmplatform: 0,
  63. is_examine: 1,
  64. commission_price: 0,
  65. // info: {},
  66. posterheight: 0,
  67. poster_bg_img_path: '',
  68. commission_alias: '',
  69. info: {
  70. commission_alias: "",
  71. commission_price: "0",
  72. extract_min_price: "100",
  73. first: "50",
  74. instructions: "满100可以提现,48小时到账",
  75. 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>",
  76. is_commission: "1",
  77. is_examine: "2",
  78. is_ranking: "1",
  79. is_self_buy: "2",
  80. is_self_buy_commission: "2",
  81. level: "2",
  82. // poster_bg_height: "1334",
  83. // poster_bg_width: "750",
  84. poster_bg_width: "700",
  85. poster_bg_height: "1100",
  86. poster_bg_img: "1671",
  87. poster_qrcode_x: "270",
  88. poster_qrcode_y: "858",
  89. poster_qrcode_width: "160",
  90. poster_bg_img_filename: "推广海报.jpg",
  91. // poster_bg_img_path: "https://nywhcm.com/addons/wike_aging/public/static/storage/20230625/74f8be11f3f174e63576a777c71d644b.jpg",
  92. poster_bg_img_path: '',
  93. poster_qrcode_width_filename: "tmp_c1537e2c3beb0a3d14f87a63da8b84cc548ea7871f918188.jpg",
  94. poster_qrcode_width_path: "https://nywhcm.com/addons/wike_aging/public/static/storage/20230322/17859fbc20087bd430f224905f5d9370.jpg",
  95. second: "10",
  96. third: "0"
  97. },
  98. haibaoUrl: '',
  99. qrcode: ''
  100. }
  101. },
  102. onLoad() {
  103. // this.createPoster()
  104. this.getCode()
  105. // this.getPosterBg()
  106. },
  107. methods: {
  108. async getCode() {
  109. let res1 = await getCode()
  110. console.log('邀请码返回值--------2', res1);
  111. if (res1.code == 0) {
  112. this.qrcode = res1.data.url
  113. this.getPosterBg()
  114. } else {
  115. this.$toast(res1.message)
  116. }
  117. },
  118. async getPosterBg() {
  119. let res1 = await getPosterBg({
  120. key: 'promotion_background'
  121. })
  122. console.log('海报背景图返回值--------2', res1, this.$ossBaseUrl + res1.data.value);
  123. if (res1.code == 0) {
  124. // this.qrcode = res1.data.url
  125. // this.info.poster_bg_img_path = this.$picBase2 + "haibao_bg.png"
  126. this.info.poster_bg_img_path = this.$ossBaseUrl + res1.data.value
  127. this.createPoster()
  128. } else {
  129. this.$toast(res1.message)
  130. }
  131. },
  132. toSave() {
  133. uni.showLoading({
  134. title: '海报生成中'
  135. });
  136. this.$refs.painter.canvasToTempFilePathSync({
  137. // 在nvue里是jpeg
  138. fileType: 'jpg',
  139. quality: 1,
  140. success: res => {
  141. // wx.saveImageToPhotosAlbum({
  142. // filePath: res.tempFilePath,
  143. // success: (res) => {
  144. // wx.showToast({
  145. // title: '保存成功',
  146. // icon: 'success'
  147. // })
  148. // }
  149. // })
  150. // #ifdef MP-WEIXIN
  151. wx.showShareImageMenu({
  152. path: res.tempFilePath,
  153. success: (r) => {
  154. console.log('r--------------', r);
  155. uni.showToast({
  156. title: '操作成功',
  157. icon: 'success'
  158. })
  159. }
  160. })
  161. // this.showPoster = false;
  162. uni.hideLoading();
  163. // #endif
  164. }
  165. });
  166. },
  167. getdownload(e) {
  168. return new Promise((resolve, reject) => {
  169. uni.request({
  170. url: e,
  171. method: 'GET',
  172. responseType: 'arraybuffer',
  173. success: ress => {
  174. let base64 = wx.arrayBufferToBase64(ress.data);
  175. base64 = 'data:image/jpeg;base64,' + base64
  176. resolve(base64);
  177. },
  178. fail: (e) => {
  179. resolve('fail');
  180. }
  181. })
  182. });
  183. },
  184. posterSuccess() {
  185. uni.hideLoading();
  186. },
  187. test() {
  188. console.log('1212232323---------', this.commissionLv);
  189. },
  190. revertUrl() {
  191. this.$refs.painter.canvasToTempFilePathSync({
  192. // 在nvue里是jpeg
  193. fileType: 'jpg',
  194. quality: 1,
  195. success: res => {
  196. this.haibaoUrl = res.tempFilePath
  197. console.log('this.haibaoUrl', this.haibaoUrl);
  198. }
  199. });
  200. },
  201. async createPoster(e) {
  202. let that = this;
  203. let httpsurl = '';
  204. uni.showLoading({
  205. title: '海报渲染中'
  206. });
  207. console.log('1212232323---------', that.info);
  208. if (that.info.poster_bg_img_path.indexOf("https") < 0) {
  209. httpsurl = await that.getdownload(that.info.poster_bg_img_path.replace("http:", "https:"));
  210. } else {
  211. httpsurl = await that.getdownload(that.info.poster_bg_img_path);
  212. }
  213. if (httpsurl == 'fail') {
  214. uni.hideLoading();
  215. uni.showToast({
  216. title: '生成失败',
  217. icon: 'none'
  218. })
  219. return;
  220. }
  221. let proportionally = this.info.poster_bg_width / uni.$u.sys().windowWidth;
  222. (this.posterObj = {
  223. width: (this.info.poster_bg_width / proportionally) + 'px',
  224. height: (this.info.poster_bg_height / proportionally) + 'px',
  225. background: '#fff',
  226. borderRadius: '16rpx',
  227. views: [{
  228. src: httpsurl,
  229. type: "image",
  230. css: {
  231. width: (this.info.poster_bg_width / proportionally) + 'px',
  232. height: (this.info.poster_bg_height / proportionally) + 'px',
  233. }
  234. },
  235. {
  236. type: 'view',
  237. css: {
  238. left: (this.info.poster_qrcode_x / proportionally) + 'px',
  239. top: (this.info.poster_qrcode_y / proportionally) + 'px',
  240. position: 'fixed',
  241. },
  242. views: [{
  243. type: 'image',
  244. src: this.qrcode,
  245. css: {
  246. width: (this.info.poster_qrcode_width / proportionally) + 'px',
  247. height: (this.info.poster_qrcode_width / proportionally) + 'px',
  248. background: '#fff'
  249. }
  250. }]
  251. }
  252. ]
  253. }),
  254. (
  255. this.showPoster = true,
  256. // this.revertUrl()
  257. setTimeout(() => {
  258. that.$refs.painter.canvasToTempFilePathSync({
  259. // 在nvue里是jpeg
  260. fileType: 'jpg',
  261. quality: 1,
  262. success: res => {
  263. that.haibaoUrl = res.tempFilePath
  264. console.log('that.haibaoUrl', that.haibaoUrl);
  265. }
  266. })
  267. }, 1000)
  268. );
  269. },
  270. }
  271. }
  272. </script>
  273. <style lang="scss" scoped>
  274. @import "./index.scss";
  275. </style>