invitationCode.vue 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  1. <template>
  2. <view class="container">
  3. <navbar :config="config" backColor="#666666"></navbar>
  4. <view class="bg">
  5. <!-- <image class="bgImg" :src="imgUrl+'/bg.png'"></image> -->
  6. <view class="position-ab">
  7. <view style="color: #000000;" class="u-FFF u-font44">绿马助残 · 就业创业 · 共同富裕</view>
  8. <view class="mt64">
  9. <view class="code-top-bg">
  10. <!-- <image :src="imgUrl+'/code-top-bg.png'"></image> -->
  11. <div class="bg Poster"></div>
  12. <!--个人信息-->
  13. <view class="user">
  14. <image class="Poster" v-if="accountInfo.head_photo" :src="accountInfo.head_photo"></image>
  15. <image v-else :src="imgUrl+'/head-on.png'" mode=""></image>
  16. <view class="u-font30 u-mt15 u-text-width-two " style="text-align: center; margin: 0 auto;"
  17. v-if="accountInfo.nickname != ''">{{
  18. accountInfo.nickname
  19. }}</view>
  20. <view class="u-font30 u-mt15" v-if="accountInfo.nickname == ''">无名称</view>
  21. <view class="u-font24 u-mt20" @click="copy(accountInfo.invitation_code)">邀请码:
  22. <text class="u-mr30"> {{ accountInfo.invitation_code }}</text>
  23. 复制
  24. </view>
  25. </view>
  26. </view>
  27. <view class="code-bt-bg">
  28. <image :src="imgUrl+'/code-bt-bg.png'"></image>
  29. <!--二维码-->
  30. <view class="code">
  31. <view class="itemcode">
  32. <uqrcode ref="uqrcode" :size="125" canvas-id="qrcode" :value="url"
  33. :options="{ margin: 10 }" @complete="uqrcodeComplete"></uqrcode>
  34. </view>
  35. <!-- <image :src="qrcode"></image> -->
  36. <view class="u-mt20 u-1A1A1A u-font30">我的分享二维码</view>
  37. </view>
  38. </view>
  39. </view>
  40. <canvas canvas-id="canvasId" style="width: 290px; height: 380px;" type="2d" id="canvasId"></canvas>
  41. <canvas canvas-id="myCanvas" style="width: 63px; height: 63px;" type="2d" id="myCanvas"></canvas>
  42. <view class="copy-btn u-mt50" @click="init()">
  43. <!-- @click="saveImg" -->
  44. <button class="u-btn-two u-font24">保存图片</button>
  45. </view>
  46. </view>
  47. </view>
  48. <!--页面加载动画-->
  49. <ldLoading isFullScreen :active="loading"></ldLoading>
  50. </view>
  51. </template>
  52. <script>
  53. // import ayQrcode from "../../components/ay-qrcode/ay-qrcode.vue"
  54. import ayQrcode from "@/components/ay-qrcode/ay-qrcode.vue";
  55. export default {
  56. components: {
  57. ayQrcode,
  58. },
  59. data() {
  60. return {
  61. config: {
  62. back: true, //false是tolbar页面 是则不写
  63. title: "我的邀请码",
  64. color: "#1A1A1A",
  65. //背景颜色;参数一:透明度(0-1);参数二:背景颜色(array则为线性渐变,string为单色背景)
  66. backgroundColor: [1, "#FFF"],
  67. statusBarFontColor: "#1A1A1A",
  68. },
  69. modal_qr: false,
  70. url: "",
  71. loading: true,
  72. accountInfo: {},
  73. qrcode: "",
  74. imgUrl: this.$mConfig.staticUrl,
  75. rpx: 0,
  76. systemInfo:{},
  77. qrcodeUrl:""
  78. };
  79. },
  80. onLoad() {
  81. uni.getSystemInfo({
  82. success: (res) => {
  83. this.systemInfo = res
  84. }
  85. })
  86. //获取用户信息
  87. this.$http.get("/account/getAccountInfo").then((res) => {
  88. if (res && res.code == 200) {
  89. this.accountInfo = res.data;
  90. // this.url = "https://www.baidu.com"
  91. //扫描之后跳到了h5的注册页面去了
  92. this.url = this.$mConfig.hostUrl + "/pages/register?code=" + this.accountInfo.invitation_code;
  93. this.loading = false;
  94. }
  95. });
  96. },
  97. methods: {
  98. onSuccess(e) {
  99. console.log(e)
  100. },
  101. init() {
  102. if(!this.qrcodeUrl){
  103. uni.showToast({
  104. title: "暂无分享码",
  105. icon: "none",
  106. });
  107. return
  108. }
  109. uni.showLoading({
  110. title: '保存中'
  111. });
  112. this.getArcImg().then(res => {
  113. uni.getImageInfo({
  114. src: '/static/code-bt-bg.jpg',
  115. success: (image)=>{
  116. let context = uni.createCanvasContext('canvasId');
  117. context.setStrokeStyle("#0B844A")
  118. context.beginPath();
  119. context.arc(10, 10, 10, -Math.PI, -Math.PI / 2);
  120. context.lineTo(280, 0);
  121. context.arc(280, 10, 10, -Math.PI / 2, 0);
  122. context.lineTo(290, 182);
  123. context.lineTo(0, 182);
  124. context.lineTo(0, 10);
  125. context.fillStyle = "#0B844A";
  126. context.fill();
  127. context.stroke()
  128. context.drawImage(res, 115, 20, 63, 63);
  129. context.font = "400 15px Arial";
  130. context.fillStyle = "#fff";
  131. context.textAlign = "center"
  132. context.fillText(this.accountInfo.nickname, 290/2, 100);
  133. let codeText='邀请码:'+this.accountInfo.invitation_code;
  134. context.font = "400 13px Arial";
  135. context.fillText(codeText, 290/2, 130);
  136. context.textAlign = "center";
  137. context.drawImage(image.path, 0, 163, 290, 220);
  138. context.drawImage(this.qrcodeUrl, (290-125)/2, 188, 125, 125);
  139. context.fillStyle = "black";
  140. context.font = "400 15px Arial";
  141. context.fillText('我的分享二维码', 290/2, 340);
  142. context.clip();
  143. context.draw(false, () => {
  144. // 返回canvas图片信息
  145. uni.canvasToTempFilePath({
  146. canvasId: 'canvasId',
  147. success: (res) => {
  148. uni.saveImageToPhotosAlbum({
  149. filePath:res.tempFilePath,
  150. success() {
  151. uni.hideLoading();
  152. uni.showModal({
  153. title: "保存成功",
  154. content: "图片已成功保存到相册",
  155. showCancel: false
  156. })
  157. },
  158. fail(e) {
  159. console.log(e)
  160. }
  161. })
  162. },
  163. fail: function(err) {
  164. console.log(err)
  165. uni.hideLoading();
  166. }
  167. })
  168. })
  169. }
  170. })
  171. })
  172. },
  173. getArcImg() {
  174. return new Promise((resolve, ret )=> {
  175. uni.getImageInfo({
  176. src: '/static/head-on.png',
  177. success:(image)=>{
  178. let ctx = uni.createCanvasContext('myCanvas', this);
  179. ctx.save();
  180. ctx.setStrokeStyle("#fff")
  181. ctx.beginPath(); //开始绘制
  182. //先画个圆 x,y是圆心的(x,y) 坐标 r是圆的半径 第四个参数是起始角,以弧度计。(弧的圆形的三点钟位置是 0 度) 第五个参数是结束角,以弧度计 最后是绘图方向 默认是false,即顺时针
  183. ctx.arc(32, 32, 30, 0, Math.PI * 2, false);
  184. ctx.setLineWidth(3)
  185. ctx.stroke()
  186. ctx.clip(); //画好了圆 开始剪切 原始画布中剪切任意形状和尺寸。一旦剪切了某个区域,则所有之后的绘图都会被限制在被剪切的区域内 这也是我们要save上下文的原因
  187. // drawImage(图片路径,x,y,绘制图像的宽度,绘制图像的高度)
  188. //path 是用uni.getImageInfo 获取的地址
  189. ctx.drawImage(this.accountInfo.head_photo||image.path, 0, 0, 63, 63); // 推进去图片,必须是https图片
  190. ctx.restore(); //恢复之前保存的绘图上下文 恢复之前保存的绘图上下午即状态 还可以继续绘制
  191. ctx.draw(false, (ret) => { // draw方法 把以上内容画到 canvas 中。
  192. uni.canvasToTempFilePath({
  193. canvasId: 'myCanvas',
  194. success: (re) => {
  195. // that.imgUrl = res.tempFilePath;
  196. resolve(re.tempFilePath)
  197. console.log(re)
  198. },
  199. fail: function(err) {
  200. console.log(err)
  201. }
  202. })
  203. });
  204. }
  205. })
  206. })
  207. },
  208. //传入组件的方法
  209. hideQrcode() {
  210. this.modal_qr = false;
  211. },
  212. //复制邀请码
  213. copy(code) {
  214. uni.setClipboardData({
  215. data: code,
  216. success: () => {
  217. uni.showToast({
  218. title: "复制成功",
  219. });
  220. },
  221. });
  222. },
  223. uqrcodeComplete(){
  224. this.$refs.uqrcode.toTempFilePath({
  225. success: res => {
  226. this.qrcodeUrl=res.tempFilePath;
  227. },
  228. });
  229. },
  230. },
  231. };
  232. </script>
  233. <style lang="scss">
  234. page {
  235. height: 100vh;
  236. }
  237. .bg {
  238. position: absolute;
  239. width: 100%;
  240. height: 100%;
  241. top: 0;
  242. bottom: 0;
  243. left: 0;
  244. right: 0;
  245. .bgImg {
  246. width: 100%;
  247. height: 100vh;
  248. vertical-align: bottom;
  249. overflow: hidden;
  250. }
  251. .position-ab {
  252. position: absolute;
  253. top: 272rpx;
  254. left: 0;
  255. right: 0;
  256. text-align: center;
  257. .mt64 {
  258. margin-top: 64rpx;
  259. }
  260. .code-top-bg {
  261. position: relative;
  262. height: 365rpx;
  263. // display: flex;
  264. // justify-content: center;
  265. .bg {
  266. height: 365rpx;
  267. background: #0B844A;
  268. width: 581rpx;
  269. margin-left: 50%;
  270. transform: translateX(-50%);
  271. border-top-left-radius: 20rpx;
  272. border-top-right-radius: 20rpx;
  273. }
  274. }
  275. .code-top-bg image {
  276. height: 365rpx;
  277. vertical-align: bottom;
  278. }
  279. .user {
  280. position: absolute;
  281. top: 46rpx;
  282. left: 0;
  283. right: 0;
  284. text-align: center;
  285. color: #ffffff;
  286. image {
  287. width: 126rpx;
  288. height: 126rpx;
  289. border-radius: 50%;
  290. border: 4rpx solid #fff;
  291. }
  292. }
  293. .code-bt-bg {
  294. position: relative;
  295. image {
  296. height: 396rpx;
  297. vertical-align: bottom;
  298. transform: rotate(180deg);
  299. width: 581rpx;
  300. }
  301. .code {
  302. position: absolute;
  303. top: 50rpx;
  304. left: 0;
  305. right: 0;
  306. text-align: center;
  307. .itemcode {
  308. display: flex;
  309. justify-content: center;
  310. }
  311. image {
  312. width: 196rpx;
  313. height: 196rpx;
  314. }
  315. }
  316. }
  317. .copy-btn {
  318. width: 294rpx;
  319. margin: 60rpx auto 0;
  320. }
  321. .copy-btn button {
  322. height: 60rpx;
  323. line-height: 60rpx;
  324. background: #0B844A;
  325. color: #ffffff;
  326. // border: 1rpx solid #0B844A;
  327. }
  328. }
  329. }
  330. #canvasId{
  331. width: 580rpx;
  332. height: 742rpx;
  333. margin-top: 20rpx;
  334. border-radius: 20rpx;
  335. overflow: hidden;
  336. position: fixed;
  337. right: -99999rpx;
  338. }
  339. #myCanvas{
  340. position: absolute;
  341. left: -99999rpx;
  342. }
  343. </style>