青蛙卖大米小程序2024-11-24
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

311 lines
7.0 KiB

1 year ago
11 months ago
11 months ago
1 year ago
1 year ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
1 year ago
1 year ago
11 months ago
1 year ago
11 months ago
1 year ago
1 year ago
11 months ago
1 year ago
11 months ago
1 year ago
11 months ago
11 months ago
1 year ago
11 months ago
11 months ago
1 year ago
11 months ago
1 year ago
11 months ago
1 year ago
11 months ago
1 year ago
11 months ago
1 year ago
1 year ago
1 year ago
1 year ago
11 months ago
1 year ago
11 months ago
1 year ago
11 months ago
1 year ago
1 year ago
11 months ago
11 months ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
11 months ago
1 year ago
  1. <template>
  2. <view class="promotion">
  3. <navbar title="推荐有礼"
  4. :bgColor="bgColor"
  5. color="#fff"
  6. leftClick @leftClick="$utils.navigateBack" />
  7. <view class="tui_image"
  8. v-if="!show">
  9. <image :src="configList.tui_image" mode="widthFix"
  10. style="width: 100%;"></image>
  11. <view class="uni-color-btn"
  12. @click="clickTab">
  13. 推荐二维码海报生成
  14. </view>
  15. </view>
  16. <view
  17. v-if="show">
  18. <image
  19. class="image"
  20. :src="imagePath" mode="aspectFill"></image>
  21. <!-- <view class="uni-color-btn"
  22. @click="preservationImg(imagePath)">保存二维码</view> -->
  23. </view>
  24. <canvas id="myCanvas" type="2d" canvas-id="firstCanvas1"></canvas>
  25. <!-- <view class="promotion-card"
  26. v-if="show">
  27. <image :src="userInfo.headImage" mode="aspectFill"
  28. class="headImage"></image>
  29. <image style="width: 100%;" :src="imagePath" mode="widthFix"></image>
  30. <view class="invitation-code">加油站: {{ title }}</view>
  31. <canvas id="myCanvas" type="2d" canvas-id="firstCanvas1"></canvas>
  32. <view class="uni-color-btn"
  33. @click="preservationImg(imagePath)">保存二维码</view>
  34. </view> -->
  35. </view>
  36. </template>
  37. <script>
  38. import { mapState } from 'vuex'
  39. export default {
  40. name: 'Promotion',
  41. computed: {
  42. ...mapState(['userInfo']),
  43. },
  44. data() {
  45. return {
  46. url: '',
  47. title: '123123',
  48. baseUrl: 'https://image.hhlm1688.com/',
  49. canvas: {},
  50. imagePath: '',
  51. show : false,
  52. bgColor : '#fe6c17',
  53. load : false,
  54. }
  55. },
  56. onShow() {
  57. this.getQrCode()
  58. this.$store.commit('getUserInfo')
  59. },
  60. methods: {
  61. getQrCode() {
  62. // this.show = true
  63. this.load = true
  64. this.$api('getInviteCode', res => {
  65. if (res.code == 200) {
  66. this.url = res.result.url
  67. this.title = res.result.name
  68. this.draw()
  69. }
  70. })
  71. },
  72. clickTab(){
  73. this.bgColor = '#de0917'
  74. this.show = true
  75. if(this.load){
  76. uni.showLoading({
  77. title: "拼命绘画中..."
  78. })
  79. }
  80. },
  81. draw() {
  82. // uni.showLoading({
  83. // title: "拼命绘画中..."
  84. // })
  85. wx.createSelectorQuery()
  86. .select('#myCanvas') // 绘制的canvas的id
  87. .fields({
  88. node: true,
  89. size: true
  90. })
  91. .exec((res) => {
  92. const canvas = res[0].node
  93. // 渲染上下文
  94. const ctx = canvas.getContext('2d')
  95. // Canvas 画布的实际绘制宽高
  96. const width = res[0].width
  97. const height = res[0].height
  98. console.log(width, height);
  99. // 初始化画布大小
  100. const dpr = wx.getWindowInfo().pixelRatio
  101. //根据dpr调整
  102. // dpr 2 4
  103. // 3 6
  104. let Ratio = dpr * 2
  105. console.log("bug", dpr)
  106. canvas.width = width * dpr
  107. canvas.height = height * dpr
  108. this.canvas = canvas
  109. ctx.scale(dpr, dpr)
  110. ctx.clearRect(0, 0, width, height)
  111. // ctx.fillStyle = '#fff'
  112. // ctx.fillRect(0, 0, canvas.width, canvas.height)
  113. const bgImage = canvas.createImage()
  114. bgImage.src = this.configList.qr_image
  115. bgImage.onload = () => {
  116. canvas.width = bgImage.width
  117. canvas.height = bgImage.height
  118. ctx.drawImage(bgImage,
  119. 0, 0, bgImage.width, bgImage.height)
  120. }
  121. //用户图片
  122. // const image = canvas.createImage()
  123. // image.onload = () => {
  124. // ctx.drawImage(image, 30, 18, 40, 40)
  125. // }
  126. // image.src = '/public/img/wechar_1.png'
  127. // image.src = this.userInfo.headImage
  128. ctx.fillStyle = 'black'
  129. ctx.font = '22px PingFangSC-regular';
  130. // 绘制用户姓名
  131. // let nickName = this.userInfo.nickName || '绘制用户姓名'
  132. // ctx.fillText(nickName, canvas.width / Ratio - nickName.length * 11, 40);
  133. // ctx.font = '18px PingFangSC-regular';
  134. // 绘制欢迎语
  135. let s = this.title || ''
  136. // ctx.fillText(s, canvas.width / Ratio - s.length * 11, 50);
  137. //二维码图片
  138. const coderImage = canvas.createImage()
  139. coderImage.src = this.baseUrl + this.url
  140. coderImage.onload = () => {
  141. ctx.drawImage(coderImage,
  142. canvas.width / 2 - 175, canvas.height / 2 - 100, 350, 350)
  143. }
  144. // 绘制完成后存储路径
  145. setTimeout(() => {
  146. wx.canvasToTempFilePath({
  147. x: 0,
  148. y: 0,
  149. width: this.canvas.width,
  150. height: this.canvas.height,
  151. canvas,
  152. success: (res) => {
  153. var tempFilePath = res.tempFilePath;
  154. this.imagePath = tempFilePath
  155. uni.hideLoading()
  156. this.load = false
  157. }
  158. });
  159. }, 600);
  160. })
  161. },
  162. back() {
  163. uni.navigateBack(-1)
  164. },
  165. preservationImg(img) {
  166. let that = this
  167. uni.authorize({
  168. /* scope.writePhotosAlbum 类型是保存到相册 */
  169. scope: 'scope.writePhotosAlbum',
  170. success() {
  171. /* 已授权进入 */
  172. /* 保存图片到相册方法方法 */
  173. that.imgApi(img);
  174. },
  175. complete(res) {
  176. /* 判断如果没有授权就打开设置选项让用户重新授权 */
  177. uni.getSetting({
  178. success(res) {
  179. if (!res.authSetting['scope.writePhotosAlbum']) {
  180. /* 打开设置的方法 */
  181. that.openInstall();
  182. }
  183. }
  184. });
  185. }
  186. });
  187. },
  188. imgApi(image) {
  189. /* 获取图片的信息 */
  190. uni.getImageInfo({
  191. src: image,
  192. success: function(image) {
  193. /* 保存图片到手机相册 */
  194. uni.saveImageToPhotosAlbum({
  195. filePath: image.path,
  196. success: function() {
  197. uni.showModal({
  198. title: '保存成功',
  199. content: '图片已成功保存到相册',
  200. showCancel: false
  201. });
  202. },
  203. complete(res) {
  204. console.log(res);
  205. }
  206. });
  207. }
  208. });
  209. },
  210. }
  211. }
  212. </script>
  213. <style lang="scss" scoped>
  214. .promotion {
  215. width: 100%;
  216. height: 100vh;
  217. background-color: #de0917;
  218. .tui_image{
  219. position: relative;
  220. .uni-color-btn{
  221. position: absolute;
  222. bottom: 150rpx;
  223. height: 40rpx;
  224. background-color: #fff;
  225. box-shadow: 0 0 10rpx 10rpx #ffffff66;
  226. color: #de0917;
  227. font-weight: 900;
  228. width: 80%;
  229. font-family: STFangsong;
  230. font-size: 34rpx;
  231. }
  232. }
  233. .image{
  234. width: 100%;
  235. height: calc(100vh - 200rpx);
  236. }
  237. // background-color: $uni-color;
  238. .promotion-card {
  239. width: 90%;
  240. margin: 140rpx auto 0rpx auto;
  241. box-shadow: 0rpx 0rpx 15rpx rgba(0, 0, 0, .2);
  242. border-radius: 40rpx;
  243. padding: 40rpx 30rpx;
  244. box-sizing: border-box;
  245. background-color: #fff;
  246. position: relative;
  247. padding-top: 100rpx;
  248. .headImage{
  249. position: absolute;
  250. height: 180rpx;
  251. width: 180rpx;
  252. border-radius: 50%;
  253. top: -80rpx;
  254. left: 50%;
  255. transform: translate(-50%);
  256. border: 10rpx solid #fff;
  257. box-shadow: 0 0 10rpx 10rpx #00000013;
  258. }
  259. }
  260. }
  261. #myCanvas {
  262. position: fixed;
  263. left: 100%;
  264. /* visibility: hidden */
  265. /* visibility: hidden; */
  266. /* margin-top: 100rpx; */
  267. width: 750rpx;
  268. height: calc(100vh - 120rpx);
  269. /* line-height: 20px; */
  270. background-color: rgba(255, 255, 255, 1);
  271. text-align: center;
  272. }
  273. </style>