invitationCode.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438
  1. <template>
  2. <view class="container">
  3. <navbar :config="config" backColor="#666666">
  4. <template v-slot:right>
  5. <view class="">
  6. <text class="iconfont3" style="font-size: 38rpx;margin-right: 30rpx;color: #fff;"
  7. @click="share">&#xe624;</text>
  8. </view>
  9. </template>
  10. </navbar>
  11. <view class="code-box">
  12. <view class="text-bg">
  13. <image src="../../../static/career/txt.png" mode="widthFix"></image>
  14. </view>
  15. <view class="tip">
  16. 注册就送168贡献值,激活就可获得积分收益!
  17. </view>
  18. <view class="code-bg">
  19. <view class="code-content">
  20. <!-- <view class="code-hide">
  21. <image v-if="accountInfo.head_photo" :src="accountInfo.head_photo"></image>
  22. <image v-else :src="imgUrl+'/head-on.png'" mode=""></image>
  23. </view>
  24. <view class="user-name " style="text-align: center; margin: 0 auto;" v-if="accountInfo.nickname != ''">
  25. {{ accountInfo.nickname }}
  26. </view>
  27. <view class="u-font30 u-mt15" v-if="accountInfo.nickname == ''">无名称</view> -->
  28. <view class="user-code-num" @click="copy(accountInfo.invitation_code)">邀请码:
  29. <text class="u-mr30">{{ accountInfo.invitation_code }}</text>
  30. 复制
  31. </view>
  32. <view class="code-bt-bg">
  33. <!--二维码-->
  34. <view class="itemcode">
  35. <uqrcode ref="uqrcode" canvas-id="qrcode" :size="192" :value="url" :options="{ margin: 10 }"
  36. @complete="uqrcodeComplete"></uqrcode>
  37. <!-- <ayQrcode ref="qrcode" :modal="modal_qr" :url="url" @hideQrcode="hideQrcode" :height="120" :width="150" /> -->
  38. </view>
  39. <!-- <image :src="qrcode"></image> -->
  40. </view>
  41. <view class="code-title">消费获得贡献值,分享获得贡献值</view>
  42. <view class="code-title pt0">贡献值越多积分就越多,积分越多收益就越多!</view>
  43. </view>
  44. <canvas canvas-id="canvasId" style="width: 290px; height: 380px;" type="2d" id="canvasId"></canvas>
  45. <canvas canvas-id="myCanvas" style="width: 63px; height: 63px;" type="2d" id="myCanvas"></canvas>
  46. <view class="copy-btn-box " @click="saveQrcode">
  47. <button class="copy-btn">保存图片</button>
  48. </view>
  49. </view>
  50. <view class="bottom-bg">
  51. <image src="../../../static/career/bottom.png" mode="widthFix"></image>
  52. </view>
  53. </view>
  54. <share ref="shares" :contentHeight="580" v-if="isvisible"></share>
  55. </view>
  56. <!--页面加载动画-->
  57. <!-- <ldLoading isFullScreen :active="loading"></ldLoading> -->
  58. <!-- </view> -->
  59. </template>
  60. <script>
  61. // import ayQrcode from "../../components/ay-qrcode/ay-qrcode.vue"
  62. // import ayQrcode from "@/components/ay-qrcode/ay-qrcode.vue";
  63. import Draw from '@/uni_modules/sakura-canvas/js_sdk/index'
  64. import share from "../../public/share";
  65. export default {
  66. components: {
  67. share
  68. },
  69. data() {
  70. return {
  71. config: {
  72. back: true, //false是tolbar页面 是则不写
  73. title: "会员码",
  74. color: '#1A1A1A',
  75. barPlaceholder: false,
  76. //背景颜色;参数一:透明度(0-1);参数二:背景颜色(array则为线性渐变,string为单色背景)
  77. backgroundColor: [0, "#fff"],
  78. statusBarFontColor: '#1A1A1A',
  79. rightSlot: true,
  80. },
  81. modal_qr: false,
  82. url: "",
  83. loading: true,
  84. accountInfo: {},
  85. qrcode: "",
  86. imgUrl: this.$mConfig.staticUrl,
  87. rpx: 0,
  88. isvisible: false,
  89. qrcodeUrl: ''
  90. };
  91. },
  92. onLoad() {
  93. //获取用户信息
  94. this.$http.get("/account/getAccountInfo").then((res) => {
  95. if (res && res.code == 200) {
  96. this.accountInfo = res.data;
  97. // this.url = "https://www.baidu.com"
  98. //扫描之后跳到了h5的注册页面去了
  99. this.url = this.$mConfig.hostUrl + "/pages/register?code=" + this.accountInfo.invitation_code;
  100. console.log(this.url, 1111)
  101. this.loading = false;
  102. }
  103. });
  104. },
  105. methods: {
  106. //复制邀请码
  107. copy(code) {
  108. uni.setClipboardData({
  109. data: code,
  110. success: () => {
  111. uni.showToast({
  112. title: "复制成功",
  113. });
  114. },
  115. });
  116. },
  117. saveQrcode() {
  118. if (!this.qrcodeUrl) {
  119. uni.showToast({
  120. title: "暂无分享码",
  121. icon: "none",
  122. });
  123. return
  124. }
  125. uni.showLoading({
  126. title: '保存中'
  127. });
  128. this.getArcImg().then(res => {
  129. uni.getImageInfo({
  130. src: '/static/career/invitation3.png',
  131. success: (image) => {
  132. let context = uni.createCanvasContext('canvasId');
  133. context.setStrokeStyle("#fff")
  134. context.beginPath();
  135. // context.drawImage("/static/career/bg.png", 0, 0, 290, 380);
  136. context.arc(10, 10, 10, -Math.PI, -Math.PI / 2);
  137. context.lineTo(280, 0);
  138. context.arc(280, 10, 10, -Math.PI / 2, 0);
  139. context.lineTo(290, 380);
  140. context.lineTo(0, 380);
  141. context.lineTo(0, 10);
  142. context.fillStyle = "#fff";
  143. context.fill();
  144. context.stroke()
  145. context.drawImage(res, 115, 20, 63, 63);
  146. context.font = "400 15px Arial";
  147. context.fillStyle = "#1a1a1a";
  148. context.textAlign = "center"
  149. context.fillText(this.accountInfo.nickname, 290 / 2, 100);
  150. let codeText = '邀请码:' + this.accountInfo.invitation_code;
  151. context.font = "400 13px Arial";
  152. context.fillStyle = "#3775f6";
  153. context.fillText(codeText, 290 / 2, 130);
  154. context.textAlign = "center";
  155. context.drawImage(image.path, (290 - 150) / 2, 160, 150, 150);
  156. context.drawImage(this.qrcodeUrl, (290 - 125) / 2, 170, 125, 125);
  157. context.fillStyle = "#1a1a1a";
  158. context.font = "400 12px Arial";
  159. context.fillText('消费获得贡献值,分享获得贡献值', 290 / 2, 340);
  160. context.fillText('贡献值越多积分就越多,积分越多收益就越多!', 290 / 2, 360);
  161. context.clip();
  162. context.draw(false, () => {
  163. // 返回canvas图片信息
  164. uni.canvasToTempFilePath({
  165. canvasId: 'canvasId',
  166. success: (res) => {
  167. uni.saveImageToPhotosAlbum({
  168. filePath: res.tempFilePath,
  169. success() {
  170. uni.hideLoading();
  171. uni.showModal({
  172. title: "保存成功",
  173. content: "图片已成功保存到相册",
  174. showCancel: false
  175. })
  176. },
  177. fail(e) {
  178. console.log(e)
  179. }
  180. })
  181. },
  182. fail: function(err) {
  183. console.log(err)
  184. uni.hideLoading();
  185. }
  186. })
  187. })
  188. }
  189. })
  190. })
  191. },
  192. getArcImg() {
  193. return new Promise((resolve, ret) => {
  194. uni.getImageInfo({
  195. src: '/static/sh-head-on.png',
  196. success: (image) => {
  197. let ctx = uni.createCanvasContext('myCanvas', this);
  198. ctx.save();
  199. ctx.setStrokeStyle("#fff")
  200. ctx.beginPath(); //开始绘制
  201. //先画个圆 x,y是圆心的(x,y) 坐标 r是圆的半径 第四个参数是起始角,以弧度计。(弧的圆形的三点钟位置是 0 度) 第五个参数是结束角,以弧度计 最后是绘图方向 默认是false,即顺时针
  202. ctx.arc(32, 32, 30, 0, Math.PI * 2, false);
  203. ctx.setLineWidth(3)
  204. ctx.stroke()
  205. ctx.clip(); //画好了圆 开始剪切 原始画布中剪切任意形状和尺寸。一旦剪切了某个区域,则所有之后的绘图都会被限制在被剪切的区域内 这也是我们要save上下文的原因
  206. // drawImage(图片路径,x,y,绘制图像的宽度,绘制图像的高度)
  207. //path 是用uni.getImageInfo 获取的地址
  208. ctx.drawImage(this.accountInfo.head_photo || image.path, 0, 0, 63, 63); // 推进去图片,必须是https图片
  209. ctx.restore(); //恢复之前保存的绘图上下文 恢复之前保存的绘图上下午即状态 还可以继续绘制
  210. ctx.draw(false, (ret) => { // draw方法 把以上内容画到 canvas 中。
  211. uni.canvasToTempFilePath({
  212. canvasId: 'myCanvas',
  213. success: (re) => {
  214. // that.imgUrl = res.tempFilePath;
  215. resolve(re.tempFilePath)
  216. },
  217. fail: function(err) {
  218. console.log(err)
  219. }
  220. })
  221. });
  222. }
  223. })
  224. })
  225. },
  226. uqrcodeComplete() {
  227. this.$refs.uqrcode.toTempFilePath({
  228. success: res => {
  229. this.qrcodeUrl = res.tempFilePath;
  230. },
  231. });
  232. },
  233. share() {
  234. let token = uni.getStorageSync("apiToken");
  235. if (!token) {
  236. uni.navigateTo({
  237. url: "/pages/login/index",
  238. });
  239. } else {
  240. this.isvisible = true;
  241. this.$nextTick(() => {
  242. this.$refs.shares.shareInfo(
  243. "",
  244. 'pages/register?code=' + this.accountInfo.invitation_code,
  245. '',
  246. "",
  247. ''
  248. );
  249. })
  250. }
  251. },
  252. },
  253. };
  254. </script>
  255. <style lang="scss" scoped>
  256. page {
  257. height: 100vh;
  258. }
  259. .code-box {
  260. width: 100%;
  261. min-height: 1622rpx;
  262. // min-height: 100vh;
  263. padding-top: 150rpx;
  264. // min-height: 490rpx;
  265. // background: #287fe5 url('../../../static/career/invitation2.png') no-repeat bottom center;
  266. // background-size: 750rpx 220rpx;
  267. background: url('../../../static/career/bg.png') no-repeat;
  268. background-size: 100% 100%;
  269. .code-bg {
  270. width: 100%;
  271. position: relative;
  272. top: 300rpx;
  273. // background: url('../../../static/career/invitation1.png') no-repeat top center;
  274. // background-size: 750rpx 490rpx;
  275. // padding-top: 315rpx;
  276. z-index: 3;
  277. .code-content {
  278. width: 698rpx;
  279. padding: 60rpx;
  280. background-color: #fff;
  281. margin: 0 auto;
  282. border: 3px solid #3fc3d7;
  283. border-radius: 20rpx;
  284. display: flex;
  285. flex-direction: column;
  286. align-items: center;
  287. .code-hide {
  288. width: 138rpx;
  289. height: 138rpx;
  290. border-radius: 50%;
  291. image {
  292. width: 100%;
  293. height: 100%;
  294. border-radius: 50%;
  295. }
  296. }
  297. .user-name {
  298. padding: 5px 0;
  299. font-size: 36rpx;
  300. font-family: PingFang SC, PingFang SC-Bold;
  301. font-weight: 700;
  302. text-align: center;
  303. color: #1a1a1a;
  304. }
  305. .user-code-num {
  306. font-size: 24rpx;
  307. font-family: PingFang SC, PingFang SC-Regular;
  308. font-weight: 400;
  309. color: #FA6138;
  310. padding-bottom: 42rpx;
  311. }
  312. .code-bt-bg {
  313. width: 438rpx;
  314. height: 412rpx;
  315. padding: 22rpx 35rpx;
  316. background: url('../../../static/career/invitation3.png') no-repeat center center;
  317. background-size: 438rpx 412rpx;
  318. .itemcode {
  319. width: 100%;
  320. height: 100%;
  321. // background-color: red;
  322. display: flex;
  323. justify-content: center;
  324. align-items: center;
  325. }
  326. }
  327. .code-title {
  328. padding-top: 26rpx;
  329. font-size: 24rpx;
  330. font-family: PingFang SC, PingFang SC-Regular;
  331. font-weight: 500;
  332. color: #000;
  333. }
  334. .pt0 {
  335. padding-top: 5rpx;
  336. }
  337. }
  338. }
  339. .copy-btn-box {
  340. width: 387rpx;
  341. height: 90rpx;
  342. margin: 45rpx auto;
  343. background-color: #FFFFFF;
  344. border-radius: 45rpx;
  345. .copy-btn {
  346. width: 100%;
  347. height: 100%;
  348. border-radius: 45rpx;
  349. font-size: 30rpx;
  350. font-family: PingFang SC, PingFang SC-Regular;
  351. font-weight: 400;
  352. color: #FA6138;
  353. display: flex;
  354. justify-content: center;
  355. align-items: center;
  356. }
  357. }
  358. #canvasId {
  359. width: 580rpx;
  360. height: 742rpx;
  361. margin-top: 20rpx;
  362. border-radius: 20rpx;
  363. overflow: hidden;
  364. position: fixed;
  365. right: -99999rpx;
  366. }
  367. #myCanvas {
  368. position: absolute;
  369. left: -99999rpx;
  370. }
  371. .text-bg {
  372. // position: absolute;
  373. // top: 190rpx;
  374. // left: 50%;
  375. width: 525rpx;
  376. margin: 50rpx auto 0;
  377. // transform: translateX(-50%);
  378. image {
  379. width: 100%;
  380. }
  381. }
  382. .tip {
  383. font-size: 22rpx;
  384. font-family: Source Han Sans CN, Source Han Sans CN-Bold;
  385. font-weight: 700;
  386. text-align: center;
  387. color: #ffffff;
  388. }
  389. .bottom-bg {
  390. position: fixed;
  391. bottom: 0;
  392. width: 100%;
  393. z-index: 1;
  394. image {
  395. width: 100%;
  396. vertical-align: middle;
  397. }
  398. }
  399. // <view class="code-bg">
  400. // <view class="code-content">
  401. // </view>
  402. // </view>
  403. }
  404. </style>